Hi, a question for Python,
a want to build a Dict {} with pointers to functions,
for example:
key1:functionPointer1
key2:functionPointer2
how to store the function addresses ?
how to execute them ?
Thanks in advance for your reply.
Hi, a question for Python,
a want to build a Dict {} with pointers to functions,
for example:
key1:functionPointer1
key2:functionPointer2
how to store the function addresses ?
how to execute them ?
Thanks in advance for your reply.
Functions are first-class objects – the name of the functions is, effectively, a pointer to a function.
So if you have
def f1(x):
return x+1
def f2(x):
return f"my name is {x}"
then you can just do
fundict = {"key1": f1, "key2": f2}
and then
fundict["key1"](3) ### -> 4
Thanx Andrew, for quick reply !