如果条件不在python中工作

时间:2016-08-08 15:01:22

标签: python

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();

1 个答案:

答案 0 :(得分:2)

狂野猜测:您的回复以换行符终止。试试这个:

            status = status.strip()
            print status
            if status=='17':
                    light.lighton();
            elif status=='0':
                    light.lightoff();