tags:

views:

281

answers:

4

I'm sure this is a easy question, my Google-fu is obviously failing me.

How do you mount a filesystem using Python (i.e the equivalent of running the shell command mount ...). Obviously you can use os.system to run the shell command, but surely this is a nice tidy, python interface to the mount system call.

I can't find it (I thought it would just be a nice, easy os.mount()).

+4  A: 

surely this is a nice tidy, python interface to the mount system call.

I can't find it (I thought it would just be a nice, easy os.mount()).

Surely, there is none. What would this function do on Windows?

Use the shell command instead.

Ferdinand Beyer
Use the shell command via `subprocess.Popen( "mount ...")`
S.Lott
it's also possible to umount/mount a partition on windows
presario
@Ferdinand `What would this function do on Windows?` Actually, Python has quite a few platform-specific modules (_winreg, msilib, msvcrt, posix, maxostools, ...), also some common functions behave differently on some platforms like `subprocess.Popen(..., shell=False)` for example. So this is not a criterion to exclude that option.
RedGlyph
A: 

Mounting is a pretty rare operation, so it's doubtful that there is any direct python way to do it.

Either use ctypes to do the operation directly from python, or else (and probably better), use subprocess to call the mount command (don't use os.system() - much better to use subprocess).

Douglas Leeder
+2  A: 

Badly, mounting and unmounting belongs to the things that are highly system dependent and since they are

  • rarely used and
  • can affect system stability

There is no solution that is portable available. Since that, I agree with Ferdinand Beyer, that it is unlikely, a general Python solution is existing.

Juergen
+2  A: 

Import cdll from ctypes. Then load your os libc, then use libc.mount()

Read libc's docs for mount parameters

marianov