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 7802809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:22:06+00:00 2026-06-02T01:22:06+00:00

I am converting a Python 2 program to Python 3 and I’m not sure

  • 0

I am converting a Python 2 program to Python 3 and I’m not sure about the approach to take.

The program reads in either a single email from STDIN, or file(s) are specified containing emails. The program then parses the emails and does some processing on them.

SO we need to work with the raw data of the email input, to store it on disk and do an MD5 hash on it. We also need to work with the text of the email input in order to run it through the Python email parser and extract fields etc.

With Python 3 it is unclear to me how we should be reading in the data. I believe we need the raw binary data in order to do an md5 on it, and also to be able to write it to disk. I understand we also need it in text form to be able to parse it with the email library. Python 3 has made significant changes to the IO handling and text handling and I can’t see the “correct” approach to read the email raw data and also use the same data in text form.

Can anyone offer general guidance on this?

  • 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-02T01:22:07+00:00Added an answer on June 2, 2026 at 1:22 am

    The general guidance is convert everything to unicode ASAP and keep it that way until the last possible minute.

    Remember that str is the old unicode and bytes is the old str.

    See http://docs.python.org/dev/howto/unicode.html for a start.

    With Python 3 it is unclear to me how we should be reading in the data.

    Specify the encoding when you open the file it and it will automatically give you unicode. If you’re reading from stdin, you’ll get unicode. You can read from stdin.buffer to get binary data.

    I believe we need the raw binary data in order to do an md5 on it

    Yes, you do. encode it when you need to hash it.

    and also to be able to write it to disk.

    You specify the encoding when you open the file you’re writing it to, and the file object encodes it for you.

    I understand we also need it in text form to be able to parse it with the email library.

    Yep, but since it’ll get decoded when you open the file, that’s what you’ll have.


    That said, this question is really too open ended for Stack Overflow. When you have a specific problem / question, come back and we’ll help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To all: I have a question about converting from string to float in python
I am converting some code from another language to python. That code reads a
I am converting to python and numpy from IDL (kinda like Matlab). This is
How would I go about using Python to read the frequency peaks from a
This is a follow on from: Python - Converting Hex to INT/CHAR I now
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
I am trying to learn web programming in python. I am converting my old
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I am converting a script from PHP to ASP.net C#. In PHP, i could
I am trying to port a python program to c#. Here is the line

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.