import light
import urllib2
true = 1
while(true):
try:
response = urllib2.urlopen('http://192.168.1.6/light.php')
status = response.read()
except urllib2.HTTPError, e:
print e.code
except urllib2.URLError, e:
print e.args
print status
if status=='17':
light.lighton();
elif status=='0':
light.lightoff();
-16
A
回答
2
狂猜:你的響應以換行符結束。試試這個:
status = status.strip()
print status
if status=='17':
light.lighton();
elif status=='0':
light.lightoff();
+0
感謝它的作品 –
+0
請解釋爲什麼使用strip(); –
+0
因爲您的輸入以換行符結束。 'str.strip()'將刪除終端換行符。 –
相關問題
- 1. 如果(條件&&條件)不起作用,
- 2. 如果IE條件不起作用
- 3. 如果條件不起作用
- 4. 如果條件不起作用
- 5. Android:如果條件不起作用
- 6. Rails3 URI()如果條件不起作用
- 7. 如果IE條件不起作用
- 8. JavaScript如果條件不起作用
- 9. EJS如果條件不起作用
- 10. 多個如果條件不起作用
- 11. Javascript longhand如果條件不起作用
- 12. 如果條件不起作用?
- 13. 如果聲明條件不起作用
- 14. knockout.js如果條件不起作用
- 15. 如果條件不起作用
- 16. 如果條件不起作用
- 17. javascript如果條件不起作用?
- 18. 如果條件在jframe中不起作用
- 19. 如果條件在javascript中不起作用
- 20. 如果條件在sencha touch中不起作用
- 21. 如果條件在服務器中不起作用
- 22. Laravel如果條件在模板中不起作用?
- 23. 或條件在xlst中不起作用如果
- 24. 如果條件在自舉開關中不起作用
- 25. javascript如果條件&&條件不起作用
- 26. 如果沒有用戶界面,組件條件不起作用
- 27. 或條件在FTL中不起作用?
- 28. 如果background.js中的條件不起作用
- 29. 如果jsp中的條件不起作用
- 30. 否則如果PL SQL中的條件不起作用
如果你能提供有關目標的功能和發生的錯誤輸入,這將使它很容易幫助您。 –
請注意縮進。爲每個封裝提供一個標籤空間 – Mechanic
請檢查此鏈接 - http://stackoverflow.com/help/how-to-ask –