关于对象的 Python 属性错误

如何解决关于对象的 Python 属性错误

嘿,我正在努力提高 Python 方面的能力并决定去上课。我运行代码,它一直运行到它调用对象Employees。它给了我一个属性错误:类型对象“员工”没有属性“HourlyAssociate”。谁能帮我吗。我四处寻找修复方法并尝试了一些方法,但我遇到了障碍。

class Employees:
   
   def __init__(self,name):
        self.name = name
    
        def setName(self,name):
            self.name = name

            def getName(self):
                return self.name

class SalariedEmployee(Employees):


    def __init__(self,name,rate,monthly):
        rate.monthly = monthly
        Employees.__init__(self,name)
    

        def setMonthly(rate,monthly):
            rate.monthly = monthly 

            def getMonthly(rate,monthly):
                return rate.monthly

class HourlyEmployee(Employees):

    def __init__(self,hourly,time,hours):
        rate.hourly= hourly
        Employees.__init__(self,name)
    
        def setHourly(rate,hourly):
            rate.hourly = hourly 

            def getHourly(rate):
                return rate.hourly
   
                def setHours(time,hours):
                    time.hours = hours

                    def getHours(time,hours):
                        time.hours = hours

import Employee

#main function
def main():

   associates=AssociateList()

   print('All associates hired for the company: ')
   display_associates(associates)
#function for user input,and storing in the objects created. Then store in the array
def AssociateList():

    #an empty array for employee data
    associate_list = []

    # Input to get the number of employee's date the user will be entering in
    numOfAssociates = int(input('How many workers hired today? '))

    #loop for input for each employee

    for num in range(numOfAssociates):

        #input data
        name = input('Enter the name of the worker: ')
        answer = str(input('Enter if associate is hourly or salary: '))

        if answer == ('hourly'):
            hours = int(input('Enter the amount of hours: '))
            hourly = float(input('Enter the hourly rate: '))
        else:
            monthlyRate = int(input('Enter the monthly rate: '))
        print()

        associates = Employees.HourlyAssociate(name,hours,hourly)
        associates = Employees.SalaryAssociate(name,monthlyRate)
        
        associate_list.append(associate)

        return associate_list

    def display_associate(associate_list):
        for associate in associate_list:
            print('Name:',associate.get_name())
            print('Hourly rate: $',associate.get_Hourlyrate())
            print('Hours worked: ',associate.get_Hours())
            print()

#calls the main function
main()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?