Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: list() takes at most 1 argument (3 given) for list class inheritance

Tags:

python

I searched other posts in stackoverflow and even copied them to try on my machine as answered. However, it keep failing throwing "TypeError"

# this is as one of other post in StackOverflow. 
class ListClass(list):
    def __init__(self, *args):
        super().__init__(self, *args)
        self.append('a')
        self.name = 'test'

I also tried empty class with pass. But, that also fails if I inherit and I guess I missed something instead of adding something more or wrong?

1) what is this "TypeError" and why? 2) how to fix it?

further snapshot on TypeError:

>>> class ListClass(list):
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list() takes at most 1 argument (3 given)  
like image 207
GoGo Avatar asked Jan 06 '23 21:01

GoGo


1 Answers

You are giving it to many paramerters when you create the ListClass object, this is what you are doing:

s = list(2,3,3)

This is what you shuold be doing:

s = list([2,3,3])

Try this snippets on you interpreter.

like image 59
wind85 Avatar answered Jan 08 '23 11:01

wind85