Install pip
PyPi, GitHub, or other VCSs
easy_install is a simple installer from PyPi. It comes with setuptools
setuptools has recently merged distribute, which was a fork of setuptools.
this versions is Py3k compatible.
Both are a library to build, package and install Python projects.
Install virtualenv
sudo pip install virtualenv
Use virtualenv
virtualenv venvs/pycourse
Create a new environment with different Python version:
which python3.3
/usr/local/bin/python3.3
virtualenv venvs/pycourse3.3 -p /usr/local/bin/python3.3
Enable the virtualenv
echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:...
source venvs/pycourse/bin/activate
echo $PATH
/Users/pev/venvs/pycourse/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:...
Disable the virtualenv:
deactivate
Use pip (inside virtualenvs)
pip freeze
wsgiref==0.1.2
pip search pep8
wsgiref==0.1.2
autopep8 - A tool that automatically formats Python code...
pep8 - Python style guide checker
pip install pep8
Downloading/unpacking pep8
Downloading pep8-1.4.5.tar.gz (63kB): 63kB downloaded
Running setup.py egg_info for package pep8
...
Successfully installed pep8
Cleaning up...
pip freeze
wsgiref==0.1.2
pep8==1.4.4
Install your project's requirements:
pip install -r requirements.txt
Create your project's requirements file:
pip freeze > requirements.txt
Use PEP8
Normally we accept 120 charactes per line (instead of 80)
You can run and check code style from console
pep8 --max-line-length=119 .
./file1.py:7:1: E302 expected 2 blank lines, found 1
./file1.py:9:5: E301 expected 1 blank line, found 0
./file2.py:11:5: E301 expected 1 blank line, found 0
./file2.py:13:1: W293 blank line contains whitespace
In [ ]:
def func(arg1, arg2=None):
'''This is the docstring of the function, explaining what it does
its arguments, its exceptions raised and its return value
It may be multiline or just a single line
'''
pass
class MyClass(object):
'''This is the docstring of the class, explaining what it does
'''
def method(self, arg1, arg2=None):
'''This is the docstring of the method, explaining what it does
'''
pass
In [ ]:
print func.__doc__
print
print MyClass.__doc__
print
print MyClass.method.__doc__ # Even you can access docstring
Use docstrings