fork download
  1. from collections import UserList
  2.  
  3.  
  4. class EstSpisok(UserList):
  5. # Нужно, чтобы он записывался в txt фаил
  6. def to_file(self, filename='estspisok'):
  7. with open(str(filename) + '.txt', 'w') as f:
  8. f.write(self.__repr__())
  9.  
  10. # При вызове выводилось что-то вроде
  11. def __call__(self):
  12. print(self)
  13.  
  14. def __repr__(self):
  15. repr = ''
  16. for num, value in enumerate(self.data):
  17. repr += '{}. {} - {}\n'.format(num, *value)
  18. return repr
  19.  
  20. spisok = EstSpisok()
  21. spisok.append(['OP', 'huy'])
  22. spisok.append(['Abu', 'ohuel'])
  23. spisok()
  24. spisok.to_file()
  25.  
Runtime error #stdin #stdout #stderr 0.02s 10248KB
stdin
Standard input is empty
stdout
0. OP - huy
1. Abu - ohuel

stderr
Traceback (most recent call last):
  File "./prog.py", line 24, in <module>
  File "./prog.py", line 7, in to_file
PermissionError: [Errno 13] Permission denied: 'estspisok.txt'