Upload
prashantkhedekar
View
218
Download
0
Embed Size (px)
Citation preview
7/26/2019 Amit Perfect 1
1/13
Opening And Closing Filein Python
Amit S. Ashtikar
Roll No : 861
7/26/2019 Amit Perfect 1
2/13
Contents
Definition Of File
Types Of Files
Operations on File
Opening A File
Closing A File
Detecting The Writing Data To A File
7/26/2019 Amit Perfect 1
3/13
Definition Of File
A File is a collection of data stored on a
computers disk.
Information can be saed to files and later
reused.
7/26/2019 Amit Perfect 1
4/13
Types Of Files
There are three types of files.
!" #e$uential Access Files
%"&andom Access Files
'" (inary Files
7/26/2019 Amit Perfect 1
5/13
Sequential Access File
A se$uential access file is a stream of data that
must be read from its beginning to its end.
To read a record that is stored in the middle or at
the end of se$uential access file an application
must read all the records in the file before it.
7/26/2019 Amit Perfect 1
6/13
Random Access File
In &andom access file &ecords must be identical
in length and may be accessed in any order.
An application may immediately )ump to any
record in a random access file *ithout first
reading the preceding records.
7/26/2019 Amit Perfect 1
7/13
Binary File
In binary file data is stored in binary form not in
plain te+t.
The records in binary files may ary in length.
(inary files are usually smaller than te+t files but
user cannot ie* their contents *ith te+t editor.
7/26/2019 Amit Perfect 1
8/13
Binary File
In binary file data is stored in binary form not in
plain te+t.
The records in binary files may ary in length.
(inary files are usually smaller than te+t files but
user cannot ie* their contents *ith te+t editor.
7/26/2019 Amit Perfect 1
9/13
Opening A File
Open statement is used to open a file.
Open*filename*for mode as filenum!er "len#recordlength$
Synta% &
7/26/2019 Amit Perfect 1
10/13
Contd''
When a se$uential file is opened , isual basic
creates a file buffer.
A file buffer is a small holding section of memory
that data is first *ritten to.
7/26/2019 Amit Perfect 1
11/13
Closing A File
Close statement is used to close a file.
Close "filenum!erlist$
Synta% &
In synta+, Filenumberlsit is one or more file numbers separated by commas.
The - symbol must appear *ith each file number.
+ample close -!,-%
7/26/2019 Amit Perfect 1
12/13
Opening a file in append modeWhen a file is opened in append mode data is *ritten
to the end of the file.
If the file is already e+ist its contents are not erased.
If the file does not e+ist it is created.
Open filename for append as (
Synta%
7/26/2019 Amit Perfect 1
13/13
Than)*ou++++++++