[Edu-sig] Natural Language Programming

Tim Peters tim.one@home.com
Wed, 10 Jan 2001 19:09:20 -0500


I'm gonna skip all the *interesting* stuff and get straight to the technical
Python nit <wink>:

[Kirby Urner]
> ...
> PS:  In Python, don't forget that you can just define synonyms.
> Like, if your Vector object has a translate(self,v) method (mine
> does), feel free to write:
>
>        def move(self,v):
>            return self.translate(v)

Too hard!  It's enough to do

         move = translate

inside the class body, after the "translate" method has been defined.
Example:

class C:
    def hifalutin_offputting_name(self, arg):
        print arg

    plainfolks_friendly_name = hifalutin_offputting_name

C().plainfolks_friendly_name(42)


prints 42.

> And you could define resize() as an alternative to scale().

No, I'm afraid that one isn't allowed <wink>.  Oh, all right, it is.

You can actually have any executable code whatsoever in a class body.  At
the end of the class body, whatever is sitting in the class's local
namespace becomes the content of the class __dict__.  And this is why
assignment works just as well as a "def" to define a method in the class.

sometimes-the-chisel-is-as-surprisingly-interesting-as-the-
    sculpture<wink>-ly y'rs  - tim