Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyparsing pproblems
#1
I am trying to parse the bookmarks from a document x.pdf


>>> import pyparsing as pp
>>> import PyPDF2
>>> from PyPDF2 import PdfFileReader
>>> pdfFileObj=open('x.pdf','rb')
>>> PdfReader=PyPDF2.PdfFileReader(pdfFileObj)
>>> pdfNestedExp=PdfReader.getOutlines()
>>> print(pp.nestedExpr(opener='{', closer='}').parseString(pdfNestedExp))
This code results int he following error:

Error:
Traceback (most recent call last): File "<pyshell#57>", line 1, in <module> print(pp.nestedExpr(opener='{', closer='}').parseString(pdfNestedExp)) File "C:\Python34\lib\site-packages\pyparsing.py", line 1620, in parseString instring = instring.expandtabs() AttributeError: 'list' object has no attribute 'expandtabs'
What am I doing wrong?
Reply
#2
I am trying to parse a Python nested list that is the result of the getOutlines() function of module PyPFD2 using pyparsing module. This is the result I get. what in the world are 'expandtabs' and why is that making a difference to my parse attempt?
import PPDF2,pyparsing
from pyparsing import Word, alphas, nums
pdfFileObj=open('x.pdf','rb')
pdfReader=PyPDF2.PdfFileReader(pdfFileObj)
List=pdfReader.getOutlines()
myparser = Word( alphas ) + Word(nums, exact=2) +"of" + Word(nums, exact=2)
myparser.parseString(List)
Error:
Traceback (most recent call last): File "<pyshell#23>", line 1, in <module> myparser.parseString(List) File "C:\python\lib\site-packages\pyparsing.py", line 1620, in parseString instring = instring.expandtabs() AttributeError: 'list' object has no attribute 'expandtabs'
Reply
#3
(Feb-04-2018, 02:45 PM)standenman Wrote: what in the world are 'expandtabs' and why is that making a difference to my parse attempt?

str.expandtabs() is a builtin method in class str. Obviously you are calling a method (parseString()) that expects a string argument with a list argument and this is the cause for the error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parsing logical expression with pyparsing palo173 2 5,488 May-13-2019, 09:22 AM
Last Post: palo173

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020