Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.060 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'stored': 0.04; 'subject:data': 0.07; 'bytes.': 0.09; 'bytes;': 0.09; 'subject:string': 0.09; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:changing': 0.16; 'string': 0.18; 'trying': 0.20; 'received:209.85.210.174': 0.20; 'received:mail-iy0-f174.google.com': 0.20; 'wrote:': 0.21; '64-bit': 0.22; 'pointer': 0.22; 'header:In-Reply-To:1': 0.22; 'quite': 0.26; 'memory': 0.27; 'message-id:@mail.gmail.com': 0.27; 'equivalent': 0.27; 'bits': 0.29; 'correctly.': 0.29; 'asking': 0.29; 'received:209.85': 0.32; 'received:209.85.210': 0.32; 'chris': 0.32; 'received:google.com': 0.32; 'subject: (': 0.33; 'thu,': 0.33; 'unicode': 0.33; 'problem': 0.34; 'received:209': 0.35; 'point': 0.35; 'should': 0.35; 'actually': 0.35; 'subject:)': 0.36; 'supposed': 0.36; 'but': 0.36; 'several': 0.38; 'to:addr:python-list': 0.39; 'think': 0.40; 'long': 0.40; 'to:addr:python.org': 0.40; 'your': 0.60; 'mar': 0.61; 'course': 0.61; 'type': 0.62; 'easy': 0.65; 'taking': 0.65; 'different': 0.65; 'treat': 0.66; 'here': 0.66; 'is.': 0.67; 'number.': 0.67; '2012': 0.69; 'series': 0.80; 'impossible.': 0.84; '29,': 0.93; 'memory,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=inMLqZTFe5x+mFuNfLUR84G963c03vSLk+2IxCL0A2s=; b=R6xjnmMkT8RMTVlcIeb+lX/9nP1ckJJn8tkrsZMqYMLTNatnsKCBD6OpYeHZNSYksS 27j8rDueYFAMY3BMTiLQOmb8WsP+8fhHtgUGKqCsqEV6zFQIr2Ohbm6U6E2foMwvj6ME k3Zjp2E3+IlR3p3IAnSvJrsUrJ11qKbDlPFATA9V7PkR2exSeqFhiygDiesQNb24HaGJ 3j2be4eyRYueKcaiboLcxPZGA76hO/nkCvPdSZIE0NXOleKu9ZL0TENn5XKnRcIKjrTi uKfT4ug/3VPIUT65o5qtYZ4/D12VpXo8xk5Wtvg67zREFfgXviTUbtBXUHnCk87t5y/N qhkA== MIME-Version: 1.0 In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Date: Thu, 29 Mar 2012 03:18:43 +1100 Subject: Re: "convert" string to bytes without changing data (encoding) From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 1332951527 news.xs4all.nl 6876 [2001:888:2000:d::a6]:47827 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22283 On Thu, Mar 29, 2012 at 2:36 AM, Ross Ridge wr= ote: > Chris Angelico =A0 wrote: >>What is a string? It's not a series of bytes. > > Of course it is. =A0Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. Note that distinction. I said that a string "is not" a series of bytes; you say that it "is stored" as bytes. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. That's equivalent to taking a 64-bit integer and trying to treat it as a 64-bit floating point number. They're all just bits in memory, and in C it's quite easy to cast a pointer to a different type and dereference it. But a Python Unicode string might be stored in several ways; for all you know, it might actually be stored as a sequence of apples in a refrigerator, just as long as they can be referenced correctly. There's no logical Python way to turn that into a series of bytes. ChrisA