Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

เข้าถึงข้อมูลระบุตัวตนของ Platform ใน Python (โมดูล platform)

ฟังก์ชันในโมดูล platform ช่วยสำรวจ Hardware, Operating System และข้อมูลเวอร์ชัน Interpreter ของ Platform ที่อยู่เบื้องหลัง

ฟังก์ชันหลัก

ฟังก์ชันคำอธิบายตัวอย่างผลลัพธ์
architecture()สอบถามข้อมูล Architecture ของ Executable (Default: Python Interpreter)('64bit', '')
machine()คืน Machine Type เช่น 'x86_64', 'i386''x86_64'
node()คืน Network Name ของคอมพิวเตอร์'my-computer'
platform()คืน String ระบุ Platform เดียว'Linux-5.4.0-x86_64-with-glibc2.31'
processor()คืนชื่อ Processor จริง'x86_64'
python_build()คืน Tuple (buildno, builddate)('default', 'Oct 13 2023 12:00:00')
python_compiler()คืน String ระบุ Compiler ที่ใช้คอมไพล์ Python'GCC 11.2.0'
python_implementation()คืน Implementation: 'CPython', 'IronPython', 'Jython', 'PyPy''CPython'
python_version()คืน Version String รูปแบบ 'major.minor.patchlevel''3.11.4'
system()คืน System/OS Name'Linux', 'Windows', 'Darwin'
uname()คืน Named Tuple: system, node, release, version, machine, processoruname_result(...)

ตัวอย่างการใช้งาน

import platform

print("System:", platform.system())
print("Node:", platform.node())
print("Release:", platform.release())
print("Version:", platform.version())
print("Machine:", platform.machine())
print("Processor:", platform.processor())
print("Python Version:", platform.python_version())
print("Python Implementation:", platform.python_implementation())
print("Python Compiler:", platform.python_compiler())
print("Platform:", platform.platform())
print("Architecture:", platform.architecture())
print("Uname:", platform.uname())