tomer 发表于 2014-11-05 09:37

书上的代码敲了一遍,报错,郁闷


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'

tomer 发表于 2014-11-05 10:17

python在window下的怎么和linux一下的要求啊、是斜杠反了

zxjiuniu 发表于 2014-11-05 11:24

spath=r"e:\test\test.txt"回复 2# tomer


   

tomer 发表于 2014-11-05 14:02

spath="e:/test/test.txt"

Buring__ 发表于 2014-11-05 17:52

回复 1# tomer


    用双斜杠\\

tomer 发表于 2014-11-05 20:26

回复 5# Buring__


    恩,用 用双斜杠\\也行

liujinz 发表于 2014-11-06 16:45

前面加r是比较好的,r'c:\app\test.txt' 和r'c:/app/test.txt'都可以。
页: [1]
查看完整版本: 书上的代码敲了一遍,报错,郁闷