Accessing class instance variables with vars().

Arcady Genkin agenkin at thpoon.com
Tue Feb 4 21:34:08 EST 2003


How would I make the following code print both class variable 'foo'
and the local variable 'bar' through a variable mapping?

class A:
    foo = 1
    def show( self ):
        bar = 2
        print '%(foo)d %(bar)d' % vars(self)

This does not work since vars(self) returns an empty dictionary.

Many thanks in advance,
-- 
Arcady Genkin

guilt is the cause of more disauders
than history's most obscene marorders (E.E. Cummings)




More information about the Python-list mailing list