HOW TO Create new module from source text

Chris Gonnerman chris.gonnerman at
Sat Aug 10 06:08:34 CEST 2002

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.

This is for an extension to my 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

More information about the Python-list mailing list