How to import constants into many files

I have a package containing many modules. Each module uses constants, which I defined independently in each file. However, all these constants must be constant with each other. Therefore, I try to define them in one file and import in each file. When I run it, I have errors for constants that are not found.

Is their a clean way to have one file imported by many others and containing constants?

thanks for the help

+4
source share
1 answer

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 
+8
source

All Articles