这是代码
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])
这段代码是机器学习在线课程的一部分,我已经在这一点上停留了 3 个小时。任何帮助将非常感激。
(PS 这不是家庭作业问题,也没有附加成绩,它是免费的在线课程)