2016-12-12 22 views
-1

私はAttributeErrorを取得し続けます。それはわかりません。助けていただければ幸いです。ここでAttributeError: 'module'オブジェクトに 'HourlyWorker'属性がありません

import worker 

def main(): 
    #Create a list to store employee and volunteer objects 
    workers = make_list() 

    #Display the objects in the list 
    print ('\n\nHere are the workers, their ID numbers, city of residence, shift, and pay.') 
    print ('--------------------------------------------------------------') 

    display_list(workers) 

def make_list(): 
    #Create an empty list 
    worker_list = [] 

    #Create a volunteer object 
    print ('Create a volunteer worker object:') 
    name = input('\nWhat is the employee name? ') 
    id_number = input("What is the employee's number? ") 
    city = input("What is the employee's city? ") 
    volunteerworker = worker.Person(name, id_number, city) 
    worker_list.append(volunteerworker) 

    #Create 3 hourly worker objects 
    print ('Create 3 hourly worker objects:') 
    for hourlyworkers in range(1,4): 
     name = input('\nWhat is the employee number ' + str(hourlyworkers + 1) + "'s name? ") 
     id_number = input("What is the employee's number? ") 
     city = input("What is the employee's city? ") 
     shift = input("What is the employee's shift? ") 
     #validate the shift entered is 1, 2, or 3 
     while shift != '1' and shift != '2' and shift != '3': 
      print('ERROR: the shift can only be 1, 2, or 3.') 
      shift = input('Please enter the correct shift: ') 

     pay_rate = float(input("What is the employee's hourly pay rate? ")) 
     hourlyworker = worker.HourlyWorker(name, id_number, city, shift, pay_rate) 
     worker_list.append(hourlyworker) 

    #create a salary worker object 
    print ('Create a volunteer worker object') 
    name = input("\nWhat is the salaried employee's name? ") 
    id_number = input("What is the employee's number? ") 
    city = input("WHat is the employee's city? ") 
    pay_rate = float(input("What is the employee's annual salary? ")) 
    salaryworker = worker.SalaryWorker(name, id_number, city, pay_rate) 
    worker_list.append(salaryworker) 

    #append invalid object to list 
    worker_list.append('\nThis is an invalid object') 

    return worker_list 

#This function accpets an object as an argument, and calls its show_employee 
#and show_pay methods 

def display_list(worker_list): 
    for person in worker_list: 
     if isinstance(person, worker.Person): 
      person.show_employee() 
      person.show_pay() 
      print() 
     else: 
      print('That is not a valid employee type!') 

main() 

worker.pyクラスPersonクラスHourlyWorker(者)のためのコードです:

PREMIUM2 = .05 
PREMIUM3 = .10 
PAY_PERIODS = 26 

class Person: 

    #The __init__ method initialized the attributes 
    def __init__(self, name, id_number, city): 
     self.__name = name 
     self.__id_number = id_number 
     self.__city = city 

    #This method accepts an argument for the person's name 
    def set_name(self, name): 
     self.__name = name 

    #This method accepts an argument for the person's ID number 
    def set_id_number(self, id_number): 
     self.__id_number = id_number 

    #This method accepts an argument for the person's city of residence 
    def set_city(self, city): 
     self.__city = city 

    #This method returns the employee's name 
    def get_name(self): 
     return self.__name 

    #This method returns the employee's number 
    def get_id_number(self): 
     return self.__id_number 

    #This method returns the employee's city of residence 
    def get_city(self): 
     return self.__city 

    #This method displays a message indicating the employee's name, ID, and city of residence 
    def show_employee(self): 
     print ('Employee name is', self.__name) 
     print ('Employee number is', self.__id_number) 
     print ('Employee city is', self.__city) 

    #This method displays a message about the volunteer's pay status 
    def show_pay(self): 
     print() 
     print ('This person is an unpaid volunteer.') 
     print() 

class Hourlyworker(Person): 

    #This method calls the superclass's init method and initializes shift and 
    #pay rate attributes 
    def __init__(self, name, id_number, city, shift, pay_rate): 
     Person.__init__(self, name, id_number, city) 
     self.__shift = shift 
     self.pay_rate = pay_rate 

    #This method calculates and displays the hourly and premium pay rate of a 
    #production employee 
    def show_pay(self): 
     print ('Employee shift is', self.__shift) 
     if self.__shift == '1': 
      premium_rate = self.__pay_rate 
     elif self.__shift == '2': 
      premium_rate = (PREMIUM2 * self.__pay_rate) + self.__pay_rate 
     else: 
      premium_rate = (PREMIUM3 * self.__pay_rate) + self.__pay_rate 
     print('Employee hourly premium rate is $', format(premium_rate, '.2f')) 

class SalaryWorker(Person): 

    #This method calls the superclass's init method and initializes the 
    #pay rate attribute 
    def __init__(self, name, id_number, city, pay_rate): 
     Person.__init__(self, name, id_number, city) 
     self.__pay_rate = pay_rate 

    #This method displays the annual salary and bi_weekly gross pay for the 
    #salaried employee 
    def show_pay(self): 
     print('Employee annual salary is $', format(self.__pay_rate, '.2f')) 
     bi_weekly_pay = float(self.__pay_rate)/PAY_PERIODS 
     print('Employee bi-weekly gross pay is $', format(bi_weekly_pay, '.2f')) 

これは私がウィングIDEで得続けるエラーです:

Traceback (most recent call last): 
    File "10.py", line 77, in <module> 
    main() 
    File "10.py", line 15, in <module> 
    workers = make_list() 
    File "10.py", line 48, in <module> 
    hourlyworker = worker.HourlyWorker(name, id_number, city, shift, pay_rate) 
builtins.AttributeError: 'module' object has no attribute 'HourlyWorker' 

感謝

+1

Typo dude!あなたのケースを確認してください... – Julien

+0

shiiiiiiiiiiiiiiiiiiiiiiiit。ありがとう男 – Alex

答えて

1

あなたはHourlyworkerという名前のクラスを実装していて、クラス名はHourlyWorker? Pythonがobject has no attributeと言っているときは、実際にそれを意味します;)

ヒント、ちょっとした場合:Pythonは大文字と小文字を区別します。

+0

ありがとうございます。私はばかです。 – Alex

+0

@Alexは日曜の夜はあまりにも難しいと判断しない;) – Art

関連する問題