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')
次に、デバイスの正規表現を使用して出力を操作または検索します。