Adding Line Numbers to a Python Script : File Text : File PYTHON examples


PYTHON examples » File » File Text »

 

Adding Line Numbers to a Python Script



import fileinput

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


           
       



Leave a Comment / Note


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


PYTHON examples

 Navioo File
» File Text