- 论坛徽章:
- 0
|
本帖最后由 guangjing888 于 2012-05-30 19:30 编辑
python对txt文件的写入操作:
- testFile = open('cainiao.txt','w')
- testFile.write('wwwwww')
- codeStr = ('<div>','<p>','aaaaa','</p>','</div>')
- testFile.write('\n\n')
- testFile.writelines(codeStr)
- testFile.close()
复制代码 可是我换成绝对路径为了就无效了,想使用绝对路径应该怎么写呢?
- //这段运行无效
- testFile = open('C:\Users\cking\Desktop\11\pyplugin_demo\cainiao.txt','w')
- testFile.write('wwwwww')
- codeStr = ('<div>','<p>','aaaaa','</p>','</div>')
- testFile.write('\n\n')
- testFile.writelines(codeStr)
- testFile.close()
复制代码 正确的写法:
f=open("d:/tmp.txt")
f=open("d://tmp.txt")
f=open("d:\\tmp.txt")
f=open("r ‘d:\tmp.txt’ ")
http://bbs.chinaunix.net/thread-3749378-1-1.html
http://hi.baidu.com/newtype/blog ... e1d0001c9583aa.html
http://bbs.chinaunix.net/thread-1090769-1-1.html
|
|