Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100406
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-12-13 21:54 -0800 |
| References | <mailman.210.1450027598.12405.python-list@python.org> |
| Message-ID | <ef8e07e6-c13a-4b1b-a38e-a52099ae5240@googlegroups.com> (permalink) |
| Subject | Re: Calling a list of functions |
| From | Anand <abapat@gmail.com> |
On Sunday, December 13, 2015 at 9:26:52 AM UTC-8, Ganesh Pal wrote:
> Hi Team,
>
> Iam on linux and python 2.7 . I have a bunch of functions which I
> have run sequentially .
> I have put them in a list and Iam calling the functions in the list as
> shown below , this works fine for me , please share your
> opinion/views on the same
>
>
> Sample code :
>
> def print1():
> print "one"
>
> def print2():
> print "two"
>
> def print3():
> print "three"
>
> print_test = [print1(),print2(),print3()] //calling the function
>
> for test in range(len(print_test)):
> try:
> print_test[test]
> except AssertionError as exc:
>
>
> Regards,
> Ganesh
def print1():
print "one"
def print2():
> print "two"
>
> def print3():
> print "three"
>
> print_test = [print1(),print2(),print3()] //calling the function
If the idea is to have a 'pointers to function array' (as in C), you can do this:
fun_arr=[print1,print2,print3]
# Execute now
[ f() for f in fun_arr ]
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Calling a list of functions Ganesh Pal <ganesh1pal@gmail.com> - 2015-12-13 22:56 +0530
Re: Calling a list of functions BartC <bc@freeuk.com> - 2015-12-13 17:38 +0000
Re: Calling a list of functions Grant Edwards <invalid@invalid.invalid> - 2015-12-13 17:41 +0000
Re: Calling a list of functions Steven D'Aprano <steve@pearwood.info> - 2015-12-14 13:43 +1100
Re: Calling a list of functions Chris Angelico <rosuav@gmail.com> - 2015-12-14 13:49 +1100
Re: Calling a list of functions Anand <abapat@gmail.com> - 2015-12-13 21:54 -0800
csiph-web