[Numpy-discussion] Dcoument strings for ndarray

Colin J. Williams cjw at sympatico.ca
Mon Oct 10 04:53:30 EDT 2005


Travis Oliphant wrote:

>
>>> I'm not sure what you are talking about here?  Where are you getting 
>>> this?
>>>
>>>
>>> I don't know of any such attribute.  There is a __class__ 
>>> attribute.  But I don't see a
>>>
>>> __class__ module(name[, doc])   attribute
>>>
>>> -Travis
>>>
>>
>> Please see the sequence below:
>>
>>     >>> import scipy.base.multiarray as M
>>     >>> M.__class__
>>    <type 'module'>
>>     >>>
>>
>> I am surprised that this name points to a module.  It usually is an 
>> attribute of a class instance which
>> points to the class object of that instance.
>
>
> Why is this surprising?   scipy.base.multiarray is a module, therefore 
> it's "class" is type 'module'.  This seems fine to me.   At any rate, 
> Python is assigning the __class__ attribute to the extension module 
> multiarray, so it is what it is.
>
> -Travis
>
Yes, this is the Python practice:
 >>> import timeit
 >>> timeit.__class__
<type 'module'>
 >>> import anydbm
 >>> anydbm.__class__
<type 'module'>
 >>>

Yes, timeit.__class__ points to the internal module creator function:
 >>> import new
 >>> new.module
<type 'module'>
 >>> new.module.__doc__
'module(name[, doc])\n\nCreate a module object.\nThe name must be a 
string; the optional doc argumen
t can have any type.'
 >>> new.module is timeit.__class__
True
 >>>

With a little digging, this is logical, consistent and no longer surprising.

Colin W.




More information about the NumPy-Discussion mailing list