Git Product home page Git Product logo

namelist_python's Introduction

Fortran namelist files in Python

Build Status

Install with pip

pip install namelist_python

Read in a namelist file:

from namelist_python import read_namelist_file
namelist = read_namelist_file('SIM_CONFIG.nl')

namelist is an instance of namelist_python.Namelist and all groups are stored in the attribute groups with each variable in a nested dictionary structure (using OrderedDict so that the order will be remembered).

Write a Namelist object back to a file:

with open('NEW_FILE.nl', 'w') as f:
	f.write(namelist.dump())

dump takes an optional argument array_inline a boolean which sets whether arrays should be inline or given in index notation.

If you use ipython there is usefull attribute called data which allows you to do tab completion on the group and variable names, and do assignment:

In [7]: namelist.data.ATHAM_SETUP.dt
namelist.data.ATHAM_SETUP.dt
namelist.data.ATHAM_SETUP.dtmax
namelist.data.ATHAM_SETUP.dtmin
In [7]: namelist.data.ATHAM_SETUP.dt
Out[7]: 3.0

In [8]: namelist.data.ATHAM_SETUP.dt = 4.0

In [9]: namelist.data.ATHAM_SETUP.dt
Out[9]: 4.0

Features

  • Parses ints, floats, booleans, escaped strings and complex numbers.
  • Parses arrays in index notation and inlined.
  • Can output in namelist format.
  • Tab-completion and variable assignment in interactive console

Missing features

  • Currently can't handle variable definitions across multiple lines
  • Comments are not kept, and so won't exist in output.

Contribute

Please send any namelist files that don't parse correctly or fix the code yourself and send me a pull request :)

Thanks, Leif

namelist_python's People

Contributors

jfburkhart avatar leifdenby avatar stefanstoeckl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.