vars(os) starts help in ActivePython!!!

Patrick K. O'Brien pobrien at orbtech.com
Tue Feb 26 14:31:09 EST 2002


Well, this particular problem still exists. It has nothing to do with
PythonWin or PyCrust. It has to do with the trick used by help, license,
etc. Which is to make an object callable and then hook up that call to the
__repr__ method. This works nicely in the shell in that you can then call
the object without the trailing parens:

>>> help

instead of

>>> help()

The problem is the object is called whenever a representation of itself is
requested, which happens during vars() and other similar functions in the
shell. What you are seeing are the side effects of this trick. If the called
object does something unusual (like exiting the application <wink>) you can
get unexpected (but not entirely unpredictable) behavior.

--
Patrick K. O'Brien
Orbtech


"Keith Farmer" <kfarmer at thuban.org> wrote in message
news:k7me8.42891$9_1.1798161575 at newssvr14.news.prodigy.com...
> Not ActiveState -- regular Win32 install:
>
> Microsoft Windows 2000 [Version 5.00.2195]
> (C) Copyright 1985-2000 Microsoft Corp.
>
> C:\>python
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
>
> Here's one symptom I noticed (in the copyright entry .. also in the
license,
> you'll see):
>
>  <class exceptions.AssertionError at 0x00881490>, 'TypeError': <class
> exceptions
> .TypeError at 0x0087E868>, 'copyright': Copyright (c) 2001 Python Software
> Found
> ation.
> All Rights Reserved.
>
> Copyright (c) 2000 BeOpen.com.
> All Rights Reserved.
>
> Copyright (c) 1995-2001 Corporation for National Research Initiatives.
> All Rights Reserved.
>
> Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
> All Rights Reserved., 'license': Type license() to see the full license
> text, 'c
> lassmethod': <type 'classmethod'>, 'KeyboardInterrupt': <class
> exceptions.Keyboa
> rdInterrupt at 0x0087ED50>, 'UserWarning': <class exceptions.UserWarning
at
> 0x00
>
> What I ended up noticing was that the way the dict gets handled seems to
> execute the value under certain conditions which I didn't bother to
> investigate further.  In PyCrust (before Patrick made his corrections,
which
> I haven't tried out), I was able to cause my program to exit by inserting
a
> reference to the exit function into the namespace and then print it out.
>
> However, the excerpt above doesn't come from PyCrust -- it was from the
> command line interpreter.
>
> I'm running Win2k SP2.
>
> ----------
> Keith J. Farmer
> kfarmer at thuban.org
> http://www.thuban.org






More information about the Python-list mailing list