Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Examining File Contents

Let’s take a look at examining file contents. One common problem that you may face is the encoding of the byte data. An encoding is a translation from byte data to human readable characters.

This is typically done by assigning a numerical value to represent a character. The two most common encodings are the ASCII and UNICODE Formats. ASCII can only store 128 characters, while Unicode can contain up to 1,114,112 characters.

ASCII is a subset of Unicode (UTF-8), meaning that ASCII and Unicode share the same numerical to character values. It’s important to note that parsing a file with the incorrect character encoding can lead to failures or misrepresentation of the character.

For example, if a file was created using the UTF-8 encoding, and you try to parse it using the ASCII encoding, if there is a character that is outside of those 128 values, then an error will be thrown.

Comments & Discussion

Abby Jones on July 10, 2019

I am getting an I/O error on the closed audio.mp3 file. Any ideas?

Darren Jones RP Team on July 16, 2019

Hi Abby. Do you have more info to share on your I/O error - the code you’re using or the error? The more info you give, the more chance of getting to the bottom of the problem.

Deepak on July 21, 2019

the input() in the file reading changed the for loop to except to hit enter to dispaly next line ?

Darren Jones RP Team on July 23, 2019

input() in the loop was present just to allow the user to press ENTER to continue or X + ENTER to exit the loop - just a simple way of making it interactive.

Become a Member to join the conversation.