RE: Capitalization for variable that holds a class

Discussion in 'Python' started by Prasad, Ramit, Sep 27, 2012.

  1. Dennis Lee Bieber wrote:

    > Sent: Sunday, September 23, 2012 11:53 AM
    > To:
    > Subject: Re: Capitalization forvariable that holds a class
    >
    > On Sun, 23 Sep 2012 16:48:38 +0100, Joshua Landau
    > <> 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 ofinformation, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Sep 27, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    403
  2. Jim Freeze

    Instance variable capitalization

    Jim Freeze, Feb 20, 2004, in forum: Ruby
    Replies:
    7
    Views:
    154
    Robert Klemme
    Feb 23, 2004
  3. Chris Angelico
    Replies:
    1
    Views:
    191
    Steven D'Aprano
    Sep 23, 2012
  4. Dennis Lee Bieber
    Replies:
    0
    Views:
    177
    Dennis Lee Bieber
    Sep 23, 2012
  5. Tim Chase
    Replies:
    0
    Views:
    202
    Tim Chase
    Sep 23, 2012
Loading...

Share This Page