+ 1
Please help, the code doesn't work
The goal of this code is Opening and Reading a TXT file line by line and show its content like this: ['Lucas,Turing,22', 'Alan,Williams,27', 'Layla,Trinh,21', 'Brayden,Huang,22', 'Oliver,Greek,20'] The TXT file content is: Lucas,Turing,22 Alan,Williams,27 Layla,Trinh,21 Brayden,Huang,22 Oliver,Greek,20 The code is: https://code.sololearn.com/cWgo9cAwWmLs/#py ERROR: NameError: name 'train1' is not defined
3 Respostas
+ 2
i guess you should put txt name as string as function parameter. ”train1.txt” - that is just example.
0
I replaced train1 with 'train1.txt' but received this ERROR:
SyntaxError: invalid syntax
Revised Code:
https://code.sololearn.com/cy7H37OiPO73/#py
0
In the definition of the function you have to use a variable as parameter, not a string. This parameter could you use in the open function. But what you want will not work, because the code will be executed on the server and there is not your file. So you could try to write the file in your code and then try to open that file.