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 st...@remove-this-cybersource.com.au 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

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

2010-10-19 Thread alex23
Steven D'Aprano steve-remove-t...@cybersource.com.au 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

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

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

2010-10-18 Thread Neil Cerutti
On 2010-10-18, f...@slick.airforce-one.org f...@slick.airforce-one.org 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:

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 ne...@norwich.edu wrote: On 2010-10-18, f...@slick.airforce-one.org f...@slick.airforce-one.org 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

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

2010-10-18 Thread fab
Neil Cerutti ne...@norwich.edu 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: x

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 Ceruttine...@norwich.edu 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

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

2010-10-18 Thread fab
Gary Herron gher...@islandtraining.com 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

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 ne...@norwich.edu 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

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

2010-10-18 Thread fab
Jean-Michel Pichavant jeanmic...@sequans.com 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

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 far from

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 = () def

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

2010-10-18 Thread fab
Christian Heimes li...@cheimes.de 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

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 li...@cheimes.de 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

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 li...@cheimes.de 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

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 use...@geekmail.invalid wrote: On Mon, 18 Oct 2010 17:17:52 +0200 Christian Heimes li...@cheimes.de 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.

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 jeanmic...@sequans.com 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):

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

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, but

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 be

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 be

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 be

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 be

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 be

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 be

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 be

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 be

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 be

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 be

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 st...@remove-this-cybersource.com.au 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.

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

2010-10-18 Thread Seebs
On 2010-10-18, Aahz a...@pythoncraft.com wrote: In article 4cbcca47$0$29979$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: [duplicate post] Maybe, but there's no reason for posting that ten times! ;-) I would guess that there is almost

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 st...@remove-this-cybersource.com.au wrote: I'm sorry, I don't see that language Foo programmers will be surprised that Python is not language Foo is an argument

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

2010-10-18 Thread alex23
Steven D'Aprano st...@remove-this-cybersource.com.au 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

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 wuwe...@gmail.com 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 -- --

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 wuwe...@gmail.com 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

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 st...@remove-this-cybersource.com.au 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

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 st...@remove-this-cybersource.com.au 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!