我有以下片段:
#!/usr/bin/env python
import sys
mypath = "D:\inetpub\wwwroot"
if mypath:
try:
print "Path: %s" % mypath
if mypath.find("/"):
print "OS: Linux/Unix"
elif mypath.find(":"):
print "OS: Windows"
else:
print "OS: Unknown"
except:
print "Error"
else:
print "[?] OS detection failure."
执行输出:
$ python test.py
Path: D:\inetpub\wwwroot
OS: Linux/Unix
我究竟做错了什么?我得到与预期相反的结果。还是有更好的方法来做到这一点?“ /”-> Linux / Unix和“:”-> Windows
相关分类