D
dg.google.groups
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?
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?