Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Controlling Conversion

getting error __init__() takes 1 positional argument but two were given

here's my numstring code

class NumString:
    def __init__(self, value):
        self.value = str(value)

    def __str__(self):
        return self.value

    def __init__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

Then in shell I run:

five = NumString(5)

And I get

Traceback (most recent call last):                                                                            
  File "<stdin>", line 1, in <module>                                                                         
TypeError: __init__() takes 1 positional argument but 2 were given 

Can't figure out why

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

Why do you have a second __init__() defined? It doesn't have any parameters defined (besides self) - don't you want to remove that method?

1 Answer

Bc Im an idiot. It's supposed to be int()