[Python-bugs-list] [ python-Feature Requests-686323 ] Minor array module enhancements

SourceForge.net noreply@sourceforge.net
Thu, 13 Feb 2003 20:34:29 -0800


Feature Requests item #686323, was opened at 2003-02-13 20:13
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=686323&group_id=5470

>Category: None
>Group: None
Status: Open
Resolution: None
>Priority: 4
Submitted By: paul rubin (phr)
Assigned to: Nobody/Anonymous (nobody)
Summary: Minor array module enhancements

Initial Comment:
1) I notice that array('B', (2,3,4)) throws an error
saying the
2nd arg must be a list or string.  That is, array('B',
[2,3,4]) is
legal but using the tuple (2,3,4) is not.  The
limitation doesn't
seem harmful, but I also don't see any good reason for
it.  May
as well remove it.

2) Of more usefulness (and maybe of more controversy), I
think the byte array methods should accept string
arguments,
for example
   a = array('B', 'abc')
   a.append('def')
should do the obvious thing.  That gives a natural way to
build up a string in pieces instead of making a list of
strings
and doing the counterintuitive ''.join(x) maneuver. 
Appending
to byte arrays is the usual way to build up a string in
Java,
if that matters.  So I favor this change too.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-02-13 23:34

Message:
Logged In: YES 
user_id=80475

The first request is reasonable.

The second is not the natural meaning of append().  In 
python, multiple appends are handled with extend().  The 
array module already provides extend.  So, for the 
example given above, the code is:

>>> a = array('B', 'abc')
>>> a.extend(array('B', 'def'))
>>> a
array('B', [97, 98, 99, 100, 101, 102])

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=686323&group_id=5470