Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Python 2 vs Python 3 for teaching Date: Sun, 1 Nov 2015 20:43:14 +1100 Lines: 36 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de o/Bdts9bKZrsF99FZVkHqAtPOP5Wn9ItT0EoyohjLYvg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'subject:Python': 0.05; 'json': 0.05; 'created,': 0.09; 'migration': 0.09; "object's": 0.09; 'repr': 0.09; 'python': 0.10; '2.7': 0.13; 'exception': 0.13; 'output': 0.13; 'different,': 0.16; 'distinction': 0.16; 'evaluating': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parentheses': 0.16; 'prefix,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'string:': 0.16; 'tutoring': 0.16; 'string': 0.17; '>>>': 0.20; 'library': 0.20; 'changes': 0.20; 'issue.': 0.20; 'to:name:python- list@python.org': 0.20; '(the': 0.22; 'meant': 0.22; '"",': 0.22; 'assuming': 0.22; 'converted': 0.22; 'environments': 0.22; 'int,': 0.22; 'bit': 0.23; 'import': 0.24; '(this': 0.24; 'compare': 0.27; 'message-id:@mail.gmail.com': 0.27; 'looks': 0.29; 'strings,': 0.29; 'subset': 0.29; 'yields': 0.29; "i'm": 0.30; 'print': 0.30; 'code': 0.30; 'becomes': 0.30; 'push': 0.30; 'putting': 0.30; 'returned': 0.32; 'common': 0.33; 'displayed': 0.33; 'skip:j 20': 0.33; 'changing': 0.34; 'covered': 0.34; 'equal': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'unicode': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'really': 0.37; 'there,': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'virtual': 0.38; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'company': 0.60; 'show': 0.62; 'course': 0.62; 'between': 0.65; 'teaching': 0.69; 'bulk': 0.76; '3.4': 0.84; 'calls,': 0.84; 'chrisa': 0.84; 'disappears': 0.84; 'etc),': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=qNJ3/YyhgjMqx3s7T4qkihGbUsHsFBzQ7hDCQdpv5hA=; b=Vlx1jGH2wtmwfdNSSKI17mLiL4wK0r/fxhM4WAdWcNPuIyefBjhn6nUL4eUm/msVpG yzWFzo5P4bsAaM2y5ftcDtbEvlNSFNXMVgWp+4RWbw55aN7W2Zv4aewCHASQn1JBneJh qrj/Eiasj0Z9fcjMWwXHnD1pfe6jzZKifHvC7Spp0iuv8n3LPQnn7A9wtTvHJLiFtyS6 AMyV9S4JxqkV4NwDDiZSMAFcibvtQnQMjWwzv9m27hthBTFAAS79bJieSD8jF0gizlaS RHXJM2sUHcNL1ofFIjG9YroD+XjxJC48NHvVINJS51z+KaCs34dhnLmacbEOqRtEwPho v91g== X-Received: by 10.50.88.4 with SMTP id bc4mr6531623igb.94.1446370994911; Sun, 01 Nov 2015 01:43:14 -0800 (PST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98029 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 "" becomes "", 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