Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def write_file():
  2. print("Writing a file..")
  3. try:
  4. f = open("my_file.txt", "a")
  5. for num in range(100):
  6. f.write("Line " + str(num) + "\n")
  7. f.close()
  8. except Exception:
  9. print("Could not write to file")
  10.  
  11.  
  12. def read_file():
  13. print("Now reading the file..")
  14. try:
  15. f = open("my_file.txt", "r")
  16. for line in f.readlines():
  17. print(line)
  18. f.close()
  19. except Exception:
  20. print("Could not read to file")
  21.  
  22.  
  23. write_file()
  24.  
  25. read_file()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement