A stupid newbie question about output...

J

J

Can someone explain why this code results in two different outputs?
for os in comp.CIM_OperatingSystem ():
print os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVersion
osVer = os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVersion
print osVer

the first print statement gives me this:
Microsoft Windows XP Professional Service Pack 3

and the second print statement gives me this:
(u'Microsoft Windows XP Professional Service Pack', 3)

I know this is a grossly oversimplified example.

The ultimate goal is to get certain things from the system via WMI and
then use that data in other scripts to generate test case scripts for
a testing tool.

So given this example, what I ultimately want is to create a class
full of this stuff, that I can call from another program like this:
import SystemInformation
comp = SystemInformation()
# Get OS info
OSVersion = comp.osVer

OR just print the result
print comp.osVer

Can this be cleared up by using some sort of formatting in print (like
sprintf) or am I going to have to manipulate the WMI results before
sending them out??

Thanks

Jeff
 
N

nn

Can someone explain why this code results in two different outputs?
for os in comp.CIM_OperatingSystem ():
 print os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVersion
 osVer = os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVersion
 print osVer

the first print statement gives me this:
  Microsoft Windows XP Professional Service Pack 3

and the second print statement gives me this:
(u'Microsoft Windows XP Professional Service Pack', 3)

I know this is a grossly oversimplified example.

The ultimate goal is to get certain things from the system via WMI and
then use that data in other scripts to generate test case scripts for
a testing tool.

So given this example, what I ultimately want is to create a class
full of this stuff, that I can call from another program like this:
import SystemInformation
comp = SystemInformation()
# Get OS info
OSVersion = comp.osVer

OR just print the result
print comp.osVer

Can this be cleared up by using some sort of formatting in print (like
sprintf) or am I going to have to manipulate the WMI results before
sending them out??

Thanks

Jeff

This is because of some magic the print statement does with variables
separated by commas adding a space. So you can either do:

print (os.Name.split("|")[0] + " Service Pack",
os.ServicePackMajorVersion)

or

osVer = "%s %s" % (os.Name.split("|")[0] + " Service Pack",
os.ServicePackMajorVersion)
 

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

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top