Adding Line Numbers to a Python Script : File Text : File : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  File   » [  File Text  ]  Screenshots 
 



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)


           
       
Related examples in the same category
1.  Define class to deal with files
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.