简体   繁体   中英

How to call functions from a dictionary in python

what I am trying to do is use a dictionary of references to functions. what I want to do is something like

alive = {var1: <someFunction>, var2: <someOtherFunction>};
p = multiprocessing.Process(target=var1, args=(<someArgs>))

I want var1 to be a reference to a function either in the .py file or in one that is in a given location.

Does anyone have any pointers to source code, tutorials, or the like?

How about:

alive = {'var1': <someFunction>, 'var2': <someOtherFunction>}
p = multiprocessing.Process(target=alive['var1'], args=(<someArgs>))

you can call that function by importing your eg.py file

import eg

eg.var1()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM