Python is a versatile language that was built as a general−purpose scripting language. Hence a lot of automation tasks, along with scripting, can be done. Getting the system information tasks, along with scripting, can be done. Getting the system information becom system importes task in many applications such as machine learning, deep learning, etc., where hardware plays a crucial role. Python provides several methods to gather information about the operating system and hardware.
import platform system_info = platform.uname() print("System Info:", system_info)
System Info: uname_result(system='Linux', node='asifr-Nitro-AN515-45', release='5.19.0-43-generic', version='#44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 22 13:39:36 UTC 2', machine='x86_64')
Obtaining System information
import platform system_name = platform.system() system_release = platform.release() system_architecture = platform.machine() system_aliases = platform.platform() print("The system details are as follows:") print("Operating System:", system_name) print("Release Version:", system_release) print("System Architecture:", system_architecture) print("Systemaliases:", system_aliases)
The system details are as follows: Operating System: Linux Release Version: 5.19.0-43-generic System Architecture: x86_64 Systemaliases: Linux-5.19.0-43-generic-x86_64-with-glibc2.35
Get CPU Information
Example
import platform def get_cpu_info(): cpu_info = platform.processor() return cpu_info cpu = get_cpu_info() print("CPU Information:") print("Processor:", cpu) print("Architecture:", platform.machine())
CPU Information: Processor: x86_64 Architecture: x86_64
結論
###在本文中,我們已經了解如何使用Python的函式庫來取得系統和硬體資訊。 Python是一種通用的腳本語言,提供了與硬體和軟體互動的各種方式。 Python中有多個函式庫可用,如psutil、GPUtil等,可用於取得系統和硬體資訊。 ###以上是使用Python平台模組獲取硬體和系統信息的詳細內容。更多資訊請關注PHP中文網其他相關文章!