Python has the lovely 'platform' module to help you out.
>>> import platform
>>> platform.win32_ver()
('XP', '5.1.2600', 'SP2', 'Multiprocessor Free')
>>> platform.system()
'Windows'
>>> platform.version()
'5.1.2600'
>>> platform.release()
'XP'
NOTE: As mentioned in the comments proper values may not be returned when using older versions of python.