How to use the platform module to obtain system information in Python, pythonplatform

Source: Internet
Author: User

How to use the platform module to obtain system information in Python, pythonplatform

Operating System Problems

  • System (): operating system type (see example)
  • Version (): operating system version
  • Release (): release Number of the operating system, for example, win 7 returns 7, and NT, 2.2.0, and so on.
  • Platform (aliased = 0, terse = 0): Operating system Information string, platform and system () + win32_ver () [: 3]
  • Win32_ver (release = '', version ='', csd = '', ptype =''): win system information
  • Linux_distribution (distname = '', version ='', id = '', supported_dists = ('suse', 'debiaare', 'yellowdog ', 'gentoo', 'unitedlinux ', 'turbolinux '), full_distribution_name = 1): Linux system information
  • Dist (distname = '', version ='', id = '', supported_dists = ('suse', 'debian ', 'ora ora', 'redhat ', 'centos ', 'mandrake', 'mandriva ', 'rocks', 'slackware', 'yellowdog ', 'gentoo', 'unitedlinux', 'turbolinux ')): try to obtain the Linux OS version. returns (distname, version, id ). dist indicates the release version.
  • Mac_ver (release = '', versioninfo = ('', '',''), machine = ''): mac version
  • Java_ver (release = '', vendor ='', vminfo = ('','', ''), osinfo = ('','','')): java version
  • Libc_ver (executable = r 'C: \ Python27 \ python.exe ', lib = '', version ='', chunksize = 2048): linux version.

The returned tuples of the query in the corresponding version correspond to their form parameters.

platform.system()'Linux' # python 3.3.2+ 64 bits on debian jessie 64 bits'Windows' # python 3.3.2 32 bits on windows 8.1 64 bits'Windows' # python 3.3.2 64 bits on windows 8.1 64 bits'Darwin' # python 3.4.1 64 bits on mac os x 10.9.4'Java' platform.version()'#1 SMP Debian 3.10.11-1 (2013-09-10)' # python 3.3.2+ 64 bits on debian jessie 64 bits'6.2.9200' # python 3.3.2 32 bits on windows 8.1 64 bits'6.2.9200' # python 3.3.2 64 bits on windows 8.1 64 bits'Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64' # python 3.4.1 64 bits on mac os x 10.9.4platform()'Windows-7-6.1.7601-SP1'win32_ver()('7', '6.1.7601', 'SP1', u'Multiprocessor Free')platform.dist()('debian', 'jessie/sid', '') # python 3.3.2+ 64 bits on debian jessie 64 bits

System Information

  • Uname (): returns the tuples, system, node, release, version, machine, processor.
  • Architecture (executable = r 'C: \ Python27 \ python.exe ', bits = '', linkage =''): System architecture
  • Machine (): CPU platform, AMD, x86? (See example)
  • Node (): node name (machine name, such as Hom-T400)
  • Processor (): CPU Information
  • System_alias (system, release, version): returns the corresponding tuples.
  • Platform. architecture ()
('64bit', 'ELF') # python 3.3.2+ 64 bits on debian jessie 64 bits('32bit', 'WindowsPE') # python 2.7.2 32 bits on windows 7 64 bits('64bit', 'WindowsPE') # python 3.3.2 64 bits on wndows 8.1 64 bits('64bit', '') # python 3.4.1 64 bits on mac os x 10.9.4platform.machine()'x86_64' # python 3.3.2+ 64 bits on debian jessie 64 bits'AMD64' # python 3.3.2 32 bits on windows 8.1 64 bits'AMD64' # python 3.3.2 64 bits on windows 8.1 64 bits'x86_64' # python 3.4.1 64 bits on mac os x 10.9.4platform.node()'Hom-T400' platform.processor()'Intel64 Family 6 Model 23 Stepping 10, GenuineIntel'platform.uname()('Windows', 'Hom-T400', '7', '6.1.7601', 'AMD64', 'Intel64 Family 6 Model 23 Stepping 10, GenuineIntel')uname_result(system='Linux', node='work', release='3.10-3-amd64', version='#1 SMP Debian 3.10.11-1 (2013-09-10)', machine='x86_64', processor='') # python 3.3.2+ 64 bits on debian jessie 64 bits uname_result(system='Windows', node='work-xxx', release='8', version='6.2.9200', machine='AMD64', processor='Intel64 Family 6 Model 58 Stepping 9,GenuineIntel') # python 3.3.2 32 bits on windows 8.1 64 bits uname_result(system='Darwin', node='mba', release='13.3.0', version='Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64', machine='x86_64', processor='i386') # python 3.4.1 64 bits on mac os x 10.9.4

Python Problems

  • Python_version (): py version
  • Python_branch (): python Branch (subversion information), which is generally empty.
  • Python_build (): python build number (default) and date.
  • Python_compiler (): py compiler Information
  • Python_implementation (): python installation and implementation methods, such as CPython, Jython, Pypy, IronPython (. net.
  • Python_revision (): python type modified version information, usually empty.
  • Python_version_tuple (): tuple after the python version number is split.
  • Popen (cmd, mode = 'R', bufsize = None): portable popen () interface, execute various commands.
  • Python_verison ()
'3.3.2+' # python 3.3.2+ 64 bits on debian jessie 64 bits'3.3.3' # python 3.3.2 32 bits on windows 8.1 64 bitspython_version_tuple()('2', '7', '2')python_build()('default', 'Jun 12 2011 15:08:59')python_compiler()'MSC v.1500 32 bit (Intel)'pl.python_implementation()'CPython'

Get User Name:

>>> import getpass >>> getpass.getuser() 'root'

Get environment variables:

>>> Import OS >>> import pwd >>> OS. environ ['lang '] 'en _ US.UTF-8'> print OS. getenv ('lang ') en_US.UTF-8> print OS. getenv ('pwd')/root> print OS. getenv ('home')/root> print OS. getenv ('user') root >>> print OS. getenv ('hostname') localhost. localdomain >>> print OS. getenv ('shell')/bin/bash> pwd. getpwuid (OS. getuid () pwd. struct_passwd (pw_name = 'root', pw_passwd = 'x', pw_uid = 0, pw_gid = 0, pw_gecos = 'root', pw_dir = '/root ', pw_shell = '/bin/bash')> pwd. getpwuid (OS. getuid () [0] # obtain the username 'root'> pwd. getpwuid (OS. getuid () [5] # obtain the home directory '/root'> pwd. getpwuid (OS. getuid () [6] # Get shell '/bin/bash'

There is also an OS. environ. get, which will return all environment variables as a dictionary.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.