[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

I'm searching for Python style guidelines

Martin Rinehart

1/7/2008 1:26:00 PM

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?
18 Answers

Peter Otten

1/7/2008 1:33:00 PM

0

MartinRinehart wrote:

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

http://www.python.org/dev/peps...

Guilherme Polo

1/7/2008 1:35:00 PM

0

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
http://www.python.org/dev/peps...

> --
> http://mail.python.org/mailman/listinfo/p...
>


--
-- Guilherme H. Polo Goncalves

Martin Rinehart

1/7/2008 4:06:00 PM

0

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/articles/code-conven...
).

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 ']'?

Fredrik Lundh

1/7/2008 4:17:00 PM

0

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>

Guilherme Polo

1/7/2008 4:20:00 PM

0

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/articles/code-conven...
> ).
>
> 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 =)

> --
> http://mail.python.org/mailman/listinfo/p...
>


--
-- Guilherme H. Polo Goncalves

Martin Rinehart

1/7/2008 6:26:00 PM

0



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).

Paul McGuire

1/7/2008 6:33:00 PM

0

On Jan 7, 12:26 pm, MartinRineh...@gmail.com wrote:
> 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).

While not required by any means, you will also find it handy to follow
*every* entry in the list with a comma, even the last one in the list
(this is legal Python). That is, in your example:

foo = [
'too long',
'too long too',
'too long too',
'last item',
]

Later on when you want to reorder the items, then you can just copy/
paste whole lines, even if moving to or from the bottom of the list.
This is also a good argument for putting the closing ']' on its own
line, instead of on the same line as the last item.

-- Paul

ajaksu

1/8/2008 2:09:00 AM

0

On Jan 7, 11:25 am, MartinRineh...@gmail.com wrote:
> 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?

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).

