Guest User

Untitled

a guest
May 25th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def search_it_all(profilesx, xname):
  2. f = open(profilesx, 'r')
  3. fileread = f.readlines()
  4. for line in fileread:
  5. line = line.replace("\n", "")
  6. x= line.split(",")
  7. name = x[0]
  8. age = x[1]
  9. gender = x[2]
  10. location = x[3]
  11. activities = x[4:]
  12. result.append(create_profile(name,age,gender,location,activities))
  13. for x in range (0, len(result)):
  14. if (result[x])["name"] == xname:
  15. print result[x]
  16. return result
  17. f.close()
  18.  
  19. #Kör sedan följande i tolken:
  20.  
  21. search_it_all("profilesx.txt", "mj") #och får följande felmeddelande:
  22.  
  23. Traceback (most recent call last):
  24. File "<pyshell#17>", line 1, in <module>
  25. search_it_all("profilesx.txt", "mj")
  26. File "E:\Plugg\Programmering grundkurs\Projekt\functions.py", line 66, in search_it_all
  27. if (result[x])["name"] == xname:
  28. TypeError: 'NoneType' object is not subscriptable
  29.  
  30. #Vad kan vara fel? :S
Add Comment
Please, Sign In to add comment