Skip to content
เข้าสู่ระบบ

platform Module

platform module ให้ข้อมูลเกี่ยวกับ platform, OS, และ Python runtime มีประโยชน์สำหรับ cross-platform applications ที่ต้องปรับพฤติกรรมตาม OS หรือ Python version

ทำไมต้องใช้ platform

Section titled “ทำไมต้องใช้ platform”

เมื่อต้องการเขียนโปรแกรมที่ทำงานได้หลาย OS platform module ช่วยตรวจสอบ:

  1. OS Detection - ตรวจว่า Windows, macOS, หรือ Linux
  2. Architecture - ตรวจว่า 32-bit หรือ 64-bit
  3. Python Version - ตรวจว่ารองรับ feature ใหม่หรือไม่
  4. Hardware Info - CPU type, machine name
  5. Cross-platform Paths - หา config/cache directories ที่ถูกต้อง
import platform
# ตัวอย่างการใช้งานเบื้องต้น
print("=== Quick System Info ===")
print(f"OS: {platform.system()}") # Darwin, Linux, Windows
print(f"Release: {platform.release()}") # OS version
print(f"Machine: {platform.machine()}") # arm64, x86_64
print(f"Python: {platform.python_version()}") # 3.11.0
# ใช้ตัดสินใจ
if platform.system() == 'Windows':
print("\nRunning on Windows!")
elif platform.system() == 'Darwin':
print("\nRunning on macOS!")
else:
print(f"\nRunning on {platform.system()}")

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด