Re: [Tutor] list of functions
On 29/03/17 22:23, kay Cee wrote: > func_list = ('func1', 'func2', 'func3') > > for f in func_list: > eval(f)() Instead of using strings just use the functions directly: func_list = (func1, func2, func3) for f in func_list: f() That avoids the potentially insecure eval and will be faster too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] list of functions
Greetings all, I would like to use a list of functions for an automation project, and this is the prototype I came up with ### def func1(): print('func1') def func2(): print('func2') def func3(): print('func3') func_list = ('func1', 'func2', 'func3') for f in func_list: eval(f)() # The output shows as intended, but I'd like to know if there are any safety or performance issues using this prototype or if there is a better way to acheive a list of functions. Thanks in advance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor