Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!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.036 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'subject:data': 0.07; 'bytes.': 0.09; 'specific.': 0.09; 'subject:string': 0.09; 'python': 0.11; 'cc:addr:python-list': 0.15; 'received:74.208.4.195': 0.16; 'subject:changing': 0.16; 'string': 0.18; 'wrote:': 0.21; 'file.': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'convert': 0.23; 'cc:no real name:2**0': 0.26; 'cc:addr:python.org': 0.27; '3.x': 0.29; 'way?': 0.29; 'cc:2**0': 0.31; 'source': 0.31; 'usually': 0.32; 'subject: (': 0.33; 'hi,': 0.33; 'bytes': 0.33; 'encoding': 0.33; 'there': 0.35; 'subject:)': 0.36; 'but': 0.36; 'peter': 0.37; 'data': 0.38; 'something': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'back': 0.63; 'more': 0.63; 'simply': 0.65; 'header:Reply-To:1': 0.66; 'reply-to:no real name:2**0': 0.72; 'series': 0.80; '04:56': 0.84; 'davea': 0.84 Date: Wed, 28 Mar 2012 13:16:57 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19 MIME-Version: 1.0 To: Peter Daum Subject: Re: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Z55jx86afUb8PM0o/RxRi8n17fvaJ9NZ/m/VXpVVvzQ IdLMWcoLsaR6V41H1e9MRCMzCi/MeiRMvOjtHG8RMf7CsWalpa Ocld/XRJiNL2okA9IfvEQYVqZz7Anz0S4Q2bazR0BVXNmI5JED hfXlk6vLNKCvdF3mlfL8OZhcO3xKwEIa4q/0Uru73/d5gXsf9T ITakQpe2vr4OJMzTSxqKon9372nY/+iXcrDaQ6WU/CaXIaST/h KqK4xB0MLolwSZm2rIwcH/o+95FZqwMlwpDkVkypeprYH88tQv jQXH0D/05ZSG5GQ2Eyl5WKtJ64I6RIvjxjqxwUXfXiBaG7OXhv STHzDiGdutbjTqINEXd4= Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332955038 news.xs4all.nl 6854 [2001:888:2000:d::a6]:43494 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22286 On 03/28/2012 04:56 AM, Peter Daum wrote: > Hi, > > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") > > Regards, > Peter You needed to specify that you are using Python 3.x . In python 2.x, a string is indeed a series of bytes. But in Python 3.x, you have to be much more specific. For example, if that string is coming from a literal, then you usually can convert it back to bytes simply by encoding using the same method as the one specified for the source file. So look at the encoding line at the top of the file. -- DaveA