2016-04-05 9 views
0

次のように私はIndexErrorを持っている:フォーマットの番号付けが失敗するのはなぜですか?

print ("Page {1} not found, {2}: {3}".format(page, sys.exc_info()[0], err)) 

IndexError: tuple index out of range 

私のコードは次のとおりです。

wait = WebDriverWait(browser, 10) 
     try:  
      wait.until(EC.visibility_of_element_located((By.ID, "summaries"))) 
     except (TimeoutException, ConnectionRefusedError) as err:#not a TimeoutError, not the basic set of exceptions 

      print ("Page {1} not found, {2}: {3}".format(page, sys.exc_info()[0], err)) 
      file.write("Page {} not found, {}: {}".format(page, sys.exc_info()[0], err)) 
      #file.write(str(summary)) 
      continue#next 

私はそれを解決:

print ("Page {} not found, {}: {}".format(page, sys.exc_info()[0], err)) 

しかし、私は中IndexErrorを得た理由を私は理解していません最初の場所は、{3}が存在するからですか?

これは、sys.exc_info()[0]がタプルであることを意味しますか? (type(sys.exc_info()[0])を印刷すると、返される値は<class 'type'>ですか? exc_info[0]はエラーの種類を返すように作られていますか?それはリストをコメントにし、あなたのインデックスとして言及されていますと同じように

+4

インデックスは、あなたが '"ページ{0}を使用すべきではない。1. – Selcuk

+1

、0で始まります。 .. {1} ... {2} "の代わりに" {1} ... {2} ... {3} "' – Andy

答えて

1

、インデックスは常に0から開始します:

print ("Page {0} not found, {1}: {2}".format(page, sys.exc_info()[0], err)) 
+0

うわー、ごめんなさい、本当に!それは私がそれを見ることができないほど明らかでした。ありがとう! –

関連する問題