How to run a python script with a configuration file at command line ?
Ben Finney
ben+python at benfinney.id.au
Thu Jun 3 21:47:47 EDT 2010
steph_awk <stephane.larochelle at gmail.com> writes:
> I have been searching for quite some times without success.
Did you try the standard library?
> I have a python script that needs to start from command line and it
> should have a config file to fill out the detais (itis one program,
> and many possible configurations).
The ‘ConfigParser’ module in Python 2.x, or ‘configparser’ in Python 3.x
<URL:http://docs.python.org/library/configparser> reads Windows
INI-style configuration files into Python data structures.
> something as simple as PHP would be nice %> ./PHPscript -c configfile
>
> is there such a thing in Python?
For handling command-line arguments, see ‘optparse’
<URL:http://docs.python.org/library/optparse> or ‘getopt’
<URL:http://docs.python.org/library/getopt>.
A significant improvement is available in the ‘argparse’ module,
currently third-party <URL:http://pypi.python.org/pypi/argparse> but on
track for inclusion in the Python standard library
<URL:http://www.python.org/dev/peps/pep-0389/>.
--
\ “Pinky, are you pondering what I'm pondering?” “Uh, I think so, |
`\ Brain, but we'll never get a monkey to use dental floss.” |
_o__) —_Pinky and The Brain_ |
Ben Finney
More information about the Python-list
mailing list