I've got a file, constants.py
, that contains a bunch of global constants. Is there a way I can grab all of them as dict, for just this file?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I'm not sure I see the point of this though. How is writing
constants_dict['MY_CONSTANT']
any better/easier/more readable thanconstants.MY_CONSTANT
?EDIT:
Based on the comments, I see some potential uses now.
Here's another way to write the above, depending on how compact you want it.
EDIT2:
cji for the win!
constants.__dict__
It should be simple: