On 2009-04-24, Steven D'Aprano <st...@remove-this-cybersource.com.au> wrote:
> On Fri, 24 Apr 2009 03:00:26 -0700, GC-Martijn wrote:
>
>> Hello,
>> 
>> I'm trying to do a if statement with a function inside it. I want to use
>> that variable inside that if loop , without defining it.
>> 
>> def Test():
>>     return 'Vla'
>> 
>> I searching something like this:
>> 
>> if (t = Test()) == 'Vla':
>>     print t # Vla
>> 
>> or
>> 
>> if (t = Test()):
>>     print t # Vla
>
> Fortunately, there is no way of doing that with Python. This is one 
> source of hard-to-debug bugs that Python doesn't have.

I think this is an unfortunate consequence of choosing '=' for the
assignment. They could have chosen an other token to indicate an
assignment one that would have made the difference between an
assignment and a comparison more visually different and thus
bugs by using one while needing the other less hard to track
down.

So when a certain kind of bug is hard to track down because of
the similarity of the tokens and not because of the specific
functionality I find it unfortunate they dropped the functionality
instead of making the tokens less similar.

-- 
Antoon Pardon
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to