我有一个文件 config.py,其中包含几个常量。 我怎样才能打印所有这些? 像这样的东西:
for c in config:
print c
这对于模块 config.py 来说当然是不可能的,因为它不可迭代。
最佳答案
你要找的可能是__dict__
。
for c in config.__dict__:
print c
将打印与config
for c in config.__dict__:
print config.__dict__[c]
会给你所有的值。
关于python - 打印 python 文件的所有常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35440549/