Learn Before
  • Built-In Functions in Python

open()

The built-in open() function can open a file in a given directory and return a corresponding file object to it.

Parameters for open are as follows:

  • file: object representing file path
  • mode (optional): mode when opening file, including reading ('r'), writing ('w'), exclusive creation ('x'), appending ('a'), text ('t'), binary ('b'), and read/write ('+') modes
  • errors (optional): string specifying how to handle encoding/decoding errors
  • newline​ (optional): how newlines mode works (available values: None, ' ', '\n', 'r', and '\r\n'
  • closed (optional): must be True (default); if given otherwise, an exception will be raised
  • opener (optional): a custom opener; must return an open file descriptor

Some methods for file reading and editing, including open().write and open().read.

0

1

4 years ago

Tags

Python Programming Language

Data Science

Related
  • print()

  • input() Function

  • id()

  • range()

  • abs() function

  • bin()

  • bool()

  • len()

  • round()

  • pow(x, y, z)

  • chr(i)

  • slice()

  • hex()

  • oct()

  • int()

  • str()

  • float()

  • ord()

  • open()