Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-to import constants in many files

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

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

Thanks for your help

like image 577
kheraud Avatar asked Jul 18 '11 10:07

kheraud


1 Answers

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
like image 158
dogbane Avatar answered Oct 07 '22 14:10

dogbane