python for this C: "if ((a = b(c)) != NULL)"

Steve Holden sholden at holdenweb.com
Tue May 14 10:23:48 EDT 2002


"David Carson" <davidccarson at hotmail.com> wrote in message
news:12257ec4.0205140344.2680b226 at posting.google.com...
> "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.
>
So what you really want to know is, why isn't Python more like C?

> 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.
>
I would suggest that readability is a matter of opinion. Further, the
original C consgtruct *is* a source of errors (use of "=" where "==" should
have been used).

> So, I'll ask again: How do I do the equivalent in Python so that it is
> both clear and concise?
>
You don't, because concise is less clear. See

    http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.030.htp

for a rationale behind the specific decision to exclude that particular
conciseness.

readability-counts-ly y'rs  - steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list