|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请问这个错误怎么修改
#/usr/bin/python
#encoding:utf-8
import csv
import os
import time
#app类
from typing import List, Tuple
class App(object):
def __init__(self):
self.content= ''
self.startTime=0
#启动App
def LaunchApp(self):
cmd='adb shell am start -W -n com.bylh.yyb.follow/com.bylh.yyb.follow.ui.activity.MainActivity'
self.content=os.popen(cmd)
#停止app
def StopApp(self):
cmd='adb shell am force-stop com.bylh.yyb.follow'
os.popen(cmd)
#获取启动时间
def GetLaunchedTime(self):
for line in self.content.readline():
if 'ThisTime' in line:
self.startTime = line.split(':')[1]
break
return self.startTime
#控制类
class Controller(object):
def __init__(self,count):
self.app=App()
self.counter =count
self.alldata=[('timestamp','elapsedtime')]
#单次测试过程
def testprocess(self):
self.app.LaunchApp()
elpasedtime= self.app.GetLaunchedTime
self.app.StopApp()
currentTime = self.getCurrentTime()
self.alldata.append((currentTime , elpasedtime))
#多次执行测试过程
def run(self):
while self.counter >0:
self.testprocess()
self.counter =self.counter -1
#获取当前的时间戳
def getCurrentTime(self):
currentTime = time.strftime("%Y -%m-%d %H:%M;%S",time.localtime())
return currentTime
#数据的存储
def SaveDataToCSV(self):
csvfile = open('starTime.csv','wb')
writer =csv.writer(csvfile)
writer.writerows(self.alldata)
csvfile.close()
if __name__ == '__main__':
controller =Controller(10)
controller.run()
controller.SaveDataToCSV()
报错如下
D:\test\Scripts\python.exe D:/test/launchIime/launchTime.py
Traceback (most recent call last):
File "D:/test/launchIime/launchTime.py", line 66, in <module>
controller.SaveDataToCSV()
File "D:/test/launchIime/launchTime.py", line 61, in SaveDataToCSV
writer.writerows(self.alldata)
TypeError: a bytes-like object is required, not 'str'
Process finished with exit code 1
|
|