Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100386 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2015-12-13 14:31 -0500 |
| Last post | 2015-12-13 14:31 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Calling a list of functions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-13 14:31 -0500
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2015-12-13 14:31 -0500 |
| Subject | Re: Calling a list of functions |
| Message-ID | <mailman.215.1450035089.12405.python-list@python.org> |
On Sun, 13 Dec 2015 22:56:31 +0530, Ganesh Pal <ganesh1pal@gmail.com>
declaimed the following:
>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
Note: syntax error... // is division operator, NOT a comment
>
>for test in range(len(print_test)):
> try:
> print_test[test]
> except AssertionError as exc:
Too late... Any assertion error will occur when you CALLED the
function. Here you are just retrieving the value the function returned (and
since they don't return anything, that value is None) and immediately
throwing it away.
testList = [print1, print2, print3] #do NOT CALL functions
for test in testList:
try:
test() #call the function now
except ... #whatever you intend to handle
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to top | Article view | comp.lang.python
csiph-web