我有几个这样设计的defs:
def first():
try:
"Talking Business Here"
except IOError, e:
print e
else:
"Make a deal"
def second():
try:
"Business solution"
except IOError, e:
print e
first()
else:
third()
def third():
#Similar functionality
def main():
second()
if __name__ == 'main':main()
我想将所有except
消息和print
消息收集到标准输出中。然后在这个 python 脚本中,我想检查标准输出,看看是否有任何消息,比如:
if len(sys.stdout) > 0 :
#Send me an email
任何帮助/建议表示赞赏。