[go: up one dir, main page]

0% found this document useful (0 votes)
25 views9 pages

Unit III File Handling , Classes_Part1

Files are named locations on disk used to store related information, which can be accessed from various sources like keyboard or databases. There are two main types of files: text files, which contain sequences of lines, and binary files, which can store various data types including images and audio. File handling in Python involves operations such as opening, reading, writing, and closing files, with different modes available for these operations.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Unit III File Handling , Classes_Part1

Files are named locations on disk used to store related information, which can be accessed from various sources like keyboard or databases. There are two main types of files: text files, which contain sequences of lines, and binary files, which can store various data types including images and audio. File handling in Python involves operations such as opening, reading, writing, and closing files, with different modes available for these operations.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Unit III

BCA 4rth Semester


FILES
 File is a named location on disk to store related information.
 Data for python program can come from difference sources such
as keyboard, text file, web server, database.
 To store data permanently. Stored non-volatile memory.
 We can retrieve whenever required.
 Ex: Student.txt
 Two types of files
 Text files : A text file can be a sequence of
lines without any images, tables etc. Ex: text,
json.
 Binary files : Files are capable of storing text,
image, video, audio, database files, etc which
contains the data in the form of bits.
 File Handling:
 Opening files
 Reading files
 Writing files
 Closing files
age =input(“Enter your age”)
print(age)
 Above statement age will be lost once application
is closed.
 To store data permanently using files
age =input(“Enter your age”)
f=open(“data.txt”,’w’)
f.write(age)
f.close()
statement
 automatically closes the file.
 syntax:
 open(“filename “, mode=‘r’, buffering,
encoding=None, errors=None, newline=None,
closefd=True)
 f= open(“filename”, “mode”)
//mode : reading, writing, appending etc.

 If mode is not specified , by default, open( ) uses


mode ‘r’ for reading
files in python
 collection of data stored on a secondary storage device.
 RAM(volatile)
 ROM(non-volatile)
 file path:
every file identified by its path.
relative path and absolute path.
file path
 absolute path : always contains the root to the
complete dictionary.
 relative path:start with respect to the current working
directory.
 example:
c:\students\undergraduate\BTech_cs.dcox
why we need file?
types of file

You might also like