File Handling in Python

 


Python File Handling


File handling is always an important part of any application on large scale.

Python supports four modes to open a File.
  • "r"    to read, open the file in read mode, return file not found error if file not found
  • "w"   : to write, open a file in write mode with existing data erased in file, creates file if file not exist
  • "a"    : to append, open file in append keeping existence data as it is, creates file if not exist.
  • "x"    : to create, creates a specified file, throws file exist error if file exists.

All four open mode supports 2 additional parameter to select type of file
  • "t"   : text file, to create, read, open file text file (this is default mode)
  • "b"  : binary file, to create binary files or files to store image.


Default Mode : 
  • By default the mode is "rt", open text file in read mode.
  • Return error if file does not exist.


File Handling>>>>>





Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India