在Python中,可以使用`psutil`庫來獲取Windows系統(tǒng)上所有的磁盤信息。 `psutil`是一個(gè)跨平臺(tái)的庫,它提供了許多系統(tǒng)信息和進(jìn)程管理功能。
下面是使用`psutil`庫獲取Windows系統(tǒng)上所有磁盤的示例代碼:文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html
import psutil
def get_all_disk_partitions():
partitions = psutil.disk_partitions()
disk_list = []
for partition in partitions:
if 'cdrom' in partition.opts or partition.fstype == '':
continue
disk_list.append(partition.device)
return disk_list
all_disks = get_all_disk_partitions()
print(all_disks)
運(yùn)行這段代碼將返回一個(gè)包含所有磁盤的列表。每個(gè)磁盤都用設(shè)備號(hào)表示,例如`C:\`、`D:\`等。文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html
請(qǐng)確保在運(yùn)行以上代碼前已經(jīng)安裝了`psutil`庫。你可以使用以下命令通過pip安裝:文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html
pip install psutil
這樣就可以獲取Windows系統(tǒng)上所有的磁盤信息了。希望對(duì)你有幫助!文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html
相關(guān)文章文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html
python使用ttkthemes庫制作下拉菜單選擇磁盤文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html 文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.hvig.cn/11587.html


評(píng)論