Okay, on further research, a character in Python is a String of one item.  So it is a one 'character' String, not one or more characters.

Still, should:

import array

a = array.array("c", "abc123')

print a


    array('c', 'abc123')      like in Python 2.5.2


    array('c', ['a', 'b', 'c', '1', '2', '3'])    like in Jython 2.5a1?

Also, when I use an 'L' type code I get the same value error message as when I used the 'B' type code.

And, when using 'H', Jython just changes it into 'i' and when using 'I' (upper case eye), Jython changes it to 'l' (lower case el).

 - Bob

-----Original Message-----
From: boblusebob@aim.com
To: jython-dev@lists.sourceforge.net
Sent: Sat, 19 Jul 2008 3:29 am
Subject: [Jython-dev] Possible Bugs in Jython 2.5a1 array


I have found what I think are two bugs in the Jython 2.5 Alpha code for arrays.  The reason that I am writing here rather than making a bug report is that I am not positive they are bugs since arrays in Jython are a bit complicated (to me anyway).

The first question:

The following runnable short code snippet runs on both Jython and Python (I am running on Windows XP Pro) but gives slightly different results.

import array

a = array.array("c", 'abc123')
print a
print a.tostring()

print repr(a.tostring())

for i in a:
    print i,


In Python 2.5.2 it prints the following:

    array('c', 'abc123')  # this is where they are different

    a b c 1 2 3

In Jython 2.5a1 it prints:

    array('c',['a', 'b', 'c', '1', '2', '3'])  # this is where they are different

    a b c 1 2 3

Intuitively, the Jython result seems right, an array of char.  But, my understanding of char in Python says that the Jython is wrong.  I think a Python char is 1 or more characters, in other words a string.  the Jython char array is actually several char arrays rather than one char array.

The other problem is unsigned char  -  using a 'B' as the type code.  I receive the following error message in Jython when declaring an array with the 'B' type code ( 'b' - signed char - works ok):

 Traceback (most recent call last):
  File "C:\...\src\charArraysUnsigned.py", line 6, in <module>
    a = array.array("B", 'abc123')
ValueError: typecode must be in [zcbhilfd]

The following very short code snippet should recreate the error in Jython:

import array

a = array.array("B", 'abc123')


I'll open bug reports if someone will confirm that these are bugs and not something that needed to be done to get Java and Python working together.


This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
Jython-dev mailing list