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

问个python脚本,报错

code:
spath="e:\test\test.txt"
f=open(spath,'w')
f.write("First Line1.\n")
f.writelines("Second Line2.")
f.close()

run:
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'

HH106 发表于 2014-11-05 09:59

window上使用正斜杠

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

回复 2# HH106


    改成正斜杠报错:
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'

HH106 发表于 2014-11-05 10:08

回复 3# tomer
你赢了
spath="e:\test\test.txt"===> spath="e:/test/test.txt"


   

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

回复 4# HH106

:mrgreen:
    靠,明明是改过来了

bulletmarquis 发表于 2014-11-05 11:06

回复 3# tomer


    windows上是两个斜杠吧

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

回复 6# bulletmarquis


    写成这样就可以了
spath="e:/test/test.txt"

bulletmarquis 发表于 2014-11-05 14:09

回复 7# tomer


    咦,我记得windows下os.sep是两个斜杠的呀。。。
页: [1]
查看完整版本: 问个python脚本,报错