spir wrote:
Hello pyhonistas,

Example:
=== module content ===
a = 1
b = 2
======================

I'm looking for a way to get something like {'a':a, b':2}.

Maybe this will get you started:

[EMAIL PROTECTED] root]# cat > testmod.py
a=1
b=2
[EMAIL PROTECTED] root]# python
Python 2.5 (r25:51908, Nov  1 2006, 15:36:22)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import testmod
>>> dir(testmod)
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'b']
>>> D=dict([(varname,getattr(testmod,varname))
        for varname in dir(testmod)
        if not varname.startswith("_") ])
>>> D
{'a': 1, 'b': 2}
>>>

HTH,

Emile


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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to