title: Undefined variable error, though it's defined in function
body: <pre><code>def append_customer(file_variable, fields):
  """
  -------------------------------------------------------
  Appends a customer record to a sequential file.
  -------------------------------------------------------
  Preconditions:
      file_variable - the file to search (file)
      fields - data to append to the file (list)
  Postconditions:
      The data in fields are appended to file_variable.
  -------------------------------------------------------
  """
  if os.path.exists(file_variable) == True:
      file = open(file_variable, "w", encoding="utf-8")
      file.seek(0)
      print("{0}".format(fields), file=file_variable)
  file.close()
  return
  </code></pre>
  
  <p>This is a function i wrote to append data to a file, the only error being that apparently "file_variable is undefined"... even though it's clearly defined by the function. I have no clue as to why this error is occurring.</p>