鱼C论坛

 找回密码
 立即注册
查看: 2111|回复: 2

[已解决]TypeError: a bytes-like object is required, not 'str'求助

[复制链接]
发表于 2018-4-8 14:58:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
最佳答案
2018-4-8 15:02:32
'w'打开试试,不要'wb'....
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-4-8 15:02:32 | 显示全部楼层    本楼为最佳答案   
'w'打开试试,不要'wb'....
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-8 15:26:05 | 显示全部楼层
完美解决,谢谢哈
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-19 02:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表