mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Fixed all H2 headings
Before, H2 fomratting was not consistent. Now, all H2 headings use over/under asterisks.
This commit is contained in:
+33
-15
@@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
########################
|
||||
Structuring Your Project
|
||||
========================
|
||||
########################
|
||||
|
||||
.. image:: /_static/photos/33907151224_0574e7dfc2_k_d.jpg
|
||||
|
||||
@@ -21,9 +24,9 @@ project. We then discuss various perspectives on how to build code which
|
||||
can be extended and tested reliably.
|
||||
|
||||
|
||||
|
||||
***************************
|
||||
Structure of the Repository
|
||||
---------------------------
|
||||
***************************
|
||||
|
||||
It's Important.
|
||||
:::::::::::::::
|
||||
@@ -313,9 +316,9 @@ The resulting structure:
|
||||
|
||||
|
||||
|
||||
|
||||
************************
|
||||
Structure of Code is Key
|
||||
------------------------
|
||||
************************
|
||||
|
||||
Thanks to the way imports and modules are handled in Python, it is
|
||||
relatively easy to structure a Python project. Easy, here, means
|
||||
@@ -366,8 +369,9 @@ include:
|
||||
task at hand, you might be swimming in ravioli code.
|
||||
|
||||
|
||||
*******
|
||||
Modules
|
||||
-------
|
||||
*******
|
||||
|
||||
Python modules are one of the main abstraction layers available and probably the
|
||||
most natural one. Abstraction layers allow separating code into parts holding
|
||||
@@ -476,8 +480,9 @@ Being able to tell immediately where a class or function comes from, as in the
|
||||
all but the simplest single file projects.
|
||||
|
||||
|
||||
********
|
||||
Packages
|
||||
--------
|
||||
********
|
||||
|
||||
Python provides a very straightforward packaging system, which is simply an
|
||||
extension of the module mechanism to a directory.
|
||||
@@ -509,8 +514,10 @@ Lastly, a convenient syntax is available for importing deeply nested packages:
|
||||
``import very.deep.module as mod``. This allows you to use `mod` in place of the
|
||||
verbose repetition of ``very.deep.module``.
|
||||
|
||||
|
||||
***************************
|
||||
Object-oriented programming
|
||||
---------------------------
|
||||
***************************
|
||||
|
||||
Python is sometimes described as an object-oriented programming language. This
|
||||
can be somewhat misleading and needs to be clarified.
|
||||
@@ -587,8 +594,9 @@ things that are manipulated (windows, buttons, avatars, vehicles) have a
|
||||
relatively long life of their own in the computer's memory.
|
||||
|
||||
|
||||
**********
|
||||
Decorators
|
||||
----------
|
||||
**********
|
||||
|
||||
The Python language provides a simple yet powerful syntax called 'decorators'.
|
||||
A decorator is a function or a class that wraps (or decorates) a function
|
||||
@@ -621,8 +629,10 @@ expensive function in a table and use them directly instead of recomputing
|
||||
them when they have already been computed. This is clearly not part
|
||||
of the function logic.
|
||||
|
||||
|
||||
****************
|
||||
Context Managers
|
||||
----------------
|
||||
****************
|
||||
|
||||
A context manager is a Python object that provides extra contextual information
|
||||
to an action. This extra information takes the form of running a callable upon
|
||||
@@ -694,8 +704,10 @@ to decide when to use which. The class approach might be better if there's
|
||||
a considerable amount of logic to encapsulate. The function approach
|
||||
might be better for situations where we're dealing with a simple action.
|
||||
|
||||
|
||||
**************
|
||||
Dynamic typing
|
||||
--------------
|
||||
**************
|
||||
|
||||
Python is dynamically typed, which means that variables do not have a fixed
|
||||
type. In fact, in Python, variables are very different from what they are in
|
||||
@@ -758,8 +770,10 @@ a `final` keyword and it would be against its philosophy anyway. However, it may
|
||||
be a good discipline to avoid assigning to a variable more than once, and it
|
||||
helps in grasping the concept of mutable and immutable types.
|
||||
|
||||
|
||||
***************************
|
||||
Mutable and immutable types
|
||||
---------------------------
|
||||
***************************
|
||||
|
||||
Python has two kinds of built-in or user-defined types.
|
||||
|
||||
@@ -873,16 +887,20 @@ like above or in cases where you are adding to an existing string, using
|
||||
foobar = '{foo}{bar}'.format(foo=foo, bar=bar) # It is best
|
||||
|
||||
|
||||
************************
|
||||
Vendorizing Dependencies
|
||||
------------------------
|
||||
************************
|
||||
|
||||
|
||||
|
||||
*******
|
||||
Runners
|
||||
-------
|
||||
*******
|
||||
|
||||
|
||||
***************
|
||||
Further Reading
|
||||
---------------
|
||||
***************
|
||||
|
||||
- http://docs.python.org/2/library/
|
||||
- http://www.diveintopython.net/toc/index.html
|
||||
|
||||
Reference in New Issue
Block a user