title: How to get all the filename and filesize in current directory in Python
body: <p>Hi I am working with a little script. I try to print all the files in the current directory and store the <code>filename:filesize</code> as <code>key:value</code> pairs to the <code>size_dir</code>.     </p>
  
  <pre><code>from os import listdir,environ
  from sys import argv
  from os.path import isfile,join
  import os
  
  size_limit = argv[1]
  my_path = "./"
  onlyfiles = [f for f in listdir(my_path) if isfile(join(my_path, f))]
  sizes = []
  size_dir = {}
  print size_limit
  for item in onlyfiles:
      print type(os.path.getsize(my_path+item))
      if os.path.getsize(my_path+item) &lt; size_limit:
          size_dir[item] = os.path.getsize(my_path+item)
  print(size_dir)
  </code></pre>
  
  <p>I run this program in my terminal by:</p>
  
  <pre><code>python THISFILENAME.py 300
  </code></pre>
  
  <p>As I expected, the size_limit received 300 from my input command. In the for loop, I set a if-statement to check whether the file exceeds the size_limit, if not then we add the file to the size_dir.
  However, when I print the size_dir out, I find that size_dir contains every file in my current directory, and this is not what I expected.</p>
  
  <p>Result:</p>
  
  <pre><code>{'dir_print.py': 825, 'argvdemo.py': 215, 'formatter.py': 404}
  </code></pre>
  
  <p>Any help is appreciated.</p>