在 Python 中訪問底層平臺的識別資料


platform 模組中的函式可以幫助我們探查底層平臺的硬體、作業系統和直譯器版本資訊。

architecture()

此函式查詢給定的可執行檔案(預設為 Python 直譯器可執行檔案)以獲取各種架構資訊。

>>> import platform
>>> platform.architecture()
('64bit', '')

machine()

此函式返回機器型別,例如 'i386'。如果無法確定值,則返回空字串。

>>> platform.machine()
'x86_64'

node()

此函式返回計算機的網路名稱。

>>> platform.node()
'malhar-ubuntu'

platform(aliased=0, terse=0)

此函式返回一個識別底層平臺的單個字串。

>>> platform.platform()
'Linux-4.13.0-46-generic-x86_64-with-debian-stretch-sid'

processor()

此函式返回(實際)處理器名稱。

>>> platform.processor()
'x86_64'

python_build()

此函式返回一個元組 (buildno, builddate)

>>> platform.python_build()
('default', 'Oct 13 2017 12:02:49')

python_compiler()

此函式返回一個字串,標識用於編譯 Python 的編譯器。

>>> platform.python_compiler()
'GCC 7.2.0'

python_implementation()

此函式返回一個字串,標識 Python 的實現。可能的返回值為:'CPython'、'IronPython'、'Jython'、'PyPy'。

>>> platform.python_implementation()
'CPython'

python_version()

此函式返回一個字串,包含 Python 版本,格式為 'major.minor.patchlevel'。

>>> platform.python_version()
'3.6.3'

System()

此函式返回系統/作業系統名稱

>>> platform.system()
'Linux'

uname()

相當便攜的 uname 介面。返回一個命名元組(),包含六個屬性:system、node、release、version、machine 和 processor。

>>> platform.uname()
uname_result(system='Linux', node='malhar-ubuntu', release='4.13.0-46-generic', version='#51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018', machine='x86_64', processor='x86_64')

更新於: 2019-07-30

181 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.