[issue29173] Python 3.6 on Windows wastes a lot of CPU cycles in a while loop

2017-01-05 Thread STINNER Victor
STINNER Victor added the comment: The code doesn't seem like a bug in Python, but more a classic inefficient busy loop pattern. Your loop doesn't sleep and so eats all the CPU. I suggest to close the issue and ask Python questions on a place to ask questions, not on the Python *bug tracker*.

[issue29173] Python 3.6 on Windows wastes a lot of CPU cycles in a while loop

2017-01-05 Thread Prahlad Yeri
is the code for pomodoro.py that runs the while loop inside start_tracking() function: https://github.com/prahladyeri/PyPomodoro/blob/master/pomodoro.py def start_tracking(task): global last_beep print("Working on %s:%s (%d minutes)." % (task['category'], task['na

Re: Python while loop

2016-11-30 Thread John Gordon
In <0c642381-4dd2-48c5-bb22-b38f2d5b2...@googlegroups.com> paul.garcia2...@gmail.com writes: > Write a program which prints the sum of numbers from 1 to 101 > (1 and 101 are included) that are divisible by 5 (Use while loop) > x=0 > count=0 > while x<=100: > if x%

Re: Python while loop

2016-11-29 Thread BartC
On 29/11/2016 23:58, paul.garcia2...@gmail.com wrote: Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(co

Re: Python while loop

2016-11-29 Thread MRAB
On 2016-11-29 23:58, paul.garcia2...@gmail.com wrote: Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(co

Python while loop

2016-11-29 Thread paul . garcia2345
Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(count) Question: How does python know what count means

Re: Iteration, while loop, and for loop

2016-10-27 Thread Veek M
Elizabeth Weiss wrote: > words=["hello", "world", "spam", "eggs"] > counter=0 > max_index=len(words)-1 > > while counter<=max_index: > word=words[counter] > print(word + "!") > counter=counter + 1 while 0 < 10: get 0'th element do something with element increment 0 to 1 (repeat)

Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread BartC
f the loop body. But with 'else', if you see the message it means the while statement has been entered. Here: if cond: while n>=x: n=n-1 print "*"* n else: print ("2nd loop exit n=",n,"x=",x) Lawrence is right. The encl

Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread Peter Otten
BartC wrote: > On 12/10/2016 05:30, Lawrence D’Oliveiro wrote: >> On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote: >>> while n>=x: >>> n=n-1 >>> print "*"* n >>> else: >>> print ("2nd loop exit n=",n,"x=",x) >> >> What is the difference between that and >> >>

Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread BartC
On 12/10/2016 05:30, Lawrence D’Oliveiro wrote: On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote: while n>=x: n=n-1 print "*"* n else: print ("2nd loop exit n=",n,"x=",x) What is the difference between that and while n>=x: n=n-1 print

Re: while loop (Reposting On Python-List Prohibited)

2016-10-11 Thread BartC
On 11/10/2016 22:26, Lawrence D’Oliveiro wrote: On Wednesday, October 12, 2016 at 6:58:46 AM UTC+13, dhawan...@gmail.com wrote: Only first loop is executing not the second one? n=6 x=1 while x<=n: print("*"*x) x+=1 print('n=', n)

Re: while loop

2016-10-11 Thread Jussi Piitulainen
dhawanpawa...@gmail.com writes: > n=6 > x=1 > while x<=n: > print "*"*x > x+=1 > while n>=x: > n=n-1 > print "*"* n > > > Only first loop is executing not the second one? It's a basic fact about while loops that after the loop the condition is false. The two conditions x <= n

Re: while loop

2016-10-11 Thread Michael Torrie
On 10/11/2016 11:58 AM, dhawanpawa...@gmail.com wrote: > > n=6 > x=1 > while x<=n: > print "*"*x > x+=1 > while n>=x: > n=n-1 > print "*"* n > > > Only first loop is executing not the second one? Did you try printing out the loop variable to see what it does and what it is

Re: while loop

2016-10-11 Thread Larry Martell
On Tue, Oct 11, 2016 at 1:58 PM, wrote: > > n=6 > x=1 > while x<=n: > print "*"*x > x+=1 > while n>=x: > n=n-1 > print "*"* n > > > Only first loop is executing not the second one? Because after the first loop n < x --

while loop

2016-10-11 Thread dhawanpawan32
n=6 x=1 while x<=n: print "*"*x x+=1 while n>=x: n=n-1 print "*"* n Only first loop is executing not the second one? -- https://mail.python.org/mailman/listinfo/python-list

Re: Error in while loop code for packing items

2016-08-18 Thread MRAB
On 2016-08-18 14:10, GP wrote: On Thursday, August 18, 2016 at 5:59:43 PM UTC+5:30, Peter Otten wrote: GP wrote: [snip] However, when you really want to remove all items you instead assign a new empty list for item in items: print(item) items = [] Thanks Peter for the information.

Re: Error in while loop code for packing items

2016-08-18 Thread GP
sed), > "baz" is printed and then items.pop(1) removes "baz" and the list becomes > > items = ["bar"] > > Now k=2, so when you access items[2] from a list with only one item you get > the IndexError. To make similar code work you need a while lo

Re: Error in while loop code for packing items

2016-08-18 Thread Peter Otten
item is set to items[1], ie. "baz" ("bar" is never processed), "baz" is printed and then items.pop(1) removes "baz" and the list becomes items = ["bar"] Now k=2, so when you access items[2] from a list with only one item you get the IndexError. To

Error in while loop code for packing items

2016-08-18 Thread GP
I have a list dictionary of items: ListDictItem = [ {'Item No': 1,'Weight':610,'Quantity':2},{'Item No': 2,'Weight':610,'Quantity':2},{'Item No': 3,'Weight':500,'Quantity':2},{'Item No': 4,'Weight':484,'Quantity':2},{'Item No': 5,'Weight':470,'Quantity':2},{'Item No':

Re: Iteration, while loop, and for loop

2016-06-30 Thread jfong
Steven D'Aprano at 2016/6/30 7:59:40AM wrote: > py> mi = list('bananas') > py> for char in mi: > ... if char == 'a': > ... mi.extend(' yum') > ... print(char, end='') > ... else: # oh no, the feared for...else! > ... # needed to prevent the prompt overwriting the output >

Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote: > But there's no need to go to such effort for a mutable iterator. This is > much simpler: > > py> mi = list('bananas') > py> for char in mi: > ... if char == 'a': > ... mi.extend(' yum') > ...

Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote: > I'm curious what REPL you are using, because in the vanilla Python > interactive interpreter, the output if over-written by the prompt. That is, > what I see in Python 3.6 is: > > py> nas yum yum yumpy> > > unless I

Re: Iteration, while loop, and for loop

2016-06-30 Thread Tim Chase
On 2016-06-30 09:59, Steven D'Aprano wrote: > But there's no need to go to such effort for a mutable iterator. > This is much simpler: > > py> mi = list('bananas') > py> for char in mi: > ... if char == 'a': > ... mi.extend(' yum') > ... print(char, end='') > ... else:

Re: Iteration, while loop, and for loop

2016-06-29 Thread Steven D'Aprano
On Thu, 30 Jun 2016 01:29 am, Ian Kelly wrote: > On Tue, Jun 28, 2016 at 11:58 AM, Grant Edwards > <grant.b.edwa...@gmail.com> wrote: [...] >>> But then, if you wrap up your "while" loop as a generator that yields >>> things, you can then use i

Re: Iteration, while loop, and for loop

2016-06-29 Thread Ian Kelly
often do something similar when processing a block of data > bytes comprising a sequence of "things" of varying number of bytes. > > data = read_a_blob_of_bytes() > while data: > #figure out how long the first "thing" is > len = 'data'> >

Re: Iteration, while loop, and for loop

2016-06-29 Thread Lawrence D’Oliveiro
On Wednesday, June 29, 2016 at 1:30:04 AM UTC+12, BartC wrote: > I don't know if that helps; I've never heard of an induction variable. Perhaps it’s just a computability-theoretic way of saying “a variable whose value each time round the loop is a function of its value on the previous

Re: Iteration, while loop, and for loop

2016-06-28 Thread Grant Edwards
bytes() while data: #figure out how long the first "thing" is len = handle_thing(data[:len]) data = data[len:] > But then, if you wrap up your "while" loop as a generator that yields > things, you can then use it in a "for" loop which seems

Re: Iteration, while loop, and for loop

2016-06-28 Thread Tim Chase
you try to change the thing over which you're iterating. But then, if you wrap up your "while" loop as a generator that yields things, you can then use it in a "for" loop which seems to me like the Pythonic way to do things. :-) -tkc -- https://mail.python.org/mailman/listinfo/python-list

Re: Iteration, while loop, and for loop

2016-06-28 Thread Jussi Piitulainen
Steven D'Aprano writes: > While loops are great for loops :) Thanks, I needed the laugh. > where you don't know how many iterations there will be but you do know > that you want to keep going while some condition applies: (Just keeping a bit of context so it doesn't seem like I'm laughing at

Re: Iteration, while loop, and for loop

2016-06-28 Thread Steven D'Aprano
On Tue, 28 Jun 2016 10:36 pm, Elizabeth Weiss wrote: > Why do we use this code if we can use the simpler for loop? Nobody with any sense would use the more complex while loop when the for loop does the same thing. While loops are great for loops where you don't know how many iterati

Re: Iteration, while loop, and for loop

2016-06-28 Thread Michael Selik
able to while-loops. > > JL: For the most part, for loops are better, but there are times when > while loops are preferable such as when you don't know the size of the > input beforehand. Not knowing the number of elements is not a reason to prefer a while-loop. A for-loop handles that

Re: Iteration, while loop, and for loop

2016-06-28 Thread Michael Selik
On Tue, Jun 28, 2016 at 9:34 AM BartC wrote: > On 28/06/2016 14:15, Michael Selik wrote: > > On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss > wrote: > > > >> I do not understand the second code. What is counter? > >> > > > > It looks like someone wanted to

Re: Iteration, while loop, and for loop

2016-06-28 Thread Jussi Piitulainen
Elizabeth Weiss writes: [- -] > What I do not understand is: > > words=["hello", "world", "spam", "eggs"] > counter=0 > max_index=len(words)-1 > > while counter<=max_index: >word=words[counter] >print(word + "!") >counter=counter + 1 # make it so that counter == 0 counter=0 # make

Re: Iteration, while loop, and for loop

2016-06-28 Thread BartC
On 28/06/2016 14:15, Michael Selik wrote: On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote: I do not understand the second code. What is counter? It looks like someone wanted to make a loop induction variable. https://en.wikipedia.org/wiki/Induction_variable I

RE: Iteration, while loop, and for loop

2016-06-28 Thread Joseph Lee
Hi, Answers inline. -Original Message- From: Python-list [mailto:python-list-bounces+joseph.lee22590=gmail@python.org] On Behalf Of Michael Selik Sent: Tuesday, June 28, 2016 6:16 AM To: Elizabeth Weiss <cake...@gmail.com>; python-list@python.org Subject: Re: Iteration, whil

Re: Iteration, while loop, and for loop

2016-06-28 Thread BartC
However, because the language is zero-based, this would have been better written as: num_words = len(words) while counter < num_words: # or just while counter < len(words) That's if you had to write it as while loop. With the for=loop version, these details are taken care of behind the scenes. -- Bartc -- https://mail.python.org/mailman/listinfo/python-list

Re: Iteration, while loop, and for loop

2016-06-28 Thread Michael Selik
On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote: > I do not understand the second code. What is counter? > It looks like someone wanted to make a loop induction variable. https://en.wikipedia.org/wiki/Induction_variable > Why do we use this code if we can use the

Iteration, while loop, and for loop

2016-06-28 Thread Elizabeth Weiss
I understand this code: words=["hello", "world", "spam", "eggs"] for words in words print(word + "!") What I do not understand is: words=["hello", "world", "spam", "eggs"] counter=0 max_index=len(words)-1 while counter<=max_index: word=words[counter] print(word + "!")

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-11-10 Thread Aaron
Aaron added the comment: Python 3.3.0, Windows 7, both 64 bit. Has it been resolved with the newer version, then? On Mon, Nov 3, 2014 at 11:15 PM, Zachary Ware rep...@bugs.python.org wrote: Zachary Ware added the comment: Aaron, what version of Python are you using on what version of

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-11-10 Thread Zachary Ware
Zachary Ware added the comment: I haven't built 3.3.0 again yet to try to reproduce with it, but there have been enough bug and security fixes in the more recent 3.3 releases that I'd strongly advise updating on general principle and seeing if this issue goes away. If not to 3.4.2, at least to

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-11-10 Thread Zachary Ware
Zachary Ware added the comment: I have had a chance to build 3.3.0 and I was able to reproduce the bug with it, so it is in fact fixed in later versions. -- resolution: - out of date stage: - resolved status: open - closed ___ Python tracker

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-11-03 Thread Zachary Ware
Zachary Ware added the comment: Aaron, what version of Python are you using on what version of Windows? Also, 32 or 64 bit on both? I can't reproduce this with any Python 3.3.6 or newer on 64-bit Windows 8.1. -- ___ Python tracker

[issue22719] os.path.isfile os.path.exists but in while loop

2014-10-24 Thread Aaron
New submission from Aaron: When using os.path.isfile() and os.path.exists() in a while loop under certain conditions, os.path.isfile() returns True for paths that do not actually exist. Conditions: The folder C:\Users\EAARHOS\Desktop\Python Review exists, as do the files C:\Users\EAARHOS

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread Aaron
Changes by Aaron hosfor...@gmail.com: -- title: os.path.isfile os.path.exists but in while loop - os.path.isfile os.path.exists bug in while loop ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22719

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread R. David Murray
R. David Murray added the comment: Interesting bug. The obvious difference between the two cases is that in the += version the address of the string pointing to the filepath doesn't change, whereas when you use a temp variable it does (there's an optimization in += that reuses the same

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread Steve Dower
Steve Dower added the comment: I wonder whether the same thing occurs if you're not appending a new extension each time? There could be some optimisation (from the dark old days of 8.3 filename) that compares baseExcel and .bak separately and assumes that the name is known. Last I looked at

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Could we encode both paths to the unicode_internal encoding and check if results are equal? -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22719

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread R. David Murray
R. David Murray added the comment: Looking at the code, it looks like it calls the win32 api directly if path-wide is true, which I'm guessing is the case unless you are using bytes paths in windows? It looks like the critical call, then, is CreateFileA (why A in a _w method I have no

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread eryksun
eryksun added the comment: What do you get for os.stat? bak_path = rC:\Users\EAARHOS\Desktop\Python Review\baseExcel.py print(os.stat(bak_path)) bak_path += '.bak' print(os.stat(bak_path)) bak_path += '.bak' print(os.stat(bak_path)) # This should raise FileNotFoundError

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread Aaron
Aaron added the comment: Interesting. It continues to reuse the last one's stats once the path is no longer valid. bak_path = rC:\Users\EAARHOS\Desktop\Python Review\baseExcel.py print(os.stat(bak_path)) nt.stat_result(st_mode=33206, st_ino=8162774324652726, st_dev=0, st_nlink=1, st_uid=0,

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread Aaron
Aaron added the comment: If I use a separate temp variable, the bug doesn't show, but if I use the same variable, even with + instead of +=, it still happens. bak_path = rC:\Users\EAARHOS\Desktop\Python Review\baseExcel.py print(os.stat(bak_path)) nt.stat_result(st_mode=33206,

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread eryksun
eryksun added the comment: When appending to a singly-referenced string, the interpreter tries to reallocate the string in place. This applies to both `s += 'text'` and `s = s + 'text'`. Storing to a temp variable is adding a 2nd reference, so a new string gets allocated instead. If the

[issue22719] os.path.isfile os.path.exists bug in while loop

2014-10-24 Thread eryksun
eryksun added the comment: i.e. the object id is the same after appending Actually, that's wrong. bak_path is a compact string. So the whole object is realloc'd, and the base address (i.e. id) could change. Check PyUnicode_AsUnicode even if the id changes. --

Re: while loop - multiple condition

2014-10-14 Thread giacomo boffi
Tim Chase python.l...@tim.thechases.com writes: On 2014-10-12 22:16, Marko Rauhamaa wrote: is equivalent with while ans.lower()[0] != 'y': ans = input('Do you like python?') And still better improved with while ans[:1].lower() != 'y': ans = input('Do you like

Re: while loop - multiple condition

2014-10-14 Thread Chris Angelico
On Wed, Oct 15, 2014 at 10:04 AM, giacomo boffi pec...@pascolo.net wrote: Tim Chase python.l...@tim.thechases.com writes: On 2014-10-12 22:16, Marko Rauhamaa wrote: is equivalent with while ans.lower()[0] != 'y': ans = input('Do you like python?') And still better improved

Re: while loop - multiple condition

2014-10-13 Thread Gelonida N
On 10/12/2014 07:08 PM, Shiva wrote: while ans.lower() != 'yes' or ans.lower()[0] != 'y': ans = input('Do you like python?') I personally consider double negations less intuitive than following: while not( ans.lower() == 'yes' and ans.lower()[0] == 'y' ): Reading this line yoy would

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 7:31 PM, Gelonida N gelon...@gmail.com wrote: Taking into account the Steven's suggestion about using the 'in' expression it could be: while True: ans = input('Do you like python?') if ans.lower() in ('yes', 'y'): break Or, even simpler: Use an

Re: while loop - multiple condition

2014-10-13 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: Or, even simpler: Use an active condition. while input('Do you like python?') not in ('yes', 'y'): pass Instead of the traditional pull technology, you could take advantage of the state-of-the-art push approach: print(You must love python -- everybody

Re: while loop - multiple condition

2014-10-13 Thread Skip Montanaro
On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico ros...@gmail.com wrote: while input('Do you like python?') not in ('yes', 'y'): pass Unfortunately, you probably have to account for people who SHOUT: while input('Do you like python?').lower() not in ('yes', 'y'): pass wink Skip --

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:10 PM, Skip Montanaro skip.montan...@gmail.com wrote: On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico ros...@gmail.com wrote: while input('Do you like python?') not in ('yes', 'y'): pass Unfortunately, you probably have to account for people who SHOUT: while

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:09 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: Or, even simpler: Use an active condition. while input('Do you like python?') not in ('yes', 'y'): pass Instead of the traditional pull technology, you could take advantage of the

Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: When you have multiple clauses in the condition, it's easier to reason about them if you write the clauses as positive statements rather than negative statements, that is, something is true rather

Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano wrote: When you have multiple clauses in the condition, it's easier to reason about them if you write the clauses as positive statements rather than negative statements,

Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) Rustom Mody rustompm...@gmail.com wrote: On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano wrote: When you have multiple clauses in the condition, it's easier to reason about

Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) Rustom Mody wrote: On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano wrote: When you have multiple clauses

Re: while loop - multiple condition

2014-10-13 Thread Michael Torrie
On 10/13/2014 11:12 AM, Rustom Mody wrote: On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) Rustom Mody wrote: On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano

while loop - multiple condition

2014-10-12 Thread Shiva
Why is the second part of while condition not being checked? while ans.lower() != 'yes' or ans.lower()[0] != 'y': ans = input('Do you like python?') My intention is if either of the conditions are true the loop should break. But the condition after 'or' doesn't seem to evaluate. Thanks,

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:08 AM, Shiva shivaji...@yahoo.com.dmarc.invalid wrote: Why is the second part of while condition not being checked? while ans.lower() != 'yes' or ans.lower()[0] != 'y': ans = input('Do you like python?') My intention is if either of the conditions are true the

Re: while loop - multiple condition

2014-10-12 Thread Shiva
The loop will continue while either part is true - that's what or means. Is that what you intended it to be doing? ChrisA Yes..however, the second part of the or condition doesn't get evaluated. So if I enter a 'y' - I expect the second part to evaluate and the loop to break - but

Re: while loop - multiple condition

2014-10-12 Thread Roy Smith
In article mailman.14792.1413133694.18130.python-l...@python.org, Shiva shivaji...@yahoo.com wrote: Why is the second part of while condition not being checked? while ans.lower() != 'yes' or ans.lower()[0] != 'y': ans = input('Do you like python?') My intention is if either of the

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
}; first cond = {!r}, second cond {!r}, disjunction {!r}.format( ans.lower(), (ans.lower() != 'yes'), (ans.lower()[0] != 'y'), (ans.lower() != 'yes' or ans.lower()[0] != 'y') )) The while loop will continue so long as the disjunction is True. See what it's actually doing

Re: while loop - multiple condition

2014-10-12 Thread Shiva
Bit confusing to use in While loop - Should have used the 'and' condition instead of OR- then it works fine. for OR both condition need to be false to produce a false output and break the loop. More of SET operations. Thanks, Shiva -- https://mail.python.org/mailman/listinfo/python-list

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:59 AM, Shiva shivaji...@yahoo.com.dmarc.invalid wrote: Bit confusing to use in While loop - Should have used the 'and' condition instead of OR- then it works fine. for OR both condition need to be false to produce a false output and break the loop. Correct, what

Re: while loop - multiple condition

2014-10-12 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Mon, Oct 13, 2014 at 4:59 AM, Shiva shivaji...@yahoo.com.dmarc.invalid wrote: Bit confusing to use in While loop - Should have used the 'and' condition instead of OR- then it works fine. for OR both condition need to be false to produce a false output

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 6:16 AM, Marko Rauhamaa ma...@pacujo.net wrote: The corrected version while ans.lower() != 'yes' and ans.lower()[0] != 'y': ans = input('Do you like python?') is equivalent with while ans.lower()[0] != 'y': It's true that the first part is

Re: while loop - multiple condition

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 17:08:00 +, Shiva wrote: while ans.lower() != 'yes' or ans.lower()[0] != 'y': while ans.lower() is not equal to yes or ans.lower()[0] is not equal to y the loop will continue to run Note that if ans.lower() == 'y', then the first clause ( ans.lower() != 'yes' ) is

Re: while loop - multiple condition

2014-10-12 Thread Tim Chase
On 2014-10-12 22:16, Marko Rauhamaa wrote: is equivalent with while ans.lower()[0] != 'y': ans = input('Do you like python?') And still better improved with while ans[:1].lower() != 'y': ans = input('Do you like python?') in the event that len(ans)==0 (a situation which

Re: while loop - multiple condition

2014-10-12 Thread Steven D'Aprano
Tim Chase wrote: On 2014-10-12 22:16, Marko Rauhamaa wrote: is equivalent with while ans.lower()[0] != 'y': ans = input('Do you like python?') And still better improved with while ans[:1].lower() != 'y': ans = input('Do you like python?') The intention is to loop

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:43 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: ONE: Python uses short circuit evaluation: for an OR, the second clause is only looked at if the first clause is FALSE (for an AND, the first clause has to be TRUE before the second is evaluated).

Re: Python While loop Takes too much time.

2014-07-01 Thread Jaydeep Patil
On Monday, 30 June 2014 18:16:21 UTC+5:30, Peter Otten wrote: Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below

Re: Python While loop Takes too much time.

2014-07-01 Thread Peter Otten
Jaydeep Patil wrote: Dear Peter, I have tested code written by you. But still it is taking same time. Too bad ;( If you run the equivalent loop written in Basic from within Excel -- is that faster? If you run the loop in Python with some made-up data instead of that fetched from Excel --

Re: Python While loop Takes too much time.

2014-07-01 Thread Denis McMahon
On Tue, 01 Jul 2014 14:40:18 +0200, Peter Otten wrote: What I'm trying to tell you: you need to put in some work to identify the culprit... His next question was how do I read a range from excel, please give me an example I gave him an example of using google to search for solutions to his

Python While loop Takes too much time.

2014-06-30 Thread Jaydeep Patil
I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much time? Code: def transientTestDict(self,ws,startrow,startcol):

Re: Python While loop Takes too much time.

2014-06-30 Thread Peter Otten
Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much time? Code: def

Re: Python While loop Takes too much time.

2014-06-30 Thread marco . nawijn
On Monday, June 30, 2014 1:32:23 PM UTC+2, Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much

Re: Python While loop Takes too much time.

2014-06-30 Thread Gregory Ewing
marco.naw...@colosso.nl wrote: In the past I even dumped an EXCEL sheet as a CSV file That's probably the only way you'll speed things up significantly. In my experience, accessing Excel via COM is abysmally slow no matter how you go about it. -- Greg --

Re: multiprocessing in a while loop?

2014-06-27 Thread Jesse Adam
Could you post a) what the output looks like now (sans the logging part) b) what output do you expect In any event, this routine does not look right to me: def consume_queue(queue_name): conn = boto.connect_sqs() q = conn.get_queue(queue_name) m = q.read() while m is not None:

multiprocessing in a while loop?

2014-05-06 Thread Johan Llewellyn
hi, I am struggling to understand how to leverage python's multiprocessing module in a while loop.  the examples I have found seem to assume it is known ahead of time how many items need to be processed. specifically, I am reading from an external queue.  I currently process items one

Thread is somehow interfering with a while loop called after the thread is started

2014-03-16 Thread Dan McInerney
Coming back to this a long time later. I figured it out a little bit after I posted this. I wasn't aware that q.try_run() within the nfqueue module was a blocking call https://www.wzdftpd.net/redmine/projects/nfqueue-bindings/wiki/Examples. I'm not sure I was even aware of what it meant to be

Re: Thread is somehow interfering with a while loop called after the thread is started

2013-07-28 Thread Irmen de Jong
the while loop actually prints running is if the callback function is called consistently. If the callback function isn't started, the script will never print running. How can that be if the while loop is AFTER the thread was started? Shouldn't the while loop and the thread operate independantly

Thread is somehow interfering with a while loop called after the thread is started

2013-07-27 Thread dan . h . mcinerney
I have a simple scapy + nfqueue dns spoofing script that I want to turn into a thread within a larger program: http://www.bpaste.net/show/HrlfvmUBDA3rjPQdLmdp/ Below is my attempt to thread the program above. Somehow, the only way the while loop actually prints running is if the callback

Re: First python program, syntax error in while loop

2013-05-07 Thread Mark Lawrence
On 07/05/2013 01:17, alex23 wrote: On May 6, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: One of these days I'll work out why some people insist on using superfluous parentheses in Python code. Could it be that they enjoy exercising their fingers by reaching for the shift key in

Re: First python program, syntax error in while loop

2013-05-07 Thread Chris Angelico
On Tue, May 7, 2013 at 4:10 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 07/05/2013 01:17, alex23 wrote: On May 6, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: One of these days I'll work out why some people insist on using superfluous parentheses in Python code. Could it

Re: First python program, syntax error in while loop

2013-05-07 Thread Chris Angelico
On Tue, May 7, 2013 at 10:44 PM, Ombongi Moraa Fe moraa.lovetak...@gmail.com wrote: My first language was Pascal. It was at a time in 2005 when computers were finally becoming popular in Africa and our year was the first time a girls school from our Province did a computer coursework for

Re: First python program, syntax error in while loop

2013-05-06 Thread Neil Cerutti
On 2013-05-03, John Gordon gor...@panix.com wrote: In auil2vfijo...@mid.individual.net Neil Cerutti ne...@norwich.edu writes: Not quite yet. Players who guess correctly on the fifth try don't get credit. Are you sure? tries is initialized to zero and isn't incremented for the initial

Re: First python program, syntax error in while loop

2013-05-06 Thread Mark Lawrence
On 06/05/2013 13:06, Neil Cerutti wrote: On 2013-05-03, John Gordon gor...@panix.com wrote: In auil2vfijo...@mid.individual.net Neil Cerutti ne...@norwich.edu writes: Not quite yet. Players who guess correctly on the fifth try don't get credit. Are you sure? tries is initialized to zero

Re: First python program, syntax error in while loop

2013-05-06 Thread Neil Cerutti
On 2013-05-06, Mark Lawrence breamore...@yahoo.co.uk wrote: On 06/05/2013 13:06, Neil Cerutti wrote: On 2013-05-03, John Gordon gor...@panix.com wrote: In auil2vfijo...@mid.individual.net Neil Cerutti ne...@norwich.edu writes: Not quite yet. Players who guess correctly on the fifth try

Re: First python program, syntax error in while loop

2013-05-06 Thread Roy Smith
In article mailman.1360.1367843880.3114.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: while (number != guess) and (tries 5): One of these days I'll work out why some people insist on using superfluous parentheses in Python code. Could it be that they enjoy

Re: First python program, syntax error in while loop

2013-05-06 Thread Chris Angelico
On Mon, May 6, 2013 at 11:08 PM, Roy Smith r...@panix.com wrote: On the other hand, I've long since given up trying to remember operator precedence in various languages. If I ever have even the slightest doubt, I just go ahead and put in the extra parens. If I ever have even the slightest

Re: First python program, syntax error in while loop

2013-05-06 Thread rusi
On May 6, 6:08 pm, Roy Smith r...@panix.com wrote: BTW, in C, I used to write: return (foo) for years until somebody pointed out to me that return foo works.  I just assumed that if I had to write: if (foo) while (foo) for (foo; bar; baz) then return (foo) made sense too. I

<    1   2   3   4   5   >