How can I import a script with an arbitrary name ?

Fredrik Lundh fredrik at pythonware.com
Tue Oct 31 07:28:00 EST 2006


Steven D'Aprano wrote:

> I'm not arguing, you could very well be right, but I'm just curious what
> part of the OP's post led you to believe he needed to specify an absolute
> filename. Unless I'm missing a second post, he certainly never suggested
> that his scripts weren't in the Python path, or that he couldn't add their
> location to the path.

the fact that he's using dashes in the module name might be a hint, though.

in current versions, __import__ doesn't care as long as the file has
the right extension, but import requires valid Python identifiers, for 
obvious reasons.

execfile doesn't care about any part of the filename, of course (and if 
you replace it with exec, you don't even have to read the script from a 
file).

</F>




More information about the Python-list mailing list