Re: Classes in a class: how to access variables from one in another

2010-10-20 Thread Andreas Waldenburger
On 18 Oct 2010 22:29:27 GMT Steven D'Aprano wrote: > On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > > > Also, Python's scoping rules, particularly for class-level scopes, > > don't work the way programmers from languages where nested classes > > are common would expect: > [snip exampl

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread alex23
Steven D'Aprano wrote: > Avoiding namespace pollution and information hiding are two good reasons > for nesting classes. Python already has a great mechanism for regulating namespaces: modules & importing. Information hiding seems to go against the 'all consenting adults' ethos as well. > There'

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 20:37:34 -0700, alex23 wrote: > Steven D'Aprano wrote: >> I'll accept that nested classes are unusual, but unPythonic? Never! > > Not even if "flat is better than nested" ;) But "Namespaces are one honking great idea -- let's do more of those!" (classes are a good thing) an

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 3:24 PM, Steven D'Aprano wrote: > On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > >> Also, Python's scoping rules, particularly for class-level scopes, don't >> work the way programmers from languages where nested classes are common >> would expect: > [snip exampl

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Tue, 19 Oct 2010 13:54:32 +1000, James Mills wrote: > On Tue, Oct 19, 2010 at 1:37 PM, alex23 wrote: >> Given that there's little if anything gained from nesting classes >> (other than possible scoping confusion) is there ever a need? > > 15+ years of programming and I've never used nested cl

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread James Mills
On Tue, Oct 19, 2010 at 1:37 PM, alex23 wrote: > Given that there's little if anything gained from nesting classes > (other than possible scoping confusion) is there ever a need? 15+ years of programming and I've never used nested classes in any language :) cheers James -- -- James Mills -- --

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread alex23
Steven D'Aprano wrote: > I'll accept that nested classes are unusual, but unPythonic? Never! Not even if "flat is better than nested" ;) And are you the same Steven D'Aprano who once wrote: "Never nest classes, unless you need to, or to win a bet." Given that there's little if anything gained

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 16:05:04 -0700, Aahz wrote: > In article <4cbcca47$0$29979$c3e8da3$54964...@news.astraweb.com>, Steven > D'Aprano wrote: >> >>I'm sorry, I don't see that "language Foo programmers will be surprised >>that Python is not language Foo" is an argument against Python >>programmers

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Seebs
On 2010-10-18, Aahz wrote: > In article <4cbcca47$0$29979$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: >>[duplicate post] > Maybe, but there's no reason for posting that ten times! ;-) I would guess that there is almost certainly a reason. My first candidate would be "buggy

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Aahz
In article <4cbcca47$0$29979$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > >I'm sorry, I don't see that "language Foo programmers will be surprised >that Python is not language Foo" is an argument against Python >programmers using nested classes. Surely it's an argument against >w

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: > Also, Python's scoping rules, particularly for class-level scopes, don't > work the way programmers from languages where nested classes are common > would expect: [snip example] I'm sorry, I don't see that "language Foo programmers will b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 17:17:52 +0200, Christian Heimes wrote: > Don't nest classes. Just don't. This might be a valid and good approach > in some programming languages but it's not Pythonic. Your code can > easily be implemented without nested classes. I'll accept that nested classes are unusual, b

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread John Nagle
On 10/18/2010 8:17 AM, Christian Heimes wrote: Am 18.10.2010 16:35, schrieb f...@slick.airforce-one.org: So my way of coding it is the following: class zone(GtkDrawingArea): class systemOfCoordinates: self.xmin = -5 self.xmax = 5 self.ymin = -5 self.ymax = 5 class Cu

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Jean-Michel Pichavant
f...@slick.airforce-one.org wrote: Jean-Michel Pichavant wrote: Always post working code, or at least something we can paste in the python interpreter (even if it's buggy) Ok, noted. class A: class B: x=2 class C: def __init__(self): print A.B.x c

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 8:58 AM, Andreas Waldenburger wrote: > On Mon, 18 Oct 2010 17:17:52 +0200 Christian Heimes > wrote: > >> [snip] >> Don't nest classes. Just don't. This might be a valid and good >> approach in some programming languages but it's not Pythonic. > > Explain! "Private" classe

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Jean-Michel Pichavant
f...@slick.airforce-one.org wrote: Christian Heimes wrote: Don't nest classes. Just don't. This might be a valid and good approach in some programming languages but it's not Pythonic. Your code can easily be implemented without nested classes. I think you're right. It would have been

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Andreas Waldenburger
On Mon, 18 Oct 2010 17:17:52 +0200 Christian Heimes wrote: > [snip] > Don't nest classes. Just don't. This might be a valid and good > approach in some programming languages but it's not Pythonic. Explain! /W -- To reach me via email, replace INVALID with the country code of my home country

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread fab
Christian Heimes wrote: > Don't nest classes. Just don't. This might be a valid and good approach > in some programming languages but it's not Pythonic. Your code can > easily be implemented without nested classes. I think you're right. It would have been more aesthetically pleasant to me (a Hand

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Christian Heimes
Am 18.10.2010 16:35, schrieb f...@slick.airforce-one.org: > So my way of coding it is the following: > > class zone(GtkDrawingArea): > > class systemOfCoordinates: > self.xmin = -5 > self.xmax = 5 > self.ymin = -5 > self.ymax = 5 > > class Curve: > self.listOfPoints = ()

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Nobody
On Mon, 18 Oct 2010 14:35:58 +, fab wrote: > So my way of coding it is the following: > > class zone(GtkDrawingArea): > > class systemOfCoordinates: > self.xmin = -5 > self.xmax = 5 > self.ymin = -5 > self.ymax = 5 "self" isn't meaningful within a class definition. It's f

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread fab
Jean-Michel Pichavant wrote: > Always post working code, or at least something we can paste in the > python interpreter (even if it's buggy) Ok, noted. > class A: >class B: >x=2 >class C: >def __init__(self): >print A.B.x > > c = A.C() > > >2 Good, thanks.

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Jean-Michel Pichavant
f...@slick.airforce-one.org wrote: Neil Cerutti wrote: I have a class A that contains two classes B and C: class A: class B: self.x = 2 class C: I only wanted to show the structure of the code, not the actual instructions. Always post working code, or at least some

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread fab
Gary Herron wrote: > Well, your code still doesn't make sense, but the generic answers are: I'll clarify what I need then: I'm drawing Bézier curves. I draw them on a zone that is defined as a subclass of GtkDrawingArea. In a zone, I define a system of coordinates by 4 values: xmin, xmax, ymin,

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Gary Herron
On 10/18/2010 06:45 AM, f...@slick.airforce-one.org wrote: Neil Cerutti wrote: I have a class A that contains two classes B and C: class A: class B: self.x = 2 class C: I only wanted to show the structure of the code, not the actual instructions. That's not valid Python code. D

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread fab
Neil Cerutti wrote: >> I have a class A that contains two classes B and C: >> >> class A: >> class B: >> self.x = 2 >> >> class C: I only wanted to show the structure of the code, not the actual instructions. > That's not valid Python code. Do you mean: > > Class A: > Class B: >

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Neil Cerutti
On 2010-10-18, Neil Cerutti wrote: > On 2010-10-18, > wrote: >> Hello. >> >> I have a class A that contains two classes B and C: >> >> class A: >> class B: >> self.x = 2 >> >> class C: >> >> Is there a way to access the x defined in B in class C? > > That's not valid Python code. Do

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Neil Cerutti
On 2010-10-18, wrote: > Hello. > > I have a class A that contains two classes B and C: > > class A: > class B: > self.x = 2 > > class C: > > Is there a way to access the x defined in B in class C? That's not valid Python code. Do you mean: Class A: Class B: x = 2 or Class A

Classes in a class: how to access variables from one in another

2010-10-18 Thread fab
Hello. I have a class A that contains two classes B and C: class A: class B: self.x = 2 class C: Is there a way to access the x defined in B in class C? Thanks. -- F. Delente -- http://mail.python.org/mailman/listinfo/python-list