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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![bdi](https://secure.gravatar.com/avatar/1f9323c6d078fa87a9a9df4074cfd791?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
bdi
8,377 Pointsunsure why im getting this error: TypeError: descriptor '__init__' of 'list' object needs an argument
class Liar(list):
def __init__(self, *args, **kwargs):
self = list.__init__(*args, **kwargs)
return self
def __len__(self):
liar_len = super().__len__()+2
return liar_len
class Liar(list):
def __init__(self, *args, **kwargs):
self = list.__init__(*args, **kwargs)
return self
def __len__(self):
liar_len = super().__len__()+2
return liar_len
[MOD: fixed ```python formatting -cf]
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsYour explicit call to list.__init__
is missing the self argument. But you don't need to override __init__
at all here, simply redefine __len__
:
class Liar(list):
def __len__(self):
liar_len = super().__len__() + 2
return liar_len
Chris Freeman
Treehouse Moderator 68,425 PointsChris Freeman
Treehouse Moderator 68,425 Pointsbdi, as an aside to Steve’s answer, there are two ways to call the base class’s
__init__
method, if you really needed to. This explanation might be too advanced for now. Bookmark and come back later after covering inheritance, class methods, andsuper()
.The preferred method is to use
super()
. It understands accessing the parent classes and calls a bound version (self predefined) of the method of the parent class (this is why “self” is not needed).This other way is to call the
__init__
method of the parent class directly. This is viewed as less “Pythonic”. When calling this class method, the method is “unbound” to an instance and has no value for “self”, so theself
of the current instance must be provided in the call.These are both show below:
Post back if you have more questions. Good luck!!!
bdi
8,377 Pointsbdi
8,377 PointsGreat, thank you