이 코드는 간단한 목록에서 완벽하게 실행되었지만 데이터베이스에서 실행하려고했기 때문에 double for 루프에 StopIteration 오류가 발생합니다. EDIT : 이제 문제는 단지 어떤 유형의 오류도 발생하지 않는다는 것입니다. 명령 행은 실행할 때 비어 있습니다.간단한 목록 대신 데이터베이스에서 Visual Studio를 실행할 때 코드가 실행되지 않는 이유는 무엇입니까?
['flore', 'fleur', 'fleuriste'], ['remaniement', 'remanier', 'manier', 'maniable'], ['désaimer', 'aimer', 'aimant'], ['mêler', 'emmêler', 'désemmêler']
별도로 코드의 각 부분을 시도하는 데, 모든 작품 :
# -*- coding: utf-8 -*-
import pyodbc
import re
from difflib import SequenceMatcher
[x for x in pyodbc.drivers() if x.startswith('Microsoft Access Driver')]
# Connection to accdb
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:\\Users\\alice\\Desktop\\lexique3.accdb;'
)
cnxn = pyodbc.connect(conn_str)
crsr = cnxn.cursor()
# Put all words into a list
crsr.execute("select unites_lexicales from Mot where cat_grammat='Verbe' or 'Nom' or 'Adjectif' or 'Adverbe'")
resultat = crsr.fetchall()
words = [row[0] for row in resultat]
#print(words)
# Remove unwanted characters and put radicals into a list
radicals = []
motifp = "^(an|re|dé|dés)"
motifs = "(ist|man|er|an|able|asyon)$"
for word in words :
word = re.sub(motifp, '', word)
word = re.sub(motifs, '', word)
radicals.append(word)
#print(radicals)
# Match radicals and put words into new lists
ratio = 0.6
n = len(radicals)
result = []
used_js = []
for i in range(n) :
if i in used_js:
continue
matches = [words[i]]
js = (x for x in range(n) if x != i and x not in used_js)
for j in js : # Previous error : StopIteration
if SequenceMatcher(None, radicals[i], radicals[j]).ratio() >= ratio :
matches.append(words[j])
used_js.append(j)
result.append(matches)
print(result)
가 예상되는 결과는 (내가 이전에 간단한 목록 있던) 다음과 같다 : 여기
내 코드입니다 double for 루프 외에도 괜찮습니다. 왜 내가 그것을 실행할 수 없는지에 대한 단서와 내가 이것을 고칠 수있는 방법이 정말로 도움이 될 것이다. 감사합니다.(x for x in range(n) if x != i and x not in used_js)
이 아이템을 얻을 수 없습니다 반복자입니다 :
당신이 스택 추적을 게시 할 수 있습니까? –
@LaurentLAPORTE print_stack()을 사용하여 작동하는 경우, 실행할 때 아무 것도 나타나지 않습니다. –
@LaurentLAPORTE Visual Studio에서는 오류가 전혀 발생하지 않지만 코드는 실행되지 않는다고 알려줍니다. –