On Sun, Nov 24, 2013 at 2:18 AM, Christian Gollwitzer <aurio...@gmx.de> wrote: > Am 24.11.13 04:41, schrieb Chris Angelico: > >> As part of a post on python-ideas, I wanted to knock together a quick >> little script that "imports" a file based on its name, in the same way >> that the Python interpreter will happily take an absolute pathname for >> the main script. > > > Is it imp.load_source() that you are looking for?
That appears to work, but I note that it's undocumented and seems to be used internally only by the deprecated load_module function. I expect it will likely be removed in Python 3.5. > Modifying sys.path is only necessary because the file could further import > modules from the same path. This won't work if the imported file is part of a package and attempts to import another module in the same package (unless it uses the old relative import syntax, which was removed in Python 3). -- https://mail.python.org/mailman/listinfo/python-list