Automating section analysis in Python