Les Partages de Memiks
Tag cloud
Picture wall
Daily
RSS Feed
  • RSS Feed
  • Daily Feed
  • Weekly Feed
  • Monthly Feed
Filters

Links per page

  • 20 links
  • 50 links
  • 100 links

Filters

Untagged links
Python: Call Functions by String | Open Source Kitty https://arithxu.com/2017/10/14/Python-Call-Functions-by-String/
Fri Feb 22 17:20:30 2019 archive.org
QRCode
thumbnail

Approach 3: Synbol Tables

Built-in function locals() and globals() return a dictionary of current local and global symbol table respectively. So you could call a function just like:

def my_func(arg1, arg2):
print(arg1, arg2)
return arg1 + arg2

r = locals()['my_func'](http://1, 2)
print(r)

The output is:

1 2
3

This approach is just like the examples provided in the very beginning of this post, in which, I maintained a symbol table by myself and called the function by its string-typed name.

python dynamic call function
4756 links, including 1670 private
Shaarli - The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community - Theme by kalvn