replace subprocess and use python for editing file