Re: Big problem fetching members from dynamically loaded module



> My French is mostly read-only, so let me rephrase:
Thank you :-)

> from module import *, try ... except, eval(), exec all work together to
> make your program harder to understand and more likely to fail in obscure
> ways.
What would you suggest then, I just want my code to
1) be sturdy
2) some of the modules might not be there depending on the configuration,
and I want their members in the menus if they are installed.

If there is a cleaner way, I'm ready to try it.


> eval("BC", self.m_process_global, self.m_process_local)
>
> to ensure that eval() and exec share the same namespace.
> Generally speaking, I would prefer (I hope I got that right)

That was it, thank you!

>
> module = __import__("package.module", globals(), locals(), ["module"])
> members = inspect.getmembers(module)
>
> Members of the module would then be accessed via getattr():
>
> member = getattr(module, member_name)
>
I will study that.


Many thanks

Philippe



Peter Otten wrote:

> Philippe C. Martin wrote:
>
>> 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 ;-)
>
> My French is mostly read-only, so let me rephrase:
>
> from module import *, try ... except, eval(), exec all work together to
> make your program harder to understand and more likely to fail in obscure
> ways.
>
>>> 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
>
> That traceback and the code you posted do not fit together. So back to
> square one.
>
> Staring at the code you posted, I think one thing you could try would be
> to modify the eval() to
>
> eval("BC", self.m_process_global, self.m_process_local)
>
> to ensure that eval() and exec share the same namespace.
> Generally speaking, I would prefer (I hope I got that right)
>
> module = __import__("package.module", globals(), locals(), ["module"])
> members = inspect.getmembers(module)
>
> Members of the module would then be accessed via getattr():
>
> member = getattr(module, member_name)
>
> Peter

.



Relevant Pages

  • Re: how does an exec meeting work?
    ... The exec should be very very keen on you attending. ... The Group Scout Council is the electoral body, ... Group Scout Fellowship members; ... the maintenance of the Group's property and equipment; ...
    (uk.rec.scouting)
  • Re: problems with leaders - advice appreciated
    ... >>> Go check your constitution regarding the position of your Exec members. ... The chairman has no more say in fiscal matters than ... I do believe it because that is how an effective committee works. ...
    (uk.rec.scouting)
  • Re: If you could....
    ... up nominations each year who are preferably not uniformed members. ... In the past we had a large exec too. ... to ask for nominations from Groups - I think that stopped a long time ago. ... many and it was getting like a leaders meeting with too much of that being ...
    (uk.rec.scouting)
  • Re: If you could....
    ... We have a fairly large exec. ... The more non-uniformed members the better and all the ADC's attend as well but we stick to the agenda and have separate ADC meetings so that the Exec can focus. ...
    (uk.rec.scouting)
  • Re: Authenticate to GAL but hide membership?
    ... Creating a GAL with no users will still fail as you have to have at least ... one or the Outlook client will fail with a INVALID_BOOKMARK error. ... authenticate to a default GAL but *not* be able to see the other members ...
    (microsoft.public.exchange.applications)