I am transitioning from Java to Python and am currently stumped with this seemingly simple code whose Java equivalent works just fine.
I am trying to create an object called TestClass that either takes one argument called text or no arguments; in which case a default string "foo" is assigned to the text instance variable.
class TestClass(object):
def __init__(self):
self.text = "foo"
def __init__(self, text):
self.text = text
a = TestClass()
b = TestClass("bar")
I really am unable to pinpoint the issue and get the following error:
a = TestClass()
TypeError: init() missing 1 required positional argument: 'text
Your help would be appreciated, Thank you!