change open() to open(mode='a') to make mode explicit.