Quantcast
Channel: Calling a function of a module by using its name (a string) - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by Aliakbar Ahmadi for Calling a function of a module by using its name (a string)

$
0
0

In python3, you can use the __getattribute__ method. See following example with a list method name string:

func_name = 'reverse'l = [1, 2, 3, 4]print(l)>> [1, 2, 3, 4]l.__getattribute__(func_name)()print(l)>> [4, 3, 2, 1]

Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>