大家好我想打印函数xcode_version的输出只有版本号,我的代码在这里包含2个错误,
第一个是:print(" Xcode版本:%s%s%s"%(G,R)xcode_version())
SyntaxError:语法无效
第二个是,当执行命令时,它只是按照它应该做的那样grep版本号(Xcode 7.0.1)但它打印了hole xcodebuild -version命令,结果是:Xcode 7.0.1 Build version 7A1001
这2个错误的解决方案?
#!/usr/bin/env python2.7
#
#Putty-On-Osx By Fedy Wesleti
import sys
import os
import subprocess
G = '\033[92m' #green
Y = '\033[93m' #yellow
B = '\033[94m' #blue
R = '\033[91m' #red
def xcode_version():
try:
xcode = subprocess.call(["xcodebuild","-version","&","grep","xcode"])
print(xcode)
except OSError as e:
if e.errno == os.errno.ENOENT:
print("Not Installed")
else:
# Something else went wrong while trying to run `wget`
raise
print("Xcode Version : %s%s%s"%(G,R)xcode_version())