Parsing Nested List

Chris Angelico rosuav at gmail.com
Sun Feb 4 17:36:04 EST 2018


On Mon, Feb 5, 2018 at 9:26 AM, Stanley Denman
<dallasdisabilityattorney at gmail.com> wrote:
> 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?
>
> Python Code
> 7
> 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)
>
> This is the error I get:
>
> 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'
>
> Thanks so much, not getting any helpful responses from https://python-forum.io.

By the look of this code, it's expecting a string. (The variable name
"instring" is suggestive of this, and strings DO have an expandtabs
method.) You're calling a method named "parseString", and presumably
giving it a list. I don't know what you mean by "nested" though.

Maybe you want to iterate over the list and parse each of the strings in it?

More info about what you're trying to do here would help.

ChrisA



More information about the Python-list mailing list