Pythonファイルのコードが無限ループを通過するかどうかを識別する関数を作成しようとしています。これは私がこれまでに持っているものです:
def reader(filename):
myfile = open(filename)
counter = 0
#counters the number of lines in the file
for line in myfile:
counter +=1
print line
#print number of lines in file
print counter
#execute the code in file
execution = execfile(filename)
私がやろうとしているのは、ファイルを実行することです。おそらく、実行された行数を数えて、それを前のカウンターの数値と比較してみてください。たとえば、counter > lines_exected の場合に True を返すと、コードに無限ループが発生します。これは機能しますか?それとも、何か他のことを試す必要がありますか?