[ANN] markup.py - 1.2 - an HTML/XML generator

Peter Hansen peter at engcorp.com
Mon Apr 3 21:39:51 EDT 2006


Felipe Almeida Lessa wrote:
> $ pwd
> /usr/lib/python2.4/site-packages
> $ grep -re klass . | wc -l
> 274
> $ grep -re class_ . | wc -l
> 897

How many of those "class_" instances are really just substrings of 
"__class__" and "class_name" and such?  On my machine, I see a handful 
in the standard library, and _none_ in site-packages (which has only 
1709 .py files, mind you).

> For me that's enough. "class_" is used at least three times more than
> "klass". Besides, as Scott pointed out, "class_" is prefered by the
> guidelines too.

Actually what he posted explicitly states that "cls" is preferred. 
Following that it says that one should considering appending _ if the 
name conflicts with a keyword (and one can assume it means "for all 
keywords other than class").

>>`cls`, at least, is more commonly used within 
>>Python itself (e.g., classmethods).
> 
> Yes. cls wouldn't be a good choice. But class_ is. Or maybe even
> css_class. But klass isn't.

As has been pointed out, klass has a fairly established tradition of 
use.  (I happen to agree with the PEP and use "cls" exclusively for such 
things, and do agree that "klass" is crude.)

-Peter




More information about the Python-list mailing list