modifiable config files in compiled code?
Tom Willis
tom.willis at gmail.com
Thu Mar 10 09:22:31 EST 2005
10 Mar 2005 06:02:22 -0800, gaudetteje at gmail.com <gaudetteje at gmail.com> 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?
>
> Jay
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Don't know if you knew about this.....
#example
from ConfigParser import ConfigParser
def getconfig():
"""
initialize configuration settings
"""
result = ConfigParser()
result.read("config.ini")
return result
def main():
"""
runs the app
"""
config = getconfig()
...
dbsettings = {}
for key,value in config.items("db"):
print "%s: %s" % (key,value)
#etc...
#-------------------config.ini--------------
;db settings
[db]
server = 127.0.0.1
db = db
user = user
password = password
#--------------------end config.ini------------
There are other projects for dealing with config information but
ConfigParser is included wth python I think.
Hope that helps...
--
Thomas G. Willis
http://paperbackmusic.net
More information about the Python-list
mailing list