问什么要使用csv格式,文件默认是,逗号分割的,文件较小,可以用文本编辑器直接打开,或用Excel表格直接分析数据。
下面是简单的代码实现逻辑。结合android的adb命令,执行命令,读取执行结果,写入csv文件,画图分析。
写csv 文件
import csv
import os
alldata = [("timestamp", "cpustatus"),("1",12)]
path = os.path.dirname(__file__)
pathfile = os.path.join(path,"csvfile.csv")
#newline 不指定newline='',则每写入一行将有一空行被写入
with open(path,'w',newline='') as fd:
writer = csv.writer(fd)
for row in alldata:
writer.writerow(row)
读csv文件
import csv
import os
path = os.path.dirname(__file__)
pathfile = os.path.join(path,"csvfile.csv")
print(path)
with open(pathfile,'r') as fd:
reader = csv.reader(fd)
# print(list(reader))
for row in reader:
print(row)
网友评论