Skip to content

Commit c165064

Browse files
committed
updating rendered materials
1 parent 35150f1 commit c165064

9 files changed

Lines changed: 199 additions & 130 deletions

File tree

‎_sources/modules/StaticAndClassMethods.rst.txt‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Static and Class Methods
88
You've seen how methods of a class are *bound* to an instance when it is
99
created.
1010

11-
And you've seen how the argument ``self`` is then automatically passed to
12-
the method when it is called.
11+
And you've seen how the argument ``self`` is then automatically passed to the method when it is called.
1312

1413
And you've seen how you can call *unbound* methods on a class object so
1514
long as you pass an instance of that class as the first argument.
@@ -36,9 +35,6 @@ A *static method* is a method that doesn't get self:
3635
Out[37]: 9
3736
3837
39-
.. [demo: :download:`static_method.py <../../Examples/Session08/static_method.py>`]
40-
41-
4238
Where are static methods useful?
4339

4440
Usually they aren't. It is often better just to write a module-level function.
@@ -80,9 +76,6 @@ argument
8076
Out[42]: 16
8177
8278
83-
.. [demo: :download:`class_method.py <../../Examples/Session08/class_method.py>`]
84-
85-
8679
Why?
8780
----
8881

@@ -102,6 +95,9 @@ Consider this:
10295
in a class method: <class '__main__.SubClassy'>
10396
Out[45]: 64
10497
98+
``a_class_method`` is defined in the ``Classy`` class (see above).
99+
And it prints the class that it is called on. But despite being defined in ``Classy``, it gets the ``SubClassy`` class object as the first parameter (``cls``).
100+
So a classmethod will "do the right thing" when used in a subclass.
105101

106102
Alternate Constructors
107103
-----------------------
@@ -123,7 +119,6 @@ keys:
123119
TypeError: cannot convert dictionary update sequence element #0 to a sequence
124120
125121
126-
127122
The stock constructor for a dictionary won't work this way. So the dict object
128123
implements an alternate constructor that *can*.
129124

@@ -144,8 +139,7 @@ implements an alternate constructor that *can*.
144139
See also ``datetime.datetime.now()``, etc....
145140

146141

147-
Properties, Static Methods and Class Methods are powerful features of Python's
148-
OO model.
142+
Properties, Static Methods and Class Methods are powerful features of Python's OO model.
149143

150144
They are implemented using an underlying structure called *descriptors*
151145

‎_sources/modules/Unicode.rst.txt‎

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ What the heck is Unicode anyway?
2626
* First there was chaos...
2727

2828
* Different machines used different encodings -- different ways of mapping
29-
binary data that the computer stores to letters.
29+
the binary data that the computer stores to letters.
3030

3131
* Then there was ASCII -- and all was good (7 bit), 127 characters
3232

@@ -84,7 +84,7 @@ http://www.joelonsoftware.com/articles/Unicode.html
8484

8585
Actually, dealing with numbers rather than bytes is big
8686

87-
-- but we take that for granted
87+
-- but we take that for granted.
8888

8989

9090
Mechanics
@@ -98,11 +98,11 @@ Py2 strings were simply sequences of bytes. When text was one per character tha
9898
Py3 strings (or Unicode strings in py2) are sequences of "platonic characters".
9999

100100
It's almost one code point per character -- there are complications
101-
with combined characters: accents, etc -- but we can mostly ignore those -- you will get far thiking of a code point as a character.
101+
with combined characters: accents, etc -- but we can mostly ignore those -- you will get far thinking of a code point as a character.
102102

103103
Platonic characters cannot be written to disk or network!
104104

105-
(ANSI: one character == one byte -- so easy!)
105+
(ANSI: one character == one byte -- it was so easy!)
106106

107107

108108
Strings vs Unicode
@@ -132,7 +132,7 @@ And two ways to work with binary data:
132132
py3 is more clear:
133133

134134
``str`` for text
135-
``byte`` for binary data
135+
``bytes`` for binary data
136136

