A C-like if statement

bonono at gmail.com bonono at gmail.com
Fri Feb 24 05:02:02 EST 2006


Steven D'Aprano wrote:
> On Thu, 23 Feb 2006 16:49:09 -0800, bonono wrote:
>
> >
> > Steven D'Aprano wrote:
> >> On Thu, 23 Feb 2006 12:04:38 -0700, Bob Greschke wrote:
> >>
> >> >> try:
> >> >>    i = a.find("3")
> >> >>    print "It's here: ", i
> >> >> except NotFound:
> >> >>    print "No 3's here"
> >> >
> >> > Nuts.  I guess you're right.  It wouldn't be proper.  Things are added or
> >> > proposed every day for Python that I can't even pronounce, but a simple 'if
> >> > (I = a.find("3")) != -1' isn't allowed.  Huh.  It might be time to go back
> >> > to BASIC. :)
> >>
> >> There are *reasons* why Python discourages functions with side-effects.
> >> Side-effects make your code hard to test and harder to debug.
> >>
> >
> >>>> "test".index("a")
> > Traceback (most recent call last):
> >   File "<pyshell#0>", line 1, in -toplevel-
> >     "test".index("a")
> > ValueError: substring not found
> >>>> "test".find("a")
> > -1
>
>
> Did you have a point?
>
It was about your side-effect talk, if you failed to see it, that is
fine.

BTW, it seems that the term side-effect of function used is a bit
different from my understanding of how it is in general used in this
field.




More information about the Python-list mailing list