How is a file read using a limited buffer size using Python?

PythonServer Side ProgrammingProgramming

You can read a file using a limited buffer by specifying the buffer size in the read function. It takes the number of bytes you want to read from the current position of the pointer in the file. 

example

with open('my_file.txt', 'r') as f:
    print(f.read(10))  # Read and print 10 bytes

Output

This will give the output −

Hello worl

If the file contents were Hello world!

raja
Published on 28-Dec-2017 06:25:51
Advertisements