码迷,mamicode.com
首页 > 编程语言 > 详细

python模块介绍-platform:底层平台信息 --参考资料待更新

时间:2015-06-09 10:07:11      阅读:688      评论:0      收藏:0      [点我收藏+]

标签:

解释器信息

  • platform.python_version():  返回的Python版本字符串‘major.minor.patchlevel‘。sys.version有类似功能,但是返回的信息更多。

  • platform.python_version_tuple(): 返回Python版本 (major, minor, patchlevel)。

  • platform.python_build(): 返回元组(buildno, builddate),即Python版本号和日期。

  • platform.python_compiler():返回说明编译Python的编译器的字符串。

  • platform.python_branch():返回说明编译Python分支。

  • platform.python_implementation():返回Python实现,比如‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’。

  • platform.python_revision():返回Python补丁版本号。

下面是ubuntu 14.04执行的结果:

>>> import platform
>>> platform.python_version()
‘2.7.6‘
>>> import sys
>>> sys.version
‘2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]‘
>>> platform.python_version_tuple()
(‘2‘, ‘7‘, ‘6‘)
>>> platform.python_compiler()
‘GCC 4.8.2‘
>>> platform.python_build()
(‘default‘, ‘Mar 22 2014 22:59:56‘)
>>> platform.python_implementation()
‘CPython‘
>>> platform.python_revision()
‘‘
>>> platform.python_branch()
‘‘

平台信息

  • platform.platform(aliased=0, terse=0): 返回描述底层平台信息的字符串。

输出尽量面向用户而不是机器,在不同的平台会不同。

如果aliased为true,SunOS将被报告为别名Solaris,实际上是调用system_alias函数。

terse设置为true会使用简洁模式,只显示内核相关信息。

  • platform.uname(): 返回元组(system, node,release, version, machine, processor)。跟os.uname()比,增加了处理器信息。

  • platform.java_ver(release=‘‘, vendor=‘‘, vminfo=(‘‘, ‘‘, ‘‘), osinfo=(‘‘, ‘‘, ‘‘)):返回元组(release, vendor, vminfo, osinfo)vminfo是元组(vm_name, vm_release, vm_vendor)osinfo是元组(os_name, os_version, os_arch)
>>> platform.platform()
‘Linux-3.13.0-51-generic-x86_64-with-Ubuntu-14.04-trusty‘
>>> platform.platform(aliased=True)
‘Linux-3.13.0-51-generic-x86_64-with-Ubuntu-14.04-trusty‘
>>> platform.platform(terse=True)
‘Linux-3.13.0-51-generic-x86_64-with-glibc2.4‘
>>> platform.uname()
(‘Linux‘, ‘andrew-Hi-Fi-A88S2‘, ‘3.13.0-53-generic‘, ‘#89-Ubuntu SMP Wed May 20 10:34:39 UTC 2015‘, ‘x86_64‘, ‘x86_64‘
>>> platform.java_ver()
(‘1.8.0_45‘, ‘Oracle Corporation‘, (‘Java HotSpot(TM) 64-Bit Server VM‘, ‘25.45-b02‘, ‘Oracle Corporation‘), (‘Linux‘, ‘3.13.0-53-generic‘, ‘amd64‘))

操作系统和硬件信息

  • platform.system():返回系统/OS名,例如 ‘Linux‘, ‘Windows‘或 ‘Java‘。如果无法确定则返回空字符串。

  • platform.system_alias(system, release, version):返回系统别名,例如 ‘Linux‘, ‘Windows‘或 ‘Java‘。如果无法确定则返回空字符串。

  • platform.node():返回计算机的网络名称(不一定完整)。如果无法确定则返回空字符串。

  • platform.release(): 返回系统的发布,例如‘2.2.0‘或‘NT‘。如果无法确定则返回空字符串。

  • platform.version(): 返回系统的发布版本,例如‘#3on degas‘。如果无法确定则返回空字符串。

  • platform.machine(): 返回机器类型,例如‘386‘。如果无法确定则返回空字符串。

  • platform.processor(): 返回(真实)处理器名称,例如“amdk6”。则返回一个空字符串。许多平台不提供此信息, 则直接返回machine函数的结果。

  • platform.win32_ver(release=‘‘, version=‘‘, csd=‘‘, ptype=‘‘): 返回元组(release, version, csd, ptype)
  • platform.mac_ver(release=‘‘, versioninfo=(‘‘, ‘‘, ‘‘), machine=‘‘):返回元组(release, versioninfo,machine)versioninfo(version, dev_stage,non_release_version)
  • platform.linux_distribution(distname=‘‘, version=‘‘, id=‘‘, supported_dists=(‘SuSE‘, ‘debian‘, ‘redhat‘, ‘mandrake‘, ...), full_distribution_name=1) 返回元组(distname,version,id)
  • platform.libc_ver(executable=sys.executable, lib=‘‘, version=‘‘, chunksize=2048):返回libc版本(lib,version)
>>> import platform
>>> platform.system()
‘Linux‘
>>> platform.node()
‘andrew-Hi-Fi-A88S2‘
>>> platform.release()
‘3.13.0-51-generic‘
>>> platform.version()
‘#84-Ubuntu SMP Wed Apr 15 12:08:34 UTC 2015‘
>>> platform.machine()
‘x86_64‘
>>> platform.processor()
‘x86_64‘
>>> platform.linux_distribution()
(‘Ubuntu‘, ‘14.04‘, ‘trusty‘)
>>> platform.libc_ver()
(‘glibc‘, ‘2.4‘)


参考资料


python模块介绍-platform:底层平台信息 --参考资料待更新

标签:

原文地址:http://my.oschina.net/u/1433482/blog/464470

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!