[Python] Setting sys.displayhook only works if it's ran at the same time as other commands

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to have Spyder print newlines between commands, so I run this:

    # Force Spyder to print newlines every command
    def alwaysprint_displayhook(value):
    if value is not None:
    sys.stdout.write(str(value) + "\n\n")

    sys.displayhook = alwaysprint_displayhook


    However, it only runs if I run everything at once like:

    sys.displayhook = alwaysprint_displayhook
    df1.columns
    df2.columns


    Instead, I would like it to be globally set. Having Spyder run those lines at startup does not work.
    displayhook documentation:
    https://docs.python.org/3/library/sys.html#sys.displayhook

    Continue reading...

Compartilhe esta Página