By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

Arrays

P: n/a
Absolute newbie here. In spite of the Python Software Foundation tutorial's
( http://www.python.org/doc/current/tut/tut.html ) use of the array
declaration
array(type[,initializer]), the Python interpreter does NOT accept the word
array! It , presumably, needs to have an import <somethingincluded. Could
some show me how to declare arrays with some basic examples?
Gord.

Nov 13 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 12 nov, 20:19, "Gordon C" <gc...@vif.comwrote:
Absolute newbie here. In spite of the Python Software Foundation tutorial's
(http://www.python.org/doc/current/tut/tut.html) use of the array
declaration
array(type[,initializer]), the Python interpreter does NOT accept the word
array! It , presumably, needs to have an import <somethingincluded. Could
some show me how to declare arrays with some basic examples?
Gord.
hey Gordon,

here's a good reading for you: http://effbot.org/zone/python-list.htm

Nov 13 '07 #2

P: n/a

Bernard wrote:
On 12 nov, 20:19, "Gordon C" <gc...@vif.comwrote:
Absolute newbie here. In spite of the Python Software Foundation tutorial's
(http://www.python.org/doc/current/tut/tut.html) use of the array
declaration
array(type[,initializer]), the Python interpreter does NOT accept the word
array! It , presumably, needs to have an import <somethingincluded. Could
some show me how to declare arrays with some basic examples?
Gord.

hey Gordon,

here's a good reading for you: http://effbot.org/zone/python-list.htm
Hey Bernard, read Gordon's message carefully; he's asking about
arrays, not lists.

Hey Gordon, You seem a little lost; here's the tutorial reference:
http://docs.python.org/tut/node13.ht...00000000000000
which produces:
"""
The array module provides an array() object that is like a list that
stores only homogenous data and stores it more compactly. The
following example shows an array of numbers stored as two byte
unsigned binary numbers (typecode "H") rather than the usual 16 bytes
per entry for regular lists of python int objects:

>>from array import array
a = array('H', [4000, 10, 700, 22222])
sum(a)
26932
>>a[1:3]
array('H', [10, 700])
"""

The 2nd word (array) is a link (http://docs.python.org/lib/module-
array.html) to the docs for the array module.

Cheers,
John

Nov 13 '07 #3

P: n/a
On Nov 13, 2007 6:58 AM, John Machin <sj******@lexicon.netwrote:
Hey Bernard, read Gordon's message carefully; he's asking about
arrays, not lists.
Chances are a list is exactly what the OP wants.

--
Cheers,
Simon B.
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
Nov 13 '07 #4

P: n/a
On Nov 13, 8:36 pm, "Simon Brunning" <si...@brunningonline.netwrote:
On Nov 13, 2007 6:58 AM, John Machin <sjmac...@lexicon.netwrote:
Hey Bernard, read Gordon's message carefully; he's asking about
arrays, not lists.

Chances are a list is exactly what the OP wants.
Chances are a list is what he *needs*. However he explicitly referred
to the array module array, not some generic array concept. Serial
processing of the tutorial should have clued him in on Python lists
way before he arrived at the mention of the array module.

Nov 13 '07 #5

P: n/a
OK, thanks to all. The key statement is "from array import array" which is
not exactly intuitive!
Gord

"John Machin" <sj******@lexicon.netwrote in message
news:11*********************@k35g2000prh.googlegro ups.com...
>
Bernard wrote:
>On 12 nov, 20:19, "Gordon C" <gc...@vif.comwrote:
Absolute newbie here. In spite of the Python Software Foundation
tutorial's
(http://www.python.org/doc/current/tut/tut.html) use of the array
declaration
array(type[,initializer]), the Python interpreter does NOT accept the
word
array! It , presumably, needs to have an import <somethingincluded.
Could
some show me how to declare arrays with some basic examples?
Gord.

hey Gordon,

here's a good reading for you: http://effbot.org/zone/python-list.htm

Hey Bernard, read Gordon's message carefully; he's asking about
arrays, not lists.

Hey Gordon, You seem a little lost; here's the tutorial reference:
http://docs.python.org/tut/node13.ht...00000000000000
which produces:
"""
The array module provides an array() object that is like a list that
stores only homogenous data and stores it more compactly. The
following example shows an array of numbers stored as two byte
unsigned binary numbers (typecode "H") rather than the usual 16 bytes
per entry for regular lists of python int objects:

>>from array import array
>>a = array('H', [4000, 10, 700, 22222])
>>sum(a)
26932
>>a[1:3]
array('H', [10, 700])
"""

The 2nd word (array) is a link (http://docs.python.org/lib/module-
array.html) to the docs for the array module.

Cheers,
John

Nov 13 '07 #6

P: n/a
On Nov 13, 2007 10:26 AM, Gordon C <gc***@vif.comwrote:
OK, thanks to all. The key statement is "from array import array" which is
not exactly intuitive!
Gord
It becomes intuitive when you learn Python, which is what you're
reading the tutorial for, and it's why the tutorial shows you exactly
what to type. If you're progressing through the tutorial step by step
instead of jumping ahead, you should already have been introduced to
the import statement.
Nov 13 '07 #7

P: n/a
On Tue, 13 Nov 2007 11:26:28 -0500, Gordon C wrote:
OK, thanks to all. The key statement is "from array import array" which
is not exactly intuitive!

"The only intuitive interface is the nipple. After that, it's all
learned." -- Bruce Ediger on user interfaces.

Once you've been using Python for a while, using import becomes as
intuitive as a spoon. The only tricky part is knowing *which* module to
import. But, honestly, are you surprised to learn that the array type is
held in in the array module?

--
Steven.
Nov 13 '07 #8

P: n/a
Steven D'Aprano wrote:
"The only intuitive interface is the nipple. After that, it's all
learned." -- Bruce Ediger on user interfaces.
And after we learn its other "uses", not even the nipple is so easy... Who
haven't heard (or said, if you're a woman) "Don't bite it like that, it
hurts!"? :-)

Anyway, back to nippling, I mean, programming... :-)
Nov 14 '07 #9

P: n/a
OK Steve, But why do we say "from array import array" and NOT "from math
import math"? Why the difference in syntax?
Gord

"Steven D'Aprano" <st***@REMOVE-THIS-cybersource.com.auwrote in message
news:13************@corp.supernews.com...
On Tue, 13 Nov 2007 11:26:28 -0500, Gordon C wrote:
>OK, thanks to all. The key statement is "from array import array" which
is not exactly intuitive!


"The only intuitive interface is the nipple. After that, it's all
learned." -- Bruce Ediger on user interfaces.

Once you've been using Python for a while, using import becomes as
intuitive as a spoon. The only tricky part is knowing *which* module to
import. But, honestly, are you surprised to learn that the array type is
held in in the array module?

--
Steven.

Nov 14 '07 #10

P: n/a
On Tue, 13 Nov 2007 20:25:07 -0500, Gordon C wrote:
OK Steve, But why do we say "from array import array" and NOT "from
math import math"? Why the difference in syntax?
It isn't different syntax. The difference is that there is a function
"array" (technically, a type rather than a function) in the module
"array", but there is no function "math" in the array "math". There is
however a function sin, so you can do this:

from math import sin
Precisely the same syntax: "from <module-nameimport <object-name>".
Only the names are different.

--
Steven.
Nov 14 '07 #11

P: n/a
On Tue, 13 Nov 2007 22:31:57 -0200, Jorge Godoy wrote:
Steven D'Aprano wrote:
>"The only intuitive interface is the nipple. After that, it's all
learned." -- Bruce Ediger on user interfaces.

And after we learn its other "uses", not even the nipple is so easy...
Who haven't heard (or said, if you're a woman) "Don't bite it like that,
it hurts!"? :-)
Or even "Please Sir, bite it like that! Thank you Sir!"
*ducks and hides*

--
Steven
Nov 14 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.