Search code examples
python-3.xpycharmpyautogui

How to give a Subclip a new name in Python using PyAutoGUI?


Complete beginner here making my first program with PyAutoGui as I cannot get access to the software's API. My issues are currently being that I am unable to come up with a solution to name each subclip with a different appended letter on the end. The naming convention should go like so, MI899001~AA, MI899001~AB, MI899001~AC, MI899001~AD. The only thing that changes is the last letter.

Below is the relevant code I'm currently using for the program I am writing;

def naming_promo():
x = string.ascii_uppercase
pyautogui.typewrite('DNH~P336007A' + x[0][0])

for i in range(7):
   if i == 0:
      sub_clip_clean()
   else:
      if i >= 1:
        pyautogui.typewrite('567890qwe', 0.2)
        sub_clip_package()
   naming_promo() # See above Fn for method
   pyautogui.moveTo(646, 404, duration=0.50)
   pyautogui.click()
   move_clips()

The naming_promo() takes the ascii_uppercase and types the first letter. I however can't figure out how to iterate through each character in the string as the For Loop repeats. I've googled many solutions, but I guess I can't get my head around how to do a loop in a loop and increment the x value used each time.

This is my first post so apologies for any etiquette I break. Any help and explanation would be greatly appreciated.


Solution

  • This is my first answer so apologies for any etiquette I break. I'm not sure I understand everything here, since there's a few functions in the code that I don't know about. However, are you just looking for something like:

    def naming_promo(n):
    x = string.ascii_uppercase
    pyautogui.typewrite('DNH~P336007A' + x[0][n])
    

    and further down in your code, simply create a variable and increment it up one after use:

    m = 0
    for i in range(7):
        if i == 0:
            sub_clip_clean()
        else:
            if i >= 1:
                pyautogui.typewrite('567890qwe', 0.2)
                sub_clip_package()
        naming_promo(m) # See above Fn for method
        m += 1
        pyautogui.moveTo(646, 404, duration=0.50)
        pyautogui.click()
        move_clips()