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

Rick Dooling rpdooling at gmail.com
Wed Mar 12 14:16:15 EDT 2008


On Mar 12, 11:22 am, mrstephengross <mrstevegr... at gmail.com> wrote:
> 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?
>

I think you answered your own question, but if you want more info:

>From the Python Tutorial:

http://docs.python.org/tut/node8.html

"A module is a file containing Python definitions and statements. The
file name is the module name with the suffix .py appended."

RD




> Thanks,
> --Steve




More information about the Python-list mailing list