title: Reading a text document and converting it to a string
body: <p>I'm trying to make a basic script that reads a specified text document, asks for a string of characters to replace and what to replace it, then saves it:</p>
  
  <pre><code>from tkinter import Tk, filedialog
  from tkinter.filedialog import askopenfilename
  
  Tk().withdraw()
      def OpenFile():
      fileName = askopenfilename(initialdir="C:/Users", filetypes = (("Text File", "*.txt"),("All Files","*.*")), title = "Open a document.")
      with open(fileName, 'r') as f:
          textFile = f.read()
  
  OpenFile()
  print(textFile)
  </code></pre>
  
  <p>There's an error when running the script and selecting a file</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\****\Documents\Python\Find and Replace\replace.py", line 11, in &lt;module&gt;
  print(textFile)
  NameError: name 'textFile' is not defined
  </code></pre>