__import__ function broken in 2.6

Carl Banks pavlovevidence at gmail.com
Sat Apr 25 21:22:26 EDT 2009


On Apr 25, 2:37 pm, Paul <Paul22... at gmail.com> wrote:
> It seems in 2.6 you are no longer able to use the __import__ function
> with different paths.

That functionality was deliberately removed, since it was never
intended to be present in the first place, and it only "worked" before
by accident.  To get that behavior:

1. Insert the directory where it's located into sys.path.  (And be
wary of module name conflicts.)

2. If it's a small config-type file, then execfile() would

As for why it was removed, it's because importing is designed to work
on package names, not filenames.  (Given that Python's importing
framework is so complicated, though, one wonders whethter sticking to
a design ideal is worth it.)


Carl Banks



More information about the Python-list mailing list