0
我試圖爲我的系統驅動器提取信息。我遇到的問題是能夠將信息分解並放在需要去的地方。下面是所需出來放,如果有一個以上的卷:使用Python進行for循環的文本格式化
Mountpoint: C:\
OS Volume: True
GUID: d1dd2893f42711e09090806e6f6e6963
Mountpoint: D:\
OS Volume: False
GUID: b4584ed2e3b211e2ae7d806e6f6e6963
下面是打印出來的時候我跑我目前掌握的信息:
Mountpoint: C:\
Mountpoint: D:\
OS Volume: True
OS Volume: False
GUID: d1dd2893f42711e09090806e6f6e6963
GUID: b4584ed2e3b211e2ae7d806e6f6e6963
我知道我做錯了,我不知道如何解決它。我已經瀏覽了互聯網,但無濟於事。這可能只是我的天真。
這裏是我使用的代碼:variable
是迭代的strdrives
內容
def driveInfo(agent):
info = "info " + agent + " | grep "
drives = subprocess.Popen(info + "'\[mountpoints\]'", shell=True, stdout=subprocess.PIPE)
drives, err = drives.communicate()
strdrives = str(drives)
### Volume Information
mount = subprocess.Popen(info + "'\[mountpoints\]'", shell=True, stdout=subprocess.PIPE)
osvol = subprocess.Popen(info + "'\[OSVolume\]'", shell=True, stdout=subprocess.PIPE)
guid = subprocess.Popen(info + "'\[guid\]'", shell=True, stdout=subprocess.PIPE)
### Communicate calls
mount, err = mount.communicate()
osvol, err = osvol.communicate()
guid, err = guid.communicate()
### String conversions
mount = str(mount).strip()
osvol = str(osvol).strip()
guid = str(guid).strip()
### Drive Information Output
for drive in strdrives:
print mount
print osvol
print guid
driveInfo(agent)
布魯斯,我編輯了我原來的問題,使事情更清楚一點。對於問題的所有意圖和目的,「代理人」變量可以被忽略 – Greg