首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用python对象访问另一个目录中的文件

无法使用python对象访问另一个目录中的文件
EN

Stack Overflow用户
提问于 2016-09-02 19:35:40
回答 1查看 57关注 0票数 0

我想使用python 2实现一个分类应用程序,在进行分类之前,应该对文本进行预处理。分类器和预处理器在不同的包中。然后在分类包中在类中创建了一个preprocessing class对象。

这是我的项目探险家

代码语言:javascript
运行
复制
preprocessing class

类预处理: def预处理(self,file):inputFile = "text“outputFile = "plainText.txt”# infile = io.open(inputFile,"r",编码=‘utf-8’).read() outfile = io.open(outputFile,"w",编码=‘utf-8’) text = unnecessaryCharsObj.removeChars(file) text = stopWrdsObj.removeStopwords( text ) text= text.lower()平原= text.split() stemmObj.stemminig(平原) for x in纯文本: outfile.write(x) outfile.write(u'\u0020') #明文= ".join(str(x) for x in平原)#outfile.write(明文)返回输出文件outfile.close()

预处理在分类包中创建的类对象,

def分类(自):dao = DAO();procc =预处理();#获取uncatNewsList uncatNewsList =dao.selectUncategerizedNews()的未变化新闻ID;关于uncatNewsList中的新闻: description =dao.getDescriptionById(新闻) wf = io.open('news.txt','w',编码=‘utf-8’)x= description wf.write(x) rf = io.open('news.txt','r',编码=‘utf-8’).read() txt = procc.preprocess(rf)分类= MultinomialNBClassifier().classifier(txt) dao.updateNews(新闻,类别)

但是在预处理类中,它使用同一个预处理包中的文本文件。所以我不能按我的意愿去做,因为它返回了错误"No such file or directory: 'stopWordList.txt'"

我能做些什么来解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2016-09-02 19:52:58

请检查该文件是否与当前执行的文件的路径相同。以下是idea:How do I get the path of the current executed file in Python?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39299593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档