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")

ParameterLists=[]
ComponentTestParam="Resistor,Cap,Diode"
RFTestParam="Start=1G,Stop=10G,Step100MHz"
OpticalTestParam="StartWL=1500,StopWL=1600,StepWL=10"
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:
    ParamIndex=(funcList.index(runfunc))
    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:

WordPress.com Logo

You are commenting using your WordPress.com 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