请注æï¼ææçç¨åºå¨å®ä»¬ç¬¬ä¸è¡é½æ¯#!/usr/bin/env/pythonï¼ä¹å°±æ¯è¯´ï¼æ们æ³è¦Pythonç解éå¨æ¥æ§è¡è¿äºèæ¬ãå æ¤ï¼å¦æä½ æ³ä½ çèæ¬å
·ææ§è¡æ§ï¼è¯·ä½¿ç¨chmod +x your-script.pyï¼ é£ä¹ä½ å°±å¯ä»¥ä½¿ç¨./your-script.pyæ¥æ§è¡å®äºï¼å¨æ¬æä¸ä½ å°ä¼çå°è¿ç§æ¹å¼ï¼
æ¢ç´¢platform模å
platform模åå¨æ ååºä¸ï¼å®æå¾å¤è¿è¡æ们è·å¾ä¼å¤ç³»ç»ä¿¡æ¯çå½æ°ã让æ们è¿è¡Python解éå¨æ¥æ¢ç´¢å®ä»¬ä¸çä¸äºå½æ°ï¼é£å°±ä»platform.uname()å½æ°å¼å§å§ï¼
>>> import platform
>>> platform.uname()
('Linux', 'fedora.echorand', '3.7.4-204.fc18.x86_64', '#1 SMP Wed Jan 23 16:44:29 UTC 2013', 'x86_64')
å¦æä½ å·²ç¥élinuxä¸çunameå½ä»¤ï¼é£ä¹ä½ å°±ä¼è®¤åºæ¥è¿ä¸ªå½æ°å°±æ¯è¿ä¸ªå½ä»¤çä¸ä¸ªæ¥å£ãå¨Python 2ä¸ï¼å®ä¼è¿åä¸ä¸ªå
å«ç³»ç»ç±»å(æè
å
æ ¸çæ¬)ï¼ä¸»æºåï¼çæ¬ï¼åå¸çæ¬ï¼æºå¨ç硬件以åå¤çå¨ä¿¡æ¯å
ç»(tuple)ãä½ å¯ä»¥ä½¿ç¨ä¸æ 访é®ä¸ªå«å±æ§ï¼åè¿æ ·ï¼
>>> platform.uname()[0]
'Linux'
å¨Python 3ä¸ï¼è¿ä¸ªå½æ°è¿åçæ¯ä¸ä¸ªå½åå
ç»ï¼
>>> platform.uname()
uname_result(system='Linux', node='fedora.echorand',
release='3.7.4-204.fc18.x86_64', version='#1 SMP Wed Jan 23 16:44:29
UTC 2013', machine='x86_64', processor='x86_64')
å 为è¿åç»ææ¯ä¸ä¸ªå½åå
ç»ï¼è¿å°±å¯ä»¥ç®åå°éè¿ååæ¥æå®ç¹å®çå±æ§ï¼èä¸æ¯å¿
须记ä½ä¸æ ï¼åè¿æ ·ï¼
>>> platform.uname().system
'Linux'
platform模åè¿æä¸äºä¸é¢å±æ§çç´æ¥æ¥å£ï¼åè¿æ ·ï¼
>>> platform.system()
'Linux'
>>> platform.release()
'3.7.4-204.fc18.x86_64'
温馨提示:答案为网友推荐,仅供参考