Commit 1846ad07 authored by Martin Claus's avatar Martin Claus

Fixed some Git-flavour markdown errors

parent 6e4da85e
......@@ -4,28 +4,41 @@ Parse Fortran Namelists to dict-like objects and back
## Download
To get the latest git version do
$ git clone https://github.com/martinclaus/py-namelist.git
```
$ git clone https://github.com/martinclaus/py-namelist.git
```
## Usage
To parse a namelist file you call parse_namelist(fobj) where fobj is a file-like object offering a read() and seek() method (usually the standard python file object).
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.
To parse a namelist file you call `parse_namelist(fobj)` where fobj is a file-like object offering a `read()` and `seek()` method (usually the standard python file object).
```
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.
The Namelist class is a subclass of dict or OrderedDict if you use Python >= 2.7. A Namelist object, nml, is initialized with an name and optionally with initial values.
nml = Namelist("param", (("key1", val1), ...))
`Namelist` is a subclass of `dict` or `OrderedDict` 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.
print nml.name
nml.update({"eggs": 1, "spam": [1, 2, 3]})
del(nml["param"])
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.
```
print nml.name
nml.update({"eggs": 1, "spam": [1, 2, 3]})
del(nml["param"])
```
To create a Fortran readable string representation of the Namelist instance, just use the str() build-in
s = str(nml)
To create a Fortran readable string representation of the Namelist instance, just use the `str()` build-in
```
s = str(nml)
```
or just
print(nml)
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)
```
print(nml)
```
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)
```
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment