Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28199 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2012-08-31 22:50 -0500 |
| Last post | 2012-08-31 22:50 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: how to get character hex number? Tim Chase <python.list@tim.thechases.com> - 2012-08-31 22:50 -0500
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2012-08-31 22:50 -0500 |
| Subject | Re: how to get character hex number? |
| Message-ID | <mailman.19.1346471360.27098.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web