title: Use a Python Module to Open Explorer on a file
body: <p>I'm a python newbie, and I'm having some difficulty making a module out of some very useful code located at:  <a href="https://stackoverflow.com/questions/281888/open-explorer-on-a-file">Open explorer on a file</a>.</p>
  
  <p>I can't figure out what I am doing wrong.</p>
  
  <p>I get the following error messages:</p>
  
  <blockquote>
    <p>line 31: C:\Apps\E_drive\Python_win32Clipboard.pdf line 34: r'explorer
    /select, "C:\Apps\E_drive\Python_win32Clipboard.pdf"' Traceback (most
    recent call last):   File
    "P:\Data\VB\Python_MarcsPrgs\Python_ItWorks\Open_Win_Explorer_and_Select_File.py",
    line 42, in 
        Open_Win_Explorer_and_Select_Fil(filepath)       File "P:\Data\VB\Python_MarcsPrgs\Python_ItWorks\Open_Win_Explorer_and_Select_File.py",
    line 35, in Open_Win_Explorer_and_Select_Fil
        subprocess.Popen(Popen_arg)   File "C:\Python27\lib\subprocess.py", line 679, in <strong>init</strong>
        errread, errwrite)   File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
        startupinfo) WindowsError: [Error 2] The system cannot find the file specified</p>
  </blockquote>
  
  <p>here's my module:</p>
  
  <pre><code>"""
  Open Win Explorer and Select File
  # "C:\Apps\E_drive\Python_win32Clipboard.pdf"
  """
  import sys
  import os, subprocess, pdb
  
  def fn_get_txt_sysarg():
      "Harvest a single (the only) command line argument"
      # pdb.set_trace()
      try:
          arg_from_cmdline = sys.argv[1]
          arg_from_cmdline = str(arg_from_cmdline)
  
      except:
          this_scriptz_FULLName = sys.argv[0]
  
          ErrorMsg = "Message from fn_get_txt_sysarg() in Script (" + this_scriptz_FULLName + '):\n' \
          + "\tThe Script did not receive a command line argument (arg_from_cmdline)"
  
      returnval = arg_from_cmdline
  
      return returnval
  
  
  def Open_Win_Explorer_and_Select_Fil(filepathe):
      # harvested from... https://stackoverflow.com/questions/281888/open-explorer-on-a-file
      #import subprocess 
      #subprocess.Popen(r'explorer /select,"C:\path\of\folder\file"') 
      f = str(filepathe)
      print "line 31: " + f
      Popen_arg = "r'explorer /select, " + '"' + f + '"' + "'"
      Popen_arg = str(Popen_arg)
      print "line 34: " + Popen_arg
      subprocess.Popen(Popen_arg)
  
  
  if __name__ == '__main__': 
  
      filepath = fn_get_txt_sysarg()
  
      Open_Win_Explorer_and_Select_Fil(filepath)    
  </code></pre>
  
  <p>Any help would be much appreciated.</p>
  
  <pre><code>             Marceepoo
  </code></pre>