[英]How can you find out what operating system the user is running?
I want to find out what OS a person has in Python. I know I could always do this:我想找出一个人在 Python 中拥有的操作系统。我知道我总是可以这样做:
try:
os.system(unixonlycommand)
except:
os.system(windowsonlycommand)
But is there another way to do it?但是还有另一种方法吗? A special module for that or something?一个特殊的模块之类的?
Use platform.system
:使用platform.system
:
Returns the system/OS name, eg
'Linux'
,'Windows'
, or'Java'
.返回系统/操作系统名称,例如'Linux'
、'Windows'
或'Java'
。 An empty string is returned if the value cannot be determined.如果无法确定该值,则返回一个空字符串。
You should also look at the other methods in the platform
module, depending on exactly what you're trying to do.您还应该查看platform
模块中的其他方法,具体取决于您要执行的操作。
Also relevant: sys.platform
.也相关: sys.platform
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.