Can I import a file without file extension .py?

Dustan DustanGroups at gmail.com
Thu Feb 1 04:44:41 EST 2007


On Feb 1, 12:51 am, "Jia Lu" <Roka... at gmail.com> wrote:
> >     def make_module_from_file(module_name, file_name):
> >         """ Make a new module object from the code in specified file """
>
> >         from types import ModuleType
> >         module = ModuleType(module_name)
>
> >         module_file = open(file_name, 'r')
> >         exec module_file in module.__dict__
>
> Thank you very much.
> And can you tell me what does " exec module_file in module.__dict__ "
> mean?
>
> Thanx

http://docs.python.org/ref/exec.html

It executes whatever code is in module_file and dumps all variables
defined in the process into module.__dict__.




More information about the Python-list mailing list