• Advertisement
Sign in to follow this  

Converting strings to ASCII/single byte?

This topic is 1702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to figure out how to ensure that all strings passed to my function use single byte characters. I read somewhere that python uses unicode by default. Anyways I'm trying to write a string packing function that will save my strings in a binary format readable by my C++ engine. I use this function:

def packString(str, data):
	data += struct.pack('I', len(str))
	for c in str:
		data += struct.pack('c', c)
	
	return {'FINISHED'}

Whenever this function gets called though, I get this error:

struct.error: char format requires a bytes object of length 1

 

I'm writing this script for Blender 2.66.1. My game engine expects strings that are stored in binary files to have an unsigned int for the number of characters in the string followed by that number of chars.

 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement