Re: While loop help

2013-04-09 Thread Chris Angelico
On Wed, Apr 10, 2013 at 3:18 AM, wrote: > sorry i just started using google groups, not really all that sure how to use > it properly. The best way to use Google Groups is to not use it, frankly. Just subscribe to the mailing list in gmail; it has its own issues (eg it encourages top-posting by

Re: While loop help

2013-04-09 Thread thomasancilleri
sorry i just started using google groups, not really all that sure how to use it properly. -- http://mail.python.org/mailman/listinfo/python-list

Re: While loop help

2013-04-09 Thread Dave Angel
loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program. Also suddenly I'm getting an invalid syntax error next to my elif statements when I wasn't a minute ago. What is wrong

Re: While loop help

2013-04-09 Thread Chris Angelico
On Wed, Apr 10, 2013 at 2:57 AM, wrote: > I responded before I saw this message, this was very helpful so I appreciate > your quick and helpful responses. So do you think prompting for a string and > then checking if the string is true is a good practice for something like > this? When would c

Re: While loop help

2013-04-09 Thread thomasancilleri
I responded before I saw this message, this was very helpful so I appreciate your quick and helpful responses. So do you think prompting for a string and then checking if the string is true is a good practice for something like this? When would checking for true/false be necessary? -- http://ma

Re: While loop help

2013-04-09 Thread thomasancilleri
So what would be the proper way to perform a loop of this program. I still can't quite figure out the best way to do it. -- http://mail.python.org/mailman/listinfo/python-list

Re: While loop help

2013-04-09 Thread Chris Angelico
;, but that's optional. > Also what confuses me is that python doesn't use brackets. How do I contain > all of my if/else statements into one while loop? Do I have to indent each > line of code and extra indentation? I'm used to highschool doing c++ and java > when I woul

Re: While loop help

2013-04-09 Thread Joel Goldstick
;true" then the loop would continue but i > imagine there is a better way then matching strings and integers like i > have been. > > Also what confuses me is that python doesn't use brackets. How do I > contain all of my if/else statements into one while loop? Do I have to >

Re: While loop help

2013-04-09 Thread thomasancilleri
ke i have been. Also what confuses me is that python doesn't use brackets. How do I contain all of my if/else statements into one while loop? Do I have to indent each line of code and extra indentation? I'm used to highschool doing c++ and java when I would just say: whi

Re: While loop help

2013-04-09 Thread Chris Angelico
On Wed, Apr 10, 2013 at 1:47 AM, wrote: > ... I'm not sure what version I'm using ... Try putting these lines into a Python script: import sys print(sys.version) That, on any version of Python (back a fairly long way, Steven D'Aprano can probably say how far), will give you a line or so of out

Re: While loop help

2013-04-09 Thread Joel Goldstick
On Tue, Apr 9, 2013 at 11:47 AM, wrote: > Sorry I'm just starting to learn python and I'm not sure what version I'm > using to be quite honest. I just started typing it up in Komodo edit (Which > I'm not personally a fan in particular) I fixed the missing parenthesis > which fixed the invalid syn

Re: While loop help

2013-04-09 Thread thomasancilleri
Sorry I'm just starting to learn python and I'm not sure what version I'm using to be quite honest. I just started typing it up in Komodo edit (Which I'm not personally a fan in particular) I fixed the missing parenthesis which fixed the invalid syntax problem. Also, I apologize for submitting c

Re: While loop help

2013-04-09 Thread Chris Angelico
On Tue, Apr 9, 2013 at 11:58 PM, wrote: > Also I'm getting a invalid syntax next to my elif statements that i wasnt > getting before. why is this happening now? Ah! That's relating to the close parenthesis problem I mentioned. That's the exact issue I saw. When you get told about a problem, so

Re: While loop help

2013-04-09 Thread Chris Angelico
On Tue, Apr 9, 2013 at 11:32 PM, wrote: > I'm new to learning python and creating a basic program to convert units of > measurement which I will eventually expand upon but im trying to figure out > how to loop the entire program. When I insert a while loop it only loops the &

Re: While loop help

2013-04-09 Thread thomasancilleri
Also I'm getting a invalid syntax next to my elif statements that i wasnt getting before. why is this happening now? -- http://mail.python.org/mailman/listinfo/python-list

Re: While loop help

2013-04-09 Thread thomasancilleri
On Tuesday, April 9, 2013 9:32:18 AM UTC-4, thomasa...@gmail.com wrote: > I'm new to learning python and creating a basic program to convert units of > measurement which I will eventually expand upon but im trying to figure out > how to loop the entire program. When I insert a whil

While loop help

2013-04-09 Thread thomasancilleri
I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner fri

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-04 Thread Ulrich Eckhardt
Am 01.03.2013 17:28, schrieb Isaac Won: What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question. You are not helping yourself... In any

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
Thank you Ulich for reply, What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question. Thank you, Isaac On Friday, March 1, 2013 6:00:42 AM UTC

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip().split() for raw in f ): > > > while d <335: > > > > Note your indentation levels: the code does not agree

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
Thank you, Chris. I just want to acculate value from y repeatedly. If y = 1,2,3...10, just have a [1,2,3...10] at onece. On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Chris Angelico
On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > while c <24: > for columns in ( raw.strip().split() for raw in f ): > while d <335: Note your indentation levels: the code does not agree with your subject line. The third loop is not actually inside your second. Should it be? Ch

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Joel Goldstick
On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt < ulrich.eckha...@dominolaser.com> wrote: > Am 01.03.2013 09:59, schrieb Isaac Won: > > try to make my triple nested loop working. My code would be: >> c = 4 >> > [...] > > while c <24: >> c = c + 1 >> > > This is bad style and you shouldn

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Ulrich Eckhardt
Am 01.03.2013 09:59, schrieb Isaac Won: try to make my triple nested loop working. My code would be: c = 4 [...] while c <24: c = c + 1 This is bad style and you shouldn't do that in python. The question that comes up for me is whether something else is modifying "c" in that loop,

Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
1 = m1 + [m] print m1 My purpose is make a list of [mean(fpsd[0]), mean(fpsd[1]), mean(fpsd[2]).. mean(fpsd[335])]. Each y1 would be the list of fpsd[d]. I check it is working pretty well before second while loop and I can get indi

Re: Run once while loop

2012-04-04 Thread Benjamin Kaplan
hd for Mac OS X, and Cron for other *nixes). > On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan > wrote: >> >> On Tue, 3 Apr 2012 23:00:22 +0200 >> Anatoli Hristov wrote: >> >> > On 03 Apr 2012, at 22:45, Ian Kelly wrote: >> > >> > > O

Re: Run once while loop

2012-04-04 Thread Anatoli Hristov
; On Tue, 3 Apr 2012 23:00:22 +0200 > Anatoli Hristov wrote: > > > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > > > > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov > wrote: > > >> Hi, > > >> > > >> I'm trying to do a while

Re: Run once while loop

2012-04-04 Thread John O'Hagan
On Tue, 3 Apr 2012 23:00:22 +0200 Anatoli Hristov wrote: > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: > >> Hi, > >> > >> I'm trying to do a while loop with condition of time if time i

Re: Run once while loop

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 3:00 PM, Anatoli Hristov wrote: > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > >> On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >>> Hi, >>> >>> I'm trying to do a while loop with condition of time if time is >>

Re: Run once while loop

2012-04-03 Thread Anatoli Hristov
On 03 Apr 2012, at 22:45, Ian Kelly wrote: > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >> Hi, >> >> I'm trying to do a while loop with condition of time if time is >> 12:00:00 print text, but for this one second the text is printed at >> lea

Re: Run once while loop

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: > Hi, > > I'm trying to do a while loop with condition of time if time is > 12:00:00 print text, but for this one second the text is printed at > least 50 times, how can I print only once? Set a flag when you print the t

Run once while loop

