到目前为止,我的代码是这样的:
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
,但我不能。而已。
感谢您的任何建议。