As you are reading lines from a file, you are getting the trailing new line character \n
. You can see this in the Traceback that you posted and I assume that this is where the problem is coming from.
Use .strip()
to remove unwanted white space and new line characters before trying to open the file. You may also have to provide the full path to the file you wish to work on rather than just the file name.