text = """
def sample_func(self):
print("aaa")
data = []
if data:
for i, j in enumerate(data):
print(i, j
print("ifでメッセージ")
else:
for i in range(10):
print(i)
print("elseでメッセージ")
"""
stack = []
pair = []
for i, t in enumerate(text):
if t == "(":
stack.append(i)
if t == ")":
if stack:
pair.append([stack.pop(), i])
else:
pair.append(["pair not found", i])
print(stack, "", pair)
print("***********************")
if stack: # (が多い場合
print(text[stack[0] - 10 : stack[0] + 10])
else: # )が多い場合
for p in pair:
if p[0] == "pair not found":
print(text[p[1] - 10 : p[1] + 10])
➀添付したtxtファイルをダウンロードして拡張子を「.py」に変更する。
➁pyファイルのtextという変数の値を変える。(2~12行目)
エラーが起きているファイルをそのまま値として変数に入れたいです。
➂pyファイルを実行します。
vscodeだと右クリックで「pythonの実行」があるので、それで大丈夫です。
④ターミナルを確認し、どこで()がズレているか確認します。