137137
Unicode
138138
--------
@@ -154,12 +154,12 @@ If you need to deal with the actual bytes for some reason, you may need to conve
154154

155155
And can get even more confusing with py2 strings being *both* text and bytes!
156156

157-
This is actually one of the biggest differences between Python 2 and Python 3. As an ordinary user (particularly one that used English...), you may not notice -- text is text, and things generally "just work", but under the hood it is very different, and folks writing libraries for things like Internet protocols struggle with the differences.
157+
This is actually one of the biggest differences between Python 2 and Python 3. As an ordinary user (particularly one that used English...), you may not notice -- text is text, and things generally "just work", but under the hood it is very different, and folks writting libraries for things like Internet protocols struggled with the differences.
158158

159159
Using Unicode in Py2
160-
---------------------
160+
--------------------
161161

162-
If you do need to write Python2 code, you really should use Unicode.
162+
If you do need to write Python2 code, you really should use Unicode. If you don't -- skip ahead to "Unicode Literals".
163163

164164
Here are the basics:
165165

@@ -214,7 +214,9 @@ Encoding and Decoding
214214
215215
216216
Unicode Literals
217-
------------------
217+
----------------
218+
219+
How do you get text that isn't plain English text?
218220

219221
1) Use Unicode in your source files:
220222

@@ -226,6 +228,8 @@ Unicode Literals
226228

227229
2) Escape the Unicode characters:
228230

231+
Either by its hexadecimal value, or its name:
232+
229233
.. code-block:: python
230234
231235
print u"The integral sign: \u222B"
@@ -239,7 +243,7 @@ One example: http://inamidst.com/stuff/unidata/
239243

240244

241245
Using Unicode
242-
--------------
246+
-------------
243247

244248
Use ``unicode`` objects in all your code
245249

@@ -251,14 +255,17 @@ Many packages do this for you: *XML processing, databases, ...*
251255

252256
**Gotcha:**
253257

254-
Python has a default encoding (usually ascii)
258+
Python has a default encoding. On Mac and Unix systems, it's usually utf-8 -- Windows? not nearly as consistent.
255259

256260
.. code-block:: ipython
257261
258-
In [2]: sys.getdefaultencoding()
259-
Out[2]: 'ascii'
262+
In [7]: sys.getdefaultencoding()
263+
Out[7]: 'utf-8'
264+
265+
Try this on your machine, and see what you get.
260266

261-
The default encoding will get used in unexpected places!
267+
The default encoding will get used in unexpected places!
268+
Notably in text files by default.
262269

263270
Using Unicode Everywhere
264271
-------------------------
@@ -329,12 +336,13 @@ UTF-16
329336

330337
Kind of like UTF-8, except it uses at least 16bits (2 bytes) for each character: NOT ASCII compatible.
331338

332-
But is still needs more than two bytes for some code points, so you still can't process it as two bytes per character.
339+
But it still needs more than two bytes for some code points, so you still can't simply process it as two bytes per character.
333340

334-
In C/C++ held in a "wide char" or "wide string".
341+
In C/C++, it is held in a "wide char" or "wide string".
335342

336343
MS Windows uses UTF-16, as does (I think) Java.
337344

345+
338346
UTF-16 criticism
339347
-----------------
340348

@@ -362,7 +370,7 @@ A 1-byte per char encoding.
362370

363371
* The most common one-byte per char encoding for European text.
364372

365-
* Nice property -- every byte value from 0 to 255 is a valid character ( at least in Python )
373+
* Nice property -- every byte value from 1 to 255 is a valid character ( at least in Python )
366374

367375
* You will never get an UnicodeDecodeError if you try to decode arbitrary bytes with latin-1.
368376

@@ -384,27 +392,25 @@ http://docs.python.org/howto/unicode.html
384392

385393
"Reading Unicode from a file is therefore simple"
386394

387-
use io.open:
395+
use plain old open:
388396

