Python实现获取操作系统版本信息方法
作者:junjie 时间:2021-10-19 04:14:14
最近,想在我的YouMoney(http://code.google.com/p/youmoney/)里面增加提取用户操作系统版本信息。比如windows用户,可能要返回Windows XP ,或者Windows 2003, 苹果用户应该返回Mac OS X 10.5.8。用了很多办法,包括在mac系统里调用系统命令,取环境变量,等等。最后无意发现,原来python里里面有个platform模块就可以干这件事情。省事啊!
mac上这么干
localhost:~ apple$ python
Python 2.5.1 (r251:54863, Jun 17 2009, 20:37:34)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.mac_ver()
('10.5.8', ('', '', ''), 'i386')
>>> platform.version()
'Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386'
>>> platform.platform()
'Darwin-9.8.0-i386-32bit'
>>> platform.system()
'Darwin'
>>>
基本上用platform.platform()就足够了。如果是在windows上,专门还有个platform.win32_ver() 可用。
标签:Python,操作系统,版本信息
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pytorch平均池化nn.AvgPool2d()使用方法实例
2023-09-30 02:49:35
![](https://img.aspxhome.com/file/2023/1/104921_0s.png)
Pandas分组聚合之groupby()、agg()方法的使用教程
2021-07-07 00:29:55
![](https://img.aspxhome.com/file/2023/4/87744_0s.png)
asp datediff 时间相减
2011-03-25 10:34:00
Python中PyAutoGUI帮助文档(推荐!)
2022-12-18 20:50:16
django跳转页面传参的实现
2022-01-23 00:56:55
Django中对通过测试的用户进行限制访问的方法
2021-08-27 16:42:46
在Python中使用M2Crypto模块实现AES加密的教程
2022-09-29 17:43:59
python集成开发环境配置(pycharm)
2021-08-28 08:23:10
![](https://img.aspxhome.com/file/2023/8/115678_0s.jpg)
python实现自动发送邮件发送多人、群发、多附件的示例
2023-01-13 22:24:32
![](https://img.aspxhome.com/file/2023/5/107215_0s.jpg)
创建IE各版本专属CSS方法
2007-09-27 12:16:00
javascript面向对象技术基础(一)
2010-02-07 13:01:00
Frontpage轻松下载网页或站点
2007-10-22 13:14:00
![](https://img.aspxhome.com/file/UploadPic/200710/22/20071022131645701s.gif)
Python为何不能用可变对象作为默认参数的值
2022-11-30 13:42:04
![](https://img.aspxhome.com/file/2023/1/105621_0s.jpg)
设计从"心"开始
2011-05-21 08:37:00
在JAVASCRIPT中LEFT,RIGHT,MID函数的等价函数
2009-07-21 12:37:00
asp.net中调用winrar实现压缩解压缩的代码
2023-07-18 14:30:30
深入浅析python继承问题
2023-05-20 15:22:26
Python库skimage绘制二值图像代码实例
2023-06-12 15:05:33
![](https://img.aspxhome.com/file/2023/2/59122_0s.png)
Python3 获取文件属性的方式(时间、大小等)
2022-05-06 09:13:41
![](https://img.aspxhome.com/file/2023/7/112787_0s.jpg)
在ASP中使用SQL语句之2:用WHERE子句设置查询条件
2009-04-21 13:03:00