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 included. Could some show me how to declare arrays with some basic examples? Gord. -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays
OK, thanks to all. The key statement is "from array import array" which is not exactly intuitive! Gord "John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Bernard wrote: >> On 12 nov, 20:19, "Gordon C" <[EMAIL PROTECTED]> wrote: >> > 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 included. >> > 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.html#SECTION001370 > 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, 2]) >>>> 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 > -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays
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" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Limit Guessing Algorithm
One of the difficulties of this kind of a problem is that one is looking for a solution to a limited number of data points for which it may be possible to define a function. There can never be a guarantee that the chosen "fit" can be reliably extrapolated. You need to tie a possible solution to the realworld characteristics of that data. Just taking a bunch of data by itself cannot be sufficient. Gord -- http://mail.python.org/mailman/listinfo/python-list
Re: alternating string replace
This is very cool stuff but I suspect that the code is unreadable to many readers, including me. Just for fun here is a complete program, written in Turbo Pascal, circa 1982, that does the job. Readable n'est pas? Program dash; var str: string[80]; n: integer; odd: boolean; begin str:='Hi there_how are you?_'; odd::=TRUE; for n:= 1 to length(str) do begin if ((str[n]='_') and (odd=TRUE)) then begin str[n]:= ','; odd:=FALSE; end else if ((str[n]='_') and (odd=FALSE) then begin str[n]:= ':'; odd:= TRUE;end; end; {for} writeln(str); end. {dash} Regards, Gord -- http://mail.python.org/mailman/listinfo/python-list