modifiable config files in compiled code?

Stephen Thorne stephen.thorne at
Fri Mar 11 05:41:06 CET 2005

On 10 Mar 2005 06:02:22 -0800, gaudetteje at
<gaudetteje at> wrote:
> Hi All,
> I've been trying to come up with an elegant solution to this problem,
> but can't seem to think of anything better than my solution below.
> I have a Python program that needs to be converted into an executable.
> The problem is that I have a "config" template file that I've been
> using to modify initialization constants such as paths, global
> variables, structures, etc.  Obviously, once I convert my code into an
> executable I can no longer read/write to my configuration file.
> My solution was to convert this config file into a standard ASCII text
> document and have Python parse it for user set variables.  This doesn't
> seem like the most elegant of solutions; however, and I thought others
> must have implemented a better way than this.
> Anyone have a better solution for this problem?

Package outside the zipfile containing all the python bytecode.

1) Remove config.pyc from dist\ as the last thing you do in

2) As the first thing you do in (or whatever your main is), do:

import sys, os
    import config
except ImportError:
    # We're in a py2exe, so we'll append an element to the (one element) 
    # sys.path which points to, to the directory that contains 
    #, allowing us to import
    import config

3) Put in your

setug( ....
        data=[('.', [''])]# Package seperately.

Stephen Thorne

More information about the Python-list mailing list