
Hi all, i'm in the process of embedding python in a C# application. After initializing the engine, my application imports via (ImportModule) a custom package which contains the python side of my code. doing the following code raises an AttributeError Exception: PyObject pypackage = PythonEngine.ImportModule('pypackage'); PyObject sub_module = pypackage.GetAttr('sub_module'); <-- raises the exception here One other thing that isn't working is a non empty __init__.py inside the package; trying to import any symbol defined in the __init__.py also raises an AttributeError. instead, this line works as expected: PyObject pypackage = PythonEngine.ImportModule('pypackage.submodule'); I've tried the code with the old trunk and with the newer Christian's one. am I doing something wrong? Anyone as any clue? thanks in advance Alberto

Note that imports are subtley different than getattr behavior... does your main main 'pypackage' package contain something like the following in its __init__? from subpackage import * -Brian On 7/31/07 9:22 PM, "Alberto Berti" <alberto@metapensiero.it> wrote:
Hi all,
i'm in the process of embedding python in a C# application. After initializing the engine, my application imports via (ImportModule) a custom package which contains the python side of my code.
doing the following code raises an AttributeError Exception:
PyObject pypackage = PythonEngine.ImportModule('pypackage'); PyObject sub_module = pypackage.GetAttr('sub_module'); <-- raises the exception here
One other thing that isn't working is a non empty __init__.py inside the package; trying to import any symbol defined in the __init__.py also raises an AttributeError.
instead, this line works as expected:
PyObject pypackage = PythonEngine.ImportModule('pypackage.submodule');
I've tried the code with the old trunk and with the newer Christian's one.
am I doing something wrong? Anyone as any clue?
thanks in advance
Alberto
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
-------------------------- Brian Lloyd brian.lloyd@revolutionhealth.com

"Brian" == Brian Lloyd <brian.lloyd@revolutionhealth.com> writes:
Brian> Note that imports are subtley different than getattr Brian> behavior... does your main main 'pypackage' package Brian> contain something like the following in its __init__? Brian> from subpackage import * It's really late here, but if i correctly remember i've tried a star import, a named import and an empty __init__.py, all with the same effect, but i will retry asap, thanks. Alberto

Alberto Berti wrote:
doing the following code raises an AttributeError Exception:
PyObject pypackage = PythonEngine.ImportModule('pypackage'); PyObject sub_module = pypackage.GetAttr('sub_module'); <-- raises the exception here
That doesn't work under Python unless pypackage import submodule in its __init__.py: $ python Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import email getattr(email, 'charset') Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'charset' import email.charset getattr(email, 'charset') <module 'email.charset' from 'email/charset.pyc'>
Christian
participants (3)
-
Alberto Berti
-
Brian Lloyd
-
Christian Heimes