User Profile

Collapse

Profile Sidebar

Collapse
mcff
mcff
Last Activity: Dec 4 '12, 12:01 AM
Joined: Dec 3 '12
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Sorry it was easy, I just added i+1:
    Code:
    infile=open('resultado.txt','r')
    lines=infile.readlines()
    infile.close()
    outtext=['%d %s' % (i+1,line) for i, line in enumerate(lines)]
    outfile = open ('res.txt','w')
    outfile.write(str(''.join(outtext)))
    outfile.close()
    See more | Go to post
    Last edited by bvdet; Dec 3 '12, 04:32 PM. Reason: Please use code tags when posting code.

    Leave a comment:


  • Edit text file to add row numbers (begins in 1 ) - Python

    If this is the input:
    a
    b
    c

    I want to have this:
    1 a
    2 b
    3 c

    I have this code:
    Code:
    infile=open('resultado.txt','r')
    lines=infile.readlines()
    infile.close()
    outtext=['%d %s' % (i,line) for i, line in enumerate(lines)]
    outfile = open ('res.txt','w')
    outfile.write(str(''.join(outtext)))
    outfile.close()
    but my row number begins in ...
    See more | Go to post
    Last edited by bvdet; Dec 3 '12, 04:31 PM. Reason: Please use code tags when posting code.
No activity results to display
Show More
Working...