Big problem fetching members from dynamically loaded module

Philippe C. Martin philippe at philippecmartin.com
Sat Jun 25 21:18:04 CEST 2005


Hi,

I found the solution to my problem:

Besides the fact I still have no clue as to how the Python name spacing
works, the code I though did stuff (the __EXEC_LIST loop) did not do as I
expected as I had already imported all of the modules in an explicit
manner.

So now I can rephrase my problem:

1) I have a program (XYZ) which displays class members in menus
2) At the time I write my program, I do not know what class members should
be in thos menus
3) So I have the class names in external files so that I can send new
modules to the 'customer' without having to release a new version of 'XYZ'

What puzzles me furher is that the 'exec' of commands such as 'sc_bc = BC()'
do work as I use them further in 'XYZ' whereas the exec of 'from xxxxxxx
import *' does not _seem_ to do anything.

Grrr! I feel more stupid every day !

Any insight ?

Thanks,

Philippe












Philippe C. Martin wrote:

> Hi,
> 
> I'm getting pretty desperate here:
> 
> The code below crashes on the last line (but works from a shell).
> 
> The class 'BC' exists and the loop on self.__BC_EXEC_LIST passes fine.
> 
> It's got to be something really stupid but I've been looking at it too
> long I guess.
> 
> Any clue would be quite welcome.
> 
> Regards,
> 
> Philippe
> 
> 
> 
> 
> 
> 
>     __EXEC_LIST = [ \
>     'import os', \
>     'import sys', \
>     'from SC.pilot.SC_Script_Processor import *', \
>     'from SC.utils.SC_Convert import *', \
>     'import string ', \
>     'from SC.iso.SC_Dec_ISO import *', \
>     'from SC.iso.SC_Enc_ISO import *', \
>     'from SC.iso.SC_Analysis import *', \
>     'sc_sp = SC_Script_Processor ()', \
>     'sc_enc = SC_Enc_ISO ()', \
>     'sc_dec = SC_Dec_ISO ()', \
>     'sc_a = SC_Analysis ()', \
>     'sc_conv = SC_Convert()' ]
>   
>     __BC_EXEC_LIST = ['from SC.CARDS.BC import *','from
> SC.Solutions.SCF.BCInterface import *','sc_bc = BC_Interface()']
> 
> 
>       for l_s in self.__BC_EXEC_LIST: #this loop works fine
>         try:
>           exec (l_s, self.m_process_global,self.m_process_local)
>           
>         except:
>           traceback.print_exc()
> 
>       for l_s in self.__EXEC_LIST: #this loop works fine
>         try:
>           exec (l_s, self.m_process_global,self.m_process_local)
>           
>         except:
>           print >> sys.stderr, 'FATAL INIT ERROR - PLEASE CHECK YOUR
> CONFIGURATION'
> 
>         l = inspect.getmembers(eval('SC_Dec_ISO')) #THIS WORKS - the class
> exists
>         l = inspect.getmembers(eval('BC')) #THIS CRASHES - the class
>         exists




More information about the Python-list mailing list