TypeError: object() takes no parameters Python 报错解决方案
在初学python学习类的使用的时候一个常犯的错误就是:
Employee.py文件为:
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 26 19:34:39 2019
@author: qzh
"""
class Employee:
empCount = 0
def __init__(self,name,salary):
self.name = name
self.salary = salary
Employee.empCount+=1
def displayCount(self):
print("Total Employee %d" % Employee.empCount)
def displayEmployee(self):
print("Name:", self.name,"Salary:",self.salary)
test2.py文件为:
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 26 19:39:59 2019
@author: qzh
"""
import Employee
emp1=Employee.Employee("1",123)
一定要注意啊:构造函数__init__是两个下划线,共4个下划线