Ich habe versucht .replace, ich habe versucht Trim Ich habe versucht fast jede Lösung da draußen diese verdammten weißen Räume, um mich in Ruhe zu lassen, aber sie werden nicht weggehen.Python Cant Leerzeichen von zurückgegebenen String entfernen
import win32api
import string
import re
disks = win32api.GetLogicalDriveStrings()
disks = disks.translate({ord(c): None for c in ':\\ '})
disks = re.sub(r'\s+','',disks, flags=re.UNICODE)
print (disks)
for disk in disks.strip().split(): # or just disks without the other stuff
print('Trying drive: '+disk)
try:
drives,_,_,_,_ = win32api.GetVolumeInformation(disk+':\\')
print ('Got info for drive: ' + disk)
print(drives)
except Exception as details:
print('Ooops, not a hard drive')
Ausgang ohne .strip(). Split()
== RESTART: C:\~~~~~~ ==
C D E F
Trying drive: C
Got info for drive: C
Windows
Trying drive:
Ooops, not a hard drive
Trying drive: D
Ooops, not a hard drive
Trying drive:
Ooops, not a hard drive
Trying drive: E
Got info for drive: E
Media 2
Trying drive:
Ooops, not a hard drive
Trying drive: F
Ooops, not a hard drive
Trying drive:
Ooops, not a hard drive
Ausgang ohne .strip(). Split()
== RESTART: C:\~~~~ ==
C D E F
Trying drive: C D E F
Ooops, not a hard drive
haben versucht nun
" ".join(disks.split())
Ich glaube, Sie sollten die Dokumentation aufhören zu raten und lesen. In dieser Zeichenfolge sind keine Leerzeichen enthalten. –