Subject | Re: [firebird-python] pack problem in Python 3 |
---|---|
Author | Pavel Cisar |
Post date | 2012-01-12T17:22:22Z |
Dne 12.1.2012 14:46, Philippe Makowski napsal(a):
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
Conversion from <str> to <bytes> object should fix this.
regards
Pavel Cisar
> Hi,Yes, see:
>
> I need your help
>
> this piece of code have no problem under Python2
> #coding:utf-8
> #
> import struct
>
> def addString(codeAsByte, s):
> sLen = len(s)
> format = 'cc%ds' % sLen # like 'cc50s' for a 50-byte string
> newEntry = struct.pack(format, chr(codeAsByte), chr(sLen), s)
>
> def addInt(codeAsByte, value):
> newEntry = struct.pack('ccc', chr(codeAsByte), '\x01', chr(value))
>
> if __name__=='__main__':
> addInt(10,10)
> addString(28,'test'.encode("utf8"))
>
> but under Python3 I get
>
> struct.error: char format requires a bytes object of length 1
>
> for both
>
> any clue ?
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
Conversion from <str> to <bytes> object should fix this.
regards
Pavel Cisar