Mat*_*hew 11 python directory dictionary filesize
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('.'))
Run Code Online (Sandbox Code Playgroud)
无论何时运行,我得到输出{'example.py':392L}
,为什么?什么是L?我不想在最后剥掉L.
如果我在没有将其添加到字典的情况下运行它,它将返回文件大小为392
.
pep*_*epr 13
这仅显示或以交互模式显示,或者通过时获得字符串表示repr()
.正如zigg所写,你可以简单地忽略它.考虑这个实现细节.在正常的int和long int之间做出区分很重要的时候,它可能很有用.例如,在Python 3中没有L
.无论多大,int都是int:
d:\>py
Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 100000000000000000000000000000000000000000000
>>> a
100000000000000000000000000000000000000000000
>>> ^Z
d:\>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 100000000000000000000000000000000000000000000
>>> a
100000000000000000000000000000000000000000000L
>>>
Run Code Online (Sandbox Code Playgroud)
请注意L
Python 2.7,但Python 3.2没有类似的东西.