I'm searching for Python style guidelines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MartinRinehart@gmail.com

    #1

    I'm searching for Python style guidelines

    There's a lot of dumb stuff out there. "Algorithms should be coded
    efficiently ..." Thanks, I'll keep that in mind.

    van Rossum's guidelines tend toward "pick something and stick to it"
    which is OK if you have enough experience to pick something Pythonic.
    I'm a relative newbie, not qualified to pick.

    Anything written somewhere that's thorough? Any code body that should
    serve as a reference?
  • Peter Otten

    #2
    Re: I'm searching for Python style guidelines

    MartinRinehart wrote:
    Anything written somewhere that's thorough? Any code body that should
    serve as a reference?
    This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.

    Comment

    • Guilherme Polo

      #3
      Re: I'm searching for Python style guidelines

      2008/1/7, MartinRinehart@ gmail.com <MartinRinehart @gmail.com>:
      There's a lot of dumb stuff out there. "Algorithms should be coded
      efficiently ..." Thanks, I'll keep that in mind.
      >
      van Rossum's guidelines tend toward "pick something and stick to it"
      which is OK if you have enough experience to pick something Pythonic.
      I'm a relative newbie, not qualified to pick.
      >
      Anything written somewhere that's thorough? Any code body that should
      serve as a reference?
      PEP 8
      This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.


      --
      -- Guilherme H. Polo Goncalves

      Comment

      • MartinRinehart@gmail.com

        #4
        Re: I'm searching for Python style guidelines

        Thank you both.

        Stupid me, went to Python.org and found Style Guidelines and thought
        that was the last word. Oh well.

        PEP 8 reminds me a lot of Sun's Java conventions, in ways I wish it
        didn't. The overall structure seems like a random list of topics and
        it omits a lot. For Java I went from Sun to other conventions to try
        to compile a meta-convention ( http://www.MartinRinehart.com/articl...nventions.html
        ).

        Here's just one of my questions:

        foo = [
        'some item, quite long',
        'more items, all demanding there own line as they are not short',
        ...

        Where would you put the closing ']'?

        Comment

        • Fredrik Lundh

          #5
          Re: I'm searching for Python style guidelines

          MartinRinehart@ gmail.com wrote:
          Here's just one of my questions:
          >
          foo = [
          'some item, quite long',
          'more items, all demanding there own line as they are not short',
          ...
          >
          Where would you put the closing ']'?
          on a line by itself, indented as your favourite Python editor indents it.

          </F>

          Comment

          • Guilherme Polo

            #6
            Re: I'm searching for Python style guidelines

            2008/1/7, MartinRinehart@ gmail.com <MartinRinehart @gmail.com>:
            Thank you both.
            >
            Stupid me, went to Python.org and found Style Guidelines and thought
            that was the last word. Oh well.
            >
            PEP 8 reminds me a lot of Sun's Java conventions, in ways I wish it
            didn't. The overall structure seems like a random list of topics and
            it omits a lot. For Java I went from Sun to other conventions to try
            to compile a meta-convention ( http://www.MartinRinehart.com/articl...nventions.html
            ).
            >
            Here's just one of my questions:
            >
            foo = [
            'some item, quite long',
            'more items, all demanding there own line as they are not short',
            ...
            >
            Where would you put the closing ']'?
            I would put ']' at a new line:

            foo = [
            'too long',
            'too long too',
            ...
            ]

            I don't really believe it should exist style guidelines for everything
            that is possible (or if it did I doubt it would matter), many/most
            people adapt the guidelines to fetch their own style. That is not
            really a problem if you are consistent during all the code, and if it
            is not too ugly as well =)

            --
            -- Guilherme H. Polo Goncalves

            Comment

            • MartinRinehart@gmail.com

              #7
              Re: I'm searching for Python style guidelines



              Guilherme Polo wrote:
              foo = [
              'too long',
              'too long too',
              ...
              ]
              OK, I'll put it there too, and it will be easy for us to read each
              other's code (at least in this particular).

              Comment

              • Ben Finney

                #8
                Re: I'm searching for Python style guidelines

                ajaksu <ajaksu@gmail.c omwrites:
                I've done this search before and it was very interesting, doing it
                again gave me new results that also seem valuable. Here's most of
                them (where PCG = Python Coding Guidelines).
                Thanks, this is an awesome list. It's good to have a variety of real
                examples when drafting a coding standard for a project.
                Do you think this could be a valuable addition to the Python wiki?
                Definitely!

                --
                \ "The most merciful thing in the world... is the inability of |
                `\ the human mind to correlate all its contents." -- Howard |
                _o__) Philips Lovecraft |
                Ben Finney

                Comment

                • Martin Vilcans

                  #9
                  Re: I'm searching for Python style guidelines

                  On 1/7/08, Guilherme Polo <ggpolo@gmail.c omwrote:
                  2008/1/7, MartinRinehart@ gmail.com <MartinRinehart @gmail.com>:
                  Anything written somewhere that's thorough? Any code body that should
                  serve as a reference?
                  >
                  PEP 8
                  http://www.python.org/dev/peps/pep-0008/
                  The problem with PEP 8 is that even code in the standard libraries
                  doesn't follow the recommendations regarding the naming of functions
                  for example. The recommendation is to_separate_wor ds_with_undersc ore,
                  but some code uses lowerCamelCase instead.

                  I tended to dislike the underscore convention, but after forcing
                  myself to use it for a while I'm starting to appreciate its beauty.

                  --
                  martin@librador .com

                  Comment

                  • Colin J. Williams

                    #10
                    Re: I'm searching for Python style guidelines

                    Martin Vilcans wrote:
                    On 1/7/08, Guilherme Polo <ggpolo@gmail.c omwrote:
                    >2008/1/7, MartinRinehart@ gmail.com <MartinRinehart @gmail.com>:
                    >>Anything written somewhere that's thorough? Any code body that should
                    >>serve as a reference?
                    >PEP 8
                    >http://www.python.org/dev/peps/pep-0008/
                    >
                    The problem with PEP 8 is that even code in the standard libraries
                    doesn't follow the recommendations regarding the naming of functions
                    for example. The recommendation is to_separate_wor ds_with_undersc ore,
                    but some code uses lowerCamelCase instead.
                    >
                    I tended to dislike the underscore convention, but after forcing
                    myself to use it for a while I'm starting to appreciate its beauty.
                    I've come to like lowerCamelCase and a
                    tab of 2.

                    A tab of 4 wastes more space than is
                    needed for the occasional heavy
                    indenting.

                    Colin W.

                    Comment

                    • Neil Cerutti

                      #11
                      Re: I'm searching for Python style guidelines

                      On Jan 8, 2008 12:35 PM, Martin Vilcans <martin@librado r.comwrote:
                      On 1/7/08, Guilherme Polo <ggpolo@gmail.c omwrote:
                      2008/1/7, MartinRinehart@ gmail.com <MartinRinehart @gmail.com>:
                      Anything written somewhere that's thorough? Any code body that should
                      serve as a reference?
                      PEP 8
                      http://www.python.org/dev/peps/pep-0008/
                      >
                      The problem with PEP 8 is that even code in the standard libraries
                      doesn't follow the recommendations regarding the naming of functions
                      for example. The recommendation is to_separate_wor ds_with_undersc ore,
                      but some code uses lowerCamelCase instead.
                      >
                      I tended to dislike the underscore convention, but after forcing
                      myself to use it for a while I'm starting to appreciate its beauty.
                      Conventions get broken when there's a good reason, e.g., elegant
                      looking "deque" instead of clumsy looking "Deque".

                      --
                      Neil Cerutti <mr.cerutti+pyt hon@gmail.com>

                      Comment

                      • Matthew Woodcraft

                        #12
                        Re: I'm searching for Python style guidelines

                        <MartinRinehart @gmail.comwrote :
                        A quick look (thorough analysis still required) shows that OLPC and
                        PyPy are, indeed, extensive standards.
                        one-laptop-per-child.html (olpc),74.3,,http://wiki.laptop.org/go/Python_Style_Guide
                        I think that's mostly PEP 8, with some notes added.

                        -M-

                        Comment

                        • MartinRinehart@gmail.com

                          #13
                          Re: I'm searching for Python style guidelines



                          Matthew Woodcraft wrote:
                          I think [the olpc guidlines are] mostly PEP 8, with some notes added.
                          Took a good look. You are absolutely correct.

                          PEP 8 is basically word processing text stuck between <preand </pre>
                          tags. OLPC is Wiki HTML. Good example of how the latter is a lot
                          bigger than the former, with little extra content.

                          Comment

                          • Caleb

                            #14
                            Re: I'm searching for Python style guidelines

                            MartinRinehart@ gmail.com wrote:
                            Anything written somewhere that's thorough? Any code body that should
                            serve as a reference?
                            1. Don't use tabs (use spaces).
                            2. Study "import this"
                            3. Use lists and dictionaries as much as you possibly can
                            4. Use comprehensions and generators as much as you possibly can
                            5. Use the standard library for everything you possibly can
                            6. As much as you possibly can, when starting a new project, postpone
                            setting up classes for everything (start with functions). In some
                            projects, you might never need the overhead at all.

                            It will be difficult to go far wrong regarding style if you do a lot of
                            what's in this list. This list is not mine. I jotted these points
                            down, but this information is continually repeated by the actual wise
                            people (not me) in this newsgroup.

                            Caleb

                            Comment

                            Working...