Python , Running functions in a list

Example only( was create under Python3.7  while inside Anaconda Spyder,

Showing a method for running functions from a list with arg from a parameter list (just a str  for example)

also sending parameters to function bases on a parameter list.

Task Run Test function as listed in a function list(test list).


# -*- coding: utf-8 -*-
Created on Thu Oct 24 08:29:30 2019

@author: aleja

def ComponentTest(strParameter=""):
    print("Loaded Param:",strParameter)
    print("Running Component Test")

def RFTest(strParameter):
    print("Loaded Param:",strParameter)
    print("Running RF Test")

def OpticalTest(strParameter):
    print("Loaded Param:",strParameter)
    print("Running Optical Test")

ParameterList=[ComponentTestParam,RFTestParam,OpticalTestParam] #same order as test

funcList=[ComponentTest,RFTest,OpticalTest]  #same order as parameters
print("\nStart testing per function list\n")
for runfunc in funcList:
    runfunc(ParameterList[ParamIndex])  #notice running a function that was in the list, cool
     #print(eval(runfunc.__name__+"Param"))  # this is a way call a variable when given as a string
    print(runfunc.__name__," Done\n")


Output of console

Python functions in list

About LV_TS_Test_Engineer_3000_VI

Automated Test Equipment Software
This entry was posted in Test Sector and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s