[Tutor] [Fwd: Re: get a module's own (top_level) dict?]

spir denis.spir at free.fr
Mon Nov 10 10:25:58 CET 2008

(forwarded to the list)

>> Hello pyhonistas,
>> Example:
>> === module content ===
>> a = 1
>> b = 2
>> ======================
>> I'm looking for a way to get something like {'a':a, b':2}. Actually,
>> names defind in the module will be instances of a custom type. I want to
>> give them an attribute that holds their own name. E.g.: for key,obj in
>> dict:
>> 	obj.name = key

Thank you Lie & Kent, that's it. Excuse me, Lie, I answered too fast.
Now, to answer Kent questions, there are several reasons why I wish to do that.
These objects will be of a 'pattern' type that (unlike function, for instance),
don't know how they're called. They need to hold their name to pass it to
further objects (say, tokens) that will be generated according to these
patterns, but who are not instances of the patterns. Actually, the pattern's
name is a kind of token 'type'. You see what I mean?
Concretely, I need to instanciate object with a type specified by the pattern's
name and init data given by the result of the parsing.
Also, I want to write the pattern --> name --> type --> object toolset in a
general to be able to reuse it. Also, simply because I want it so!
There will be many such names, too.
Also: the patterns will actually be generated at runtime according to a config
file -- and can also change at runtime (--> reload() grammar module), following
user customization. So that I don't even know the names at design time.


More information about the Tutor mailing list