Commit 8d776b50 authored by Guillaume Seguin's avatar Guillaume Seguin

Pythonize some file handling

parent e94d076b
......@@ -55,7 +55,7 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
if filename is None:
return
if binary:
f = open(filename, "wb")
with open(filename, "wb") as f:
buf = "".join(["\0"] * 80)
buf += struct.pack("<I", len(facets))
facetformat = struct.Struct("<ffffffffffffH")
......@@ -67,10 +67,8 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
# print len(l)
buf += facetformat.pack(*l)
f.write(buf)
f.close()
return
f = open(filename, "w")
else:
with open(filename, "w") as f:
f.write("solid " + objname + "\n")
for i in facets:
f.write(" facet normal " + " ".join(map(str, i[0])) + "\n outer loop\n")
......@@ -79,8 +77,6 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
f.write(" endloop" + "\n")
f.write(" endfacet" + "\n")
f.write("endsolid " + objname + "\n")
f.close()
class stl(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment