include statement
Larry Bates
larry.bates at websafe.com
Wed Sep 20 09:11:02 EDT 2006
More information about the Python-list mailing list
Wed Sep 20 09:11:02 EDT 2006
- Previous message (by thread): Embedding Python and command history
- Next message (by thread): include statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
joakim.hove at gmail.com wrote: > Thanks to all who took time to answer! > > >>> is it possible in python to include another python source file into the >>> current namespace, i.e.completely analogous to the #include statement >>> in C. > > [...] > >> Tell us why you are contemplating such a thing, and someone >> here will help you implement it the "Pythonic" way. > > My application has a configuration file where lots of variables are > set. (The configuration file is python source, so there is no > home-brewed parsing involved.) The configuration file is starting to > get quite large and unwieldy, so for this reason I would like to split > it in several files. > > I know I could do: > from configA import * > from configB import * > > But I felt that the import statemant was 'more' than I wanted. Maybe I > am just pedantic. > > Regards > > Joakim > I might also suggest that you consider using ConfigParser module to store your "variables". If you are worried about performance, I can tell you that I use it to feed thousands of lines of configuration info into one of my applications (this app has 5 of these files) and ConfigParser handles them so quickly that performance is NOT a problem. The format of the file is easily understandable by nearly every user which means I don't have to worry with someone not understanding Python's syntax. If someone gets something wrong in a file that gets included, it is harder to take a sane default or handle the error than with ConfigParser. Just a suggestion that I hope helps. -Larry Bates or
- Previous message (by thread): Embedding Python and command history
- Next message (by thread): include statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list