Howto MACRO in python ?
tismer at tismer.com
Wed Aug 13 19:34:09 CEST 2003
Bengt Richter wrote:
> maybe there ought to be a magic __self__ in the local namespace of a function?
> Or better yet (?;-) if a user-defined function were a subclass of type function
> instead of an instance, and a frame were an activation-instance of this function subclass,
> then frame.__class__.__dict__ would be the function __dict__, where you could find attributes.
I have similar thoughts, here, maybe simpler:
A frame is something like an instance of a function,
the function is somehow instantiated to be executed.
Unfortunately, on creation of a frame, the function
is "unpacked", in the sense that certain information
is used to parameterize the frame, but then the frame
has only the code object left.
This is probably so, because frames are created in
different context, like in the executable part of
a class, or when the code of a script is run.
There is no function, but there is a frame with a code
Maybe it makes sense to just add the function/method
to the code object as a new slot, which is either filled
or set to None?
I guess that not to do this was a decision from the
pre-GC time, where this would have been a really bad
Then we could grow a frame attribute like __callable__
which grabs the callable from the code object.
Maybe we should ask python-dev what they think.
ciao - chris
Christian Tismer :^) <mailto:tismer at tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Python-list