Table of Contents
show
File Open
- A file can be opened using built – in open( ) function
- No module is required
- The file should be exist in the same directory as python program files else full path name has to be specified as file name
- The open() function takes two parameters; filename and mode
There are four different methods (modes) for opening a file,
In addition, one can specify if the file should be handled as binary or text mode
Syntax
Fileobject = open(filename,access_mode)
filename is the name of the file to open, access_mode is the method in which we open to open. It is optional. If not specified, the default value is “rt”
The syntax above is same as
Fileobject = open(filename,”rt”)
- Because “r” for read and “t” for text are default values
- If the file does not exist, then it produces error
Views: 1