先上代码
try:
res+="会话数<span style='color: blue;'> "+str(info[1]).strip('\n')+"</span><br>"
except Exception,e:
print e
try:
res+="失效数<span style='color: blue;'> "+str(info[2]).strip('\n')+"</span><br>"
except Exception,e:
print e
try:
res+="连接数<span style='color: blue;'> "+str(info[3]).strip('\n').strip('\t')+"</span><br>"
except Exception,e:
print e
上面的info[1]、info2[2]、info3[3],可能并不存在,所以我用try包起来,以免程序中途停止。而且各个的处理方式不一样。这段代码要怎么写才合适才优雅?
为什么用优雅语言写出来的还是一坨......
Initialize info, for example info=[0,0,0] I think this is quite elegant!
JS implementation, similar to other languages.
Using the format function is a better choice than concatenating strings.