luke.leighton at googlemail.com
Fri Oct 3 13:16:34 CEST 2008
On Oct 3, 10:29 am, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> lkcl a écrit :> On Oct 2, 7:42 pm, Bruno Desthuilliers
> > <bdesth.quelquech... at free.quelquepart.fr> wrote:
> >> lkcl a écrit :
> Not 'mine' - I'm not the OP.
whoops, yes - i missed that. sorry!
> And as far as I'm concerned, the point is
> exactly here : it's doing "a little bit more" than the original code.
yeah, i know. and that "bit more" gets you a proper representation
of the python "class" concept.
i was merely pointing out that if you want to _really_ translate the
original code into python - _really_ strictly - it's not actually
possible. because python doesn't have the concept of non-prototyping
(but... see below: i believe i may stand corrected on that)
> [..snip..] and is
> actually useless for the OP's use case (else the OP's code wouldn't use
> litteral object notation but a full-blown prototype).
i know :)
> > it's
> > overriding the "prototype" of dataListener, making it a true "class"
> > object.
> course already know.
okay,okay :) class-like :)
> Indeed. But the point is that Python - while close to a prototype-based
> language in many aspects - is still class-based. The closer Python
> using a 'class singleton' - that is, using the class itself as an
oh is _that_ how you do it. thanks. i always wondered how you did
class singletons in python.
> pyjamas - it would just be way too complicated to automatize such a
well... you _say_ that... but... actually, if that's the real way to
represent class singletons, and it's an accurate representation of the
definitely have that added as a feature - to understand that a class
example you gave.
not that many people would _want_ to do that, so it goes onto the
"diminishing returns TODO list", but...
> Nope. You defined functions outside the object's scope, and you still
> have to instanciate dataListener. Also, this above code just won't work
> - unless you explicitely pass the dataListener instance to the
> functions, ie:
> d = dataListener()
> d.onDataAvailable(d, ...)
yeah - i didn't realise what the python class singleton thing was.
> It seem you didn't read my other translation proprosal, so I repost it here:
> class dataListener(object):
> data = ''
i did - i just didn't understand its significance.
so - to get this straight: when you do class clsname(object), and you
have the indentation and declaration of variables (e.g. data, above)
at the same level as the functions, it means that there's only one of
them? (i.e. a singleton)?
so, if i do this:
d = dataListener()
e = dataListener()
d.data = "fred"
will return "fred"?
More information about the Python-list