>  Q&A  >  본문

python - 怎么写才合适才优雅

先上代码

    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包起来,以免程序中途停止。而且各个的处理方式不一样。这段代码要怎么写才合适才优雅?
为什么用优雅语言写出来的还是一坨......

天蓬老师天蓬老师2740일 전701

모든 응답(4)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-18 10:25:29

    으아악

    회신하다
    0
  • PHP中文网

    PHP中文网2017-04-18 10:25:29

    정보를 초기화합니다(예: info=[0,0,0]). 꽤 우아한 것 같아요!

    회신하다
    0
  • 黄舟

    黄舟2017-04-18 10:25:29

    JS 구현은 다른 언어도 비슷해야 합니다.

    으아악

    회신하다
    0
  • 阿神

    阿神2017-04-18 10:25:29

    문자열을 연결하는 것보다 형식 함수를 사용하는 것이 더 나은 선택입니다.

    으아악

    회신하다
    0
  • 취소회신하다