私はこの構造に似たコードを持っています:
def my_gen(some_str):
if some_str == "":
raise StopIteration("Input was empty")
else:
parsed_list = parse_my_string(some_str)
for p in parsed_list:
x, y = p.split()
yield x, y
for x, y in my_gen()
# do stuff
# I want to capture the error message from StopIteration if it was raised manually
forループを使用してこれを行うことは可能ですか? これに似たケースは他に見当たりませんでした。for ループを使用できない場合、他にどのような方法がありますか?
ありがとう