9

The python statvfs module was marked as deprecated since python 2.6 and it's now removed since python 3.0. I haven't been able to figure out what apps are supposed to use if they want to get information about a disk, specifically how to check the capacity and free space of a given path. Anybody have any idea? This is on os x, if that makes a difference, although being cross platform would be a plus.

Franklin Piat
  • 3,952
  • 3
  • 32
  • 45
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146

2 Answers2

11

It appears that only the module that contains the constants for sequential access is being deprecated.

Doing

x = os.statvfs('/')
x.f_favail 

will still work.

Sidenote: according to the docs, this function is only available on unix based platforms. So OSX and linux variants are fine, as is freeBSD and others, but windows won't be.

Bryan McLemore
  • 6,438
  • 1
  • 26
  • 30
  • 1
    It seems Android also doesn't support os.statvfs() –  Nov 15 '14 at 22:11
  • 1
    `os.statvfs` was **removed in python3**. It was deprecated since python 2.6, see [python statvfs doc](https://docs.python.org/2/library/statvfs.html). – Franklin Piat Nov 08 '15 at 14:41
  • 1
    @FranklinPiat to clarify, the `statvfs` module is deprecated, but in the `os` module, the `os.statvfs()` function is [still valid for Unix](https://docs.python.org/3/library/os.html#os.statvfs). Deprecated: `os.statvfs('/')[statvfs.F_FAVAIL]` Valid: `os.statvfs('/').f_favail`. But you do need [something else for Windows](https://stackoverflow.com/a/2372171/673991). – Bob Stein Jan 30 '20 at 00:59
0

I had the same question, it's os.fstatvfs(fd)

As of Python 3.3, this is equivalent to os.statvfs(fd). Availability: Unix.

mindonly
  • 54
  • 3