Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

Add new number from a list every time a function is repeated (Python 3)

I have this list:

list_vin = ['D03960','D03987','D04014']

This function which uses the list:

def lol():
    pyautogui.click(699,60)
    pyautogui.hotkey('command','f')
    pyautogui.typewrite(list_vin[2])
    pyautogui.press('enter')
    time.sleep(0.5)
    pyautogui.hotkey('command','p')
    pyautogui.press('enter')
lol()

And this function to repeat the list:

def refresh():
    schedule.every(int(1)).seconds.do(lol)
    while 1:
        schedule.run_pending()
        time.sleep(1)
refresh()

How can I make it so that every time the function repeats a new item is used from the list? E.g. first time function runs it uses this D03960, second time the function runs it uses this D03987 in this line of the function pyautogui.typewrite(list_vin[2])

I am a beginner, don't be mad if I phrased the question incorrectly, hopefully, you understand it. Btw feel free to change the code entirely.

Thanks in advance.

question from:https://stackoverflow.com/questions/65602004/add-new-number-from-a-list-every-time-a-function-is-repeated-python-3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use .pop()

The pop() method returns the item present at the given index. This item is also removed from the list.

def lol():
    pyautogui.click(699,60)
    pyautogui.hotkey('command','f')
    pyautogui.typewrite(list_vin[2])
    pyautogui.press('enter')
    time.sleep(0.5)
    pyautogui.hotkey('command','p')
    pyautogui.press('enter')
    list_vin.pop()
lol()

So every time you run lol() your iterable list_vinwill become "shorter"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...