You are here : python_2ososread - os


The method read() reads at most n bytes from file desciptor fd, return a string containing the bytes read. If the end of file referred to by fd has been reached, an empty string is returned.

  • fd -- This is the file descriptor of the file.

  • n -- These are n bytes from file descriptor fd.



# !/usr/bin/python

import os, sys
# Open a file
fd ="f1.txt",os.O_RDWR)
# Reading text
ret =,12)
print ret

# Close opened file
print "Closed the file successfully!!"

Output / Return Value

Let us compile and run the above program, this will print the contents of file f1.txt:

This is test Closed the file successfully!!


Alternatives / See Also