Adding Line Numbers to a Python Script : Fileinput : Buildin Module PYTHON TUTORIALS


PYTHON TUTORIALS » Buildin Module » Fileinput »

 

Adding Line Numbers to a Python Script


import fileinput

for line in fileinput.input(inplace=True):
    line = line.rstrip()
    num = fileinput.lineno()
    print '%-40s # %2i' % (line, num)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Buildin Module
» Fileinput