accessing individual element in a list.

simon.dahlbacka at simon.dahlbacka at
Fri Jul 1 13:39:43 CEST 2005

>>> import wmi
>>> c = wmi.WMI()
>>> for printdriver in c.Win32_PrinterDriver():

...     pd = printdriver.Name
>>> print pd

AGFA-AccuSet v52.3,3,Windows NT x86
>>> pd[1] # type(pd) == str
>>> pd.split(',')
# split returns a new list, and you do not save it

[u'AGFA-AccuSet v52.3', u'3', u'Windows NT x86']
>>> pd[0]
# pd is still a string

so basically, .split is probably the best way to split it up (unless
you want to fiddle with regular expressions, but that seems overkill in
this case), but you need to store the new list. split does not do
anything "inline"

More information about the Python-list mailing list