Capitalization for variable that holds a class

Chris Angelico rosuav at gmail.com
Sun Sep 23 12:12:25 EDT 2012


On Mon, Sep 24, 2012 at 1:48 AM, Joshua Landau
<joshua.landau.ws at gmail.com> wrote:
> Simple question:
>
> [myClass() for myClass in myClasses]
> vs
> [MyClass() for MyClass in myClasses]
>
> Fight.
>
> (When considering, substitute in a more real-world example like [Token() for
> Token in allTokens] or [token() for token in allTokens])

An interesting point! I assume you're basing this on the PEP 8 recommendation:
http://www.python.org/dev/peps/pep-0008/#class-names

Since there's no difference between a "class" and a "variable
containing a class" or a "pointer to a class" or any other such
concept, it makes sense to capitalize MyClass in your example, if you
are guaranteeing that they're all classes. And certainly a long-lived
variable ought to be named in CapWords. However, all you're really
doing is taking a bunch of callables, calling them, and making a list
of the results. I'd therefore be inclined to _not_ capitalize it. YMMV
though.

ChrisA



More information about the Python-list mailing list