为什么os.path.getsize()返回一个10GB文件的负数? [英] Why does os.path.getsize() return a negative number for a 10gb file?

查看:449
本文介绍了为什么os.path.getsize()返回一个10GB文件的负数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用函数 os.path.getsize(),它以字节为单位给出了文件的大小。



所以任何人都可以告诉我为什么会发生这种情况?



这是我的代码:

  import os 
ospathsize = os。 path.getsize('/ home / user / Desktop / test1.nrg')
print(ospathsize)


ls -l <​​/ code>能够正常工作,所以你的Linux内核显然有很大的文件支持。因此,这是你的Python安装缺乏支持。 (您是使用发行版的Python包吗?是什么发行版?)

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 calls stat() on a file whose size exceeds (1<<31)-1 bits.

(I believe the last word should be "bytes".)

这篇关于为什么os.path.getsize()返回一个10GB文件的负数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