[Tutor] Partition in Windows or Linux

Mats Wichmann mats at wichmann.us
Sat May 23 10:14:40 EDT 2020


On 5/23/20 2:44 AM, Michael Kommenda wrote:
>    Hello,
>     
>    Unfortunately, I couldn't find an answer to the FAQ.
>     
>    How to define a partition in Windows or Linux in Python 3? So e.g. "F:/"
>    or "sda3"? I know a definition of a file, is there a special term for
>    partitions?

There are some different concepts in play here.

A Python program should not need to worry about what are actually
(physical or logical) partitions.  They're not visible to running
programs unless the system has made them available, and if they're
available, they're under a different name than the partition name.

Windows partitions, *if* they look like they have valid Windows-readable
file systems on them *and* haven't been excluded by volume management
settings, are mapped in to the "filesystem" as a drive letter (that even
includes local network storage).  Drive letter handling in Python is a
bit awkward... a drive letter like "F:" is not technically part of a
path, it is in addition to the path, but Python needs to treat is as if
it is to present some kind of consistent treatment across systems.
Unfortunately, Windows shells have a working directory per drive letter
and Python doesn't which can lead to some confusion when the paths are
relative paths but a drive letter is also specified. Okay - I'll stop now.

You can get some idea of the concepts in play if you look at the
documentation for the pathlib module, which has a bit more to say than
os.path does.

Linux partitions are only visible parts of the file system when they are
mounted, and if they are, access is through the path to the mount point.

Is this even what you were asking?



More information about the Tutor mailing list