Re: Can self crush itself?

2009-11-30 Thread n00m
Why would you want to do that in the first place? I don't know... :-) As Schoepenhauer put it: The man can do what he wants to do but he can't want to want what he wants to do -- http://mail.python.org/mailman/listinfo/python-list

Re: Can self crush itself?

2009-11-30 Thread n00m
Ok ok Of course, it's a local name; -- just my silly slip. And seems it belongs to no dict[]... Just an internal volatile elf -- http://mail.python.org/mailman/listinfo/python-list

Re: Can self crush itself?

2009-11-26 Thread Francesco Guerrieri
On Thu, Nov 26, 2009 at 8:04 AM, Gregory Ewing greg.ew...@canterbury.ac.nzwrote: n00m wrote: I can't understand why we can get __name__, but not __dict__, on the module level? For much the same reason that you can see your own feet but (unless you look in a mirror) you can't see your

Re: Can self crush itself?

2009-11-26 Thread Lie Ryan
n00m wrote: Ok ok Of course, it's a local name; -- just my silly slip. And seems it belongs to no dict[]... Just an internal volatile elf Local names are not implemented as dict, but rather as sort of an array in the compiler. The name resolution of locals is compile time and doesn't use

Re: Can self crush itself?

2009-11-26 Thread Aahz
In article 7ace3de0-4588-4b7d-9848-d97298717...@z41g2000yqz.googlegroups.com, n00m n...@narod.ru wrote: Or just raise an exception in __init__(),.. Then we are forced to handle this exception outside of class code. Absolutely! That's the whole point. If you can't construct the class, you

Re: Can self crush itself?

2009-11-25 Thread n00m
Then how can we destroy the 3rd instance, right after its creation and from inside class Moo code? class Moo: cnt = 0 def __init__(self, x): self.x = x self.__class__.cnt += 1 if self.__class__.cnt 2: print id(self) ## 13406816

Re: Can self crush itself?

2009-11-25 Thread Chris Rebert
On Wed, Nov 25, 2009 at 1:46 AM, n00m n...@narod.ru wrote: Then how can we destroy the 3rd instance, right after its creation and from inside class Moo code? Why would you want to do that in the first place? It's strange to say the least. If you want to prevent an instance being created in the

Re: Can self crush itself?

2009-11-25 Thread Ben Finney
n00m n...@narod.ru writes: Then how can we destroy the 3rd instance, right after its creation and from inside class Moo code? Normally, one binds whatever references one needs, and lets the garbage collector clean them up once they fall out of scope. If the references are living beyond their

Re: Can self crush itself?

2009-11-25 Thread Aahz
In article mailman.965.1259143133.2873.python-l...@python.org, Chris Rebert c...@rebertia.com wrote: If you want to prevent an instance being created in the first place, you can override __new__(). Or just raise an exception in __init__(), which I think is more common practice. -- Aahz

Re: Can self crush itself?

2009-11-25 Thread n00m
Or just raise an exception in __init__(),.. Then we are forced to handle this exception outside of class code. It's Ok. Never mind. Next thing. I can't understand why we can get __name__, but not __dict__, on the module level? print __name__ print __dict__

Re: Can self crush itself?

2009-11-25 Thread Terry Reedy
n00m wrote: Or just raise an exception in __init__(),.. Then we are forced to handle this exception outside of class code. It's Ok. Never mind. Next thing. I can't understand why we can get __name__, but not __dict__, on the module level? print __name__ print __dict__

Re: Can self crush itself?

2009-11-25 Thread Steven D'Aprano
On Wed, 25 Nov 2009 20:09:25 -0500, Terry Reedy wrote: n00m wrote: Or just raise an exception in __init__(),.. Then we are forced to handle this exception outside of class code. It's Ok. Never mind. Next thing. I can't understand why we can get __name__, but not

Re: Can self crush itself?

2009-11-25 Thread n00m
aaah... globals()... Then why self not in globals()? class Moo: cnt = 0 def __init__(self, x): self.__class__.cnt += 1 if self.__class__.cnt 3: self.x = x else: print id(self) for item in globals().items():

Re: Can self crush itself?

2009-11-25 Thread Steven D'Aprano
On Wed, 25 Nov 2009 18:39:09 -0800, n00m wrote: aaah... globals()... Then why self not in globals()? class Moo: cnt = 0 def __init__(self, x): self.__class__.cnt += 1 Because it isn't a global, it's a local -- it is defined inside a class. Inside functions and classes,

Re: Can self crush itself?

2009-11-25 Thread Mel
n00m wrote: aaah... globals()... Then why self not in globals()? class Moo: cnt = 0 def __init__(self, x): self.__class__.cnt += 1 if self.__class__.cnt 3: self.x = x else: print id(self) for item in

Re: Can self crush itself?

2009-11-25 Thread Gregory Ewing
n00m wrote: I can't understand why we can get __name__, but not __dict__, on the module level? For much the same reason that you can see your own feet but (unless you look in a mirror) you can't see your own eyes. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Can self crush itself?

2009-11-24 Thread n00m
Why does h instance stay alive? class Moo: cnt = 0 def __init__(self, x): self.x = x self.__class__.cnt += 1 if self.__class__.cnt 2: self.crush_me() def crush_me(self): print 'Will self be crushed?' self = None f = Moo(1) g =

Re: Can self crush itself?

2009-11-24 Thread Ben Finney
n00m n...@narod.ru writes: def crush_me(self): print 'Will self be crushed?' self = None As with any function, the parameter is bound to a *local* name, in this case the name ‘self’. Whatever you rebind ‘self’ to inside the function, the binding is lost once the function

Re: Can self crush itself?

2009-11-24 Thread n00m
Whatever you rebind ‘self’ to inside the function... Seems you are right! Thanks, Ben, for the lesson :-) class Moo: cnt = 0 def __init__(self, x): self.x = x self.__class__.cnt += 1 if self.__class__.cnt 2: self.crush_me() def crush_me(self):