diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index 615b6ac..0e4e4e2 100644 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -68,7 +68,6 @@ mark{background:#ff8;font-weight:bold}
2to3We’re going to migrate the chardet module from Python 2 to Python 3. Python 3 comes with a utility script called 2to3, which takes your actual Python 2 source code as input and auto-converts as much as it can to Python 3. In some cases this is easy — a function was renamed or moved to a different modules — but in other cases it can get pretty complex. To get a sense of all that it can do, refer to the appendix, Porting code to Python 3 with 2to3. In this chapter, we’ll start by running 2to3 on the chardet package, but as you’ll see, there will still be a lot of work to do after the automated tools have performed their magic.
The main chardet package is split across several different files, all in the same directory. The 2to3 script makes it easy to convert multiple files at once: just pass a directory as a command line argument, and 2to3 will convert each of the files in turn.
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
C:\home\chardet> python c:\Python30\Tools\Scripts\2to3.py -w chardet\
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
diff --git a/dip3.js b/dip3.js
index 85e272d..7776531 100644
--- a/dip3.js
+++ b/dip3.js
@@ -4,7 +4,6 @@ var LANGS = {'python2': 'Python 2', 'java': 'Java', 'perl5': 'Perl 5', 'clang':
//google.load("jquery", "1.3");
//google.setOnLoadCallback(function() {
$(document).ready(function() {
- $("#noscript").hide();
var HS = {'visible': 'hide', 'hidden': 'show'};
/*
// toggle-able language comparisons
diff --git a/html5.js b/html5.js
new file mode 100644
index 0000000..e973e7f
--- /dev/null
+++ b/html5.js
@@ -0,0 +1 @@
+(function(){var e="abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,figure,footer,header,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()
\ No newline at end of file
diff --git a/native-datatypes.html b/native-datatypes.html
index 2925c99..f610cb8 100644
--- a/native-datatypes.html
+++ b/native-datatypes.html
@@ -31,7 +31,6 @@ body{counter-reset:h1 2}
Booleans
Booleans are either true or false. Python has two constants, True and False, which can be used to assign boolean values directly. Expressions can also evaluate to a boolean value. In certain places (like if statements), Python expects an expression to evaluate to a boolean value. These places are called boolean contexts. You can use virtually any expression in a boolean context, and Python will try to determine its truth value. Different datatypes have different rules about which values are true or false in a boolean context. (This will make more sense once you see some concrete examples later in this chapter.)
For example, take this snippet from humansize.py:
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
if size < 0:
raise ValueError('number must be non-negative')
size is an integer, 0 is an integer, and < is a numerical operator. The result of the expression size < 0 is always a boolean. You can test this yourself in the Python interactive shell:
diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html
index d1b49f8..f68f94e 100644
--- a/porting-code-to-python-3-with-2to3.html
+++ b/porting-code-to-python-3-with-2to3.html
@@ -28,7 +28,6 @@ td pre{padding:0;border:0}
Virtually all Python 2 programs will need at least some tweaking to run properly under Python 3. To help with this transition, Python 3 comes with a utility script called 2to3, which takes your actual Python 2 source code as input and auto-converts as much as it can to Python 3. Case study: porting chardet to Python 3 describes how to run the 2to3 script, then shows some things it can't fix automatically. This appendix documents what it can fix automatically.
print statement
In Python 2, print was a statement. Whatever you wanted to print simply followed the print keyword. In Python 3, print() is a function — whatever you want to print is passed to print() like any other function.
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
Notes
diff --git a/regular-expressions.html b/regular-expressions.html
index 6582a1b..a5faf6b 100644
--- a/regular-expressions.html
+++ b/regular-expressions.html
@@ -23,7 +23,6 @@ body{counter-reset:h1 4}
Case study: street addresses
This series of examples was inspired by a real-life problem I had in my day job several years ago, when I needed to scrub and standardize street addresses exported from a legacy system before importing them into a newer system. (See, I don’t just make this stuff up; it’s actually useful.) This example shows how I approached the problem.
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
>>> s = '100 NORTH MAIN ROAD'
>>> s.replace('ROAD', 'RD.') ①
diff --git a/unit-testing.html b/unit-testing.html
index 9f5a3f9..39b3719 100644
--- a/unit-testing.html
+++ b/unit-testing.html
@@ -49,7 +49,6 @@ body{counter-reset:h1 7}
The to_roman() function should return the Roman numeral representation for all integers 1 to 3999.
It is not immediately obvious how this code does… well, anything. It defines a class which has no __init__() method. The class does have another method, but it is never called. The entire script has a __main__ block, but it doesn't reference the class or its method. But it does do something, I promise.
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
import roman1
import unittest
diff --git a/your-first-python-program.html b/your-first-python-program.html
index e0f9cd9..b3317f1 100644
--- a/your-first-python-program.html
+++ b/your-first-python-program.html
@@ -17,7 +17,6 @@ th{font-family:inherit !important}
Diving in
Books about programming usually start with a bunch of boring chapters about fundamentals and eventually work up to building something useful. Let's skip all that. Here is a complete, working Python program. It probably makes absolutely no sense to you. Don't worry about that, because you're going to dissect it line by line. But read through it first and see what, if anything, you can make of it.
-
[The code examples will be easier to follow if you enable Javascript, but whatever.]
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}