if the else short form
Emile van Sebille
emile at fenx.com
Thu Sep 30 10:05:06 EDT 2010
On 9/30/2010 3:21 AM Sion Arrowsmith said...
> Andreas Waldenburger<usenot at geekmail.INVALID> wrote:
>> <http://docs.python.org/release/3.1/reference/datamodel.html#the-standard-type-hierarchy>
>> [ ... ]
>> Boolean values behave like the values 0 and 1, respectively, in
>> almost all contexts, the exception being that when converted to a
>> string, the strings "False" or "True" are returned, respectively.
>
> Hmm. So the original problem of:
>
> button = gtk.Button(("False,", "True,")[fill==True])
>
> could also rewritten as:
>
> button = gtk.Button(str(bool(fill))+",")
>
I think I'd prefer
button = gtk.Button("%s," % bool(fill))
Emile
More information about the Python-list
mailing list