User Profile

Collapse

Profile Sidebar

Collapse
Boeileh
Boeileh
Last Activity: Oct 6 '08, 12:45 PM
Joined: Oct 2 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Boeileh
    replied to Edit text file to add row numbers
    It works! Thanks everybody!

    This is the final code:
    Code:
    infile=open('2_2000.txt', 'r')
    lines=infile.readlines()
    infile.close()
    outtext = ['%d %s' % (i, line) for i, line in enumerate(lines)]
    outfile = open("3_2000.txt","w")
    outfile.writelines(str("".join(outtext)))
    outfile.close()
    See more | Go to post

    Leave a comment:


  • Boeileh
    replied to Edit text file to add row numbers
    Their is still something going wrong. This is the code I have now:
    Code:
    infile=open('infile.txt', 'r')
    lines=infile.readlines()
    infile.close()
    inlist=list(lines)
    outtext = {}
    for i in range(len(inlist)):
        outtext[i] = str(i) + ' ' + inlist[i]
    outfile = open("outfile.txt","w")
    outfile.writelines(str(outtext))
    outfile.close()

    If this is the input:
    ...
    See more | Go to post

    Leave a comment:


  • Boeileh
    replied to Edit text file to add row numbers
    I now have this, but it is still not working..

    file = open("infile.tx t")
    intext = file.read()
    file.close()

    for i in range(len(intex t)):
    outtext[i] = str(i) + ' ' + intext[i]

    file = open("outfile.t xt","w")
    file.write(outt ext)
    file.close()
    See more | Go to post

    Leave a comment:


  • Boeileh
    started a topic Edit text file to add row numbers

    Edit text file to add row numbers

    Hi guys!
    I just arrived here on this forum, and I hope you people can help me a bit with Python.

    What I want is to edit a few large text files, by adding in front of each row the concerning rownumber. What I find out myself (not much..) is:

    infile = open('infile.tx t')
    outfile = open('outfile.t xt','w')
    for i in range(len(infil e)):
    infile[i] = str(i) + ' ' + cb[i]
    infile.close()
    ...
    See more | Go to post
No activity results to display
Show More
Working...