On Thursday, July 10, 2014 12:17:25 PM UTC-4, Maurice Waka wrote: > > in my web2py app, i created this code that works well in python shell. > > python modules: > #The methods work in such a way that a user inputs an equation query to > get an answer. If it is an addition, method1 works it out, the same to > other methods being invoked to performing different codes > > def method1():# to do additions > name = input('Please Enter equation here: ').lower() > if '1 + 1': > answer = code > return answer > > def method2():# to do subtractions > name = input('Please Enter equation here: ').lower() > if '1 - 1': > answer = code > return answer > > > in the controller, I imported the methods as follows. There are many more > methods than these shown > > from applications ...... import method1 > from applications ...... import method2 > from applications ...... import method3 > from applications ...... import method4 > > method1 = method1 > method1 = method2 > method1 = method3 > method1 = method4 > > G0 = [method1, method2, method3, m3thod4] > > def Foo(): > code.. > for (func) in G0: > return func() > > The problem is that only method1 which is at position[0] in the list is > invoked and not other methods. I want to randomly call any method when a > user inputs any query. >
It is very difficult to see what you are trying to accomplish in those functions. But if your intent is to run through multiple functions, returning results, one way is with "yield": def runfuncs(): for func in g0: yield(func()) for result in runfuncs(): print "result: ",result -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.