C-like assignment expression?

inhahe inhahe at gmail.com
Wed May 21 10:57:32 EDT 2008


one of the few things i miss from C is being able to use assignment in 
expressions.   that's the only thing, really.
also there's no switch/case, you have to use a dictionary of functions 
instead, although i rarely need that, usually i just use elif.

<boblatest at googlemail.com> wrote in message 
news:7df99fd4-21c9-49a1-ba65-e55794fd4c12 at 26g2000hsk.googlegroups.com...
> On May 21, 1:47 pm, Hrvoje Niksic <hnik... at xemacs.org> wrote:
>
>> Although that solution is pretty, it is not the canonical solution
>> because it doesn't cover the important case of "if" bodies needing to
>> access common variables in the enclosing scope.  (This will be easier
>> in Python 3 with 'nonlocal', though.)  The snippet posted by Diez is
>> IMHO closer to a canonical solution to this FAQ.
>
> Hello everybody,
>
> thanks for the various answers. I'm actually pretty puzzled because I
> expected to see some obvious solution that I just hadn't found before.
> In general I find Python more elegant and syntactically richer than C
> (that's where I come from), so I didn't expect the solutions to be a
> lot more verbose and/or ugly (no offense) than the original idea which
> would have worked if Python's assignment statement would double as
> expression, as in C.
>
> Thanks again,
> robert
>
> PS: Since I'm testing only three REs, and I only need the match
> results from one of them, I just re-evaluate that one. 





More information about the Python-list mailing list