Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #5142
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Stefan Behnel <python-de@behnel.de> |
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] Migration Python 2 auf 3 |
| Date | Fri, 16 Mar 2018 15:46:51 +0100 |
| Lines | 46 |
| Message-ID | <mailman.109.1521211619.1867.python-de@python.org> (permalink) |
| References | <p8ggsi$96i$1@solani.org> <p8gkmm$bn2$2@solani.org> <8a7cb3d8-0784-c53c-0196-973192dc7951@behnel.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de MLN4qUkB8+V7oyPD3uMPmQlNQg9V/FAMgRPWJIpuW1sg== |
| Return-Path | <python-de@behnel.de> |
| X-Original-To | python-de@python.org |
| Delivered-To | python-de@mail.python.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; t=1521211612; s=strato-dkim-0002; d=behnel.de; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:Date:Message-ID: From:References:To:Subject:X-RZG-CLASS-ID:X-RZG-AUTH; bh=ICfVJ4lXmIrNxYD0rfzFDqYT4Xe3Pw3bL1+2dAKvMNE=; b=K1pWchCS29JWfWtPweCNhDhbDaKPakeCUFlQlz/Ihfp4z0bO+e6H10W0rTeO97vcwW 23z8DXGM9+7vBqCURD+Ob9/siBO7WCzUGxEiWsq5Ti6MeuoZ7dDUlCa4RU8BQTe9XT+f pwRcXOg/KLaHKAIMsdy0xPYcQUmcXZlP5z4b0e39rGBz/NP3VJbS73/lhZFq7cvJZfLt OiFxMsFofRoI/3k1Jn5CvLUok2iZcVlFUiMghf8HHNVdyhCU3S92Tgyt6u0fwNjF/lY0 NhlbBuUwq6/KYmaWQYyr3LmYaLeT/NeOcJcaqe00ylwy2SQuwhx2WjisZ54B5nHPnJKP 5xiw== |
| X-RZG-AUTH | :E1MMdFW4b++AXZOTwA41DOYM0Dv9LNWvavC/fJZ6Wfgmp/Lh1ANWCRaaq2R1hCooD/t2Vl9QPVeBUNbEes6Rlw6QSosucbUWfc1WN+9rZt+H2RwU |
| X-RZG-CLASS-ID | mo00 |
| 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 | <8a7cb3d8-0784-c53c-0196-973192dc7951@behnel.de> |
| X-Mailman-Original-References | <p8ggsi$96i$1@solani.org> <p8gkmm$bn2$2@solani.org> |
| Xref | csiph.com de.comp.lang.python:5142 |
Show key headers only | View raw
Philipp Klaus Krause schrieb am 16.03.2018 um 15:35:
> Der Rat,
> from __future__ import print_function
> zu verwenden, hat mir schonmal weitergeholfen. Vielen Dank.
>
> Nun hätte ich noch ein
>
> m = re.match(r'([^/]*)/([^/]*)/([^/]*)/(.*)$', name)
> if (m >= 3):
> base = m.group(3)
>
> das mit Python 2 funktioniert, aber mit Python 3 nicht:
>
> Traceback (most recent call last):
> File "./compact-results.py", line 50, in <module>
> if (m >= 3):
> TypeError: '>=' not supported between instances of '_sre.SRE_Match' and
> 'int'
Sehr hübsch. Das ist ein Bug im Code, hätte nie da stehen dürfen,
funktioniert aber durch Zufall:
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m = re.match('.', "abc")
>>> m
<_sre.SRE_Match object at 0x7fe76e8546b0>
>>> m >= 3
True
>>> m = None
>>> m >= 3
False
Sprich: was du eigentlich willst, ist der Test: regex hat gematcht oder
nicht. Das machst du am einfachsten mit
if m:
...
Da es in der regex immer vier Gruppen gibt, war die vermutliche
ursprüngliche Intention, auf die Anzahl der Gruppen zu testen, wohl auch
eher sinnfrei.
Stefan
Back to de.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
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