Python-typeerror:object () takes no parameters

Source: Internet
Author: User

Error: Typeerror:object () takes no parameters

Where?

When you use a custom class, the instance class passes arguments, prompting for this error

Why?

Because of the class instance, no arguments are required, but the class parameter is given, essentially the class has no __init__ instance method, or the __init__ instance method does not declare any parameters to be received

The same?

Check if the __init__ function is incorrectly written, Init misspelled, or whether the parameter that needs to be initialized is passed in the __INIT__ function

Error code:

Class Student (object):    # init is wrong, written as int    def __int__ (self, student_list):        self.student_list = student_list    def __getitem__ (self, item):        return self.student_list[item]students = Student (["Beimenchuixue", "North gate Blowing Snow"])

Correct code:

Class Student (object):    # change int to init    def __init__ (self, student_list):        self.student_list = student_list< C3/>def __getitem__ (self, item):        return self.student_list[item]students = Student (["Beimenchuixue", "North gate Blowing Snow"])

  

Python-typeerror:object () takes no parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.