Guest User

Untitled

a guest
Jul 6th, 2020
26
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Employee():
  2.     def __init__(self, first_name, last_name, salary):
  3.         self.first_name = first_name
  4.         self.last_name = last_name
  5.         self.salary = salary
  6.        
  7.     @classmethod
  8.     def from_string(cls, string):
  9.         cls.string = string = string.replace("-", ", ")
  10.         cls.string = string = string.split(" ")
  11.         cls.first_name = string[0]
  12.         cls.last_name = string[1]
  13.         cls.salary = string[2]
  14.  
  15.  
  16. """
  17. first_name = "Klaus"
  18. last_name = "Mikealson"
  19. salary = 2000
  20. emp1 = Employee(first_name, last_name, salary)
  21. вот это работает
  22. """
  23.  
  24. """
  25. emp2 = Employee.from_string("frist_name-last_name-salary")
  26. А вот эта фигня не работает.
  27.  
  28. Ошибка где-то
  29. Traceback (most recent call last):
  30.  File "<pyshell#54>", line 1, in <module>
  31.    emp2.first_name
  32. AttributeError: 'NoneType' object has no attribute 'first_name'
  33.  
  34. Помогите пожалуйста
  35. """
RAW Paste Data