简体   繁体   English

您如何找出用户正在运行的操作系统?

[英]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.

相关问题 你如何找出“系统默认编码”是什么? - How do you find out what the “system default encoding” is? 如何找到我在任何操作系统上运行的文件的路径? (Python 3) - How do I find the path of the file I am running on any operating system? (Python 3) 如何获取使用 Django 的用户的操作系统? - How to get the Operating System of the user using Django? 如何确定运行Python脚本的操作系统是否类似于Unix? - How can I determine if the operating system a Python script is running on is Unix-like? (如何)可以将用户从Firebase中注销? - (How) can you log a user out of firebase? 如何在 Python Poetry 中指定对操作系统的依赖关系? - How can I specify dependencies on operating system in Python Poetry? 在Win 7操作系统上,如何使cygwin在python程序中使用pywin32库(的一部分)? (假设使用python版本2.7) - How can you get cygwin to use (a component of) pywin32 library in a python program on a Win 7 Operating System? (Assume python version 2.7 is used) 在Python中从ip查找操作系统 - Find Operating System from ip in Python 我怎样才能知道选择了哪个按钮 - how can I find out what button has been selected 如何找出python模块所属的软件包? - How can I find out what package that a python module belongs to?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM