title: program running on IDLE but not through command line
body: <p>This is my code , let us call it  "example.py"</p>
  
  <pre><code>import traceback
  import sys
  import os
  import linecache
  
  
  try:
      data_files = [x[2] for x in os.walk(os.path.dirname(sys.argv[0]))]
      fileNameList = data_files[0]    # gets the list of files in the directory where example.py is present
      execfile("sample.py")
  
  except:
  </code></pre>
  
  <p>this program works perfectly when I run it through IDLE but gives me the following error when I run it through the command line</p>
  
  <pre><code>Traceback (most recent call last):
    File "example.py", line 15, in &lt;module&gt;
      fileNameList = data_files[0]
  IndexError: list index out of range
  </code></pre>
  
  <p>I can only assume it cannot get the list of files in the folder from the command line , I am new to python programming so I would be truly grateful if someone could solve this or atleast point where I am going wrong</p>