All pastes #106175 Raw Edit

Mine

public text v1 · immutable
#106175 ·published 2006-07-30 04:28 UTC
rendered paste body
class myfile:

	def __init__(self, myfile, mode="r"):
		self.myfile = open(myfile, "r+")
		
	def get_lines(self):
		return self.myfile.readlines()
	
	def replace_line(self, oldline, newline ):
		for line in self.get_lines():
			self.myfile.seek(0)
			self.myfile.write(line.replace(oldline, newline))

myfile = myfile("example.txt", "r+")
myfile.replace_line("Nano", "Daniel")