Re: Documentation, assignment in expression.

2012-03-26 Thread Tim Chase
On 03/26/12 08:59, Thomas Rachel wrote: Am 25.03.2012 15:03 schrieb Tim Chase: while True: data = conn.fetchmany() if not data: break for row in data: process(row) Or simpler for data in iter(conn.fetchmany, []): for row in data: process(row) Nice! T

Re: Documentation, assignment in expression.

2012-03-26 Thread Terry Reedy
On 3/26/2012 1:36 AM, Steven D'Aprano wrote: (I seem to recall a language that used a single = for both assignment and equality testing, guessing which one you meant from context. BASIC perhaps? Right. In some Basics, such as MS GW-Basic (I still have their book), a = b = c meant a = (b = c),

Re: Documentation, assignment in expression.

2012-03-26 Thread Thomas Rachel
Am 26.03.2012 00:59 schrieb Dennis Lee Bieber: If you use the longer form con = db.connect() cur = con.cursor() the cursor object, in all that I've worked with, does function for iteration I use this form regularly with MySQLdb and am now surprised to see that this is optional according to

Re: Documentation, assignment in expression.

2012-03-26 Thread Thomas Rachel
Am 25.03.2012 15:03 schrieb Tim Chase: Perhaps a DB example works better. With assignment allowed in an evaluation, you'd be able to write while data = conn.fetchmany(): for row in data: process(row) whereas you have to write while True: data = conn.fetchmany() if not data:

Re: Documentation, assignment in expression.

2012-03-26 Thread Kiuhnm
On 3/26/2012 13:13, Jussi Piitulainen wrote: Kiuhnm writes: On 3/26/2012 10:52, Devin Jeanpierre wrote: On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm wrote: On 3/25/2012 15:48, Tim Chase wrote: The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for ass

Re: Documentation, assignment in expression.

2012-03-26 Thread mwilson
Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 19:09:12 -0400, mwil...@the-wire.com declaimed the > following in gmane.comp.python.general: > > >> Most of my database programs wind up having the boilerplate (not tested): >> >> def rowsof (cursor): >> names = [x[0] for x in cursor.descriptio

Re: Documentation, assignment in expression.

2012-03-26 Thread Jussi Piitulainen
Kiuhnm writes: > On 3/26/2012 10:52, Devin Jeanpierre wrote: > > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > > wrote: > >> On 3/25/2012 15:48, Tim Chase wrote: > >>> > >>> The old curmudgeon in me likes the Pascal method of using "=" for > >>> equality-testing, and ":=" for assignment which feels

Re: Documentation, assignment in expression.

2012-03-26 Thread Kiuhnm
On 3/26/2012 10:52, Devin Jeanpierre wrote: On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm wrote: On 3/25/2012 15:48, Tim Chase wrote: The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for assignment which feels a little closer to mathematical use of "=".

Re: Documentation, assignment in expression.

2012-03-26 Thread Tim Chase
On 03/25/12 17:59, Dennis Lee Bieber wrote: On Sun, 25 Mar 2012 08:48:31 -0500, Tim Chase Yeah, it has the same structure internally, but I'm somewhat surprised that the DB connection object doesn't have an __iter__() that does something like this automatically under the covers. I beli

Re: Documentation, assignment in expression.

2012-03-26 Thread Devin Jeanpierre
On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer to >> mathematical use of "=". > > > Unfortunately, ":=" means "is

Re: Documentation, assignment in expression.

2012-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2012 17:16:16 +0200, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer >> to mathematical use of "=". > > Unfortunately, ":=" means "is d

Re: Documentation, assignment in expression.

2012-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2012 08:03:14 -0500, Tim Chase wrote: > I think the complaint was backed by a bad example. Perhaps a DB example > works better. With assignment allowed in an evaluation, you'd be able > to write > >while data = conn.fetchmany(): > for row in data: >process(row)

Re: Documentation, assignment in expression.

2012-03-25 Thread mwilson
Tim Chase wrote: > On 03/25/12 08:11, Chris Angelico wrote: >> On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase >> wrote: >>> Granted, this can be turned into an iterator with a yield, making the >>> issue somewhat moot: >> >> No, just moving the issue to the iterator. Your iterator has exactly >> th

Re: Documentation, assignment in expression.

2012-03-25 Thread Tim Chase
On 03/25/12 10:16, Kiuhnm wrote: On 3/25/2012 15:48, Tim Chase wrote: The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for assignment which feels a little closer to mathematical use of "=". Unfortunately, ":=" means "is defined as" in mathematics. Th

Re: Documentation, assignment in expression.

2012-03-25 Thread rusi
On Mar 25, 6:48 pm, Tim Chase wrote: > > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little > closer to mathematical use of "=". > > -tkc Carroll Morgan author of programming from specifications http://www.cs.ox.ac.uk

Re: Documentation, assignment in expression.

2012-03-25 Thread Kiuhnm
On 3/25/2012 15:48, Tim Chase wrote: The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for assignment which feels a little closer to mathematical use of "=". Unfortunately, ":=" means "is defined as" in mathematics. The "right" operator would have bee

Re: Documentation, assignment in expression.

2012-03-25 Thread Kiuhnm
On 3/25/2012 16:11, Chris Angelico wrote: On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase wrote: Yeah, it has the same structure internally, but I'm somewhat surprised that the DB connection object doesn't have an __iter__() that does something like this automatically under the covers. Sure. Tha

Re: Documentation, assignment in expression.

2012-03-25 Thread Chris Angelico
On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase wrote: > Yeah, it has the same structure internally, but I'm somewhat surprised that > the DB connection object doesn't have an __iter__() that does something like > this automatically under the covers. Sure. That's definitely the truly Pythonic techniq

Re: Documentation, assignment in expression.

2012-03-25 Thread Tim Chase
On 03/25/12 08:11, Chris Angelico wrote: On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase wrote: Granted, this can be turned into an iterator with a yield, making the issue somewhat moot: No, just moving the issue to the iterator. Your iterator has exactly the same structure in it. Yeah, it has

Re: Documentation, assignment in expression.

2012-03-25 Thread Chris Angelico
On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase wrote: > Granted, this can be turned into an iterator with a yield, making the issue > somewhat moot: No, just moving the issue to the iterator. Your iterator has exactly the same structure in it. Personally, I quite like assignment-in-conditional nota

Re: Documentation, assignment in expression.

2012-03-25 Thread Tim Chase
On 03/25/12 07:18, Alexander Blinne wrote: I am not sure I understand your argument. The doc section states that " [...] in Python you’re forced to write this: while True: line = f.readline() if not line: break ... # do something with line". That simply isn't true as on

Re: Documentation, assignment in expression.

2012-03-25 Thread Alexander Blinne
I am not sure I understand your argument. The doc section states that " [...] in Python you’re forced to write this: while True: line = f.readline() if not line: break ... # do something with line". That simply isn't true as one can simply write: for line in f: #do s

Re: Documentation, assignment in expression.

2012-03-23 Thread Roy Smith
In article <4f6d0060$0$6634$9b4e6...@newsspool2.arcor-online.net>, Alexander Blinne wrote: > The last sentence "For example, in the current version of Python file > objects support the iterator protocol, so you can now write simply > (for line in file:)" ... In general, words like "current",