[Tutor] please help

Alan G alan.gauld at freenet.co.uk
Mon Jul 11 06:14:43 CEST 2005


> The line that Ive been writing (of course wrong
> script):
> 
> f1 = open('myfile','r')
> stuff = f1.read().split('\n')
> for i in stuff:
>   if i != '//':
>        trcode = line.split('\t')[0]
>        trquant = line.split('\t')[1]
>        print trcode+'\t'+trquant
> 

You use i in the for loop but line in the code block inside?

try

for line in file('myfile'):
   if line != '\\':
      trcode = line.split('\t')[0]
      etc...

HTH,

Alan G.


More information about the Tutor mailing list