Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Wrap(str):
- def custom_interface(self):
- pass
- class Wrap(object):
- def __init__(self, value):
- """initiate with a str
- """
- self._value = value
- def custom_interface(self):
- pass
- >>> w = Wrap('foo') # wrap any `str`
- >>> type(w)
- <class 'Wrap'>
- >>> t = w * 2 # use a `str` operator on `Wrap`
- >>> t
- 'foofoo'
- >>> type(w * 2)
- <class 'Wrap'>
- >>> j = Wrap('.').join(['b', 'a', 'r']) # use `str` interface on `Wrap`
- >>> j
- 'b.a.r'
- >>> type(j)
- <class 'Wrap'>
- >>> j.custom_interface() # and still enjoy dedicated interface
Add Comment
Please, Sign In to add comment