On Oct 20, 2:23 pm, J <dreadpiratej...@gmail.com> wrote: > 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 > > -- > > Ted Turner - "Sports is like a war without the killing." > -http://www.brainyquote.com/quotes/authors/t/ted_turner.html
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) -- http://mail.python.org/mailman/listinfo/python-list