Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'string.': 0.05; "subject:' ": 0.07; 'subject:skip:s 10': 0.07; 'string': 0.09; 'python': 0.11; '2.7': 0.14; '<>_': 0.16; 'bytes).': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'result;': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'unicode': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'gives': 0.31; 'class': 0.32; 'url:python': 0.33; 'skip:b 30': 0.33; 'but': 0.35; 'skip:> 10': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:3': 0.61; 'different': 0.65; 'results': 0.69 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=aYTvnHYt c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=1oDRhzKAKukA:10 a=IuCgiK7341YA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=S-rolQTqg6yRjofkp6kA:9 a=QEXdDO2ut3YA:10 a=b3IY2nkS3zMA:10 a=-isbq5Mmx2wA:10 X-AUTH: mrabarnett:2500 Date: Thu, 15 May 2014 15:47:58 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: struct.unpack: why 's' fmt char convert to bytestring References: , <87mweotfe5.fsf@dpt-info.u-strasbg.fr>, <87iopbtmh1.fsf@dpt-info.u-strasbg.fr>, <871tvxtwgj.fsf@dpt-info.u-strasbg.fr>, <8761l9pi3n.fsf@elektro.pacujo.net>, <5372b488$0$29977$c3e8da3$5496439d@news.astraweb.com>, , <1613032089421800145.832800sturla.molden-gmail.com@news.gmane.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400165287 news.xs4all.nl 2968 [2001:888:2000:d::a6]:43986 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71617 On 2014-05-15 13:34, GuoChao wrote: > T he Python > documentation gives this same example: > >>>>record = b'raymond\x32\x12\x08\x01\x08' >>>>name, serialnum, school, gradelevel = unpack('<10sHHb', record) > > but get different results as to 's', don't know why this change in > Python 3? need extra work to encode... > >>>>name >>>>'raymond ' #for 2.7 > >>>>name >>>>b'raymond ' #for _3.3 _ > They are actually the same result; they are both bytestrings (a string of bytes). In Python 2, the 'str' class is for bytestrings and the 'unicode' class is for Unicode strings, so 'abc' (or b'abc') is a bytestring and u'abc' is a Unicode string. In Python 3, the 'bytes' class is for bytestrings and the 'str' class is for Unicode strings, so b'abc' is a bytestring and 'abc' is a Unicode string.