0

Searching words in a specific field inside a file using readline

I would like to created a list with the first five fields and another 6 fields starting at the 20th collun of each line of a text file. Can I use this code or maybe there is another easier way? For line in file: Line = readline() Field1=line[:6] Field2=line[20:27]

5th Jul 2020, 5:00 AM
Ricardo
2 Respostas
+ 4
You forgot to open file. Without it, it won't work. And python is case-sensitive language. So, "line" and "Line" are two different variables.... This code will give you exception (error)..
5th Jul 2020, 5:10 AM
Arctic Fox
Arctic Fox - avatar
0
Yes thanks. But is there another pythonic idea to create the variables Field1 and Field2 ?
5th Jul 2020, 11:25 AM
Ricardo