You are on page 1of 13

Opening And Closing File

in Python

Amit S. Ashtikar
Roll No : 861

Contents
Definition
Types

Of File

Of Files

Operations

on File

Opening A File

Closing A File

Detecting The Writing Data To A File

Definition Of File
A

File is a collection of data stored on a

computers disk.
Information

reused.

can be saved to files and later

Types Of Files
There

are three types of files.

1)

Sequential Access Files

2)

Random Access Files

3)

Binary Files

Sequential Access File


A

sequential 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 sequential access file an application


must read all the records in the file before it.

Random Access File


In

Random access file Records must be identical

in length and may be accessed in any order.


An

application may immediately jump to any

record in a random access file without first


reading the preceding records.

Binary File
In

binary file data is stored in binary form not in

plain text.
The

records in binary files may vary in length.

Binary

files are usually smaller than text files but

user cannot view their contents with text editor.

Binary File
In

binary file data is stored in binary form not in

plain text.
The

records in binary files may vary in length.

Binary

files are usually smaller than text files but

user cannot view their contents with text editor.

Opening A File
Open

statement is used to open a file.

Syntax :
Open*filename*for mode as # filenumber [len=recordlength]

Contd..
When

a sequential file is opened , visual basic

creates a file buffer.


A

file buffer is a small holding section of memory

that data is first written to.

Closing A File
Close

statement is used to close a file.

Syntax :
Close [filenumberlist]

In syntax, Filenumberlsit is one or more file


numbers separated by commas.
The

# symbol must appear with each file number.

Example

close #1,#2

Opening a file in append mode


When

a file is opened in append mode data is written

to the end of the file.


If

the file is already exist its contents are not erased.

If

the file does not exist it is created.


Syntax

Open filename for append as #1

Thank

You !!
!!!!!!

You might also like