Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29821 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2012-09-24 02:12 +1000 |
| Last post | 2012-09-23 21:42 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-09-24 02:12 +1000 |
| Subject | Re: Capitalization for variable that holds a class |
| Message-ID | <mailman.1124.1348416749.27098.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-09-23 21:42 +0000 |
| Message-ID | <505f823f$0$1612$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #29821 |
On Mon, 24 Sep 2012 02:12:25 +1000, Chris Angelico wrote: > 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. The difference is in the programmer's intention. I would go with: [aclass() for aclass in MyClasses] to emphasise that aclass is intended as a temporary loop variable and not a long-lasting class definition. So I guess I'm agreeing with Chris. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web