Cogent project PCG
http://jaynes.colorado.edu/PythonGuide...
(also http://jaynes.colorado.edu/PythonI...)

Freevo Coding Standard
http://doc.freevo.org/Codi...

Mercurial Basic Coding Style
http://www.selenic.com/mercurial/wiki/index.cgi/Basic_Co...

PyBlosxom Coding Style Guide
http://pyblosxom.sourceforge.net/blog/static/developm...

MoinMoin Coding Style
http://moinmoin.wikiwikiweb.de/C...

Webware Style Guidelines
http://www.webwareforpython.org/Docs/StyleGuide...

NOAA Enhanced Forecaster Tools PCG
http://www-md.fsl.noaa.gov/eft/developer/PythonCodingStan...

BioPython Coding Conventions
http://biopython.org/wiki/Contributing#Coding_c...

Mnet PCG
http://mnet.sourceforge.net/coding_stan...

Michael Foord's (aka Voidspace) PCG
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_04_01....

SQLObject Coding Style
http://www.sqlobject.org/DeveloperGuide.html#s...

WxPython PCG
http://www.wxpython.org/codeguid...

Python coding style guide for Mailman
http://barry.warsaw.us/software/STYL...

VoiceCode PCG
http://voicecode.iit.nrc.ca/VoiceCode/uploads/codingGuide...

Bazaar Coding Stile Guidelines
http://doc.bazaar-vcs.org/bzr.dev/en/developer-guide/HACKING.html#coding-style-...

IPython Developer Guidelines
http://ipython.scipy.org/moin/Developer_Zone/Developer_...

OSAF Chandler PCG
http://chandlerproject.org/Projects/ChandlerCodingStyle...
(along with http://chandlerproject.org/Projects/ChandlerEpydoc...)

Twisted Coding Standard
http://twistedmatrix.com/trac/browser/trunk/doc/development/policy/coding-standard.xhtml?...

PyPy RPython and CPython Coding Guidelines
http://codespeak.net/pypy/dist/pypy/doc/coding-...

Django PCG (and general contribution recommendations)
http://www.djangoproject.com/documentation/contributing/#co...

Docutils PCG
http://docutils.sourceforge.net/docs/dev/policies.html#python-coding-c...

Trac Coding Style
http://trac.edgewall.org/wiki/TracDev/C...

OLPC PCG
http://wiki.laptop.org/go/Python_S...

Skeletonz Coding and Naming Conventions
http://orangoo.com/skeletonz/Developer_guide/Coding_c...
http://orangoo.com/skeletonz/Developer_guide/Naming_c...

CherryPy Code Conventions
http://www.cherrypy.org/wiki/CodeC...

More generic but still good (or great) insights:
Software Carpentry on style http://www.swc.scipy.org/lec/...
Zope's Coding Style http://wiki.zope.org/zope3/C...
The docstrings PEP http://www.python.org/dev/peps...



The NiceStyle Triad®:
Pyflakes http://divmod.org/trac/wiki/Divm...
PyChecker http://pychecker.source...
Pylint http://www.logil...



Do you think this could be a valuable addition to the Python wiki?

HTH,
Daniel

Ben Finney

1/8/2008 9:21:00 AM

0

ajaksu <ajaksu@gmail.com> writes:

> 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

G F

1/8/2008 9:35:00 AM

0

On Jan 8, 3:08 am, ajaksu <aja...@gmail.com> wrote:
> On Jan 7, 11:25 am, MartinRineh...@gmail.com wrote:
>
> > Anything written somewhere that's thorough? Any code body that should
> > serve as a reference?
>
> 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).

[...]

>
> Do you think this could be a valuable addition to the Python wiki?
>

+1, absolutely

Here's the list in rest format:

------------------------------
FOSS Projects Style Guidelines
------------------------------

`Cogent project PCG`__

... _Cogent PCG: http://jaynes.colorado.edu/PythonGuide...

__ `Cogent PCG`_

`Cogent project Python Idioms`__

... _Cogent Idioms: http://jaynes.colorado.edu/PythonI...

__ `Cogent Idioms`_

`Freevo Coding Standard`__

... _Freevo PCG: http://doc.freevo.org/Codi...

__ `Freevo PCG`_

`Mercurial Basic Coding Style`__

... _Mercurial PCG: http://www.selenic.com/mercurial/wiki/index.cgi/Basic_Co...

__ `Mercurial PCG`_

`PyBlosxom Coding Style Guide`__

... _PyBlosxom PCG: http://pyblosxom.sourceforge.net/blog/static/developm...

__ `PyBlosxom PCG`_

`MoinMoin Coding Style`__

... _MoinMoin PCG: http://moinmoin.wikiwikiweb.de/C...

__ `MoinMoin PCG`_

`Webware Style Guidelines`__

... _Webware PCG: http://www.webwareforpython.org/Docs/StyleGuide...

__ `Webware PCG`_

`NOAA Enhanced Forecaster Tools PCG`__

... _NOAA PCG: http://www-md.fsl.noaa.gov/eft/developer/PythonCodingStan...

__ `NOAA PCG`_

`BioPython Coding Conventions`__

... _BioPython PCG: http://biopython.org/wiki/Contributing#Coding_c...

__ `BioPython PCG`_

`Mnet PCG`__

... _Mnet PCG: http://mnet.sourceforge.net/coding_stan...

__ `Mnet PCG`_

`Michael Foord's (aka Voidspace) PCG`__

... _Michael PCG: http://www.voidspace.org.uk/python/weblog/arch_d7_2006_04_01....

__ `Michael PCG`_

`SQLObject Coding Style`__

... _SQLObject PCG: http://www.sqlobject.org/DeveloperGuide.html#s...

__ `SQLObject PCG`_

`WxPython PCG`__

... _WxPython PCG: http://www.wxpython.org/codeguid...

__ `WxPython PCG`_

`Mailman PCG`__

... _Mailman PCG: http://barry.warsaw.us/software/STYL...

__ `Mailman PCG`_

`VoiceCode PCG`__

... _VoiceCode PCG: http://voicecode.iit.nrc.ca/VoiceCode/uploads/codingGuide...

__ `VoiceCode PCG`_

`Bazaar Coding Style Guidelines`__

... _Bazaar PCG: http://doc.bazaar-vcs.org/bzr.dev/en/developer-guide/HACKING.html#coding-style...

__ `Bazaar PCG`_

`IPython Developer Guidelines`__

... _IPython PCG: http://ipython.scipy.org/moin/Developer_Zone/Developer_...

__ `IPython PCG`_

`OSAF Chandler PCG`__

... _OSAF PCG: http://chandlerproject.org/Projects/ChandlerCodingStyle...

__ `OSAF PCG`_

`OSAF Chandler Epydoc Style Guide`__

... _OSAF Epydoc: http://chandlerproject.org/Projects/ChandlerEpydoc...

__ `OSAF Epydoc`_

`Twisted Coding Standard`__

... _Twisted PCG: http://twistedmatrix.com/trac/browser/trunk/doc/development/policy/coding-standard.xhtml?...

__ `Twisted PCG`_

`PyPy RPython and CPython Coding Guidelines`__

... _PyPy PCG: http://codespeak.net/pypy/dist/pypy/doc/coding-...

__ `PyPy PCG`_

`Django PCG`__

... _Django PCG: http://www.djangoproject.com/documentation/contributing/#co...

__ `Django PCG`_

`Docutils PCG`__

... _Docutils PCG: http://docutils.sourceforge.net/docs/dev/policies.html#python-coding-c...

__ `Docutils PCG`_

`Trac Coding Style`__

... _Trac PCG: http://trac.edgewall.org/wiki/TracDev/C...

__ `Trac PCG`_

`OLPC PCG`__

... _OLPC PCG: http://wiki.laptop.org/go/Python_S...

__ `OLPC PCG`_

`Skeletonz Coding and Naming Conventions`__

... _Skeletonz PCG: http://orangoo.com/skeletonz/Developer_guide/Coding_c...

__ `Skeletonz PCG`_

`CherryPy Code Conventions`__

... _CherryPy PCG: http://www.cherrypy.org/wiki/CodeC...

__ `CherryPy PCG`_

`Software Carpentry on style`__

... _Software Carpentry PCG: http://www.swc.scipy.org/lec/...

__ `Software Carpentry PCG`_

`Zope's Coding Style`__

... _Zope PCG: http://wiki.zope.org/zope3/C...

__ `Zope PCG`_

`The docstrings PEP`__

... _docstrings: http://www.python.org/dev/peps...

__ `docstrings`_

`Pyflakes`__

... _Pyflakes: http://divmod.org/trac/wiki/Divm...

__ `Pyflakes`_

`PyChecker`__

... _PyChecker: http://pychecker.source...

__ `PyChecker`_

`Pylint`__

... _Pylint: http://www.logil...

__ `Pylint`_