Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于循环的Python操作系统-TypeError:';模块';对象不可调用_Python_For Loop_Pdf_Module - Fatal编程技术网

用于循环的Python操作系统-TypeError:';模块';对象不可调用

用于循环的Python操作系统-TypeError:';模块';对象不可调用,python,for-loop,pdf,module,Python,For Loop,Pdf,Module,我有以下代码来迭代文件夹中的每个文件,并在其上运行pdfplumber模块: #Import required packages: import os import pdfplumber #Iterate over pdf's os.chdir(r'C:\MyDocuments\PDF') directory = r'C:\MyDocuments\PDF' for filename in os.listdir(directory):

我有以下代码来迭代文件夹中的每个文件,并在其上运行
pdfplumber
模块:

#Import required packages:
import os
import pdfplumber

#Iterate over pdf's 
os.chdir(r'C:\MyDocuments\PDF')
directory = r'C:\MyDocuments\PDF'
for filename in os.listdir(directory):                              #iterate over each file in directory
    if filename.endswith(".pdf"):                                   #if the file is a pdf (we will be creating .txt files - do not want to include these)
        pdf = pdfplumber(filename)                                  #pdfplumber extracts the pdf file first
    else:
        continue

一旦使用
pdfplumber
导入PDF,就会有更多的事情发生,但是这个
for
循环给出了问题的要点。当我运行此命令时,会收到错误消息

TypeError:“模块”对象不可调用


似乎应该有这样的解决方案:
从操作系统导入…
其中。。。应该是任何需要的功能(我认为)。如果这是一个解决方案,我不知道我需要从操作系统导入哪个特定功能。如果有人会有一个如何使这项工作的建议,我将非常感谢

pdfplumber
本身就是类名。您需要为此使用
.open()

import os
import pdfplumber

#Iterate over pdf's 
os.chdir(r'C:\MyDocuments\PDF')
directory = r'C:\MyDocuments\PDF'
for filename in os.listdir(directory):                              #iterate over each file in directory
    if filename.endswith(".pdf"):                                   #if the file is a pdf (we will be creating .txt files - do not want to include these)
        pdf = pdfplumber.open(filename)                                  #pdfplumber extracts the pdf file first
    else:
        continue

真不敢相信我竟然没有注意到这一点。非常感谢!