The 'c:\temp\test.py' code below shows how easy this is using Python:
Code: Select all
import sys
def main():
filename = 'c:\\temp\\test.py'
with open(filename) as lines:
# enumerate the lines of the file
for index, line in enumerate(lines):
# Note: Use stdout as the line already has a line feed
sys.stdout.write('[' + str(index) + ']: ' + line)
main()
[0]: import sys
[1]:
[2]: def main():
[3]: filename = 'c:\\temp\\test.py'
[4]:
[5]: with open(filename) as lines:
[6]: # enumerate the lines of the file
[7]: for index, line in enumerate(lines):
[8]: # Note: Use stdout as the line already has a line feed
[9]: sys.stdout.write('[' + str(index) + ']: ' + line)
[10]: main()