HOW TO Create new module from source text

holger krekel pyth at devel.trillke.net
Sat Aug 10 05:59:52 EDT 2002


Chris Gonnerman wrote:
> I know I've done this before but darned if I can figure out
> how.  I need to load a block of source text and convert it
> into a module.  I can't just use import because the name 
> being imported may match a builtin module.

Have you looked into using 'execfile'?

    holger

 
> This is for an extension to my makesite.py site builder
> package.  I have files with arbitrary names but with a
> .src extension, which are loaded and stuffed through a 
> template to produce final pages.  I want to be able to
> load a module from a file with the same rootname but with 
> a different extension; but if that file doesn't exist I 
> don't want to accidentally load a standard module.
> 
> This like-named module will then be used to provide 
> additional pagebuilding logic for the template engine.
> 
> Any ideas?
> 
> Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
> http://newcenturycomputers.net
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list