Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os.path
- import sys
- read_or_write = str(input("Read or Write? (read/write)"))
- exist_or_not = 0
- if read_or_write == "read":
- which_one = str(input("Which file would you like to read?"))
- exist_or_not = os.path.exists(which_one)
- if exist_or_not == True:
- with open(which_one, "r") as f:
- reader = f.read()
- print(reader)
- elif exist_or_not == False:
- build_or_not = str(input("There is no said file, wanna build? (build/no)"))
- if build_or_not == "build":
- what_name = str(input("What would you like to name it? "))
- open(what_name, 'a').close()
- elif build_or_not == "no":
- print("Goodbye! ")
- sys.exit()
- elif read_or_write == "write":
- which_one = str(input("Which file would you like to overwrite? "))
- exist_or_not = os.path.exists(which_one)
- if exist_or_not == True:
- thing_to_write = str(input("What would you like to write?"))
- with open(which_one, "w") as f:
- writer = f.write(thing_to_write)
- print("This is what you wrote in the file: " + str(thing_to_write))
- elif exist_or_not == False:
- build_or_not = str(input("There is no said file, wanna build? (build/no)"))
- if build_or_not == "build":
- what_name = str(input("What would you like to name it? "))
- open(what_name, 'a').close()
- elif build_or_not == "no":
- print("Goodbye! ")
- sys.exit()
Add Comment
Please, Sign In to add comment