The last line disappears in files in0
and output0
if I open it in gedit and I'm not sure why?
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0] on linux2
from math import ceil, floor, log
from random import randint, choice
def in2text(table):
out=''
out+=str(len(table))+'\n'
for t in table:
out+=(str(t[0])+' '+str(t[1])+'\n')
return out
def out2text(table):
out=''
for t in table:
out+=(str(t)+'\n')
return out
nr_inst=1000
max_n=1000000
in0=[randint(1, max_n) for e in range(1,nr_inst+1)]
input0=[[i,i] for i in in0]
output0=[5 for n,x in input0]
fin=open("in0","w")
fout=open("out0","w")
fin.write(in2text(input0))
fout.write(out2text(output0))
fin.close()
fout.close()
Write function? If I print in2text(input0)
, then I can see the last new line (enter, '\n').
I get (in out0):
5
5
5
...
5
5
without the last new line (the empty new line). I want:
5
5
5
...
5
5
<new line>
Why gedit do not show this line? Bug?
答案 0 :(得分:0)
代码本身可以正常运行,这是问题出在那之后您如何查看文件。具体来说,这似乎是gedit中存在的错误。
bugs.launchpad.net/ubuntu/+source/gedit/+bug/1621732
确认2018-11-06