I am trying to make a program that involves the user opening a file in python. Here is the relevant code:
def fileopen():
source = input("Enter the name of the source file (w/ extension): ")
f = open("%s" %source, "r") #open the file
filelist = f.read()
f.close()
print(filelist)
encrypt(filelist)
this is resulting in the following error:
Enter the name of the source file (w/ extension): source
Traceback (most recent call last):
File "C:\Python27\Encrypt\Encrypt.py", line 27, in <module>
fileopen()
File "C:\Python27\Encrypt\Encrypt.py", line 2, in fileopen
source = input("Enter the name of the source file (w/ extension): ")
File "<string>", line 1, in <module>
NameError: name 'source' is not defined
>>>
It was working when I was leaving it set as a static file (ex. source.txt) but I need to be able to select the file to use.