Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

FILE OBJECTS

IN PYTHON!
 A file is a collection of data stored in the secondary memory
 Files are used for storing information that can be processed by
the programs
What is a file  THERE ARE TWO TYPES OF FILES:

and types of  1.Text Files: Text files consists of human readable characters ,

files? which can be opened by any text editor


 2.Binary Files: Binary file are made up of non-human readable
characters and symbols , which require specific programs to
access its contents
 Python file object provides methods and attributes to access
and manipulate file.
What is a file
 Using file objects we can read or write any files.
object?
 File Objects can be used to access not only normal disk files ,
but also any other types of file that uses abstraction
 The open built in function is used to open a file
and it returns as file object that is then used
for all succeeding operations on the file.
open()  Syntax :
file.object =open(filename , access_mode)
>>f=open(‘cyber.txt’,’r’)
data=f.read()
print(data)
Here read() method is used to read bytes directly into a string reading at most the number od
bytes

You might also like