Does __import__ require a module to have a .py suffix?

Michael Wieher michael.wieher at gmail.com
Wed Mar 12 12:34:12 EDT 2008


2008/3/12, mrstephengross <mrstevegross at gmail.com>:
>
> Hi all. I've got a python file called 'foo' (no extension). I want to
> be able to load it as a module, like so:
>
>   m = __import__('foo')
>
> However, the interpreter tells me "No module named foo". If I rename
> it foo.py, I can indeed import it. Is the extension required? Is there
> any way to override that requirement?
>
> Thanks,
> --Steve
>
> --
> http://mail.python.org/mailman/listinfo/python-list


>>> m=__import__('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named foo
>>> m=__import__('foo.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named foo.py
>>>
michael at majw-m65:~/Code/Scratch$ ls
foo
michael at majw-m65:~/Code/Scratch$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080312/72e45c71/attachment-0001.html>


More information about the Python-list mailing list