"リスト索引が範囲外です"というエラーが表示されます。私はコード内のどこかで、2つのセット番号の範囲から番号を呼び出すことができる場所を探しました。私が間違っていると私は謝ります。私はこれに全く新しいです。リスト索引が範囲外です - 範囲外の変数を見つけることがありません
#!/usr/bin/python
import sys,time,geolocation,publisher
from subprocess import call
SleepTime = 10 # seconds
_lat = 0.00
_lon = 0.00
def maintain():
global _lat
global _lon
(lat,lon,accuracy) = geolocation.getLocation()
if(lat != _lat or lon !=_lon):
data = str(lat) + "," + str(lon) + "," + str(accuracy)
print ("publishing") , data
publisher.publishtoInternet(data)
_lat = lat
_lon = lon
else:
print ("no change in coordinates")
print ("program begins")
while True:
try:
maintain()
except Exception as inst:
print (type)(inst), ('exception captured')
print (inst)
sys.stdout.flush()
#file = open('/tmp/loctracker.error.log','a')
#file.write('exception occured, trying to reboot')
#file.close()
#call(["sudo","reboot"])
#break
for i in range(0,SleepTime):
sys.stdout.write ("restarting in %d seconds " % (SleepTime-i))
sys.stdout.flush()
time.sleep(1)
プログラムは、ネットワークのIPアドレスから位置を検索し、その後、Sparkfish.comに送信されている場所を送り返しマップをGoogleにデータを送信すると仮定されています。ここでは
コードですデータを格納する。
以下の回答でコードを変更しましたが、まだ運がありません。ここにコードとスクリーンショットがあります。
#!/usr/bin/python
import sys,time,geolocation,publisher
from subprocess import call
SleepTime = 10 # seconds
_lat = 0.00
_lon = 0.00
def maintain():
global _lat
global _lon
(lat,lon) =geolocation.getLocation()
if(lat != _lat or lon != _lon):
data = str(lat) + "," + str(lon) + "," + str(accuracy)
print ("publishing") , data
publisher.publishtoInternet(data)
_lat = lat
_lon = lon
else:
print ("no change in coordinates")
print ("program begins")
while True:
try:
maintain()
except Exception as inst:
print (type)(inst), ('exception captured')
print (inst)
sys.stdout.flush()
#file = open('/tmp/loctracker.error.log','a')
#file.write('exception occured, trying to reboot')
#file.close()
#call(["sudo","reboot"])
#break
for i in range(0,SleepTime):
sys.stdout.write ("restarting in %d seconds " % (SleepTime-i))
sys.stdout.flush()
time.sleep(1)
画面では、それが言うように、
geolocation.getLocation()
リターンのみ二つのオブジェクト、すなわち緯度と経度をhttps://developers.google.com/maps/documentation/geolocation/intro#responses で適切ご覧になる場合があります !(https://onedrive.live.com/redir?resid=2BBD197F439CC237!30330&authkey=!AJv8LN5_4gHqKpI&ithint=file%2c)
?また、あなたの関数maintain()が正しく字下げされていない – Keatinge
完全なトレースバックが役に立ちます。 – nephlm
トレースバックメッセージは**エラーが発生した正確な*を見つけるのに**非常に**役立ちます。 –