Skip to content

Instantly share code, notes, and snippets.

@KatiGithub
Created July 16, 2018 10:26
Show Gist options
  • Save KatiGithub/b5aee4c7808b005fad539f994bf8c9b8 to your computer and use it in GitHub Desktop.
Save KatiGithub/b5aee4c7808b005fad539f994bf8c9b8 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment