这是代码
sys.path.append( "../tools/" )
from parse_out_email_text import parseOutText #(its just another .py file that has a function I wrote)
from_sara = open("from_sara.txt", "r")
from_chris = open("from_chris.txt", "r")
from_data = []
word_data = []
temp_counter = 0
for name, from_person in [("sara", from_sara), ("chris", from_chris)]:
for path in from_person:
### only look at first 200 emails when developing
### once everything is working, remove this line to run over full dataset
temp_counter += 1
if temp_counter < 200:
path = os.path.join('..', path[:-1]) #(THIS IS THE PART I CAN'T GET MY HEAD AROUND)
print path
email = open(path, "r")
email.close()
print "emails processed"
from_sara.close()
from_chris.close()
当我运行它时,它给我一个错误,如下所示:
Traceback (most recent call last):
..\maildir/bailey-s/deleted_items/101.
File "C:/Users/AmitSingh/Desktop/Data/Udacity/Naya_attempt/vectorize_text.py", line 47, in <module>
email = open(path, "r")
IOError: [Errno 2] No such file or directory: '..\\maildir/bailey-s/deleted_items/101.'
我的笔记本电脑上什至没有这个 """'..\maildir/bailey-s/deleted_items/101.'"""目录路径,我尝试通过替换 '..' 来更改路径在代码中通过保存所有文件的文件夹的实际路径名,没有任何变化。
path = os.path.join('..', path[:-1])
此代码是机器学习在线类(class)的一部分,我已经在这一点上停留了 3 个小时。任何帮助将非常感激。
(P.S.这不是作业问题,也没有附加分数,它是免费的在线类(class))
最佳答案
您的测试数据不存在,因此找不到它。您应该再次运行启动代码并确保必要的 maildir 都在那里。
关于python-2.7 - 我不明白这个 "os.join"函数是如何工作的?我不断收到错误,并且阅读操作系统函数对我没有帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35186747/