[Tutor] loop couldn't work well and file couldn't close
baidusandy
baidusandy at 126.com
Tue Apr 22 18:13:18 CEST 2014
I'm a newbie to Python. I want to make python useful to my work, to write a script for get some data out. But there are some setbacks. I really needs your help. Please, help me.
-------the first one--------------
for x in range(1,a):
tem=open('results\\temp'+str(x))
tem.seek(0)
i_line=tem.readline()
while i_line:
i_list=i_line.split('\t')
if float(i_list[1])<float(b[x]):
o=open('results\\'+str(x),'a')
o.write(i_line)
o.close
else:
tem02=open('results\\temp'+str(x+1),'a')
tem02.write(i_line)
tem02.close
i_line=tem.readline()
tem.close
for x in range(a,a+1):
close('results\\temp'+str(x))
os.rename('results\\temp'+str(x),'results\\'+str(x))
## for the last line, the code couldn't work. I run the script in Windows XP, i don't know if there is something to do with the OS.
--------for another question:-----------
for x in range (a,a+1):
m=open(01)
m_line=m.readline()
b=open('02','w')
while m_line:
b.write(m_line)
m_line=m.readline()
b.close
m.close
## for this one, file 02 and 01are not the same. to tell the truth, the last line of 01 has not been written into file 02. What's wrong?
I hope you guys can help me.
Thank you all very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140423/039e72a9/attachment.html>
More information about the Tutor
mailing list