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


Groups > comp.lang.python > #87582

Re: Python 2 to 3 conversion - embrace the pain

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <songofacandy@gmail.com>
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; 'read.': 0.03; 'skip:[ 20': 0.04; 'yet.': 0.04; 'encoding': 0.05; 'explicitly': 0.05; 'subject:Python': 0.06; '*not*': 0.07; 'tests.': 0.07; 'utf-8': 0.07; 'string': 0.09; '%s",': 0.09; '2to3': 0.09; 'already.': 0.09; 'anticipate': 0.09; 'ascii': 0.09; 'lines.': 0.09; 'msg': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bug': 0.12; 'jan': 0.12; 'changes': 0.15; "'r',": 0.16; '*only*': 0.16; 'agree.': 0.16; 'codec': 0.16; 'csv': 0.16; 'easier.': 0.16; 'moving,': 0.16; 'non-ascii': 0.16; 'ordinal': 0.16; 'porting': 0.16; 'programmer,': 0.16; 'reedy': 0.16; 'self.args': 0.16; 'skip:" 100': 0.16; 'unicode,': 0.16; 'utf-8)': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'handles': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'parse': 0.24; 'replace': 0.24; 'specify': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'developers': 0.25; 'logging': 0.26; 'this:': 0.26; 'supported': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'change,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'easy,': 0.31; 'everywhere': 0.31; 'libraries': 0.31; 'ok.': 0.31; 'file': 0.32; 'this.': 0.32; "we're": 0.32; 'another': 0.32; 'url:python': 0.33; '(most': 0.33; 'programmers': 0.33; 'reader': 0.33; 'trouble': 0.34; 'skip:d 20': 0.34; 'subject:the': 0.34; 'could': 0.34; "can't": 0.35; 'knows': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'edge': 0.36; 'url:listinfo': 0.36; 'next': 0.36; 'url:org': 0.36; 'should': 0.36; 'effort': 0.37; 'application': 0.37; 'easily': 0.37; 'server': 0.38; 'handle': 0.38; 'needed': 0.38; 'that,': 0.38; 'recent': 0.39; 'url:mail': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'company': 0.60; 'logged': 0.60; 'most': 0.60; 'year.': 0.61; 'lost': 0.61; 'new': 0.61; 'skip:* 10': 0.61; 'our': 0.64; 'teaching': 0.64; 'more': 0.64; 'benefit': 0.68; 'mar': 0.68; '2015': 0.84; 'change?': 0.84; 'everywhere.': 0.84; 'hard.': 0.84; '8bit%:83': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=z9krVCXD2VCjQ4k9CYjwq8Jkk+rKkFiH3o9cyJu9pb4=; b=qIUhxvmG+gLWa5CY5zFvGefcvm7XqMRm9n0QiZagpGHf+ydA+3yQo8E6s008P1n+Ki 3KFe5VmTwWqJBhHY4WXukfxtX0iYQmwM68xXRSF1JCrtrOVMlv7k+2KRr0TaOpgpgvAG qNF4pgHTHBztd258ujWk3Fkj9hJKd0G0drhlLCPCS61v6tZfaU4zLVXu1hvPfjiyvegX mF/RyGzi/t7/1mxmy/XGcMGyySVervHd+VqNYnVBzx+ie1gXqgXWlomOjGepks/zpWeU p0DXLwGAS11FhDo/qlQP/pPdIQ7U2stWH5i5bnym1MrtZkT+rO7SMvpl37MD3vdxxf02 VbrQ==
X-Received by 10.202.210.215 with SMTP id j206mr18207454oig.131.1426534891274; Mon, 16 Mar 2015 12:41:31 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <me7505$rnp$1@ger.gmane.org>
References <CAPTjJmqr4w_tAxkJ5N5aw=8YBKYOyJLGCMqnEjDDCk3T2LrSgA@mail.gmail.com> <20150316025301.GA94576@cskk.homeip.net> <mailman.409.1426476166.21433.python-list@python.org> <873855tts4.fsf@jester.gateway.sonic.net> <mailman.411.1426484388.21433.python-list@python.org> <55068cb0$0$12923$c3e8da3$5496439d@news.astraweb.com> <8761a1gxhq.fsf@jester.gateway.sonic.net> <CAEfz+TxKBdUrhxUT43Bq5Td=G9Nbu1ANHjF2Ou1tPfih8PNh6w@mail.gmail.com> <me7505$rnp$1@ger.gmane.org>
From INADA Naoki <songofacandy@gmail.com>
Date Tue, 17 Mar 2015 04:41:11 +0900
Subject Re: Python 2 to 3 conversion - embrace the pain
To Terry Reedy <tjreedy@udel.edu>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.462.1426534899.21433.python-list@python.org> (permalink)
Lines 104
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1426534899 news.xs4all.nl 2916 [2001:888:2000:d::a6]:58207
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87582

Show key headers only | View raw


On Tue, Mar 17, 2015 at 2:47 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 3/16/2015 5:13 AM, INADA Naoki wrote:
>
>> Another experience is porting Flask application in my company from
>> Python 2 to Python 3.
>> It has 26k lines of code and 7.6k lines of tests.
>>
>> Since we don't need to support both of PY2 and PY3, we used 2to3.
>> 2to3 changes 740 lines.
>
>
> That is less than 3% of the lines.  Were any changes incorrect?  How many
> lines *not* flagged by 2to3 needed change?

All changes are OK. Flask (and Werkzeug) handles most part of pain.
Application using Flask uses unicode most everywhere on Python 2 already.

Few changes 2to3 can't handle is like this:

-    reader = DictReader(open(file_path, 'r'), delimiter='\t')
+    reader = DictReader(open(file_path, 'r', encoding='utf-8'), delimiter='\t')

Since csv module in Python 2 doesn't support unicode, we had to parse
csv as bytestring.
And our server doesn't have utf-8 locale, we should specify encoding
explicitly on PY3.
There were few (less than 10, maybe) easy trouble like this.


>
>> I had to replace google-api-client with
>> requests+oauthlib since
>> it had not supported PY3 yet.
>
>
> Other than those needed for this change, which 2to3 could not anticipate or
> handle?
>
>> After that, we encountered few trouble with untested code. But Porting
>> effort is surprisingly small.
>> We're happy now with Python 3.  We can write non-ascii string to log
>> without fear of UnicodeError.
>> We can use csv with unicode without hack.
>
>
> People who use ascii only or perhaps one encoding everywhere severely
> underestimate the benefit of unicode strings (and utf-8) everywhere.


I agree. We may lost log easily on Python 2. It makes investigating bug hard.

    >>> import logging
    >>> logging.error("%s %s", u'こんにちは', 'こんにちは')
    Traceback (most recent call last):
    ...
      File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py",
line 335, in getMessage
        msg = msg % self.args
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in
position 0: ordinal not in range(128)
    Logged from file <stdin>, line 1


And log including unicode is hard to read.

    >>> logging.error("%s", [u'こんにちは'])
    ERROR:root:[u'\u3053\u3093\u306b\u3061\u306f']


Python 3 makes our development faster and easier.

Since old Python programmers knows how to avoid pitfalls in Python 2,
writing Python 2 is not a pain.
But when teaching Python to PHP programmer, teaching tons of pitfalls is pain.
This is why I think new applications should start with Python 3.

>
>> Porting *modern* *application* code to *PY3 only* is easy, while
>> porting libraries on the edge of
>> bytes/unicode like google-api-client to PY2/3 is not easy.
>>
>> I think application developers should use *only* Python 3 from this year.
>> If we start moving, more library developers will be able to start
>> writing Python 3 only code from next year.
>
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list



--
INADA Naoki  <songofacandy@gmail.com>

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


Thread

Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-16 14:22 +1100
  Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-15 22:07 -0700
    Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-16 16:39 +1100
      Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-15 23:17 -0700
        Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-16 19:00 +1100
          Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-16 01:31 -0700
            Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 00:05 +1100
              Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-17 00:29 +1100
            Re: Python 2 to 3 conversion - embrace the pain Terry Reedy <tjreedy@udel.edu> - 2015-03-16 13:59 -0400
      Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-16 18:56 +1100
        Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-16 01:25 -0700
          Re: Python 2 to 3 conversion - embrace the pain INADA Naoki <songofacandy@gmail.com> - 2015-03-16 18:13 +0900
            Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-16 22:55 +1100
          Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 01:25 +1100
            Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-16 15:36 -0700
              Re: Python 2 to 3 conversion - embrace the pain Terry Reedy <tjreedy@udel.edu> - 2015-03-16 22:28 -0400
                Re: Python 2 to 3 conversion - embrace the pain wxjmfauth@gmail.com - 2015-03-17 01:31 -0700
              Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 22:26 +1100
                Re: Python 2 to 3 conversion - embrace the pain wxjmfauth@gmail.com - 2015-03-17 07:03 -0700
                Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-17 15:35 +0100
                Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-19 16:23 -0700
                Re: Python 2 to 3 conversion - embrace the pain Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-03-19 22:03 -0400
                Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-20 03:54 +0100
          Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 11:20 -0600
            Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 07:36 +1100
              Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 20:14 -0600
              Re: Python 2 to 3 conversion - embrace the pain Cameron Simpson <cs@zip.com.au> - 2015-03-17 17:47 +1100
          Re: Python 2 to 3 conversion - embrace the pain Terry Reedy <tjreedy@udel.edu> - 2015-03-16 13:47 -0400
          Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-16 18:14 +0000
          Re: Python 2 to 3 conversion - embrace the pain INADA Naoki <songofacandy@gmail.com> - 2015-03-17 04:41 +0900
          Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-17 09:02 +1100
            Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-17 04:04 +0100
              Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 21:33 -0600
                Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 19:36 +1100
              Re: Python 2 to 3 conversion - embrace the pain Ben Finney <ben+python@benfinney.id.au> - 2015-03-17 14:42 +1100
                Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-17 05:30 +0100
                Re: Python 2 to 3 conversion - embrace the pain Cameron Simpson <cs@zip.com.au> - 2015-03-18 08:53 +1100
              Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-17 14:49 +1100
                Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-17 05:26 +0100
                Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 04:36 +0000
                Re: Python 2 to 3 conversion - embrace the pain Grant Edwards <invalid@invalid.invalid> - 2015-03-17 14:50 +0000
                Re: Python 2 to 3 conversion - embrace the pain wxjmfauth@gmail.com - 2015-03-17 08:15 -0700
                Re: Python 2 to 3 conversion - embrace the pain Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-03-17 18:36 -0400
                Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 22:41 +0000
                Re: Python 2 to 3 conversion - embrace the pain Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-03-18 08:04 -0400
                Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-18 02:02 +0100
          [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 19:46 -0600
            Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 19:39 +1100
              Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-17 09:02 -0600
            Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-19 16:37 -0600
              Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain wxjmfauth@gmail.com - 2015-03-20 02:40 -0700
                Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-20 15:59 +0100
                Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-20 16:03 +0100
                Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-20 15:42 +0000
                Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-21 04:13 +1100
                Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain wxjmfauth@gmail.com - 2015-03-20 12:21 -0700
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-17 12:57 +1100
            Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-16 19:45 -0700
              Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 21:05 -0600
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 20:07 -0600
          Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 02:21 +0000
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Ben Finney <ben+python@benfinney.id.au> - 2015-03-17 13:40 +1100
            Package manager cooperation? (was Weaknesses of distro package managers) Rustom Mody <rustompmody@gmail.com> - 2015-03-16 20:09 -0700
              Re: Package manager cooperation? (was Weaknesses of distro package managers) Michael Torrie <torriem@gmail.com> - 2015-03-16 21:32 -0600
              Re: Package manager cooperation? (was Weaknesses of distro package managers) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 04:03 +0000
              Re: Package manager cooperation? (was Weaknesses of distro package managers) Chris Angelico <rosuav@gmail.com> - 2015-03-17 15:18 +1100
                Re: Package manager cooperation? (was Weaknesses of distro package managers) wxjmfauth@gmail.com - 2015-03-17 01:44 -0700
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 20:51 -0600
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 03:01 +0000
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Michael Torrie <torriem@gmail.com> - 2015-03-16 21:05 -0600
            Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mario Figueiredo <marfig@gmail.com> - 2015-03-17 04:07 +0100
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-17 03:17 +0000
          Re: [OT] Weaknesses of distro package managers - was Re: Python 2 to 3 conversion - embrace the pain Alexander <xr.lists@gmail.com> - 2015-03-17 16:44 +1300
        Re: Python 2 to 3 conversion - embrace the pain Chris Angelico <rosuav@gmail.com> - 2015-03-16 19:51 +1100
    Re: Python 2 to 3 conversion - embrace the pain Terry Reedy <tjreedy@udel.edu> - 2015-03-16 04:53 -0400
      Re: Python 2 to 3 conversion - embrace the pain Paul Rubin <no.email@nospam.invalid> - 2015-03-16 02:27 -0700

csiph-web