Returns 文件正文的总字数

Returns the total number of words in the text of a file

我正在使用 Python 3,我正在尝试编写一个函数,该函数将文件名作为参数,returns 该文件文本中的总字数。我不断收到错误 "AttributeError: '_io.TextIOWrapper' object has no attribute 'closes'",但我不知道如何解决。任何帮助将不胜感激。

问题是您引用的函数无效。 file.closes() 应该是 file.close()