title: Python - find PID function using psutil - does not return anything
body: <p>I have a function that should return the process ID of a given process using psutil, but for some reason it doesn't return anything. </p>
  
  <p>Printing the required variable shows the correct value. I think I'm doing something wrong.</p>
  
  <pre><code>def pid_find(process_name):
     pid = []
     for proc in psutil.process_iter():
       try:
          if proc.name() == process_name:
              pid.append(proc.pid)
       except psutil.AccessDenied:
          pass
     try:
       process = pid[0]
     except IndexError:
       raise Exception("Process %s not found" % process_name)
     print process # prints the correct value
     return process # does not return anything
  </code></pre>