[Edu-sig] Version 0.2.03 of PataPata released (adds Jython/Swing support)

kirby urner kirby.urner at gmail.com
Tue Aug 8 16:48:34 CEST 2006


On 8/8/06, Arthur <ajsiegel at optonline.net> wrote:

> What you haven't said in your reference here and before to Martelli's
> post about Ruby and the relevance of it to properties is that it was I
> who pointed you to it, and specifically because you had pointed to the
> authority of Martelli's Nutshell for your interpretation of the intent
> of properties, and I felt that Martelli's post about Ruby was some
> authority for the fact that you were misinterpreting him.
>
> Art

Yes, you pointed me to it.

Relevant to this discussion I think because he points out the two ways
of mentioning a function in Python:

(1) without parentheses, in which case it refers you to its type and
location (but it doesn't actually *do* anything at that point)

(2) with parentheses, in which case you're invoking it to do its work (job)

>>> class Quirky:
	def __init__(me, a='a'):
		me.val = a
	def somefunkyfunction(me_or_should_I_say_self):
		print me_or_should_I_say_self.val

			
>>> thething = Quirky() # __init__
>>> thething.somefunkyfunction
<bound method Quirky.somefunkyfunction of <__main__.Quirky instance at
0x00D04198>>
>>> Quirky.somefunkyfunction
<unbound method Quirky.somefunkyfunction>
>>> thething.somefunkyfunction()
a

Paul seems to find this confusing, i.e. he doesn't like that functions
become like inert properties (attributes, fields) if you forget to
invoke them.  They tell you who they are.

The issue of whether wrapping functions to look like properties is
moral and wholesome is more what I thought you and I were
investigating.  I assumed you felt not, that this was signature of
Java's moral corruption invading pristine Python.  I argued the need
on purely practical grounds, suggesting we needn't worry about
morality at this low level.

For those on edu-sig who may be learning Python:  the builtin property
function wraps setter and getter functions to make them accessible
through obj.x syntax i.e. you'll be triggering callables in setting
and/or getting x.

You could think of this as "moderation" as in "moderated group."
There's some coded oversight or bureaucracy in the system, not
necessarily visible to the casual reader, that your use of the objects
may trigger behind the scenes (e.g. a moderator will get your post to
her inbox, and have to approve it before it goes into the permanent
archive).

However, this behavior is not really new with the property syntax.
Python had already long supported such as __getattr__ and (later)
__getattribute__ (new-style classes), meaning property syntax has
always had the ability to trigger code.

This PEP goes over some of the relevant design level thinking, however
refers to a proposal that has not actually been implemented
http://www.python.org/dev/peps/pep-0213/

Kirby


More information about the Edu-sig mailing list