Favorite non-python language trick?

James Stroud jstroud at mbi.ucla.edu
Sat Jun 25 21:44:12 EDT 2005



On Saturday 25 June 2005 11:08 am, Steven D'Aprano wrote:
> The problem is, you have made colour (returning to English spelling
> instead of foreign) into a class. If you need two colour variables, you
> have to duplicate the code for the class (perhaps only changing the
> numeric constants. You can't even make instances from the class, because
> they all share the same RGB values, which is pretty useless if they are
> meant to represent different colours.

py> class color:
...   pass
...
py> def with(classname, **kwargs):
...   classname.__dict__.update(kwargs)
...
py> with(color, red=0,
...             blue=255,
...             green=255)
py>
py> color.blue
255

Is this what you want to do?

> > Also avoids those stupid little colons.
>
> Using := and = for assignment and equality is precisely as stupid as using
> = and == for assignment and equality. Perhaps less stupid: why do we use
> == for equals, but not ++ for plus and -- for minus?

The colons are to make it look more official or something. They are useless 
and hence stupid. The two equals signs for comparison could be argued to be 
redundant, but the colons are absolutely unecessary. I thought they were 
pointless 18 years ago when I learned pascal in highschool and after 20 
years, I still think they are still pointless.

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list