Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonCHB committed Oct 26, 2018
2 parents 156470a + acc0422 commit 644e87b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Building the docs for uploading to gh-pages

The html docs are published by gitHub's gh-pages. This is accomplished by putting all the html in the ``gh-pages`` branch of the repo.

YOu can do that by hand, by copying any new html to the branch, but if you want to do it more often, it's easier to automate it.
You can do that by hand, by copying any new html to the branch, but if you want to do it more often, it's easier to automate it.

There is a bash script that will do it for you: ``build_gh_pages.sh``.

Expand All @@ -54,7 +54,7 @@ It requires a bit of setup:

git pull

* Once this is setup, you can run the build_gh_pages script from the name repo, and it should:
* Once this is setup, you can run the build_gh_pages script from the main repo, and it should:

- build the html docs
- copy that build docs over to the other clone
Expand Down
2 changes: 1 addition & 1 deletion build_gh_pages.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# simple script to build and push to gh-pages
# designed to be run from master
Expand Down
2 changes: 2 additions & 0 deletions source/exercises/dict_lab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ should be able to run the script directly like so:

To make this work you, make sure you include the 'shebang' on the first line of your file.

.. code-block:: bash
#!/usr/bin/env python3
Expand Down
2 changes: 1 addition & 1 deletion source/modules/CollectionsModule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The Collections Module
######################

Python has a very complete set of built in standard types that support most programming tasks. These include strings and numbers, and also types that can be used to hold other objects -- or "collection" types"
Python has a very complete set of built in standard types that support most programming tasks. These include strings and numbers, and also types that can be used to hold other objects -- or "collection" types.

* tuples
* lists
Expand Down
10 changes: 6 additions & 4 deletions source/modules/Comprehensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ This results in the same set as this for loop:
or, indeed, the same as passing a list comp to ``set()``.
new_set = set([expression_with_variable for variable in a_sequence])
.. code-block:: python
new_set = set([expression_with_variable for variable in a_sequence])
**Example:** Finding all the vowels in a string...
Expand All @@ -180,7 +182,7 @@ new_set = set([expression_with_variable for variable in a_sequence])
.. note::
Why did I use ``set('aeiou')`` rather than just `aeiou` ? ... ``in`` works with strings as well, but is it efficient?
Why did I use ``set('aeiou')`` rather than just ``'aeiou'`` ? ... ``in`` works with strings as well, but is it efficient?
Dict Comprehensions
Expand Down Expand Up @@ -297,7 +299,7 @@ dict comps are still nice if you need to filter the results, though:
Generator Expressions
---------------------
There is yet another type of comprehension: generator comprehensions, technically known as "generator expressions". They are very much like a list comprehension, except that they evaluate to an lazy-evaluated "iterable", rather than a list. That is, they *generate* the items on the fly.
There is yet another type of comprehension: generator comprehensions, technically known as "generator expressions". They are very much like a list comprehension, except that they evaluate to a lazy-evaluated "iterable", rather than a list. That is, they *generate* the items on the fly.
This is useful, because we often create a comprehension simply to loop over it right away:
Expand Down Expand Up @@ -372,7 +374,7 @@ If we use it in a list comp:
test called with: 2
Out[10]: [0, 1, 4]
We see that test gets called for all the values, and then a list is returned with all the results.
We see that ``test()`` gets called for all the values, and then a list is returned with all the results.
But if we use it in a generator comprehension:
.. code-block:: ipython
Expand Down
6 changes: 3 additions & 3 deletions source/modules/DictsAndSets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ When new items are added to a dict, they go on the "end":
and ``dict.popitem()`` will remove the "last" item in the dict.

**CAUTION** This is new behavior in cPython 3.6 -- older versions of Python (notably including Python 2) do not preserve order. In older versions, there is a special version of a dict in the collections module: ``Collections.OrderedDict`` which preserves order in all versions of Python, and has a couple extra features.
**CAUTION** This is new behavior in cPython 3.6 -- older versions of Python (notably including Python 2) do not preserve order. In older versions, there is a special version of a dict in the collections module: ``collections.OrderedDict`` which preserves order in all versions of Python, and has a couple extra features.


Dictionary Iterating
Expand Down Expand Up @@ -442,8 +442,8 @@ If you want a copy, use the explicit copy method to get a copy:
'something': 'a value',
'something else': 'another value'}
In [54]: item_copy
Out[54]: {'something': 'a value', 'something else': 'another value'}
In [54]: item_copy
Out[54]: {'something': 'a value', 'something else': 'another value'}
Sets
Expand Down
6 changes: 3 additions & 3 deletions source/modules/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This is not useful:
# apply soap to each sponge
worker.apply_soap(sponge)
Note: Nothing special about Python here -- basic good programing practice. Note that you will need a lto fewer comments if you choose your names well!
Note: Nothing special about Python here -- basic good programing practice. Note that you will need a lot fewer comments if you choose your names well!

Docstrings
----------
Expand Down Expand Up @@ -89,9 +89,9 @@ A Function Docstring Should:
* Be a complete sentence in the form of a command describing what the function
does.

* """Return a list of values based on blah blah""" is a good docstring
* ``"""Return a list of values based on blah blah"""`` is a good docstring

* """Returns a list of values based on blah blah""" is *not* as good..
* ``"""Returns a list of values based on blah blah"""`` is *not* as good..

* Have a useful single line.

