I'm trying to write a Python 2.7 function that will allow me to type in the name of text file into the pre-made GUI which will open the text file and then pass on the file name as the base for other functions (i.e. count characters) to read that file. I wrote the function before I was given the GUI and now I'm having issue with global variable.
def OpenFile(filename):
try:
rfile = open(filename, "r") #please type the file as a string
except IOError:
print ("File Not Found")
else:
print ("File Opened")
This is what I wrote and I'm not sure where to go from there cause the function is supposed to open the file and prints either of the messages accordingly. I've been trying to find the solution but I'm really struggling.