accessing individual element in a list.

F

future_retro

hi all,could someone clear this up for me. I'm sure it's probably very
simple but I can't seem to get my head round it.....

doing the following
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] u'G'
pd.split(',') [u'AGFA-AccuSet v52.3', u'3', u'Windows NT x86']
pd[0]
u'A'

why does pd[1] or pd[0] not return an element from the list instead of
a character from the string? Is split the best method to try and
seperate the individual elements?

Thanks, MW.
 
S

simon.dahlbacka

import wmi
.... pd = printdriver.Name
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 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"
 
F

future_retro

the square brackets round the output of split got me. Have plit into a
new list and all works as expeted. Cheers, MW.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,308
Members
47,956
Latest member
AmeeBerger

Latest Threads

Top