Win32 drive mapping... aka "net use"

Diez B. Roggisch deetsNOSPAM at web.de
Sat Mar 5 15:12:11 EST 2005


>>>> b = a.strip(r'\\\x00')
>>>> b
> 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
>>>> b = a.split(r'\\\x00')
>>>> b
> ['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00']
> 
> I'm a bit of a novice at python (even more so of the win32 api), but
> I've used the split and strip functions before (for example to get rid
> of '\n' from strings) so it is unclear to me why this does not work.

The string you get ist actually a list of null-terminated strings. And the
byte 0 that you want to have as delimiter for splitting is written

'\x00'

So do this:

b = a.split('\x00')

Read the python docs about strings and raw strings and escaping of
characters to understand the subtle details here.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list