include statement

Bruno Desthuilliers onurb at xiludom.gro
Wed Sep 20 04:04:11 EDT 2006


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.

Maybe... "import" is the very appropriate statement for what you want
here IMVHO. I'd just put the config<X>.py files into a 'config'
directory, add an __init__.py, and put the 'from configX import *'
there. Then in the app code, a simple 'import config', which allow acces
to config vars via 'config.varname' (clean namespaces really improve
maintainability).

My 2 cents

> Regards
> 
> Joakim
> 


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list