Re: Loop until condition is true

2005-06-23 Thread Mike Meyer
Michael Hoffman <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: > >> Making None a constant broke existing code (and I just saw old code >> that assigned to None). Are True and False that much more common as >> variable names than None? > > Yes. In fact, I count at least 4 different modules in the

Re: Loop until condition is true

2005-06-23 Thread Roy Smith
Michael Hoffman <[EMAIL PROTECTED]> wrote: > I count at least 4 different modules in the Python 2.4 standard > library that assign to True or False, mainly as a compatibility > measure for the days before they were built-ins. Hopefully, none of them as creative as http://thedailywtf.com/forums/36

Re: Loop until condition is true

2005-06-23 Thread Michael Hoffman
Antoon Pardon wrote: > Op 2005-06-22, Michael Hoffman schreef <[EMAIL PROTECTED]>: > >>Remi Villatel wrote: >> >>>Fredrik Lundh wrote: >>> checking if a logical expression is true by comparing it to True is bad style, and comparing values using "is" is also bad style. >>> >>>I wrote it thi

Re: Loop until condition is true

2005-06-23 Thread Michael Hoffman
Mike Meyer wrote: > Making None a constant broke existing code (and I just saw old code > that assigned to None). Are True and False that much more common as > variable names than None? Yes. In fact, I count at least 4 different modules in the Python 2.4 standard library that assign to True or F

Re: Loop until condition is true

2005-06-23 Thread Benji York
Mike Meyer wrote: > Making None a constant broke existing code (and I just saw old code > that assigned to None). Are True and False that much more common as > variable names than None? I would think so. I know that my pre-booleans-in-Python code routinely did something like "from booleans impor

Re: Loop until condition is true

2005-06-23 Thread Mike Meyer
Stelios Xanthakis <[EMAIL PROTECTED]> writes: > Michael Hoffman wrote: >> Stelios Xanthakis wrote: >> >>> Magnus Lycka wrote: >> > >> Right. Silly me. Maybe in some future Python version, True and False will be constants, like None is since Python 2.4. >>> >>> >>> Actually, there is sup

Re: Loop until condition is true

2005-06-23 Thread Stelios Xanthakis
Michael Hoffman wrote: > Stelios Xanthakis wrote: > >> Magnus Lycka wrote: > > > > >>> Right. Silly me. Maybe in some future Python version, True and False >>> will be constants, like None is since Python 2.4. >> >> >> Actually, there is support in marshal to write True and False objects so >>

Re: Loop until condition is true

2005-06-23 Thread Antoon Pardon
Op 2005-06-22, Michael Hoffman schreef <[EMAIL PROTECTED]>: > Remi Villatel wrote: >> Fredrik Lundh wrote: >>> checking if a logical expression is true by comparing it to True is bad >>> style, and comparing values using "is" is also bad style. >> >> I wrote it this way because, first, it's perfec

Re: Loop until condition is true

2005-06-23 Thread Michael Hoffman
Stelios Xanthakis wrote: > Magnus Lycka wrote: > >> Right. Silly me. Maybe in some future Python version, True and False >> will be constants, like None is since Python 2.4. > > Actually, there is support in marshal to write True and False objects so > I don't understand why this isn't in 2.4 Be

Re: Loop until condition is true

2005-06-22 Thread Scott David Daniels
Magnus Lycka wrote: > In some cases, "==" and "is" happens to give the same result. > >>> a = 1 > >>> b = 1 > >>> a == b > 1 > >>> a is b > 1 > > But often not. > > >>> c = 123456789 > >>> d = 123456789 > >>> c == d > 1 > >>> c is d > 0 > ... > First of all, a lot of Python values except

Re: Loop until condition is true

2005-06-22 Thread Jeff Epler
def until(pred): yield None while True: if pred(): break yield None def example(): i = 0 for _ in until(lambda: x==0): x = 10 - i i += 1 print x, i example() pgpeP7iW6mcQm.pgp Description: PGP signature -- http://mail.python.org/mailman/l

Re: Loop until condition is true

2005-06-22 Thread Michael Hoffman
Remi Villatel wrote: > Fredrik Lundh wrote: >> checking if a logical expression is true by comparing it to True is bad >> style, and comparing values using "is" is also bad style. > > I wrote it this way because, first, it's perfectly valid Python code and, > second and most important, it's also

Re: Loop until condition is true

2005-06-22 Thread Magnus Lycka
Remi Villatel wrote: > Erm... You totally missed the point. I wrote it this way because, first, > it's perfectly valid Python code and, second and most important, it's > also a valid english sentence. Remi, I think you have failed to understand what Fredrik was telling you. I can understand that

Re: Loop until condition is true

2005-06-22 Thread Tim Williams
- Original Message - From: "Greg Lindstrom" <[EMAIL PROTECTED]> > A bit off topic, but what does the expression "Don't try to teach your > grandfather how to suck eggs." mean? I've never heard it before and am > curious to the story behind it. A relatively well know phrase, however as

