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): ...@@ -55,7 +55,7 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
if filename is None: if filename is None:
return return
if binary: if binary:
f = open(filename, "wb") with open(filename, "wb") as f:
buf = "".join(["\0"] * 80) buf = "".join(["\0"] * 80)
buf += struct.pack("<I", len(facets)) buf += struct.pack("<I", len(facets))
facetformat = struct.Struct("<ffffffffffffH") facetformat = struct.Struct("<ffffffffffffH")
...@@ -67,10 +67,8 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1): ...@@ -67,10 +67,8 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
# print len(l) # print len(l)
buf += facetformat.pack(*l) buf += facetformat.pack(*l)
f.write(buf) f.write(buf)
f.close() else:
return with open(filename, "w") as f:
f = open(filename, "w")
f.write("solid " + objname + "\n") f.write("solid " + objname + "\n")
for i in facets: for i in facets:
f.write(" facet normal " + " ".join(map(str, i[0])) + "\n outer loop\n") 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): ...@@ -79,8 +77,6 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
f.write(" endloop" + "\n") f.write(" endloop" + "\n")
f.write(" endfacet" + "\n") f.write(" endfacet" + "\n")
f.write("endsolid " + objname + "\n") f.write("endsolid " + objname + "\n")
f.close()
class stl(object): 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