Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> class A(object):
- def __init__(self, **kwargs):
- for key, value in kwargs.items():
- setattr(self, key, value)
- def method(self):
- print(self.__dict__)
- >>> a = A(x=1, y=2)
- >>> a.method()
- {'a': 1, 'b': 2}
- >>> a = A(x=1, y=2, method="blah")
- >>> a.method()
- Traceback (most recent call last):
- File "/python3.5/site-packages/IPython/core/interactiveshell.py", line 281, in run_code
- exec(code_obj, self.user_global_ns, self.user_ns)
- File "<ipython-input-29-76ebeb9909f4>", line 1, in <module>
- a.method()
- TypeError: 'str' object is not callable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement