fork download
  1. from itertools import chain
  2.  
  3. def insert_file(filename):
  4. with open(filename, "w") as file:
  5. matrix = []
  6. for i in range(2):
  7. row = []
  8. for j in range(2):
  9. row.append(raw_input())
  10. matrix.append(row)
  11. file.write("\n".join(chain(*matrix)))
  12.  
  13. def read_file(filename):
  14. with open(filename, "r") as file:
  15. matrix = []
  16. for i in range(2):
  17. row = []
  18. for j in range(2):
  19. row.append(int(file.readline().strip()))
  20. matrix.append(row)
  21. return matrix
  22.  
  23. insert_file("data.txt")
  24. data = read_file("data.txt")
  25.  
  26. print(data)
Runtime error #stdin #stdout #stderr 0s 23352KB
stdin
1
2
3
4
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 23, in <module>
  File "prog.py", line 4, in insert_file
IOError: [Errno 13] Permission denied: 'data.txt'