使用Python跨平台列出Linux,Windows和Mac上磁盘驱动器的方法? [英] Cross platform way to list disk drives on Linux, Windows and Mac using Python?

查看:140
本文介绍了使用Python跨平台列出Linux,Windows和Mac上磁盘驱动器的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python2.6。我试图列出系统可能具有的磁盘驱动器。

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

在Windows上,可能类似于 C:/ D:/ E:/ 等。在Linux上,可能类似于 / boot / media / SDCard 等。我不知道Mac上的情况。也许在/ Volumes下。

On Windows, it may be something like C:/, D:/, E:/, etc. On Linux, it may be something like /boot, /media/SDCard, etc. And I don't know what it's like on a Mac. Maybe something under /Volumes.

有人知道Python中的跨平台方式(即适用于Linux,Windows和Mac的方式)吗?

Does anyone know of a cross platform way (that is, one which works on Linux, Windows and Mac) in Python?

谢谢!

推荐答案

Linux设备确实没有统一的命名方案保证您可以格式化的块设备。有约定,但是约定可以相差很大,如果需要的话,我可以叫拇指驱动器/ Thomas / O,Python中没有跨平台的方式可以知道:

There isn't really a unified naming scheme for Linux devices that guarantees you a formatable block device. There are conventions, but they can vary widely and I can call my thumb-drive /Thomas/O if I want and there is no cross-platform way in Python to know:


  1. / Thomas / O对应于/ dev / sdf1

  2. / dev / sdf1可以具有FAT32文件系统

  3. / dev / sdf1相对于/ dev / sdf1而言, sdf 不是

  1. That /Thomas/O corresponds to /dev/sdf1
  2. That /dev/sdf1 can have a FAT32 filesystem made on it
  3. That /dev/sdf is not preferred to /dev/sdf1

我很确定没有一个跨平台的Python模块,该模块可以让您确定H:/在Windows系统上是可格式化的,而Z:/不是。

I'm pretty sure that neither is there a cross-platform Python module which will allow you to determine that H:/ is formattable on a Windows system but that Z:/ is not.

每个系统都需要自己进行特定的检查和验证,您可以从研究开放源代码磁盘操作软件中最好地学习到。

Each system will require its own specific checks and validations which you could best learn from studying open-source disk manipulation software.

这篇关于使用Python跨平台列出Linux,Windows和Mac上磁盘驱动器的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