0% found this document useful (0 votes)
35 views13 pages

Opening and Closing File in Python: Amit S. Ashtikar

This document discusses opening and closing files in Python. It defines a file as a collection of data stored on a computer's disk that can be saved and reused. There are three types of files: sequential access files which must be read from beginning to end, random access files where records are identical in length and can be accessed in any order, and binary files where data is stored in binary rather than plain text. To open a file in Python, the open statement is used, while the close statement closes the file. Writing data to an open file first stores it in a file buffer in memory.

Uploaded by

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

Opening and Closing File in Python: Amit S. Ashtikar

This document discusses opening and closing files in Python. It defines a file as a collection of data stored on a computer's disk that can be saved and reused. There are three types of files: sequential access files which must be read from beginning to end, random access files where records are identical in length and can be accessed in any order, and binary files where data is stored in binary rather than plain text. To open a file in Python, the open statement is used, while the close statement closes the file. Writing data to an open file first stores it in a file buffer in memory.

Uploaded by

PrashantKhedekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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