到目前为止,我的代码是这样的:如何从特定的目录中导入文件,不使用os.path中在Python
from glob import glob
shakedir='D:\report\shakeall'
from shakedir import isfile
def countwords(fp):
with open(fp) as fh:
return len(fh.read().split())
print "There are" ,sum(map(countwords, filter(isfile, glob("*.txt")))), "words in the files."
问题是这样的代码不工作:)
我不习惯Python语法,所以我只是尝试了任何东西。
我想要的是,我希望这个脚本从特定目录导入文本文件。
不是从os.path
,我的.py文件是。
我想从D:\report\shakeall
进口,我不能。而已。
感谢您的任何建议。
我不认为os.path中做什么,你认为它...:S 也 - didnt我已经回答这个问题的吗? http://stackoverflow.com/questions/11842548/how-do-i-count-unique-words-of-text-files-in-specific-directory-with-python/11842758#11842758 – 2012-08-08 12:43:46
可能重复的[I不明白Python中的'from'](http://stackoverflow.com/questions/11865835/i-dont-understand-the-from-in-python) – 2012-08-08 15:55:57