Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


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: 1071

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: 2503

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