i

Python Programming

Python File Open

Introduction

The most amazing thing in python is file handling. We have capabilities with different packages to deal with the files. You will learn to know below with examples:

Opening Files

Let’s see how to use actual data files. Python provides functions and methods to manipulate files generally by default.

The open-Function

In Python we have open() built-in function to open any file.This function creates the file object, which would be utilized to call the other support methods associated with.

Syntax

File-object = open(file-name [, access-mode][, buffering])

Below is the parameter details:

• file-name − The file-name argument is the string value that contains name of file that you want to access.

• access-mode − The access-mode determines mode in which file has to be opened, i.e., read / write / append, etc. A complete list of the possible values is given below. This is an optional parameter and default file-access mode is read (r).

• buffering − If buffering value is set to 0, no buffering happens. If the buffering value is 1, the line buffering performed while accessing a file. If you specify buffering value as an integer greater than 1, then buffering action is performed with indicated buffe-size. If negative buffer size is system default(default behavior).