Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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; 'python,': 0.02; 'completeness': 0.07; 'subject:data': 0.07; 'element': 0.09; 'subject:string': 0.09; 'python': 0.11; 'to:name:python- list@python.org': 0.15; '...)': 0.16; 'append': 0.16; 'currencies': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'distinction': 0.16; 'from:addr:jpmorgan.com': 0.16; 'rarely': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'sentence': 0.16; 'separated': 0.16; 'separating': 0.16; 'subject:changing': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'accuracy': 0.18; 'later': 0.18; 'string': 0.18; 'header:Received:8': 0.20; 'received:169.254': 0.20; 'string,': 0.22; 'header:In-Reply-To:1': 0.22; 'received:169': 0.27; 'received:155': 0.29; 'strict': 0.29; 'easier': 0.31; 'phone:': 0.31; 'gets': 0.32; 'subject: (': 0.33; 'hi,': 0.33; 'space': 0.34; 'things': 0.36; 'far': 0.36; 'subject:)': 0.36; 'but': 0.36; 'does': 0.36; 'charset:us-ascii': 0.36; 'list': 0.37; 'you?': 0.38; 'correct': 0.38; 'to:addr :python-list': 0.39; 'how': 0.40; 'to:addr:python.org': 0.40; 'reached': 0.64; 'between': 0.64; 'information,': 0.65; 'length': 0.67; 'purchase': 0.67; 'subject': 0.70; 'investment': 0.71; 'legal': 0.73; 'bank': 0.74; 'sale': 0.75; "'are'": 0.84; '712': 0.84; 'houston,': 0.84; 'idiom': 0.84; 'received:169.254.8': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sj3.jpmchase.com q2SIKXGa000336 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=jpmorgan.com; s=smtpout; t=1332958834; bh=KRu3W9DcFc6zbECx9sznI4ggg87vHv+hTlHaQuPFnbk=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=hPtcZWR4F6udoKPxyx5uo1QIZT29SktrmpEffvEv04f/wj80dn5c0NhbnBt3JN/nI z68sI0wvfEKOfckdSmjiSfRawcL5jgNsHMPwNIGA/oYDRiCsOqQvvnUvB/cypy7LA4 7pdMx+8bK7EDti9EdfrxJjJdTH286eVZwy2cCrNg= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: "convert" string to bytes without changing data (encoding) Thread-Topic: "convert" string to bytes without changing data (encoding) Thread-Index: AQHNDQpNHZNzdgc8qEeb3v43AQCsyZaAAVbQ Date: Wed, 28 Mar 2012 18:20:23 +0000 References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.38] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332958844 news.xs4all.nl 6873 [2001:888:2000:d::a6]:39932 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22294 > As it seems, this would be far easier with python 2=2Ex=2E With python 3= =0D=0A> and its strict distinction between "str" and "bytes", things gets= =0D=0A> syntactically pretty awkward and error-prone (something as innocent= ly=0D=0A> looking like "s=3Ds+'/'" hidden in a rarely reached branch and a= =0D=0A> seemingly correct program will crash with a TypeError 2 years=0D=0A= > later =2E=2E=2E)=0D=0A=0D=0AJust a small note as you are new to Python, s= tring concatenation can=0D=0Abe expensive (quadratic time)=2E The Python (2= =2Ex and 3=2Ex) idiom for =0D=0Afrequent string concatenation is to append = to a list and then join =0D=0Athem like the following (linear time)=2E =0D= =0A=0D=0A>>>lst =3D [ 'Hi,' ]=0D=0A>>>lst=2Eappend( 'how' )=0D=0A>>>lst=2Ea= ppend( 'are' )=0D=0A>>>lst=2Eappend( 'you?' )=0D=0A>>>sentence =3D ' '=2Ejo= in( lst ) # use a space separating each element=0D=0A>>>print sentence=0D= =0AHi, how are you?=0D=0A=0D=0AYou can use join on an empty string, but the= n they will not be =0D=0Aseparated by spaces=2E=0D=0A=0D=0A>>>sentence =3D = ''=2Ejoin( lst ) # empty string so no separation=0D=0A>>>print sentence=0D= =0AHi,howareyou?=0D=0A=0D=0AYou can use any string as a separator, length d= oes not matter=2E=0D=0A=0D=0A>>>sentence =3D '@-Q'=2Ejoin( lst )=0D=0A>>>pr= int sentence=0D=0AHi,@-Qhow@-Qare@-Qyou?=0D=0A=0D=0A=0D=0ARamit=0D=0A=0D=0A= =0D=0ARamit Prasad | JPMorgan Chase Investment Bank | Currencies Technology= =0D=0A712 Main Street | Houston, TX 77002=0D=0Awork phone: 713 - 216 - 5423= =0D=0A=0D=0A--=0D=0A=0D=0AThis email is confidential and subject to importa= nt disclaimers and=0D=0Aconditions including on offers for the purchase or = sale of=0D=0Asecurities, accuracy and completeness of information, viruses,= =0D=0Aconfidentiality, legal privilege, and legal entity disclaimers,=0D=0A= available at http://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E