如果运行python时需要根据当前运行操作系统的不同,来执行不同的操作,或者使用不同的配置,这时可以用platform模块来实现。
直接上代码:
1 2 3 4 5 6 7 8 9
| import platform print(platform.system())
if(platform.system()=='Windows'): print('Windows系统') elseif(platform.system()=='Linux'): print('Linux系统') else: print('其他')
|
下面列一些platform方法,有用到的也可以了试试。
1 2 3 4 5 6 7 8 9 10
| import platform platform.platform() platform.version() platform.architecture() platform.machine() platform.node() platform.processor() platform.uname() release='7', version='6.1.7601', machine='x86', processor='x86 Family 16 Model 6 Stepping 3, AuthenticAMD')
|