How to tell if I'm being run from a shell or a module

dg.google.groups at thesamovar.net dg.google.groups at thesamovar.net
Thu Feb 14 18:21:59 CET 2008


Hi all,

Is there any standard way to tell if the user is running from a module
or from an interactive shell like IDLE or IPython? The best I've come
up with so far is for a function to look at
getouterframes(currentframe())[1][1] (the filename in the frame record
of the frame that called the function), and check if it exists or not
with os.path.exists. IPython gives '(ipython console)' and IDLE gives
'pyshell#0' whereas running from a module gives its filename. This
seems a bit hacky. Any better ideas?

--
Dan Goodman
http://thesamovar.net/contact



More information about the Python-list mailing list