def find_prompt(ssh_conn):
 ssh_conn.send('\n')
 time.sleep(1)
 ssh_conn.expect('#')
 prompt = (ssh_conn.before + ssh_conn.after)
 return prompt.strip()

def find_prompt ( ssh_conn ) : ssh_conn . send ( '\n' ) time . sleep ( 1 ) ssh_conn . expect ( '#' ) prompt = ( ssh_conn . before + ssh_conn . after ) return prompt . strip ( )
find the current prompt pexpect is non-greedy which is problematic .