Cross platform way to list disk drives on Linux, Windows and Mac using Python?

后端 未结 4 1539
名媛妹妹
名媛妹妹 2021-01-02 03:22

I am using Python2.6. I am trying to list the disk drives that a system may have.

On Windows, it may be something like C:/, D:/, E:/

4条回答
  •  一生所求
    2021-01-02 03:57

    Eric Smith's answer to use psutil works well for me on Windows, but on OS X, I prefer this:

    from os import listdir
    listdir('/Volumes')
    

    It gives you back the human readable names that, at least in my case, would be preferable (IE, it gives you Macintosh HD instead of / or /dev/disk0s2.)

提交回复
热议问题