Python equivalent of Java Vector

hoopy_frood at my-deja.com hoopy_frood at my-deja.com
Mon Oct 2 17:19:50 EDT 2000


I've been asked another Python question that's over my head, so I asked
the querant to re-phrase it a bit so I could ask y'all.  Here is his
question:

"Does Python have something equivalent to Java's Vector?  For instance,
most of the time if you want to use an array you have to declare the
size up front.  Java has a Vector class which is an array of objects
which grows as you add things to it.

"Just curiousity on my part really, but if you are serious about using
Python productively, you probably need to answer that.  In Java, for
instance, if I want an array of String I say "String tmp[]=new
String[5]" and I have an array of Strings with 5 slots.  If I didn't
know how many Strings I was going to have though, I could say "Vector
tmp=new Vector()" then every time I wanted to add a String, say "String
tmpvalue" I could say "tmp.addElement(tmpvalue)".  Then, I could say
"tmp.size()" to see how many elements were in the Vector, and I can even
to a "tmp.elementAt(int x)" to retrieve a value.  So, I think the
terminology would be that Java supports dynamic arrays of objects.  I
was wondering if Python had the equivalent."

Appreciatively,
Rob Andrews


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list