Skip to content
Vince Buffalo edited this page Aug 10, 2015 · 1 revision

Executing something only if Python's in interactive mode

import __main__ as main
if not hasattr(main, '__file__'):
    # stuff goes here

This is useful if one has a script that outputs something to standard out that they'd like to work interactively with — just throw the outputting code in this block.

Clone this wiki locally