how to modify specific line in a file using python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanijh
    New Member
    • Jul 2016
    • 1

    how to modify specific line in a file using python

    i want to increment only one number in a file
    instead of that i am getting only string is displaying but not the number kindly help me in this


    [with open('d:/test.txt', 'r') as file:
    data = file.readlines( )

    print (data)
    print ("Your name: " + data[2])
    count=0
    data[2] ="routing context count"
    while count < 2:
    count+=1
    print(data[2])
    with open('d:/test.txt', 'w') as file:
    file.write('%d' % count)
    file.writelines ( data )
    ][/CODE]
Working...