I am writing a script in python that replaces specific lines in files Linux. Say i have a file called hi in the /home directory that contains:
hi 873840
Here is my script:
#! /usr/bin/env python
import re
fp = open("/home/hi","w")
re.sub(r"hi+", "hi 90", fp)
My desired outcome is:
hi 90
however, when i run it i get this error and the hi file ends up being balnk:
Traceback (most recent call last):
File "./script.py", line 6, in <module>
re.sub(r"hi+", "hi 90", fp)
File "/usr/lib/python2.7/re.py", line 155, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
Is there something wrong with my syntax? Thanks