os.path.getsize报告一个文件大小与L在结尾,为什么? [英] os.path.getsize reports a filesize with an L at the end, why?
问题描述
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。
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.
如果我没有将其添加到字典中,则运行它,它返回文件大小为 392
。
If I run it without adding it to a dictionary, it comes back with the filesize as 392
.
推荐答案
这仅显示或以交互模式或当您通过 repr()
获取字符串表示。正如zigg所写,你可以简单地忽略它。请考虑一个实现细节。在正常int和long int之间做出区别很重要的时候,它可能是有用的。在Python 3中,例如没有 L
。 int是int,不管多大:
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 no L
, for example. The int is int no matter how big:
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
>>>
请注意Python 2.7中的 L
没有相似的Python 3.2。
Notice the L
by Python 2.7, but nothing similar by Python 3.2.
这篇关于os.path.getsize报告一个文件大小与L在结尾,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!