且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在许多文件中导入常量

更新时间:2022-11-22 13:03:52

您可以在一个文件中声明所有常量,比如说 constants.py 然后将它们导入其他人。以下是一个示例:

You can declare all your constants in one file, say constants.py and then import them into others. Here is an example:

# constants.py
FOO = 'foo'
PI = 3.14

# main.py
import constants
print constants.PI