[Tutor] text file help
Alan Gauld
alan.gauld at btinternet.com
Tue Mar 3 21:48:36 CET 2015
On 03/03/15 12:56, Tihomir Zjajic wrote:
> kl_number = []
> myfile = open("formular_doznake.txt")
> for line in myfile:
> if line.startswith('1'):
> num = makeNumber(next[vrs_drv], next[prs_prec], next[teh_kl])
> kl_number.append(num)
>
> def makeNumber(l1,l2,l3):
> nums = []
> for line in(vrs_drv,prs_prec,teh_kl):
> nums.append(line.rstrip().split()[-1])
> return ".join(nums)"
> print(next(myfile) + next(myfile) + next(myfile))
> print(kl_number)
Do you have any idea what these two lines do?
If not you need to go and read about next() and iterators.
It is obviously never going to work to try to read the next
line from a file that has already been processed.
I don't know what you think the lines will do but they
obviously throw an error. Its like trying to climb a ladder
when you ae already at the top.
I don't know what your logic is here, only you can answer that.
But you will get better responses asking the whole iist
not just me. I'm only one pair of eyes. The list has dozens.
> Traceback (most recent call last):
> File "C:\Python31\pro.py", line 13, in <module>
> print(next(myfile) + next(myfile) + next(myfile))
> StopIteration
Alan G.
More information about the Tutor
mailing list