Big problem fetching members from dynamically loaded module

Philippe C. Martin philippe at philippecmartin.com
Sat Jun 25 15:59:25 EDT 2005


OK Peter, first of all thanks.

You seem to be German and although I leave in the states, I'm French and
your english is clearly far more advanced than mine: I have yet to
understand a few of your comments ;-)

> Care to provide the traceback?

Traceback (most recent call last):
  File "SC_Shell.py", line 1095, in ?
    l_d = SC_Shell()
  File "SC_Shell.py", line 326, in __init__
    self.__Make_Menu_Area()
  File "SC_Shell.py", line 828, in __Make_Menu_Area
    l = inspect.getmembers(eval(c))
  File "<string>", line 0, in ?
NameError: name 'BC' is not defined

> What happened in lines 1 through 22? My guess would be
just import inspect


and after that .... QUID ?

Thanks and regards,

Philippe





Peter Otten wrote:

> 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