Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Var:
- def __init__(self, obj=None):
- self.obj=obj
- def __getattr__(self, attr):
- return getattr(self.obj, attr)
- v1 = Var([1,2,3])
- print(v1.__len__())
- # output: 3
- print(len(v1))
- # output: TypeError: object of type 'Var' has no len()
- class Var:
- def __init__(self, obj=None):
- self.obj=obj
- def __getattr__(self, attr):
- return getattr(self.obj, attr)
- def __len__(self):
- return len(self.obj)
- v1 = Var([1,2,3])
- print(v1.__len__())
- print(len(v1))
- pawel@pawel-XPS-15-9570:~/test$ python len.py
- 3
- 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement