Jump to content
  • Advertisement
Sign in to follow this  
3DModelerMan

Converting strings to ASCII/single byte?

This topic is 2031 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

If you can guarantee that your strings are only using ascii chars, then you could write the data to file encoded as utf-8. 

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!