[Pythonmac-SIG] Transparent methods (and more) in Python...

Jack Jansen Jack.Jansen@cwi.nl
Wed, 5 Feb 2003 11:48:01 +0100


On Wednesday, Feb 5, 2003, at 01:16 Europe/Amsterdam, JR wrote:

> Python linguists and MacPython geeks,
>
> I have a few questions that my books and experience aren't answering...
>
> 1) If I override __del__ will Python's (normal) garbage collection et 
> al.
> *still* go off behind it or (since I'm overriding) am I then 
> responsible for
> manually triggering it.  If the later, how does one do so (I saw 
> something
> about some "super.blah" notation but haven't digested that just yet)?

This should be in the books (at least, in the better books:-) but it 
may be hard to find.
Providing an __del__ does *not* alter the normal behaviour of garbage 
collection. Your
method is simply called just before the object goes away. And: you can 
revive the object if
you want, as you can see by running the following code:
stash = None

class Stasher:
         def __del__(self):
                 global stash
                 print "About to be deleted:", self
                 stash = self

stash = Stasher()
stash = None
stash = None
stash = None

> 2) Is there an elegant method of loading CLI args into sys.args in 
> MacPython
> (not MachO Python) in OS X without employing Apple Events?

I'm not sure what you mean, but maybe EasyDialogs.GetArgv() is what you 
want?
It allows the user to specify a sys.argv-like list of arguments.

> 3) Is there a transparent assignment op I can override (i.e., the 
> equivalent
> of what might call __=__ ... no not __eq__)?  If not, is there a brief
> synopsis that describes why the language (seemingly ... at least from 
> my
> mental vantage point) cannot support he same?

This is more a c.l.p question, but anyway: this can't be done in 
Python, because
assignment in Python is different from assignment in C and such. In 
Python it is
only the binding of a name, not the assignment of a variable.

In other words: if you do "i = 1+1" then the interpreter first takes 
the two objects
"1" and "1", adds them giving a new object and finally increments the 
refcount on that
new object and stores a reference in the local variable "i". So 
assignment isn't really
an operator in Python.
--
Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman