convert use of sed to pure python

Solves #1267.