Big problem fetching members from dynamically loaded module
Peter Otten
__peter__ at web.de
Sat Jun 25 15:37:38 EDT 2005
Philippe C. Martin wrote:
> l = inspect.getmembers(eval('BC')) #THIS CRASHES - the class exists
Care to provide the traceback?
> In [23]:from SC.CARDS.BC import *
>
> In [24]:l = inspect.getmembers(eval('BC'))
What happened in lines 1 through 22? My guess would be
In [13]:from SC.CARDS import *
Be that as is may, eval("BC") can be simplified to BC,
from module import *
is the last roadhouse en route to chaos and an unqualified
try ... except
shows you are willing to drive with defunct brakes. By introducing exec and
eval() you are throwing the steering wheel out of the window.
Seriously, try to make do with __import__() and getattr() to clean up your
code a bit.
Driving-analogies-well-beyond-the-abyss-ly yours
Peter
More information about the Python-list
mailing list