I have a question similar to the question asked here: Importing a long list of constants to a Python file
Basically, I have a separate module which just contains a long list of constants, e.g.
constants.py
x = 1.2
y = 30.4
.
.
.
In another module, I would like import these constants and initialize them as instance attributes.
class.py
class something(object):
def __init__(self):
import constants
self.x = constants.x
self.y = constants.y
.
.
.
Is there an easier or more pythonic way to do this instead of retyping all of the variable names?
Python developers have developed a cool solution: it’s called ConfigParser.
A practical example: config.ini
class.py
I hope this helps.
EDIT: If you need instance attributes, you can do:
EDIT2: need a Python file and a .ini file is not a solution?