免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 14905 | 回复: 1
打印 上一主题 下一主题

python实例[判断操作系统类型] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-19 10:53 |只看该作者 |倒序浏览
本帖最后由 中关村村草 于 2011-01-19 10:54 编辑

转:iTech

python实例[判断操作系统类型]  



经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台(操作系统类型)。


代码如下:
  1. import platform

  2. def TestPlatform():
  3.     print ("----------Operation System--------------------------")
  4.     #Windows will be : (32bit, WindowsPE)
  5.     #Linux will be : (32bit, ELF)
  6.     print(platform.architecture())

  7.     #Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600
  8.     #Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final
  9.     print(platform.platform())

  10.     #Windows will be : Windows
  11.     #Linux will be : Linux
  12.     print(platform.system())

  13.     print ("--------------Python Version-------------------------")
  14.     #Windows and Linux will be : 3.1.1 or 3.1.3
  15.     print(platform.python_version())

  16. def UsePlatform():
  17.   sysstr = platform.system()
  18.   if(sysstr =="Windows"):
  19.     print ("Call Windows tasks")
  20.   elif(sysstr == "Linux"):
  21.     print ("Call Linux tasks")
  22.   else:
  23.     print ("Other System tasks")
  24.    
  25. UsePlatform()
复制代码
完!

感谢,Thanks!

论坛徽章:
0
2 [报告]
发表于 2011-01-19 11:31 |只看该作者
本帖最后由 a515200 于 2011-01-19 11:33 编辑

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP