Jump to content

  • Log In with Google      Sign In   
  • Create Account


Converting strings to ASCII/single byte?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 3DModelerMan   Members   -  Reputation: 965

Like
0Likes
Like

Posted 27 May 2013 - 06:30 PM

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.

 



Sponsor:

#2 ChaosEngine   Crossbones+   -  Reputation: 2232

Like
1Likes
Like

Posted 27 May 2013 - 08:48 PM

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


if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS