Untitled

You might also like

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

Python Modules

Files are named locations on disk to store related


information.
They are used to permanently store data in a non-
volatile memory (e.g. hard disk).
Since Random Access Memory (RAM) is volatile
(which loses its data when the computer is turned off).
The file handling plays an important role when the
data needs to be stored permanently into the file. A file
is a named location on disk to store related
information. We can access the stored information
(non-volatile) after the program termination.
File operations
File operations:
Open a file
Read or write (perform operation)

Close the file


Opening a file
Python provides an open() built-in function that accepts
two arguments, file name and access mode in which the
file is accessed.
The function returns a file object which can be used to
perform various operations like reading, writing, etc.
Opening a file
Python provides an open() built-in function that accepts
two arguments, file name and access mode in which the
file is accessed.
The function returns a file object which can be used to
perform various operations like reading, writing, etc.

>>> f = open(“stu.txt")# open file in current directory


>>> f = open(“Z:/Python/stu.txt") #specifying full path
Example Program

You might also like