arrays - Python ValueError -


so keep receiving error:

valueerror: mixing iteration , read methods lose data

and 1) don't quite understand why i'm receiving it, , 2) people similar problems seem doing things code more complex beginner (like myself) can adapt with.

the idea of code read data_file.txt , convert each line own individual array.

so far have this:

    array = [] #declaring list name '**array**'      open('file.txt','r') input_file:     line in input_file:         line = input_file.readlines()         array.append(line)         print('done 1') #for test purposes         return array 

and keep recieving error.

"value error: mixing iteration , read methods lose data "message while extracting numbers string .txt file using python

the above question seemed doing similar, calling in items array, code skipping lines , using range call in parts of it, don't need that. need call in lines , have them made array.

python: mixing files , loops

in question, once again, more can understand being asked. understood, wanted code restart after error , continue, , answers part. once again not i'm looking for.

the error pretty self-explanatory (once know about), here goes.

you start loop for line in input_file:. file objects iterable in python. iterate on lines in file. means each iteration of loop, line contain next line in file.

next read line manually line = input_file.readlines(). attempts read line file, iterating on lines in loop.

files read sequentially, no going backwards. end conflict. if read line using readline, iterator in loop forced return line after next since can not go back. however, promising return next line. error telling readline knows there active iterator , calling interfere loop.

if take out line = input_file.readlines(), loop expect to.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -