-1

Hi I am having a problem with a code I wrote. I am trying to make a class and import it to another file but a error keeps coming up. Here is my code:

File1 (With class):

class Employee:

    def __init__(self, Number, employeeName, Address, Wage, Time):
        self.Staff = self
        self.employeeNum = Number
        self.Name = employeeName
        self._Address = Address
        self.Wage = Wage
        self.workTime = Time

    def getInfo():
        return(_employeeNum,__Address)

    def setInfo(newNumber):
        if newNumber > 6:
            self._employeeNum = newNumber

File2(Importing class):

from Project7 import Employee as e

Emp1 = e.__init__("Employee", "6765", "John", "123 Baker Street", 13.00, 15)

print(Employee)
print(Emp1) 

I am not sure what is happening and any info would be really helpful! Thanks in advance!

Kafels
  • 3,864
  • 1
  • 15
  • 32
liil
  • 37
  • 4
  • try to remove self.Staff = self . self is the object, what is the pourpose of your code on that part? Also on getInfo() and setInfo() should go to self.variables – Wonka May 08 '19 at 15:48
  • get_info needs self in both the definition and the return for the variables. set info needs it in the definition. – Stael May 08 '19 at 15:54
  • also your constructor for employee is being passed "Employee" in the place of Number etc. – Stael May 08 '19 at 15:56

1 Answers1

0

You do not have to explicitly call __init__ method.

You can simply run:

Emp1 = e("Employee", "6765", "John", "123 Baker Street", 13.00, 15)

then, you renamed Employee class as "e": so print(Employee) will raise an error, because name "Employee" does not exist.

I also suggest to follow Python conventions for naming classes and variables: Capital for classes lowercase for variables

from Project7 import Employee

emp1 = Employee("Employee", "6765", "John", "123 Baker Street", 13.00, 15)
Don
  • 16,928
  • 12
  • 63
  • 101