Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98029

Python 2 vs Python 3 for teaching

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Python 2 vs Python 3 for teaching
Date 2015-11-01 20:43 +1100
Message-ID <mailman.7.1446371003.4463.python-list@python.org> (permalink)

Show all headers | View raw


I'm proud to say that a Python tutoring company has just converted its
course over from teaching Python 2.7 to teaching 3.x. For the
naysayers out there, it actually wasn't much of a transition; putting
parentheses around all print calls, plus changing the way virtual
environments get created, pretty much covered it. The difference
between well-written 2.7 code and well-written 3.4 code is really not
huge.

Interestingly, the bytes/unicode distinction wasn't much of an issue.
Under 2.7, a lot of functions return Unicode strings, and their reprs
show a u prefix, which disappears under Py3. In both cases, a Unicode
string returned from a library will compare equal to a simple
double-quoted string:

>>> import json
>>> json.loads('["Hello", "World"]')
[u'Hello', u'World']
>>> _[0] == "Hello"
True

The bulk of the changes were actually just changing displayed output
to match a change to some object's repr (eg "<type 'bool'>" becomes
"<class 'bool'>", and "set([1])" becomes "{1}"), or the exact text of
an exception (the TypeError from evaluating None[0] looks different,
but it's still a TypeError).

Who out there is currently teaching/tutoring/training using Python 2?
Push to the common subset (parenthesized single string prints, never
assuming int/int yields int, etc), with a view to migration - it's
easier than you might think!

(This isn't meant to be an ad for a specific company, so much as a
general recommendation to push to Py3, but they deserve a bit of a
shout-out anyway. The company is Thinkful, www.thinkful.com.)

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Python 2 vs Python 3 for teaching Chris Angelico <rosuav@gmail.com> - 2015-11-01 20:43 +1100
  Re: Python 2 vs Python 3 for teaching beliavsky@aol.com - 2015-11-02 05:15 -0800
    Re: Python 2 vs Python 3 for teaching Chris Angelico <rosuav@gmail.com> - 2015-11-03 01:10 +1100

csiph-web