How to read a number of characters from a text file using Python?

To read a file’s contents, you can call, which reads some quantity of data and returns it as a string. size is an optional numeric argument. When size is omitted or negative, the entire contents of the file will be read and returned. Otherwise, at most size bytes are read and returned. If the end of the file has been reached, will return an empty string ("").

So if you want to read 10 ASCII characters, you can simply pass 10 as the argument.

For example

>>> f = open('my_file', 'r')
>>> print(
Hello worl
>>> f.close()