Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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; '(at': 0.05; 'encoded': 0.07; 'gather': 0.07; 'subject:data': 0.07; 'bytes.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'portions': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'referencing': 0.09; 'subject:string': 0.09; '~ethan~': 0.09; 'python': 0.11; 'assume': 0.12; 'cc:addr:python-list': 0.15; '...)': 0.16; 'ascii': 0.16; 'bytes,': 0.16; 'no;': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:changing': 0.16; 'language': 0.17; 'string': 0.18; 'specifically': 0.21; 'wrote:': 0.21; 'i.e.': 0.22; 'string,': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'basically': 0.23; '(or': 0.24; '(which': 0.24; '>>>': 0.24; 'cc:no real name:2**0': 0.26; 'variable': 0.27; 'cc:addr:python.org': 0.27; 'least': 0.27; 'interpreted': 0.29; 'safely': 0.29; 'question': 0.30; 'points': 0.30; 'cc:2**0': 0.31; 'subject: (': 0.33; 'encoding': 0.33; 'facing': 0.33; 'unicode': 0.33; 'view,': 0.33; 'problem': 0.34; 'there': 0.35; 'characters': 0.35; 'actually': 0.35; 'really': 0.36; "i'm": 0.36; 'subject:)': 0.36; 'text': 0.36; 'but': 0.36; 'peter': 0.37; 'data': 0.38; 'being': 0.39; 'either': 0.39; 'your': 0.60; 'is:': 0.61; 'biggest': 0.61; 'received:userid': 0.61; 'above.': 0.63; 'different': 0.65; 'sounds': 0.66; 'storage': 0.67; 'care': 0.67; "you'll": 0.67; 'talking': 0.70; 'bulk': 0.72; 'perfectly': 0.72; 'natural': 0.74; 'series': 0.80; 'encoding,': 0.84; 'from?': 0.84; 'stated': 0.85 Date: Wed, 28 Mar 2012 11:17:56 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Peter Daum Subject: Re: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1764 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== Cc: python-list@python.org 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332959710 news.xs4all.nl 6860 [2001:888:2000:d::a6]:51903 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22301 Peter Daum wrote: > On 2012-03-28 12:42, Heiko Wundram wrote: >> Am 28.03.2012 11:43, schrieb Peter Daum: >>> ... in my example, the variable s points to a "string", i.e. a series of >>> bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. >> No; a string contains a series of codepoints from the unicode plane, >> representing natural language characters (at least in the simplistic >> view, I'm not talking about surrogates). These can be encoded to >> different binary storage representations, of which ascii is (a common) one. >> >>> What I am looking for is a general way to just copy the raw data >>> from a "string" object to a "byte" object without any attempt to >>> "decode" or "encode" anything ... >> There is "logically" no raw data in the string, just a series of >> codepoints, as stated above. You'll have to specify the encoding to use >> to get at "raw" data, and from what I gather you're interested in the >> latin-1 (or iso-8859-15) encoding, as you're specifically referencing >> chars >= 0x80 (which hints at your mindset being in LATIN-land, so to >> speak). > > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. Where is the data coming from? Files? In that case, it sounds like you will want to decode/encode using 'latin-1', as the bulk of your text is plain ascii and you don't really care about the upper-ascii chars. ~Ethan~