Module Name Conflicts

torched_smurf at yahoo.com torched_smurf at yahoo.com
Fri Aug 19 03:12:32 CEST 2005


ncf wrote:
> Maybe what you're looking for is __import__()?

Okay, actually this does work, but only in one direction. That is, I
can import the python package first, and then the java package, but not
the other way around.

--------------------------------------------------------------
Importing the python cmd first:

$~> jython
Jython 2.2a1 on java1.4.2_08 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> __import__('cmd')
<module 'cmd' from '~/code/jython-2.2a1/Lib/cmd.py'>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ python package
>>> import sys
>>> sys.path.insert(0, java_classpath)
>>> sys.modules.clear()
>>> __import__('cmd')
<java package cmd 1>
^^^^^^^^^^^^^^^^^^^^ java package

--------------------------------------------------------------
Importing the java cmd first:

$~> jython
Jython 2.2a1 on java1.4.2_08 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0, java_classpath)
>>> __import__('cmd')
<java package cmd 1>
^^^^^^^^^^^^^^^^^^^^ java package
>>> sys.path = sys.path[1:]
>>> sys.modules.clear()
>>> __import__('cmd')
<java package cmd 1>
^^^^^^^^^^^^^^^^^^^^ java package, again
--------------------------------------------------------------

Very odd.

-Smurf




More information about the Python-list mailing list