Ask coding questions

← Back to all posts
Python functions question?
isaiah08 (63)

If i have a variable that contains a function name, and i wanted to run that function in the variable, how would i do it?

(Without just doing funcname().)

Answered by Pankak (48) [earned 5 cycles]
View Answer
isaiah08 (63)

I would be more inclined to believe you if your profile didn't say 'I don't know things.' @Pankak

Pankak (48)

@isaiah08 if you stored the names of the functions inside a list/array or object (depends on what language) and referenced the name to the function, then it could be possible

isaiah08 (63)

How? I'm using python. @Pankak

Bookie0 (6027)


Wdym "have a variable that contains a function name"?
do you mean like this:

def hello(): # the function

a_variable = hello() # a function in a variable

In this case, I don't think its possible, but I think you can store functions inside arrays tho...

isaiah08 (63)

i mean
x = 'func()'


Bookie0 (6027)

@isaiah08 hum ok have you tried that code in an editor? Ive never heard of the run keyword

isaiah08 (63)

neither have i, it was just an example. @Bookie0

Bookie0 (6027)

sry, idk, try googling it maybe.. @isaiah08