Is there something similar to ?: operator (C/C++) in Python?

Peter Hansen peter at engcorp.com
Mon Jun 20 09:24:20 EDT 2005


D H wrote:
> Peter Hansen wrote:
>> Bo Peng wrote:
>>
>>> I need to pass a bunch of parameters conditionally. In C/C++, I can do
>>> func(cond1?a:b,cond2?c:d,.....)
>>>
>>> Is there an easier way to do this in Python?
>>
>> Please read the FAQ to learn the answer and much other useful ...
> 
> The answer is no.  Use if statements.

Actually that's just one possible answer.  Whether it's _the_ answer is 
obviously again a matter of opinion, and as usual we differ.

Doug, please stop making an idiot of yourself by offering simplistic 
"corrections" to every one of my posts.  I realize you don't like me, 
and that's too bad, but that isn't a good reason to be rude when I try 
to be helpful to someone or to offer my opinion on some issue.  It's 
downright immature.

A better alternative would simply be to provide your own response to the 
OP, instead of appearing to be trying to correct me, and leave it to 
others to figure out for themselves which piece of advice they prefer. 
Given that I'm hardly a troll around here, and do find ways of providing 
useful advice from time to time, I believe I deserve the courtesy of a 
bit of respect.

(I'd have emailed Doug about this many a time, but it doesn't appear he 
uses a real email address here so I'm forced to respond in a public 
forum.  Sorry for the waste of bandwidth, and regardless of the response 
I won't bring it up again.)

-Peter



More information about the Python-list mailing list