0

Web サイトから 1 時間ごとに読み取り、特定の文字列を検索する小さなスクリプトを作成しました。この文字列は、計算したい数値です。

「nohup python3 /path/to/script &」でスクリプトを実行すると、しばらくは機能します。数時間後、数日後、または弱い場合でも、スクリプトは "~/nohup" のエラー出力で動作を停止し、float() が 41 行目の文字列を変換できないというエラーが出力されます。

line 41: current_value = float(html_content[temperature_pos_begin:temperature_pos_end])

スクリプト全体: http://pastebin.com/AEY1Kafa

4

1 に答える 1

2

例外ハンドラーを使用して、エラーの原因を確認してください。温度が利用できない場合、おそらく何らかのプレースホルダーを使用します。

try:
    current_value = float(html_content[temperature_pos_begin:temperature_pos_end])
except ValueError:
    print "Failed to convert %r to a float"%html_content[temperature_pos_begin:temperature_pos_end]
    current_value = None # or something that makes sense
于 2012-11-19T09:23:47.370 に答える