Help with Pexpect / python coding

trying to use this to gatt …any help would be appreciated

import pexpect
import time
device_no = "hci0"
mac_str = "34:85:18:6A:52:52"
cmd = pexpect.spawn('sudo gatttool -i ' + device_no + ' -b ' + mac_str + ' -I')
cmd.expect('\[LE\]>')
cmd.sendline('connect')
cmd.expect('Connection successful')
cmd.sendline('char-write-req 0x0030 a500000800536f0e000310010212010aff01209a')
cmd.expect('Characteristic value was written successfully')
time.sleep(10)
cmd.sendline('disconnect')
cmd.expect('\[LE\]>')
cmd.sendline('exit')

exit0