By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

how to modify specific line in a file using python

P: 1
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]
Jul 4 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.