Re: Is there a more elegant way to handle determing fail status?

Discussion in 'Python' started by Ian Kelly, Jan 16, 2013.

  1. Ian Kelly

    Ian Kelly Guest

    On Tue, Jan 15, 2013 at 4:24 PM, J <> wrote:
    > The exit code determination above works, but it just feels inelegant.
    > It feels like there's a better way of implementing that, but I can't
    > come up with one that still honors the fail level properly (e.g. other
    > solutions will fail on medium, but won't fail properly on medium OR
    > higher).


    First, instead of having separate variables 'critical_fails',
    'high_fails', etc., put them in a collections.Counter 'fails' keyed by
    fail level.
    Second, make sure those fail level keys are orderable by severity.

    Then your check is just:

    if fail_priority <= max(fails):
    return 1
    return 0
    Ian Kelly, Jan 16, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kamilche
    Replies:
    7
    Views:
    280
    Peter Hansen
    Jun 29, 2004
  2. Lilith
    Replies:
    8
    Views:
    343
    Dave Rahardja
    Sep 2, 2005
  3. J
    Replies:
    3
    Views:
    149
    Steven D'Aprano
    Jan 16, 2013
  4. Oscar Benjamin
    Replies:
    0
    Views:
    126
    Oscar Benjamin
    Jan 15, 2013
  5. Dr.Ruud
    Replies:
    1
    Views:
    158
    Ted Zlatanov
    Feb 21, 2013
Loading...

Share This Page