Quantcast
Viewing latest article 17
Browse Latest Browse All 22

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

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 latest article 17
Browse Latest Browse All 22

Trending Articles



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