Expand Down
24 changes: 12 additions & 12 deletions source/modules/Exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This is really important if your code does anything before the exception occurre
In this case, the file will be properly closed regardless. And many other systems, like database managers, etc. can also be used with ``with``.

This is known as a "context manager", and was added to Python specifically to handle the common cases that required finally clauses. But if your use case does not already have a context manager that handles the cleanup you may need.
This is known as a "context manager", and was added to Python specifically to handle the common cases that required ``finally`` clauses. But if your use case does not already have a context manager that handles the cleanup you may need.

Exceptions -- ``else``
----------------------
Expand All @@ -185,11 +185,11 @@ Yet another flow control option:
So the ``else`` block only runs if there was no exception. That was also the case in the previous code, so what's the difference?

**Advantage of ``else``:**
**Advantage of** ``else`` **:**

Using the ``else`` block lets you catch the exception as close to where it occurred as possible -- always a good thing.

Why? -- because maybe the "process(f)" could raise an exception, too? Then you don't know if the exception came from the ``open()`` call or in some code after that.
Why? -- because maybe the ``process(f)`` could raise an exception, too? Then you don't know if the exception came from the ``open()`` call or in some code after that.

This bears repeating:

Expand Down Expand Up @@ -250,16 +250,16 @@ For an example -- try running this code:

.. code-block:: ipython
In [34]: try:
...: f = open("blah")
...: except IOError as err:
...: print(err)
...: print(dir(err))
...: the_err = err
In [34]: try:
...: f = open("blah")
...: except IOError as err:
...: print(err)
...: print(dir(err))
...: the_err = err
The ``print(dir(err))`` will print all the names (attributes) in the error object. A number of those are ordinary names that all objects have, but a few are specific to this error.

the ``the_err`` = err line is there so that we can keep a name bound to the err after the code is run. ``err`` as bound by the except line only exists inside the following block.
the ``the_err = err`` line is there so that we can keep a name bound to the ``err`` after the code is run. ``err`` as bound by the except line only exists inside the following block.

Now that we have a name to access it, we can look at some of its attributes. The name of the file that was attempted to be opened:

Expand All @@ -268,14 +268,14 @@ Now that we have a name to access it, we can look at some of its attributes. The
In [35]: the_err.filename
Out[35]: 'blah'
The message that will be pronted is usually in the "args" attribute:
The message that will be printed is usually in the ``.args`` attribute:

.. code-block:: ipython
In [37]: the_err.args
Out[37]: (2, 'No such file or directory')
the ``.__traceback__`` attribute hold the actual traceback object -- all the information about the context the exception was raised in. That can inpsected to get all sorts of info. tHat is very advanced stuff, but you can investigate the ``inspect`` module if you want to know how.
the ``.__traceback__`` attribute hold the actual traceback object -- all the information about the context the exception was raised in. That can be inspected to get all sorts of info. That is very advanced stuff, but you can investigate the ``inspect`` module if you want to know how.

Multiple Exceptions
-------------------
Expand Down
6 changes: 3 additions & 3 deletions source/modules/Files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Text File Notes

Text is default:

* Newlines are translated: ``\r\n -> \n``
* Newlines are translated: ``\r\n`` -> ``\n``
* -- reading and writing!
* Use \*nix-style in your code: ``\n``

Expand Down Expand Up @@ -212,8 +212,6 @@ Relative paths are relative to the current working directory, which is only rele
os.getcwd()
os.chdir(path)
os.path.abspath()
os.path.relpath()
``os.path`` module
Expand All @@ -226,6 +224,8 @@ Relative paths are relative to the current working directory, which is only rele
os.path.basename()
os.path.dirname()
os.path.join()
os.path.abspath()
os.path.relpath()
(all platform independent)
Expand Down
6 changes: 3 additions & 3 deletions source/modules/Modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Packages

A package is a module with other modules in it.

On a filesystem, this is represented as a directory that contains one or more``.py`` files, one of which **must** be called ``__init__.py``.
On a filesystem, this is represented as a directory that contains one or more ``.py`` files, one of which **must** be called ``__init__.py``.

When you have a package, you can import only the package, or any of the modules inside it. When a package is imported, the code in the ``__init__.py`` file is run, and any names defined in that file are available in the *package namespace*.

Expand Down Expand Up @@ -155,7 +155,7 @@ Save another file in your my_package dir called ``a_module.py``, and put this in
def a_function():
print("a_function has been called")
You now have about the simplest package you can have. If make sure your current working dir is the dir that ``my_package`` is in, and start python or iPython. Then try this code:
You now have about the simplest package you can have. Make sure your current working dir is the dir that ``my_package`` is in, and start python or iPython. Then try this code:

.. code-block:: ipython
Expand Down Expand Up @@ -204,7 +204,7 @@ Note that you can also put a package inside a package. So you can create arbitra

"Flat is better than nested."

So don't overdue it -- only go as deep as you really need to to keep the your code organized.
So don't overdo it -- only go as deep as you really need to to keep your code organized.

Importing modules
-----------------
Expand Down
2 changes: 1 addition & 1 deletion source/modules/NamingThings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Naming Guidelines
-----------------

Whenever possible, use strong, unambiguous names that relate to a concept in the business area applicable for your program.
For example, cargo_weight is probably better than item_weight, current_fund_price is better than value.
For example, ``cargo_weight`` is probably better than ``item_weight``, ``current_fund_price`` is better than ``value``.

Only use single-letter names for things with limited scope: indexes and the like:

Expand Down

0 comments on commit 644e87b

Please sign in to comment.