-
Notifications
You must be signed in to change notification settings - Fork 58
Lists of namelists cannot be added #167
Description
A namelist containing a list of namelists created in Python cannot be written to file and throws an error.
The test program:
import f90nml
data = f90nml.Namelist()
data["dict1"] = f90nml.Namelist(attr1=1, attr2=2)
data["list1"] = []
data["list1"].append(f90nml.Namelist(attr3=3, attr4=4))
data["list1"].append(f90nml.Namelist(attr3=5, attr4=6))
data.write("somefile.out")
gives - for Python 3.8 and f90nml versions 1.4.1, 1.4.3, and 1.4.4
Traceback (most recent call last):
File "/home/rhfogh/Software/scripts/test_f90nml.py", line 9, in
data.write("/home/rhfogh/calc/mxcube_data/f90nmltst5.out")
File "/alt/rhfogh/Software/miniconda3/envs/mxcubeqt/lib/python3.8/site-packages/f90nml/namelist.py", line 578, in write
self._writestream(nml_file, sort)
File "/alt/rhfogh/Software/miniconda3/envs/mxcubeqt/lib/python3.8/site-packages/f90nml/namelist.py", line 677, in _writestream
self._write_nmlgrp(grp_name, grp_vars, nml_file, sort)
File "/alt/rhfogh/Software/miniconda3/envs/mxcubeqt/lib/python3.8/site-packages/f90nml/namelist.py", line 693, in _write_nmlgrp
for v_name, v_val in grp_vars.items():
AttributeError: 'list' object has no attribute 'items'
With the output:
&dict1
attr1 = 1
attr2 = 2
/
&list1
When running with Python 3.8 and f90nml version 1.3.1 the test works and you get the desired result:
&dict1
attr1 = 1
attr2 = 2
/
&list1
attr3 = 3
attr4 = 4
/
&list1
attr3 = 5
attr4 = 6
/