python - Using string to call function -
from en import verb print verb.tenses() print verb.infinitive('argue') ['infinitive', 'present participle', 'past plural', '2nd singular present', '2nd singular past', 'past', '3rd singular present', 'past participle', '1st singular present', '1st singular past', '3rd singular past', 'present plural'] argue
i can't find method give tenses of verb. there 1 way call each function: replace space list using verb object. how can accomplish this?
the input: argue
. output should be: arguing
,argued
,argue
..
you can create list of names / parameters each name of tense. example:
tense_functions = { 'infinitive': ('infinitive', {}), 'present participle': ('present_participle', {}), '1st singular present': ('present', {'person': 1}), ... } tense in verb.tenses(): options = tense_functions[tense] func = getattr(verb, options[0]) print(func('argue', **options[1]))
Comments
Post a Comment