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
5/31/2018 9:26:14 PMNIMA
4 AnswersNew Answer
You have to save the txt-file e.g. with filename text.txt . And then you have to put "text.txt" as function parameter in the print()-function, instead of 'train1' as you did.
i guess you should put txt name as string as function parameter. ”train1.txt” - that is just example.
I replaced train1 with 'train1.txt' but received this ERROR: SyntaxError: invalid syntax Revised Code: https://code.sololearn.com/cy7H37OiPO73/#py
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.