Interesting. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
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):
>>
>>
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
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
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.
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
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
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
> ...
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
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:
|>
|>
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
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:/
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.
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
[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
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
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
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
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
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
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
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
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
23 matches
Mail list logo