fileinput « Buildin Module « Python Tutorial

14.5.fileinput
14.5.1.Adding Line Numbers to a Python Script