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('.'))
每当运行时,我都会得到输出{'example.py':392L}
, 为什么? L是什么?我不想最后把 L 去掉。
如果我运行它而不将其添加到字典中,它会返回文件大小为392
.
这仅在交互模式下或当您通过获取字符串表示形式时显示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
>>>
注意L
Python 2.7 与此类似,但 Python 3.2 没有类似的情况。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)