python - TypeError: argument of type 'PSLiteral' is not iterable -


i trying remove hidden enters using pdfform-scraper-script before write csv file. keep receiving error mentioned in title. relevant piece of code is:

import glob import os import sys import csv pdfminer.pdfparser import pdfparser pdfminer.pdfdocument import pdfdocument pdfminer.pdftypes import resolve1  path = 'c:\users\wonen\downloads\test' filename in glob.glob(os.path.join(path, '*.pdf')):     fp = open(filename, 'rb')     #read pdf's     parser = pdfparser(fp)     doc = pdfdocument(parser)     #doc.initialize()    # <<if password required     fields = resolve1(doc.catalog['acroform'])['fields']     row = []     in fields:         field = resolve1(i)         name, value = field.get('t'), field.get('v')         #removing 'hidden enter'         if value == none:            print 'ok'         elif value == notimplementederror:             print 'ok'         elif '\n' in value:                value.replace('\n',' ')         elif '\r' in value:                value.replace('\r',' ')         row.append(value)     writer.writerow(list(reversed(row))) 

the complete error (+output) is:
ok
ok

traceback (most recent call last): file "c:\python27\scripts\test3.py", line 37, in elif '\n' in value: typeerror: argument of type 'psliteral' not iterable

does know how solve this?

not knowing content of input file it's hard guess. think problem non string value when calling field.get('v') solve suggest change value string. try this:

if value == none:    print 'ok' elif value == notimplementederror:     print 'ok' elif '\n' in str(value):    value = str(value)        value.replace('\n',' ') elif '\r' in str(value):    value = str(value)        value.replace('\r',' ') 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -