0

I'm currently working on some code for one of my classes which is shown right here (changed names/addresses to hide names).

# coding=utf:8
#————————————————————————Attendance Checker Start————————————————————————#
import bluetooth
import time

#-----Function Definition Start-----#
def student_check(index):
    result = bluetooth.lookup_name(blue_address_list[index], timeout=1)

    if (result is not None):
        return True
    else:
        return False
#-----Function Definition End-----#


#————————Defined Dictionary Start————————#
blue_student_list = ['Name1', 'Name2', 'Name3', 'Name4',
                  'Name5', 'Name6', 'Name7', 'Name8',
                  'Name9']
blue_address_list = ['Address1', 'Address2', 'Address3', 'Address4', 'Address5', 'Address6', 'Address7', 'Address8', 'Address9']
#—————————Defined Dictionary End—————————#

#———————————————Print Method Start———————————————#

print ' '
time.sleep(1)
print 'Checking who is here on ' + time.strftime('%b %d, %Y', time.gmtime())
print ' '
time.sleep(1)

for i in range(0, len(blue_address_list)):
    if (student_check(i)):
        print blue_student_list[i] + ': Present '
    else:
        print blue_student_list[i] + ': Absent '

print 'Script Completed'

#————————————————Print Method End————————————————#

#—————————————————————————Attendance Checker End—————————————————————————#

My issue is when the script starts, I get this output.

Checking who is here on Feb 24, 2016

Name1: Present
Name2: Absent
Name3: Absent
Name4: Absent
Name5: Absent
Name6: Absent
Name7: Absent
Name8: Absent
Name9: Absent

Script Completed

My issue with this is not them being absent. I have another device paired under Name7 that says absent no matter what. I believe it actually checks on the first one and fails the rest once one goes absent. The reason I think this is because they all go absent at the exact same time, it doesn't have any delay unlike the first which has a delay when checking for the nearby device.

4

1 回答 1

1

__sizeof__返回给定对象的内部大小(以字节为单位),而不是项目数。我认为你应该使用len(blue_address_list)它来代替它。

编辑:增加超时将解决问题,似乎bluetooth.lookup_name无法在给定时间响应。

于 2016-02-25T15:17:13.437 回答