I'm using Python 2.6 on Linux. What is the fastest way:
If you need the device name and mount point associated with the file, you should call an external program to get this information.
df will provide all the information you need -- when called as
df filename it prints a line about the partition that contains the file.
To give an example:
import subprocess df = subprocess.Popen(["df", "filename"], stdout=subprocess.PIPE) output = df.communicate() device, size, used, available, percent, mountpoint = \ output.split("\n").split()
If you don't need device name and mount point, going with
os.statvfs() will be better (see other answers).