Python Forum

Full Version: saving a true/false of a single value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i often have statements like:
    fail = result < 0
to save true/false from a conditional until later, when the test can't readily be done again and/or the relevant variables may ha been changed. or there may be a variety of different tests for a common end result. today i was wanting to this for the truthfulness of a variable's value instead of an expression. the code today is:
    doargs = True if ptargs else False
in the above code ptargs is initialized to be an empty list and may have arguments appended to it. but the logic that depends on doargs (to decide whether to use the arguments or read input) is in a loop where that list gets changed or cleared. making a copy of it seems wasteful (although i'm sure i have enough memory for it) and all i need is its true/false, hence the way i set doargs. is there a better/simpler way to do this? would this work?
   doargs = not not ptargs
or is what i have, now, the best way to go?
I tend to use bool(ptargs).
do you also use it around expressions that are clearly boolean?
Why would I?