Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100386

Re: Calling a list of functions

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: Calling a list of functions
Date 2015-12-13 14:31 -0500
Organization IISS Elusive Unicorn
Message-ID <mailman.215.1450035089.12405.python-list@python.org> (permalink)
References <CACT3xuXP640BS3V+w1ABAjG5OvNWGb3yq6dEQZkZhdFaeUKP=A@mail.gmail.com>

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Calling a list of functions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-13 14:31 -0500

csiph-web