liste als 'type' (python2) /'class' (python3)

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
nezzcarth
User
Beiträge: 1793
Registriert: Samstag 16. April 2011, 12:47

Hallo :)

ich spiele gerade ein wenig mit dem python-levenshtein Paket herum, das angeblich unter Python2 und Python3 problemlos funktionieren sollte.
Allerdings stoße ich auf folgendes Problem, wenn ich folgendes Beispiel aus der Dokumentation unter Python3.3 laufen lasse:

(python 3.3.3)

Code: Alles auswählen

>>> from Levenshtein import *
>>> e = editops('man', 'scotsman')
>>> apply_edit(e, 'man', 'scotsman')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: apply_edit first argument must be a List of edit operations
>>> type(e)
<class 'list'>
(python 2.7.6)

Code: Alles auswählen

>>> from Levenshtein import *
>>> e = editops('man', 'scotsman')
>>> apply_edit(e, 'man', 'scotsman')
'scotsman'
>>> type(e)
<type 'list'>
Scheinbar liegt das Problem darin, dass Listen in Python 3 Klassen sind, in Python 2 (mit dem ich mich bisher nicht befasst habe) allerdings als Typen behandelt werden. Gibt es eine Möglichkeit, das ich das in Python3 umgehen kann, ohne, dass in der in C geschriebenen Bibliothek rumfummeln muss?

Ich nehme an, dass es sich dabei um ein wohlbekanntes Problem, nach dem schon oft gefragt wurde, handelt. Leider konnte ich aber nichts finden. Daher würde ich mich über ein paar Hinweise freuen :)
BlackJack

Eigenartiges Problem welches wohl von dieser Zeile herrührt aber eigentlich gar nicht dürfte wenn ich das richtig verstanden habe: https://github.com/ztane/python-Levensh ... in.c#L1809

Dann wäre das ein Fehler in Python 3. :K
Antworten