389397
.. code-block:: python
390398
391-
from io import open
392-
io.open('unicode.rst', encoding='utf-8')
399+
open('unicode.rst', encoding='utf-8')
393400
for line in f:
394401
print repr(line)
395402
396-
(https://docs.python.org/2/library/io.html#module-interface)
397-
398-
.. note: This is all for Python 2 -- the built in ``open`` in Py3 does utf-8 by default.
399403
400404
Encodings Built-in to Python:
401-
http://docs.python.org/2/library/codecs.html#standard-encodings
405+
http://docs.python.org/3/library/codecs.html#standard-encodings
402406

403407

404408
Gotchas in Python 2
405-
--------------------
409+
-------------------
406410

407-
file names, etc:
411+
(Probaly do'nt need to worry about this anymore!)
412+
413+
File names, etc:
408414

409415
If you pass in unicode, you get unicode
410416

@@ -438,7 +444,7 @@ Exception messages:
438444
:download:`exception_test.py <../examples/unicode/exception_test.py>`.
439445

440446
Unicode in Python 3
441-
----------------------
447+
-------------------
442448

443449
The "string" object **is** Unicode (always).
444450

@@ -456,7 +462,8 @@ It's all much cleaner.
456462
(by the way, the recent implementations are very efficient...)
457463

458464
So you can pretty much ignore encodings and all that for most basic text processing.
459-
If you do find yourself needing to deal with binary data, you ay need to encode/decode stuff yourself. IN which case, Python provides an ``.encode()`` method on strings that encode the string to a bytes object with the encoding you select:
465+
If you do find yourself needing to deal with binary data, you ay need to encode/decode stuff yourself.
466+
In which case, Python provides an ``.encode()`` method on strings that encode the string to a bytes object with the encoding you select:
460467

461468
.. code-block:: ipython
462469
@@ -477,7 +484,7 @@ It's all quite simple an robust.
477484

478485
But there are a couple key points to remember:
479486

480-
* The primary people struggling were those that wrote (or wored with) libraries that had to deal with protocols that used both binary and text data in the same data stream.
487+
* The primary people struggling were those that wrote (or worked with) libraries that had to deal with protocols that used both binary and text data in the same data stream.
481488

482489
* As of Python 3.4 or so, the python string object had grown the features it needed to support even those ugly binary+text use cases.
483490

‎_sources/topics/01-setting_up/git_hints.rst.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ It's a good way to work -- branching and merging is easy enough it git that it p
246246

247247
Above, we talked about using ``git checkout`` to restore a file to the state it was in in a previous commit, like so::
248248

249-
git checkout 8e5908a37d7d examples/Session05/maillroom_test.py
249+
git checkout 8e5908a37d7d examples/Session05/mailroom_test.py
250250

251251
But what happens if you do a checkout with a commit, and no specific file?
252252

@@ -266,7 +266,7 @@ It does what you might expect -- puts ALL the files back the way they were at th
266266

267267
HEAD is now at c03bb5b adding print_grid from class
268268

269-
So the files are set to the old state -- but now there is that note about "detached HEAD" -- this means that changes you make, even commits, will not effect the git repo. IF you want to start from here and make changes that will stick, you need to do what it says, and make a new branch. But what it DOESN'T tell you is how to simpel "re-attach" the HEAD. Turns out there is an easy way::
269+
So the files are set to the old state -- but now there is that note about "detached HEAD" -- this means that changes you make, even commits, will not effect the git repo. If you want to start from here and make changes that will stick, you need to do what it says, and make a new branch. But what it DOESN'T tell you is how to simply "re-attach" the HEAD. Turns out there is an easy way::
270270

271271
$ git checkout -
272272
Previous HEAD position was c03bb5b adding print_grid from class
@@ -277,7 +277,7 @@ the dash means "the branch or commit you were on before your last checkout comma
277277

278278
For more info about "detached HEAD", see:
279279

280-
https://howtogit.net/recipes/getting-out-of-detached-head-state.html
280+
https://www.cloudbees.com/blog/git-detached-head
281281

282282

283283

0 commit comments

Comments
 (0)