I have a small python script which serves as a configuration file. The structure is like
project=Project(param1=..., param2=..., ...)
project.add_plugins(P1(data=project.db1()),
P2(data=project.db2()))
project.run_plugins(get_selected())
For easier notation I’d like to introduce something like
db1=project.db1
db2=project.db2
for all attributes of project, so that I don’t need to write out project.. Can you suggest a nice way of doing that for all attributes automatically?
I don’t think it’s a good idea (see my comment to your question), but you can do it with the globals built-in:
The reason I don’t think it’s a good idea is that it pollutes the global namespace with something that was to begin with very neatly wrapped in a logically named namespace. Your going from better to worse.
The Zen of Python (
import this) has a last line which reads: