Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从带有 python 的 USB 硬盘驱动器获取唯一 ID,用于我正在处理的项目。实现这一目标的最简单方法是什么?有更好的方法吗?这可以独立于平台完成吗?
使用系统调用读取“lsusb”,然后解析输出。
import os cmd = 'lsusb' os.system(cmd)
或者更容易解析的解决方案是命令库。
import commands output = commands.getstatusoutput('lsusb')
然后您将使用正则表达式为您的设备操作或搜索输出。