| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -286,12 +286,11 @@ Other Tools | |||
| 286 | 286 | IDLE | |
| 287 | 287 | ---- | |
| 288 | 288 | ||
| 289 | - `IDLE <http://docs.python.org/library/idle.html>`_ is an integrated | ||
| 290 | - development environment that is part of Python standard library. It is | ||
| 291 | - completely written in Python and uses the Tkinter GUI toolkit. Though IDLE | ||
| 292 | - is not suited for full-blown development using Python, it is quite | ||
| 293 | - helpful to try out small Python snippets and experiment with different | ||
| 294 | - features in Python. | ||
| 289 | + :ref:`IDLE <python:idle>` is an integrated development environment that is | ||
| 290 | + part of Python standard library. It is completely written in Python and uses | ||
| 291 | + the Tkinter GUI toolkit. Though IDLE is not suited for full-blown development | ||
| 292 | + using Python, it is quite helpful to try out small Python snippets and | ||
| 293 | + experiment with different features in Python. | ||
| 295 | 294 | ||
| 296 | 295 | It provides the following features: | |
| 297 | 296 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,4 +11,6 @@ Clint | |||
| 11 | 11 | docopt | |
| 12 | 12 | ------ | |
| 13 | 13 | ||
| 14 | - `docopt <http://docopt.org/>`_ is a lightweight, highly Pythonic package that allows creating command line interfaces easily and intuitively, by parsing POSIX-style usage instructions. | ||
| 14 | + `docopt <http://docopt.org/>`_ is a lightweight, highly Pythonic package that | ||
| 15 | + allows creating command line interfaces easily and intuitively, by parsing | ||
| 16 | + POSIX-style usage instructions. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ What You Should Do Instead | |||
| 65 | 65 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 66 | 66 | ||
| 67 | 67 | Create a new object each time the function is called, by using a default arg to | |
| 68 | - signal that no argument was provided (``None`` is often a good choice). | ||
| 68 | + signal that no argument was provided (:py:data:`None` is often a good choice). | ||
| 69 | 69 | ||
| 70 | 70 | .. code-block:: python | |
| 71 | 71 | ||
@@ -137,9 +137,9 @@ is looked up in the surrounding scope at call time. By then, the loop has | |||
| 137 | 137 | completed and ``i`` is left with its final value of 4. | |
| 138 | 138 | ||
| 139 | 139 | What's particularly nasty about this gotcha is the seemingly prevalent | |
| 140 | - misinformation that this has something to do with ``lambda``\s in Python. | ||
| 141 | - Functions created with a ``lambda`` expression are in no way special, and in | ||
| 142 | - fact the same exact behavior is exhibited by just using an ordinary ``def``: | ||
| 140 | + misinformation that this has something to do with :ref:`lambdas <python:lambda>` | ||
| 141 | + in Python. Functions created with a ``lambda`` expression are in no way special, | ||
| 142 | + and in fact the same exact behavior is exhibited by just using an ordinary ``def``: | ||
| 143 | 143 | ||
| 144 | 144 | .. code-block:: python | |
| 145 | 145 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ while another would handle low-level manipulation of data. The most natural way | |||
| 83 | 83 | to separate these two layers is to regroup all interfacing functionality | |
| 84 | 84 | in one file, and all low-level operations in another file. In this case, | |
| 85 | 85 | the interface file needs to import the low-level file. This is done with the | |
| 86 | - `import` and `from ... import` statements. | ||
| 86 | + ``import`` and ``from ... import`` statements. | ||
| 87 | 87 | ||
| 88 | 88 | As soon as you use `import` statements you use modules. These can be either built-in | |
| 89 | 89 | modules such as `os` and `sys`, third-party modules you have installed in your | |
@@ -106,7 +106,7 @@ Aside for some naming restrictions, nothing special is required for a Python fil | |||
| 106 | 106 | to be a module, but the import mechanism needs to be understood in order to use | |
| 107 | 107 | this concept properly and avoid some issues. | |
| 108 | 108 | ||
| 109 | - Concretely, the `import modu` statement will look for the proper file, which is | ||
| 109 | + Concretely, the ``import modu`` statement will look for the proper file, which is | ||
| 110 | 110 | `modu.py` in the same directory as the caller if it exists. If it is not | |
| 111 | 111 | found, the Python interpreter will search for `modu.py` in the "path" | |
| 112 | 112 | recursively and raise an ImportError exception if it is not found. | |
@@ -120,20 +120,20 @@ Then, the module's variables, functions, and classes will be available to the ca | |||
| 120 | 120 | through the module's namespace, a central concept in programming that is | |
| 121 | 121 | particularly helpful and powerful in Python. | |
| 122 | 122 | ||
| 123 | - In many languages, an `include file` directive is used by the preprocessor to | ||
| 123 | + In many languages, an ``include file`` directive is used by the preprocessor to | ||
| 124 | 124 | take all code found in the file and 'copy' it into the caller's code. It is | |
| 125 | 125 | different in Python: the included code is isolated in a module namespace, which | |
| 126 | 126 | means that you generally don't have to worry that the included code could have | |
| 127 | 127 | unwanted effects, e.g. override an existing function with the same name. | |
| 128 | 128 | ||
| 129 | 129 | It is possible to simulate the more standard behavior by using a special syntax | |
| 130 | - of the import statement: `from modu import *`. This is generally considered bad | ||
| 131 | - practice. **Using `import *` makes code harder to read and makes dependencies less | ||
| 130 | + of the import statement: ``from modu import *``. This is generally considered bad | ||
| 131 | + practice. **Using ``import *`` makes code harder to read and makes dependencies less | ||
| 132 | 132 | compartmentalized**. | |
| 133 | 133 | ||
| 134 | - Using `from modu import func` is a way to pinpoint the function you want to | ||
| 135 | - import and put it in the global namespace. While much less harmful than `import | ||
| 136 | - *` because it shows explicitly what is imported in the global namespace, its | ||
| 134 | + Using ``from modu import func`` is a way to pinpoint the function you want to | ||
| 135 | + import and put it in the global namespace. While much less harmful than ``import | ||
| 136 | + *`` because it shows explicitly what is imported in the global namespace, its | ||
| 137 | 137 | advantage over a simpler `import modu` is only that it will save some typing. | |
| 138 | 138 | ||
| 139 | 139 | **Very bad** | |
@@ -166,7 +166,7 @@ Python. Readability means to avoid useless boilerplate text and clutter, | |||
| 166 | 166 | therefore some efforts are spent trying to achieve a certain level of brevity. | |
| 167 | 167 | But terseness and obscurity are the limits where brevity should stop. Being | |
| 168 | 168 | able to tell immediately where a class or function comes from, as in the | |
| 169 | - `modu.func` idiom, greatly improves code readability and understandability in | ||
| 169 | + ``modu.func`` idiom, greatly improves code readability and understandability in | ||
| 170 | 170 | all but the simplest single file projects. | |
| 171 | 171 | ||
| 172 | 172 | ||
@@ -383,7 +383,7 @@ Python has two kinds of built-in or user-defined types. | |||
| 383 | 383 | ||
| 384 | 384 | Mutable types are those that allow in-place modification | |
| 385 | 385 | of the content. Typical mutables are lists and dictionaries: | |
| 386 | - All lists have mutating methods, like ``append()`` or ``pop()``, and | ||
| 386 | + All lists have mutating methods, like :py:meth:`list.append` or :py:meth:`list.pop`, and | ||
| 387 | 387 | can be modified in place. The same goes for dictionaries. | |
| 388 | 388 | ||
| 389 | 389 | Immutable types provide no method for changing their content. | |
@@ -464,10 +464,11 @@ should be your preferred method. | |||
| 464 | 464 | foo = ''.join([foo, 'ooo']) | |
| 465 | 465 | ||
| 466 | 466 | .. note:: | |
| 467 | - You can also use the ``%`` formatting operator to concatenate the | ||
| 468 | - pre-determined number of strings besides ``join()`` and ``+``. However, | ||
| 469 | - according to :pep:`3101`, the ``%`` operator became deprecated in | ||
| 470 | - Python 3.1 and will be replaced by the ``format()`` method in the later versions. | ||
| 467 | + You can also use the :ref:`% <python:string-formatting>` formatting operator | ||
| 468 | + to concatenate a pre-determined number of strings besides :py:meth:`str.join` | ||
| 469 | + and ``+``. However, according to :pep:`3101`, the ``%`` operator became | ||
| 470 | + deprecated in Python 3.1 and will be replaced by the :py:meth:`str.format` | ||
| 471 | + method in the later versions. | ||
| 471 | 472 | ||
| 472 | 473 | .. code-block:: python | |
| 473 | 474 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,7 +335,7 @@ Instead, use a list comprehension: | |||
| 335 | 335 | four_lists = [[] for __ in xrange(4)] | |
| 336 | 336 | ||
| 337 | 337 | ||
| 338 | - A common idiom for creating strings is to use `join <http://docs.python.org/library/string.html#string.join>`_ on an empty string.:: | ||
| 338 | + A common idiom for creating strings is to use :py:meth:`str.join` on an empty string.:: | ||
| 339 | 339 | ||
| 340 | 340 | letters = ['s', 'p', 'a', 'm'] | |
| 341 | 341 | word = ''.join(letters) | |
@@ -433,7 +433,7 @@ Check if variable equals a constant | |||
| 433 | 433 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 434 | 434 | ||
| 435 | 435 | You don't need to explicitly compare a value to True, or None, or 0 - you can | |
| 436 | - just add it to the if statement. See `Truth Value Testing | ||
| 436 | + just add it to the if statement. See :ref:`Truth Value Testing | ||
| 437 | 437 | <http://docs.python.org/library/stdtypes.html#truth-value-testing>`_ for a | |
| 438 | 438 | list of what is considered false. | |
| 439 | 439 | ||
@@ -466,8 +466,8 @@ list of what is considered false. | |||
| 466 | 466 | Access a Dictionary Element | |
| 467 | 467 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 468 | 468 | ||
| 469 | - Don't use the ``has_key`` function. Instead use ``x in d`` syntax, or pass | ||
| 470 | - a default argument to ``get``. | ||
| 469 | + Don't use the :py:meth:`dict.has_key` method. Instead, use ``x in d`` syntax, | ||
| 470 | + or pass a default argument to :py:meth:`dict.get`. | ||
| 471 | 471 | ||
| 472 | 472 | **Bad**: | |
| 473 | 473 | ||
@@ -497,10 +497,9 @@ Short Ways to Manipulate Lists | |||
| 497 | 497 | ||
| 498 | 498 | `List comprehensions | |
| 499 | 499 | <http://docs.python.org/tutorial/datastructures.html#list-comprehensions>`_ | |
| 500 | - provide a powerful, concise way to work with lists. Also, the `map | ||
| 501 | - <http://docs.python.org/library/functions.html#map>`_ and `filter | ||
| 502 | - <http://docs.python.org/library/functions.html#filter>`_ functions can perform | ||
| 503 | - operations on lists using a different concise syntax. | ||
| 500 | + provide a powerful, concise way to work with lists. Also, the :py:func:`map` | ||
| 501 | + :py:func:`filter` functions can perform operations on lists using a different, | ||
| 502 | + more concise syntax. | ||
| 504 | 503 | ||
| 505 | 504 | **Bad**: | |
| 506 | 505 | ||
@@ -540,8 +539,7 @@ operations on lists using a different concise syntax. | |||
| 540 | 539 | # Or: | |
| 541 | 540 | a = map(lambda i: i + 3, a) | |
| 542 | 541 | ||
| 543 | - Use `enumerate <http://docs.python.org/library/functions.html#enumerate>`_ to | ||
| 544 | - keep a count of your place in the list. | ||
| 542 | + Use :py:func:`enumerate` keep a count of your place in the list. | ||
| 545 | 543 | ||
| 546 | 544 | .. code-block:: python | |
| 547 | 545 | ||
@@ -552,9 +550,8 @@ keep a count of your place in the list. | |||
| 552 | 550 | # 1 4 | |
| 553 | 551 | # 2 5 | |
| 554 | 552 | ||
| 555 | - The ``enumerate`` function has better readability than handling a counter | ||
| 556 | - manually. Moreover, | ||
| 557 | - it is better optimized for iterators. | ||
| 553 | + The :py:func:`enumerate` function has better readability than handling a | ||
| 554 | + counter manually. Moreover, it is better optimized for iterators. | ||
| 558 | 555 | ||
| 559 | 556 | Read From a File | |
| 560 | 557 | ~~~~~~~~~~~~~~~~ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ Some general rules of testing: | |||
| 16 | 16 | alone, and also within the test suite, regardless of the order they are called. | |
| 17 | 17 | The implication of this rule is that each test must be loaded with a fresh | |
| 18 | 18 | dataset and may have to do some cleanup afterwards. This is usually | |
| 19 | - handled by `setUp()` and `tearDown()` methods. | ||
| 19 | + handled by ``setUp()`` and ``tearDown()`` methods. | ||
| 20 | 20 | ||
| 21 | 21 | - Try hard to make tests that run fast. If one single test needs more than a | |
| 22 | 22 | few millisecond to run, development will be slowed down or the tests will not | |
| Back | FazBrowse Home | New Git URL |
0 commit comments