James wrote: > Hi. > > I'm re-writing a rather complex bash script I've been using for years > in Python. The bash script uses a relatively simple configuration > file in order to get pertinent information before it runs. The > configuration file is relatively simple: about 30 variables are > defined in this manner in the config file: > > VARNAME=value > > In the bash script I simply "source" this configuration file and the > script runs merrily using those variables defined in the > configuration file. i.e., > > "source configFile" > > I'm trying to implement similar behavior in a Python script, > specifically having a configuration file (with a list of variables > and their values defined) that my Python program will read once > running. I'm not really sure what the best way to implement this is. > > Ideas? > The simplest, IMHO, is: create and import a module (e.g. config.py) with a series of assignments:
VARNAME1='value1' VARNAME2='value2' In the script: from config import * There are also a number of modules in the Python library for doing more complex config file manipulation. _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
