python实例[判断操作系统类型]
生活随笔
收集整理的這篇文章主要介紹了
python实例[判断操作系统类型]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考文獻:http://bbs.chinaunix.net/thread-1848086-1-1.html
經常地我們需要編寫跨平臺的腳本,但是由于不同的平臺的差異性,我們不得不獲得當前所工作的平臺(操作系統類型)。
import platformdef TestPlatform():print ("----------Operation System--------------------------")#Windows will be : (32bit, WindowsPE)#Linux will be : (32bit, ELF)print(platform.architecture())#Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600#Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Finalprint(platform.platform())#Windows will be : Windows#Linux will be : Linuxprint(platform.system())print ("--------------Python Version-------------------------")#Windows and Linux will be : 3.1.1 or 3.1.3print(platform.python_version())def UsePlatform():sysstr = platform.system()if(sysstr =="Windows"):print ("Call Windows tasks")elif(sysstr == "Linux"):print ("Call Linux tasks")else:print ("Other System tasks")UsePlatform()//方法1TestPlatform()//方法2
我安裝了python以后,使用python GUI打開以后執行上述方法,其輸出結果如下圖所示。
本文轉自xwdreamer博客園博客,原文鏈接http://www.cnblogs.com/xwdreamer/p/3310134.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的python实例[判断操作系统类型]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 美股周五:三大股指均跌超1%,苹果跌近2
- 下一篇: python爬虫笔记(三):提取(二)