Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Stop writing Python 4 incompatible code Date: Thu, 14 Jan 2016 12:21:23 +1100 Lines: 36 Message-ID: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de YB8RhjiN3uvJ21SFeeHkjgVlIMO0GrHzzb/0nYfkAWuQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'bytes.': 0.07; 'pypy': 0.07; 'subject:code': 0.07; 'cc:addr:python-list': 0.09; 'implies': 0.09; 'yeah,': 0.09; 'python': 0.10; 'jan': 0.11; '2.7': 0.13; 'argument': 0.15; 'things.': 0.15; 'thu,': 0.15; '2016': 0.16; 'conditional': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parentheses': 0.16; 'pypy.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simple.': 0.16; 'sorts': 0.16; 'subject:writing': 0.16; 'unicode.': 0.16; 'xrange': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'issue.': 0.20; 'fix': 0.21; '2.x': 0.22; '3.x': 0.22; 'text,': 0.22; 'code,': 0.23; 'code.': 0.23; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'compatible': 0.27; 'handling': 0.27; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'specify': 0.27; 'went': 0.28; '(it': 0.29; "i'm": 0.30; 'print': 0.30; 'version,': 0.30; 'usually': 0.33; 'optimize': 0.33; 'surprised': 0.33; 'open': 0.33; "i'll": 0.33; 'worked': 0.34; 'handle': 0.34; 'lists': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'could': 0.35; 'text': 0.35; 'files,': 0.35; 'lists.': 0.35; "isn't": 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'faster': 0.36; 'smaller': 0.36; "wasn't": 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'wanted': 0.37; 'difference': 0.38; 'version': 0.38; 'received:209': 0.38; 'end': 0.39; 'sure': 0.39; "didn't": 0.39; 'easy': 0.60; 'your': 0.60; "you'll": 0.61; 'different': 0.63; 'between': 0.65; 'differences': 0.66; 'biggest': 0.67; 'programs,': 0.72; 'chrisa': 0.84; 'subject:Stop': 0.84; 'surprisingly': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=CMaFPw8bxCeB/+SY1YhSIAKL3euNyc3Tv2rG6fl6mpg=; b=FbP0hd3T3vrna+SyixNspM9Rwl0yiNNkdpxRXriK4mVe/UP8vUf3VaBV7+PduLcvVS M3h6dzuV0XKqjwY/FP+Uly3xY0iyDourTZGQIctl94q7+KyTl+NJKkW77A96DQrC3TAD o7UbTP/DDWLqxs8Mmp46HnDUWxYPr64u8dPshjiZxZSXsuP9KLwm/oy3i6vlQkgAy5KQ ZxTvfEsbAbO1MOSUK7DDcUklWVl4295gyLvcKio41UBJEUtB4Up80LwRGMZvH4LMwkOE AvejIbIo+7c6d55c+PDqJ21mV1HPmtkyVOoGa8lDtJQlrL3vkdz3eP2WJA8QmiNA+3mI 0Wlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=CMaFPw8bxCeB/+SY1YhSIAKL3euNyc3Tv2rG6fl6mpg=; b=ioAn9S8KPpnRVGbf7IKRb1znRqMGnxgYdAooN+qF2b4q6crdur3CG60aKqh1tyPw/c w8VooLWBm+kl4nT9dZV8Un7XF9mWr6BqXkQcGrKCg4f/v9jOqBCMosHpObJ8e7d/1PKS 4zXLdT3tphZzpVmd/bD3oIpca2GHd/sXJMeZi7QNaXGITyNowyOdPIXW2QQw9AnvjhQm 6PkKU8gquOMjXyXXjr0TIvs0Sxo2Lv8BatcNG0MkYFvJm29d1RstHBT/+gBHq+Ijutp3 jhbOrLDcMYtxQy185gNJ3HdlZrPrnzkW7Culx6G9to7Xrk3Qrlx00oL+xlnnHaYkw4M3 LxCQ== X-Gm-Message-State: ALoCoQnYB1LfMxZqQCMwPuPISeEh5nxcAgRM9zNhz8BslgfXHMqNh/FNuZUQUKTY8czAk8IJYZJQQayIimM5UYLwY6SgXlrPLQ== X-Received: by 10.107.14.73 with SMTP id 70mr2041009ioo.31.1452734483132; Wed, 13 Jan 2016 17:21:23 -0800 (PST) In-Reply-To: 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:101655 On Thu, Jan 14, 2016 at 12:02 PM, BartC wrote: > I was surprised recently by just how much incompatibility there was between > Python 2 and 3. It wasn't just about print with parentheses and range > instead of xrange. > > I wanted to try out a jpeg decoder with PyPy and the three different ones I > could find only worked with 2.x. Attempts to fix the incompatibilities > usually lead to deeper mire. This implies that there are many differences between 2.x and 3.x. > In the end it was easier to put together my own version, which ran on all > Pythons (2.7 to 3.4). It was surprisingly easy to do; no need for > conditional version code. But this implies that the differences are pretty simple. Which argument are you putting? The biggest difference between 2.x and 3.x is the handling of text vs bytes. This is a very important distinction, but for a lot of programs, it's not difficult; most of what you'll be using will be text, and the only difference is that the 3.x version of your program can handle all of Unicode. If you open any files, you might need to specify encoding="utf-8" or encoding="ascii" or something, but that's about the only issue. > (It was also smaller and considerably faster than the others even before I > went tried PyPy. Using range in 2.7 instead of xrange didn't make much > difference either.) Yeah, the effectiveness of xrange over range isn't significant on smallish lists. And PyPy can optimize all sorts of things. If I'm writing 2/3 compatible code, I'll usually just use range() everywhere, unless I know for sure that the lists are going to be huge. ChrisA