[Python.NET] followup: import works only after failed import

Leonard :paniq: Ritter paniq at gmx.net
Thu Jan 15 07:51:03 EST 2004


update:

it seems as if

import CLR
from CLR.QuenceNET import bla

does the trick, however that doesnt work on the python prompt.

anyway, so far it all works great in the code,
thanks for that wrapper, brian, with your work you have already
filled a big hole in the compatibility chain.

----------------8<--------------------------

this is even funnier. importing a .net assembly seems only to work if the dll has been loaded before.

in each try, i restart python from the directory where the .net DLL is located.

first try:

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET

second try:

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

third try (optimized):

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

fourth try (variant):

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

so to import my custom assembly in python, the code currently looks like this:

import CLR
try:
        import QuenceNET # for the error
except:
        pass # catch
import CLR.QuenceNET


-- Leonard Ritter
-- paniq at gmx.net
-- http://www.quence.com
-- http://www.paniq.de





More information about the PythonDotNet mailing list