`
请问这个是怎么回事,需要怎么解决呢?在笨方法学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')