title: What is the pythonic way to get file handles from the command line with relative or absolute paths?
body: <p>When I write a command line script in python, I'm assuming that it can be invoked from anywhere. This seems to cause incongruity when I want to pass a list of files into the script.</p>
  
  <p>Passing the files using a list or wildcard arguments (whether expanded by bash under *nix or glob.glob with Windows) will return either a relative path or an absolute one, depending on how the file path was described, but this seems to give two different behaviors which have to either be checked or harmonized.</p>
  
  <p>If the script is in the same directory as the files to be imported, this isn't really a problem, but if the script is in a different directory, it seems like you need to grab the absolute path first:</p>
  
  <pre><code>import os,sys,glob
  
  for arg in sys.argv[1:]:
      file_list = glob.glob(arg)
      for fn in file_list:
          print("File Reference: {}".format(os.path.abspath(fn)))
  </code></pre>
  
  <hr>
  
  <pre><code>&gt; pwd
  /Users/user1/Desktop/script_dir/
  
  &gt; cd ~/Desktop
  
  &gt; script_dir/test.py test_dir/*.csv /Users/user1/Desktop/test_dir/*.txt
  
  File Reference: /Users/user1/Desktop/test_dir/temp1.csv
  File Reference: /Users/user1/Desktop/test_dir/temp2.csv
  File Reference: /Users/user1/Desktop/test_dir/temp1.txt
  File Reference: /Users/user1/Desktop/test_dir/temp2.txt
  </code></pre>
  
  <p>Assuming the program continued on to do something with the files, it would then manipulate them by absolute path. Is this the correct thing to do here? It seems weirdly klugy, and I can seem to find any references that lay this out.</p>