I want to create new methods for str
datatype. Here's what I tried
class str(str):
def __init__(self) -> None:
super().__init__()
def work(self):
# Just for testing
print("works")
Here, when I initialize strings using str()
this works but wrapping them around simple quotation this raises the error AttributeError: 'str' object has no attribute 'work'
Like this:
b = str("Hello world")
b.work()
Works as intended with stdout "works"
but,
a = "Hello world"
a.work()
Raises AttributeError: 'str' object has no attribute 'work'
I want to create new methods such that they work with these cases :
"foo".work()
str("foo").work() # <- This actually works :D
bar = "foo"; bar.work()
Thanks for the help.