accessing individual element in a list.
simon.dahlbacka at gmail.com
simon.dahlbacka at gmail.com
Fri Jul 1 07:39:43 EDT 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
u'G'
>>> 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
u'A'
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