Search this site


Metadata

Articles

Projects

Presentations

Python is getting on my nerves

Add lacking dynamic assignment ability to my "I wish Python had Foo" list.

Python does not appear to have dynamically assignable arrays. Where are we, C? Assembly? When I assign past the end of the array, I mean resize the god damned array. Thanks.

nightfall(~) % python -c "foo = []; foo[3] = 234"
Traceback (most recent call last):
  File "<string>", line 1, in ?
  IndexError: list assignment index out of range
This is completely unacceptable. Sure, I can use list comprehensions to make an N element array that's empty:
foo = [None for x in range(100)]
foo[44] = "Hi"
That only gets me an array with 100 empty elements. Uh.. Not what I want. If I did this on an array with data in it I didn't want to lose, I'd lose all the data.

Sigh...


2 responses to 'Python is getting on my nerves'

Showing last 2 comments... (Click here to view all comments)

To Err isHuman wrote at Fri Mar 21 17:09:31 2008...
When I assign past the end of an array, I'm usually making a mistake and I appreciate it when the language catches it.

I spent many unhappy hours assigning past the ends of arrays in C, and not getting any errors.

Jordan Sissel wrote at Fri Mar 21 18:41:31 2008...
Yes, but in C you can also declare the size of the array when you create it, and you can grow it later. There's no list.resize() in python, but perhaps using lists in this way is "unpythony" for lack of a better (overused) term ;)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: