gpt4 book ai didi

Python os.name 在 Windows 7 上返回 nt

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:03 24 4
gpt4 key购买 nike

Python os.name 在 Windows 7 上返回“nt”

我正在使用 os.name 获取运行当前脚本的当前操作系统的名称。但奇怪的是,它返回的不是“windows 7”,而是“nt”。

代码如下:

import os

print(os.name)

结果:

nt

最佳答案

你可以使用platform模块来检查:

In [244]: import platform

In [247]: platform.version()
Out[247]: '6.1.7601'

In [248]: platform.system()
Out[248]: 'Windows'

In [249]: platform.release()
Out[249]: '7'

In [250]: platform.win32_ver()
Out[250]: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')

In [268]: platform.platform()
Out[268]: 'Windows-7-6.1.7601-SP1'

所以只需使用 platform.system() == 'Windows' 和 platform.release() == 7 来检查 ;)

或者更简单的 platform.platform() 中的“Windows-7”

关于Python os.name 在 Windows 7 上返回 nt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22321397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com