Trying to perfect my code step by step, prompting user in python for file -
for first part, prompt user name of file containing keywords, check make sure file exists , if not exist, program should generate exception , exit. have done part right?
done = false while not done: try: keywords = input("enter file named keywords.txt: ") infile = open(keywords, "r") done = true except ioerror : print("error: file not found.") exit() try: tweets = input("enter file named tweets.txt: ") infile = open(tweets, "r") done = true except ioerror : print("error: file not found.") exit() #should exit if doesnt exist? doesnt in assignment ignore #statement lol
ok. think should like:
try: file_path = input("enter file named keywords.txt: ") # don't call keywords, cause not open(file_path, "r") infile: #this open file , close when needed #do need file except ioerror : # catch exception if file not found print("error: file not found.") exit()
Comments
Post a Comment