[issue44332] For Loop temporary variable scope should be local to For loop

2021-06-07 Thread Mark Dickinson
Change by Mark Dickinson : -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44332] For Loop temporary variable scope should be local to For loop

2021-06-06 Thread Steven D'Aprano
Steven D'Aprano added the comment: By the way, loop variables are not considered to be "temporary" in Python. They are no more temporary than any other local variable -- they *are* local variables with exactly the same scope and lifetime as all other local variables. --

[issue44332] For Loop temporary variable scope should be local to For loop

2021-06-06 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, it is intentional design and has been since Python 1. You are incorrect about x consuming memory "always". If the value bound to x is in use elsewhere, deleting x will save no memory. If the value is not in use elsewhere, it will be

[issue44332] For Loop temporary variable scope should be local to For loop

2021-06-06 Thread Debasis Satapathy
New submission from Debasis Satapathy : numbers = [1, 2, 3, 4, 5, 6, 7, 8] for x in numbers: print(x) print(x) In the above code, print(x) statement should give error. Because x scope should be local to for loop only. 99% cases, developers will not use the temporary variable x outside

Re: Temporary Variable

2006-02-25 Thread Steven D'Aprano
On Fri, 24 Feb 2006 14:08:22 -0800, darthbob88 wrote: Reply to all: I realize that naming a variable spam is not entirely kosherized. It was originally named secret, but I renamed it in a fit of whimsy. The language is named after Monty Python's Flying Circus, is it not? Remember the Spam

Re: Temporary Variable

2006-02-25 Thread Terry Hancock
On 24 Feb 2006 14:08:22 -0800 [EMAIL PROTECTED] wrote: Reply to all: I realize that naming a variable spam is not entirely kosherized. In fact this is untrue: It is an official rule straight from the BDFL himself that example programs should contain words like spam, ham, eggs from the spam

Re: Temporary Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote: Steven D'Aprano wrote: On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: My comments inserted inline. #!/usr/bin/python #simple guessing game, with numbers import random spam = random.randint(1, 100) It is bad

Re: Temporary Variable

2006-02-24 Thread bonono
Steven D'Aprano wrote: Just out of curiosity, when do you think is the right time to begin teaching programmers good practice from bad? Before or after they've learnt bad habits? When you have authority over the coding guideline. Naming things is not something limited to programming and most

Re: Temporary Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 01:50:40 -0800, bonono wrote: Steven D'Aprano wrote: Just out of curiosity, when do you think is the right time to begin teaching programmers good practice from bad? Before or after they've learnt bad habits? When you have authority over the coding guideline. By that

Re: Temporary Variable

2006-02-24 Thread Jeffrey Schwab
Steven D'Aprano wrote: On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote: Steven D'Aprano wrote: On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: My comments inserted inline. #!/usr/bin/python #simple guessing game, with numbers import random spam = random.randint(1, 100)

Re: Temporary Variable

2006-02-24 Thread darthbob88
Reply to all: I realize that naming a variable spam is not entirely kosherized. It was originally named secret, but I renamed it in a fit of whimsy. The language is named after Monty Python's Flying Circus, is it not? Remember the Spam Sketch. http://en.wikipedia.org/wiki/Spam_sketch I thank you

Re: Temporary Variable

2006-02-23 Thread darthbob88
Steven D'Aprano wrote: [EMAIL PROTECTED] wrote: Problem: I wish to run an infinite loop and initialize a variable on each iteration. Sort of like, Enter Data, test it, No good!, Next Try?, test it, etc. What I've tried is simply while 1: var1 = raw_input, test var1, then run through the

Re: Temporary Variable

2006-02-23 Thread Rick Zantow
[EMAIL PROTECTED] wrote in news:1140725159.143882.202630 @j33g2000cwa.googlegroups.com: Steven D'Aprano wrote: You could try this: while 1: var = raw_input(Give me some data! ) if var == some data: print Success! break else: print No good, try

Re: Temporary Variable

2006-02-23 Thread Steven D'Aprano
On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: My comments inserted inline. #!/usr/bin/python #simple guessing game, with numbers import random spam = random.randint(1, 100) It is bad programming practice to give variables uninformative joke names. How about target instead? print

Re: Temporary Variable

2006-02-23 Thread Jeffrey Schwab
Steven D'Aprano wrote: On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: My comments inserted inline. #!/usr/bin/python #simple guessing game, with numbers import random spam = random.randint(1, 100) It is bad programming practice to give variables uninformative joke names.

Temporary Variable

2006-02-22 Thread darthbob88
Problem: I wish to run an infinite loop and initialize a variable on each iteration. Sort of like, Enter Data, test it, No good!, Next Try?, test it, etc. What I've tried is simply while 1: var1 = raw_input, test var1, then run through the loop again. What results is var1 gets and keeps the first

Re: Temporary Variable

2006-02-22 Thread [EMAIL PROTECTED]
I tried this code and it worked fine: while 1: var1 = raw_input(Enter a number: ) print You entered:,var1 var1 = int(var1) + 1 print var1 -- http://mail.python.org/mailman/listinfo/python-list

Re: Temporary Variable

2006-02-22 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: Problem: I wish to run an infinite loop and initialize a variable on each iteration. Sort of like, Enter Data, test it, No good!, Next Try?, test it, etc. What I've tried is simply while 1: var1 = raw_input, test var1, then run through the loop again. What results is