Unformatted text preview:

Coding and Decoding in Python This involves understanding how data is stored in a computer and using new terms such as bytes and byte strings We will be using utf8 encoding which is a universal standard for encoding text in Python First we need to create a Python file and a text file The text file will contain text encoded in utf8 We will use the Python file to encode and decode each line of the text file Creating Files The Main Function We will create a main function that will read each line of the text file and encode and decode it This function will call another function called print line which we will create later We will use an if statement to check if a line exists in the text file If it does we will pass it to the print line function encode and decode it and return the byte string and utf string side by side Important Notes Make sure to use the correct spelling and no spaces when defining variables such as encoding and errors Strip is used to take each line as bytes Use the return statement to call the main function again The text file is a list of human languages encoded in utf8 Running the Code Once the code is written we can run it in the terminal using the command python encoding and decoding py utf8 text file txt This will encode and decode each line of the text file and display the byte string and utf string side by side


View Full Document

MIT 18 413 - Coding and Deco

Download Coding and Deco
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Coding and Deco and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Coding and Deco 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?