I'm getting the following error when trying to write a string to a file in pythion:
Traceback (most recent call last):
File "export_off.py", line 264, in execute
save_off(self.properties.path, context)
File "export_off.py", line 244, in save_off
primary.write(file)
File "export_off.py", line 181, in write
variable.write(file)
File "export_off.py", line 118, in write
file.write(self.value)
TypeError: must be bytes or buffer, not str
I basically have a string class, which contains a string:
class _off_str(object):
__slots__ = 'value'
def __init__(self, val=""):
self.value=val
def get_size(self):
return SZ_SHORT
def write(self,file):
file.write(self.value)
def __str__(self):
return str(self.value)
Furthermore, I'm calling that class like this (where variable is an array of _off_str objects:
def write(self, file):
for variable in self.variables:
variable.write(file)
I have no idea what is going on. I've seen other python programs writing strings to files, so why can't this one?
Thank you very much for your help.
Edit: It looks like I needed to state how I opened the file, here is how:
file = open(filename, 'wb')
primary.write(file)
file.close()