Using assorted functions from the `platform` module. On my Linux box:
$ python2.7
Python 2.7.3 (default, Dec 5 2012, 10:56:01)
[GCC 4.5.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.linux_distribution()
('Gentoo Base System', '2.1', '')
>>> platform.mac_ver()
('', ('', '', ''), '')
>>> platform.win32_ver()
('', '', '', '')
On an OS X box:
$ python2.6
Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.linux_distribution()
('', '', '')
>>> platform.mac_ver()
('10.6.8', ('', '', ''), 'i386')
>>> platform.win32_ver()
('', '', '', '')
I don't have access to an MS Windows box, but presumably it returns
something like:
>>> platform.linux_distribution()
('', '', '')
>>> platform.mac_ver()
('', ('', '', ''), '')
>>> platform.win32_ver()
('XP', '5.1.2600', 'SP2', 'Multiprocessor Free')
We only want to print the one that applies (e.g. don't print a
'linux_distribution' entry on OS X), so we skip entries where value[0]
is an empty string.
del name, dependencies # cleanup namespace
-def _print_info(key, value, indent=13):
+def _print_info(key, value, indent=19):
print('{0}{1}: {2}'.format(key, ' '*(indent-len(key)), value))
def print_system_info():
_print_info('os.uname', _platform.uname())
_print_info('platform', _sys.platform)
_print_info('platform+', _platform.platform())
+ for pversion in (
+ 'linux_distribution',
+ 'mac_ver',
+ 'win32_ver',
+ ):
+ value = getattr(_platform, pversion)()
+ if value[0]:
+ _print_info(pversion, value)
_print_info('prefix', _sys.prefix)
_print_info('exec_prefix', _sys.exec_prefix)
_print_info('executable', _sys.executable)