os.path.getsize reports a filesize with an L at the end, why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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('.')) |
每当这是跑,我得到的输出的
如果我运行它无adding它到一个字典,它是与filesize作为
只有在交互模式下或通过
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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中的
尾随的
几乎可以肯定,您不必担心剥离尾随的
这是正确的,但如果你真的需要你可以做int()函数,它也适用于大整数。
1 2 3 4 5 | Python 2.7.3 (default, Jul 24 2012, 10:05:39) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 >>> import os >>> os.path.getsize('File3') 4099L |
但是,如果自动放入函数int():
1 2 | >>> int(os.path.getsize('File3')) 4099 |