Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30316 > unrolled thread
| Started by | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| First post | 2012-09-27 17:20 +0000 |
| Last post | 2012-09-27 17:20 +0000 |
| Articles | 1 — 1 participant |
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 "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-27 17:20 +0000
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| Date | 2012-09-27 17:20 +0000 |
| Subject | RE: Capitalization for variable that holds a class |
| Message-ID | <mailman.1505.1348767725.27098.python-list@python.org> |
Dennis Lee Bieber wrote: > Sent: Sunday, September 23, 2012 11:53 AM > To: python-list@python.org > Subject: Re: Capitalization for variable that holds a class > > On Sun, 23 Sep 2012 16:48:38 +0100, Joshua Landau > <joshua.landau.ws@gmail.com> declaimed the following in > gmane.comp.python.general: > > > Simple question: > > > > [myClass() for myClass in myClasses] > > vs > > [MyClass() for MyClass in myClasses] > > > > The recommended naming scheme for Python is that class DEFINITIONS > begin capitalized. Instances, methods/attributes, functions begin > lowercase. > > I abstain from the argument about camel-case vs _ (Ada "pretty > printers" automatically capitalize at _, so _ is common in Ada) > > class MyClass(object): > def myMethod(self): Are you (the OP) using Python 2 or 3? In python 2 list comprehensions leak; if you use MyClass as the list comprehension variable name it will overwrite the MyClass class definition (if it exists). >>> class MyClass(object): ... pass ... >>> print MyClass <class '__pieshell__.MyClass'> >>> _ = [ MyClass for MyClass in xrange( 5 ) ] >>> print MyClass 4 Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.
Back to top | Article view | comp.lang.python
csiph-web