Advertisement
Guest User

Untitled

a guest
Dec 29th, 2018
229
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None
  1. class Programmers:
  2.     def __init__(self, number, name, project, company):
  3.         self.name = name
  4.         self.project = project
  5.         self.company = company
  6.         self.number = number
  7.  
  8.     def __repr__(self):
  9.         return f"({self.number}, {self.name}, {self.project}, {self.company})"
  10.  
  11. proger_1 = Programmers("1", "John Carmack", "DOOM 3", "id Software")
  12. proger_2 = Programmers("3", "Tim Sweeney", "Unreal Engine", "Epic Games")
  13. proger_3 = Programmers("2", "Guido van Rossum", "Python", "Dropbox")
  14.  
  15. gods = [proger_1, proger_2, proger_3]
  16.  
  17. myAttrib = attrgetter('name')
  18.  
  19. print(myAttrib(gods))
  20.  
  21. # ERROR:
  22. # AttributeError: 'list' object has no attribute 'name'
Advertisement
RAW Paste Data Copied
Advertisement