python小白求教

爱江山--爱美人 2016-01-31 09:31:02
各位大神,帮忙看下我这个为啥打不开文件啊。

test_file=open('\\c:test.txt')
text=test_file.read()
print(text)


下面是报错
runfile('C:/Users/han/Documents/Python Scripts/untitled8.py', wdir='C:/Users/han/Documents/Python Scripts')
Traceback (most recent call last):

File "<ipython-input-3-c065fd004b65>", line 1, in <module>
runfile('C:/Users/han/Documents/Python Scripts/untitled8.py', wdir='C:/Users/han/Documents/Python Scripts')

File "D:\Users\han\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)

File "D:\Users\han\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

File "C:/Users/han/Documents/Python Scripts/untitled8.py", line 8, in <module>
test_file=open('\\c:test.txt')
test.txt 的目录就是 C:\
...全文
330 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
python_tty 2016-02-01
  • 打赏
  • 举报
回复
c:\\test.txt or r'c:\test.txt '
panghuhu250 2016-01-31
  • 打赏
  • 举报
回复
注意\的位置. 是"C:\test.txt"或者r"C:\test.txt".
baidu_33899560 2016-01-31
  • 打赏
  • 举报
回复
文件(C:/用户/韩/文件/ Python脚本/ untitled8 .py,WDIR = c:/用户/韩/文件/ Python脚本)追踪(最后调用):文件“< ipython-input-3-c065fd004b65 >”,1号线,在<模块>文件(C:/用户/韩/文件/ Python脚本/ untitled8 .py,WDIR = c:/用户/韩/文件/ Python脚本文件“D”):usershananaconda3libsite packagesspyderlibwidgetsexternalshellsitecustomize .py”,699号线,在RUNFILE execfile(filename,命名空间)文件“D:usershananaconda3libsite packagesspyderlibwidgetsexternalshellsitecustomize .py”,88号线在execfile exec(编译(open(filename,'包')。read(),文件名,“执行”),命名空间)文件的“C:/用户/韩/文件/ Python脚本/ untitled8 .py”,8号线,在<模块> test_file =开放(C:测试.txt”)

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