Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Gspread Google sheets查找for循环中的行和列值_Python_Google Sheets_Row_Cell_Gspread - Fatal编程技术网

Python Gspread Google sheets查找for循环中的行和列值

Python Gspread Google sheets查找for循环中的行和列值,python,google-sheets,row,cell,gspread,Python,Google Sheets,Row,Cell,Gspread,我制作了这个程序,它将使用Arduino串行端口的输入运行python脚本。基本上,我的项目是一个考勤设备,人们可以使用RFID读卡器登录和注销。如何在列表中查找相关数据点 我将一行电子表格(例如名称列表)分配给一个变量。然后我搜索每个单元格,直到找到正确的名称。问题是我想找到我在其中找到名称的单元格列。我不知道如何做到这一点,但我写了一些东西作为一个占位符+我希望它如何在代码中标记为“参考点1”的行中工作 # Credentials and imports ^^ file = gspread

我制作了这个程序,它将使用Arduino串行端口的输入运行python脚本。基本上,我的项目是一个考勤设备,人们可以使用RFID读卡器登录和注销。如何在列表中查找相关数据点

我将一行电子表格(例如名称列表)分配给一个变量。然后我搜索每个单元格,直到找到正确的名称。问题是我想找到我在其中找到名称的单元格列。我不知道如何做到这一点,但我写了一些东西作为一个占位符+我希望它如何在代码中标记为“参考点1”的行中工作


# Credentials and imports ^^
file = gspread.authorize(credentials) # authenticate with Google
sheet = file.open("RFID-2019-2020-Attendance").sheet1 # open sheet
#placeholder
date_added = False
name_added = False
name_matched = False
current_card_number = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]


def current_card_name():
    for id in id_Numbers:
        if id == current_card_number and name_matched == False:
            matching_name = sheet.cell(id.row,1)
            name_matched = True
    return matching_name


def current_card_number():
        card_num = serial.read_until('*', 28)
        return card_num


while True:
    print('Scan A Card To Sign In')
    id_Numbers = sheet.col_values(2)
    names = sheet.row_values(1, 1)
    dates = sheet.row_values(1)

    for name in names:
        if name.value == current_card_name(): # if card is alread in system
            print('Card Recognized...')
            for date in dates:# check if date is already a headre
                if date == datetime.today().strftime('%Y-%m-%d'):# date is in header
                    # reference point 1
                    sheet.update_cell(date.row,name.column, 'P')
                else:
                    #date not in header
                    for date in dates:# find new open spot in header
                        if date == '' and date_added == False:# if date is non existant
                            # write date in new row
                            sheet.update_cell(date, 1, datetime.today().strftime('%Y-%m-%d'))
                            date_added = True
                        #write "P" in the new date column
                        sheet.update_cell(date.row, name.column, 'P')
                        date_added = False # reset variable after date is added
                        print('Welcome ' + name + '! You Have Been Signed In ')

        else:# if card is not in system
                print('Card not Recognized.')
                print('1) Add new Profile')
                print('2) Go back to main menu')
                print('3) Change card')
                cmd_input = input()
                if cmd_input == '1':
                    print('What is the name associated with this card?')
                    cmd_input = input()
                    for name in names:
                        if name == '' and name_added == False:
                            sheet.update_cell(name.row, 1,cmd_input)# names in first column
                            sheet.update_cell(name.row, 2, current_card_number())#puts card ID in second columnFrea
                            name_added = True
                            print('New profile Created! Returning to main Menu...')
                if cmd_input == '2':
                    print('Returning to main screen...')
                if cmd_input == '3':
                    print('What is the name of the Profile associated with the card?')
                    cmd_input = input()
            # add new card y/n
            # no will take you back to main screen
我知道这是错误的,所以我没有运行它。任何帮助都将不胜感激