python3.x - python3遇到了OSError: [Errno 22] Invalid argument
本文介绍了python3.x - python3遇到了OSError: [Errno 22] Invalid argument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
`
请问这个是怎么回事,需要怎么解决呢?在笨方法学python中看到的例子写过来就出现了这个错误!
from sys import argv
script,filename=argv
txt =open(filename)
print('here is your file %r:'%filename)
print(txt.read())
txt.close()
print('Type the filename again:')
file_again=input(">")
txt_again=open(r'"E:\source code\python\ex15_sample.txt"')
print(txt_again.read())
txt_again.close()
运行时
C:\Users\winneter>python "E:\source code\python\ex15.py" "E:\source code\python\ex15_sample.txt"
here is your file 'E:\\source code\\python\\ex15_sample.txt':
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.
Type the filename again:
>ex15_sample.txt
Traceback (most recent call last):
File "E:\source code\python\ex15.py", line 9, in <module>
txt_again=open(r'"E:\source code\python\ex15_sample.txt"')
OSError: [Errno 22] Invalid argument: '"E:\\source code\\python\\ex15_sample.txt"'
解决方案
下面这句写错了:
txt_again=open(r'"E:\ource code\python\ex15_sample.txt"')
应该是:
txt_again=open(r'E:\source code\python\ex15_sample.txt')
这篇关于python3.x - python3遇到了OSError: [Errno 22] Invalid argument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文