pystl
Peter Otten
__peter__ at web.de
Wed Aug 17 08:44:00 EDT 2016
Poul Riis wrote:
> I tried the following:
>
> from pystl import PySTL
> with PySTL('stl_test.stl') as stl:
> stl.add_triangle((0,0,0),(1,0,0),(0,1,0))
>
> I got the following error message:
>
> Traceback (most recent call last):
> File
>
"C:/Users/pr/AppData/Local/Programs/Python/Python35-32/Lib/idlelib/pystl_module_test_1.py",
> line 3, in <module>
> with PySTL('stl_test.stl') as stl:
> File
> "c:\users\pr\appdata\local\continuum\anaconda3\lib\site-
packages\pystl\pystl.py",
> line 62, in __enter__
> self.write_stl_header()
> File
> "c:\users\pr\appdata\local\continuum\anaconda3\lib\site-
packages\pystl\pystl.py",
> line 75, in write_stl_header
> self.f.write(struct.pack("80s", header_str))
> struct.error: argument for 's' must be a bytes object
You can fix this particular error by replacing the line
header_str = ''
with
header_str = b''
in the write_stl_header() function which then becomes:
def write_stl_header(self):
if self.is_bin:
header_str = b''
self.f.write(struct.pack("80s", header_str))
self.write_num_triangles_bin()
else:
self.f.write('solid ' + self.model_name + '\n' )
As this kind of error indicates that the module is primarily used/tested in
Python 2 there may be other similar problems.
More information about the Python-list
mailing list