471,330 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

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?
Jan 7 '08 #1
13 987
MartinRinehart wrote:
Anything written somewhere that's thorough? Any code body that should
serve as a reference?
http://www.python.org/dev/peps/pep-0008/
Jan 7 '08 #2
2008/1/7, Ma************@gmail.com <Ma************@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/pep-0008/
--
http://mail.python.org/mailman/listinfo/python-list

--
-- Guilherme H. Polo Goncalves
Jan 7 '08 #3
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 ']'?
Jan 7 '08 #4
Ma************@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>

Jan 7 '08 #5
2008/1/7, Ma************@gmail.com <Ma************@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 =)
--
http://mail.python.org/mailman/listinfo/python-list

--
-- Guilherme H. Polo Goncalves
Jan 7 '08 #6


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).
Jan 7 '08 #7
ajaksu <aj****@gmail.comwrites:
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
Jan 8 '08 #8
On 1/7/08, Guilherme Polo <gg****@gmail.comwrote:
2008/1/7, Ma************@gmail.com <Ma************@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_words_with_underscore,
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.

--
ma****@librador.com
http://www.librador.com
Jan 8 '08 #9
Martin Vilcans wrote:
On 1/7/08, Guilherme Polo <gg****@gmail.comwrote:
>2008/1/7, Ma************@gmail.com <Ma************@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_words_with_underscore,
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.

Jan 8 '08 #10
On Jan 8, 2008 12:35 PM, Martin Vilcans <ma****@librador.comwrote:
On 1/7/08, Guilherme Polo <gg****@gmail.comwrote:
2008/1/7, Ma************@gmail.com <Ma************@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_words_with_underscore,
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***************@gmail.com>
Jan 8 '08 #11
<Ma************@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-
Jan 8 '08 #12


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.
Jan 9 '08 #13
Ma************@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
Jan 10 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by beliavsky | last post: by
41 posts views Thread by Richard James | last post: by
39 posts views Thread by jamilur_rahman | last post: by
17 posts views Thread by seb.haase | last post: by
12 posts views Thread by Steve Howell | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.