Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100382
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail |
|---|---|
| From | Grant Edwards <invalid@invalid.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Calling a list of functions |
| Date | Sun, 13 Dec 2015 17:41:27 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 42 |
| Message-ID | <n4kak7$n9h$1@reader1.panix.com> (permalink) |
| References | <mailman.210.1450027598.12405.python-list@python.org> |
| NNTP-Posting-Host | c-24-118-110-103.hsd1.mn.comcast.net |
| X-Trace | reader1.panix.com 1450028487 23857 24.118.110.103 (13 Dec 2015 17:41:27 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Sun, 13 Dec 2015 17:41:27 +0000 (UTC) |
| User-Agent | slrn/1.0.2 (Linux) |
| Xref | csiph.com comp.lang.python:100382 |
Show key headers only | View raw
On 2015-12-13, Ganesh Pal <ganesh1pal@gmail.com> 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:
I have no clue what your actual goal is, but it might be better to do
the function call in the try/except block inside the loop. Otherwise
your try/except block makes no sense because there's nothing being
executed inside it:
for test in [print1,print2,print3]:
try:
test()
except AssertionError as exc:
print exc
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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