Character Encodings : 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.
open file in python is done by invoking the open() built-in function. open() has a single required argument that is the path to the file. open() has a single return, the file object.
reader = open('dog_breeds.txt')
try:
# Further file processing goes here
finally:
reader.close()
with open('dog_breeds.txt') as reader:
# Further file processing goes here
with open('dog_breeds.txt', 'r') as reader:
# Further file processing goes here
‘rb’ or ‘wb’» Open in binary mode (read/write using byte data)
.writelines(seq) » This writes the sequence to the file. No line endings are appended to each sequence item. It’s up to you to add the appropriate line ending(s).
x = 10
if x > 5:
raise Exception('x should not exceed 5. The value of x was: {}'.format(x))