I want to use re.subn in my program to get no of times changes are made but I can't figure it out how to write the code. I have written the program with re.sub and it works fine but If I use (re.sub(r'\bi\b','I',contents)) in this program it shows this error.
TypeError: write() argument must be str, not int
import re
with open ('Sample.txt','r') as rf:
contents=rf.read()
change=(re.sub(r'\bi\b','I',contents))
with open ('Sample2.txt','w') as wf:
wf.writelines(change)
Can someone please guide how can I use re.subn to get the count. Thank you.