Problem writing to file

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Thu Sep 20, 2012 11:43 pm

Problem writing to file

Post by caibbor » Thu Sep 20, 2012 11:44 pm

This works fine in a python interpreter on the same machine, but typing this in Blender's python console results in the following error.

I'm attempting to write an export script and just using the python console to verify everything works as expected (which so far it doesnt...)

Code: Select all

PYTHON INTERACTIVE CONSOLE 3.2.2 (default, Sep  5 2011, 22:21:39)  [GCC 4.6.1]

Command History:     Up/Down Arrow
Cursor:              Left/Right Home/End
Remove:              Backspace/Delete
Execute:             Enter
Autocomplete:        Ctrl+Space
Ctrl +/-  Wheel:     Zoom
Builtin Modules:     bpy,, bpy.ops, bpy.props, bpy.types, bpy.context, bpy.utils, bgl, blf, mathutils
Convenience Imports: from mathutils import *; from math import *

>>> from struct import *
>>> file=open("testfile","w+b")
>>> file.write("BM1")
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: 'str' does not support the buffer interface


Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Fri Sep 21, 2012 6:02 am

This is Python 3. Try writing bytes rather than a string.

fi.write( bytes( 'BM1') )

Post Reply