CIME.namelist.parse
- CIME.namelist.parse(in_file=None, text=None, groupless=False, convert_tab_to_space=True)[source]
Parse a Fortran namelist.
The in_file argument must be either a str or unicode object containing a file name, or a text I/O object with a read method that returns the text of the namelist.
Alternatively, the text argument can be provided, in which case it must be the text of the namelist itself.
The groupless argument changes namelist parsing in two ways:
parse allows an alternate file format where no group names or slashes are present. In effect, the file is parsed as if an invisible, arbitrary group name was prepended, and an invisible slash was appended. However, if any group names actually are present, the file is parsed normally.
The return value of this function is not a Namelist object. Instead a single, flattened dictionary of name-value pairs is returned.
The convert_tab_to_space option can be used to force all tabs in the file to be converted to spaces, and is on by default. Note that this will usually allow files that use tabs as whitespace to be parsed. However, the implementation of this option is crude; it converts all tabs in the file, including those in character literals. (Note that there are many characters that cannot be passed in via namelist in any standard way, including ‘
- ‘,
so it is already a bad idea to assume that the namelist will preserve whitespace in strings, aside from simple spaces.)
The return value, if groupless=False, is a Namelist object.
All names and values returned are ultimately unicode strings. E.g. a value of “6*2” is returned as that string; it is not converted to 6 copies of the Python integer 2. Null values are returned as the empty string (“”).