9.2. File Built-in Function [open()]

As the key to opening file doors, the open() built-in function provides a general interface to initiate the file input/output (I/O) process. open() returns a file object on a successful opening of the file or else results in an error situation. When a failure occurs, Python generates or raises an IOError exception—we will cover errors and exceptions in the next chapter. The basic syntax of the open() built-in function is:

						file_object = open(file_name, access_mode='r', buffering=-1)

The file_name is a string containing the name of the file to open. It can be a relative or absolute/full pathname. The access_mode optional variable is also a string, consisting of a set of flags indicating which mode to open ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.