Problem with Help when using numarray

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin J. Williams

    #1

    Problem with Help when using numarray

    Python advertises some basic service:

    C:\Python24>pyt hon
    Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
    win32
    Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    With numarray, help gives unhelpful responses:

    import numarray.numarr aycore as _n
    c= _n.array((1, 2))
    print 'rank Value:', c.rank
    print 'c.rank Help:', help(c.rank)

    Results:
    rank Value: 1
    c.rank Help:Help on int object:

    class int(object)
    | int(x[, base]) -> integer
    |
    | Convert a string or number to an integer, if possible. A floating
    point
    | argument will be truncated towards zero (this does not include a
    ............... ... etc etc.

    Another example:
    [color=blue][color=green][color=darkred]
    >>> help(c.copy)[/color][/color][/color]
    <bound method NumArray.copy of array([1, 2])>[color=blue][color=green][color=darkred]
    >>> help(c.copy)[/color][/color][/color]
    Traceback (most recent call last):
    File "<interacti ve input>", line 1, in ?
    File "site.py", line 328, in __call__
    return pydoc.help(*arg s, **kwds)
    File "C:\Python24\li b\pydoc.py", line 1647, in __call__
    self.help(reque st)
    File "C:\Python24\li b\pydoc.py", line 1691, in help
    else: doc(request, 'Help on %s:')
    File "C:\Python24\li b\pydoc.py", line 1475, in doc
    pager(title % desc + '\n\n' + text.document(o bject, name))
    File "C:\Python24\li b\pydoc.py", line 297, in document
    if inspect.isrouti ne(object): return self.docroutine (*args)
    File "C:\Python24\li b\pydoc.py", line 1226, in docroutine
    if object.im_self:
    File "C:\Python24\Li b\site-packages\numarr ay\generic.py", line 537,
    in __nonzero__
    raise RuntimeError("A n array doesn't make sense as a truth value.
    Use any(a) or all(a).")
    RuntimeError: An array doesn't make sense as a truth value. Use any(a)
    or all(a).[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    c.copy.__doc_ does return the __doc__ string OK:[color=blue][color=green][color=darkred]
    >>> c.copy.__doc__[/color][/color][/color]
    'Returns a native byte order copy of the array.'[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    But c.rank.__doc__ does not:[color=blue][color=green][color=darkred]
    >>> c.rank.__doc__[/color][/color][/color]
    'int(x[, base]) -> integer\n\nConv ert a string or number to an integer,
    if possible. A floating point\nargument will be truncated towards zero
    (this does not include a string\nreprese ntation of a floating point
    number!) When converting a string, use\nthe optional base. It is an
    error to supply a base when converting a\nnon-string. If the argument is
    outside the integer range a long object\nwill be returned instead.'[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Colin W.
  • Robert Kern

    #2
    Re: Problem with Help when using numarray

    Colin J. Williams wrote:[color=blue]
    > Python advertises some basic service:
    >
    > C:\Python24>pyt hon
    > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
    > win32
    > Type "help", "copyright" , "credits" or "license" for more information.[color=green][color=darkred]
    > >>>[/color][/color]
    >
    > With numarray, help gives unhelpful responses:
    >
    > import numarray.numarr aycore as _n
    > c= _n.array((1, 2))
    > print 'rank Value:', c.rank
    > print 'c.rank Help:', help(c.rank)
    >
    > Results:
    > rank Value: 1
    > c.rank Help:Help on int object:
    >
    > class int(object)
    > | int(x[, base]) -> integer
    > |
    > | Convert a string or number to an integer, if possible. A floating
    > point
    > | argument will be truncated towards zero (this does not include a
    > ............... .. etc etc.[/color]

    c.rank is an integer, not a method. It doesn't have a docstring. It
    can't have a docstring.
    [color=blue]
    > Another example:
    >[color=green][color=darkred]
    > >>> help(c.copy)[/color][/color]
    > <bound method NumArray.copy of array([1, 2])>[color=green][color=darkred]
    > >>> help(c.copy)[/color][/color]
    > Traceback (most recent call last):
    > File "<interacti ve input>", line 1, in ?
    > File "site.py", line 328, in __call__
    > return pydoc.help(*arg s, **kwds)
    > File "C:\Python24\li b\pydoc.py", line 1647, in __call__
    > self.help(reque st)
    > File "C:\Python24\li b\pydoc.py", line 1691, in help
    > else: doc(request, 'Help on %s:')
    > File "C:\Python24\li b\pydoc.py", line 1475, in doc
    > pager(title % desc + '\n\n' + text.document(o bject, name))
    > File "C:\Python24\li b\pydoc.py", line 297, in document
    > if inspect.isrouti ne(object): return self.docroutine (*args)
    > File "C:\Python24\li b\pydoc.py", line 1226, in docroutine
    > if object.im_self:
    > File "C:\Python24\Li b\site-packages\numarr ay\generic.py", line 537,
    > in __nonzero__
    > raise RuntimeError("A n array doesn't make sense as a truth value.
    > Use any(a) or all(a).")
    > RuntimeError: An array doesn't make sense as a truth value. Use any(a)
    > or all(a).[color=green][color=darkred]
    > >>>[/color][/color][/color]

    c.copy.im_self is c . pydoc is trying to use it as a truth value (I'm
    not sure why, you'll have to take it up with pydoc, not numarray), but
    numarray has made a decision not to implement __nonzero__.

    --
    Robert Kern
    rkern@ucsd.edu

    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter

    Comment

    • Fredrik Lundh

      #3
      Re: Problem with Help when using numarray

      Colin J. Williams wrote:
      [color=blue]
      > With numarray, help gives unhelpful responses:
      >
      > import numarray.numarr aycore as _n
      > c= _n.array((1, 2))
      > print 'rank Value:', c.rank
      > print 'c.rank Help:', help(c.rank)[/color]

      c.rank returns a Python integer object.

      if you pass in an object to help(), help figures out what that object is,
      and tries to tell you what you can do with that object.

      the integer itself has no idea whatsoever from where it came; it's just
      an integer, and that's all Python knows about it.

      cf.
      [color=blue][color=green][color=darkred]
      >>> import sys
      >>> help(sys)[/color][/color][/color]
      Help on built-in module sys:
      NAME
      sys
      [color=blue][color=green][color=darkred]
      >>> help(sys.stdout )[/color][/color][/color]
      Help on file object:
      class file(object)
      | file(name[, mode[, buffering]]) -> file object
      [color=blue][color=green][color=darkred]
      >>> help(sys.stdout .softspace)[/color][/color][/color]
      Help on int object:
      class int(object)
      [color=blue][color=green][color=darkred]
      >>> help(sys.stdout .softspace.__in t__)[/color][/color][/color]
      Help on method-wrapper object:
      __int__ = class method-wrapper(object)

      and so on.

      </F>



      Comment

      • Colin J. Williams

        #4
        Re: Problem with Help when using numarray

        Fredrik Lundh wrote:[color=blue]
        > Colin J. Williams wrote:
        >
        >[color=green]
        >>With numarray, help gives unhelpful responses:
        >>
        >>import numarray.numarr aycore as _n
        >>c= _n.array((1, 2))
        >>print 'rank Value:', c.rank
        >>print 'c.rank Help:', help(c.rank)[/color]
        >
        >
        > c.rank returns a Python integer object.[/color]
        Fredrik,

        Thanks to Robert Kern and yourself.
        Yes, you are right. Most of such cases are treated as properties so
        that a doc string is available.

        I think that the script below shows that there are cases where a doc
        string is available but this information is not retrieved by help()

        names= [n * int(not ( '_' in n)) for n in dir(c)]
        for n in names:
        if len(n):
        try:
        txt= eval('c.'+n+'._ _doc__ ')
        print n, txt
        print 'help:', help('c.'+n)
        except:
        print n, ' fails'

        You give an integer example below, which I have marked <<<<<<<

        This gives the basics. help(c.rank) below gives much more and a lot of
        it is irrelevant.

        Colin W.
        [color=blue][color=green][color=darkred]
        >>> help(c.rank)[/color][/color][/color]
        Help on int object:

        class int(object)
        | int(x[, base]) -> integer
        |
        | Convert a string or number to an integer, if possible. A floating
        point
        | argument will be truncated towards zero (this does not include a string
        | representation of a floating point number!) When converting a
        string, use
        | the optional base. It is an error to supply a base when converting a
        | non-string. If the argument is outside the integer range a long object
        | will be returned instead.
        |
        | Methods defined here:
        |
        | __abs__(...)
        | x.__abs__() <==> abs(x)
        |
        | __add__(...)
        | x.__add__(y) <==> x+y
        |
        | __and__(...)
        | x.__and__(y) <==> x&y
        |
        | __cmp__(...)
        | x.__cmp__(y) <==> cmp(x,y)
        |
        | __coerce__(...)
        | x.__coerce__(y) <==> coerce(x, y)
        |
        | __div__(...)
        | x.__div__(y) <==> x/y
        |
        | __divmod__(...)
        | x.__divmod__(y) <==> xdivmod(x, y)y
        |
        | __float__(...)
        | x.__float__() <==> float(x)
        |
        | __floordiv__(.. .)
        | x.__floordiv__( y) <==> x//y
        |
        | __getattribute_ _(...)
        | x.__getattribut e__('name') <==> x.name
        |
        | __getnewargs__( ...)
        |
        | __hash__(...)
        | x.__hash__() <==> hash(x)
        |
        | __hex__(...)
        | x.__hex__() <==> hex(x)
        |
        | __int__(...)
        | x.__int__() <==> int(x)
        |
        | __invert__(...)
        | x.__invert__() <==> ~x
        |
        | __long__(...)
        | x.__long__() <==> long(x)
        |
        | __lshift__(...)
        | x.__lshift__(y) <==> x<<y
        |
        | __mod__(...)
        | x.__mod__(y) <==> x%y
        |
        | __mul__(...)
        | x.__mul__(y) <==> x*y
        |
        | __neg__(...)
        | x.__neg__() <==> -x
        |
        | __nonzero__(... )
        | x.__nonzero__() <==> x != 0
        |
        | __oct__(...)
        | x.__oct__() <==> oct(x)
        |
        | __or__(...)
        | x.__or__(y) <==> x|y
        |
        | __pos__(...)
        | x.__pos__() <==> +x
        |
        | __pow__(...)
        | x.__pow__(y[, z]) <==> pow(x, y[, z])
        |
        | __radd__(...)
        | x.__radd__(y) <==> y+x
        |
        | __rand__(...)
        | x.__rand__(y) <==> y&x
        |
        | __rdiv__(...)
        | x.__rdiv__(y) <==> y/x
        |
        | __rdivmod__(... )
        | x.__rdivmod__(y ) <==> ydivmod(y, x)x
        |
        | __repr__(...)
        | x.__repr__() <==> repr(x)
        |
        | __rfloordiv__(. ..)
        | x.__rfloordiv__ (y) <==> y//x
        |
        | __rlshift__(... )
        | x.__rlshift__(y ) <==> y<<x
        |
        | __rmod__(...)
        | x.__rmod__(y) <==> y%x
        |
        | __rmul__(...)
        | x.__rmul__(y) <==> y*x
        |
        | __ror__(...)
        | x.__ror__(y) <==> y|x
        |
        | __rpow__(...)
        | y.__rpow__(x[, z]) <==> pow(x, y[, z])
        |
        | __rrshift__(... )
        | x.__rrshift__(y ) <==> y>>x
        |
        | __rshift__(...)
        | x.__rshift__(y) <==> x>>y
        |
        | __rsub__(...)
        | x.__rsub__(y) <==> y-x
        |
        | __rtruediv__(.. .)
        | x.__rtruediv__( y) <==> y/x
        |
        | __rxor__(...)
        | x.__rxor__(y) <==> y^x
        |
        | __str__(...)
        | x.__str__() <==> str(x)
        |
        | __sub__(...)
        | x.__sub__(y) <==> x-y
        |
        | __truediv__(... )
        | x.__truediv__(y ) <==> x/y
        |
        | __xor__(...)
        | x.__xor__(y) <==> x^y
        |
        | ----------------------------------------------------------------------
        | Data and other attributes defined here:
        |
        | __new__ = <built-in method __new__ of type object>
        | T.__new__(S, ...) -> a new object with type S, a subtype of T
        [color=blue][color=green][color=darkred]
        >>>[/color][/color]
        >
        > if you pass in an object to help(), help figures out what that object is,
        > and tries to tell you what you can do with that object.
        >
        > the integer itself has no idea whatsoever from where it came; it's just
        > an integer, and that's all Python knows about it.
        >
        > cf.
        >
        >[color=green][color=darkred]
        >>>>import sys
        >>>>help(sys)[/color][/color]
        >
        > Help on built-in module sys:
        > NAME
        > sys
        >
        >[color=green][color=darkred]
        >>>>help(sys.st dout)[/color][/color]
        >
        > Help on file object:
        > class file(object)
        > | file(name[, mode[, buffering]]) -> file object
        >
        >[color=green][color=darkred]
        >>>>help(sys.st dout.softspace)[/color][/color]
        >
        > Help on int object: <<<<<<
        > class int(object)
        >
        >[color=green][color=darkred]
        >>>>help(sys.st dout.softspace. __int__)[/color][/color]
        >
        > Help on method-wrapper object:
        > __int__ = class method-wrapper(object)
        >
        > and so on.
        >
        > </F>
        >
        >
        >[/color]

        Comment

        Working...