Skip to content

Commit 98b9662

Browse files
committedSep 13, 2013
Added Python 3 support.
More or less, the only changes that were required were to do with unicode vs ascii strings, so where needed, I have added encodings and b prefixes on strings. Fixes #1.
1 parent b4f6721 commit 98b9662

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

‎Model3D.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, x, y, z):
1515
self.z = float(z)
1616

1717
key_string = '(%f, %f, %f)' % (self.x, self.y, self.z)
18+
key_string = key_string.encode('utf-8')
1819
self.hash = md5(key_string).hexdigest()
1920

2021
def __add__(self, other):
@@ -407,20 +408,20 @@ def __init__(self, f=None):
407408
contents = f.read()
408409
f.close()
409410

410-
if contents.find("vertex", 80) == -1:
411+
if contents.find(b"vertex", 80) == -1:
411412
# File is a binary STL file.
412413
self.process_bin(contents)
413414
else:
414415
self.process_text(contents)
415416

416417
def process_bin(self, contents=None):
417-
self.name, num_facets_1 = unpack("=80sI", contents[:84])
418+
self.name, num_facets_1 = unpack(b"=80sI", contents[:84])
418419

419-
self.name = self.name.replace("solid", "")
420-
self.name = self.name.strip('\x00 \t\n\r')
420+
self.name = self.name.replace(b"solid", b"")
421+
self.name = self.name.strip(b'\x00 \t\n\r')
421422

422423
if len(self.name) == 0:
423-
self.name = "Unkown"
424+
self.name = b"Unkown"
424425

425426
contents = contents[84:]
426427
facetsz = len(contents)
@@ -435,7 +436,7 @@ def process_bin(self, contents=None):
435436

436437
for i in items:
437438
nx, ny, nz, f1x, f1y, f1z, f2x, f2y, f2z, f3x, f3y, f3z = \
438-
unpack("=ffffffffffffxx", i)
439+
unpack(b"=ffffffffffffxx", i)
439440
v1 = Vector3(f1x, f1y, f1z)
440441
v2 = Vector3(f2x, f2y, f2z)
441442
v3 = Vector3(f3x, f3y, f3z)

‎pySlice.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def slice_file(f=None, resolution=0.1):
6868

6969
interval = scale * resolution
7070
stats = model.stats()
71-
print stats
71+
print(stats)
7272

73-
for targetz in xrange(0, int(stats['extents']['z']['upper']), int(interval)):
73+
for targetz in range(0, int(stats['extents']['z']['upper']), int(interval)):
7474
dwg = Drawing('outputs/svg/'+str(targetz)+'.svg', profile='tiny')
7575
pairs = model.slice_at_z(targetz)
7676
for pair in pairs:

0 commit comments

Comments
 (0)
Please sign in to comment.