problems with the types module

Manuel M. Garcia mgarcia at cole-switches.com
Wed Dec 11 16:47:27 EST 2002


On 11 Dec 2002 11:23:06 -0800, mis6 at pitt.edu (Michele Simionato)
wrote:
(edit)
>I couldn't find any correct assertion for the type of m !

I see you already have received pretty complete answers, but here is
your code with the correct 'assert' statement

~~~

import types

class C(object):
    def m(self,x): return x*x
    m=staticmethod(m)
    assert type(m) is staticmethod
    print 'type of m inside its class: %r' % (type(m))

assert type(C.m) is types.FunctionType
print 'type of C.m: %r', (type(C.m))

~~~

I agree with Carl Banks, the less type checking your Python code does,
the better.  Python has very fluid types and classes; methods and
attributes can be added to a class or an instance anytime during run
time.  The "Pythonic" thing to do is to press ahead without type
checking, catching any errors from missing attributes or methods with
"try: except:"

Manuel



More information about the Python-list mailing list