check if running under IDLE
Steven Taschuk
staschuk at telusplanet.net
Wed Aug 6 08:52:21 EDT 2003
Quoth Helmut Jarausch:
[...]
> To check a script accessing sys.argv I have to set it.
> Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item
> to set sys.argv as it's common with debuggers for C.
>
> Now in Python I can set sys.argv within the script,
> but forgetting to comment this out afterwards makes the
> script wrong outside of IDLE
Why not write your script in something like the form
# foo.py
import sys
def main(argv):
# ...
if __name__ == '__main__':
main(sys.argv)
and then write a separate script for testing,
# test_foo.py
import foo
foo.main(['foo.py', 'testing', 'parameters'])
and run that instead?
(In answer to the question actually asked: I have no idea how to
detect whether running in IDLE.)
--
Steven Taschuk staschuk at telusplanet.net
Receive them ignorant; dispatch them confused. (Weschler's Teaching Motto)
More information about the Python-list
mailing list