3

I have installed python 2.7 and trying to run below code which always gives error:

# !/usr/bin/python

import os, sys

stinfo = os.statvfs("C:\Tools")

And error comes as :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'statvfs'

Any clue to make it work?

Anthon
  • 69,918
  • 32
  • 186
  • 246
user2033758
  • 1,848
  • 3
  • 16
  • 16

2 Answers2

6

I'm assuming from your example file path that you're using Windows.

The os.statvfs() call is not supported in Windows. An attempt to add support was made, but was rejected.

You might find this answer helpful for possible solutions.

Community
  • 1
  • 1
  • +1 If one reads the python documentation one should always check the Availability statement :) – Christian Rapp Feb 26 '13 at 23:12
  • Yes, I am running on windows so i am getting error. Will that be posible, from windows os, I telnet to machine which is having linux os and there I issue this command (os.statvfs). Do you think this can be helpful to me before I put go and create telnet session and check that?? – user2033758 Feb 26 '13 at 23:25
  • @user2033758 The security professional in me hopes that you're not telnet-ing into a machine across an unsecure network. (Telnet traffic is not encrypted.) I'm not entirely sure what you're asking, but if you're trying to issue the `os.statvfs()` command on a unix or linux machine you should not get that error. A simple way you can check is to to run the command `python -c "import os; print os.statvfs('/')"` on the machine in question. –  Feb 26 '13 at 23:32
  • Like Mike said, don't use telnet. Do this with ssh! – Christian Rapp Feb 26 '13 at 23:36
0

Make sure you are running in python2.7

import sys
print(sys.version)

Also you should escape a backslash

EDIT: See Mikes answer, did not know this is not implemented for Windows. Using it is also not wise because it is deprecated since Python2.6 and has been removed in Python3

Christian Rapp
  • 1,853
  • 24
  • 37
  • Well yes, I am running on windows. >>> print (sys.version) 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] – user2033758 Feb 26 '13 at 23:10