检测操作系统 [英] detecting the operating system

查看:83
本文介绍了检测操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我尝试在这个Usenet小组上进行Google搜索,但是找不到

解决方案,所以我在这里发布我的问题(如果有更好的存档而不是

Google中的那个,请告诉我。)


有谁知道如何检测当前的操作系统

Python程序正在运行,尤其是它是Windows还是Unix?我有一个

程序,需要在c:\ test中搜索文件。如果它在

Windows下运行,并且/ home / user / test如果它是在Unix下运行的,那么我能想到的最简单的解决方案就是检测操作系统,但是如果有人可以建议一个解决方法,那就是也好。

OK, I tried a Google search on this Usenet group but couldn''t find a
solution, so I''m posting my question here (if there''s a better archive than
the one in Google, please let me know).

Does anybody know how to detect the operating system under which the current
Python program is running, especially whether it''s Windows or Unix? I have a
program that needs to search for files in "c:\test" if it''s running under
Windows, and "/home/user/test" if it''s running under Unix, so the simplest
solution I can think of is to detect the operating system, but if anyone
could suggest a workaround, that would also be fine.

推荐答案

Woojay Jeon写道:
Woojay Jeon wrote:
好的,我在这个Usenet小组上尝试过Google搜索但是没能找不到
解决方案,所以我在这里发布我的问题(如果有一个比谷歌更好的存档,请告诉我)。
程序,需要在c:\ test中搜索文件。如果它在
Windows下运行,并且/ home / user / test如果它在Unix下运行,那么我能想到的最简单的解决方案就是检测操作系统,但是如果有人可以提出解决方法,那也没关系。
OK, I tried a Google search on this Usenet group but couldn''t find a
solution, so I''m posting my question here (if there''s a better archive than
the one in Google, please let me know).

Does anybody know how to detect the operating system under which the current
Python program is running, especially whether it''s Windows or Unix? I have a
program that needs to search for files in "c:\test" if it''s running under
Windows, and "/home/user/test" if it''s running under Unix, so the simplest
solution I can think of is to detect the operating system, but if anyone
could suggest a workaround, that would also be fine.




sys.platform

Ray Smith



sys.platform

Ray Smith


" Ray Smith" < ra*@rays-web.com>在消息中写道

新闻:40 ****** @ news.syd.ip.net.au ...
"Ray Smith" <ra*@rays-web.com> wrote in message
news:40******@news.syd.ip.net.au...
Woojay Jeon写道:
- SNIP -
sys.platform

史密斯
Woojay Jeon wrote: - SNIP -
sys.platform

Ray Smith




哎呀,这是一个非常愚蠢的问题,不知道怎么样我错过了。

谢谢!



Oops, that was quite a dumbass question, don''t know how I missed that.
Thanks!


Woojay Jeon写道:
Woojay Jeon wrote:
有谁知道如何检测运行当前Python程序的操作系统,特别是它是Windows还是Unix?我有一个程序需要在c:\ test中搜索文件。如果它在Windows下运行,并且/ home / user / test如果它在Unix下运行,那么我能想到的最简单的解决方案就是检测操作系统,但是如果有人可以建议一个解决方法,那也没关系。
Does anybody know how to detect the operating system under which the
current Python program is running, especially whether it''s Windows or
Unix? I have a program that needs to search for files in "c:\test" if it''s
running under Windows, and "/home/user/test" if it''s running under Unix,
so the simplest solution I can think of is to detect the operating system,
but if anyone could suggest a workaround, that would also be fine.




而不是sys.platform,os.name可能会有所帮助,因为它不太具体。我

认为你会得到os.name ==" posix"对于Unix / Linux等和os.name ==

" nt" for win32。


Peter



Instead of sys.platform, os.name might be helpful as it is less specific. I
think you will get os.name == "posix" for Unix/Linux etc. and os.name ==
"nt" for win32.

Peter


这篇关于检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