Re: import on modules/files that don't have .py extension
anthony_barker@ hotmail.com (Anthony_Barker ) wrote in message news:<899f842.0 309170649.517e0 bb9@posting.goo gle.com>...[color=blue]
> Is it possible to import modules/files that have something other than
> the .py extension?[/color]
You can use the imp module to achieve this. For example, for a module
called "mymodule" in a source file called "myfile" then
should import the contents of "myfile" as a module which you can use
as normal. The "mymodule" parameter to the load_source function
presumably just ensures that
mymodule.__name __ = "mymodule"
so that anything relying on that has no nasty surprises. Note that, for this
example, you may end up with a file called "myfilec" alongside "myfile".
Comment