Re: Creating a local variable scope.

2009-12-09 Thread rwwh
On Nov 30, 1:26 am, markolopa wrote: > I would be much happier with the smaller namespace. To fix the code > that you show I would impose > > s = None > while True: >      s = raw_input("enter something: ") >      if s not in ('q', 'quit', 'exit'): break > print s So you propose: if the variable

Re: Creating a local variable scope.

2009-12-03 Thread Ben Finney
Lie Ryan writes: > On 12/2/2009 2:56 PM, Ben Finney wrote: > > The ‘camelCase’ form is not conformant with PEP 8 at all (which makes me > > glad, since it's hideous). > > For some reason, every time I look at a unittest code, I was thinking > of Java... and not just because it's modeled after JUn

Re: Creating a local variable scope.

2009-12-03 Thread Lie Ryan
On 12/2/2009 2:56 PM, Ben Finney wrote: The ‘camelCase’ form is not conformant with PEP 8 at all (which makes me glad, since it's hideous). For some reason, every time I look at a unittest code, I was thinking of Java... and not just because it's modeled after JUnitTest. -- http://mail.python

Re: Creating a local variable scope.

2009-12-02 Thread r0g
Ben Finney wrote: > markolopa writes: > >> Hi Roger, >> > […] >>> Long, descriptive variable names all_in_lower_case >>> Function names all in CamelCase >>> Global names are in ALL CAPS >> yes, pep8 I guess. > > Not quite: it deviates from PEP 8 on function names, which should rather > be ‘lower

Re: Creating a local variable scope.

2009-12-01 Thread Ben Finney
markolopa writes: > Hi Roger, > […] > > Long, descriptive variable names all_in_lower_case > > Function names all in CamelCase > > Global names are in ALL CAPS > > yes, pep8 I guess. Not quite: it deviates from PEP 8 on function names, which should rather be ‘lower_case_words_separated_by_unders

Re: Creating a local variable scope.

2009-12-01 Thread markolopa
Hi Roger, > > That is what I do regularly...8-> > > Well really dude, you need to stop doing that. It's not a language > problem, it's a memory problem (human not RAM!). You guessed quite correctly!...:-) I can't recognise my code sometimes after a single week. That's why I spend a lot of time cl

Re: Creating a local variable scope.

2009-12-01 Thread markolopa
Hi Dave, Since you feel like discussing my weird idea of Python reform :-) lets go... On 30 Nov, 11:29, Dave Angel wrote: > Somehow you seem to think there's some syntax for "creating" avariable.  In > fact, what's happening is you're binding/rebinding a name > to an object.  And if you forbid

Re: Creating a local variable scope.

2009-11-30 Thread r0g
markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: >> markolopa wrote: >> or >> whether you accidentally reused the same name without giving it a new >> value in the new loop. > > That is what I do regularly...8-> > Well really dude, you need to stop doing that. It's not a language p

Re: Creating a local variable scope.

2009-11-30 Thread Alf P. Steinbach
* Jean-Michel Pichavant: Steven D'Aprano wrote: On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: I think if one could somehow declare names as const (final, readonly, whatever) then that would cover the above plus much more. Having real constants is one feature that I miss.

Re: Creating a local variable scope.

2009-11-30 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: I think if one could somehow declare names as const (final, readonly, whatever) then that would cover the above plus much more. Having real constants is one feature that I miss. Because Python doesn't

Re: Creating a local variable scope.

2009-11-30 Thread Steven D'Aprano
On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: > I think if one could somehow declare names as const (final, readonly, > whatever) then that would cover the above plus much more. Having real constants is one feature that I miss. Because Python doesn't have constants, I find I've los

Re: Creating a local variable scope.

2009-11-30 Thread Dave Angel
markolopa wrote: On Nov 30, 4:46 am, Dave Angel wrote: markolopa wrote: Antoher 15 minutes lost because of that Python "feature"... Is it only me??? Yep, I think so. Not very consoling but thanks anyway!...:- You're proposing a much more complex scoping rule, w

Re: Creating a local variable scope.

2009-11-30 Thread Lie Ryan
On 11/30/2009 8:13 PM, markolopa wrote: On Nov 30, 4:46 am, Dave Angel wrote: markolopa wrote: Antoher 15 minutes lost because of that Python "feature"... Is it only me??? Yep, I think so. Not very consoling but thanks anyway!...:- You're proposing a much more complex scoping rule,

Re: Creating a local variable scope.

2009-11-30 Thread markolopa
On Nov 30, 4:46 am, Dave Angel wrote: > markolopa wrote: > > Antoher 15 minutes lost because of that Python "feature"... Is it only > > me??? > > Yep, I think so. Not very consoling but thanks anyway!...:- > You're proposing a much more complex scoping rule, > where if a variable already exi

Re: Creating a local variable scope.

