简体   繁体   中英

TypeError: 'generator' object has no attribute '__getitem__' in python

I'm writing a code that inputs data into different fields of a website, but only if there is data in the excel cell. this is my code:

import openpyxl
import pyautogui
import pyperclip
import time
def copy():
    pyautogui.keyDown('ctrl')
    pyautogui.press('c')
    pyautogui.keyUp('ctrl')
excelWorkbook = openpyxl.load_workbook('orderCodes.xlsx')
sheet = excelWorkbook.get_sheet_by_name('Sheet1')

for i in sheet.columns[1]:
    info=sheet['A'+i].value
    pyautogui.moveTo(305, 669, duration=0.25)
    pyautogui.click()
    pyautogui.typewrite(info)
    pyautogui.moveTo(295, 702, duration=0.25)
    pyautogui.click()
    pyautogui.typewrite('100')
    pyautogui.moveTo(217, 738, duration=0.25)
    pyautogui.click()
    time.sleep(1)
    pyautogui.moveTo(1521, 515, duration=0.25)
    pyautogui.dragTo(1531, 518, duration=0.25)
    quantity=copy()
    sheet['B'+i]=quantity

but i get this error:

    for i in sheet.columns[1]:
TypeError: 'generator' object has no attribute '__getitem__'

Why do i get this?

sheet.columns is a generator and you cannot __getitem__ it. (use [] to get something) Try

for i in sheet.columns:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM