some output when run as scriptmod py "if comrade napoleon says itit must be right [ def foo(arg)print( 'arg {arg}'class foopass print(sprint(afoo('quux' foo(print(xnow it should be little more interestingc:\users\john\documents>python mod py if comrade napoleon says itit must be right [ arg quux unfortunatelynow it also generates output when imported as moduleimport mod if comrade napoleon says itit must be right [ arg quux this is probably not what you want it isn' usual for module to generate output when it is imported wouldn' it be nice if you could distinguish between when the file is loaded as module and when it is run as standalone scriptask and ye shall receive when py file is imported as modulepython sets the special dunder variable __name__ to the name of the module howeverif file is run as standalone script__name__ is (creativelyset to the string '__main__using this factyou can discern which is the case at run-time and alter behavior accordinglymod py "if comrade napoleon says itit must be right [ def foo(arg)print( 'arg {arg}'