我想在我的文件中插入一些文本,
X
---
0.1
0.2
.
.
.
99.9
我想在该文件中添加一些随机浮点数:
X Y
0.1 ,38.58
0.2 ,12.45
0.3 ,79.03
. , .
. , .
99.9 ,47.36
代码:
#!/usr/bin/python
import random
a=[random.uniform(10,100) for i in range (1000)]
c = open("dosya.txt","w")
c.write('X DEGER: Y DEGER:\n')
c.write('--------------\n')
count = 0
while (count < 99.9):
count = count + 0.1
c.write("%s \n" % (count,))
c.close
c= open("dosya.txt","r+")
c.seek(37,0)
for k in range(900):
print a[k]
c.write(",%f" %(a[k]))
c.seek(5,1)
c.close
当我运行它时,我得到了凌乱的文本文件。你能告诉我我的错在哪里吗?