"Jason R. Mastaler" <[EMAIL PROTECTED]> writes:

> "Jason R. Mastaler" <[EMAIL PROTECTED]> writes:
>
> I looked at this briefly tonight.  There appears to be no sexy way to
> do this that I can think of.  Mainly because Python doesn't like the
> idea of vars() being monkeyed with.  According to the documentation[1]
> for vars():
>
>   vars([object]) 
>       Without arguments, return a dictionary corresponding to the
>       current local symbol table. With a module, class or class
>       instance object as argument (or anything else that has a
>       __dict__ attribute), returns a dictionary corresponding to the
>       object's symbol table. The returned dictionary should not be
>       modified: the effects on the corresponding symbol table are
>       undefined.
>
> Thus, even something like the following at the end of Defaults.py
> blows up with a RuntimeError:
>
>   for k,v in vars().iteritems():
>       if isinstance(v, str):
>           print '%s = %s' % (k,v)

I just looked at this (although I used globals() instead of vars(), to
guarantee I got the module-level variables).

Using the code above I get

  RuntimeError: dictionary changed size during iteration

Why that is, I have no idea, but changing the code to use the standard
dictionary iterator 'items()' instead of the new, apparently wacky,
'iteritems()' works perfectly.

    for k,v in globals().items():
        print "%s = %s" % (k, v)

I haven't bothered to track down why this is, but I did want to note
it.


Tim

_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers

Reply via email to