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.
-
-
-
Stay Informed
-
Receive updates on new releases and upcoming projects.
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.
-
-
Get Updates
-
Receive updates on new releases and upcoming projects.
diff --git a/docs/conf.py b/docs/conf.py
index f0bd46e..81fcc6f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -46,7 +46,7 @@ master_doc = 'index'
# General information about the project.
project = u'pythonguide'
-copyright = u'2016. A Kenneth Reitz Project. CC BY-NC-SA 3.0'
+copyright = u'2011–2018 Kenneth Reitz & Real Python. CC BY-NC-SA 3.0'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -106,11 +106,11 @@ html_theme = 'alabaster'
# documentation.
html_theme_options = {
'show_powered_by': False,
- 'github_user': 'kennethreitz',
+ 'github_user': 'realpython',
'github_repo': 'python-guide',
'github_banner': True,
'show_related': False,
- 'note_bg': '#FFF59C'
+ 'note_bg': '#FFF59C',
}
# Add any paths that contain custom themes here, relative to this directory.
@@ -241,7 +241,7 @@ man_pages = [
epub_title = u'pythonguide'
epub_author = u'Kenneth Reitz'
epub_publisher = u'Kenneth Reitz'
-epub_copyright = u'2016, Kenneth Reitz'
+epub_copyright = u'2011–2018, Kenneth Reitz & Real Python'
# The language of the text. It defaults to the language option
# or en if the language is not set.
diff --git a/docs/dev/env.rst b/docs/dev/env.rst
index bc6d68c..de67a9a 100644
--- a/docs/dev/env.rst
+++ b/docs/dev/env.rst
@@ -1,7 +1,7 @@
Your Development Environment
============================
-.. image:: https://farm3.staticflickr.com/2930/33175624924_7febc46cc4_k_d.jpg
+.. image:: /_static/photos/33175624924_7febc46cc4_k_d.jpg
Text Editors
@@ -164,8 +164,8 @@ MIT licensed.
Enthought Canopy
----------------
`Enthought Canopy `_ is a Python
-IDE which is focused towards Scientists and Engineers as it provides pre
-installed libraries for data analysis.
+IDE which is focused towards Scientists and Engineers as it provides pre
+installed libraries for data analysis.
Eclipse
-------
diff --git a/docs/dev/pip-virtualenv.rst b/docs/dev/pip-virtualenv.rst
index 50b6903..6971be8 100644
--- a/docs/dev/pip-virtualenv.rst
+++ b/docs/dev/pip-virtualenv.rst
@@ -3,7 +3,7 @@
Further Configuration of Pip and Virtualenv
===========================================
-.. image:: https://farm4.staticflickr.com/3934/34018732105_f0e6758859_k_d.jpg
+.. image:: /_static/photos/34018732105_f0e6758859_k_d.jpg
Requiring an active virtual environment for ``pip``
---------------------------------------------------
diff --git a/docs/dev/virtualenvs.rst b/docs/dev/virtualenvs.rst
index c3b2102..11f9248 100644
--- a/docs/dev/virtualenvs.rst
+++ b/docs/dev/virtualenvs.rst
@@ -3,9 +3,9 @@
Pipenv & Virtual Environments
=============================
-.. image:: https://farm5.staticflickr.com/4290/35294660055_42c02b2316_k_d.jpg
+.. image:: /_static/photos/35294660055_42c02b2316_k_d.jpg
-This tutorial walks you through installing and using Python packages.
+This tutorial walks you through installing and using Python packages.
It will show you how to install and use the necessary tools and make strong
recommendations on best practices. Keep in mind that Python is used for a great
@@ -34,7 +34,7 @@ install the latest 3.x version from `python.org`_ or refer to the
`Installing Python`_ section of this guide.
.. Note:: If you're newcomer and you get an error like this:
-
+
.. code-block:: python
>>> python
@@ -47,7 +47,7 @@ install the latest 3.x version from `python.org`_ or refer to the
`getting started tutorial`_ for an introduction to using your operating
system's shell and interacting with Python.
-Additionally, you'll need to make sure you have :ref:`pip` available. You can
+Additionally, you'll need to make sure you have `pip`_ available. You can
check this by running:
.. code-block:: bash
@@ -60,22 +60,23 @@ using your OS package manager, you may have to `install pip `_!
+`fork us on GitHub `_!
This handcrafted guide exists to provide both novice and expert Python
developers a best practice handbook to the installation, configuration, and
diff --git a/docs/intro/community.rst b/docs/intro/community.rst
index 472c6d5..ac5f844 100644
--- a/docs/intro/community.rst
+++ b/docs/intro/community.rst
@@ -3,7 +3,7 @@
The Community
=============
-.. image:: https://farm5.staticflickr.com/4225/34689432801_78d97ecec9_k_d.jpg
+.. image:: /_static/photos/34689432801_78d97ecec9_k_d.jpg
BDFL
----
@@ -71,7 +71,7 @@ Here's an overview of the PEP acceptance workflow:
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
@@ -81,8 +81,17 @@ A comprehensive list of conferences is maintained at `pycon.org `_.
+
+
+Online Communities
+------------------
+
+`PythonistaCafe `_ is an invite-only, online community
+of Python and software development enthusiasts helping each other succeed and grow.
+Think of it as a club of mutual improvement for Pythonistas where a broad range of
+programming questions, career advice, and other topics are discussed every day.
diff --git a/docs/intro/documentation.rst b/docs/intro/documentation.rst
index a75aa3c..ea247ce 100644
--- a/docs/intro/documentation.rst
+++ b/docs/intro/documentation.rst
@@ -1,7 +1,7 @@
Documentation
=============
-.. image:: https://farm5.staticflickr.com/4178/33928823133_2f3d32cf32_k_d.jpg
+.. image:: /_static/photos/33928823133_2f3d32cf32_k_d.jpg
Official Documentation
----------------------
diff --git a/docs/intro/duction.rst b/docs/intro/duction.rst
index 8e9cc6f..4a6772d 100644
--- a/docs/intro/duction.rst
+++ b/docs/intro/duction.rst
@@ -1,7 +1,7 @@
Introduction
============
-.. image:: https://farm5.staticflickr.com/4180/34725946825_0f85497e60_k_d.jpg
+.. image:: /_static/photos/34725946825_0f85497e60_k_d.jpg
From the `official Python website `_:
diff --git a/docs/intro/learning.rst b/docs/intro/learning.rst
index 86f8243..84320bf 100644
--- a/docs/intro/learning.rst
+++ b/docs/intro/learning.rst
@@ -1,7 +1,7 @@
Learning Python
===============
-.. image:: https://farm3.staticflickr.com/2840/32800783863_11a00db52c_k_d.jpg
+.. image:: /_static/photos/32800783863_11a00db52c_k_d.jpg
Beginner
--------
@@ -15,8 +15,22 @@ quick-start guide to the language.
`The Python Tutorial `_
+Real Python
+~~~~~~~~~~~
+
+Real Python is a repository of free and in-depth Python tutorials created by a diverse team of professional Python developers. At Real Python you can learn all things Python from the ground up. Everything from the absolute basics of Python, to web development and web scraping, to data visualization, and beyond.
+
+ `Real Python `_
+
+Python Basics
+~~~~~~~~~~~~~
+
+pythonbasics.org is an introductiory tutorial for beginners. The tutorial includes exercises. It covers the basics and there are also in-depth lessons like object oriented programming and regular expressions.
+
+ `Python basics `_
+
Python for Beginners
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~
thepythonguru.com is a tutorial focuses on beginner programmers. It covers many python concepts
in depth. It also teaches you some advance constructs of python like lambda expression, regular expression.
@@ -25,14 +39,6 @@ At last it finishes off with tutorial "How to access MySQL db using python"
`Python for beginners `_
-Learn Python for Data Science Interactively
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-If you prefer an online interactive environment to learn Python for Data Science, `this free python tutorial by DataCamp `_ is a great way to get started. If you're already somewhat advanced and interested in machine learning, check out this `course on Supervised Learning with scikit-learn `_, by one the core developers of scikit-learn.
-
-
-`Python for data science `_
-
Learn Python Interactive Tutorial
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -44,12 +50,10 @@ without having to install Python locally.
`Learn Python `_
-
If you want a more traditional book, *Python For You and Me* is an excellent
resource for learning all aspects of the language.
`Python for You and Me `_
- `Learn Python Interactively with DataCamp! `_
Learn Python Step by Step
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -116,7 +120,7 @@ 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 `_
+ `Dive Into Python 3 `_
Think Python: How to Think Like a Computer Scientist
@@ -191,6 +195,15 @@ making the process of learning Python fun and engaging.
Intermediate
------------
+Python Tricks: The Book
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Discover Python's best practices with simple examples and start writing even more beautiful + Pythonic code. "Python Tricks: The Book" shows you exactly how.
+
+You’ll master intermediate and advanced-level features in Python with practical examples and a clear narrative:
+
+ `Python Tricks: The Book `_
+
Effective Python
~~~~~~~~~~~~~~~~
@@ -243,7 +256,7 @@ and can make classes and objects behave in different and magical ways.
.. note:: The Rafekettler.com is currently down, you can go to their Github version directly. Here you can find a PDF version:
`A Guide to Python's Magic Methods (repo on GitHub) `_
-
+
For Engineers and Scientists
@@ -266,7 +279,7 @@ puts the emphasis on numerical methods and how to implement them in Python.
`Numerical Methods in Engineering with Python `_
-Miscellaneous topics
+Miscellaneous Topics
--------------------
Problem Solving with Algorithms and Data Structures
@@ -315,6 +328,14 @@ web app from scratch.
`Fullstack Python `_
+PythonistaCafe
+~~~~~~~~~~~~~~
+
+PythonistaCafe is an invite-only, online community of Python and software development enthusiasts helping each other succeed and grow. Think of it as a club of mutual improvement for Pythonistas where a broad range of programming questions, career advice, and other topics are discussed every day.
+
+ `PythonistaCafe `_
+
+
References
----------
diff --git a/docs/intro/news.rst b/docs/intro/news.rst
index c3a0195..7a23d61 100644
--- a/docs/intro/news.rst
+++ b/docs/intro/news.rst
@@ -1,7 +1,22 @@
News
====
-.. image:: https://farm4.staticflickr.com/3804/33573767786_eececc5d27_k_d.jpg
+.. image:: /_static/photos/33573767786_eececc5d27_k_d.jpg
+
+PyCoder’s Weekly
+~~~~~~~~~~~~~~~~
+
+PyCoder’s Weekly is a free weekly Python newsletter for Python developers
+by Python developers (Projects, Articles, News, and Jobs).
+
+ `PyCoder’s Weekly `_
+
+Real Python
+~~~~~~~~~~~
+
+At Real Python you can learn all things Python from the ground up, with weekly free and in-depth tutorials. Everything from the absolute basics of Python, to web development and web scraping, to data visualization, and beyond.
+
+ `Real Python `_
Planet Python
~~~~~~~~~~~~~
@@ -32,14 +47,6 @@ A short-form Python podcast covering recent developer headlines.
`Python Bytes `_
-Pycoder's Weekly
-~~~~~~~~~~~~~~~~
-
-Pycoder's Weekly is a free weekly Python newsletter for Python developers
-by Python developers (Projects, Articles, News, and Jobs).
-
- `Pycoder's Weekly `_
-
Python Weekly
~~~~~~~~~~~~~
diff --git a/docs/notes/contribute.rst b/docs/notes/contribute.rst
index b75f559..4045fb1 100644
--- a/docs/notes/contribute.rst
+++ b/docs/notes/contribute.rst
@@ -1,7 +1,7 @@
Contribute
~~~~~~~~~~
-.. image:: https://farm3.staticflickr.com/2858/33573769116_49c1ef51e7_k_d.jpg
+.. image:: /_static/photos/33573769116_49c1ef51e7_k_d.jpg
Python-guide is under active development, and contributors are welcome.
diff --git a/docs/notes/license.rst b/docs/notes/license.rst
index 6df4ee6..407e173 100644
--- a/docs/notes/license.rst
+++ b/docs/notes/license.rst
@@ -2,6 +2,6 @@
License
=======
-.. image:: https://farm4.staticflickr.com/3762/32800805573_568d6b72fd_k_d.jpg
+.. image:: /_static/photos/32800805573_568d6b72fd_k_d.jpg
The Guide is licensed under the `Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license `_.
diff --git a/docs/notes/styleguide.rst b/docs/notes/styleguide.rst
index c2d4034..619c6da 100644
--- a/docs/notes/styleguide.rst
+++ b/docs/notes/styleguide.rst
@@ -4,7 +4,7 @@
The Guide Style Guide
=====================
-.. image:: https://farm4.staticflickr.com/3684/33573755856_7f43d43adf_k_d.jpg
+.. image:: /_static/photos/33573755856_7f43d43adf_k_d.jpg
As with all documentation, having a consistent format helps make the
document more understandable. In order to make The Guide easier to digest,
diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst
index ee7b512..1fe3b53 100644
--- a/docs/scenarios/admin.rst
+++ b/docs/scenarios/admin.rst
@@ -1,7 +1,7 @@
Systems Administration
======================
-.. image:: https://farm5.staticflickr.com/4179/34435690580_3afec7d4cd_k_d.jpg
+.. image:: /_static/photos/34435690580_3afec7d4cd_k_d.jpg
Fabric
------
@@ -234,37 +234,37 @@ The Ansible playbook will ping all of the servers in the :file:`hosts.yml` file.
You can also select groups of servers using Ansible. For more information
about Ansible, read the `Ansible Docs `_.
-`An Ansible tutorial `_ is also a
+`An Ansible tutorial `_ is also a
great and detailed introduction to getting started with Ansible.
Chef
----
-`Chef `_ is a systems and cloud infrastructure automation
-framework that makes it easy to deploy servers and applications to any physical,
-virtual, or cloud location. In case this is your choice for configuration management,
-you will primarily use Ruby to write your infrastructure code.
+`Chef `_ is a systems and cloud infrastructure automation
+framework that makes it easy to deploy servers and applications to any physical,
+virtual, or cloud location. In case this is your choice for configuration management,
+you will primarily use Ruby to write your infrastructure code.
-Chef clients run on every server that is part of your infrastructure and these regularly
-check with your Chef server to ensure your system is always aligned and represents the
-desired state. Since each individual server has its own distinct Chef client, each server
+Chef clients run on every server that is part of your infrastructure and these regularly
+check with your Chef server to ensure your system is always aligned and represents the
+desired state. Since each individual server has its own distinct Chef client, each server
configures itself and this distributed approach makes Chef a scalable automation platform.
-Chef works by using custom recipes (configuration elements), implemented in cookbooks. Cookbooks, which are basically
-packages for infrastructure choices, are usually stored in your Chef server.
-Read the `Digital Ocean tutorial series
-`_
+Chef works by using custom recipes (configuration elements), implemented in cookbooks. Cookbooks, which are basically
+packages for infrastructure choices, are usually stored in your Chef server.
+Read the `Digital Ocean tutorial series
+`_
on chef to learn how to create a simple Chef Server.
To create a simple cookbook the `knife `_ command is used:
-.. code-block:: console
+.. code-block:: console
knife cookbook create cookbook_name
-`Getting started with Chef `_
-is a good starting point for Chef Beginners and many community maintained cookbooks that can
-serve as a good reference or tweaked to serve your infrastructure configuration needs can be
+`Getting started with Chef `_
+is a good starting point for Chef Beginners and many community maintained cookbooks that can
+serve as a good reference or tweaked to serve your infrastructure configuration needs can be
found on the `Chef Supermarket `_.
- `Chef Documentation `_
@@ -304,7 +304,7 @@ your Puppet modules.
.. code-block:: console
$ facter operatingsystem
- Ubuntu
+ Ubuntu
Writing Modules in Puppet is pretty straight forward. Puppet Manifests together
form Puppet Modules. Puppet manifest end with an extension of ``.pp``.
@@ -374,7 +374,7 @@ Buildout
--------
`Buildout `_ is an open source software build tool.
-Buildout is created using the Python programming language. It implements a
+Buildout is created using the Python programming language. It implements a
principle of separation of configuration from the scripts that do the setting up.
Buildout is primarily used to download and set up dependencies in Python eggs
format of the software being developed or deployed. Recipes for build tasks in any
diff --git a/docs/scenarios/ci.rst b/docs/scenarios/ci.rst
index 457f232..676f0b8 100644
--- a/docs/scenarios/ci.rst
+++ b/docs/scenarios/ci.rst
@@ -1,7 +1,7 @@
Continuous Integration
======================
-.. image:: https://farm5.staticflickr.com/4173/33907150594_9abba7ad0a_k_d.jpg
+.. image:: /_static/photos/33907150594_9abba7ad0a_k_d.jpg
.. note::
For advice on writing your tests, see :doc:`/writing/tests`.
diff --git a/docs/scenarios/cli.rst b/docs/scenarios/cli.rst
index b6c7e73..14f779e 100644
--- a/docs/scenarios/cli.rst
+++ b/docs/scenarios/cli.rst
@@ -1,7 +1,7 @@
Command-line Applications
=========================
-.. image:: https://farm5.staticflickr.com/4272/34435690330_11930b5987_k_d.jpg
+.. image:: /_static/photos/34435690330_11930b5987_k_d.jpg
Command-line applications, also referred to as
`Console Applications `_,
@@ -68,9 +68,20 @@ sub-command to do the work.
Cement
------
-`Cement `_ is an advanced CLI Application Framework.
+`Cement `_ is an advanced CLI Application Framework.
Its goal is to introduce a standard, and feature-full platform
for both simple and complex command line applications as well
-as support rapid development needs without sacrificing quality.
-Cement is flexible, and it's use cases span from the simplicity of a micro-framework
-to the complexity of a meg-framework.
+as support rapid development needs without sacrificing quality.
+Cement is flexible, and it's use cases span from the simplicity of a micro-framework
+to the complexity of a meg-framework.
+
+Python Fire
+-----------
+
+`Python Fire `_ is a library for
+automatically generating command line interfaces from absolutely any Python
+object. It can help debug Python code more easily from the command line,
+create CLI interfaces to existing code, allow you to interactively explore
+code in a REPL, and simplify transitioning between Python and Bash (or any
+other shell).
+
diff --git a/docs/scenarios/clibs.rst b/docs/scenarios/clibs.rst
index 712d7f8..dba7d71 100644
--- a/docs/scenarios/clibs.rst
+++ b/docs/scenarios/clibs.rst
@@ -1,7 +1,7 @@
Interfacing with C/C++ Libraries
================================
-.. image:: https://farm5.staticflickr.com/4173/34725951345_c8f5959a2e_k_d.jpg
+.. image:: /_static/photos/34725951345_c8f5959a2e_k_d.jpg
C Foreign Function Interface
----------------------------
@@ -105,20 +105,20 @@ Example: Overloading __repr__
:linenos:
%include "string.i"
-
+
%module myclass
%{
#include
#include "MyClass.h"
%}
-
+
%extend MyClass {
std::string __repr__()
{
return $self->getName();
}
}
-
+
%include "MyClass.h"
diff --git a/docs/scenarios/client.rst b/docs/scenarios/client.rst
index 99c7ac0..459feb2 100644
--- a/docs/scenarios/client.rst
+++ b/docs/scenarios/client.rst
@@ -1,7 +1,7 @@
Network Applications
====================
-.. image:: https://farm5.staticflickr.com/4251/34364815780_bea6614025_k_d.jpg
+.. image:: /_static/photos/34364815780_bea6614025_k_d.jpg
HTTP
::::
diff --git a/docs/scenarios/crypto.rst b/docs/scenarios/crypto.rst
index 1d61c1a..3533082 100644
--- a/docs/scenarios/crypto.rst
+++ b/docs/scenarios/crypto.rst
@@ -1,13 +1,13 @@
Cryptography
============
-.. image:: https://farm5.staticflickr.com/4220/33907152824_bf91078cc1_k_d.jpg
+.. image:: /_static/photos/33907152824_bf91078cc1_k_d.jpg
Cryptography
------------
`Cryptography `_ is an actively developed
-library that provides cryptographic recipes and primitives. It supports
+library that provides cryptographic recipes and primitives. It supports
Python 2.6-2.7, Python 3.3+ and PyPy.
@@ -60,7 +60,7 @@ Example
.. code-block:: python3
import gpg
-
+
# Encryption to public key specified in rkey.
a_key = input("Enter the fingerprint or key ID to encrypt to: ")
filename = input("Enter the filename to encrypt: ")
diff --git a/docs/scenarios/db.rst b/docs/scenarios/db.rst
index 8da9a20..af610e0 100644
--- a/docs/scenarios/db.rst
+++ b/docs/scenarios/db.rst
@@ -1,7 +1,7 @@
Databases
=========
-.. image:: https://farm5.staticflickr.com/4225/33907152464_a99fdcc8de_k_d.jpg
+.. image:: /_static/photos/33907152464_a99fdcc8de_k_d.jpg
DB-API
------
diff --git a/docs/scenarios/gui.rst b/docs/scenarios/gui.rst
index ed683d6..34c3ac1 100644
--- a/docs/scenarios/gui.rst
+++ b/docs/scenarios/gui.rst
@@ -1,7 +1,7 @@
GUI Applications
================
-.. image:: https://farm5.staticflickr.com/4250/33907143624_cd621b535c_k_d.jpg
+.. image:: /_static/photos/33907143624_cd621b535c_k_d.jpg
Alphabetical list of GUI Applications.
@@ -59,7 +59,9 @@ PySide
------
PySide is a Python binding of the cross-platform GUI toolkit Qt.
- pip install pyside
+.. code-block:: console
+
+ $ pip install pyside
https://wiki.qt.io/Category:LanguageBindings::PySide::Downloads
@@ -88,6 +90,16 @@ Qt
is widely used for developing software with a GUI but can also be used for
non-GUI applications.
+PySimpleGUI
+------
+`PySimpleGUI `_ is a wrapper for the Tkinter. The amount of code required to implement custom GUIs is much shorter using PySimpleGUI than if the same GUI were written directly using tkinter. Having Tkinter as a base results in the ability to run on a larger number of platforms than other GUI frameworks.
+
+.. code-block:: console
+
+ $ pip install pysimplegui
+
+PySimpleGUI is contained in a single PySimpleGUI.py file. Should pip installation be impossible, pasting the PySimpleGUI.py file into a project's folder is all that's required to import and begin using.
+
Toga
----
`Toga `_ is a Python native, OS
diff --git a/docs/scenarios/imaging.rst b/docs/scenarios/imaging.rst
index bcd02e6..ff62080 100644
--- a/docs/scenarios/imaging.rst
+++ b/docs/scenarios/imaging.rst
@@ -2,7 +2,7 @@
Image Manipulation
==================
-.. image:: https://farm5.staticflickr.com/4157/34575689432_3de8e9a348_k_d.jpg
+.. image:: /_static/photos/34575689432_3de8e9a348_k_d.jpg
Most image processing and manipulation techniques can be carried out
effectively using two libraries: Python Imaging Library (PIL) and OpenSource
diff --git a/docs/scenarios/json.rst b/docs/scenarios/json.rst
index 55de04e..d555067 100644
--- a/docs/scenarios/json.rst
+++ b/docs/scenarios/json.rst
@@ -1,7 +1,7 @@
JSON
====
-.. image:: https://farm5.staticflickr.com/4174/33928819683_97b5c6a184_k_d.jpg
+.. image:: /_static/photos/33928819683_97b5c6a184_k_d.jpg
The `json `_ library can parse
JSON from strings or files. The library parses JSON into a Python dictionary
@@ -60,7 +60,7 @@ You can start using simplejson when the json library is not available by
importing simplejson under a different name:
.. code-block:: python
-
+
import simplejson as json
After importing simplejson as json, the above examples will all work as if you
diff --git a/docs/scenarios/ml.rst b/docs/scenarios/ml.rst
index fde4542..30eefcb 100644
--- a/docs/scenarios/ml.rst
+++ b/docs/scenarios/ml.rst
@@ -2,9 +2,9 @@
Machine Learning
================
-.. image:: https://farm4.staticflickr.com/3954/34018729885_002ced9b54_k_d.jpg
+.. image:: /_static/photos/34018729885_002ced9b54_k_d.jpg
-Python has a vast number of libraries for data analysis, statistics and Machine Learning itself, making it a language of choice for many data scientists.
+Python has a vast number of libraries for data analysis, statistics and Machine Learning itself, making it a language of choice for many data scientists.
Some widely used packages for Machine Learning and other Data Science applications are enlisted below.
@@ -45,7 +45,7 @@ Installation
Through PyPI:
.. code-block:: python
-
+
pip install -U scikit-learn
Through conda:
@@ -61,28 +61,28 @@ Example
For this example, we train a simple classifier on the `Iris dataset `_, which comes bundled in with scikit-learn.
-The dataset takes four features of flowers: sepal length, sepal width, petal length and petal width, and classifies them into three flower species (labels): setosa, versicolor or virginica. The labels have been represented as numbers in the dataset: 0 (setosa), 1 (versicolor) and 2 (virginica).
+The dataset takes four features of flowers: sepal length, sepal width, petal length and petal width, and classifies them into three flower species (labels): setosa, versicolor or virginica. The labels have been represented as numbers in the dataset: 0 (setosa), 1 (versicolor) and 2 (virginica).
We shuffle the Iris dataset, and divide it into separate training and testing sets: keeping the last 10 data points for testing and rest for training. We then train the classifier on the training set, and predict on the testing set.
.. code-block:: python
- from sklearn.datasets import load_iris
+ from sklearn.datasets import load_iris
from sklearn import tree
from sklearn.metrics import accuracy_score
import numpy as np
#loading the iris dataset
- iris = load_iris()
+ iris = load_iris()
x = iris.data #array of the data
y = iris.target #array of labels (i.e answers) of each data entry
#getting label names i.e the three flower species
- y_names = iris.target_names
+ y_names = iris.target_names
#taking random indices to split the dataset into train and test
- test_ids = np.random.permutation(len(x))
+ test_ids = np.random.permutation(len(x))
#splitting data and labels into train and test
#keeping last 10 entries for testing, rest for training
diff --git a/docs/scenarios/network.rst b/docs/scenarios/network.rst
index 0aa5860..1cea42d 100644
--- a/docs/scenarios/network.rst
+++ b/docs/scenarios/network.rst
@@ -1,7 +1,7 @@
Networking
==========
-.. image:: https://farm3.staticflickr.com/2892/34151833832_6bdfd930af_k_d.jpg
+.. image:: /_static/photos/34151833832_6bdfd930af_k_d.jpg
Twisted
-------
@@ -35,4 +35,4 @@ gevent
`gevent `_ is a coroutine-based Python networking
library that uses greenlets to provide a high-level synchronous API on top of
-the libev event loop.
+the libev event loop.
diff --git a/docs/scenarios/scientific.rst b/docs/scenarios/scientific.rst
index f81ecef..7276420 100644
--- a/docs/scenarios/scientific.rst
+++ b/docs/scenarios/scientific.rst
@@ -2,7 +2,7 @@
Scientific Applications
=======================
-.. image:: https://farm3.staticflickr.com/2890/33925223870_97e44f5629_k_d.jpg
+.. image:: /_static/photos/33925223870_97e44f5629_k_d.jpg
Context
:::::::
diff --git a/docs/scenarios/scrape.rst b/docs/scenarios/scrape.rst
index e329782..01d56f4 100644
--- a/docs/scenarios/scrape.rst
+++ b/docs/scenarios/scrape.rst
@@ -1,7 +1,7 @@
HTML Scraping
=============
-.. image:: https://farm3.staticflickr.com/2900/34268661876_442428e122_k_d.jpg
+.. image:: /_static/photos/34268661876_442428e122_k_d.jpg
Web Scraping
------------
@@ -105,5 +105,3 @@ using Python or we can save it to a file and share it with the world.
Some more cool ideas to think about are modifying this script to iterate
through the rest of the pages of this example dataset, or rewriting this
application to use threads for improved speed.
-
-If you want to learn how to import data using python - this `DataCamp course on Importing Data `_ is a great place to start.
diff --git a/docs/scenarios/serialization.rst b/docs/scenarios/serialization.rst
index 8a950ba..5d5f415 100644
--- a/docs/scenarios/serialization.rst
+++ b/docs/scenarios/serialization.rst
@@ -2,41 +2,41 @@
Data Serialization
==================
-.. image:: https://farm3.staticflickr.com/2927/33467946364_3e59bd376a_k_d.jpg
+.. image:: /_static/photos/33467946364_3e59bd376a_k_d.jpg
What is data serialization?
---------------------------
-Data serialization is the concept of converting structured data into a format
-that allows it to be shared or stored in such a way that its original
-structure to be recovered. In some cases, the secondary intention of data
-serialization is to minimize the size of the serialized data which then
+Data serialization is the concept of converting structured data into a format
+that allows it to be shared or stored in such a way that its original
+structure to be recovered. In some cases, the secondary intention of data
+serialization is to minimize the size of the serialized data which then
minimizes disk space or bandwidth requirements.
Pickle
------
-The native data serialization module for Python is called `Pickle
-`_.
+The native data serialization module for Python is called `Pickle
+`_.
Here's an example:
.. code-block:: python
-
+
import pickle
-
+
#Here's an example dict
grades = { 'Alice': 89, 'Bob': 72, 'Charles': 87 }
-
+
#Use dumps to convert the object to a serialized string
serial_grades = pickle.dumps( grades )
-
- #Use loads to de-serialize an object
+
+ #Use loads to de-serialize an object
received_grades = pickle.loads( serial_grades )
Protobuf
--------
-If you're looking for a serialization module that has support in multiple
-languages, Google's `Protobuf
-`_ library is an option.
+If you're looking for a serialization module that has support in multiple
+languages, Google's `Protobuf
+`_ library is an option.
diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst
index 18e84ec..dcb141a 100644
--- a/docs/scenarios/speed.rst
+++ b/docs/scenarios/speed.rst
@@ -1,7 +1,7 @@
Speed
=====
-.. image:: https://farm3.staticflickr.com/2826/33175625804_e225b90f3e_k_d.jpg
+.. image:: /_static/photos/33175625804_e225b90f3e_k_d.jpg
CPython, the most commonly used implementation of Python, is slow for CPU bound
tasks. `PyPy`_ is fast.
@@ -234,14 +234,14 @@ Concurrent.futures
The `concurrent.futures`_ module is a module in the standard library that
provides a "high-level interface for asynchronously executing callables". It
abstracts away a lot of the more complicated details about using multiple
-threads or processes for concurrency, and allows the user to focus on
+threads or processes for concurrency, and allows the user to focus on
accomplishing the task at hand.
The `concurrent.futures`_ module exposes two main classes, the
`ThreadPoolExecutor` and the `ProcessPoolExecutor`. The ThreadPoolExecutor
will create a pool of worker threads that a user can submit jobs to. These jobs
will then be executed in another thread when the next worker thread becomes
-available.
+available.
The ProcessPoolExecutor works in the same way, except instead of using multiple
threads for its workers, it will use multiple processes. This makes it possible
@@ -275,7 +275,7 @@ everything in parallel. :
# Do something with the result
print(page.text)
-For even more control, the `submit(func, *args, **kwargs)` method will schedule
+For even more control, the `submit(func, *args, **kwargs)` method will schedule
a callable to be executed ( as `func(*args, **kwargs)`) and returns a `Future`_
object that represents the execution of the callable.
@@ -389,9 +389,9 @@ still alive (because the join call timed out):
Because multiple threads have access to the same section of memory, sometimes
there might be situations where two or more threads are trying to write to the
same resource at the same time or where the output is dependent on the sequence
-or timing of certain events. This is called a `data race`_ or race condition.
+or timing of certain events. This is called a `data race`_ or race condition.
When this happens, the output will be garbled or you may encounter problems
-which are difficult to debug. A good example is this `stackoverflow post`_.
+which are difficult to debug. A good example is this `stackoverflow post`_.
The way this can be avoided is by using a `Lock`_ that each thread needs to
acquire before writing to a shared resource. Locks can be acquired and released
@@ -412,7 +412,7 @@ through either the contextmanager protocol (`with` statement), or by using
def monitor_website(some_website):
"""
- Monitor a website and then if there are any changes,
+ Monitor a website and then if there are any changes,
log them to disk.
"""
while True:
@@ -429,7 +429,7 @@ Here, we have a bunch of threads checking for changes on a list of sites and
whenever there are any changes, they attempt to write those changes to a file
by calling `log(changes)`. When `log()` is called, it will wait to acquire
the lock with `with file_lock:`. This ensures that at any one time, only one
-thread is writing to the file.
+thread is writing to the file.
Spawning Processes
------------------
diff --git a/docs/scenarios/web.rst b/docs/scenarios/web.rst
index 7fbb8b7..1060487 100644
--- a/docs/scenarios/web.rst
+++ b/docs/scenarios/web.rst
@@ -2,7 +2,7 @@
Web Applications & Frameworks
=============================
-.. image:: https://farm3.staticflickr.com/2891/34309496175_b82d104282_k_d.jpg
+.. image:: /_static/photos/34309496175_b82d104282_k_d.jpg
As a powerful scripting language adapted to both fast prototyping
and bigger projects, Python is widely used in web application
@@ -51,7 +51,7 @@ Development Web Server
Django
------
-`Django `_ is a "batteries included" web
+`Django `_ is a "batteries included" web
application framework, and is an excellent choice for creating content-oriented
websites. By providing many utilities and patterns out of the box, Django aims
to make it possible to build complex, database-backed web applications quickly,
@@ -91,6 +91,19 @@ suit your needs. Or, you can easily use any library you want yourself!
Flask is default choice for any Python web application that isn't a good
fit for Django.
+Falcon
+------
+
+`Falcon `_ is a good choice when your goal is
+to build RESTful API microservices that are fast and scalable.
+
+It is a reliable, high-performance Python web framework for building large-scale
+app backends and microservices. Falcon encourages the REST architectural style of
+mapping URIs to resources, trying to do as little as possible while remaining highly effective.
+
+Falcon highlights four main focuses: speed, reliability, flexibility and debuggability.
+It implements HTTP through "responders" such as ``on_get()``, ``on_put()``, etc.
+These responders receive intuitive request and response objects.
Tornado
--------
@@ -107,12 +120,26 @@ Pyramid
`Pyramid `_ is a very flexible framework with a heavy
focus on modularity. It comes with a small number of libraries ("batteries")
-built-in, and encourages users to extend its base functionality.
+built-in, and encourages users to extend its base functionality. A set of
+provided cookiecutter templates helps making new project decisions for users.
+It poweres one of the most important parts of python infrastucture
+`PyPI `_.
Pyramid does not have a large user base, unlike Django and Flask. It's a
capable framework, but not a very popular choice for new Python web
applications today.
+Masonite
+--------
+
+`Masonite `_ is a modern and developer centric, "batteries included", web framework.
+
+The Masonite framework follows the MVC (Model-View-Controller) architecture pattern and is heavily inspired by frameworks such as Rails and Laravel, so if you are coming to Python from a Ruby or PHP background then you will feel right at home!
+
+Masonite comes with a lot of functionality out of the box including a powerful IOC container with auto resolving dependency injection, craft command line tools and the Orator active record style ORM.
+
+Masonite is perfect for beginners or experienced developers alike and works hard to be fast and easy from install through to deployment. Try it once and you’ll fall in love.
+
Web Servers
:::::::::::
@@ -142,7 +169,7 @@ servers and provide top performance [3]_.
Gunicorn
--------
-`Gunicorn `_ (Green Unicorn) is a pure-python WSGI
+`Gunicorn `_ (Green Unicorn) is a pure-python WSGI
server used to serve Python applications. Unlike other Python web servers,
it has a thoughtful user-interface, and is extremely easy to use and
configure.
@@ -210,14 +237,14 @@ details.
Heroku
------
-`Heroku `_ offers first-class support for
+`Heroku `_ offers first-class support for
Python 2.7–3.5 applications.
Heroku supports all types of Python web applications, servers, and frameworks.
Applications can be developed on Heroku for free. Once your application is
ready for production, you can upgrade to a Hobby or Professional application.
-Heroku maintains `detailed articles `_
+Heroku maintains `detailed articles `_
on using Python with Heroku, as well as `step-by-step instructions
`_ on
how to set up your first application.
@@ -227,7 +254,7 @@ Heroku is the recommended PaaS for deploying Python web applications today.
Eldarion
--------
-`Eldarion `_ (formely known as Gondor) is a PaaS powered
+`Eldarion `_ (formely known as Gondor) is a PaaS powered
by Kubernetes, CoreOS, and Docker. They support any WSGI application and have a
guide on deploying `Django projects `_.
@@ -390,12 +417,12 @@ Chameleon
---------
`Chameleon `_ Page Templates are an HTML/XML template
-engine implementation of the `Template Attribute Language (TAL) `_,
+engine implementation of the `Template Attribute Language (TAL) `_,
`TAL Expression Syntax (TALES) `_,
and `Macro Expansion TAL (Metal) `_ syntaxes.
Chameleon is available for Python 2.5 and up (including 3.x and pypy), and
-is commonly used by the `Pyramid Framework `_.
+is commonly used by the `Pyramid Framework `_.
Page Templates add within your document structure special element attributes
and text markup. Using a set of simple language constructs, you control the
@@ -492,5 +519,5 @@ Mako is well respected within the Python web community.
.. rubric:: References
.. [1] `The mod_python project is now officially dead `_
-.. [2] `mod_wsgi vs mod_python `_
+.. [2] `mod_wsgi vs mod_python `_
.. [3] `Benchmark of Python WSGI Servers `_
diff --git a/docs/scenarios/xml.rst b/docs/scenarios/xml.rst
index 8af9e41..51a784d 100644
--- a/docs/scenarios/xml.rst
+++ b/docs/scenarios/xml.rst
@@ -1,7 +1,7 @@
XML parsing
===========
-.. image:: https://farm3.staticflickr.com/2808/33888714601_a1f7d020a2_k_d.jpg
+.. image:: /_static/photos/33888714601_a1f7d020a2_k_d.jpg
untangle
--------
diff --git a/docs/shipping/freezing.rst b/docs/shipping/freezing.rst
index f0b73b4..4514a85 100644
--- a/docs/shipping/freezing.rst
+++ b/docs/shipping/freezing.rst
@@ -4,27 +4,27 @@
Freezing Your Code
==================
-.. image:: https://farm5.staticflickr.com/4227/33907151034_e0a9e53402_k_d.jpg
+.. image:: /_static/photos/33907151034_e0a9e53402_k_d.jpg
-"Freezing" your code is creating a single-file executable file to distribute
-to end-users, that contains all of your application code as well as the
+"Freezing" your code is creating a single-file executable file to distribute
+to end-users, that contains all of your application code as well as the
Python interpreter.
Applications such as 'Dropbox', 'Eve Online', 'Civilization IV', and
BitTorrent clients do this.
The advantage of distributing this way is that your application will "just work",
-even if the user doesn't already have the required version of Python (or any)
+even if the user doesn't already have the required version of Python (or any)
installed. On Windows, and even on many Linux distributions and OS X, the right
version of Python will not already be installed.
-Besides, end-user software should always be in an executable format. Files
-ending in ``.py`` are for software engineers and system administrators.
+Besides, end-user software should always be in an executable format. Files
+ending in ``.py`` are for software engineers and system administrators.
-One disadvantage of freezing is that it will increase the size of your
+One disadvantage of freezing is that it will increase the size of your
distribution by about 2–12MB. Also, you will be responsible for shipping
-updated versions of your application when security vulnerabilities to
-Python are patched.
+updated versions of your application when security vulnerabilities to
+Python are patched.
Alternatives to Freezing
------------------------
@@ -75,34 +75,34 @@ Prerequisite is to install :ref:`Python, Setuptools and pywin32 dependency on Wi
1. Install :code:`bbfreeze`:
.. code-block:: console
-
+
$ pip install bbfreeze
-
+
2. Write most basic :file:`bb_setup.py`
.. code-block:: python
from bbfreeze import Freezer
-
+
freezer = Freezer(distdir='dist')
freezer.addScript('foobar.py', gui_only=True)
freezer()
-
+
.. note::
-
+
This will work for the most basic one file scripts. For more advanced freezing you will have to provide
include and exclude paths like so
-
+
.. code-block:: python
-
+
freezer = Freezer(distdir='dist', includes=['my_code'], excludes=['docs'])
3. (Optionally) include icon
.. code-block:: python
-
+
freezer.setIcon('my_awesome_icon.ico')
-
+
4. Provide the Microsoft Visual C runtime DLL for the freezer. It might be possible to append your :code:`sys.path`
with Microsoft Visual Studio path but I find it easier to drop :file:`msvcp90.dll` in the same folder where your script
resides.
@@ -110,13 +110,13 @@ resides.
5. Freeze!
.. code-block:: console
-
+
$ python bb_setup.py
py2exe
~~~~~~
-Prerequisite is to install :ref:`Python on Windows `.
+Prerequisite is to install :ref:`Python on Windows `. The last release of py2exe is from the year 2014. There is not active development.
1. Download and install http://sourceforge.net/projects/py2exe/files/py2exe/
@@ -204,7 +204,7 @@ To create a standalone windowed OS X application, use the :code:`--windowed` opt
This creates a :code:`script.app` in the :code:`dist` folder. Make sure to use GUI packages in your Python code, like `PyQt `_ or `PySide `_, to control the graphical parts of the app.
-There are several options in :code:`script.spec` related to Mac OS X app bundles `here `_. For example, to specify an icon for the app, use the :code:`icon=\path\to\icon.icns` option.
+There are several options in :code:`script.spec` related to Mac OS X app bundles `here `_. For example, to specify an icon for the app, use the :code:`icon=\path\to\icon.icns` option.
Linux
diff --git a/docs/shipping/packaging.rst b/docs/shipping/packaging.rst
index 7e55d42..79d2cc0 100644
--- a/docs/shipping/packaging.rst
+++ b/docs/shipping/packaging.rst
@@ -4,7 +4,7 @@
Packaging Your Code
===================
-.. image:: https://farm5.staticflickr.com/4325/36137234682_be6898bf57_k_d.jpg
+.. image:: /_static/photos/36137234682_be6898bf57_k_d.jpg
Package your code to share it with other developers. For example
to share a library for other developers to use in their application,
diff --git a/docs/starting/install/linux.rst b/docs/starting/install/linux.rst
index de831b6..65cff2a 100644
--- a/docs/starting/install/linux.rst
+++ b/docs/starting/install/linux.rst
@@ -3,7 +3,7 @@
Installing Python 2 on Linux
=============================
-.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
+.. image:: /_static/photos/34435688560_4cc2a7bcbb_k_d.jpg
.. note::
Check out our :ref:`guide for installing Python 3 on Linux`.
diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst
index 9d24242..5cd3db3 100644
--- a/docs/starting/install/osx.rst
+++ b/docs/starting/install/osx.rst
@@ -3,7 +3,7 @@
Installing Python 2 on Mac OS X
===============================
-.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
+.. image:: /_static/photos/34435688560_4cc2a7bcbb_k_d.jpg
.. note::
Check out our :ref:`guide for installing Python 3 on OS X`.
diff --git a/docs/starting/install/win.rst b/docs/starting/install/win.rst
index e930b46..5b807fd 100644
--- a/docs/starting/install/win.rst
+++ b/docs/starting/install/win.rst
@@ -3,12 +3,12 @@
Installing Python 2 on Windows
==============================
-.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
+.. image:: /_static/photos/34435688560_4cc2a7bcbb_k_d.jpg
.. note::
Check out our :ref:`guide for installing Python 3 on Windows`.
-First, download the `latest version `_
+First, download the `latest version `_
of Python 2.7 from the official website. If you want to be sure you are installing a fully
up-to-date version, click the Downloads > Windows link from the home page of the
`Python.org web site `_ .
diff --git a/docs/starting/install3/linux.rst b/docs/starting/install3/linux.rst
index 1c6d67d..fa1b01c 100644
--- a/docs/starting/install3/linux.rst
+++ b/docs/starting/install3/linux.rst
@@ -3,7 +3,7 @@
Installing Python 3 on Linux
============================
-.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+.. image:: /_static/photos/34435689480_2e6f358510_k_d.jpg
This document describes how to install Python 3.6 on Ubuntu Linux machines.
@@ -93,7 +93,7 @@ care about that.
Pipenv & Virtual Environments
-----------------------------
-The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
+The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projects
in separate places, by creating virtual Python environments for them. It solves the
diff --git a/docs/starting/install3/osx.rst b/docs/starting/install3/osx.rst
index b848219..d3f2367 100644
--- a/docs/starting/install3/osx.rst
+++ b/docs/starting/install3/osx.rst
@@ -5,7 +5,7 @@
Installing Python 3 on Mac OS X
===============================
-.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+.. image:: /_static/photos/34435689480_2e6f358510_k_d.jpg
The latest version of Mac OS X, High Sierra, **comes with Python 2.7 out of the box**.
@@ -112,13 +112,13 @@ The rest of the guide will assume that ``python`` references Python 3.
# Do I have a Python 3 installed?
$ python --version
- Python 3.6.4 # Success!
- # If you still see 2.7 ensure in PATH /usr/local/bin/ takes precedence over /usr/bin/
+ Python 3.7.1 # Success!
+
Pipenv & Virtual Environments
-----------------------------
-The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
+The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projects
in separate places, by creating virtual Python environments for them. It solves the
diff --git a/docs/starting/install3/win.rst b/docs/starting/install3/win.rst
index ddddad5..1a93221 100644
--- a/docs/starting/install3/win.rst
+++ b/docs/starting/install3/win.rst
@@ -3,7 +3,7 @@
Installing Python 3 on Windows
==============================
-.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+.. image:: /_static/photos/34435689480_2e6f358510_k_d.jpg
First, follow the installation instructions for `Chocolatey `_.
It's a community system packager manager for Windows 7+. (It's very much like Homebrew on OSX.)
diff --git a/docs/starting/installation.rst b/docs/starting/installation.rst
index bb84c27..d48165f 100644
--- a/docs/starting/installation.rst
+++ b/docs/starting/installation.rst
@@ -3,7 +3,7 @@
Properly Installing Python
==========================
-.. image:: https://farm5.staticflickr.com/4303/36137232412_fdcb0f84eb_k_d.jpg
+.. image:: /_static/photos/36137232412_fdcb0f84eb_k_d.jpg
There's a good chance that you already have Python on your operating system.
@@ -16,8 +16,8 @@ other third-party Python libraries.
.. note:: The use of **Python 3** is *highly* preferred over Python 2. Consider upgrading your applications and infrastructure if you find yourself *still* using Python 2 in production today. If you are using Python 3, congratulations — you are indeed a person of excellent taste.
—*Kenneth Reitz*
-
-
+
+
Installation Guides
-------------------
diff --git a/docs/starting/which-python.rst b/docs/starting/which-python.rst
index 155eadb..85f3523 100644
--- a/docs/starting/which-python.rst
+++ b/docs/starting/which-python.rst
@@ -1,7 +1,7 @@
-Picking an Python Interpreter (3 vs. 2)
-=======================================
+Picking a Python Interpreter (3 vs 2)
+=====================================
-.. image:: https://farm5.staticflickr.com/4265/34484834733_5b80f65ab1_k_d.jpg
+.. image:: /_static/photos/34484834733_5b80f65ab1_k_d.jpg
.. _which-python:
diff --git a/docs/writing/documentation.rst b/docs/writing/documentation.rst
index d251a0b..a712db8 100644
--- a/docs/writing/documentation.rst
+++ b/docs/writing/documentation.rst
@@ -1,7 +1,7 @@
Documentation
=============
-.. image:: https://farm5.staticflickr.com/4279/35620636012_f66aa88f93_k_d.jpg
+.. image:: /_static/photos/35620636012_f66aa88f93_k_d.jpg
Readability is a primary focus for Python developers, in both project
and code documentation. Following some simple best practices can save
@@ -67,10 +67,10 @@ There is also **great**, **free** hosting for your Sphinx_ docs:
your source repository so that rebuilding your documentation will
happen automatically.
-When run, Sphinx_ will import your code and using Python's introspection
+When run, Sphinx_ will import your code and using Python's introspection
features it will extract all function, method and class signatures. It will
also extract the accompanying docstrings, and compile it all into well
-structured and easily readable documentation for your project.
+structured and easily readable documentation for your project.
.. note::
@@ -146,7 +146,7 @@ their source code, and as a side effect, it also ensures that their code is
tested and works.
::
-
+
def my_function(a, b):
"""
>>> my_function(2, 3)
@@ -175,14 +175,14 @@ comment block is a programmer's note. The docstring describes the
Unlike block comments, docstrings are built into the Python language itself.
This means you can use all of Python's powerful introspection capabilities to
access docstrings at runtime, compared with comments which are optimised out.
-Docstrings are accessible from both the `__doc__` dunder attribute for almost
+Docstrings are accessible from both the `__doc__` dunder attribute for almost
every Python object, as well as with the built in `help()` function.
While block comments are usually used to explain *what* a section of code is
doing, or the specifics of an algorithm, docstrings are more intended for
explaining to other users of your code (or you in 6 months time) *how* a
-particular function can be used and the general purpose of a function, class,
-or module.
+particular function can be used and the general purpose of a function, class,
+or module.
Writing Docstrings
~~~~~~~~~~~~~~~~~~
@@ -196,19 +196,19 @@ really obvious cases, such as::
return a + b
The docstring should describe the function in a way that is easy to understand.
-For simple cases like trivial functions and classes, simply embedding the
-function's signature (i.e. `add(a, b) -> result`) in the docstring is
-unnecessary. This is because with Python's `inspect` module, it is already
+For simple cases like trivial functions and classes, simply embedding the
+function's signature (i.e. `add(a, b) -> result`) in the docstring is
+unnecessary. This is because with Python's `inspect` module, it is already
quite easy to find this information if needed, and it is also readily available
-by reading the source code.
+by reading the source code.
-In larger or more complex projects however, it is often a good idea to give
-more information about a function, what it does, any exceptions it may raise,
+In larger or more complex projects however, it is often a good idea to give
+more information about a function, what it does, any exceptions it may raise,
what it returns, or relevant details about the parameters.
For more detailed documentation of code a popular style is the one used for the
Numpy project, often called `Numpy style`_ docstrings. While it can take up more
-lines than the previous example, it allows the developer to include a lot
+lines than the previous example, it allows the developer to include a lot
more information about a method, function, or class. ::
def random_number_generator(arg1, arg2):
diff --git a/docs/writing/gotchas.rst b/docs/writing/gotchas.rst
index 76af626..b230640 100644
--- a/docs/writing/gotchas.rst
+++ b/docs/writing/gotchas.rst
@@ -1,7 +1,7 @@
Common Gotchas
==============
-.. image:: https://farm5.staticflickr.com/4163/34435688380_b5a740762b_k_d.jpg
+.. image:: /_static/photos/34435688380_b5a740762b_k_d.jpg
For the most part, Python aims to be a clean and consistent language that
avoids surprises. However, there are a few cases that can be confusing to
diff --git a/docs/writing/license.rst b/docs/writing/license.rst
index dd5fe3b..c48194e 100644
--- a/docs/writing/license.rst
+++ b/docs/writing/license.rst
@@ -1,7 +1,7 @@
Choosing a License
==================
-.. image:: https://farm5.staticflickr.com/4228/33907149294_82d7535a6c_k_d.jpg
+.. image:: /_static/photos/33907149294_82d7535a6c_k_d.jpg
Your source publication *needs* a license. In the US, if no license is
specified, users have no legal right to download, modify, or distribute.
diff --git a/docs/writing/logging.rst b/docs/writing/logging.rst
index 184e9e8..2162359 100644
--- a/docs/writing/logging.rst
+++ b/docs/writing/logging.rst
@@ -1,7 +1,7 @@
Logging
=======
-.. image:: https://farm5.staticflickr.com/4246/35254379756_c9fe23f843_k_d.jpg
+.. image:: /_static/photos/35254379756_c9fe23f843_k_d.jpg
The :mod:`logging` module has been a part of Python's Standard Library since
version 2.3. It is succinctly described in :pep:`282`. The documentation
@@ -37,14 +37,14 @@ Other reasons why logging is better than ``print``:
Logging in a Library
--------------------
-Notes for `configuring logging for a library`_ are in the
+Notes for `configuring logging for a library`_ are in the
`logging tutorial`_. Because the *user*, not the library, should
dictate what happens when a logging event occurs, one admonition bears
repeating:
.. note::
It is strongly advised that you do not add any handlers other than
- NullHandler to your library’s loggers.
+ NullHandler to your library’s loggers.
Best practice when instantiating loggers in a library is to only create them
@@ -100,23 +100,23 @@ section of the `logging tutorial`_.
[loggers]
keys=root
-
+
[handlers]
keys=stream_handler
-
+
[formatters]
keys=formatter
-
+
[logger_root]
level=DEBUG
handlers=stream_handler
-
+
[handler_stream_handler]
class=StreamHandler
level=DEBUG
formatter=formatter
args=(sys.stderr,)
-
+
[formatter_formatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
@@ -131,7 +131,7 @@ Then use :meth:`logging.config.fileConfig` in the code:
fileConfig('logging_config.ini')
logger = logging.getLogger()
logger.debug('often makes a very good meal of %s', 'visiting tourists')
-
+
Example Configuration via a Dictionary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/writing/reading.rst b/docs/writing/reading.rst
index 0b6486d..5c53d97 100644
--- a/docs/writing/reading.rst
+++ b/docs/writing/reading.rst
@@ -1,23 +1,11 @@
Reading Great Code
==================
-.. image:: https://farm5.staticflickr.com/4221/34689452831_93d7fd0571_k_d.jpg
-
-One of the core tenets behind the design of Python is creating
-readable code. The motivation behind this design is simple: The number
-one thing that Python programmers do is read code.
+.. image:: /_static/photos/34689452831_93d7fd0571_k_d.jpg
One of the secrets of becoming a great Python programmer is to read,
understand, and comprehend excellent code.
-.. raw:: html
-
-
-
-
Excellent code typically follows the guidelines outlined in
:ref:`code_style`, and does its best to express a clear and concise
intent to the reader.
@@ -36,12 +24,12 @@ reading. Each one of these projects is a paragon of Python coding.
- `Diamond `_
Diamond is a python daemon that collects metrics
and publishes them to Graphite or other backends.
- It is capable of collecting cpu, memory, network, i/o, load and disk metrics.
+ It is capable of collecting CPU, memory, network, I/O, load, and disk metrics.
Additionally, it features an API for implementing custom collectors
for gathering metrics from almost any source.
- `Werkzeug `_
- Werkzeug started as simple collection of various utilities for WSGI
+ Werkzeug started as a simple collection of various utilities for WSGI
applications and has become one of the most advanced WSGI utility modules.
It includes a powerful debugger, full-featured request and response objects,
HTTP utilities to handle entity tags, cache control headers, HTTP dates,
diff --git a/docs/writing/structure.rst b/docs/writing/structure.rst
index a2d5316..c59f4dd 100644
--- a/docs/writing/structure.rst
+++ b/docs/writing/structure.rst
@@ -1,7 +1,7 @@
Structuring Your Project
========================
-.. image:: https://farm5.staticflickr.com/4203/33907151224_0574e7dfc2_k_d.jpg
+.. image:: /_static/photos/33907151224_0574e7dfc2_k_d.jpg
By "structure" we mean the decisions you make concerning
how your project best meets its objective. We need to consider how to
@@ -395,9 +395,9 @@ folder named :file:`my` which is not the case. There is an
dot notation should be used in the Python docs.
If you'd like you could name your module :file:`my_spam.py`, but even our
-friend the underscore should not be seen often in module names. However, using other
-characters (spaces or hyphens) in module names will prevent importing
-(- is the subtract operator), so try to keep module names short so there is
+friend the underscore should not be seen often in module names. However, using other
+characters (spaces or hyphens) in module names will prevent importing
+(- is the subtract operator), so try to keep module names short so there is
no need to separate words. And, most of all, don't namespace with underscores, use submodules instead.
.. code-block:: python
@@ -799,7 +799,7 @@ its parts, it is much more efficient to accumulate the parts in a list,
which is mutable, and then glue ('join') the parts together when the
full string is needed. One thing to notice, however, is that list
comprehensions are better and faster than constructing a list in a loop
-with calls to ``append()``.
+with calls to ``append()``.
One other option is using the map function, which can 'map' a function
('str') to an iterable ('range(20)'). This results in a map object,
@@ -833,14 +833,14 @@ The map function can be even faster than a list comprehension in some cases.
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)
-
+
**Best**
.. code-block:: python
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = map(str, range(20))
- print "".join(nums)
+ print "".join(nums)
One final thing to mention about strings is that using ``join()`` is not always
best. In the instances where you are creating a new string from a pre-determined
diff --git a/docs/writing/style.rst b/docs/writing/style.rst
index abd0af4..9fde6b9 100644
--- a/docs/writing/style.rst
+++ b/docs/writing/style.rst
@@ -3,7 +3,7 @@
Code Style
==========
-.. image:: https://farm5.staticflickr.com/4223/33907150054_5ee79e8940_k_d.jpg
+.. image:: /_static/photos/33907150054_5ee79e8940_k_d.jpg
If you ask Python programmers what they like most about Python, they will
often cite its high readability. Indeed, a high level of readability
@@ -581,43 +581,124 @@ provide a powerful, concise way to work with lists. Also, the :py:func:`map` and
:py:func:`filter` functions can perform operations on lists using a different,
more concise syntax.
+Filtering a list
+~~~~~~~~~~~~~~~~
+
**Bad**:
+Never remove items from a list while you are iterating through it.
+
.. code-block:: python
# Filter elements greater than 4
a = [3, 4, 5]
- b = []
for i in a:
if i > 4:
- b.append(i)
+ a.remove(i)
+
+Don't make multiple passes through the list.
+
+.. code-block:: python
+
+ while i in a:
+ a.remove(i)
**Good**:
+Python has a few standard ways of filtering lists.
+The approach you use depends on
+
+* Python 2.x vs. 3.x
+* Lists vs. iterators
+* Possible side effects of modifying the original list
+
+Python 2.x vs. 3.x
+::::::::::::::::::
+
+Starting with Python 3.0, the :py:func:`filter` function returns an iterator instead of a list.
+Wrap it in :py:func:`list` if you truly need a list.
+
.. code-block:: python
- a = [3, 4, 5]
- b = [i for i in a if i > 4]
- # Or:
- b = filter(lambda x: x > 4, a)
+ list(filter(...))
+List comprehensions and generator expressions work the same in both 2.x and 3.x (except that comprehensions in 2.x "leak" variables into the enclosing namespace)
+
+ * comprehensions create a new list object
+ * generators iterate over the original list
+
+The :py:func:`filter` function
+
+ * in 2.x returns a list (use itertools.ifilter if you want an iterator)
+ * in 3.x returns an iterator
+
+Lists vs. iterators
+:::::::::::::::::::
+
+Creating a new list requires more work and uses more memory. If you a just going to loop through the new list, consider using an iterator instead.
+
+.. code-block:: python
+
+ # comprehensions create a new list object
+ filtered_values = [value for value in sequence if value != x]
+ # Or (2.x)
+ filtered_values = filter(lambda i: i != x, sequence)
+
+ # generators don't create another list
+ filtered_values = (value for value in sequence if value != x)
+ # Or (3.x)
+ filtered_values = filter(lambda i: i != x, sequence)
+ # Or (2.x)
+ filtered_values = itertools.ifilter(lambda i: i != x, sequence)
+
+
+
+Possible side effects of modifying the original list
+::::::::::::::::::::::::::::::::::::::::::::::::::::
+
+Modifying the original list can be risky if there are other variables referencing it. But you can use *slice assignment* if you really want to do that.
+
+.. code-block:: python
+
+ # replace the contents of the original list
+ sequence[::] = [value for value in sequence if value != x]
+ # Or
+ sequence[::] = (value for value in sequence if value != x)
+ # Or
+ sequence[::] = filter(lambda value: value != x, sequence)
+
+
+Modifying the values in a list
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Bad**:
+Remember that assignment never creates a new object. If two or more variables refer to the same list, changing one of them changes them all.
+
.. code-block:: python
# Add three to all list members.
a = [3, 4, 5]
+ b = a # a and b refer to the same list object
+
for i in range(len(a)):
- a[i] += 3
+ a[i] += 3 # b[i] also changes
**Good**:
+It's safer to create a new list object and leave the original alone.
+
.. code-block:: python
a = [3, 4, 5]
+ b = a
+
+ # assign the variable "a" to a new list without changing "b"
a = [i + 3 for i in a]
- # Or:
+ # Or (Python 2.x):
a = map(lambda i: i + 3, a)
+ # Or (Python 3.x)
+ a = list(map(lambda i: i + 3, a))
+
Use :py:func:`enumerate` keep a count of your place in the list.
diff --git a/docs/writing/tests.rst b/docs/writing/tests.rst
index 32c6e55..7da42e7 100644
--- a/docs/writing/tests.rst
+++ b/docs/writing/tests.rst
@@ -1,11 +1,11 @@
Testing Your Code
=================
-.. image:: https://farm5.staticflickr.com/4166/34435687940_8f73fc1fa6_k_d.jpg
+.. image:: /_static/photos/34435687940_8f73fc1fa6_k_d.jpg
Testing your code is very important.
-Getting used to writing testing code and running this code in parallel is now
+Getting used to writing testing code and running this code in parallel is now
considered a good habit. Used wisely, this method helps you define more
precisely your code's intent and have a more decoupled architecture.
@@ -29,7 +29,7 @@ Some general rules of testing:
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
+ when developing a function inside a module, run this function's tests
frequently, ideally automatically when you save the code.
- Always run the full test suite before a coding session, and run it again
@@ -65,10 +65,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, running and reading the related
- testing code is often the best thing that they can do to start. 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 to ensure that the new functionality is not already a
+ testing code is often the best thing that they can do to start. 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 to ensure that the new functionality is not already a
working path that has not been plugged into the interface.
The Basics
diff --git a/requirements.txt b/requirements.txt
index 7813214..c2886a7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,12 +1,20 @@
-alabaster==0.7.7
-Babel==2.2.0
-docutils==0.12
-Jinja2==2.8
-MarkupSafe==0.23
-Pygments==2.1.1
-pytz==2015.7
-six==1.10.0
+alabaster==0.7.11
+Babel==2.6.0
+certifi==2018.4.16
+chardet==3.0.4
+docutils==0.14
+idna==2.7
+imagesize==1.0.0
+Jinja2==2.10
+MarkupSafe==1.0
+packaging==17.1
+Pygments==2.2.0
+pyparsing==2.2.0
+pytz==2018.5
+requests==2.19.1
+six==1.11.0
snowballstemmer==1.2.1
-Sphinx==1.3.5
-sphinx-rtd-theme==0.1.9
-wheel==0.29.0
+Sphinx==1.7.6
+sphinx-sitemap==0.3.1
+sphinxcontrib-websupport==1.1.0
+urllib3==1.23
diff --git a/runtime.txt b/runtime.txt
new file mode 100644
index 0000000..d70c8f8
--- /dev/null
+++ b/runtime.txt
@@ -0,0 +1 @@
+3.6