def clear_readline():
    # Next line said to be reasonably portable for various Unixes
    _, cols = unpack('hh', ioctl(stdout, TIOCGWINSZ, '1234'))
    length = len(readline.get_line_buffer()) + len(prompt)
    lines = cols / length
    # ANSI escape sequences (All VT100 except ESC[0G)
    stdout.write('\x1b[2K')                 # Clear current line
    stdout.write('\x1b[1A\x1b[2K' * lines)  # Move cursor up and clear line
    stdout.write('\x1b[0G')                 # Move to start of line
dataset/ETHPy150Open hpk42/p4p/attic/play_async_print2.py/clear_readline/swapped operands of `/`