Você deve evitar subprocess
e implementar a funcionalidade de sed
com o Python, por exemplo, com o módulo fileinput
:
#! /usr/bin/python
import fileinput
for line in fileinput.input("www.txt", inplace=True):
# inside this loop the STDOUT will be redirected to the file
# the comma after each print statement is needed to avoid double line breaks
print line.replace("hello", "helloworld"),