mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Minor Polishes
This commit is contained in:
@@ -226,7 +226,7 @@ but making a public property private might be a much harder operation.
|
||||
Returning values
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
When a function grows in complexity it is not uncommon to use multiple return
|
||||
When a function grows in complexity, it is not uncommon to use multiple return
|
||||
statements inside the function's body. However, in order to keep a clear intent
|
||||
and a sustainable readability level, it is preferable to avoid returning
|
||||
meaningful values from many output points in the body.
|
||||
@@ -639,11 +639,11 @@ Short Ways to Manipulate Lists
|
||||
|
||||
`List comprehensions
|
||||
<http://docs.python.org/tutorial/datastructures.html#list-comprehensions>`_
|
||||
provide a powerful, concise way to work with lists.
|
||||
provides a powerful, concise way to work with lists.
|
||||
|
||||
`Generator expressions
|
||||
<http://docs.python.org/tutorial/classes.html#generator-expressions>`_
|
||||
follow almost the same syntax as list comprehensions but return a generator
|
||||
follows almost the same syntax as list comprehensions but return a generator
|
||||
instead of a list.
|
||||
|
||||
Creating a new list requires more work and uses more memory. If you are just going
|
||||
@@ -829,7 +829,7 @@ a white space added to the end of the line, after the backslash, will break the
|
||||
code and may have unexpected results.
|
||||
|
||||
A better solution is to use parentheses around your elements. Left with an
|
||||
unclosed parenthesis on an end-of-line the Python interpreter will join the
|
||||
unclosed parenthesis on an end-of-line, the Python interpreter will join the
|
||||
next line until the parentheses are closed. The same behavior holds for curly
|
||||
and square braces.
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ Testing Your Code
|
||||
Testing your code is very important.
|
||||
|
||||
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.
|
||||
considered a good habit. Used wisely, this method helps to define your
|
||||
code's intent more precisely and have a more decoupled architecture.
|
||||
|
||||
Some general rules of testing:
|
||||
|
||||
@@ -294,6 +294,6 @@ always returns the same result (but only for the duration of the test).
|
||||
# get_search_results runs a search and iterates over the result
|
||||
self.assertEqual(len(myapp.get_search_results(q="fish")), 3)
|
||||
|
||||
Mock has many other ways you can configure it and control its behavior.
|
||||
Mock has many other ways with which you can configure and control its behaviour.
|
||||
|
||||
`mock <http://www.voidspace.org.uk/python/mock/>`_
|
||||
|
||||
Reference in New Issue
Block a user