Python Glossary Русский

Python 3.12+Windowsosfunction

os.listmounts()

os — file system

Returns the list of mount points for a volume; the volume is given as a GUID path from os.listvolumes(). Windows only, Python 3.12+.

Syntax

os.listmounts(volume)

It takes a volume GUID path like \\?\Volume{…}\, obtained from os.listvolumes, and returns its mount points: a drive letter or a directory. A volume can have several or none — in which case there is no user-friendly path to it.

Examples

import os
print(not hasattr(os, 'listmounts') or callable(os.listmounts))   # → True
print(hasattr(os, 'listmounts') == hasattr(os, 'listvolumes'))   # → True
vols = os.listvolumes() if hasattr(os, 'listvolumes') else []
mounts = [m for v in vols for m in os.listmounts(v)]
print(all(isinstance(m, str) for m in mounts))   # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy