Previous Thread  Next Thread

chat icon Problem writing to file

caibbor

Posted: Thu Sep 20, 2012 10:44 pm
Joined: 20 Sep 2012
Posts: 8
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:

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.data, 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

>>>
Reply with quote


stiv

Posted: Fri Sep 21, 2012 5:02 am
Joined: 05 Aug 2003
Posts: 3493
This is Python 3. Try writing bytes rather than a string.

fi.write( bytes( 'BM1') )
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group