[PEAK] plugins, dynamic module loading

darryl developer at csrules.dyndns.org
Mon Nov 24 21:51:02 EST 2003


Question:

Config files are 'read-only' or at least so-much as the support
that peak provides is for reading.

If i'm keeping config values in an ini file and wish to
write out changed config values for the next time
the app runs, is there a preferred peak-ish way for this?

Also is there a way to re-read a config file.
i.e. if i do a

binding.Obtain(PropertyName('bot.modules'))

and then later edit the ini file can i re-Obtain the values?

-darryl

>
> Heavens.  Y'all sure like to do things the hard way.  :)
>
>
> Put this in the class:
>
>     modules = binding.Obtain(PropertyName('bots.modules'))
>
>
> And this in your .ini:
>
> [bots]
> modules = [
>     importString('somepkg.mymodule1'),
>     importString('somepkg.mymodule2'),
>     ...
>  ]
>
>
> Or if you *must* be dynamic about it...
>
> [bots]
> modules = [
>     importString('somepkg.'+x[:-3]) # strip the .py
>     for x in 
> importString('glob').glob(config.fileNearModule('somepkg','*.py'))
>  ]
>
>
> (By the way, 'importString' can be found in peak.util.imports, if you 
> need to use it in Python code.  Expressions in '.ini' files get it in 
> their default globals, since it's so often needed there.)






More information about the PEAK mailing list