import os, sys
def crawlLocalDirectories(directoryToCrawl):
crawledDirectory = [os.path.join(path, subname) for path, dirnames, filenames in os.walk(directoryToCrawl) for subname in dirnames + filenames]
return crawledDirectory
print crawlLocalDirectories('.')
dictionarySize = {}
def getSizeOfFiles(filesToMeasure):
for everyFile in filesToMeasure:
size = os.path.getsize(everyFile)
dictionarySize[everyFile] = size
return dictionarySize
print getSizeOfFiles(crawlLocalDirectories('.'))
Whenever this is ran, I get the output of {'example.py':392L}
, why? What's an L? I don't want to have to strip the L off at the end.
If I run it without adding it to a dictionary, it comes back with the filesize as 392
.
The trailing
L
means you have along
. You actually always have it, butprint
ing adict
will show printable representations of the values, including theL
notation; however, printing along
itself shows only the number.You almost certainly don't need to worry about stripping off the trailing
L
; you can use along
in all your calculations just as you would use anint
.This is only displayed or in interactive mode or when you get the string representation via
repr()
. As zigg wrote, you can simply ignore it. Consider this an implementation detail. It was probably usefull in time when it was important to make a difference between normal int and long int. In Python 3, there is noL
, for example. The int is int no matter how big:Notice the
L
by Python 2.7, but nothing similar by Python 3.2.It' true the pepr's answer but if you realy need you can do the int() Function, it works also on big integers
BUT if you put in the Function int() Automagically: