static? + some stuff

Daniel Schüle for_usenet2000 at yahoo.de
Mon Nov 3 12:03:48 EST 2003


Hi all

I have 2 questions
1)
is there a way do declare static variables in a class?
I coded this logic in global variable foo_cnt
2)
is there a way to see the types of all data/function members of a class?
dir(cls) returns a list of strings (of members) so it's logical that
type(tmp.i) fails ...
is it possible at all?

thanks for your time

--
Daniel


foo_cnt = 0        #<<<<<replace for static

class foo:
    a = b = None
    c = 0
    my_id = 0
    def __init__(self, c = 0):
        global foo_cnt
        foo_cnt+=1
        self.my_id = foo_cnt
        self.c = c
    def show(self):
        print self.a, self.b, self.c
    def move(self):
        print "ID = ", self.my_id, "\tc = ", self.c

print dir(foo)  #shows all member of 'foo'

x = foo(12)
y = foo(123)

print foo_cnt
x.show()
y.show()

def print_type_of_all_attr_of_class(cls):
    tmp = cls()
    attr = dir(cls)     #or dir(tmp)
    print attr
    for i in attr:None
        #print type(tmp.i)

print_type_of_all_attr_of_class(foo)






More information about the Python-list mailing list