you can also use standard module fileinput.input with ''inplace'' option which backs up original file automatically.
from python help for fileinput: Optional in-place filtering: if the keyword argument inplace=1 is passed to input() or to the FileInput constructor, the file is moved to a backup file and standard output is directed to the input file (if a file of the same name as the backup file already exists, it will be replaced silently). -- http://mail.python.org/mailman/listinfo/python-list