为什么os.path.getsize()返回一个10GB文件的负数? [英] Why does os.path.getsize() return a negative number for a 10gb file?
问题描述
我正在使用函数 os.path.getsize()
,它以字节为单位给出了文件的大小。
所以任何人都可以告诉我为什么会发生这种情况?
这是我的代码:
import os
ospathsize = os。 path.getsize('/ home / user / Desktop / test1.nrg')
print(ospathsize)
Python中的POSIX大文件支持指出,如果Python在Linux上可用,通常应该使用大文件支持。它也建议尝试和命令行配置Python
$ b
CFLAGS =' - D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS = 64'OPT = - g -O2 $ CFLAGS\
./configure
最后,引用< stat页面的手册页 / code>系统调用:
当在32位平台上编译的应用程序没有<对于大小超过
(1 <= code>)的文件,code> -D_FILE_OFFSET_BITS = 64
调用stat() 31)-1
位。
(我相信最后一个单词应该是bytes。) / p>
I am using the function os.path.getsize()
which gives the size of the file in bytes.
As my one file size is 10gb it give me size in negative(bytes).
so can anyone give me any idea why this happen?
This is my code:
import os
ospathsize = os.path.getsize('/home/user/Desktop/test1.nrg')
print (ospathsize)
Your Linux kernel obviously has large file support, since ls -l
works correctly. Thus, it's your Python installation that is lacking the support. (Are you using your distribution's Python package? What distribution is it?)
The documentation on POSIX large file support in Python states that Python should typically make use of large file support if it is available on Linux. It also suggests to try and configure Python with the command line
CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
./configure
And finally, quoting the man page of the stat
system call:
This can occur when an application compiled on a 32-bit platform without
-D_FILE_OFFSET_BITS=64
callsstat()
on a file whose size exceeds(1<<31)-1
bits.
(I believe the last word should be "bytes".)
这篇关于为什么os.path.getsize()返回一个10GB文件的负数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!