fork download
  1. class AddressBook:
  2.  
  3. def __init__(self):
  4. self.address_dict = {}
  5.  
  6. def __setitem__(self, key, value):
  7. self.address_dict[key] = value
  8.  
  9. def __getitem__(self, item):
  10. return self.address_dict[item]
  11.  
  12. def delete(self, name):
  13. del self.address_dict[name]
  14.  
  15. def save(self):
  16. with open('address_dict.txt', 'tw', encoding='utf-8') as a:
  17. for i in self.address_dict.keys():
  18. a.write(f'{i}: {self.address_dict[i]}' + '\n')
  19.  
  20. a = AddressBook()
  21. a['Vasya'] = 'Moskwa'
  22. a['Petya'] = 'Piter'
  23. a.delete('Vasya')
  24. a.save()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.5/py_compile.py", line 125, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "./prog.py", line 18
    a.write(f'{i}: {self.address_dict[i]}' + '\n')
                                         ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/py_compile.py", line 129, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 18
    a.write(f'{i}: {self.address_dict[i]}' + '\n')
                                         ^
SyntaxError: invalid syntax

stdout
Standard output is empty