-1

What I want to do is to have an function called from an array of function. I did my homework and came across this stackOverflow question. https://stackoverflow.com/questions/30549292/in-python-how-do-i-run-an-array-of-functions

However the code offered in it works for calling all the functions in the array in turn. What I would like to do is to call just one function in the array depending on the array index. What I would call in assembly terms "a vectored jump to a subroutine".

I am using Circuit Python on a RP2040

Here is the code:-

def one():
    print("One")

def two():
    print("Two")

def three():
    print("Three")

arr = (one,two,three)


for fnc in arr:
    fnc()

This runs through each function in turn

However what I would like to do is to call just one function depending on an array index. Something like "call function arr[i]

Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
Grumpy-Mike
  • 41
  • 1
  • 5

1 Answers1

0

A function will be called with just

List[k]()

So just use a for loop if you really need it, or call them individually when needeed.

FelixCrd
  • 1
  • 2