【发布时间】:2016-01-05 19:38:46
【问题描述】:
我想从 CSV 读取数据并将其保存到列表并发送到服务器。我的算法: 1. 打开 CSV 文件 2.检查CSV文件中的数据,如果CSV文件中没有数据我不想保存到列表但如果在CSV中有数据,数据将保存到列表并发送到服务器。 3.读取后删除数据
我在第 2 步和第 3 步遇到问题,因为我的系统没有向服务器发送空白列表。 我使用 python 2.7 并且有我的代码: `def readFile(self): 尝试: 打印“打开”+ self.filename f = 打开(self.filename) csv_f= csv.reader (f)
except IOError:
print 'cannot open file'
else:
## Read the first line
print "file opened " + self.filename
## If the file is not empty keep reading line one at a time
## till the file is empty
for row in csv_f:
Data.append(row)
del (row)
f.close()
return Data
你能帮帮我吗?
【问题讨论】: