Snippets

Ryan Attard Type Inspection is weird

You are viewing an old version of this snippet. View the current version.
Revised by Juliette Attard 691b580
class Foo(object):
    def __init__(self, **kwargs):
        self.__attr = kwargs.get('attr', None)
    @property
    def attr(self):
        return self.__attr

    @attr.setter
    def attr(self, attr):
        self.__attr = attr


class Bar(Foo):
    def __init__(self, **kwargs):
        super(Bar, self).__init__(**kwargs)


if __name__ == '__main__':
   b= Bar(attr="Hello, world")
   print b.attr
   for key in b.__class__.__dict__:
       print type(b.__class__.__dict__[key])

"""
Returns:
rattard@rattard-T3500:~/Downloads$ python test_classes.py 
Hello, world
<type 'str'>
<type 'NoneType'>
<type 'function'>
"""
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.