What is the best way to go about calling a function in Python? I need to get the return value of the function This is the function I want to call in another file in the same folder
Asked
Active
Viewed 181 times
2 Answers
1
You can import your function(s) and find it in globals()
dictionary:
from your_module import pullData, other_function1, other_function2
function_name = 'pullData'
function = globals()[function_name]
returned_value = function(price, allprice)
another way is to import the module and get the function from its attributes:
import your_module
function_name = 'pullData'
function = getattr(your_module, function_name)
returned_value = function(price, allprice)

Yevhen Kuzmovych
- 10,940
- 7
- 28
- 48
0
from <file_name> import pullData
Where file_name
is the file that exposts the function pullData

Ilario Pierbattista
- 3,175
- 2
- 31
- 41

The_Red_Bird
- 41
- 1