Please help, the code doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

31st May 2018, 9:26 PM
NIMA
NIMA - avatar
3 Answers
+ 2
i guess you should put txt name as string as function parameter. ”train1.txt” - that is just example.
31st May 2018, 9:34 PM
Eterxoz
Eterxoz - avatar
0
I replaced train1 with 'train1.txt' but received this ERROR: SyntaxError: invalid syntax Revised Code: https://code.sololearn.com/cy7H37OiPO73/#py
1st Jun 2018, 5:50 AM
NIMA
NIMA - avatar
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.
1st Jun 2018, 9:04 PM
Manuel Maier
Manuel Maier - avatar