Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: Calling a list of functions Date: Sun, 13 Dec 2015 14:31:22 -0500 Organization: IISS Elusive Unicorn Lines: 49 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de z2D9AXpD+iANzLqqy07ZYALqmqLHmptaY+4ZZyrfdaMQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'none)': 0.07; 'message-id:@4ax.com': 0.09; 'operator,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; '2.7': 0.13; 'syntax': 0.13; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'retrieving': 0.16; 'test()': 0.16; 'try:': 0.18; 'url:home': 0.18; 'team,': 0.18; '2015': 0.20; 'dec': 0.23; 'subject:list': 0.26; 'header:X-Complaints-To:1': 0.26; 'linux': 0.26; 'error': 0.27; 'function': 0.28; 'fine': 0.28; 'away.': 0.29; 'division': 0.29; 'print': 0.30; 'code': 0.30; 'returned': 0.32; 'run': 0.33; 'except': 0.34; 'handle': 0.34; 'list': 0.34; 'skip:> 10': 0.35; 'comment': 0.35; 'too': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'test': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'your': 0.60; 'share': 0.61; 'here': 0.66; 'note:': 0.66; '>def': 0.84; 'dennis': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-79-218-140.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100386 On Sun, 13 Dec 2015 22:56:31 +0530, Ganesh Pal 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/