Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29821

Re: Capitalization for variable that holds a class

References <CAN1F8qUxbhK8HqRr7RVUQreb2QkAsm+Y9q0LKR0eK1akYbNsLg@mail.gmail.com>
Date 2012-09-24 02:12 +1000
Subject Re: Capitalization for variable that holds a class
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1124.1348416749.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Sep 24, 2012 at 1:48 AM, Joshua Landau
<joshua.landau.ws@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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Capitalization for variable that holds a class Chris Angelico <rosuav@gmail.com> - 2012-09-24 02:12 +1000
  Re: Capitalization for variable that holds a class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-23 21:42 +0000

csiph-web