Big problem fetching members from dynamically loaded module

Peter Otten __peter__ at web.de
Sun Jun 26 02:45:54 EDT 2005


Philippe C. Martin wrote:

> Any clue would be quite welcome.

I didn't recognize the pattern in the code you posted, but sometimes the
order of imports matters:

$ find .
.
./package
./package/beta.py
./package/alpha.py
./package/__init__.py
$ python
Python 2.3.3 (#1, Feb  5 2005, 16:22:10)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from package.beta import *
>>> from package import *
>>> from package.alpha import *
>>> alpha
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'alpha' is not defined
>>> beta
<module 'package.beta' from 'package/beta.py'>

The 'right' way to do the imports if you want both 'alpha' and 'beta' is of
course

from package import alpha
from package import beta

Peter




More information about the Python-list mailing list