[Tutor] Re: sitecustomize and pythonstartup

Christopher Smith csmith@blakeschool.org
Sun, 03 Feb 2002 13:45:17 -0600


>####
>def isInteractive():
>    """Returns 1 if we're running in an interpreter window, and false
>    otherwise.  This is a variation of what pydoc.help() tries."""
>    return inspect.stack()[3][1].find("PyInteractive")<>0
>
>class _InteractiveMath:
>    def __repr__(self):
>        if isInteractive():
>            import math
>            return repr(math)
>        else:
>            raise NameError, 'name "math" is not defined'

Raising an error in this function presents a problem to 
you when you want to "Browse the namespace" of a script
window since the browser apparently calls this function
which generates the NameError.  I have replaced this 
error with 

return "Loaded for interactive use by sitecustomize.py."

/c