0

I'm working with some software for which the names evolve. This means that if I'm using the awesome pywinauto, the names can be different. Depending on the generation I'm using, for example, I might have

app.Book1AlphaXL.set_focus()
app.Book1AlphaXL.Lists.click()

or

app.Book1BetaXL.set_focus()
app.Book1BetaXL.Lists.click()

Instead of an ever expanding big fat switch statement, I'd like to alter the Book*XL part in the code so that it could be set from a JSON input or command line argument. What could be the best approach there?

Should I spin up a function file on the fly which would handle this? (That could be written actually, but feels sick.) Is there some kind of {Param} functionality in Python I can use?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
SlightlyKosumi
  • 701
  • 2
  • 8
  • 24
  • 3
    I think that "variable variable names" is enough of a well known anti-pattern that I would do anything to avoid it. Is this something you could accomplish using a dictionary instead? I'm having difficulties understanding your usecase. – JNevill Aug 25 '23 at 16:08
  • 2
    Using a dictionary is a better choice here. – shaik moeed Aug 25 '23 at 16:09
  • It can be handled easily by pywinauto using `app.window(title_re="Book*XL")` or ``app.window(title="Book" + str(param) + "XL")``. – Vasily Ryabov Aug 25 '23 at 18:16
  • Using a dictionary was indeed the solution which I didn't realise existed here. – SlightlyKosumi Aug 29 '23 at 10:27

0 Answers0