ISEexchange / Python-Bootcamp

Discussion/Materials regarding the Python Bootcamp class
3 stars 7 forks source link

Style Guide for Python Code #6

Open jwasserzug opened 10 years ago

jwasserzug commented 10 years ago

http://legacy.python.org/dev/peps/pep-0008/

The Zen of Python

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!

- Tim Peters

@vraghunandan @bdambola @kwokman @dsapienza @DRozentsvay @gganeshan @cbautista1002 @xingj53 @wcorrea @rklotz @isehgu @akbamaa

jumanjiman commented 10 years ago

if you're looking at pep8, look here too: https://github.com/dgoodwin/tito/blob/master/test/unit/pep8-tests.py

Note that Python3 does not allow mixing tabs and spaces for indentation. http://docs.python.org/3.3/reference/lexical_analysis.html

You can force your editor to do the right thing by installing a plugin for your editor from http://editorconfig.org/#download

For example, add the EditorConfig plugin for vim like this:

cd /tmp/
wget https://github.com/editorconfig/editorconfig-vim/archive/master.zip
unzip master.zip
mkdir ~/.vim
cp -r editorconfig-vim-master/* ~/.vim/
cbautista1002 commented 10 years ago

Thanks @jumanjiman for those links. But just to let everyone know, we use Python 2 here at ISE. There are differences between Python 2 and Python 3 that could cause compatibility issues. So when working on Python stuff for ISE, please be sure to limit yourself to Python 2.

https://wiki.python.org/moin/Python2orPython3

jwasserzug commented 9 years ago

@shraykay