我有下面的代码,其中我正在写一些数据到一个.csv文件并读取它..数据被写入如下当脚本在windows上运行时,有一个新的行与空白被添加,当相同的脚本在linux上运行时没有空白..有人能提供输入为什么是这样吗?你知道吗
你知道吗趋势.csv你知道吗
6/26/2013 9
6/26/2013 9
6/26/2013 9
import csv
import datetime
from collections import deque
#from collections import maxlength
icount=9
now = datetime.datetime.now()
time =now.strftime("%m/%d/%Y")
#Keep appending date and count everytime this script is run
c = csv.writer(open("trend.csv", "a"))
c.writerow([time, icount])
with open('trend.csv','rU') as fin:
reader=csv.reader(fin)
d=deque(reader,8)
print "Data"
print d
for l in d:
print l[0]
print l[1]
使用
sys.stdout.write
而不是print
。print
添加换行符。你知道吗在读入输入行之后总是修剪输入行是一种很好的做法,因为不同操作系统上的Python对换行符的解释是不同的。你知道吗
相关问题 更多 >
编程相关推荐