Sujet : Re: Script stops running with no error
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.lang.pythonDate : 29. Aug 2024, 03:33:33
Autres entêtes
Message-ID : <lja1fdF7i45U1@mid.individual.net>
References : 1
User-Agent : Pan/0.149 (Bellevue; 4c157ba)
On Wed, 28 Aug 2024 22:09:56 +0100, Daniel wrote:
if definition:
print(f"\n{word_type.capitalize()}\n")
print("\n".join(definition))
break
I don't know if that was intended but the 'break' kicks you out of
for word_type, pattern in cases.items():
I added a little debugging to show the cases iteration and commented out
the break. 'noun' has five lines and appears to be correct. 'verb' has
two lines, neither of which match the if/else. The others aren't in the
return from
https://api.wikimedia.org/core/v1/wiktionary/en/page/table.
I have to admit I sometimes miss C where I can bounce between curlies.
Output:
python wiki.py
*** Definition for table ***
word_type noun pattern: \{en-noun\}(.*?)(?=\{|\Z)
line }
line # Furniture with a top surface to accommodate a variety of uses.
line ## An item of [[furniture]] with a [[flat]] [[top]] [[surface]]
raised above the ground, usually on one or more legs.
line ##: ''Set that dish on the '''table''' over there, please.''
line ##*
Noun
1. Furniture with a top surface to accommodate a variety of uses.
a. An item of furniture with a flat top surface raised above the
ground, usually on one or more legs.
word_type verb pattern: \{en-verb\}(.*?)(?=\{|\Z)
line }
line #
word_type adjective pattern: \{en-adj\}(.*?)(?=\{|\Z)
word_type adverb pattern: \{en-adv\}(.*?)(?=\{|\Z)
word_type preposition pattern: \{en-prep\}(.*?)(?=\{|\Z)
word_type conjunction pattern: \{en-con\}(.*?)(?=\{|\Z)
word_type interjection pattern: \{en-intj\}(.*?)(?=\{|\Z)
word_type determiner pattern: \{en-det\}(.*?)(?=\{|\Z)
word_type pronoun pattern: \{en-pron\}(.*?)(?=\{|\Z)