2009-11-30 Thread markolopa
Hi Steve! On Nov 30, 1:46 am, Steve Howell wrote: > I occasionally make the error you make, but I think the real problem > you are having is lack of attention to detail.  If name collisions are > a common problem for you, consider writing shorter methods Yes, this could be a solution, though I b

Re: Creating a local variable scope.

2009-11-29 Thread Terry Reedy
markolopa wrote: so "domain" should not exist in my namespace since I have no information associated to "domain" only to "self.domains". Python should allow me to write safe code! Leaving iteration names bound after loop exit is a feature. If you do not like it, explicitly unbind it. -- ht

Re: Creating a local variable scope.

2009-11-29 Thread Dave Angel
markolopa wrote: === arg_columns =] for domain in self.domains: i =elf.get_column_index(column_names, domain.name) col =olumn_elements[i] if len(col) !=en(val_column): ValueError('column %s has not the same size as the value column %s' % (column_names[

Re: Creating a local variable scope.

2009-11-29 Thread Alf P. Steinbach
* markolopa: On 18 Sep, 10:36, "markol...@gmail.com" wrote: On Sep 11, 7:36 pm, Johan Grönqvist wrote: I find several places in my code where I would like tohavea variable scope that is smaller than the enclosing function/class/module definition. This is one of the single major frustrations

Re: Creating a local variable scope.

2009-11-29 Thread Steve Howell
On Nov 29, 4:26 pm, markolopa wrote: > Less than 3 hours have passed since my last post and got yet another > bug that could be prevented if Python had the functionality that other > languages have to destroy variables when a block ends. Here is the > code: > > = > > arg_columns = [] > for

Re: Creating a local variable scope.

2009-11-29 Thread markolopa
Hi Lie! On Nov 29, 11:11 pm, Lie Ryan wrote: > here is another bug you might have if python have an "even-more-local" > scope: > > while True: >      s = raw_input("enter something: ") >      if s not in ('q', 'quit', 'exit'): break > print s > > if the while block has become its own namespace; p

Re: Creating a local variable scope.

2009-11-29 Thread Lie Ryan
On 11/30/2009 8:12 AM, markolopa wrote: Hi, On 18 Sep, 10:36, "markol...@gmail.com" wrote: On Sep 11, 7:36 pm, Johan Grönqvist wrote: I find several places in my code where I would like tohavea variable scope that is smaller than the enclosing function/class/module definition. This is one

Re: Creating a local variable scope.

2009-11-29 Thread markolopa
Hi, On 18 Sep, 10:36, "markol...@gmail.com" wrote: > On Sep 11, 7:36 pm, Johan Grönqvist wrote: > > I find several places in my code where I would like tohavea variable > > scope that is smaller than the enclosing function/class/module definition. > > This is one of the single major frustrations

Re: Creating a local variable scope.

2009-09-24 Thread Albert van der Horst
In article <65e8a017-abcb-49ad-8867-bc473f83e...@s39g2000yqj.googlegroups.com>, Bearophile wrote: >Steven D'Aprano: > >> (3) Create an inner function, then call that. > >Several people after someone gives this anwer. > > >> My personal opinion is that if you really need a local scope >> inside a

Re: Creating a local variable scope.

2009-09-19 Thread Ethan Furman
Dave Angel wrote: Johan Grönqvist wrote: DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I l

Re: Creating a local variable scope.

2009-09-19 Thread Dave Angel
Johan Grönqvist wrote: Sean DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. Th

Re: Creating a local variable scope.

2009-09-19 Thread Johan Grönqvist
Sean DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. This also minimizes the ex

Re: Creating a local variable scope.

2009-09-19 Thread Johan Grönqvist
Gabriel Genellina skrev: En Fri, 18 Sep 2009 10:55:47 -0300, Johan Grönqvist escribió: Summarizing the answers, it seems that I will try to follow three suggestions: 3) If I define a few values intended to be used very locally, delete those after use. Why bother? Unless they're big objec

Re: Creating a local variable scope.

2009-09-18 Thread Sean DiZazzo
On Sep 11, 10:36 am, Johan Grönqvist wrote: > Hi All, > > I find several places in my code where I would like to have a variable > scope that is smaller than the enclosing function/class/module definition. > > One representative example would look like: > > -- > spam = { ... } > eggs = { .

Re: Creating a local variable scope.

2009-09-18 Thread Gabriel Genellina
En Fri, 18 Sep 2009 10:55:47 -0300, Johan Grönqvist escribió: Summarizing the answers, it seems that I will try to follow three suggestions: 1) In general, try to restructure the code into smaller modules and smaller functions. That's a good thing - "manageable" modules and functions.

Re: Creating a local variable scope.

2009-09-18 Thread Johan Grönqvist
Thanks for all replies. First, two general comments, and then my conclusions: I did not intend to ask for new features, but my interest was in writing readable code that works in python 2.5, although I may upgrade to 2.6 soon. Also, what I gave was intended as a minimal example, and not a com

Re: Creating a local variable scope.

2009-09-18 Thread Wolfgang Rohdewald
On Friday 18 September 2009, Ethan Furman wrote: > loop != scope true for python but in some languages the loop counter has a scope limited to the loop -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a local variable scope.

2009-09-18 Thread Ethan Furman
Neal Becker wrote: markol...@gmail.com wrote: On Sep 11, 7:36 pm, Johan Grönqvist wrote: Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. This is one of the single major frustrations

Re: Creating a local variable scope.

2009-09-18 Thread Neal Becker
markol...@gmail.com wrote: > On Sep 11, 7:36 pm, Johan Grönqvist wrote: >> Hi All, >> >> I find several places in my code where I would like to have a variable >> scope that is smaller than the enclosing function/class/module >> definition. > > This is one of the single major frustrations I have

Re: Creating a local variable scope.

2009-09-18 Thread markol...@gmail.com
On Sep 11, 7:36 pm, Johan Grönqvist wrote: > Hi All, > > I find several places in my code where I would like to have a variable > scope that is smaller than the enclosing function/class/module definition. This is one of the single major frustrations I have with Python and a important source of bu

Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
On Sat, Sep 12, 2009 at 10:02 AM, Ethan Furman wrote: > That's probably why he called it as: > with do_nothing() as *imaginary*_local_scope: >... >del spam, eggs, imaginary_local_scope > > and then as the last item deleted all the variables, except the one he > wanted to keep. > You're a

Re: Creating a local variable scope.

2009-09-12 Thread Ethan Furman
Daniel Stutzbach wrote: On Fri, Sep 11, 2009 at 8:29 PM, Steven D'Aprano > wrote: (4) Create a "do nothing" context manager allowing you to visually indent the block, but otherwise have no effect: "with" doesn't create a new scope. Th

Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
On Fri, Sep 11, 2009 at 8:29 PM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > (4) Create a "do nothing" context manager allowing you to visually indent > the block, but otherwise have no effect: > "with" doesn't create a new scope. Observe: Python 2.6.2 (r262:71600, Apr 15 2

Re: Creating a local variable scope.

2009-09-12 Thread Jorgen Grahn
On Fri, 11 Sep 2009 19:07:55 -0700 (PDT), Bearophile wrote: ... > No need to add other things to the > language as the OP suggests. He didn't suggest that (although he did give examples from other languages). Personally ... yes, I sometimes feel like the OP, but usually if I want that kind of s

Re: Creating a local variable scope.

2009-09-11 Thread Bearophile
Steven D'Aprano: > (3) Create an inner function, then call that. Several people after someone gives this anwer. > My personal opinion is that if you really need a local scope inside a > function, the function is doing too much and should be split up.< I agree. And a way to split a function is

Re: Creating a local variable scope.

2009-09-11 Thread Steven D'Aprano
On Fri, 11 Sep 2009 19:36:14 +0200, Johan Grönqvist wrote: > Hi All, > > I find several places in my code where I would like to have a variable > scope that is smaller than the enclosing function/class/module > definition. ... > The essence is that for readability, I want spam and eggs in separat

Re: Creating a local variable scope.

2009-09-11 Thread Carl Banks
On Sep 11, 10:36 am, Johan Grönqvist wrote: > In the other languages I have used I can either use braces (C and > descendants) or use let-bindings (SML, Haskell etc.) to form local scopes. I wouldn't mind a let statement but I don't think the language really suffers for the lack of it. I expect

Re: Creating a local variable scope.

2009-09-11 Thread Terry Reedy
Johan Grönqvist wrote: Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. One representative example would look like: -- spam = { ... } eggs = { ... } ham = (a[eggs], b[spam]) --

Re: Creating a local variable scope.

2009-09-11 Thread Ethan Furman
Patrick Sabin wrote: Johan Grönqvist schrieb: Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. One representative example would look like: -- spam = { ... } eggs = { ... } ham

Re: Creating a local variable scope.

2009-09-11 Thread Daniel Stutzbach
2009/9/11 Johan Grönqvist > I find several places in my code where I would like to have a variable > scope that is smaller than the enclosing function/class/module definition. > For what it's worth, there was a relevant proposal on the python-ideas list a few months back: http://mail.python.org

Re: Creating a local variable scope.

2009-09-11 Thread Patrick Sabin
Johan Grönqvist schrieb: Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. One representative example would look like: -- spam = { ... } eggs = { ... } ham = (a[eggs], b[spam])

Re: Creating a local variable scope.

2009-09-11 Thread Neal Becker
Johan Grönqvist wrote: > Hi All, > > I find several places in my code where I would like to have a variable > scope that is smaller than the enclosing function/class/module definition. > > One representative example would look like: > > -- > spam = { ... } > eggs = { ... } > > ham = (a

Creating a local variable scope.

2009-09-11 Thread Johan Grönqvist
Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. One representative example would look like: -- spam = { ... } eggs = { ... } ham = (a[eggs], b[spam]) -- The essence is tha