editing specific line in text file in python code example
Example 1: how to edit a specific line in text file in python
with open('stats.txt', 'r') as file:
data = file.readlines()
print data
print "Your name: " + data[0]
data[1] = 'Mage\n'
with open('stats.txt', 'w') as file:
file.writelines( data )
Example 2: editing specific line in text file in python
with open('stats.txt', 'r') as file:
data = file.readlines()
print data
print "Your name: " + data[0]
data[1] = 'Mage\n'
with open('stats.txt', 'w') as file:
file.writelines( data )