Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #5143
| From | Christopher Arndt <chris@chrisarndt.de> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] Migration Python 2 auf 3 |
| Date | 2018-03-16 15:50 +0100 |
| 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> |
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 | 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