【发布时间】:2015-04-05 19:16:13
【问题描述】:
我收到一条关于我的 python 代码没有这样的文件或目录的错误消息。我将文件保存在我的台式计算机上。但我收到错误消息
#!/usr/bin/python
fh=open("C:/Users/****/Desktop/IP Data","r")
for line in fh.readlines():
line = line.strip()
words = line.split()
# increase counters
for word in words:
if len(words)>3:
if "IP" in words[1]:
print '%s\t%s' % (words[2],1)
【问题讨论】:
-
尝试将其作为
r"C:/Users/****/Desktop/IP Data"中的原始字符串 -
@BhargavRao,你是这样说的吗:fh=open("r C:/Users/****/Desktop/IP Data","r")
-
@BhargavRao,我收到了同样的错误。我的程序在一个装有 Windows 7 的 Virtual Box 中。我安装了 python 2.7
-
试试这个
r'C:\\Users\***\Desktop\IP Data'注意C:后面的双反斜杠 -
@BhargavRao,谢谢伙计
标签: python