我的 IF 语句出现语法错误,不知道为什么?

Jlingz14

我正在尝试在 python 3.7 中运行以下代码。我不断收到无效的语法错误,但不知道为什么,有人能发现我做错了什么吗?缩进似乎没问题,我相信我的“打印”在正确的括号中,但我完全迷失在“if”和“else”语句中。

class pdfPositionHandling:

    def parse_obj(self, lt_objs):

        # loop over the object list
        for obj in lt_objs:

            if isinstance(obj, pdfminer.layout.LTTextLine):
                print ("%6d, %6d, %s" % (obj.bbox[0], obj.bbox[1], obj.get_text().replace('\n', '_'))

            # if it's a textbox, also recurse
            if isinstance(obj, pdfminer.layout.LTTextBoxHorizontal):
                self.parse_obj(obj._objs)

            # if it's a container, recurse
            elif isinstance(obj, pdfminer.layout.LTFigure):
                self.parse_obj(obj._objs)

    def parsepdf(self, filename, startpage, endpage):

        # Open a PDF file.
        fp = open(filename, 'rb')

        # Create a PDF parser object associated with the file object.
        parser = PDFParser(fp)

        # Create a PDF document object that stores the document structure.
        # Password for initialization as 2nd parameter
        document = PDFDocument(parser)

        # Check if the document allows text extraction. If not, abort.
        if not document.is_extractable:
            raise PDFTextExtractionNotAllowed

        # Create a PDF resource manager object that stores shared resources.
        rsrcmgr = PDFResourceManager()

        # Create a PDF device object.
        device = PDFDevice(rsrcmgr)

        # BEGIN LAYOUT ANALYSIS
        # Set parameters for analysis.
        laparams = LAParams()

        # Create a PDF page aggregator object.
        device = PDFPageAggregator(rsrcmgr, laparams=laparams)

            # Create a PDF interpreter object.
        interpreter = PDFPageInterpreter(rsrcmgr, device)


        i = 0
        # loop over all pages in the document
        for page in PDFPage.create_pages(document):
            if i >= startpage and i <= endpage:
                # read the page into a layout object
                interpreter.process_page(page)
                layout = device.get_result()

                # extract text from this object
                self.parse_obj(layout._objs)
            i += 1

我收到以下错误:

File "C:/Users/951298/Documents/Python Scripts/PDF Scraping/untitled1.py", line 12
    if isinstance(obj, pdfminer.layout.LTTextBoxHorizontal):
                                                           ^
SyntaxError: invalid syntax

不知道为什么它最后指向冒号?

杰森

在第 9 行,您应该在最后输入 3 个括号,但您只有其中的 2 个。添加另一个括号,它会正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何解决:我的第二个 if 语句出现语法错误,但我不知道为什么?

来自分类Dev

我的脚本出现语法错误,但我不知道为什么以及如何解决它>

来自分类Dev

prog.pl第24行出现语法错误,但我不知道为什么

来自分类Dev

我不知道为什么这段代码中有语法错误

来自分类Dev

不知道为什么我收到 StopIteration 错误

来自分类Dev

SMTP 错误,我不知道为什么

来自分类Dev

我不知道为什么在此python函数中出现索引错误?

来自分类Dev

我不知道为什么在 MySql 中完全连接时出现此错误

来自分类Dev

我收到一个语法错误,不知道为什么?从谷歌表调用.evaluate显示侧边栏数据时

来自分类Dev

我不知道的语法错误

来自分类Dev

PHP SQL语句中的错误($ stmt2返回false,但我不知道为什么)

来自分类Dev

我不知道为什么我的if语句有效

来自分类Dev

我不知道为什么我的“if”语句不起作用

来自分类Dev

lynx安装后出现错误,提示“ HTTP / 1.0 302已移动”,我不知道为什么

来自分类Dev

三个语法错误,不知道我做错了什么。初学者代码,if-else 语句

来自分类Dev

我不知道为什么我得到AttributeError

来自分类Dev

我的陈述无效,我也不知道为什么

来自分类Dev

我不知道为什么我得到AttributeError

来自分类Dev

我的点击器游戏中出现UnbloundLocalError,我不知道为什么

来自分类Dev

我不断得到细分错误:11错误,我不知道为什么... c ++

来自分类Dev

我不知道为什么我的代码是错误的?那是什么错呢?

来自分类Dev

导致单元测试失败的“如果”语句,但我不知道为什么

来自分类Dev

我的第二个 if 语句被忽略不知道为什么

来自分类Dev

我不断遇到细分错误,但我不知道为什么

来自分类Dev

我不知道为什么我得到“未定义的不是函数”错误

来自分类Dev

我的C程序正在生成分段错误,我不知道为什么

来自分类Dev

我不断收到此错误消息,但我不知道为什么

来自分类Dev

我收到 mysqli 错误 1064 但我不知道为什么

来自分类Dev

我收到此错误,“错误:'{'令牌之前的预期表达式”。我不知道为什么?语法对我来说很好

Related 相关文章

  1. 1

    如何解决:我的第二个 if 语句出现语法错误,但我不知道为什么?

  2. 2

    我的脚本出现语法错误,但我不知道为什么以及如何解决它>

  3. 3

    prog.pl第24行出现语法错误,但我不知道为什么

  4. 4

    我不知道为什么这段代码中有语法错误

  5. 5

    不知道为什么我收到 StopIteration 错误

  6. 6

    SMTP 错误,我不知道为什么

  7. 7

    我不知道为什么在此python函数中出现索引错误?

  8. 8

    我不知道为什么在 MySql 中完全连接时出现此错误

  9. 9

    我收到一个语法错误,不知道为什么?从谷歌表调用.evaluate显示侧边栏数据时

  10. 10

    我不知道的语法错误

  11. 11

    PHP SQL语句中的错误($ stmt2返回false,但我不知道为什么)

  12. 12

    我不知道为什么我的if语句有效

  13. 13

    我不知道为什么我的“if”语句不起作用

  14. 14

    lynx安装后出现错误,提示“ HTTP / 1.0 302已移动”,我不知道为什么

  15. 15

    三个语法错误,不知道我做错了什么。初学者代码,if-else 语句

  16. 16

    我不知道为什么我得到AttributeError

  17. 17

    我的陈述无效,我也不知道为什么

  18. 18

    我不知道为什么我得到AttributeError

  19. 19

    我的点击器游戏中出现UnbloundLocalError,我不知道为什么

  20. 20

    我不断得到细分错误:11错误,我不知道为什么... c ++

  21. 21

    我不知道为什么我的代码是错误的?那是什么错呢?

  22. 22

    导致单元测试失败的“如果”语句,但我不知道为什么

  23. 23

    我的第二个 if 语句被忽略不知道为什么

  24. 24

    我不断遇到细分错误,但我不知道为什么

  25. 25

    我不知道为什么我得到“未定义的不是函数”错误

  26. 26

    我的C程序正在生成分段错误,我不知道为什么

  27. 27

    我不断收到此错误消息,但我不知道为什么

  28. 28

    我收到 mysqli 错误 1064 但我不知道为什么

  29. 29

    我收到此错误,“错误:'{'令牌之前的预期表达式”。我不知道为什么?语法对我来说很好

热门标签

归档