title: How to terminate external program or window using python
body: <p>I am trying to close the program, in this case spotify, but I am keep getting semantic mistake. Here is my code:</p>
  
  <p>sup_programs.txt</p>
  
  <pre><code>{ 
  'spotify': ['C:/Users/Daniiar/AppData/Roaming/Spotify/Spotify.exe']
  }
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>class Path(object):
      import ast
      sup_programs_txt = open('sup_programs.txt', 'r')
      s_p = sup_programs_txt.read()
      paths = ast.literal_eval(s_p)
      sup_programs_txt.close()
  paths = Path().paths
  program_name = 'spotify'
  
  
  def open_program(path_name):
      import subprocess
      subprocess.Popen(path_name)
      open_program(paths[program_name])
  
  
  def close_program(path_name):
      import subprocess
      p = subprocess.Popen(path_name)
      p.terminate()
  
  
  yes = input(" ... ")
  if 'close' in yes or 'yes' in yes:
      close_program(paths[program_name])
  else:
      print('too bad')
  </code></pre>
  
  <p>I used kill() and terminate() neither of them have worked and os.system('TASKKILL ')
  Is there any other methods or am using existing ones incorrectly?</p>
  
  <p>BTW, I am using windows 10 and python 3.5 . Thank you for your help</p>