Writing bytes to odd and even locations

I'm having a problem where I want to write bytes into specific odd and even places in a binary file (key.bin), but it just writes over everything. How can this problem be fixed, so it writes specific bytes in even and odd byte positions without rewriting everything?

text = open("text.bin","wb")
key = open("key.bin","wb")
print('Enter text:')
txt='python' # input()
print(" ".join(txt))
strtobin= ' '.join(format(ord(x), 'b') for x in txt)
print(strtobin)
l=len(txt)
print(l, 'bytes')

# even bytes
for v in range(0, len(txt), 2):
    print(v)
    key.seek(v,0)
    key.write(bytes(0)) # for XOR

shift=2
sh=shift.to_bytes(1, byteorder='big')
# odd bytes
for a in range(1,len(txt)+1):
    if a % 2 != 0:
        print(a)
    key.seek(a,0)
    key.write(sh)

#writing second XOR mask with shifted bytes by 2 (shift=2)
for i in range( len(txt) ):
    print(ord(txt[i]))
    b=ord(txt[i])
    byte = b.to_bytes(1, byteorder='big')
    text.write(byte)
    #print(txt)

enter image description here

It should be 00000100 011111001 00000100 011111001 00000100 (00000100 - means an offset by 2 bytes in text.bin file.)