title: Python strange NameError for def
body: <p>My code isnt too long so here is the whole program, when i run it it says </p>
  
  <blockquote>
    <p>NameError: name 'xmlp' is not defined for line 88</p>
  </blockquote>
  
  <p>It seems too simple, whats happening here ?
  It worked just before i took extract and copied it and renamed it to <code>xmlp</code>, i then made a new button to execute it but then it broke, why does it say its not defined when it very clearly is ?</p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  from tkinter import filedialog
  import tkinter as tk
  
  import xml.etree.ElementTree as ET
  
  interface = tk.Tk()
  interface.geometry("900x500")
  interface.title("Text display")
  
  T = tk.Text(interface, height=20, width=150)
  T.grid(column=1, row=2, columnspan=3)
  
  def openfile(): # open your file and load it into the text widget
  
      global filename
      filename = filedialog.askopenfilename()
      print(filename)
      file = open(filename)
      global txt
      txt = file.read()
  
      T.delete('1.0', END)
      T.insert(tk.END, txt)
  
      return txt
  
  def extract(): # take the opened file and write it to a text file
      open('somefile.txt', 'w').close()
  
      root = ET.fromstring(txt)
  
      str_params = root.findall('.//parameter/[parameterid="str"]')
      for param in str_params:
          if param.find('./name').text == 'Text':
              print(format(param.find('./value').text))
              with open('somefile.txt', 'a') as the_file:
                  the_file.write(format(param.find('./value').text))
                  the_file.write("\n")
  
      exportFileDir = open('somefile.txt',)
  
      txtExport = exportFileDir.read()
  
      T.delete('1.0', END)
      T.insert(tk.END,txtExport)
  
      def xmlp():  # take the opened file and write it to a text file
          open('somefile.txt', 'w').close()
  
          root = ET.fromstring(txt)
  
          str_params = root.findall('.//parameter/[parameterid="str"]')
          for param in str_params:
              if param.find('./name').text == 'Text2':
                  print(format(param.find('./value').text))
                  with open('somefile.txt', 'a') as the_file:
                      the_file.write(format(param.find('./value').text))
                      the_file.write("\n")
  
          exportFileDir = open('somefile.txt', )
  
          txtExport = exportFileDir.read()
  
          T.delete('1.0', END)
          T.insert(tk.END, txtExport)
  
  
  
  def file_save():
      f = filedialog.asksaveasfile(mode='w', defaultextension=".txt")
      if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
          return
      exportFileDir = open('somefile.txt')
  
      txtExport = exportFileDir.read()
  
      f.write(txtExport)
      f.close() # `()` was missing.
  
  button = ttk.Button(interface, text="Open text File", command=openfile)  # &lt;------
  button.grid(column=1, row=3, sticky = W)
  
  buttonex = ttk.Button(interface, text="Extract subtitles", command=extract)  # &lt;------
  buttonex.grid(column=2, row=3, sticky = W)
  
  buttonexp = ttk.Button(interface, text="X XML P", command=xmlp)  # &lt;------
  buttonexp.grid(column=2, row=4, sticky = W)
  
  buttonsv = ttk.Button(interface, text="Save as", command=file_save)  # &lt;------
  buttonsv.grid(column=3, row=3, sticky = W)
  
  interface.mainloop()
  </code></pre>