openmc
openmc copied to clipboard
Python API: Replace magic strings with constants
Right now, the Python API has a lot of hardcoded strings in the code. For example, in summary.py:
if "dagmc" not in self._f['geometry'].attrs.keys():
. . .
for group in self._f['geometry/surfaces'].values():
. . .
for group in self._f['geometry/universes'].values():
. . .
for group in self._f['geometry/lattices'].values():
. . .
This could be replaced by:
"""tags.py:"""
GEOMETRY = "geometry"
SURFACE = GEOMETRY + "/surfaces"
. . .
"""summary.py"""
if "dagmc" in self._f[tags.GEOMETRY]:
. . .
for group in self._f[tags.SURFACE].values():
. . .
This makes it possible to change things in a single location instead of many, and creates tags accessible by users of the API.
If there's interest this is something I can do next time I'm bored.