python - Setting sys.displayhook only works if it's ran at the same time as other commands - Stack Overflow

admin2025-04-16  4

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:
.html#sys.displayhook

转载请注明原文地址:http://www.anycun.com/QandA/1744759095a87211.html