FEEDBACK WANTED: Type/class unification

Paul Prescod paulp at ActiveState.com
Sun Jul 29 15:37:04 EDT 2001


Guido van Rossum wrote:
> 
> ...
> 
> Yes, it's a lot less useful than you seem to think.  If you are
> interested in documentation, it's better to use something like pydoc
> which gives much more details.

Major: Pydoc seems only useful for a small subset of types and classes. 

Major: I use dir() in object browsers and other graphical constructs. I
can't use pydoc for that. I don't see an obvious dir-like function in
inspect.py.

Minor: It returns so much prose information that I might prefer to use
dir() to just get the spelling or name of a function.

Consider this traceback and you'll see why I still depend on dir()

>>> a=urllib.urlopen("file:///c|/autoexec.bat")
>>> type(a)
<type 'instance'>
>>> dir(a)
['fileno', 'fp', 'headers', 'read', 'readline', 'readlines', 'url']
>>> help(a)
Help on instance of addinfourl:

<addinfourl at 16411468 whose fp = <open file 'C:\autoexec.bat', mode
'rb' at 00
F7EB28>>

>>> m = re.match("abc","abcdef")
>>> type(m)
<type 'SRE_Match'>
>>> dir(m)
['end', 'expand', 'group', 'groupdict', 'groups', 'span', 'start']
>>> help(m)
Help on SRE_Match:

<SRE_Match object>

> Right now, pydoc doesn't understand the new types yet, but eventually,
> before 2.2 final, pydoc (or more likely inspect.py) will be able to
> introspect according to PEP 252.

Maybe that will be enough to help me for my object-browsing
applications. And perhaps pydoc will be reliable enough for me to give
up on dir(x).

> 
> ....
> Hm, I'd like you to tell me more about how you use dir().  I find
> getting the entire list of attributes overwhelming.

I use dir(x) as a compressed and somewhat more reliable pydoc that works
great for modules and built-in types and works poorly for instances.

What do *you* use dir(x) for? When do you want to introspect an instance
and you care about instance data but not class data and functions that
are instance attributes but not true methods.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list