[Tutor] text file help
Alan Gauld
alan.gauld at btinternet.com
Tue Mar 3 02:33:57 CET 2015
Forwarding to list too.
On 02/03/15 19:04, Tihomir Zjajic wrote:
> kl_number = []
> myfile = open("formular_doznake.txt")
> for line in "formular_doznake":
Note that you want to iterate over the file not the name of the file.
The code above sets line to each character in the file name.
You want to set it to each line in the file so it should look like:
myfile = open("formular_doznake.txt")
for line in myfile:
or just
for line in open("formular_doznake.txt") :
> 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)
> sorry, but this doesn't work !
Always try to be specific. Say what doesn't work about it and
include any error messages.
The hint above may help however.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list