Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import os.path
  2. import sys
  3.  
  4. read_or_write = str(input("Read or Write? (read/write)"))
  5. exist_or_not = 0
  6.  
  7. if read_or_write == "read":
  8.  
  9. which_one = str(input("Which file would you like to read?"))
  10. exist_or_not = os.path.exists(which_one)
  11.  
  12. if exist_or_not == True:
  13. with open(which_one, "r") as f:
  14. reader = f.read()
  15.  
  16. print(reader)
  17. elif exist_or_not == False:
  18. build_or_not = str(input("There is no said file, wanna build? (build/no)"))
  19.  
  20. if build_or_not == "build":
  21. what_name = str(input("What would you like to name it? "))
  22. open(what_name, 'a').close()
  23.  
  24. elif build_or_not == "no":
  25. print("Goodbye! ")
  26. sys.exit()
  27.  
  28.  
  29. elif read_or_write == "write":
  30. which_one = str(input("Which file would you like to overwrite? "))
  31. exist_or_not = os.path.exists(which_one)
  32.  
  33. if exist_or_not == True:
  34. thing_to_write = str(input("What would you like to write?"))
  35. with open(which_one, "w") as f:
  36. writer = f.write(thing_to_write)
  37.  
  38. print("This is what you wrote in the file: " + str(thing_to_write))
  39. elif exist_or_not == False:
  40. build_or_not = str(input("There is no said file, wanna build? (build/no)"))
  41.  
  42. if build_or_not == "build":
  43. what_name = str(input("What would you like to name it? "))
  44. open(what_name, 'a').close()
  45.  
  46. elif build_or_not == "no":
  47. print("Goodbye! ")
  48. sys.exit()
Add Comment
Please, Sign In to add comment