python for this C: "if ((a = b(c)) != NULL)"
David Carson
davidccarson at hotmail.com
Tue May 14 07:44:38 EDT 2002
"Mark McEahern" <marklists at mceahern.com> wrote in message news:<mailman.1021328064.29854.python-list at python.org>...
> [David Carson]
> > So, how do I do this in Python, since I want to avoid running method
> > b() twice in the case where I want to use 'a' later? In other words,
> > I don't want to do:
> >
> > if b(c):
> > a = b(c)
> > use a here ...
>
> a = b(c)
> if a:
> ...
>
> // m
OK, so I wasn't quite clear in my original post. I got four fine
answers like this one -- that is how I do it too.
They lack the other criterion that makes me use this style in C in the
first place -- brevity. I choose the C syntax in the header because I
can save a line _and_ it is as clear and readable as the alternative
of doing it on two lines (as all these solutions suggest). I would
not choose it if it was not readable.
So, I'll ask again: How do I do the equivalent in Python so that it is
both clear and concise?
Cheers,
David
More information about the Python-list
mailing list