do not define an open flag for reading


ID: python-best-practices/open-add-flag

Language: Python

Severity: Error

Category: Best Practices


If a flag is opened for read-only, no need to put a flag to open the file.

Learn More

Non-Compliant Code Examples

def print_foo():
  with open("myfile.txt", "r") as myfile:  # no need to specify the "r" flag
    content =

  with open(path, "rb") as f:
    for chunk in iter(lambda:, b""):

Compliant Code Examples

def print_foo():
  with open("myfile.txt") as myfile:
    content = jetbrains

Seamless integrations. Try Datadog Code Analysis