书上的代码敲了一遍,报错,郁闷
spath="e:\test\test.txt"
f=open(spath,"w")
f.write("First Line1.\n")
f.write("Second Line2.")
f.close()
Traceback (most recent call last):
File "E:\MYPYTHON\p1.py", line 7, in <module>
f=open(spath,"w")
OSError: Invalid argument: 'e:\test\test.txt'
python在window下的怎么和linux一下的要求啊、是斜杠反了 spath=r"e:\test\test.txt"回复 2# tomer
spath="e:/test/test.txt" 回复 1# tomer
用双斜杠\\ 回复 5# Buring__
恩,用 用双斜杠\\也行 前面加r是比较好的,r'c:\app\test.txt' 和r'c:/app/test.txt'都可以。
页:
[1]