Module Name Conflicts

torched_smurf at yahoo.com torched_smurf at yahoo.com
Thu Aug 18 19:58:08 EDT 2005


Robert Kern wrote:
> Dan Sommers wrote:
>
> > Assuming you can fiddle with sys.path at the right times, you can call
> > an imported module anything you want:
> >
> >     fix_sys_path_to_find_java_cmd_first()
> >     import cmd as java_cmd
> >     fix_sys_path_to_find_python_cmd_first()
> >     import cmd as python_cmd
> >
> > Obviously, then, 'cmd' does not reference either module; you'd have to
> > use java_cmd and python_cmd as appropriate.
>
> That doesn't work. The first module is recorded as 'cmd' in sys.modules
> and gets reused on the second import.

Exactly. And clearing sys.modules doesn't fix the problem. Once it's
imported something from the first cmd package, it can no longer find
anything in another cmd package; it will always look for it in that
first package.

-Smurf




More information about the Python-list mailing list