-1

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

enter image description here

rioV8
  • 24,506
  • 3
  • 32
  • 49
Ali
  • 3
  • 4
  • You can import the file without the ```py``` extension, then call the ```pullData``` –  Aug 12 '21 at 15:08

2 Answers2

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