Variable interpolation question

Andrew Fabbro andrew-wants-no-spam at fabbro.org
Mon Nov 17 18:43:16 CET 2003


This is probably a beginner's question, but I'm stuck...please be kind
to an ex-perler ;)

How do I do something like this:

for attr in dir(some_obj):
  if ( some_obj.attr == 0 ):
    print "Missing data: %s field %s" % ( some_obj.name,
some_obj.attr)

Of course, this gives 
"AttributeError: foo instance has no attribute 'attr'"

I really don't want to use exec/eval, as that slows things down
dramatically.

Help?

Thanks.

-Drew




More information about the Python-list mailing list