How can I import a script with an arbitrary name ?

Ben Finney bignose+hates-spam at
Tue Oct 31 12:53:56 CET 2006

"Steven D'Aprano" <steve at> writes:

> On Tue, 31 Oct 2006 11:00:52 +1100, Ben Finney wrote:
> > If you want a solution that gives you an actual module object,
> > here's what I use:
> > 
> >     def make_module_from_file(module_name, file_name):
> >         """ Make a new module object from the code in specified file """
> The only advantage (or maybe it is a disadvantage?) I can see to
> your function is that it doesn't search the Python path and you can
> specify an absolute file name.

Which is exactly what the OP asked for (though he didn't necessarily
need a module object).

 \        "We have to go forth and crush every world view that doesn't |
  `\             believe in tolerance and free speech."  -- David Brin |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list