Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:48:45+00:00 2026-06-14T20:48:45+00:00

Has HEX codec been excluded from Python 3.3? When I write the code >>>

  • 0

Has HEX codec been excluded from Python 3.3? When I write the code

>>> s="Hallo"
>>> s.encode('hex')
Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    s.encode('hex')
LookupError: unknown encoding: hex

What does that mean? I know about binascii.hexlify() but still .encode() method is nice!

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:48:46+00:00Added an answer on June 14, 2026 at 8:48 pm

    No, using encode() to hexlify isn’t nice.

    The way you use the hex codec worked in Python 2 because you can call encode() on 8-bit strings in Python 2, ie you can encode something that is already encoded. That doesn’t make sense. encode() is for encoding Unicode strings into 8-bit strings, not for encoding 8-bit strings as 8-bit strings.

    In Python 3 you can’t call encode() on 8-bit strings anymore, so the hex codec became pointless and was removed.

    Although you theoretically could have a hex codec and use it like this:

    >>> import codecs
    >>> hexlify = codecs.getencoder('hex')
    >>> hexlify(b'Blaah')[0]
    b'426c616168'
    

    Using binascii is easier and nicer:

    >>> import binascii
    >>> binascii.hexlify(b'Blaah')
    b'426c616168'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This question has been rewritten from an issue with NSTextView following some further research)
Whenever a URL that has %2F which is the hex code for / is
A UUID in the form of b2f0da40ec2c11e00000242d50cf1fbf has been transformed (see the following code
This is a follow on from: Python - Converting Hex to INT/CHAR I now
Getting the (hex) error code from an IOException, or regular Exception! Is this possible?
I've seen binary and hex used quite often but never octal. Yet octal has
Has anyone ever used the hidden class PackageParser in Android source code with java
Has anyone met this error? Right now i am trying to do switch from
Is there a way to follow a program's execution through DLL code in hex?
This has been bugging me for a few days now. I'm trying to migrate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.