Re: Loop until condition is true

2005-06-22 Thread Greg Lindstrom
A bit off topic, but what does the expression "Don't try to teach your grandfather how to suck eggs." mean? I've never heard it before and am curious to the story behind it. Thanks, --greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop until condition is true

2005-06-22 Thread Steven D'Aprano
On Wed, 22 Jun 2005 09:54:44 +0200, Fredrik Lundh wrote: >> [CENSORED] I keep for myself how stupid I found your post. > > so let's see if everyone who understands how embarrassingly stupid > your post is will keep that to themselves... Damn, did I fail some test? -- Steven. -- http://ma

Re: Loop until condition is true

2005-06-22 Thread Ville Vainio
> "Stelios" == Stelios Xanthakis <[EMAIL PROTECTED]> writes: Stelios> Anyway, if you can't wait for 2.5 either use 'while 1:', Stelios> or pyc[1] ... and I can't see why people don't want to use 'while 1:' in the first place, given that everyone can identify the idiom immediately. It'

Re: Loop until condition is true

2005-06-22 Thread Fredrik Lundh
Remi Villatel wrote: > >>while True: > >> some(code) > >> if final_condition is True: > >> break > >> # > >># > > > checking if a logical expression is true by comparing it to True is bad > > style, and comparing values using "is" is also bad style. > > Erm... You totally missed the point. I wrote

Re: Loop until condition is true

2005-06-21 Thread Shane Hathaway
Remi Villatel wrote: > Hi there, > > There is always a "nice" way to do things in Python but this time I can't > find one. > > What I'm trying to achieve is a conditionnal loop of which the condition > test would be done at the end so the loop is executed at least once. It's > some way the opp

Re: Loop until condition is true

2005-06-21 Thread Steven D'Aprano
On Wed, 22 Jun 2005 02:01:14 +0200, Remi Villatel wrote: > Fredrik Lundh wrote: > >>>while True: >>> some(code) >>> if final_condition is True: >>> break >>> # >>># > >> checking if a logical expression is true by comparing it to True is bad >> style, and comparing values

Re: Loop until condition is true

2005-06-21 Thread Remi Villatel
Fredrik Lundh wrote: >>while True: >> some(code) >> if final_condition is True: >> break >> # >># > checking if a logical expression is true by comparing it to True is bad > style, and comparing values using "is" is also bad style. Erm... You totally missed the point.

Re: Loop until condition is true