2012-04-03 Thread Anatoli Hristov
Hi, I'm trying to do a while loop with condition of time if time is 12:00:00 print text, but for this one second the text is printed at least 50 times, how can I print only once? Thank Anatoli -- http://mail.python.org/mailman/listinfo/python-list

Re: NEED HELP- read file contents, while loop to accept user

2011-05-24 Thread Cathy James
elopment? > (Octavian Rasnita) > 3. Re: Why did Quora choose Python for its development? > (Chris Angelico) > 4. NEED HELP- read file contents, while loop to accept user > input, andenter to exit (Cathy James) > 5. Re: NEED HELP- read file contents, whil

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Jean-Michel Pichavant
Cathy James wrote: f = open ('c:/testing.txt'', 'r') replace the double quote by a single quote. JM -- http://mail.python.org/mailman/listinfo/python-list

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Chris Rebert
27;', 'r') > f.readlines() > #2)  and 3) use while loop  to write user input to file, save to file, close > when press enter: > while True: >     s = input ('enter name: ').strip() >     f = open ('c:/testing.txt', 'a') >     if f.w

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Chris Angelico
On Tue, May 24, 2011 at 6:31 PM, Cathy James wrote: >     s = input ('enter name: ').strip() Are you using Python 2 or Python 3? If it's Python 2, this should be raw_input(). >     f = open ('c:/testing.txt', 'a') > ... >     f = open ('c:/testing.txt', 'r') You may be having trouble here a

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Tim Golden
On 24/05/2011 09:31, Cathy James wrote: dear mentor, I need help with my code: 1) my program won't display file contents upon opening #1) open file and display current file contents: f = open ('c:/testing.txt'', 'r') f.readlines() If you're running this in an interactive interpreter, I would

NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Cathy James
dear mentor, I need help with my code: 1) my program won't display file contents upon opening 2) my program is not writing to file 3) my program is not closing when user presses enter- gow do I do this with a while loop? please see my attempt below and help: #1) open file and display cu

Re: socket.rcv timeout while-loop

2011-02-07 Thread Dwayne Blind
Dear Stephen, Thanks for telling me this all looked very peculiar. As you said, it did not really need solving. Cheers, Dwayne 2011/2/4 Stephen Hansen > On 2/4/11 9:16 AM, Dwayne Blind wrote: > > @ Stephen Hansen > > Now I am pretty much worried. :'( > > Why? This is all sounding like a probl

Re: socket.rcv timeout while-loop

2011-02-04 Thread Stephen Hansen
On 2/4/11 9:16 AM, Dwayne Blind wrote: > @ Stephen Hansen > Now I am pretty much worried. :'( Why? This is all sounding like a problem that isn't actually a problem. I think you may have over-analyzed yourself into a corner and think you have something to solve which doesn't really need solving.

Re: socket.rcv timeout while-loop

