By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

accessing individual element in a list.

P: n/a
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.

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>>> 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"

Jul 19 '05 #2

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

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.