Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding python3 compatibility #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pdftableextract/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Example package with a console entry point
from core import process_page, output, table_to_list
from .core import process_page, output, table_to_list
10 changes: 5 additions & 5 deletions src/pdftableextract/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def popen(name,command, *args, **kwargs):
try:
result=subprocess.Popen(command,*args, **kwargs)
return result
except OSError, e:
except OSError as e:
message="""Error running {0}. Is it installed correctly?
Error: {1}""".format(name, e)
raise OSError(message)
except Exception, e:
except Exception as e:
raise

def colinterp(a,x) :
Expand Down Expand Up @@ -307,7 +307,7 @@ def isDiv(a, l,r,t,b) :

whitespace = re.compile( r'\s+')

def getCell( (i,j,u,v) ):
def getCell(i,j,u,v):
(l,r,t,b) = ( vd[2*i+1] , vd[ 2*(i+u) ], hd[2*j+1], hd[2*(j+v)] )
p = popen("pdftotext",
"pdftotext -r %d -x %d -y %d -W %d -H %d -layout -nopgbrk -f %d -l %d %s -" % (bitmap_resolution, l-pad, t-pad, r-l, b-t, pg, pg, quote(infile)),
Expand All @@ -329,7 +329,7 @@ def getCell( (i,j,u,v) ):
#check that pdftotext exists by running a simple command
check_for_required_executable("pdftotext",["pdftotext","-h"])
#end check
cells = [ getCell(x) for x in cells if
cells = [ getCell(*x) for x in cells if
( frow == None or (x[1] >= frow and x[1] <= lrow)) ]
return cells

Expand Down Expand Up @@ -404,7 +404,7 @@ def o_cells_xml(cells,pgs, outfile=None,infile=None, name=None, output_type=None
root.setAttribute("name",name)
for cl in cells :
x = doc.createElement("cell")
map(lambda(a): x.setAttribute(*a), zip("xywhp",map(str,cl)))
map(lambda a: x.setAttribute(*a), zip("xywhp",map(str,cl)))
if cl[5] != "" :
x.appendChild( doc.createTextNode(cl[5]) )
root.appendChild(x)
Expand Down
6 changes: 3 additions & 3 deletions src/pdftableextract/extracttab.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def isDiv(a, l,r,t,b) :

whitespace = re.compile( r'\s+')

def getCell( (i,j,u,v) ):
def getCell(i,j,u,v):
(l,r,t,b) = ( vd[2*i+1] , vd[ 2*(i+u) ], hd[2*j+1], hd[2*(j+v)] )
p = subprocess.Popen(
("pdftotext -r %d -x %d -y %d -W %d -H %d -layout -nopgbrk -f %d -l %d %s -"
Expand All @@ -269,13 +269,13 @@ def getCell( (i,j,u,v) ):
#if args.boxes :
# cells = [ x + (pg,"",) for x in cells ]
#else :
# cells = map(getCell, cells)
# cells = [getCell(*cell) for cell in cells]

if args.boxes :
cells = [ x + (pg,"",) for x in cells if
( frow == None or (x[1] >= frow and x[1] <= lrow)) ]
else :
cells = [ getCell(x) for x in cells if
cells = [ getCell(*x) for x in cells if
( frow == None or (x[1] >= frow and x[1] <= lrow)) ]
return cells

Expand Down
2 changes: 1 addition & 1 deletion src/pdftableextract/pnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def readPNM(fd):
m = int(m)

if m != 255 :
print "Just want 8 bit pgms for now!"
print("Just want 8 bit pgms for now!")

d = fromstring(data,dtype=uint8)
d = reshape(d, (height,width) )
Expand Down