【发布时间】:2016-06-10 20:17:01
【问题描述】:
运行代码时。
file_path = raw_input("Drag the text file here: ")
file_path = file_path.strip()
file_handle = open(file_path, 'r')
for line in file_handle:
print line
输出:
Drag the text file here: /Users/user_name/Desktop/white\ space/text.txt
Traceback (most recent call last):
File "desktop/test.py", line 3, in <module>
file_handle = open(file_path, 'r')
IOError: [Errno 2] No such file or directory: '/Users/user_name/Desktop/white\\ space/text.txt'
对于任何没有空格的路径名,该程序都可以正常运行。
【问题讨论】:
标签: python io whitespace filepath