473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Arrays

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
11 1846
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

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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.