News for hackers. Stuff that matters.
Re:Unpythonic Python by icambron on Thursday April 10, 2014 @01:26AM (#7564341)
I was curious about that. Is multiplying a string by a boolean idiomatic Python? I don't write nearly enough Python to know, but it strikes me that this might be more like writing French using lots of obscure words.
Re:Unpythonic Python by softbuilder on Thursday April 10, 2014 @05:10AM (#7564944)
This starts to get into "what is idiomatic python?" which changes as the language evolves. For example, before Python had an official ternary form, this was a common idiom:

    account.status = ["paid", "unpaid"][amount_due > 0]
This does the same thing as the FizzBuzz example, coercing a bool to int. Here the int is used as an index into the list of the two strings.

Personally, I found this handy and liked it a lot. Others didn't and now there is this, which isn't bad:

   account.status = "unpaid" if amount_due > 0 else "paid"

Maybe it's less like using obscure French and more like speaking in a slightly different dialect, or in a different region with different cultural references.
Re:Unpythonic Python by yen223 on Thursday April 10, 2014 @06:19AM (#7565086)
Multiplying a string by an integer is fine.

Treating a boolean as an integer is iffy

Multiplying a string by a boolean frankly should be a no-no.