The easiest way to do this is to simply configure the parameters as a module.
(settings.py)
CONSTANT1 = "value1" CONSTANT2 = "value2"
(consumer.py)
import settings print settings.CONSTANT1 print settings.CONSTANT2
When importing a python module, you must prefix the variables that you extract from it with the module name. If you know exactly what values ββyou want to use from this file in the file and you do not care about changing them at runtime, then you can do
from settings import CONSTANT1, CONSTANT2 print CONSTANT1 print CONSTANT2
but I would not be carried away by this last. This makes it difficult for people reading your code to know where the values ββcome from. and excludes that these values ββare updated if another client module changes them. The last way to do this is
import settings as s print s.CONSTANT1 print s.CONSTANT2
This will allow you to print, distribute updates and require readers to remember that there is something after s from the settings module.
aaronasterling Sep 29 '10 at 17:59 2010-09-29 17:59
source share