求助,当我使用open()函数读取文件时,最终报错 Cannot open console output buffer for reading
我在使用open()函数读取文件时,最终报错
Cannot open console output buffer for reading
在使用该函数时,我引入了argparse并以短参数-r指定了文件路径,部分代码如下
run = argparse.ArgumentParser()
run.add_argument('-r',dest='read',help='获取文件路径')
run.add_argument('-p','--port',help='用逗号隔开')
args = run.parse_args()
if args.read and args.port:
port = args.port
dir = args.read
for a in open(dir):
for i in port:
print(a,i)
It is caused by the argument of the built-in function
open
,open(dir)
called here.Basically, wrong file path
dir
to open in your code, check how you use your script ?