Windows, IDLE, __doc_, other

Alf P. Steinbach alfps at start.no
Mon Dec 21 02:53:21 EST 2009


* W. eWatson:
> When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words 
> without reasonable line breaks.
> 
> "\nNumPy\n=====\n\nProvides\n  1. An array object of arbitrary 
> homogeneous items\n  2. Fast mathematical operations over arrays\n  3. 
> Linear Algebra, Fourier Transforms, Random Number
> ...
> 
> Is there a way to get this formated properly.

print( numpy.__doc__ )

(For Python 2.x you can and best should leave out the parenthesis)


> If I use dir(numpy), I get yet a very long list that starts as:
> ['ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DataSource', 'ERR_CALL', 
> 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 
> 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 
> 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'False_', 'Inf', 
> 'Infinity', 'MAXDIMS', 'MachAr', 'NAN', 'NINF', 'NZERO', 'NaN', 'PINF', 
> 'PZERO', 'PackageLoader', 'RAISE', 'RankWarning', 'SHIFT_DIVIDEBYZERO', 
> 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'ScalarType', 
> 'Tester', 'True_', 'UFUNC_BUFSIZE_DEFAULT'
> ...
> I see this might be a dictionary. What can I do to make it more readable 
> or useful, or is that it? Is there a more abc as in Linux?

Something like (off the cuff, fix if eroRs!)

   for name in dir[numpy]:
       if name.startswith( "_" ):
           pass
       else:
           doc_lines = getattr( numpy, name ).__doc__.split()
           print( format( "{0:25} {1}".format( name, doc_lines[0] ) )

Should ideally work whether you use Python 2.x or 3.x.

But as mentioned I just typed that in so there may be eroRs.


> It the IDLE shell, it's not possible to retrieve lines entered earlier 
> without copying them. Is there an edit facility?

I suggest you download a programmers' editor (like Notepad++ or PsPad) for 
programming work and use the basic Python interpreter for interactive work. The 
basic interpreter lives in a standard Window console window where you can use up 
and down arrow keys, F8 completion, F7 for list of earlier commands, etc (as 
documented by the doskey command in the Windows command interpreter). Just 
forget IDLE in windows: while Windows console windows are something from the 
middle ages, IDLE seems to stem from a period before that! <g>


Cheers & hth.,

- Alf

PS: Shameless plug: take a look at <url: http://tinyurl.com/programmingbookP3>, 
it's for Windows.



More information about the Python-list mailing list