"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I have some places in pyparsing where I've found that the most
> straightforward way to adjust an instance's behavior is to change its
> class.
> I do this by assigning to se
Heiko Wundram <[EMAIL PROTECTED]> wrote:
> bruno at modulix wrote:
> > Paul McGuire wrote:
> >> or am I taking advantage of a fortuitous accident, which may get
> >> undone at a future time?
> >
> > It's certainly not a fortuitous accident.
>
> And even the (printed) cookbook has examples which
bruno at modulix wrote:
> Paul McGuire wrote:
>> or am I taking advantage of a fortuitous accident, which may get
>> undone at a future time?
>
> It's certainly not a fortuitous accident.
And even the (printed) cookbook has examples which assign to
self.__class__... I guess this means this featu
ython is to :
>(snip) assigning to self.__class__, (snip)
!-)
>
> Any comments on this practice?
It can be very confusing for newbies and peoples having no experience
with *dynamic* languages, and I guess control-freaks and
static-typing-addicts would runaway screaming. But I like it
I have some places in pyparsing where I've found that the most
straightforward way to adjust an instance's behavior is to change its class.
I do this by assigning to self.__class__, and things all work fine.
(Converting to use of __new__ is not an option - in one case, the change is
Jeff Shannon wrote:
> class __Foo:
> "I am a singleton!"
> pass
>
> def Foo(foo_obj = __Foo()):
> assert isinstance(foo_obj, __Foo
> return foo_obj
this is a bit simpler, I think, and takes advantage from Python's free
name-rebinding.
class Singleton(object):
def __call__(s
Marc 'BlackJack' Rintsch wrote:
Frans Englich wrote:
Then I have some vague, general questions which perhaps someone can reason
from: what is then the preferred methods for solving problems which requires
Singletons?
As already mentioned it's similar to a global variable. If I need a
"Singleton"
In <[EMAIL PROTECTED]>, Frans Englich
wrote:
> Then I have some vague, general questions which perhaps someone can reason
> from: what is then the preferred methods for solving problems which requires
> Singletons?
As already mentioned it's similar to a global variable. If I need a
"Singleton"
"Frans Englich" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On Monday 17 January 2005 20:03, John Roth wrote:
"Frans Englich" <[EMAIL PROTECTED]> wrote in message
In other words, you're trying to create a singleton. In general,
singletons are frowned on these days for a number of
On Monday 17 January 2005 21:24, Peter Otten wrote:
> Frans Englich wrote:
> > On Monday 17 January 2005 20:03, John Roth wrote:
> >> "Frans Englich" <[EMAIL PROTECTED]> wrote in message
> >
> >
> >
> >> In other words, you're trying to create a singleton. In general,
> >> singletons are frowned o
Frans Englich wrote:
> On Monday 17 January 2005 20:03, John Roth wrote:
>> "Frans Englich" <[EMAIL PROTECTED]> wrote in message
>
>
>
>> In other words, you're trying to create a singleton. In general,
>> singletons are frowned on these days for a number of reasons,
>> not least because of the
Frans Englich wrote:
>> > >>> class Foo(object):
>> >
>> > ... cache = {}
>> > ... def __new__(cls, id):
>> > ... try:
>> > ... return cls.cache[id]
>> > ... except KeyError:
>> > ... pass
>> > ... cls.cache[id] =
On Monday 17 January 2005 20:03, John Roth wrote:
> "Frans Englich" <[EMAIL PROTECTED]> wrote in message
> In other words, you're trying to create a singleton. In general,
> singletons are frowned on these days for a number of reasons,
> not least because of the difficulty of testing them.
Then
On Monday 17 January 2005 20:55, Frans Englich wrote:
> On Monday 17 January 2005 19:02, Peter Otten wrote:
> > Frans Englich wrote:
> > > What the code attempts to do is implementing a, to the API user,
> > > transparent memory-saver by ensuring that no more than one instance of
> > > the class fo
On Monday 17 January 2005 19:02, Peter Otten wrote:
> Frans Englich wrote:
> > What the code attempts to do is implementing a, to the API user,
> > transparent memory-saver by ensuring that no more than one instance of
> > the class foo exists for a particular id. E.g, the user can simply
> > "crea
"Frans Englich" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello,
[...]
What the code attempts to do is implementing a, to the API user,
transparent
memory-saver by ensuring that no more than one instance of the class foo
exists for a particular id. E.g, the user can simply "crea
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> An implementation of what you want can be found here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558
>
I think this recipe pre-dates the introduction of __new__ in Python.
How about something like this (requires the nam
Frans Englich wrote:
> Hello,
>
> I am having trouble with throwing class instances around. Perhaps I'm
> approaching my goals with the wrong solution, but here's nevertheless a
> stripped down example which demonstrates my scenario:
>
> #
Frans Englich wrote:
> What the code attempts to do is implementing a, to the API user,
> transparent memory-saver by ensuring that no more than one instance of the
> class foo exists for a particular id. E.g, the user can simply "create" an
> instance and if one not already exists, it is created.
Frans Englich wrote:
Hello,
I am having trouble with throwing class instances around. Perhaps I'm
approaching my goals with the wrong solution, but here's nevertheless a
stripped down example which demonstrates my scenario:
[snip]
The basic problem seems to be that you're trying to avoid creat
An implementation of what you want can be found here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558
--
http://mail.python.org/mailman/listinfo/python-list
On Monday 17 January 2005 18:45, Frans Englich wrote:
> The line 'self = me'(scary..) doesn't really
> work for the attribute attr; the attribute exists on line 21, but it fails
> when yo() tries to access it.
Typo; line 21 is yo(). I ment line 18, the print statement in __init__.
Cheers,
Hello,
I am having trouble with throwing class instances around. Perhaps I'm
approaching my goals with the wrong solution, but here's nevertheless a
stripped down example which demonstrates my scenario:
#--
23 matches
Mail list logo