Re: What is the reason for defining classes within classes in Python?

2013-04-24 Thread vasudevram
Interesting. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: What is the reason for defining classes within classes in Python?

2013-04-24 Thread Peter Otten
vasudevram wrote: > On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: >> >> A nested class definition will be defined as an attribute of the class >> >> its defined within: >> >> >> >> >>> class Outer(object): >> >> ... foo = 'FOO' >> >> ... class Inner(object): >> >>

Re: What is the reason for defining classes within classes in Python?

2013-04-24 Thread vasudevram
On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: > On Apr 24, 9:13 am, vasudevram wrote: > > > On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > > > > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram  wrote: > > > > > I saw an example of defining a class within another cl

Re: What is the reason for defining classes within classes in Python?

2013-04-23 Thread alex23
On Apr 24, 9:13 am, vasudevram wrote: > On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram  wrote: > > > I saw an example of defining a class within another class > > > In what way is this useful? > > > In that particular case they're just

Re: What is the reason for defining classes within classes in Python?

2013-04-23 Thread vasudevram
On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: > > > > > > Hi list, > > > > > > I saw an example of defining a class within another class, here, in the > > docs for peewee, a simple ORM for Python: > > > > > > http://peewee.

Re: What is the reason for defining classes within classes in Python?

2013-04-23 Thread Ian Kelly
On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: > > Hi list, > > I saw an example of defining a class within another class, here, in the docs > for peewee, a simple ORM for Python: > > http://peewee.readthedocs.org/en/latest/peewee/quickstart.html > > In what way is this useful? In that parti

What is the reason for defining classes within classes in Python?

2013-04-23 Thread vasudevram
Hi list, I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: http://peewee.readthedocs.org/en/latest/peewee/quickstart.html In what way is this useful? Thanks, Vasudev -- http://mail.python.org/mailman/listinfo/python-list

Re: Defining classes

2006-12-15 Thread Michele Simionato
Steven Bethard wrote: > How are you doing it currently? Here's a sort of minimalist option: > > >>> class weeble(object): > ... def __metaclass__(name, bases, bodydict): > ... cls = type(name, bases, bodydict) > ... cls.wumpus = 'brinjal', cls > ...

Re: Defining classes

2006-12-14 Thread Steven Bethard
Nick Maclaren wrote: > I am defining a class, and I need to refer to that class when > setting up its static data - don't ask - like this: > > Class weeble : > wumpus = brinjal(weeble) Duncan Booth wrote: > Alternatively you can play tricks with metaclasses for a similar effect. Nick Maclare

Re: Defining classes

2006-12-14 Thread Nick Maclaren
In article <[EMAIL PROTECTED]>, "Michele Simionato" <[EMAIL PROTECTED]> writes: |> Nick Maclaren wrote: |> > It would be much cleaner not to have to fiddle with static |> > members after the class is initialised. |> |> You can hide the fiddling, for instance with the trick explained here: |> |>

Re: Defining classes

2006-12-14 Thread Nick Maclaren
In article <[EMAIL PROTECTED]>, Michael Spencer <[EMAIL PROTECTED]> writes: |> |> "instantiation" (i.e., calling the __new__ method) of new-style classes |> can return whatever you like, but I'm not sure how that helps. Yes and no. While it can return any value you like, it can't act as a clas

Re: Defining classes

2006-12-14 Thread Michele Simionato
Nick Maclaren wrote: > It would be much cleaner not to have to fiddle with static > members after the class is initialised. You can hide the fiddling, for instance with the trick explained here: http://www.phyast.pitt.edu/~micheles/python/classinitializer.html Michele Simionato -- http:/

Re: Defining classes

2006-12-13 Thread Michael Spencer
Nick Maclaren wrote: > > Well, I am already doing that, and regretting the fact that Python > doesn't seem to allow a class instantiation to return a new class :-) > >>> class Fake(object): ... def __new__(cls): ... return 42 ... >>> Fake() 42 >>> "instantiation" (i.e.

Re: Defining classes

2006-12-13 Thread Nick Maclaren
In article <[EMAIL PROTECTED]>, Duncan Booth <[EMAIL PROTECTED]> writes: |> > |> > I am defining a class, and I need to refer to that class when |> > setting up its static data - don't ask - like this: |> > |> > Class weeble : |> > wumpus = brinjal(weeble) |> |> You cannot refer to weeble u

Re: Defining classes

2006-12-13 Thread Duncan Booth
[EMAIL PROTECTED] (Nick Maclaren) wrote: > > I am defining a class, and I need to refer to that class when > setting up its static data - don't ask - like this: > > Class weeble : > wumpus = brinjal(weeble) You cannot refer to weeble until it has been created which isn't until after all of

Re: Defining classes

2006-12-13 Thread Gabriel Genellina
At Wednesday 13/12/2006 18:04, Nick Maclaren wrote: I am defining a class, and I need to refer to that class when setting up its static data - don't ask - like this: Class weeble : wumpus = brinjal(weeble) Move it below the class: class weeble: weeble.wumpus = brinjal(weebl

Defining classes

2006-12-13 Thread Nick Maclaren
I am defining a class, and I need to refer to that class when setting up its static data - don't ask - like this: Class weeble : wumpus = brinjal(weeble) Does anyone know how I can achieve this? Naturally, I don't need anything more than the address of the class in brinjal, as it won't be u

Re: defining classes

2005-09-02 Thread Steve Holden
LeRoy Lee wrote: > I have been searching for the answer to this as it will determine how I use > classes. Here are two bits of code. [snip already well-quoted examples] > > I can't figure out why it is working this way. I figure I must be thinking > about this wrong. I was thinking that I c

Re: defining classes

2005-09-02 Thread Steve Horsley
LeRoy Lee wrote: > I have been searching for the answer to this as it will determine how I > use classes. Here are two bits of code. > > class foo1: >def __init__(self, i): >self.r = i >self.j = 5 > >>> h = foo1(1) >>> h.r > > 1 > >>> h.j > > 5 > > > Now take this examp

Re: defining classes

2005-09-02 Thread Benji York
LeRoy Lee wrote: > I have been searching for the answer to this as it will determine how I use > classes. Here are two bits of code. > class foo2: > def __init__(self): > self.j = 5 > > >>>h = foo2() >>>h.j > > Traceback (most recent call last): > File "", line 1, in ? > Attribu

Re: defining classes

2005-09-02 Thread Grant Edwards
On 2005-09-02, LeRoy Lee <[EMAIL PROTECTED]> wrote: > Now take this example > > class foo2: > def __init__(self): > self.j = 5 > >>>h = foo2() >>>h.j > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: foo2 instance has no attribute 'j' Works fine for me e

Re: defining classes

2005-09-02 Thread Michael Hoffman
LeRoy Lee wrote: > class foo2: >def __init__(self): >self.j = 5 > >>> h = foo2() >>> h.j > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: foo2 instance has no attribute 'j' Try again: >>> class foo2: ...def __init__(self): ...self.j = 5

defining classes

2005-09-02 Thread LeRoy Lee
I have been searching for the answer to this as it will determine how I use classes. Here are two bits of code. class foo1: def __init__(self, i): self.r = i self.j = 5 >>h = foo1(1) >>h.r 1 >>h.j 5 Now take this example class foo2: def __init__(self): self.j