Re: A C-like if statement

2006-02-24 Thread Kay Schluehr
Paul Rubin wrote: > "Kay Schluehr" <[EMAIL PROTECTED]> writes: > > Hmm. A statement has side-effects but it returns no value. And yes, you > > can create a name within an expression producing a value in Python, > > using a list/generator comprehension. The solution to Bob's problem > > would look

Re: A C-like if statement

2006-02-24 Thread Paul Rubin
"Kay Schluehr" <[EMAIL PROTECTED]> writes: > Hmm. A statement has side-effects but it returns no value. And yes, you > can create a name within an expression producing a value in Python, > using a list/generator comprehension. The solution to Bob's problem > would look like this: > > if (I for I i

Re: A C-like if statement

2006-02-24 Thread Kay Schluehr
Roy Smith wrote: > Bob Greschke <[EMAIL PROTECTED]> wrote: > >I miss being able to do something like this in Python > > > >1f (I = a.find("3")) != -1: > >print "It's here: ", I > >else: > >print "No 3's here" > > > >where I gets assigned the index returned by find() AND the if statement ge

Re: A C-like if statement

2006-02-24 Thread Diez B. Roggisch
Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> Side-effects aren't always bad (import, for example, does all its work by >> side-effect). But they are generally frowned upon, and in functional >> languages they are verboten. > > How do you d

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 08:03:49 -0500, Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> Side-effects aren't always bad (import, for example, does all its work by >> side-effect). But they are generally frowned upon, and in functional >> languages

Re: A C-like if statement

2006-02-24 Thread Rene Pijlman
Roy Smith: >How do you do any I/O in a functional language if side effects are >verboten? The user is a function. Output is its parameter, input its return value. The user is not allowed to maintain state ;-) >For that matter, how does a functional program ever stop running? By returning to t

Re: A C-like if statement

2006-02-24 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Side-effects aren't always bad (import, for example, does all its work by > side-effect). But they are generally frowned upon, and in functional > languages they are verboten. How do you do any I/O in a functional langu

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 06:45:41 -0500, Kent Johnson wrote: > Steven D'Aprano wrote: >> Now that's a Python wart: using >>> for the prompt for interactive >> sessions. It makes it ambiguous when posting code in email or newsgroups, >> especially once the code gets quoted a few times. > > So change it

Re: A C-like if statement

2006-02-24 Thread Antoon Pardon
Op 2006-02-23, Roy Smith schreef <[EMAIL PROTECTED]>: > Bob Greschke <[EMAIL PROTECTED]> wrote: >>I miss being able to do something like this in Python >> >>1f (I = a.find("3")) != -1: >>print "It's here: ", I >>else: >>print "No 3's here" >> >>where I gets assigned the index returned by fi

Re: A C-like if statement

2006-02-24 Thread Kent Johnson
Steven D'Aprano wrote: > Now that's a Python wart: using >>> for the prompt for interactive > sessions. It makes it ambiguous when posting code in email or newsgroups, > especially once the code gets quoted a few times. So change it. My pythonstartup.py contains: import sys sys.ps1 = ' >>> ' sys.

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 02:02:02 -0800, bonono wrote: >> "test".index("a") >> > Traceback (most recent call last): >> > File "", line 1, in -toplevel- >> > "test".index("a") >> > ValueError: substring not found >> "test".find("a") >> > -1 >> >> >> Did you have a point? >> > It was abou

Re: A C-like if statement

2006-02-24 Thread bonono
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

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
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.

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 20:41:52 -0600, Terry Hancock wrote: > On Fri, 24 Feb 2006 09:14:53 +1100 > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: >> There are *reasons* why Python discourages functions with >> side-effects. Side-effects make your code hard to test and >> harder to debug. > > You of co

Re: A C-like if statement

2006-02-23 Thread Terry Hancock
On Fri, 24 Feb 2006 09:14:53 +1100 "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > There are *reasons* why Python discourages functions with > side-effects. Side-effects make your code hard to test and > harder to debug. You of course meant "expressions with side-effects". Python is pretty good at

Re: A C-like if statement

2006-02-23 Thread Paul Rubin
"Bob Greschke" <[EMAIL PROTECTED]> writes: > I miss being able to do something like this in Python > > 1f (I = a.find("3")) != -1: > print "It's here: ", I > else: > print "No 3's here" > > where I gets assigned the index returned by find() AND the if statement gets > to do its job in th

Re: A C-like if statement

2006-02-23 Thread bonono
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

Re: A C-like if statement

2006-02-23 Thread Steven D'Aprano
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 pronoun

Re: A C-like if statement

2006-02-23 Thread Dave Hansen
On Thu, 23 Feb 2006 12:04:38 -0700 in comp.lang.python, "Bob Greschke" <[EMAIL PROTECTED]> wrote: > >"Roy Smith" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] [...] >> try: >>i = a.find("3") >>print "It's here: ", i >> except NotFound: >>print "No 3's here" > >Nuts. I

Re: A C-like if statement

2006-02-23 Thread Giles Brown
But maybe we're talking about string methods so to get an exception we'd want to use "index" instead of "find". Giles -- http://mail.python.org/mailman/listinfo/python-list

Re: A C-like if statement

2006-02-23 Thread Bob Greschke
"Roy Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Bob Greschke <[EMAIL PROTECTED]> wrote: >>I miss being able to do something like this in Python >> >>1f (I = a.find("3")) != -1: >>print "It's here: ", I >>else: >>print "No 3's here" >> >>where I gets assigned the

Re: A C-like if statement

2006-02-23 Thread Roy Smith
Bob Greschke <[EMAIL PROTECTED]> wrote: >I miss being able to do something like this in Python > >1f (I = a.find("3")) != -1: >print "It's here: ", I >else: >print "No 3's here" > >where I gets assigned the index returned by find() AND the if statement gets >to do its job in the same line.