in python3, how can i change this to work? ``` def GetInputFileName(inFile): filename = eval(input('Enter your input file name: ')) inFile = open(filename,'r') return filename ``` I need it to ask for input of a filename to collect data from.
do you think the issue is related to the method, or how you got the user input?
not sure, i get an error. hold on
error message: ``` Traceback (most recent call last): File "C:/Users/nicholas/Desktop/CMPS 150/Programming Assignments/Programming Assignment 6.py", line 10, in <module> main() File "C:/Users/nicholas/Desktop/CMPS 150/Programming Assignments/Programming Assignment 6.py", line 7, in main filename = eval(input('Enter your input file name: ')) File "<string>", line 1, in <module> NameError: name 'pa6' is not defined ``` the file provided as an example is 'pa6.sales'
I'm not quite sure, I am a java guy.. for what it's worth, I'll make a java version; public static String GetInputFileName() { Scanner scan = new Scanner(System.in); System.out.println("Enter the file name: "); String file = scan.nextLine(); return file; }
if you have a means of debugging, it might help going step-by-step to see if the error occurs in that method, or after you return the file name. - to help pinpoint the error
thanks woodrow, gonna take a break and go for a walk and get back at it in a bit ill take your advice adn try that
Join our real-time social learning platform and learn together with your friends!