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
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
14 matches
Mail list logo