2005-06-21 Thread Stelios Xanthakis
Magnus Lycka wrote: > Konstantin Veretennicov wrote: > >> On 6/21/05, Magnus Lycka <[EMAIL PROTECTED]> wrote: >> >>> I don't know anything about the Python compiler internals, >>> but it doesn't seem very hard to identify simple literals following >>> while and if, and to skip the runtime test. (P

Re: Loop until condition is true

2005-06-21 Thread Magnus Lycka
Konstantin Veretennicov wrote: > On 6/21/05, Magnus Lycka <[EMAIL PROTECTED]> wrote: > >>I don't know anything about the Python compiler internals, >>but it doesn't seem very hard to identify simple literals following >>while and if, and to skip the runtime test. (Perhaps it's done >>already?) >

Re: Loop until condition is true

2005-06-21 Thread Konstantin Veretennicov
On 6/21/05, Magnus Lycka <[EMAIL PROTECTED]> wrote: > I don't know anything about the Python compiler internals, > but it doesn't seem very hard to identify simple literals following > while and if, and to skip the runtime test. (Perhaps it's done > already?) True doesn't seem to be a literal, it

Re: Loop until condition is true

2005-06-21 Thread Magnus Lycka
Benji York wrote: > If by "economy" you mean "optimization", then I would suggest that the > difference would be unnoticeable. If there is a measurable performance gain in skipping the runtime test in "while True", then this is a compiler issue, not a language issue. I don't know anything about t

Re: Loop until condition is true

2005-06-21 Thread Fredrik Lundh
Remi Villatel wrote: > There is always a "nice" way to do things in Python but this time I can't > find one. > > What I'm trying to achieve is a conditionnal loop of which the condition > test would be done at the end so the loop is executed at least once. It's > some way the opposite of "while".

Re: Loop until condition is true

2005-06-21 Thread Charles Krug
On Tue, 21 Jun 2005 12:05:25 +0200, Magnus Lycka <[EMAIL PROTECTED]> wrote: > Remi Villatel wrote: >> while True: >> some(code) >> if final_condition is True: >> break >> # >> # >> >> What I don't find so "nice" is to have to build an infinite loop only to >> break it. > > Th

Re: Loop until condition is true

2005-06-21 Thread Benji York
Cyril BAZIN wrote: > Another question could be: why is there not a statement "whileTrue" or > "loop"? I don't think the saving of a single space to transform "while True:" into "WhileTrue:" is really worth it. The same goes for "loop", the added complexity to the language (as little as it is)

Re: Loop until condition is true

2005-06-21 Thread Cyril BAZIN
Another question could be: why is there not a statement "whileTrue" or "loop"? For exemple: whileTrue:     statement 1     if condition:     break     statement 2 It could be an economy of one unuseful test by loop.On 6/21/05, Magnus Lycka <[EMAIL PROTECTED]> wrote: Remi Villate

Re: Loop until condition is true

2005-06-21 Thread Magnus Lycka
Remi Villatel wrote: > while True: > some(code) > if final_condition is True: > break > # > # > > What I don't find so "nice" is to have to build an infinite loop only to > break it. This is a common Python idiom. I think you will get used to it. > Is there a better recipe?

Re: Loop until condition is true

2005-06-19 Thread D H
Joseph Garvin wrote: > Peter Otten wrote: > >> I found 136 occurrences of "do {" versus 754 of "while (" and 1224 of >> "for >> (" in the Python 2.4 source, so using these rough estimates do-while >> still >> qualifies as "rarely used". >> >> Peter >> >> >> > That's 136 times you'd have to use

See Pep 315. was: Re: Loop until condition is true

2005-06-19 Thread John Roth
See Pep 315, which is still open, and targeted at 2.5. It survived the recent spate of PEP closings and rejections. http://www.python.org/peps/pep-0315.html John Roth "Remi Villatel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi there, > > There is always a "nice" way to do t

Re: Loop until condition is true

2005-06-18 Thread Ron Adam
Joseph Garvin wrote: > Peter Otten wrote: > >> I found 136 occurrences of "do {" versus 754 of "while (" and 1224 of >> "for >> (" in the Python 2.4 source, so using these rough estimates do-while >> still >> qualifies as "rarely used". >> >> Peter >> >> >> > That's 136 times you'd have to use

Re: Loop until condition is true

2005-06-18 Thread Joseph Garvin
Peter Otten wrote: >I found 136 occurrences of "do {" versus 754 of "while (" and 1224 of "for >(" in the Python 2.4 source, so using these rough estimates do-while still >qualifies as "rarely used". > >Peter > > > That's 136 times you'd have to use an ugly hack instead. I definitely wouldn't m

Re: Loop until condition is true

2005-06-18 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, Andrea Griffini <[EMAIL PROTECTED]> wrote: > On Sat, 18 Jun 2005 13:35:16 -, Grant Edwards <[EMAIL PROTECTED]> > wrote: > > >AFAICT, the main use for do/while in C is when you want to > >define a block of code with local variables as a macro: > > When my job

Re: Loop until condition is true

2005-06-18 Thread Andrea Griffini
On Sat, 18 Jun 2005 13:35:16 -, Grant Edwards <[EMAIL PROTECTED]> wrote: >AFAICT, the main use for do/while in C is when you want to >define a block of code with local variables as a macro: When my job was squeezing most out of the CPU (videogame industry) I remember that the asm code generat

Re: Loop until condition is true

2005-06-18 Thread Donn Cave
Quoth Peter Otten <[EMAIL PROTECTED]>: ... | 'until' in C is actually | | do | statement | while (expression); Oops. Well, QED - I sure don't need it often. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop until condition is true

2005-06-18 Thread Tim Williams
- Original Message - From: "Remi Villatel" <[EMAIL PROTECTED]> > There is always a "nice" way to do things in Python but this time I can't > find one. > So far, all I got is: > > while True: > some(code) > if final_condition is True: > break > # > # > > What I don't find so "nice" is t

Re: Loop until condition is true

2005-06-18 Thread Grant Edwards
On 2005-06-18, Peter Otten <[EMAIL PROTECTED]> wrote: >> If you look at C code, at least in my experience the >> "until" loop is quite rarely used.  (I don't see it once in the source >> to Python 2.4, for example.) > > Long time no C? > > 'until' in C is actually > > do > statement > while

Re: Loop until condition is true

2005-06-18 Thread Peter Otten
Donn Cave wrote: > If you look at C code, at least in my experience the > "until" loop is quite rarely used.  (I don't see it once in the source > to Python 2.4, for example.) Long time no C? 'until' in C is actually do statement while (expression); I found 136 occurrences of "do {" ver

Re: Loop until condition is true

2005-06-17 Thread Donn Cave
Quoth Remi Villatel <[EMAIL PROTECTED]>: | What I'm trying to achieve is a conditionnal loop of which the condition | test would be done at the end so the loop is executed at least once. It's | some way the opposite of "while". | | So far, all I got is: | | while True: | some(code) |

Loop until condition is true

2005-06-17 Thread Remi Villatel
Hi there, There is always a "nice" way to do things in Python but this time I can't find one. What I'm trying to achieve is a conditionnal loop of which the condition test would be done at the end so the loop is executed at least once. It's some way the opposite of "while". So far, all I got