mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Host photos locally
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user