Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person:
- def __new__(cls, first, last):
- print("Calling __new__() method of class {}".format(cls))
- return object.__new__(cls, first, last)
- def __init__(self, first, last):
- """Constructor of Person working instance
- (attribute initialization)"""
- print("Calling __init__()")
- self.first = first
- self.last = last
- self.age = 23
- self.residency = "Lyon"
- def __repr__(self):
- return "Person : {} {} aged {} years living in {}".format(self.first, self.last, self.age, self.residency)
- person = Person("Doe", "John")
- print(person)
- Calling __new__() method of class <class '__main__.Person'>
- Traceback (most recent call last):
- File "test.py", line 20, in <module>
- person = Person("Doe", "John")
- File "test.py", line 6, in __new__
- return object.__new__(cls, first, last)
- TypeError: object() takes no parameters
Add Comment
Please, Sign In to add comment