How to import from filename with dots in it?

Frank Niessink niessink at serc.nl
Tue Feb 13 06:30:07 EST 2001


Frank Niessink <niessink at serc.nl> wrote:
> 
> I want to import from a file called 'foo-0.1.py'. Is this at all possible?
> Maybe using __import__?

After some experimenting I found a solution:

>>> import imp
>>> location = imp.find_module('foo-0.1')
>>> foo_0_1 = imp.load_module('dummy', *location)

The first argument to load_module does not seem to matter?

Cheers, Frank
-- 
"An SEP," he said, "is something that we can't see, or don't see, or our brain
doesn't let us see, because we think that it's somebody else's problem. That's
what SEP means. Somebody Else's Problem. The brain just edits it out, it's
like a blind spot."
	-- Douglas Adams, 'Life, the Universe, and Everything'



More information about the Python-list mailing list