Skip to content

Make Python 2.7 division behave like Python 3 #211

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
6 changes: 4 additions & 2 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Compatible with Python versions 2.7-3.x
"""

from __future__ import division

__version__ = "2.1.3"

from struct import pack, unpack, calcsize, error, Struct
Expand Down Expand Up @@ -163,7 +165,7 @@ def signed_area(coords):
xs, ys = map(list, list(zip(*coords))[:2]) # ignore any z or m values
xs.append(xs[1])
ys.append(ys[1])
return sum(xs[i]*(ys[i+1]-ys[i-1]) for i in range(1, len(coords)))/2.0
return sum(xs[i]*(ys[i+1]-ys[i-1]) for i in range(1, len(coords))) / 2

def ring_bbox(coords):
"""Calculates and returns the bounding box of a ring.
Expand Down Expand Up @@ -262,7 +264,7 @@ def itercoords():
if ccw == triplet_ccw:
# get triplet centroid
xs,ys = zip(*triplet)
xmean,ymean = sum(xs) / 3.0, sum(ys) / 3.0
xmean,ymean = sum(xs) / 3, sum(ys) / 3
# check that triplet centroid is truly inside the ring
if ring_contains_point(coords, (xmean,ymean)):
return xmean,ymean
Expand Down