Skip to content Skip to sidebar Skip to footer

Variable Within A Variable In Python (3)

My head is probably in the wrong place with this, but I want to put a variable within a variable. My goal for this script is to compare current versions of clients software with cu

Solution 1:

You can put your functions into a dictionary:

per_version = {
    '83': v83,
    '82': v82,
}

and simply use that to map string to function:

per_version[program_main]('program_1')

However, you may want to instead parameterise your version functions; make one function that takes the version as a parameter:

def program_check(version, program_1=None, program_2=None, program_3=None):
   # ...

which then looks up default values per program_x parameter based no the version, again from a dictionary perhaps.


Post a Comment for "Variable Within A Variable In Python (3)"