assignment hook

John Machin sjmachin at lexicon.net
Sat Sep 23 20:47:23 EDT 2006


Roy Smith wrote:
> paul.lafollette at gmail.com wrote:
> > Kind people,
> > Is there any way one can, within Python, intercept the act of
> > assignment.
>
> Sure.  You just need to define a __setattr__() method for your class.  See
> http://docs.python.org/ref/attribute-access.html for details.

Is it possible that at least one of you has the concepts of
"assignment" and "binding" a little mixed?

>
> > For instance, suppose that I was obsessed with
> > FORTRAN II, and decided that I wanted to print a warning,
> > or raise an exception any time someone assigned an int to a
> > variable whose name did not start with i,j,k,l,m, or n.
>
> Well, you know the old joke, "You can write Fortran in any language" :-)

Yes, but it's a bit difficult to express old FORTRAN jokes in another
language:

real = float
integer = int
assert isinstance(God, real) and isinstance(Jesus, integer)

Cheers,
John




More information about the Python-list mailing list