[JPython] dir and java classes

Jim Althoff jima at aspectdv.com
Tue Oct 26 18:22:45 EDT 1999


To further compound the teaching problem, dir()
is inconsistent between Python and JPython.
So when trying to teach someone JPython,
I always advise them to install Python just
so that they can use the "more fully loaded"
dir() of Python to help in their learning process.
Not pretty.

Jim



At 02:28 PM 10/26/99 -0700, David Ascher wrote:
>>>>>> "BAW" == Barry A Warsaw <bwarsaw at cnri.reston.va.us> writes:
>
>BAW> Okay, so what can you do to get the information you want?
>BAW> Well, it isn't really that difficult to write your own dir()
>BAW> function that, given an instance traversed into the instance's
>BAW> class to find method and attribute names.  For completeness you
>BAW> probably want to cruise the entire class hierarchy (but maybe
>BAW> not).
>
>BAW> So the issue is, why doesn't dir() do this by default?  
>
>I think that it's a very real question.  The purpose of dir() is fairly
>ill-defined.  It makes sense for modules and builtin objects in CPython,
>but it's quite inconsistent as soon as classes and instances are brought
>in.  It's currenty quite hard to explain to novices, mostly because
>
> 1) they need it the most, especially when learning about the language
>    in interactive mode, and
>
> 2) understanding what dir() does currently requires a fairly deep
>    understanding of the various kinds of objects, certainly deeper than
>    should be required (IMHO).
>
>If it were up to me, dir() would return all the things that I can do a
>getattr with, with the exclusion of all the names which start with an
>underscore.  That's a rule which I can explain in two minutes and
>leverages on the other distinction between 'first class' and 'not first
>class' attributes in Python (see 'from ... import *', pseudo-private
>variables, reserved method names, etc.).
>
>Making a new version of dir() for my own purposes does not work when I'm
>teaching "Python", not "David's Python".
>
>--david
>
>
>
>
>-- 
>http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list