4
def read_lines():
    readFileName = "readfile.txt"
    f = open(readFileName, 'r+')
    contents = f.read()
        ... # and so on 

read_lines()

When I run this, I get an error:

f = open(readFileName, 'r+')
UnboundLocalError: local variable 'open' referenced before assignment
NPE
  • 486,780
  • 108
  • 951
  • 1,012
RRR
  • 339
  • 1
  • 6
  • 15

1 Answers1

19

This means that further down in your function you create a variable called open:

open = ...

Rename it so that it doesn't clash with the built-in function.

NPE
  • 486,780
  • 108
  • 951
  • 1,012