Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28199
| 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!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'encode': 0.09; 'notation': 0.09; 'subject:number': 0.09; 'encoding': 0.15; '-tkc': 0.16; '3.1.3': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'least,': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'syntax.': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; "skip:' 10": 0.30; 'dies': 0.33; 'to:addr:python-list': 0.33; 'whatever': 0.35; 'subject:?': 0.35; 'skip:u 20': 0.36; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'skip:6 10': 0.63; 'subject:get': 0.81; 'received:50.22': 0.84; 'to:name:python': 0.84; 'do:': 0.91 |
| Date | Fri, 31 Aug 2012 22:50:33 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 |
| MIME-Version | 1.0 |
| To | Python <python-list@python.org> |
| Subject | Re: how to get character hex number? |
| References | <CA+YdQ_66ap1tQCRibdkntGvHqE1sp+Nv_kK2iiKh50GoAa=K6Q@mail.gmail.com> <50417631.1080508@tim.thechases.com> <CA+YdQ_6s1dj_ewZR0wT-WAd1uCwR8dhDDusbnkot4p5DkgmE5w@mail.gmail.com> |
| In-Reply-To | <CA+YdQ_6s1dj_ewZR0wT-WAd1uCwR8dhDDusbnkot4p5DkgmE5w@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| X-Source | |
| X-Source-Args | |
| X-Source-Dir | |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19.1346471360.27098.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346471360 news.xs4all.nl 6916 [2001:888:2000:d::a6]:48466 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28199 |
Show key headers only | View raw
On 08/31/12 22:41, contro opinion wrote:
>>>>>> u"english".encode("utf-8")
>>> 'english'
>>>>>> u"english".encode("ascii")
>>> 'english'
>>>
>>> how can i get 656e676c697368 in encode method?
>>
>> At least in 2.x, you can do:
>>
>> >>> u"english".encode("hex")
>> '656e676c697368'
>
> how about in python3.0?
Well, in 3.1.3 at least, using the u"..." notation dies on me with
an invalid syntax. However, as Ian suggests, you can do
my_str = "english"
"".join("%02x" % c for c in my_str.encode("ascii"))
or whatever other encoding you want instead of "ascii".
-tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how to get character hex number? Tim Chase <python.list@tim.thechases.com> - 2012-08-31 22:50 -0500
csiph-web