Merge pull request #125 from benregn/master

Source formatting
This commit is contained in:
Kenneth Reitz
2012-04-23 12:14:38 -07:00
22 changed files with 472 additions and 218 deletions
+31 -14
View File
@@ -63,7 +63,10 @@ order to do this, add the following lines to your `vimrc`::
TextMate
--------
"`TextMate <http://macromates.com/>`_ brings Apple's approach to operating systems into the world of text editors. By bridging UNIX underpinnings and GUI, TextMate cherry-picks the best of both worlds to the benefit of expert scripters and novice users alike."
"`TextMate <http://macromates.com/>`_ brings Apple's approach to operating
systems into the world of text editors. By bridging UNIX underpinnings and GUI,
TextMate cherry-picks the best of both worlds to the benefit of expert
scripters and novice users alike."
Sublime Text
------------
@@ -75,7 +78,8 @@ extraordinary features."
Sublime Text has excellent support for editing Python code and uses Python for
its plugin API.
`Sublime Text 2 <http://www.sublimetext.com/blog/articles/sublime-text-2-beta>`_ is currently in beta.
`Sublime Text 2 <http://www.sublimetext.com/blog/articles/sublime-text-2-beta>`_
is currently in beta.
IDEs
::::
@@ -83,7 +87,9 @@ IDEs
PyCharm / IntelliJ IDEA
-----------------------
`PyCharm <http://www.jetbrains.com/pycharm/>`_ is developed by JetBrains, also known for IntelliJ IDEA. Both share the same code base and most of PyCharm's features can be brought to IntelliJ with the free `Python Plug-In <http://plugins.intellij.net/plugin/?id=631/>`_.
`PyCharm <http://www.jetbrains.com/pycharm/>`_ is developed by JetBrains, also
known for IntelliJ IDEA. Both share the same code base and most of PyCharm's
features can be brought to IntelliJ with the free `Python Plug-In <http://plugins.intellij.net/plugin/?id=631/>`_.
Eclipse
@@ -95,24 +101,28 @@ The most popular Eclipse plugin for Python development is Aptana's
Komodo IDE
-----------
`Komodo IDE <http://www.activestate.com/komodo-ide>`_ is developed by ActiveState and is a commercial IDE for Windows, Mac
`Komodo IDE <http://www.activestate.com/komodo-ide>`_ is developed by
ActiveState and is a commercial IDE for Windows, Mac
and Linux.
Spyder
------
`Spyder <http://code.google.com/p/spyderlib/>`_ an IDE specifically geared toward working with scientific python libraries (namely `Scipy <http://www.scipy.org/>`_).
`Spyder <http://code.google.com/p/spyderlib/>`_ an IDE specifically geared
toward working with scientific python libraries (namely `Scipy <http://www.scipy.org/>`_).
Includes integration with pyflakes_, `pylint <http://www.logilab.org/857>`_,
and `rope <http://rope.sourceforge.net/>`_.
Spyder is open-source (free), offers code completion, syntax highlighting, class and function browser, and object inspection.
Spyder is open-source (free), offers code completion, syntax highlighting,
class and function browser, and object inspection.
WingIDE
-------
`WingIDE <http://wingware.com/>`_ a python specific IDE. Runs for Linux, Windows, and Mac (as an X11 application, which frustrates some Mac users).
`WingIDE <http://wingware.com/>`_ a python specific IDE. Runs for Linux,
Windows, and Mac (as an X11 application, which frustrates some Mac users).
Interpreter Tools
@@ -122,8 +132,10 @@ Interpreter Tools
virtualenv
----------
Virtualenv is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them.
It solves the "Project X depends on version 1.x but, Project Y needs 4.x" dilemma and keeps your global site-packages directory clean and manageable.
Virtualenv is a tool to keep the dependencies required by different projects
in separate places, by creating virtual Python environments for them.
It solves the "Project X depends on version 1.x but, Project Y needs 4.x"
dilemma and keeps your global site-packages directory clean and manageable.
`virtualenv <http://www.virtualenv.org/en/latest/index.html>`_ creates
a folder which contains all the necessary executables to contain the
@@ -195,7 +207,8 @@ control by adding it to the ignore list.
virtualenvwrapper
-----------------
`Virtualenvwrapper <http://pypi.python.org/pypi/virtualenvwrapper>`_ makes virtualenv a pleasure to use by wrapping the command line API with a nicer CLI.
`Virtualenvwrapper <http://pypi.python.org/pypi/virtualenvwrapper>`_ makes
virtualenv a pleasure to use by wrapping the command line API with a nicer CLI.
::
@@ -208,7 +221,8 @@ Put this into your `~/.bash_profile` (Linux/Mac) file:
$ export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
This will prevent your virtualenvs from relying on your (global) site packages directory, so that they are completely separate..
This will prevent your virtualenvs from relying on your (global) site packages
directory, so that they are completely separate..
Other Tools
:::::::::::
@@ -233,10 +247,12 @@ It provides following features:
IPython
-------
`IPython <http://ipython.org/>`_ provides a rich toolkit to help you make the most out of using Python interactively. Its main components are:
`IPython <http://ipython.org/>`_ provides a rich toolkit to help you make the
most out of using Python interactively. Its main components are:
* Powerful Python shells (terminal- and Qt-based).
* A web-based notebook with the same core features but support for rich media, text, code, mathematical expressions and inline plots.
* A web-based notebook with the same core features but support for rich media,
text, code, mathematical expressions and inline plots.
* Support for interactive data visualization and use of GUI toolkits.
* Flexible, embeddable interpreters to load into your own projects.
* Tools for high level and interactive parallel computing.
@@ -250,7 +266,8 @@ IPython
BPython
-------
`bpython <http://bpython-interpreter.org/>`_ is an alternative interface to the Python interpreter for Unix-like operating systems. It has the following features:
`bpython <http://bpython-interpreter.org/>`_ is an alternative interface to the
Python interpreter for Unix-like operating systems. It has the following features:
* In-line syntax highlighting.
* Readline-like autocomplete with suggestions displayed as you type.
+5 -2
View File
@@ -8,8 +8,11 @@ The Hitchhiker's Guide to Python!
Welcome to The Hitchhiker's Guide to Python. **DON'T PANIC!**
**This guide is currently under heavy development, and is mostly a skeleton at the moment.** If you'd like to help, `fork us on GitHub <https://github.com/kennethreitz/python-guide>`_!
**This guide is currently under heavy development, and is mostly a skeleton at
the moment.** If you'd like to help, `fork us on GitHub <https://github.com/kennethreitz/python-guide>`_!
This *opinionated* guide exists to provide both novice and expert Python developers a best-practice handbook to the installation, configuration, and usage of Python on a daily basis.
This *opinionated* guide exists to provide both novice and expert Python
developers a best-practice handbook to the installation, configuration, and
usage of Python on a daily basis.
.. include:: contents.rst.inc
+20 -9
View File
@@ -4,14 +4,17 @@ The Community
BDFL
----
Guido van Rossum, the creator of Python, is often referred to as the BDFL — the Benevolent Dictator For Life.
Guido van Rossum, the creator of Python, is often referred to as the BDFL — the
Benevolent Dictator For Life.
Python Software Foundation
--------------------------
The mission of the Python Software Foundation is to promote, protect, and advance the Python programming language, and to support and facilitate the growth of a diverse and international community of Python programmers.
The mission of the Python Software Foundation is to promote, protect, and
advance the Python programming language, and to support and facilitate the
growth of a diverse and international community of Python programmers.
`Learn More about the PSF <http://www.python.org/psf/>`_.
@@ -19,7 +22,8 @@ The mission of the Python Software Foundation is to promote, protect, and advanc
PEPs
----
PEPs are *Python Enhancement Proposals*. They describe changes to Python itself, or the standards around it.
PEPs are *Python Enhancement Proposals*. They describe changes to Python itself,
or the standards around it.
There are three different types of PEPs (as defined by `PEP1 <http://www.python.org/dev/peps/pep-0001/>`_):
@@ -27,7 +31,8 @@ There are three different types of PEPs (as defined by `PEP1 <http://www.python.
Describes a new feature or implementation.
**Informational**
Describes a design issue, general guidelines, or information to the community.
Describes a design issue, general guidelines, or information to the
community.
**Process**
Describes a process related to Python.
@@ -45,24 +50,28 @@ There are a few PEPs that could be considered required reading:
A list of 19 statements that briefly explain the philosophy behind Python.
- `PEP257 <http://www.python.org/dev/peps/pep-0257/>`_: Docstring Conventions.
Gives guidelines for semantics and conventions associated with Python docstrings.
Gives guidelines for semantics and conventions associated with Python
docstrings.
You can read more at `The PEP Index <http://www.python.org/dev/peps/>`_.
Submitting a PEP
~~~~~~~~~~~~~~~~
PEPs are peer-reviewed and accepted/rejected after much discussion. Anyone can write and submit a PEP for review.
PEPs are peer-reviewed and accepted/rejected after much discussion. Anyone
can write and submit a PEP for review.
Here's an overview of the PEP acceptance workflow:
.. image:: http://www.python.org/dev/peps/pep-0001/pep-0001-1.png
Python Conferences
Python Conferences
--------------------------
The major events for the Python community are developer conferences. The two most notable conferences are PyCon, which is held in the US, and its European sibling, EuroPython.
The major events for the Python community are developer conferences. The two
most notable conferences are PyCon, which is held in the US, and its European
sibling, EuroPython.
A comprehensive list of conferences is maintained `at pycon.org <http://www.pycon.org/>`_.
@@ -70,4 +79,6 @@ A comprehensive list of conferences is maintained `at pycon.org <http://www.pyco
Python User Groups
--------------------------
User Groups are where a bunch of Python developers meet to present or talk about Python topics of interest. A list of local user groups is maintained at the `Python Software Foundation Wiki <http://wiki.python.org/moin/LocalUserGroups>`_.
User Groups are where a bunch of Python developers meet to present or talk
about Python topics of interest. A list of local user groups is maintained at
the `Python Software Foundation Wiki <http://wiki.python.org/moin/LocalUserGroups>`_.
+2 -1
View File
@@ -13,7 +13,8 @@ The official Python Language and Library documentation can be found here:
Read the Docs
-------------
Read the Docs is a popular community project, providing a single location for all documentation of popular and even more exotic Python modules.
Read the Docs is a popular community project, providing a single location for
all documentation of popular and even more exotic Python modules.
`Read the Docs <http://readthedocs.org/>`_
+31 -22
View File
@@ -7,14 +7,18 @@ Beginner
Learn Python Interactive Tutorial
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learnpython.org is an easy non-intimidating way to get introduced to python. The website takes the same approach used on the popular `Try Ruby <http://tryruby.org/>`_ website, it has an interactive python interpreter built into the site that allows you to go through the lessons without having to install Python locally.
Learnpython.org is an easy non-intimidating way to get introduced to python.
The website takes the same approach used on the popular `Try Ruby <http://tryruby.org/>`_
website, it has an interactive python interpreter built into the site that
allows you to go through the lessons without having to install Python locally.
`Learn Python <http://www.learnpython.org/>`_
Learn Python the Hard Way
~~~~~~~~~~~~~~~~~~~~~~~~~
This is an excellent beginner programmer's guide to Python. It covers "hello world" from the console to the web.
This is an excellent beginner programmer's guide to Python. It covers "hello
world" from the console to the web.
`Learn Python the Hard Way <http://learnpythonthehardway.org/book/>`_
@@ -22,7 +26,8 @@ This is an excellent beginner programmer's guide to Python. It covers "hello wor
Crash into Python
~~~~~~~~~~~~~~~~~
Also known as *Python for Programmers with 3 Hours*, this guide gives experienced developers from other languages a crash course on Python.
Also known as *Python for Programmers with 3 Hours*, this guide gives
experienced developers from other languages a crash course on Python.
`Crash into Python <http://stephensugden.com/crash_into_python/>`_
@@ -30,8 +35,8 @@ Also known as *Python for Programmers with 3 Hours*, this guide gives experience
Dive Into Python 3
~~~~~~~~~~~~~~~~~~
Dive Into Python 3 is a good book for those ready to jump in to Python 3. It's a
good read if you are moving from Python 2 to 3 or if you already have some
Dive Into Python 3 is a good book for those ready to jump in to Python 3. It's
a good read if you are moving from Python 2 to 3 or if you already have some
experience programming in another language.
`Dive Into Python 3 <http://diveintopython3.ep.io/>`_
@@ -39,30 +44,33 @@ experience programming in another language.
Think Python: How to Think Like a Computer Scientist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Think Python attempts to give an introduction to basic concepts in computer science through the
use of the python language. The focus was to create a book with plenty of exercises, minimal jargon and
a section in each chapter devoted to the subject of debugging.
Think Python attempts to give an introduction to basic concepts in computer
science through the use of the python language. The focus was to create a book
with plenty of exercises, minimal jargon and a section in each chapter devoted
to the subject of debugging.
While exploring the various features available in the python language the author weaves in various design
patterns and best practices.
While exploring the various features available in the python language the
author weaves in various design patterns and best practices.
The book also includes several case studies which have the reader explore the topics discussed in the book
in greater detail by applying those topics to real-world examples. Case studies include assignments in GUI
and Markov Analysis.
The book also includes several case studies which have the reader explore the
topics discussed in the book in greater detail by applying those topics to
real-world examples. Case studies include assignments in GUI and Markov
Analysis.
`Think Python <http://greenteapress.com/thinkpython/html/index.html>`_
Python Koans
Python Koans
~~~~~~~~~~~~
Python Koans is a port of Edgecase's Ruby Koans. It uses a test-driven approach, q.v. TEST DRIVEN DESIGN SECTION
to provide an interactive
tutorial teaching basic python concepts. By fixing assertion statements that fail in a test script, this
provides sequential steps to learning python.
Python Koans is a port of Edgecase's Ruby Koans. It uses a test-driven
approach, q.v. TEST DRIVEN DESIGN SECTION to provide an interactive tutorial
teaching basic python concepts. By fixing assertion statements that fail in a
test script, this provides sequential steps to learning python.
For those used to languages and figuring out puzzles on their own, this can be a fun, attractive option.
For those new to python and programming, having an additional resource or reference will be helpful.
For those used to languages and figuring out puzzles on their own, this can be
a fun, attractive option. For those new to python and programming, having an
additional resource or reference will be helpful.
`Python Koans <http://bitbucket.org/gregmalcolm/python_koans>`_
@@ -102,5 +110,6 @@ References
Python in a Nutshell
~~~~~~~~~~~~~~~~~~~~
Python in a Nutshell, written by Alex Martelli, covers most cross-platform python's usage,
from its syntax to built-in libraries to advanced topics such as writing C extensions.
Python in a Nutshell, written by Alex Martelli, covers most cross-platform
python's usage, from its syntax to built-in libraries to advanced topics such
as writing C extensions.
+23 -9
View File
@@ -5,20 +5,29 @@ Continuous Integration
Why?
----
Martin Fowler, who first wrote about `Continuous Integration <http://martinfowler.com/articles/continuousIntegration.html>`_ (short: CI) together with Kent Beck, describes the CI as follows:
Martin Fowler, who first wrote about `Continuous Integration <http://martinfowler.com/articles/continuousIntegration.html>`_
(short: CI) together with Kent Beck, describes the CI as follows:
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.
Continuous Integration is a software development practice where members of
a team integrate their work frequently, usually each person integrates at
least daily - leading to multiple integrations per day. Each integration is
verified by an automated build (including test) to detect integration errors
as quickly as possible. Many teams find that this approach leads to
significantly reduced integration problems and allows a team to develop
cohesive software more rapidly.
Jenkins
-------
`Jenkins CI <http://jenkins-ci.org>`_ is an extensible continuous integration engine. Use it.
`Jenkins CI <http://jenkins-ci.org>`_ is an extensible continuous integration
engine. Use it.
Buildbot
--------
`Buildbot <http://buildbot.net/buildbot/docs/current>`_ is a Python system to automate the compile/test cycle to validate code changes.
`Buildbot <http://buildbot.net/buildbot/docs/current>`_ is a Python system to
automate the compile/test cycle to validate code changes.
Mule?
@@ -29,12 +38,17 @@ Mule?
Tox
---
`tox <https://bitbucket.org/hpk42/tox>`_ is an automation tool providing packaging, testing and deployment of Python software right from the console or CI server.
It is a generic virtualenv management and test command line tool which provides the following features:
`tox <https://bitbucket.org/hpk42/tox>`_ is an automation tool providing
packaging, testing and deployment of Python software right from the console or
CI server. It is a generic virtualenv management and test command line tool
which provides the following features:
* Checking that packages install correctly with different Python versions and interpreters
* Running tests in each of the environments, configuring your test tool of choice
* Acting as a frontend to Continuous Integration servers, reducing boilerplate and merging CI and shell-based testing.
* Checking that packages install correctly with different Python versions and
interpreters
* Running tests in each of the environments, configuring your test tool of
choice
* Acting as a frontend to Continuous Integration servers, reducing boilerplate
and merging CI and shell-based testing.
Travis-CI
+17 -4
View File
@@ -6,14 +6,23 @@ Network Applications
HTTP
::::
The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web.
The Hypertext Transfer Protocol (HTTP) is an application protocol for
distributed, collaborative, hypermedia information systems. HTTP is the
foundation of data communication for the World Wide Web.
Requests
--------
Pythons standard urllib2 module provides most of the HTTP capabilities you need, but the API is thoroughly broken. It was built for a different time — and a different web. It requires an enormous amount of work (even method overrides) to perform the simplest of tasks.
Pythons standard urllib2 module provides most of the HTTP capabilities you
need, but the API is thoroughly broken. It was built for a different time —
and a different web. It requires an enormous amount of work (even method
overrides) to perform the simplest of tasks.
Requests takes all of the work out of Python HTTP — making your integration with web services seamless. Theres no need to manually add query strings to your URLs, or to form-encode your POST data. Keep-alive and HTTP connection pooling are 100% automatic, powered by urllib3, which is embedded within Requests
Requests takes all of the work out of Python HTTP — making your integration
with web services seamless. Theres no need to manually add query strings to
your URLs, or to form-encode your POST data. Keep-alive and HTTP connection
pooling are 100% automatic, powered by urllib3, which is embedded within
Requests.
- `Documention <http://docs.python-requests.org/en/latest/index.html>`_
- `PyPi <http://pypi.python.org/pypi/requests>`_
@@ -27,4 +36,8 @@ Distributed Systems
ZeroMQ
------
ØMQ (also spelled ZeroMQ, 0MQ or ZMQ) is a high-performance asynchronous messaging library aimed at use in scalable distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ØMQ system can run without a dedicated message broker. The library is designed to have a familiar socket-style API.
ØMQ (also spelled ZeroMQ, 0MQ or ZMQ) is a high-performance asynchronous
messaging library aimed at use in scalable distributed or concurrent
applications. It provides a message queue, but unlike message-oriented
middleware, a ØMQ system can run without a dedicated message broker. The
library is designed to have a familiar socket-style API.
+7 -5
View File
@@ -14,9 +14,9 @@ Nearly all Python database modules such as `sqlite3`, `psycopg` and
SQLAlchemy
----------
`SQLAlchemy <http://www.sqlalchemy.org/>`_ is a commonly used database toolkit. Unlike many database libraries
it not only provides an ORM layer but also a generalized API for writing
database-agnostic code without SQL.
`SQLAlchemy <http://www.sqlalchemy.org/>`_ is a commonly used database toolkit.
Unlike many database libraries it not only provides an ORM layer but also a
generalized API for writing database-agnostic code without SQL.
::
@@ -25,8 +25,10 @@ database-agnostic code without SQL.
Django ORM
----------
The Django ORM is the interface used by `Django <http://www.djangoproject.com>`_ to provide database access.
The Django ORM is the interface used by `Django <http://www.djangoproject.com>`_
to provide database access.
It's based on the idea of models, an abstraction that makes it easier to manipulate data in Python.
It's based on the idea of models, an abstraction that makes it easier to
manipulate data in Python.
Documentation can be found `here <https://docs.djangoproject.com/en/1.3/#the-model-layer>`_
+6 -4
View File
@@ -4,7 +4,8 @@ GUI Applications
Qt
::
Qt is a cross-platform application framework that is widely used for developing software with a GUI but can also be used for non-GUI applications.
Qt is a cross-platform application framework that is widely used for developing
software with a GUI but can also be used for non-GUI applications.
PySide
------
@@ -30,15 +31,16 @@ WXPython
Install (Stable)
----------------
*Go to http://www.wxpython.org/download.php#stable and download the appropriate package for your OS.*
*Go to http://www.wxpython.org/download.php#stable and download the appropriate
package for your OS.*
Gtk
:::
PyGTK provides Python bindings for the GTK+ toolkit. Like the GTK+ library
itself, it is currently licensed under the GNU LGPL. It is worth noting that
PyGTK only currenty supports the Gtk-2.X API (NOT Gtk-3.0). It is currently
recommended that PyGTK is not used for new projects and existing applications be
ported from PyGTK to PyGObject.
recommended that PyGTK is not used for new projects and existing applications
be ported from PyGTK to PyGObject.
Tk
::
+37 -25
View File
@@ -5,59 +5,71 @@ Scientific Applications
Context
:::::::
Python is frequently used for high-performance scientific applications. Python is widely used in academia
and scientific projects because it is easy to write, and it performs really well.
Python is frequently used for high-performance scientific applications. Python
is widely used in academia and scientific projects because it is easy to write,
and it performs really well.
Due to its high performance nature, scientific computing in python often refers to external libraries, typically
written in faster languages (like C, or FORTRAN for matrix operations). The main libraries used are NumPy and SciPy
Due to its high performance nature, scientific computing in python often refers
to external libraries, typically written in faster languages (like C, or FORTRAN
for matrix operations). The main libraries used are NumPy and SciPy
Libraries
:::::::::
Numpy
-----
`NumPy <http://numpy.scipy.org/>`_ is a low level library written in C (and FORTRAN) for high level mathematical functions.
NumPy cleverly overcomes the problem of running slower algorithms on Python by using multidimensional arrays and functions that operate on arrays.
Any algorithm can then be expressed as a function on arrays, allowing the algorithms to be run quickly.
`NumPy <http://numpy.scipy.org/>`_ is a low level library written in C (and
FORTRAN) for high level mathematical functions. NumPy cleverly overcomes the
problem of running slower algorithms on Python by using multidimensional arrays
and functions that operate on arrays. Any algorithm can then be expressed as a
function on arrays, allowing the algorithms to be run quickly.
NumPy is part of the SciPy project, and is released as a separate library so people who only need the basic requirements can just use NumPy.
NumPy is part of the SciPy project, and is released as a separate library so
people who only need the basic requirements can just use NumPy.
NumPy is compatible with Python versions 2.4 through to 2.7.2 and 3.1+.
NumPy is compatible with Python versions 2.4 through to 2.7.2 and 3.1+.
SciPy
-----
`SciPy <http://scipy.org/>`_ is a library that uses Numpy for more mathematical function. SciPy uses NumPy arrays as its basic data structure.
SciPy comes with modules for various commonly used tasks in scientific programing like linear algebra, integration (calculus),
ordinary differential equation solvers and signal processing.
`SciPy <http://scipy.org/>`_ is a library that uses Numpy for more mathematical
function. SciPy uses NumPy arrays as its basic data structure. SciPy comes with
modules for various commonly used tasks in scientific programing like linear
algebra, integration (calculus), ordinary differential equation solvers and
signal processing.
Enthought
---------
Installing NumPy and SciPy can be a daunting task. Which is why the `Enthought Python distribution <http://enthought.com/>`_ was created. With Enthought,
scientific python has never been easier (one click to install about 100 scientific python packages). User beware: Enthought is not free.
Installing NumPy and SciPy can be a daunting task. Which is why the
`Enthought Python distribution <http://enthought.com/>`_ was created. With
Enthought, scientific python has never been easier (one click to install about
100 scientific python packages). User beware: Enthought is not free.
Matplotlib
----------
`matplotlib <http://matplotlib.sourceforge.net/>`_ is a flexible plotting library
for creating interactive 2D and 3D plots that can also be saved as manuscript-quality
figures. The API in many ways reflects that of `MATLAB <http://www.mathworks.com/products/matlab/>`_, easing transition of MATLAB
users to Python. Many examples, along with the source code to re-create them,
can be browsed at the `matplotlib gallery <http://matplotlib.sourceforge.net/gallery.html>`_.
`matplotlib <http://matplotlib.sourceforge.net/>`_ is a flexible plotting
library for creating interactive 2D and 3D plots that can also be saved as
manuscript-quality figures. The API in many ways reflects that of `MATLAB <http://www.mathworks.com/products/matlab/>`_,
easing transition of MATLAB users to Python. Many examples, along with the
source code to re-create them, can be browsed at the `matplotlib gallery <http://matplotlib.sourceforge.net/gallery.html>`_.
PyQwt
-----
`PyQwt <http://pyqwt.sourceforge.net/>`_ is a solid library for plotting
numerical data. It is built on top of the popular `PyQt <http://www.riverbankcomputing.co.uk/software/pyqt/intro>`_ GUI framework.
It typically has better performance than matplotlib, but the range of built-in
chart/plot types is slightly smaller than matplotlib.
numerical data. It is built on top of the popular `PyQt <http://www.riverbankcomputing.co.uk/software/pyqt/intro>`_
GUI framework. It typically has better performance than matplotlib, but the
range of built-in chart/plot types is slightly smaller than matplotlib.
Resources
:::::::::
Many people who do scientific computing are on Windows. And yet many of the scientific computing packages are notoriously difficult to build and install.
`Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_ however, has compiled a list of Windows binaries for many useful Python packages.
The list of packages has grown from a mainly scientific python resource to a more general list. It might be a good idea to check it out if you're on Windows.
Many people who do scientific computing are on Windows. And yet many of the
scientific computing packages are notoriously difficult to build and install.
`Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_ however, has
compiled a list of Windows binaries for many useful Python packages. The list
of packages has grown from a mainly scientific python resource to a more
general list. It might be a good idea to check it out if you're on Windows.
+18 -12
View File
@@ -1,13 +1,16 @@
Speed
=====
CPython, the most commonly used implementation of Python, is slow for CPU bound tasks. `PyPy`_ is fast.
CPython, the most commonly used implementation of Python, is slow for CPU bound
tasks. `PyPy`_ is fast.
Using a slightly modified version of `David Beazleys`_ CPU bound test code(added loop for multiple tests), you can see the difference between CPython and PyPy's processing.
Using a slightly modified version of `David Beazleys`_ CPU bound test code
(added loop for multiple tests), you can see the difference between CPython
and PyPy's processing.
::
PyPy
PyPy
$ ./pypy -V
Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10)
[PyPy 1.7.0 with GCC 4.4.3]
@@ -23,7 +26,7 @@ Using a slightly modified version of `David Beazleys`_ CPU bound test code(added
CPython
$ ./python -V
Python 2.7.1
$ ./python measure2.py
$ ./python measure2.py
1.06774401665
1.45412397385
1.51485204697
@@ -37,13 +40,16 @@ Context
The GIL
-------
`The GIL`_ (Global Interpreter Lock) is how Python allows multiple threads to operate at the same time. Python's
memory management isn't entirely thread-safe, so the GIL is requried to prevents multiple threads from running
the same Python code at once.
`The GIL`_ (Global Interpreter Lock) is how Python allows multiple threads to
operate at the same time. Python's memory management isn't entirely thread-safe,
so the GIL is requried to prevents multiple threads from running the same
Python code at once.
David Beazley has a great `guide`_ on how the GIL operates. He also covers the `new GIL`_ in Python 3.2. His
results show that maximizing performance in a Python application requires a strong understanding of the GIL,
how it affects your specific application, how many cores you have, and where your application bottlenecks are.
David Beazley has a great `guide`_ on how the GIL operates. He also covers the
`new GIL`_ in Python 3.2. His results show that maximizing performance in a
Python application requires a strong understanding of the GIL, how it affects
your specific application, how many cores you have, and where your application
bottlenecks are.
C Extentions
------------
@@ -52,8 +58,8 @@ C Extentions
The GIL
-------
`Special care`_ must be taken when writing C extensions to make sure you register your threads
with the interpreter.
`Special care`_ must be taken when writing C extensions to make sure you r
egister your threads with the interpreter.
C Extentions
::::::::::::
+10 -10
View File
@@ -17,8 +17,8 @@ The Web Server Gateway Interface (or "WSGI" for short) is a standard
interface between web servers and Python web application frameworks. By
standardizing behavior and communication between web servers and Python web
frameworks, WSGI makes it possible to write portable Python web code that
can be deployed in any :ref:`WSGI-compliant web server <wsgi-servers-ref>`. WSGI is
documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
can be deployed in any :ref:`WSGI-compliant web server <wsgi-servers-ref>`.
WSGI is documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
Frameworks
@@ -74,8 +74,8 @@ you may need, such as database access or form generation and validation. For
many popular modules, `Extensions <http://flask.pocoo.org/extensions/>`_ may
already exist to suit your needs.
**Support** for flask can best be found in its mailing list. Just shoot an email to
flask@librelist.com and reply to the confirmation email.
**Support** for flask can best be found in its mailing list. Just shoot an
email to flask@librelist.com and reply to the confirmation email.
.. todo:: Explain Pyramid
@@ -129,8 +129,8 @@ The majority of self hosted Python applications today are hosted with a WSGI
server such as :ref:`gUnicorn <gunicorn-ref>`, either directly or behind a
lightweight web server such as :ref:`nginx <nginx-ref>`.
The WSGI servers serve the Python applications while the web server handles tasks
better suited for it such as static file serving, request routing, DDoS
The WSGI servers serve the Python applications while the web server handles
tasks better suited for it such as static file serving, request routing, DDoS
protection, and basic authentication.
Hosting
@@ -161,10 +161,10 @@ Heroku
`Cedar stack <http://devcenter.heroku.com/articles/cedar>`_ offers first class
support for Python 2.7 applications.
Heroku allows you to run as many Python web applications as you like, 24/7 and free
of charge. Heroku is best described as a horizontal scaling platform. They start
to charge you once you "scale" you application to run on more than one Dyno
(abstacted servers) at a time.
Heroku allows you to run as many Python web applications as you like, 24/7 and
free of charge. Heroku is best described as a horizontal scaling platform. They
start to charge you once you "scale" you application to run on more than one
Dyno (abstacted servers) at a time.
Heroku publishes `step-by-step instructions
<http://devcenter.heroku.com/articles/python>`_ on how to set up your first
+22 -12
View File
@@ -8,7 +8,8 @@ You'll need to package your code first before sharing it with other developers.
For Python Developers
:::::::::::::::::::::
If you're writing an open source Python module, `PyPI <http://pypi.python.org>`_, more properly known as *The Cheeseshop*, is the place to host it.
If you're writing an open source Python module, `PyPI <http://pypi.python.org>`_,
more properly known as *The Cheeseshop*, is the place to host it.
@@ -27,7 +28,8 @@ running from the directory which holds those packages which need to be installed
**Showing an example is always beneficial**
Say if you are after installing a package called MyPackage.tar.gz, and assuming this is your directory structure
Say if you are after installing a package called MyPackage.tar.gz, and
assuming this is your directory structure:
- archive
@@ -35,27 +37,35 @@ Say if you are after installing a package called MyPackage.tar.gz, and assuming
- MyPackage.tar.gz
Go to your command prompt and type:
::
$ cd archive
$ python -m SimpleHTTPServer 9000
.. code-block:: console
This runs a simple http server running on port 9000 and will list all packages (like **MyPackage**). Now you can install **MyPackage** using any python package installer. Using Pip, you would do it like:
::
$ cd archive
$ python -m SimpleHTTPServer 9000
$ pip install --extra-index-url=http://127.0.0.1:9000/ MyPackage
This runs a simple http server running on port 9000 and will list all packages
(like **MyPackage**). Now you can install **MyPackage** using any python
package installer. Using Pip, you would do it like:
.. code-block:: console
$ pip install --extra-index-url=http://127.0.0.1:9000/ MyPackage
Having a folder with the same name as the package name is **crucial** here.
I got fooled by that, one time. But if you feel that creating a folder called
**MyPackage** and keeping **MyPackage.tar.gz** inside that, is *redundant*, you can still install MyPackage using:
::
**MyPackage** and keeping **MyPackage.tar.gz** inside that, is *redundant*,
you can still install MyPackage using:
$ pip install http://127.0.0.1:9000/MyPackage.tar.gz
.. code-block:: console
$ pip install http://127.0.0.1:9000/MyPackage.tar.gz
Chishop
+++++++
`Chishop <https://github.com/benliles/djangopypi>`_ is a simple PyPI server written in django which allows you to register/upload with distutils and install with easy_install/pip.
`Chishop <https://github.com/benliles/djangopypi>`_ is a simple PyPI server
written in django which allows you to register/upload with distutils and
install with easy_install/pip.
For Linux Distributions
::::::::::::::::::::::::
+45 -12
View File
@@ -5,19 +5,32 @@ Installing Python on Linux
The latest version of Ubuntu, **comes with Python 2.7 out of the box**.
You do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the next section before you start building Python applications for real-world use. In particular, you should always install Distribute, as it makes it much easier for you to use other third-party Python libraries.
You do not need to install or configure anything else to use Python. Having
said that, I would strongly recommend that you install the tools and libraries
described in the next section before you start building Python applications
for real-world use. In particular, you should always install Distribute, as
it makes it much easier for you to use other third-party Python libraries.
Distribute & Pip
----------------
The most crucial third-party Python software of all is Distribute, which extends the packaging and installation facilities provided by the distutils in the standard library. Once you add Distribute to your Python system you can download and install any compliant Python software product with a single command. It also enables you to add this network installation capability to your own Python software with very little work.
The most crucial third-party Python software of all is Distribute, which
extends the packaging and installation facilities provided by the distutils
in the standard library. Once you add Distribute to your Python system you can
download and install any compliant Python software product with a single
command. It also enables you to add this network installation capability to
your own Python software with very little work.
To obtain the latest version of Distribute for Linux, run the python script available here:
http://python-distribute.org/distribute_setup.py
To obtain the latest version of Distribute for Linux, run the python script
available here: `python-distribute <http://python-distribute.org/distribute_setup.py>`_
The new``easy_install`` command you have available is considered by many to be deprecated, so we will install its replacement: **pip**. Pip allows for uninstallation of packages, and is actively maintained, unlike easy_install.
The new``easy_install`` command you have available is considered by many to be
deprecated, so we will install its replacement: **pip**. Pip allows for
uninstallation of packages, and is actively maintained, unlike easy_install.
To install pip, simply open a command prompt and run::
To install pip, simply open a command prompt and run
.. code-block:: console
$ easy_install pip
@@ -25,22 +38,42 @@ To install pip, simply open a command prompt and run::
Virtualenv
----------
After Distribute & Pip, the next development tool that you should install is `virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip::
After Distribute & Pip, the next development tool that you should install is
`virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip
.. code-block:: console
$ pip install virtualenv
The virtualenv kit provides the ability to create virtual Python environments that do not interfere with either each other, or the main Python installation. If you install virtualenv before you begin coding then you can get into the habit of using it to create completely clean Python environments for each project. This is particularly important for Web development, where each framework and application will have many dependencies.
The virtualenv kit provides the ability to create virtual Python environments
that do not interfere with either each other, or the main Python installation.
If you install virtualenv before you begin coding then you can get into the
habit of using it to create completely clean Python environments for each
project. This is particularly important for Web development, where each
framework and application will have many dependencies.
To set up a new Python environment, change the working directory to where ever you want to store the environment, and run the virtualenv utility in your project's directory::
To set up a new Python environment, change the working directory to where ever
you want to store the environment, and run the virtualenv utility in your
project's directory
.. code-block:: console
$ virtualenv --distribute venv
To use an environment, run ``source venv/bin/activate``. Your command prompt will change to show the active environment. Once you have finished working in the current virtual environment, run ``deactivate`` to restore your settings to normal.
To use an environment, run ``source venv/bin/activate``. Your command prompt
will change to show the active environment. Once you have finished working in
the current virtual environment, run ``deactivate`` to restore your settings
to normal.
Each new environment automatically includes a copy of ``pip``, so that you can setup the third-party libraries and tools that you want to use in that environment. Put your own code within a subdirectory of the environment, however you wish. When you no longer need a particular environment, simply copy your code out of it, and then delete the main directory for the environment.
Each new environment automatically includes a copy of ``pip``, so that you can
setup the third-party libraries and tools that you want to use in that
environment. Put your own code within a subdirectory of the environment,
however you wish. When you no longer need a particular environment, simply
copy your code out of it, and then delete the main directory for the environment.
--------------------------------
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_, which is available under the same license.
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_,
which is available under the same license.
+70 -17
View File
@@ -5,24 +5,41 @@ Installing Python on Mac OS X
The latest version of Mac OS X, Lion, **comes with Python 2.7 out of the box**.
You do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the next section before you start building Python applications for real-world use. In particular, you should always install Distribute, as it makes it much easier for you to use other third-party Python libraries.
You do not need to install or configure anything else to use Python. Having
said that, I would strongly recommend that you install the tools and libraries
described in the next section before you start building Python applications
for real-world use. In particular, you should always install Distribute, as it
makes it much easier for you to use other third-party Python libraries.
The version of Python that ships with OS X is great for learning, but it's not good for development. It's slightly out of date, and Apple has made significant changes that can cause hidden bugs.
The version of Python that ships with OS X is great for learning, but it's not
good for development. It's slightly out of date, and Apple has made significant
changes that can cause hidden bugs.
Doing it Right
--------------
Let's install a real version of Python.
First, you'll need to have GCC installed to compile Python. You can either get this from `XCode <http://developer.apple.com/xcode/>`_ or the smaller `OSX-GCC-Installer <https://github.com/kennethreitz/osx-gcc-installer#readme>`_ package.
First, you'll need to have GCC installed to compile Python. You can either get
this from `XCode <http://developer.apple.com/xcode/>`_ or the smaller
`OSX-GCC-Installer <https://github.com/kennethreitz/osx-gcc-installer#readme>`_ package.
While Lion comes with a large number of UNIX utilities, those familiar with Linux systems will notice one key component missing: a decent package manager. `Homebrew <http://mxcl.github.com/homebrew/>`_ fills this void.
While Lion comes with a large number of UNIX utilities, those familiar with
Linux systems will notice one key component missing: a decent package manager.
`Homebrew <http://mxcl.github.com/homebrew/>`_ fills this void.
To `install Homebrew <https://github.com/mxcl/homebrew/wiki/installation>`_, simply run::
To `install Homebrew <https://github.com/mxcl/homebrew/wiki/installation>`_,
simply run
.. code-block:: console
$ ruby -e "$(curl -fsS https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
Then, insert the hombrew directory at the top of your ``PATH`` enviornment variable. You can do this by adding the following line at the bottom of your ``~/.bashrc`` file::
Then, insert the hombrew directory at the top of your ``PATH`` enviornment
variable. You can do this by adding the following line at the bottom of your
``~/.bashrc`` file
.. code-block:: console
export PATH=/usr/local/bin:$PATH
@@ -30,21 +47,37 @@ Now, we can install Python 2.7: ::
$ brew install python --framework
This will take a minute or two. Once that's complete, you'll have to add the new Python scripts directory to your ``PATH``::
This will take a minute or two. Once that's complete, you'll have to add the
new Python scripts directory to your ``PATH``
.. code-block:: console
export PATH=/usr/local/share/python:$PATH
The ``--framework`` option tells Homebrew to compile a Framework-style Python build, rather than a UNIX-style build. The outdated version of Python that Snow Leopard comes packaged with is built as a Framework, so this helps avoid some future module installation bugs.
The ``--framework`` option tells Homebrew to compile a Framework-style Python
build, rather than a UNIX-style build. The outdated version of Python that
Snow Leopard comes packaged with is built as a Framework, so this helps avoid
some future module installation bugs.
Distribute & Pip
----------------
The most crucial third-party Python software of all is Distribute, which extends the packaging and installation facilities provided by the distutils in the standard library. Once you add Distribute to your Python system you can download and install any compliant Python software product with a single command. It also enables you to add this network installation capability to your own Python software with very little work.
The most crucial third-party Python software of all is Distribute, which
extends the packaging and installation facilities provided by the distutils
in the standard library. Once you add Distribute to your Python system you can
download and install any compliant Python software product with a single
command. It also enables you to add this network installation capability to
your own Python software with very little work.
Hombrew already installed Distribute for you. Its ``easy_install`` command is considered by many to be deprecated, so we will install its replacement: **pip**. Pip allows for uninstallation of packages, and is actively maintained, unlike easy_install.
Hombrew already installed Distribute for you. Its ``easy_install`` command is
considered by many to be deprecated, so we will install its replacement:
**pip**. Pip allows for uninstallation of packages, and is actively maintained,
unlike easy_install.
To install pip, simply open a command prompt and run::
To install pip, simply open a command prompt and run
.. code-block:: console
$ easy_install pip
@@ -52,21 +85,41 @@ To install pip, simply open a command prompt and run::
Virtualenv
----------
After Distribute & Pip, the next development tool that you should install is `virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip::
After Distribute & Pip, the next development tool that you should install is
`virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip
.. code-block:: console
$ pip install virtualenv
The virtualenv kit provides the ability to create virtual Python environments that do not interfere with either each other, or the main Python installation. If you install virtualenv before you begin coding then you can get into the habit of using it to create completely clean Python environments for each project. This is particularly important for Web development, where each framework and application will have many dependencies.
The virtualenv kit provides the ability to create virtual Python environments
that do not interfere with either each other, or the main Python installation.
If you install virtualenv before you begin coding then you can get into the
habit of using it to create completely clean Python environments for each
project. This is particularly important for Web development, where each
framework and application will have many dependencies.
To set up a new Python environment, change the working directory to where ever you want to store the environment, and run the virtualenv utility in your project's directory::
To set up a new Python environment, change the working directory to where ever
you want to store the environment, and run the virtualenv utility in your
project's directory
.. code-block:: console
$ virtualenv --distribute venv
To use an environment, run ``source venv/bin/activate``. Your command prompt will change to show the active environment. Once you have finished working in the current virtual environment, run ``deactivate`` to restore your settings to normal.
To use an environment, run ``source venv/bin/activate``. Your command prompt
will change to show the active environment. Once you have finished working in
the current virtual environment, run ``deactivate`` to restore your settings
to normal.
Each new environment automatically includes a copy of ``pip``, so that you can setup the third-party libraries and tools that you want to use in that environment. Put your own code within a subdirectory of the environment, however you wish. When you no longer need a particular environment, simply copy your code out of it, and then delete the main directory for the environment.
Each new environment automatically includes a copy of ``pip``, so that you can
setup the third-party libraries and tools that you want to use in that
environment. Put your own code within a subdirectory of the environment,
however you wish. When you no longer need a particular environment, simply
copy your code out of it, and then delete the main directory for the environment.
--------------------------------
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_, which is available under the same license.
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_,
which is available under the same license.
+63 -16
View File
@@ -3,13 +3,24 @@
Installing Python on Windows
============================
First, download the `latest version <http://python.org/ftp/python/2.7.2/python-2.7.2.msi>`_ of Python 2 from the official Website.
First, download the `latest version <http://python.org/ftp/python/2.7.2/python-2.7.2.msi>`_
of Python 2 from the official Website.
The Windows version is provided as an MSI package. To install it manually, just double-click the file. The MSI package format allows Windows administrators to automate installation with their standard tools.
The Windows version is provided as an MSI package. To install it manually, just
double-click the file. The MSI package format allows Windows administrators to
automate installation with their standard tools.
By design, Python installs to a directory with the version number embedded, e.g. ``C:\Python27\``, so that you can have multiple versions of Python on the same system without conflicts. Of course, only one interpreter can be the default application for Python file types. It also does not automatically modify the ``PATH`` environment variable, so that you always have control over which copy of Python is run.
By design, Python installs to a directory with the version number embedded,
e.g. ``C:\Python27\``, so that you can have multiple versions of Python on the
same system without conflicts. Of course, only one interpreter can be the
default application for Python file types. It also does not automatically
modify the ``PATH`` environment variable, so that you always have control over
which copy of Python is run.
Typing the full path name for a Python interpreter each time quickly gets tedious, so add the directories for your default Python version to the PATH. Assuming that your Python installation is in ``C:\Python27\``, add this to your PATH::
Typing the full path name for a Python interpreter each time quickly gets
tedious, so add the directories for your default Python version to the PATH.
Assuming that your Python installation is in ``C:\Python27\``, add this to your
PATH::
C:\Python27\;C:\Python27\Scripts\
@@ -17,20 +28,34 @@ You can do this easily by running the following in ``powershell``::
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
You do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the next section before you start building Python applications for real-world use. In particular, you should always install Distribute, as it makes it much easier for you to use other third-party Python libraries.
You do not need to install or configure anything else to use Python. Having
said that, I would strongly recommend that you install the tools and libraries
described in the next section before you start building Python applications for
real-world use. In particular, you should always install Distribute, as it
makes it much easier for you to use other third-party Python libraries.
Distribute + Pip
----------------
The most crucial third-party Python software of all is Distribute, which extends the packaging and installation facilities provided by the distutils in the standard library. Once you add Distribute to your Python system you can download and install any compliant Python software product with a single command. It also enables you to add this network installation capability to your own Python software with very little work.
The most crucial third-party Python software of all is Distribute, which
extends the packaging and installation facilities provided by the distutils in
the standard library. Once you add Distribute to your Python system you can
download and install any compliant Python software product with a single
command. It also enables you to add this network installation capability to
your own Python software with very little work.
To obtain the latest version of Distribute for Windows, run the python script available here:
http://python-distribute.org/distribute_setup.py
To obtain the latest version of Distribute for Windows, run the python script
available here: `python-distribute <http://python-distribute.org/distribute_setup.py>`_
You'll now have a new command available to you: **easy_install**. It is considered by many to be deprecated, so we will install its replacement: **pip**. Pip allows for uninstallation of packages, and is actively maintained, unlike easy_install.
You'll now have a new command available to you: **easy_install**. It is
considered by many to be deprecated, so we will install its replacement:
**pip**. Pip allows for uninstallation of packages, and is actively maintained,
unlike easy_install.
To install pip, simply open a command prompt and run::
To install pip, simply open a command prompt and run
.. code-block:: console
> easy_install pip
@@ -38,23 +63,45 @@ To install pip, simply open a command prompt and run::
Virtualenv
----------
After Distribute & Pip, the next development tool that you should install is `virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip::
After Distribute & Pip, the next development tool that you should install is
`virtualenv <http://pypi.python.org/pypi/virtualenv/>`_. Use pip
.. code-block:: console
> pip install virtualenv
The virtualenv kit provides the ability to create virtual Python environments that do not interfere with either each other, or the main Python installation. If you install virtualenv before you begin coding then you can get into the habit of using it to create completely clean Python environments for each project. This is particularly important for Web development, where each framework and application will have many dependencies.
The virtualenv kit provides the ability to create virtual Python environments
that do not interfere with either each other, or the main Python installation.
If you install virtualenv before you begin coding then you can get into the
habit of using it to create completely clean Python environments for each
project. This is particularly important for Web development, where each
framework and application will have many dependencies.
To set up a new Python environment, change the working directory to where ever you want to store the environment, and run the virtualenv utility in your project's directory::
To set up a new Python environment, change the working directory to where ever
you want to store the environment, and run the virtualenv utility in your
project's directory
.. code-block:: console
> virtualenv --distribute venv
To use an environment, run the ``activate.bat`` batch file in the ``Scripts`` subdirectory of that environment. Your command prompt will change to show the active environment. Once you have finished working in the current virtual environment, run the ``deactivate.bat`` batch file to restore your settings to normal.
To use an environment, run the ``activate.bat`` batch file in the ``Scripts``
subdirectory of that environment. Your command prompt will change to show the
active environment. Once you have finished working in the current virtual
environment, run the ``deactivate.bat`` batch file to restore your settings to
normal.
Each new environment automatically includes a copy of ``pip`` in the ``Scripts`` subdirectory, so that you can setup the third-party libraries and tools that you want to use in that environment. Put your own code within a subdirectory of the environment, however you wish. When you no longer need a particular environment, simply copy your code out of it, and then delete the main directory for the environment.
Each new environment automatically includes a copy of ``pip`` in the
``Scripts`` subdirectory, so that you can setup the third-party libraries and
tools that you want to use in that environment. Put your own code within a
subdirectory of the environment, however you wish. When you no longer need a
particular environment, simply copy your code out of it, and then delete the
main directory for the environment.
--------------------------------
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_, which is available under the same license.
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_,
which is available under the same license.
+8 -2
View File
@@ -3,12 +3,18 @@ Properly Installing Python
There's a good chance that you already have Python on your operating system.
If so, you do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the guides below before you start building Python applications for real-world use. In particular, you should always install Distribute, Pip, and Virtualenv — they make it much easier for you to use other third-party Python libraries.
If so, you do not need to install or configure anything else to use Python.
Having said that, I would strongly recommend that you install the tools and
libraries described in the guides below before you start building Python
applications for real-world use. In particular, you should always install
Distribute, Pip, and Virtualenv — they make it much easier for you to use
other third-party Python libraries.
Installation Guides
-------------------
These guides go over the proper installation of :ref:`Python 2.7 <which-python>` for development purposes, as well as distribute, pip, and virtualenv setup.
These guides go over the proper installation of :ref:`Python 2.7 <which-python>`
for development purposes, as well as distribute, pip, and virtualenv setup.
- :ref:`Mac OS X <install-osx>`.
- :ref:`Microsoft Windows<install-windows>`.
+2 -1
View File
@@ -16,7 +16,8 @@ Which Python to use?
Today
-----
If you're choosing a Python interpreter to use, I *highly* recommend you Use Python 2.7.x, unless you have a strong reason not to.
If you're choosing a Python interpreter to use, I *highly* recommend you Use
Python 2.7.x, unless you have a strong reason not to.
The Future
+9 -3
View File
@@ -38,7 +38,8 @@ Docstrings
PEP 257 is the primary reference for docstrings. (http://www.python.org/dev/peps/pep-0257/)
There are two types of docstrings, one-line and multi-line. Their names should be fairly self explanatory.
There are two types of docstrings, one-line and multi-line. Their names
should be fairly self explanatory.
One-line docstrings: ::
def kos_root():
@@ -63,7 +64,9 @@ Multi-line docstrings: ::
Sphinx
------
Sphinx_ is a tool which converts documentation in the :ref:`restructuredtext-ref` markup language into a range of output formats including HTML, LaTeX (for printable PDF versions), manual pages and plain text.
Sphinx_ is a tool which converts documentation in the :ref:`restructuredtext-ref`
markup language into a range of output formats including HTML, LaTeX (for
printable PDF versions), manual pages and plain text.
.. note:: This Guide is built with Sphinx_
@@ -75,7 +78,10 @@ Sphinx_ is a tool which converts documentation in the :ref:`restructuredtext-ref
reStructuredText
----------------
Most Python documentation is written with reStructuredText_. The `reStructuredText Primer <http://sphinx.pocoo.org/rest.html>`_ and the `reStructuredText Quick Reference <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_ should help you familiarize yourself with its syntax.
Most Python documentation is written with reStructuredText_. The
`reStructuredText Primer <http://sphinx.pocoo.org/rest.html>`_ and the
`reStructuredText Quick Reference <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_
should help you familiarize yourself with its syntax.
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
+4 -2
View File
@@ -3,9 +3,11 @@ Choosing a License
Open source.
There are plenty of `open source licenses <http://opensource.org/licenses/alphabetical>`_ available to choose from.
There are plenty of `open source licenses <http://opensource.org/licenses/alphabetical>`_
available to choose from.
To help you choose one for your project, there's a `license chooser <http://three.org/openart/license_chooser/>`_, use it.
To help you choose one for your project, there's a `license chooser <http://three.org/openart/license_chooser/>`_,
use it.
Non-Restrictive
+17 -13
View File
@@ -388,7 +388,8 @@ keep a count of your place in the list.
# 1, 4
# 2, 5
The ``enumerate`` function has better readability than handling a counter manually. Moreover,
The ``enumerate`` function has better readability than handling a counter
manually. Moreover,
it is better optimized for iterators.
Read From a File
@@ -414,8 +415,8 @@ files for you.
for line in f:
print line
The ``with`` statement is better because it will ensure you always close the file,
even if an exception is raised.
The ``with`` statement is better because it will ensure you always close the
file, even if an exception is raised.
Returning Multiple Values from a Function
-----------------------------------------
@@ -447,15 +448,17 @@ values in before you return
Line Continuations
~~~~~~~~~~~~~~~~~~
When a logical line of code is longer than the accepted limit, you need to split it over multiple
physical lines. Python interpreter will join consecutive lines if the last character of the line is
a backslash. This is helpful sometime but is preferably avoided, because of its fragility: a white
space added to the end of the line, after the backslash, will break the code and may have unexpected
results.
When a logical line of code is longer than the accepted limit, you need to
split it over multiple physical lines. Python interpreter will join consecutive
lines if the last character of the line is a backslash. This is helpful
sometime but is preferably avoided, because of its fragility: a white space
added to the end of the line, after the backslash, will break the code and may
have unexpected results.
A prefered solution is to use parenthesis around your elements. Left with an unclosed parenthesis on an end-of-line
the Python interpreter will join the next line until the parenthesis is closed. The same behavior holds for
curly and square braces.
A prefered solution is to use parenthesis around your elements. Left with an
unclosed parenthesis on an end-of-line the Python interpreter will join the
next line until the parenthesis is closed. The same behavior holds for curly
and square braces.
**Bad**:
@@ -479,5 +482,6 @@ curly and square braces.
from some.deep.module.inside.a.module import (a_nice_function, another_nice_function,
yet_another_nice_functio)
However, more often than not having to split long logical line is a sign that you
are trying to do too many things at the same time, which may hinder readability.
However, more often than not having to split long logical line is a sign that
you are trying to do too many things at the same time, which may hinder
readability.
+25 -23
View File
@@ -21,9 +21,10 @@ Some general rules of testing:
- Try hard to make tests that run fast. If one single test needs more than a
few millisecond to run, development will be slowed down or the tests will not
be run as often as desirable. In some cases, test can't be fast because they
need a complex data structure to work on, and this data structure must be loaded
every time the test runs. Keep these heavier tests in a separate test suite
that is run by some scheduled task, and run all other tests as often as needed.
need a complex data structure to work on, and this data structure must be
loaded every time the test runs. Keep these heavier tests in a separate test
suite that is run by some scheduled task, and run all other tests as often
as needed.
- Learn your tools and learn how to run a single test or a test case. Then,
when developing a function inside a module, run this function's tests very
@@ -41,9 +42,9 @@ Some general rules of testing:
When comming back to work, you will have a pointer to where you were and get
faster on tracks.
- The first step when you are debugging your code is to write a new test pinpointing
the bug. While it is not always possible to do, those bug catching test are among
the most valuable piece of code in your project.
- The first step when you are debugging your code is to write a new test
pinpointing the bug. While it is not always possible to do, those bug
catching test are among the most valuable piece of code in your project.
- Use long and descriptive names for testing functions. The style guide here is
slighlty different than that of running code, where short names are often
@@ -62,10 +63,10 @@ Some general rules of testing:
- Another use of the testing code is as an introduction to new developers. When
someone will have to work on the code base, runnning and reading the related
testing code is often the best they can do. They will or should discover the
hot spots, where most difficulties arise, and the corner cases. If they have to
add some functionality, the first step should be to add a test and, by this mean,
ensure the new functionality is not already a working path that has not been
plugged in the interface.
hot spots, where most difficulties arise, and the corner cases. If they have
to add some functionality, the first step should be to add a test and, by this
mean, ensure the new functionality is not already a working path that has not
been plugged in the interface.
The Basics
::::::::::
@@ -99,15 +100,15 @@ As of Python 2.7 unittest also includes its own test discovery mechanisms.
Doctest
-------
The doctest module searches for pieces of text that look like interactive Python
sessions in docstrings, and then executes those sessions to verify that they work exactly as
shown.
The doctest module searches for pieces of text that look like interactive
Python sessions in docstrings, and then executes those sessions to verify that
they work exactly as shown.
Doctests have a different use case than proper unit tests: they are usually less
detailed and don't catch special cases or obscure regression bugs. They are
useful as an expressive documentation of the main use cases of a module and
its components. However, doctests should run automatically each time
the full test suite runs.
Doctests have a different use case than proper unit tests: they are usually
less detailed and don't catch special cases or obscure regression bugs. They
are useful as an expressive documentation of the main use cases of a module and
its components. However, doctests should run automatically each time the full
test suite runs.
A simple doctest in a function:
@@ -128,8 +129,9 @@ A simple doctest in a function:
import doctest
doctest.testmod()
When running this module from the command line as in ``python module.py``, the doctests
will run and complain if anything is not behaving as described in the docstrings.
When running this module from the command line as in ``python module.py``, the
doctests will run and complain if anything is not behaving as described in the
docstrings.
Tools
:::::
@@ -144,7 +146,7 @@ py.test is a no-boilerplate alternative to Python's standard unittest module.
$ pip install pytest
Despite being a fully-featured and extensible test tool it boasts a simple
Despite being a fully-featured and extensible test tool it boasts a simple
syntax. Creating a test suite is as easy as writing a module with a couple of
functions
@@ -205,8 +207,8 @@ xUnit-compatible test output, coverage reporting, and test selection.
tox
---
tox is a tool for automating test environment management and testing against multiple
interpreter configurations
tox is a tool for automating test environment management and testing against
multiple interpreter configurations
::