[Tutor] importing

Kristoffer Erlandsson krier115@student.liu.se
Tue Jun 24 15:24:01 2003


On Tue, Jun 24, 2003 at 02:14:14PM -0500, Isaac Hall wrote:
> alright, this is kind of an odd question, and Im not sure that there is 
> another way I can go about doing this.
> 
> I have a program that I would like to call with one or more than one 
> configuration files in the command line.  For what I want, the easiest way 
> to create these configuration files was just to make them a collection of 
> python dictionaries.  This way I figured I wouldnt have to waste time 
> creating some method to read a configuration file.  However I found that 
> putting in a statement like:
> 
> try:
>    import sys.argv[1]
> except:
>    print 'bad config file'
> 
> doesnt quite work.  Does anyone know if there are clever ways to import a 
> file that can be specified in the command line?

Check out the ConfigParser module. It specifies some methods for
handling of configuration files, and provides a much more natrual syntax
in them than to use a Python dictionary. The docs can be found here:
http://www.python.org/doc/current/lib/module-ConfigParser.html
Not at all hard to grasp and will make life easier for you. Hope that
helps!

-- 
Kristoffer Erlandsson
E-mail:  krier115@student.liu.se
ICQ#:    378225