Nov-13-2017, 02:10 PM
If you are really struggling, you need to break this down into simple steps.
You have the basic bones of the programme (although it is hard to check the formatting is correct as it is not pasted in correctly and has lost indentation, which is CRITICAL in Python).
Assuming you have the first part like this:
Why not just write the code to output to the screen the file you have opened, just to make sure of that bit.
(Incidentally, calling the function open_file() from within itself, line 7, is called recursion and is probably not the right choice here. Would be better to have a loop that keeps going until a file has been opened.)
You have the basic bones of the programme (although it is hard to check the formatting is correct as it is not pasted in correctly and has lost indentation, which is CRITICAL in Python).
Assuming you have the first part like this:
def open_file(): filename = input("Input a file name: ") # Prompt for file name, open file, return file pointer try: fp = open(filename) # Opens filename if found and throws exception if not found except FileNotFoundError: print("Unable to open file. Please try again.") fp = open_file() except: print("Error: Unknown, Please try again...") return fp # Returns the filethe file should open correctly.
Why not just write the code to output to the screen the file you have opened, just to make sure of that bit.
(Incidentally, calling the function open_file() from within itself, line 7, is called recursion and is probably not the right choice here. Would be better to have a loop that keeps going until a file has been opened.)
I am trying to help you, really, even if it doesn't always seem that way