Capitalization for variable that holds a class

Joshua Landau joshua.landau.ws at gmail.com
Thu Sep 27 17:53:13 EDT 2012


On 27 September 2012 18:20, Prasad, Ramit <ramit.prasad at jpmorgan.com> wrote:

> Dennis Lee Bieber wrote:
> > Sent: Sunday, September 23, 2012 11:53 AM
> > To: python-list at 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 at 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
>

Don't worry, not only am I using Python 3 but I would be certain to use
GenericUnusedClassName anyway ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120927/135bfc27/attachment.html>


More information about the Python-list mailing list