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


Groups > de.comp.lang.python > #5143

Re: [Python-de] Migration Python 2 auf 3

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Christopher Arndt <chris@chrisarndt.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Migration Python 2 auf 3
Date Fri, 16 Mar 2018 15:50:28 +0100
Lines 29
Message-ID <mailman.110.1521211851.1867.python-de@python.org> (permalink)
References <p8ggsi$96i$1@solani.org> <p8gkmm$bn2$2@solani.org> <af4e9ff0-fd7a-a975-e904-0097b2204cc4@chrisarndt.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de vt92wXMavaYUhxXU3I+9uA1QxS39H+P+BvWH22uhFW9g==
Return-Path <chris@chrisarndt.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
X-Virus-Scanned Debian amavisd-new at mx01.0x20.eu
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
In-Reply-To <p8gkmm$bn2$2@solani.org>
Content-Language de-DE
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.26
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <af4e9ff0-fd7a-a975-e904-0097b2204cc4@chrisarndt.de>
X-Mailman-Original-References <p8ggsi$96i$1@solani.org> <p8gkmm$bn2$2@solani.org>
Xref csiph.com de.comp.lang.python:5143

Show key headers only | View raw


Am 16.03.2018 um 15:35 schrieb Philipp Klaus Krause:
>     m = re.match(r'([^/]*)/([^/]*)/([^/]*)/(.*)$', name)
>     if (m >= 3):
>
> TypeError: '>=' not supported between instances of '_sre.SRE_Match' and
> 'int'

Der Python 2 Code benutzt offenbar ein undokumentiertes Verhalten, dass
die Verwendung eines Regular Expression Match Objects im Integer-Kontext
zulässt. Die Semantik dessen kann ich nicht genau sagen, aber ich
vermute mal, dass es dem Attribut 'lastindex' eines Match Objects
entspricht.

Wenn dem so wäre, könntest du 'if (m >= 3):'* durch

if m and m.lastindex >= 3:

ersetzen.

Jetzt hoffe ich für dich, dass für den Code Tests existieren! ;)


* Der Original-Code hat übrigens noch einen Bug: wenn kein Match
gefunden wird, ist m None. Und die Klammern sind auch unnötig
(C-Programmierer?).


Chris

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


Thread

Migration Python 2 auf 3 Philipp Klaus Krause <pkk@spth.de> - 2018-03-16 14:29 +0100
  Re: [Python-de] Migration Python 2 auf 3 Christopher Arndt <chris@chrisarndt.de> - 2018-03-16 14:44 +0100
  Re: [Python-de] Migration Python 2 auf 3 Hartmut Goebel <h.goebel@crazy-compilers.com> - 2018-03-16 14:44 +0100
    Re: [Python-de] Migration Python 2 auf 3 Philipp Klaus Krause <pkk@spth.de> - 2018-03-16 15:32 +0100
  Re: Migration Python 2 auf 3 Philipp Klaus Krause <pkk@spth.de> - 2018-03-16 15:35 +0100
    Re: [Python-de] Migration Python 2 auf 3 Stefan Behnel <python-de@behnel.de> - 2018-03-16 15:46 +0100
    Re: [Python-de] Migration Python 2 auf 3 Christopher Arndt <chris@chrisarndt.de> - 2018-03-16 15:50 +0100
    Re: [Python-de] Migration Python 2 auf 3 Stefan Behnel <python-de@behnel.de> - 2018-03-16 17:05 +0100

csiph-web