[Tutor] Replacing "source" in Bash Scripting
bgailer at alum.rpi.edu
Fri Sep 28 16:19:48 CEST 2007
> 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:
> 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.
The simplest, IMHO, is: create and import a module (e.g. config.py) with
a series of assignments:
In the script:
from config import *
There are also a number of modules in the Python library for doing more
complex config file manipulation.
More information about the Tutor