Skip to main content

Parsing Fortran namelists to Python dictionaries and back.

Project description

pipeline status coverage report


Parse Fortran Namelists to dict-like objects and back


To get the latest release do

git clone --branch v0.1.0 --depth=1

or, if you prefer the latest unstable version

git clone


To parse a namelist file you call parse_namelist_file(fobj) where fobj is a file-like object offering a read() and seek() method (usually the standard python file object). Alternatively, you can parse a string using parse_namelist_string(str).

import namelist
with open(your_nml_file) as fobj:
	nmls = namelist.parse_namelist_file(fobj)

nmls will be a list of instances of the Namelist class.

Namelist is a subclass of OrderedDict (or dict if you use Python < 2.7). A Namelist instance, nml, is initialized with an name and optionally with initial values.

nml = Namelist("param", (("key1", val1), ...))

The name attribute will set the read-only property name of nml. To change, add or delete values the same methods are available as for dict.

nml.update({"eggs": 1, "spam": [1, 2, 3]})

To create a Fortran readable string representation of the Namelist instance, just use the str() build-in

s = str(nml)

or just


A string representation of the Namelist instance that can be used by eval() to create copies of it can be created by repr()

print repr(nml)

Note: The parsing of namelist does not have to strictly follow the Fortran standard. Hence, some namelists that are perfectly accepted by some Fortran version are not guaranteed to be correctly parsed by parse_namelist_string(). Always check the content of your Namelist object. If you do find a namelist that does not work, please create an issue at together with the namelist that does not work.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for namelist, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size namelist-0.1.0.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View
Filename, size namelist-0.1.0-py3-none-any.whl (11.8 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page