I am a python newbie so may be missing something obvious; but debugging using the Pydev 1.6 watch facility, it appears neither globals nor locals return a __length__ attribute under jython 2.5. 

On Wed, Aug 4, 2010 at 3:02 PM, Jim Baker <jbaker@zyasoft.com> wrote:
Not to mention that you can just use the simpler form, since you are attempting to use the defaults:

module = __import__(module_path)

You can also verify that the functions globals and locals both return dictionaries (with type dict as of 2.5.2); they will have the __len__ method defined on them.

- Jim

On Wed, Aug 4, 2010 at 12:33 PM, Philip Jenvey <pjenvey@underboss.org> wrote:

On Aug 3, 2010, at 7:32 PM, Owen Newnan wrote:

> A program that succeeds on cpython 2.6 fails for jython 2.5.1 with the diagnostic
>    AttributeError: __len__
> where the offending line is:
>    module = __import__(module_path, globals(), locals(), True)
> The Pydev debugger reveals that neither globals() or locals() have a a value with a __len__ attribute.  Is this correct behavior and is there a workaround for this, e.g., by providing runtime flag or option?

You're really calling __import__ incorrectly. Though this works in CPython, CPython is being too lax with the arguments. The 4th arg should be an actual list as stated in the __import__ docs.

We've came across this before with __import__, on CPython it even accepts odd things like empty strings for the globals/locals dicts. Don't rely on this, CPython is likely to become more strict in the future.

Philip Jenvey

The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
Jython-users mailing list


Owen Newnan

cell 720 260-5753