django - Get all functions inside a Python Package for getattr -
i have 2 python files , both @ same directory level this
project |> tasks.py |> queue.py i have function in tasks.py file
def foo(message): # perform functions on message data # blah blah and function in queue.py file this
import project.tasks def run_task(function_name, data): # function name string tells function call in tasks.py file return getattr(project.tasks, function_name)(data) i not want hard code function name. want access them dynamically on basis of function_name parameter. tasks.py has become large therefore want divide in parts. thing did moved tasks.py file in python package this.
project |> tasks |> __init__.py |> tasks.py |> queue.py the question want ask how can modify run_task function in order work struction. getattr function task first argument object. there other option avilable can used access function inside task package.?
answer @jonrsharpe comment. put following in in __init__.py
from .tasks import *
to expose names in tasks.py tasks module. files have in tasks package.
Comments
Post a Comment