log.txt 稍后在python中打开log.txt: def read_file(logs,self): print 'here' f1=open(l-6ren">
gpt4 book ai didi

python - shell脚本创建的文件不能被python打开?

转载 作者:太空宇宙 更新时间:2023-11-04 08:19:14 28 4
gpt4 key购买 nike

echo "Denied"> log.txt

稍后在python中打开log.txt:

def read_file(logs,self):
print 'here'
f1=open(logs,"r","utf-8")
for line in f1:
print str(line)

运行时报错:

"TypeError: coercing to Unicode: need string or buffer, instance found"

最佳答案

应该是:

def read_file(self, logs):

参数顺序相反

def read_file(logs, self):

您的方法尝试在您调用时打开 self 实例而不是日志:

self.read_file(logs)

关于python - shell脚本创建的文件不能被python打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8781679/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com