[Python.NET] Packages are wrongly initialized?

Christian Heimes lists at cheimes.de
Wed Aug 1 08:06:12 CEST 2007


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



More information about the PythonDotNet mailing list