Search Results

Search found 1 results on 1 pages for 'artdanil'.

Page 1/1 | 1 

  • Using try vs if in python

    - by artdanil
    Is there a rationale to decide which one of try or if constructs to use, when testing variable to have a value? For example, there is a function that returns either a list or doesn't return a value. I want to check result before processing it. Which of the following would be more preferable and why? result = function(); if (result): for r in result: #process items or result = function(); try: for r in result: #process items except TypeError: pass; Related discussion: Checking for member existence in Python

    Read the article

1