2011-02-04 Thread Dwayne Blind
e requested number of bytes but > the network layer has every possibility of just giving you partial > responses. > > So the network layer should just gather up the data as it arrives, > buffer it -- and pass it off to the game logic layer as each line is > complete (i.e., as \r\n

Re: socket.rcv timeout while-loop

2011-02-04 Thread Stephen Hansen
as every possibility of just giving you partial responses. So the network layer should just gather up the data as it arrives, buffer it -- and pass it off to the game logic layer as each line is complete (i.e., as \r\n or \n's are received). But there's no reason at all to do a while lo

Re: socket.rcv timeout while-loop

2011-02-04 Thread Jean-Michel Pichavant
Dwayne Blind wrote: Thanks to all of you. @ Jean-Michel Pichavant I am writing a small multiplayer game. Several clients are connected to the server. Games last, say, 20 seconds. You can think of the game as a small chat lasting 20 seconds. All the data received by the server is sent back to

Re: socket.rcv timeout while-loop

2011-02-04 Thread Dwayne Blind
AM, Dwayne Blind wrote: >> >> >>> However I would like to set timeout on the socket rcv method, so that >>> the while loop stops exactly after 3 seconds. Is this possible ? >>> >>> >> >> I rarely do low-level socket stuff -- [snip] >&g

Re: socket.rcv timeout while-loop

2011-02-04 Thread Jean-Michel Pichavant
Stephen Hansen wrote: On 2/3/11 9:56 AM, Dwayne Blind wrote: However I would like to set timeout on the socket rcv method, so that the while loop stops exactly after 3 seconds. Is this possible ? I rarely do low-level socket stuff -- [snip] Good point. Python has a module for

Re: socket.rcv timeout while-loop

2011-02-03 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Dwayne Blind wrote: or rather timeout = s.gettimeout() b=time.clock() while time.clock()-b<3 : s.settimeout(3-time.clock()+b) try : data=s.recv(1024) except : break s.settimeout(t

Re: socket.rcv timeout while-loop

2011-02-03 Thread Stephen Hansen
meout ? > s.settimeout(3) # I guess this is a 3 second timeout > s.recv(1024) > s.settimeout(timeout) # You change it back ? Yes. > So with a while loop, it should be : I don't understand why you're doing this while loop business. Your original question is ask

Re: socket.rcv timeout while-loop

2011-02-03 Thread Dwayne Blind
ments : >> >> timeout = s.gettimeout()# Is that the default timeout ? >> s.settimeout(3) # I guess this is a 3 second timeout >> s.recv(1024) >> s.settimeout(timeout) # You change it back ? >> >> So with a while loop, it should b

Re: socket.rcv timeout while-loop

2011-02-03 Thread Dwayne Blind
is a 3 second timeout > s.recv(1024) > s.settimeout(timeout) # You change it back ? > > So with a while loop, it should be : > > > timeout = s.gettimeout() > s.settimeout(3) > b=time.clock() > while time.clock()-b<3 : > >

Re: socket.rcv timeout while-loop

2011-02-03 Thread Dwayne Blind
(1024) s.settimeout(timeout) # You change it back ? So with a while loop, it should be : timeout = s.gettimeout() s.settimeout(3) b=time.clock() while time.clock()-b<3 : data=s.recv(1024) s.settimeout(timeout) Am I right ? Thanks again, Dwayne 2011/2/3

Re: socket.rcv timeout while-loop

2011-02-03 Thread Stephen Hansen
On 2/3/11 10:13 AM, Dwayne Blind wrote: > Thanks for your answer. I don't want to reset my socket. I want to apply > the timeout to the rcv method only. Setting the timeout does not "reset [your] socket", I don't think. And I get that you want to only timeout recv... that's why I pointed out its a

Re: socket.rcv timeout while-loop

2011-02-03 Thread Dwayne Blind
ne Blind wrote: > > However I would like to set timeout on the socket rcv method, so that > > the while loop stops exactly after 3 seconds. Is this possible ? > > I rarely do low-level socket stuff -- but I think s.settimeout() is what > you're looking for. It applies to

Re: socket.rcv timeout while-loop

2011-02-03 Thread Stephen Hansen
On 2/3/11 9:56 AM, Dwayne Blind wrote: > However I would like to set timeout on the socket rcv method, so that > the while loop stops exactly after 3 seconds. Is this possible ? I rarely do low-level socket stuff -- but I think s.settimeout() is what you're looking for. It applies t

socket.rcv timeout while-loop

2011-02-03 Thread Dwayne Blind
Hi everybody, I am using Python 3.0. I have such a code : b=time.clock() while time.clock()-b<3 : data=s.recv(1024) However I would like to set timeout on the socket rcv method, so that the while loop stops exactly after 3 seconds. Is this possible ? Thanks a lot, Dwayne -- h

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-13 Thread Arnaud Delobelle
Nobody writes: > On Mon, 11 Oct 2010 05:42:39 -0700, Ethan Furman wrote: > If I'm catching exceptions in order to perform clean-up, I'll use a bare except and re-raise the exception afterwards. In that situation, a bare except is usually the right thing to do. >>> >>> Wrong way to do

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Nobody
On Mon, 11 Oct 2010 05:42:39 -0700, Ethan Furman wrote: >>>If I'm catching exceptions in order to perform clean-up, I'll use a bare >>>except and re-raise the exception afterwards. In that situation, a bare >>>except is usually the right thing to do. >> >> Wrong way to do it. > > What, then, is

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Ethan Furman
Lawrence D'Oliveiro wrote: In message , Nobody wrote: If I'm catching exceptions in order to perform clean-up, I'll use a bare except and re-raise the exception afterwards. In that situation, a bare except is usually the right thing to do. Wrong way to do it. What, then, is the right way to

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > >> chad writes: >> >>> while 1: >> >> A minor point: this is more explanatory and less misleading if you write >> it as ‘while True’. > > Why is it misleading? Is there some circumstance in Python where the > lit

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-11 Thread Lawrence D'Oliveiro
In message , Nobody wrote: > If I'm catching exceptions in order to perform clean-up, I'll use a bare > except and re-raise the exception afterwards. In that situation, a bare > except is usually the right thing to do. Wrong way to do it. -- http://mail.python.org/mailman/listinfo/python-list

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Nobody
On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > Here's your problem. Don't ever use a bare ‘except’ unless you know > exactly why you're doing so. Rather, figure out what exception types you > want to catch, and catch *only* those types. If I use a bare except, I usually have a good reaso

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Steven D'Aprano
On Tue, 05 Oct 2010 11:13:53 +0800, Von wrote: > Try to use sys.exit(0) > Maybe you should print out the error in your except block. Not exiting with a status-code of 0 is no more helpful than not exiting with a status-code of 1. It's actually *less* helpful, if the intention is actually to exi

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-05 Thread Lawrence D'Oliveiro
In message , Seebs wrote: > On 2010-10-05, Lawrence D'Oliveiro > wrote: > >> In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: >> >>> Don't ever use a bare ‘except’ unless you know exactly why you're doing >>> so. >> >> In other news, don’t ever put a loaded gun in your mouth and pul

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Seebs
On 2010-10-05, Lawrence D'Oliveiro wrote: > In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: >> Don't ever use a bare ???except??? unless you know exactly why you're doing >> so. > In other news, don???t ever put a loaded gun in your mouth and pull the > trigger unless you know exa

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Lawrence D'Oliveiro
In message <87iq1hz6rc@benfinney.id.au>, Ben Finney wrote: > Don't ever use a bare ‘except’ unless you know exactly why you're doing > so. In other news, don’t ever put a loaded gun in your mouth and pull the trigger unless you know exactly why you’re doing so. Some people have a problem. T

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Ben Finney
Steven D'Aprano writes: > Why is it misleading? Is there some circumstance in Python where the > literal 1 could have a false value? It's misleading as to the intent. > "while 1" was the accepted idiom for infinite loops in Python for many > years, before the introduction of bools in (I think

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Steven D'Aprano
On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote: > chad writes: > >> while 1: > > A minor point: this is more explanatory and less misleading if you write > it as ‘while True’. Why is it misleading? Is there some circumstance in Python where the literal 1 could have a false value? "whil

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Von
ttp://www.google.com";) > data = con.read() > print "connected" > #The loop doesn't exit if I use sys.exit(1) > break > except: > time.sleep(2) > > > If I would replace 'break' with 'sys.exit(1)'

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Terry Reedy
On 10/4/2010 10:38 PM, chad wrote: Given the following.. #!/usr/bin/python import urllib2 import sys import time while 1: try: con = urllib2.urlopen("http://www.google.com";) data = con.read() print "connected" #The loop doesn't exit if I use sys.exit(1

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Ben Finney
ime.sleep(2) > > If I would replace 'break' with 'sys.exit(1)', the while loop will > keep printing connected every 2 seconds? Why I this?> I thought exit > meant exit. Have a read of the documentation for ‘sys.exit’ to see how it exits; you'll then see h

Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread Justin Ezequiel
your bare except is catching the SystemExit raised by sys.exit(1) -- http://mail.python.org/mailman/listinfo/python-list

I don't get why sys.exit(1) doesn't exit the while loop in the follow case

2010-10-04 Thread chad
break except: time.sleep(2) If I would replace 'break' with 'sys.exit(1)', the while loop will keep printing connected every 2 seconds? Why I this? I thought exit meant exit. -- http://mail.python.org/mailman/listinfo/python-list

Re: while loop with the condition used in the body

2010-02-24 Thread Gregory Ewing
Ulrich Eckhardt wrote: so why not: while as : ... and also: if as : ... This sort of thing has been suggested repeatedly in the past, and it's always been rejected. That's not likely to change. Look up the past threads for the reasons why. -- Greg -- http://mail.python.or

Re: while loop with the condition used in the body

2010-02-24 Thread Ulrich Eckhardt
Peter Otten wrote: > Duncan Booth wrote: >> for rq in incoming_requests(...): >>handle_request(rq) > > ...and a likely implementation would be > > def incoming_requests(...): > while True: > rq = ... # inlined version of get_request() > if not rq: > break >

Re: while loop with the condition used in the body

2010-02-24 Thread Peter Otten
Duncan Booth wrote: > Peter Otten <__pete...@web.de> wrote: > >> Ulrich Eckhardt wrote: >> >>> I'm looking for a way to write code similar to this C code: >>> >>> while(rq = get_request(..)) { >>> handle_request(rq); >>> } >>> >> Assuming get_request(...) is called with the same argum

Re: while loop with the condition used in the body

2010-02-24 Thread Duncan Booth
Peter Otten <__pete...@web.de> wrote: > Ulrich Eckhardt wrote: > >> I'm looking for a way to write code similar to this C code: >> >> while(rq = get_request(..)) { >> handle_request(rq); >> } >> > Assuming get_request(...) is called with the same arguments on each > iteration and uses

Re: while loop with the condition used in the body

2010-02-24 Thread Peter Otten
Ulrich Eckhardt wrote: > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq) > >

Re: while loop with the condition used in the body

2010-02-24 Thread Arnaud Delobelle
Ulrich Eckhardt wrote: > Hi! > > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq)

while loop with the condition used in the body

2010-02-24 Thread Ulrich Eckhardt
Hi! I'm looking for a way to write code similar to this C code: while(rq = get_request(..)) { handle_request(rq); } Currently I'm doing while True: rq = get_request(...) if not rq: break handle_request(rq) in Python 2.6. Any suggestions how to rewrite tha

Re: enumerated while loop

2010-01-23 Thread Terry Reedy
On 1/23/2010 9:44 AM, Roald de Vries wrote: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:58 PM, Mark Dickinson wrote: On Jan 23, 2:44 pm, Roald de Vries wrote: I assume a function like 'naturals' already exists, or a similar construction for the same purpose. But what is it called? itertools.count() On Jan 23, 2010, at 4:04 PM, Jan Kaliszewski wrote:

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:49 PM, Diez B. Roggisch wrote: Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:50 PM, Grant Edwards wrote: On 2010-01-23, Roald de Vries wrote: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i

Re: enumerated while loop

2010-01-23 Thread Jan Kaliszewski
23-01-2010 o 15:49:23 Diez B. Roggisch wrote: Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function

Re: enumerated while loop

2010-01-23 Thread Mark Dickinson
On Jan 23, 2:44 pm, Roald de Vries wrote: > I assume a function like 'naturals' already exists, or a similar   > construction for the same purpose. But what is it called? itertools.count() -- Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: enumerated while loop

2010-01-23 Thread Grant Edwards
On 2010-01-23, Roald de Vries wrote: > Dear all, > > I sometimes want to use an infinite while loop with access to the loop > index, like this: > > def naturals(): > i = 0 > while True: > yield i > y += 1 > > for i in naturals(): >

Re: enumerated while loop

2010-01-23 Thread Diez B. Roggisch
Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or

enumerated while loop

2010-01-23 Thread Roald de Vries
Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or a similar construction fo

Re: why do I get this behavior from a while loop?

2009-11-28 Thread Tim Roberts
"S. Chris Colbert" wrote: > >What a newbie mistake for me to make. Don't feel too badly about it. Even very experienced programmers get bitten by this issue. Until someone points it out, it's certainly not obvious. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.p

Re: why do I get this behavior from a while loop?

2009-11-27 Thread S. Chris Colbert
What a newbie mistake for me to make. I appreciate the replies everyone! Cheers, Chris > On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > > I would think that second loop should terminate at 9.9, no? > > > > I am missing something fundamental? > > "What Every Computer Scientist Sh

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Steven D'Aprano
On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? "What Every Computer Scientist Should Know About Floating Point" http://docs.sun.com/source/806-3568/ncg_goldberg.html -- Steven

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Carsten Haese
S. Chris Colbert wrote: > In [15]: t = 0. > > In [16]: time = 10. > > In [17]: while t < time: >: print t >: t += 0.1 >: >: > 0.0 > 0.1 > 0.2 > 0.3

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Tim Wintle
On Fri, 2009-11-27 at 17:06 +0100, S. Chris Colbert wrote: > This seems strange to me, but perhaps I am just missing something: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? Floating points variables ... http://en.wikipedia.org/wiki/Floati

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Paul Rudin
"S. Chris Colbert" writes: >: print t Try replacing with: print "%0.20f" % t The thing you're missing is that floating point arithmetic isn't (in general) exact - but when it's printed it's rounded. -- http://mail.python.org/mailman/listinfo/python-list

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Diez B. Roggisch
S. Chris Colbert schrieb: This seems strange to me, but perhaps I am just missing something: In [12]: t = 0. In [13]: time = 10. In [14]: while t < time: : print t : t += 1. : : 0.0 1.0

why do I get this behavior from a while loop?

2009-11-27 Thread S. Chris Colbert
This seems strange to me, but perhaps I am just missing something: In [12]: t = 0. In [13]: time = 10. In [14]: while t < time: : print t : t += 1. : : 0.0 1.0 2.0

PEP 315: Enhanced While Loop

2009-06-04 Thread Daniel Cotton
During some random surfing I became interested in the below piece of code: > while : > > and while : > > and while : > > else: It strikes me that the 'and while' syntax has some power that you may not have considered. Consider that if an 'an

Re: While loop

2009-03-05 Thread J Kenneth King
Fab86 writes: > On Mar 5, 5:23 pm, Marco Mariani wrote: >> Fab86 wrote: >> > Is it possible to get the program to catch the exception, wait 10 >> > seconds, then carry of from where it was rather than starting again? >> >> something like this? probably works in PASCAL as well :) >> >> > i=0 >> >

Re: While loop

2009-03-05 Thread Fab86
On Mar 5, 5:49 pm, Fab86 wrote: > On Mar 5, 5:23 pm, Marco Mariani wrote: > > > > > Fab86 wrote: > > > Is it possible to get the program to catch the exception, wait 10 > > > seconds, then carry of from where it was rather than starting again? > > > something like this? probably works in PASCAL a

Re: While loop

2009-03-05 Thread Chris Rebert
t;            i = i + 1 > >    except SearchError: > > (I currently close then reopen document here then restart i to 0) > > Any ideas? You need to narrow the `try` and put it inside another while-loop: while i<200: for domain in domains: srch.qu

Re: While loop

2009-03-05 Thread Andre Engels
On Thu, Mar 5, 2009 at 6:49 PM, Fab86 wrote: > On Mar 5, 5:23 pm, Marco Mariani wrote: >> Fab86 wrote: >> > Is it possible to get the program to catch the exception, wait 10 >> > seconds, then carry of from where it was rather than starting again? >> >> something like this? probably works in PASC

<    1   2   3   4   >