From manub@plasma.ernet.in Mon Nov 1 14:18:00 1999 From: manub@plasma.ernet.in (Manu Bajpai) Date: Mon, 1 Nov 1999 09:18:00 -0500 (GMT) Subject: [Tutor] mailing list Message-ID: Dear Sir, I'll be out of station for 16/17 days from 5 Nov. and won't be able to check my emails during the said period. Please stop temporarily sending tutor pages till 22 Nov. Manu From vcardona@worldnet.att.net Mon Nov 1 06:34:25 1999 From: vcardona@worldnet.att.net (Victor R. Cardona) Date: Mon, 1 Nov 1999 01:34:25 -0500 Subject: [Tutor] test --Don't read-- Message-ID: <99110101345500.04962@utopia> Test From vcardona@worldnet.att.net Mon Nov 1 07:13:42 1999 From: vcardona@worldnet.att.net (Victor R. Cardona) Date: Mon, 1 Nov 1999 02:13:42 -0500 Subject: [Tutor] test Message-ID: <99110102013304.04962@utopia> test From vcardona@worldnet.att.net Mon Nov 1 07:35:14 1999 From: vcardona@worldnet.att.net (Victor R. Cardona) Date: Mon, 1 Nov 1999 02:35:14 -0500 Subject: [Tutor] test Message-ID: <99110102013304.04962@utopia> test From vcardona@worldnet.att.net Mon Nov 1 14:32:56 1999 From: vcardona@worldnet.att.net (Victor R. Cardona) Date: Mon, 1 Nov 1999 09:32:56 -0500 Subject: [Tutor] sorry Message-ID: <99110109343100.05935@utopia> I apologize for the test messages. I was merely testing my procmail configuration when I ran into a problem. Victor From alan.gauld@bt.com Mon Nov 1 10:19:21 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 1 Nov 1999 10:19:21 -0000 Subject: [Tutor] Is python just a scripting language? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EBA@mbtlipnt02.btlabs.bt.co.uk> > I´m looking at sources of programs in python and I noticed > that there are just scripts written in python. Can't I > compile in an executable file? You should find more than just scripts. There should be compiled scripts too - files ending in .pyc These load slightly faster than scripts and can be distributed if, for some reason, you want to protect your source code from scrutiny. The freeze tool for producing executables is somewhat limited and produces rather big files since, as far as I can tell, it basically bundles up the interpreter and all required units into a big binary! (I think its only for Windows too) Alan G. From alan.gauld@bt.com Mon Nov 1 17:31:02 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 1 Nov 1999 17:31:02 -0000 Subject: [Tutor] Is python just a scripting language? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EBD@mbtlipnt02.btlabs.bt.co.uk> > > There should be compiled scripts too - files ending in .pyc > > Just FYI, they're not designed to protect the user from > reading them, and are easily 'uncompiled'. Agreed, but they might be better than issuing the scripts as is if, say, a corporate standard prohibited issuing source code onto liive machines > > into a big binary! (I think its only for Windows too) > > Freeze also works on Unix. Oh, OK. I've not looked closely as I have no need at present, but its nice to know Alan g. From deirdre@deirdre.net Tue Nov 2 00:04:11 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 1 Nov 1999 16:04:11 -0800 (PST) Subject: [Tutor] Is python just a scripting language? In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EBD@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Mon, 1 Nov 1999 alan.gauld@bt.com wrote: > > > There should be compiled scripts too - files ending in .pyc > > > > Just FYI, they're not designed to protect the user from > > reading them, and are easily 'uncompiled'. > > Agreed, but they might be better than issuing the scripts > as is if, say, a corporate standard prohibited issuing > source code onto liive machines I could have misunderstood something, but I thought the .pyc files were hardware platform (and perhaps OS) specific? I don't think this is such a great thing to limit. -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net "Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator "That's because the Martians keep shooting things down." -- Harlan Rosenthal , retorting in Risks Digest 20.60 From da@ski.org Tue Nov 2 00:16:18 1999 From: da@ski.org (David Ascher) Date: Mon, 1 Nov 1999 16:16:18 -0800 (Pacific Standard Time) Subject: [Tutor] Is python just a scripting language? In-Reply-To: Message-ID: > I could have misunderstood something, but I thought the .pyc files were > hardware platform (and perhaps OS) specific? Nope. .pyc files are portable. After all, they're just python virtual machine bytecodes... --david From deirdre@deirdre.net Tue Nov 2 00:10:58 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 1 Nov 1999 16:10:58 -0800 (PST) Subject: [Tutor] Is python just a scripting language? In-Reply-To: Message-ID: On Mon, 1 Nov 1999, David Ascher wrote: > > I could have misunderstood something, but I thought the .pyc files were > > hardware platform (and perhaps OS) specific? > > Nope. .pyc files are portable. After all, they're just python virtual > machine bytecodes... That makes sense, but for some reason I thought differently. I guess endianness isn't an issue either (one I personally face all the time ). -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net "Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator "That's because the Martians keep shooting things down." -- Harlan Rosenthal , retorting in Risks Digest 20.60 From Moshe Zadka Tue Nov 2 06:04:08 1999 From: Moshe Zadka (Moshe Zadka) Date: Tue, 2 Nov 1999 08:04:08 +0200 (IST) Subject: [Tutor] Is python just a scripting language? In-Reply-To: Message-ID: On Mon, 1 Nov 1999, Deirdre Saoirse wrote: > I could have misunderstood something, but I thought the .pyc files were > hardware platform (and perhaps OS) specific? I don't think this is such a > great thing to limit. They're not -- they're merely marhalled code objects. They're specific to a Python version, but that's not so horrible. (Actually, 90% of my code won't work on Python 1.5.1, so for me, it's not even a musquito bite) -- Moshe Zadka . INTERNET: Learn what you know. Share what you don't. From Gerrit Holl Tue Nov 2 08:48:41 1999 From: Gerrit Holl (Gerrit Holl) Date: Tue, 2 Nov 1999 09:48:41 +0100 Subject: [Tutor] Is python just a scripting language? In-Reply-To: References: Message-ID: <19991102094841.A3548@optiplex.palga.uucp> Moshe Zadka wrote: > On Mon, 1 Nov 1999, Deirdre Saoirse wrote: > > > I could have misunderstood something, but I thought the .pyc files were > > hardware platform (and perhaps OS) specific? I don't think this is such a > > great thing to limit. > > They're not -- they're merely marhalled code objects. They're specific to a > Python version, but that's not so horrible. Agreed, > (Actually, 90% of my code won't work on Python 1.5.1, so for me, > it's not even a musquito bite) Well, as long as you don't use functions from the latest CVS tree :-) regards, Gerrit. -- linuxgames.nl.linux.org All about games on Linux in Dutch (under construction). www.nl.linux.org The Dutch resource for Dutch Linux documentation. www.nl.linux.org/discoverb Learn foreign words and definitions. www.nl.linux.org/~gerrit/asperger I'm an Asperger, go here for more info. www.nl.linux.org/~gerrit About me and pictures of me. From sessile@in-gen.net Wed Nov 3 22:24:36 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Wed, 03 Nov 1999 17:24:36 -0500 Subject: [Tutor] Reading arrays through an extension module Message-ID: <3.0.6.32.19991103172436.007b73b0@mail.in-gen.net> The code in question is attached at the bottom. The first function (get_float_arr), after some hacking, seems to be working properly. I take each element of the 1-D array and append them into a PyList. I'm not certain this is a good approach but it gets me the numbers I want. The second function, however, is incomplete. I have not been able to figure out how to build the 2-D array of floats into a python object (list?). Could someone show me an efficent way to do this? What if the array had arbitrarily larger dimensions? Also, should I be using Py_DECREF in these functions? Thank you. Dean. ==================== /* * Format of function (from documentation): * xxx_get_float_arr( int ARG, * float **tmp_float_arr, * int *len ); * * This function takes a single argument (ARG) and returns a one * dimensional array of floats along with an int (len) which holds * the length of the array. */ static PyObject * my_xxx_get_float_arr(self, args) PyObject *self; PyObject *args; { int *ARG; int ii; int len; float *tmp_float_arr_c; PyObject *tmp_float_arr_py; if (!PyArg_ParseTuple(args, "i:get_float_arr", &ARG)) return NULL; xxx_get_float_arr(ARG, &tmp_float_arr_c, &len) tmp_float_arr_py = PyList_New(0); for (ii=0; ii This is a multi-part message in MIME format. ------=_NextPart_000_0013_01BF2636.82371280 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I thought, just like most languages, that python could create = executables able to run on other machines without python. The .pyc or = .pyo files are just binary code for the interpreter and not a compiled = file ------=_NextPart_000_0013_01BF2636.82371280 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I thought, just like most languages, = that python=20 could create executables able to run on other machines without python. = The .pyc=20 or .pyo files are just binary code for the interpreter and not a = compiled=20 file
------=_NextPart_000_0013_01BF2636.82371280-- From arcege@shore.net Thu Nov 4 13:16:31 1999 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 4 Nov 1999 08:16:31 -0500 (EST) Subject: [Tutor] Reading arrays through an extension module In-Reply-To: <3.0.6.32.19991103172436.007b73b0@mail.in-gen.net> from "sessile@in-gen.net" at "Nov 3, 99 05:24:36 pm" Message-ID: <199911041316.IAA06279@northshore.shore.net> > The code in question is attached at the bottom. The first > function (get_float_arr), after some hacking, seems to be > working properly. I take each element of the 1-D array and > append them into a PyList. I'm not certain this is a good > approach but it gets me the numbers I want. Since you know the dimension(s), it's better to create lists with that size and populate, rather than creating an empty list and appending. See below. > The second function, however, is incomplete. I have not > been able to figure out how to build the 2-D array of floats > into a python object (list?). Could someone show me an > efficent way to do this? What if the array had arbitrarily > larger dimensions? (You don't say which dimension is which, so I'll make an assumption that they are (row, col). But it doesn't really matter; just switch as needed.) Like the first function, we know the dimensions, so the task is that much easier. It would end up as something similar to the Python code: l = [None] * index1 for x in range(index1): l[x] = t = [None] * index2 for y in range(index2): t[y] = tmparray[(index2*x)+y] See below. > Also, should I be using Py_DECREF in these functions? The Py_BuildValue("N"...) does not increment the reference count, so you do not want to decrement it. BUT, since the length of the array is given as the length of the list, you could just return the list instead of a tuple containing the length and the list. You should be more conserned about the memory allocation of the C arrays being returned. The error detection is incomplete, but I've inserted enough to get by. :) Hope this helps, -Arcege > ==================== > > /* > * Format of function (from documentation): > * xxx_get_float_arr( int ARG, > * float **tmp_float_arr, > * int *len ); > * > * This function takes a single argument (ARG) and returns a one > * dimensional array of floats along with an int (len) which holds > * the length of the array. > */ > static PyObject * > my_xxx_get_float_arr(self, args) > PyObject *self; > PyObject *args; > { > int *ARG; > int ii; > int len; > float *tmp_float_arr_c; > PyObject *tmp_float_arr_py; > > if (!PyArg_ParseTuple(args, "i:get_float_arr", &ARG)) > return NULL; > > xxx_get_float_arr(ARG, &tmp_float_arr_c, &len) > > tmp_float_arr_py = PyList_New(0); > for (ii=0; ii { > PyList_Append(tmp_float_arr_py, Py_BuildValue("f", > tmp_float_arr_c[ii])); > } > /* Py_DECREF(tmp_float_arr_py); */ > return Py_BuildValue("iN", len, tmp_float_arr_py); Instead have: tmp_float_arr_py = PyList_New(len); if (tmp_float_arr_py != NULL) for (ii=0; ii } > > /* > * Format of function (from documentation): > * xxx_get_float2_arr( int ARG, > * float ***tmp_float_arr, > * int *index1, int *index2 ); > * > * This funtion takes a single argument (ARG) and returns a two > * dimensional array of floats along with two ints holding the > * dimensions of the array. > */ > static PyObject * > my_xxx_get_float2_arr(self, args) > PyObject *self; > PyObject *args; > { > int *ARG; > int index1, index2; > float *tmp_float2_arr_c; > PyObject *tmp_float2_arr_py; int x, y; PyObject *tmplist; > > if (!PyArg_ParseTuple(args, "i:get_float2_arr", &ARG)) > return NULL; > > xxx_get_float2_arr(ARG, &tmp_float2_arr_c, &index1, &index2) if ((tmp_float2_arr_py = PyList_New(index1)) != NULL) { for (x=0; x return Py_BuildValue("ii", index1, index2); /* incomplete */ > } -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From sessile@in-gen.net Fri Nov 5 03:07:28 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Thu, 04 Nov 1999 22:07:28 -0500 Subject: [Tutor] Reading arrays through an extension module In-Reply-To: <199911041316.IAA06279@northshore.shore.net> References: <3.0.6.32.19991103172436.007b73b0@mail.in-gen.net> Message-ID: <3.0.6.32.19991104220728.007a8100@mail.in-gen.net> At 08:16 AM 11/4/1999 -0500, Michael P. Reilly wrote: > > if ((tmp_float2_arr_py = PyList_New(index1)) != NULL) > { for (x=0; x { if ((tmplist = PyList_New(index2)) != NULL) > { PyList_SetItem(tmp_float2_arr_py, x, tmplist); > for (y=0; y PyList_SetItem(tmplist, y, > PyFloat_AsDouble(tmp_float2_arr_c[(index2*x)+y]) > ); > } > else > { Py_DECREF(tmp_float2_arr_py); > return NULL; /* raise NoMemoryError */ > } > } > } > else > return NULL; /* else raise NoMemoryError */ > Thanks for the idea! I played around with it for a while and ended up getting the following version to work: if ((tmp_float2_arr_py = PyList_New(index1)) != NULL) { for (x=0; x > I thought, just like most languages, that python could create > executables able to run on other machines without python. I think you'll find that *most* languages do not in fact do this. The vast majority of programming languages are interpreted. Some later aquire compilers. It is the minority that are designed from the beginning to be compiled. [Note that the vast majority of programming languages are also relatively obscure - CLU, Haskell, B, DSL, etc] Many modern languages, including Python, use a hybrid approach of compiling to some kind of byte code. Some other popular 'hybrid' languages include: Perl, Java, Lisp, Smalltalk, Visual Basic, Prolog, Logo. Pure interpreted languages include: awk, Bourne/Korn shell, Tcl, snobol... Several of these have native code compilers available now too. Requiring the platform to be on the target machine is not a big issue if enough programs use it. Consider the success of VB on Windows. It requires a 1Mb DLL on the target PC, but lots of VB apps can share it and so nobody complains. The individual VB apps are much smaller as a result. Similarly with Python, the individual apps are small so the one-off payload of the environment isn't so bad. Performance is rarely an issue. Alan g. From deirdre@deirdre.net Fri Nov 5 19:08:10 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 5 Nov 1999 11:08:10 -0800 (PST) Subject: [Tutor] Gtk+/Gnome + Glade quickstart page Message-ID: For those of you interested in Gtk+ or Gnome programming who have found the process daunting, I have a VERY quick intro (the "Ten Minute Total Idiot's Guide to Using Gnome/Gtk+ and Glade with Python"). Glade is a GUI builder that takes a HUGE amount of code work out of creating a GUI, especially if you use libglade. The guide can be found at: http://www.baypiggies.org/10mintig.html Comments welcome. I was going to add some pictures. :) -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net "Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator "That's because the Martians keep shooting things down." -- Harlan Rosenthal , retorting in Risks Digest 20.60 From sessile@in-gen.net Sun Nov 7 03:24:20 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Sat, 06 Nov 1999 22:24:20 -0500 Subject: [Tutor] Can't use len() on returned PyList object? Message-ID: <3.0.6.32.19991106222420.007b34a0@mail.in-gen.net> I've poked around in the Python/C API Reference Manual hoping to find an explanation, but all those words are making my brain hurt... perhaps due to my illiteracy in 'C', I find the API manual to be rather cryptic. Why can't I use 'len()' to find the length of a list returned from my new extension module? The error is shown as: TypeError: call of non-function (type int) The list was created by 'PyList_New()' and populated using 'PyList_SetItem()'. I get the same error message regardless of the data type held in the list. Is there a way for me to find the length of these lists in Python other than returning the length from the extension as a separate object? Python-1.5.2 SunOS-5 gcc-2.7.1 Thanks, Dean. -- E-Mail: sessile@in-gen.net "I don't want the world... I just want your half." -- TMBG (Anna Ng) From spiderman@nasachem.com Sun Nov 7 04:47:41 1999 From: spiderman@nasachem.com (R Parker) Date: Sat, 06 Nov 1999 22:47:41 -0600 Subject: [Tutor] freeze Message-ID: <3825046D.C75A0522@ghg.net> I can't find the freeze tool. Where can I get it? From Spaceram" This is a multi-part message in MIME format. ------=_NextPart_000_000B_01BF2A59.7BEDC820 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Can anyone tell me how to use the Grail browser(the one that's = programmed in python) on windows98. I download it to the desktop but = windows doesn't recognize the file and opes the "open with" box. I tried = import the file in pythonwin but all I get is a bunch of unrecognizable = characters. Any help will be appreciated. Thanks in advance. spaceram00@earthlink.net=20 ------=_NextPart_000_000B_01BF2A59.7BEDC820 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Can anyone tell me how to use the Grail = browser(the=20 one that's programmed in python) on windows98. I download it to the = desktop but=20 windows doesn't recognize the file and opes the "open with" box. I tried = import=20 the file in pythonwin but all I get is a bunch of unrecognizable=20 characters.
Any help will be = appreciated.
Thanks in advance.
spaceram00@earthlink.net=20
------=_NextPart_000_000B_01BF2A59.7BEDC820-- From Ehsan@Torabi.com Wed Nov 10 00:47:41 1999 From: Ehsan@Torabi.com (Ehsan@Torabi.com) Date: Tue, 9 Nov 1999 16:47:41 -0800 Subject: [Tutor] Update; Ad Market Public Service Message-ID: <008564147000ab9ET3@et3.Torabi.com> YOU are the Driver! Post Your Daily Advertisements to Ad Market at: http://LAMarket.net/LAMarket/AdMarket.asp Post One Ad per day per category. Free Ads are limited to 500 characters per Ad. Add your URL to E-Commerce Public Directory at: http://lamarket.net/LAMarket/UrlsAdd.asp Fully searchable by Keywords or by Category and Sub Category in E-Commerce Public Directory. Promote your business in Ad Market or E-Commerce Public Directory and Search Engine. Plus; Earn 50% on referral’s advertising revenue. The best partnership program on Internet. Please, tell your friends about this service. Also you can email your URL information for submission: Email to: Ehsan@Torabi.com Category: (for example: Internet) Sub Category: (for example: Marketing) Title: (Max 255 char. for example: Best online Marketing program) URL: (for example: http://lamarket.net/LAMarket/UrlsAdd.asp ) Description: (up to 255 characters including spaces) Key Words: (Max 20 Keywords, up to 255 characters. Dictionary words separated with Space) Your email: (Your email is required for verification of information) Thank you for your participation P.S. Enjoy the driving! This is not Spam. This is one time Announcement. I am member of many list groups and receiving thousands of emails every day. This email address was among them, and I am replying now. You welcome to review my personal Resume Profile on http://Torabi.com If you did not like to have me on your side, simply click the following link: mailto:Ehsan@Torabi.com?Subject=Remove Thank you From 7kcsl@qlink.queensu.ca Wed Nov 10 07:50:42 1999 From: 7kcsl@qlink.queensu.ca (Kevin Liang) Date: Wed, 10 Nov 1999 02:50:42 -0500 Subject: [Tutor] Major newbie question.. Message-ID: <382923D1.502C249F@qlink.queensu.ca> This might seem like a lame question, but I'm following a tutorial on a web page, and its at a point where you're supposed to create a program to count the words in a file. As you can see, I'm a little stumped..any pointers/tips would be appreciated. The thing runs, but not correctly. I thought that adding .inp= resp.readlines(): would do the trick, but I guess not. Thanks in advance Kevin import string def numwords(s): list = string.split(s) # need to qualify split() with string module return len(list) # return number of elements in list resp = raw_input("Enter a filename : ") inp = resp total = 0 # initialise to zero; also creates variable for line in resp: total = total + numwords(line) # accumulate totals for each line print "File had %d words" % total From Gerrit Holl Wed Nov 10 13:30:34 1999 From: Gerrit Holl (Gerrit Holl) Date: Wed, 10 Nov 1999 14:30:34 +0100 Subject: [Tutor] Major newbie question.. In-Reply-To: <382923D1.502C249F@qlink.queensu.ca> References: <382923D1.502C249F@qlink.queensu.ca> Message-ID: <19991110143034.A2768@optiplex.palga.uucp> Kevin Liang wrote: > This might seem like a lame question, but I'm following a tutorial on a web page, and its at a point where you're > > supposed to create a program to count the words in a file. As you can > see, I'm a little stumped..any pointers/tips would be appreciated. The > thing runs, but not correctly. I thought that adding .inp= > resp.readlines(): would do the trick, but I guess not. Thanks in > advance > > Kevin > > import string > def numwords(s): > list = string.split(s) # need to qualify split() with string module > return len(list) # return number of elements in list > resp = raw_input("Enter a filename : ") > > inp = resp > total = 0 # initialise to zero; also creates variable > > for line in resp: > total = total + numwords(line) # accumulate totals for each line > print "File had %d words" % total You can do it much easier: # untested code import string filename = raw_input("Enter filename: ") filecontents = open(filename, 'r').read() numwords = string.split(filecontents) print "File had %d words" % numwords I'm learning C and have just done it in C. Much more than 5 LOC :-) Shortest way: import string print "File has %d words" % string.split(open(raw_input("Enter filename: "), 'r').read()) Only TWO LOC! regards, Gerrit. -- linuxgames.nl.linux.org All about games on Linux in Dutch (under construction). www.nl.linux.org The Dutch resource for Dutch Linux documentation. www.nl.linux.org/discoverb Learn foreign words and definitions. www.nl.linux.org/~gerrit/asperger I'm an Asperger, go here for more info. www.nl.linux.org/~gerrit About me and pictures of me. From spiderman@nasachem.com Fri Nov 12 01:16:42 1999 From: spiderman@nasachem.com (R Parker) Date: Thu, 11 Nov 1999 19:16:42 -0600 Subject: [Tutor] Classes, Classes, Classes Message-ID: <382B6A79.452C7724@ghg.net> Hello, I am experiencing trouble understanding classes. I don't understand how they work, what they do and their purpose in general. I am a newbie so dont make it too complicated because this is the first programming language I'm learning. Thanks in advance! From alan.gauld@bt.com Fri Nov 12 10:33:37 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 12 Nov 1999 10:33:37 -0000 Subject: [Tutor] Major newbie question.. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EDA@mbtlipnt02.btlabs.bt.co.uk> > This might seem like a lame question, but I'm following a > tutorial on a web page, Looks suspiciously like mine :-) > import string > def numwords(s): > list = string.split(s) # need to qualify split() with > string module > return len(list) # return number of elements in list > resp = raw_input("Enter a filename : ") > > inp = resp But this doesn't.... you need to open the file. The actual code on the web page reads(minus comments): import string def numwords(s): list = string.split(s) return len(list) inp = open("menu.txt","r") total = 0 for line in inp.readlines(): total = total + numwords(line) print "File had %d words" % total inp.close() BTW Did you try sending me a mail via the feedback link on the web page? I don't recall seeing a message about this... Alan g. From alan.gauld@bt.com Fri Nov 12 10:38:18 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 12 Nov 1999 10:38:18 -0000 Subject: [Tutor] Major newbie question.. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EDB@mbtlipnt02.btlabs.bt.co.uk> > You can do it much easier: erm, shorter. Maybe not *easier* for a beginner to understand... The tutorial is trying to illustrate file handling and the use of functions (which are described in the preceding section). Looks like I need to do a bit more work on emphasising the open function! :-) Alan g. From alan.gauld@bt.com Fri Nov 12 10:47:02 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 12 Nov 1999 10:47:02 -0000 Subject: [Tutor] Classes, Classes, Classes Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EDD@mbtlipnt02.btlabs.bt.co.uk> > Hello, I am experiencing trouble understanding classes. Try my tutorial page on OOP at: http://members.xoom.com/alan_gauld/tutor/tutindex.htm Look in the section called "Doing it with class" near the end. Alan g. From skip@mojam.com (Skip Montanaro) Fri Nov 12 15:50:34 1999 From: skip@mojam.com (Skip Montanaro) (Skip Montanaro) Date: Fri, 12 Nov 1999 09:50:34 -0600 (CST) Subject: [Tutor] Classes, Classes, Classes In-Reply-To: <382B6A79.452C7724@ghg.net> References: <382B6A79.452C7724@ghg.net> Message-ID: <14380.14154.254055.181401@dolphin.mojam.com> RP> Hello, I am experiencing trouble understanding classes. I don't RP> understand how they work, what they do and their purpose in RP> general. Classes are used to group data together with the functions (methods) that operate on them. The usual intention is that an object holds a number of pieces of data and a functional interface (API) to those data are presented to the world. Since the data can change as requirements change (say, as new algorithms are needed to improve performance), hiding the data representation behind an API reduces the coupling between the class and the code that uses it. Perhaps the simplest example of this is the use of polar coordinates vs. cartesian coordinates to represent points in 2D or 3D space. If I develop a class like: class Point: def __init__(self): self.x = self.y = 0.0 def set_cartesian(self, x, y): self.x, self.y = x, y def set_polar (self, theta, radius): self.x, self.y = mumble(theta, radius) def get_cartesian(self): return self.x, self.y def get_polar(self): return mumble(self.x, self.y) the user need not know how I chose to represent 2D points, because there is a method available to set and get both cartesian and polar representations. If I decide for whatever reason that it's more efficient to represent points in polar form, I can change the underlying representation of a point without changing the API at all: class Point: def __init__(self): self.theta = self.radius = 0.0 def set_cartesian(self, x, y): self.theta, self.radius = mumble(x, y) def set_polar (self, theta, radius): self.theta, self.radius = theta, radius def get_cartesian(self): return mumble(self.theta, self.radius) def get_polar(self): return self.theta, self.radius If I had exposed the internal representation as part of the API, by perhaps presenting an incomplete set of methods: class Point: def __init__(self): self.x = self.y = 0.0 def set_polar (self, theta, radius): self.x, self.y = mumble(theta, radius) def get_polar(self): return mumble(self.x, self.y) I would have forced the caller to access x and y directly to get and set the cartesian coordinates. I'd then be stuck if I decided it was best to represent points internally as polar coordinates. Python doesn't force this data hiding on you. A caller can still access point.x or point.y directly, but if you make your desires known and they still sidestep your interface, that's their problem. (As Guido says, "after all, we are all adults.") There is a subtle shift in perspective from an action-centered view of things to a data-centered view of things that takes place somewhere along the way. When that happens I think most people have an "aha!" sort of experience. It suddenly gels and many problems seem to decompose naturally into objects. Until then (and perhaps frequently after) the world still looks like a bunch of functions with data getting passed around as an afterthought. I've completely ignored issues of refinement (subclassing). I'll let someone else answer that part. Skip Montanaro | http://www.mojam.com/ skip@mojam.com | http://www.musi-cal.com/ 847-971-7098 | Python: Programming the way Guido indented... From aerogems@netins.net Fri Nov 12 16:22:24 1999 From: aerogems@netins.net (Scott Billings) Date: Fri, 12 Nov 1999 10:22:24 -0600 Subject: [Tutor] Classes, Classes, Classes References: <382B6A79.452C7724@ghg.net> <14380.14154.254055.181401@dolphin.mojam.com> Message-ID: <382C3EC0.8301F4D0@netins.net> Maybe it's just because I'm bored and thinking a nice game of Q2 would cure that ailment, here's another way to look at classes in a fairly high level manner.... In your typical game of Quake(II) you encounter many different types of monsters to which you are suppose to blow to kingdom come. Each of these mosters has specific attributes about them... They attack in different ways, have different weapons at their disposal, etc. However, each class of monster has many things in common. So, the best way to write a program such as that, would be to use a method where you can construct a general form of monster. For instance, we'll take your common enemy, the sentry guy. Since all sentry guys are going to look the same (initially), have the same weapon, and same attack methods, having some sort of plan for making these monsters quickly would be nice. Classes do that.... They let you define all the details of the monster... Then, you create the individual monsters from that plan.... After which, if one monster is killed by you, you might have a variable named "dead", which would basically be a boolean (true/false) sort of variable. Also, since the monsters can attack you independantly of each other, the game might call an attack function/method of one monster, whille calling the function/method for causing another one to run away. I always liked the description of subclassing from the "Teach Yourself Java in 21 Days".... Say you want to create a bunch of monsters. Well, what do all monsters have in common? Maybe that they're scary, mean, and generally anti-social. So, you create a real general class called Monster. Now, some monsters have 4 legs, some have 2. So, you create a somewhat more specific class for 2 legged monsters, and for 4 legged monsters. Each, however, sharing the basic attributes of all monsters, so they are subclasses of the Monster class. Maybe some 4-legged monsters can fly, while others can't. So, under the 4-legged monster class, you can create a somewhat more specific set of classes. One for the 4-legged monsters that can fly, and one for 4-legged monsters that can't fly. Subclassing is basically starting with a real general subject/topic (Monsters), and then becoming increasingly specific (2/4 legs, can fly, can't fly). So, another example might be the general topic of birds. All birds have feathers, and have two legs. So, we might make a class: class Birds: legs = 2 haveFeathers = 1 Now, some birds can fly, so you might make a subclass for birds that can fly, and another for those that can't. Under those that don't fly, you might include more specific things, such as a class named Chickens. Having methods like layEgg(), runAroundWithHeadChoppedOff(), etc. > RP> Hello, I am experiencing trouble understanding classes. I don't > RP> understand how they work, what they do and their purpose in > RP> general. > > Classes are used to group data together with the functions (methods) that > operate on them. The usual intention is that an object holds a number of > pieces of data and a functional interface (API) to those data are presented > to the world. Since the data can change as requirements change (say, as new > algorithms are needed to improve performance), hiding the data > representation behind an API reduces the coupling between the class and the > code that uses it. > > Perhaps the simplest example of this is the use of polar coordinates > vs. cartesian coordinates to represent points in 2D or 3D space. [ ... ] From Gerrit Holl Fri Nov 12 06:32:55 1999 From: Gerrit Holl (Gerrit Holl) Date: Fri, 12 Nov 1999 07:32:55 +0100 Subject: [Tutor] Classes, Classes, Classes In-Reply-To: <382B6A79.452C7724@ghg.net> References: <382B6A79.452C7724@ghg.net> Message-ID: <19991112073255.A11531@optiplex.palga.uucp> R Parker wrote: > Hello, I am experiencing trouble understanding classes. I don't > understand how they work, what they do and their purpose in general. I > am a newbie so dont make it too complicated because this is the first > programming language I'm learning. > Thanks in advance! A class is representing something. For example, a list is a class, in fact. With a list you can do several things: .sort, .append, .pop, etc. This way, you could also write a game with a class representing the main person in the game. That person can .jump(), .walk_faster(), .dive(), etc. What book are you learning from, or are you learning from the WWW? regards, Gerrit. -- linuxgames.nl.linux.org All about games on Linux in Dutch (under construction). www.nl.linux.org The Dutch resource for Dutch Linux documentation. www.nl.linux.org/discoverb Learn foreign words and definitions. www.nl.linux.org/~gerrit/asperger I'm an Asperger, go here for more info. www.nl.linux.org/~gerrit About me and pictures of me. From kaiko@net21.com.sg Tue Nov 16 23:01:46 1999 From: kaiko@net21.com.sg (kaiko@net21.com.sg) Date: Tue Nov 16 17:01:46 CST 1999 Subject: [Tutor] Asean Export Centre Message-ID: <199911160954.EAA28240@python.org> Dear Sir or Madam: Allow me to introduce myself. I am NetSpirit, an electronic salesman that travels around the world to bring you all kinds of useful products and services. This time round, I have brought with me great business opportunities from South East Asia. Please visit http://www.asean-export.com to find out more. If you are looking for instant business opportunities, we have a lot of GREAT DEALS ( http://www.asean-export.com/product.htm ) in store for you! You are also invited for a free tour ( http://www.asean-export.com/freetour.htm ) of all our related web-sites. If you wish to be updated with our latest information, simply download me ( http://www.asean-export.com/download.htm ) as an icon on your desktop for direct access. However, if you do not want me to visit you again, simply delete me and do accept my sincere apology. If you have any brilliant business ideas that you want to realize or require any special Internet marketing services, we can be contacted in Singapore at: kaiko@net21.com.sg Note: This email is intended for interested users only. If you do not wish to be included in our mailing list, just reply to let us know. From PaulODavis@aol.com Tue Nov 16 22:23:01 1999 From: PaulODavis@aol.com (PaulODavis@aol.com) Date: Tue, 16 Nov 1999 17:23:01 EST Subject: [Tutor] Python saves the day? Message-ID: <0.9f9e1094.25633345@aol.com> Hi, Fascinating stuff on this site. I need some advice if possible. I have a source code (It's AI code for a game) written in C++. My intrepid programmer decided that Visual Basic was the desired front-end to bring this to the web. Sadly, he was mistaken. Now we have almost finished graphics and still seek a front-end solution. Could Python and SWIG save the day, do you think? Would Python be a better choice for such a task than say, Smalltalk? As you can tell I'm somewhat techno-limited but could sure use some help in getting out from under the VB steamroller. Thanks, Paul Davis From 7kcsl@qlink.queensu.ca Tue Nov 16 22:33:15 1999 From: 7kcsl@qlink.queensu.ca (Kevin Liang) Date: Tue, 16 Nov 1999 17:33:15 -0500 Subject: [Tutor] newbie question 2 Message-ID: <3831DBAB.2407F9B7@qlink.queensu.ca> --------------B633F793BF3360DAA6F6DEF6 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit def numwords(s): list = string.split(s) return len(list) What does the (s) mean ? Thanks.. Also, I was thinking of getting the book Learning Python , the one by O'Reily et al , and has the big rat/mouse on the cover..anyone recommend it ? It had a good review in linux journal Kevin --------------B633F793BF3360DAA6F6DEF6 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit

def numwords(s):

    list = string.split(s)
    return len(list)

What does the (s) mean ?  Thanks..
Also, I was thinking of getting the book Learning Python , the one by O'Reily et al , and has the big rat/mouse on the cover..anyone recommend it ?  It had a good review in linux journal

Kevin --------------B633F793BF3360DAA6F6DEF6-- From deirdre@deirdre.net Tue Nov 16 22:27:13 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 16 Nov 1999 14:27:13 -0800 (PST) Subject: [Tutor] newbie question 2 In-Reply-To: <3831DBAB.2407F9B7@qlink.queensu.ca> Message-ID: On Tue, 16 Nov 1999, Kevin Liang wrote: > def numwords(s): > list = string.split(s) > return len(list) > > What does the (s) mean ? Thanks.. It's a parameter passed in. In this case, it's a string variable with the name s. the next line splits it by white space and the following line counts the number of pieces. > Also, I was thinking of getting the book Learning Python , the > one by O'Reily et al , and has the big rat/mouse on the > cover..anyone recommend it ? It had a good review in linux > journal Given that there's no other beginner book, it is useful. -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net "Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator "That's because the Martians keep shooting things down." -- Harlan Rosenthal , retorting in Risks Digest 20.60 From joe@strout.net Tue Nov 16 22:41:34 1999 From: joe@strout.net (Joseph J. Strout) Date: Tue, 16 Nov 1999 14:41:34 -0800 Subject: [Tutor] Python saves the day? In-Reply-To: <0.9f9e1094.25633345@aol.com> References: <0.9f9e1094.25633345@aol.com> Message-ID: At 5:23 PM -0500 11/16/99, PaulODavis@aol.com wrote: >source code (It's AI code for a game) written in C++. My intrepid programmer >decided that Visual Basic was the desired front-end to bring this to the web. > Sadly, he was mistaken. Now we have almost finished graphics and still seek >a front-end solution. What does it mean to "bring this to the web"? Are you talking about a CGI interface (i.e., users play directly over the web), or something people download and run, or what? FWIW, I tinkered a bit with Python-based CGI games. If anybody's interested, let me know and I'll give you the URL (don't want to post it publicly and overload my server!). Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' From joe@strout.net Tue Nov 16 22:44:39 1999 From: joe@strout.net (Joseph J. Strout) Date: Tue, 16 Nov 1999 14:44:39 -0800 Subject: [Tutor] newbie question 2 In-Reply-To: <3831DBAB.2407F9B7@qlink.queensu.ca> References: <3831DBAB.2407F9B7@qlink.queensu.ca> Message-ID: At 5:33 PM -0500 11/16/99, Kevin Liang wrote: >def numwords(s): > list = string.split(s) > return len(list) > >What does the (s) mean ? It's the parameter to the "string.split" function. You need to go through the tutorial: http://www.python.org/doc/current/tut/tut.html If you're at a point where you can't recognize a parameter to a function -- and possibly don't even know what parameters and functions are -- then going through the tutorial, page by page (which will only take an hour or so) will save you many weeks of bewilderment. >Also, I was thinking of getting the book Learning Python , the one >by O'Reily et al , and has the big rat/mouse on the cover..anyone >recommend it ? It had a good review in linux journal I've never read it, but it might be a good idea. Start with the tutorial in any case; it's very good. Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' From steve@spvi.com Tue Nov 16 22:54:08 1999 From: steve@spvi.com (Steve Spicklemire) Date: Tue, 16 Nov 1999 17:54:08 -0500 (EST) Subject: [Tutor] Python saves the day? In-Reply-To: <0.9f9e1094.25633345@aol.com> (PaulODavis@aol.com) References: <0.9f9e1094.25633345@aol.com> Message-ID: <199911162254.RAA22889@acer.spvi.com> Hi Paul, I'm not sure what you mean by 'front end'.. are you talking about something that runs in a browser, or just a custom client app that talks to a game server somewhere else? -steve >>>>> "PaulODavis" == PaulODavis writes: PaulODavis> Hi, Fascinating stuff on this site. I need some advice PaulODavis> if possible. I have a source code (It's AI code for a PaulODavis> game) written in C++. My intrepid programmer decided PaulODavis> that Visual Basic was the desired front-end to bring PaulODavis> this to the web. Sadly, he was mistaken. Now we have PaulODavis> almost finished graphics and still seek a front-end PaulODavis> solution. Could Python and SWIG save the day, do you PaulODavis> think? Would Python be a better choice for such a task PaulODavis> than say, Smalltalk? As you can tell I'm somewhat PaulODavis> techno-limited but could sure use some help in getting PaulODavis> out from under the VB steamroller. Thanks, Paul Davis PaulODavis> _______________________________________________ Tutor PaulODavis> maillist - Tutor@python.org PaulODavis> http://www.python.org/mailman/listinfo/tutor From sessile@in-gen.net Tue Nov 16 23:05:59 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Tue, 16 Nov 1999 18:05:59 -0500 Subject: [Tutor] Converting from Python list or tuple to C array Message-ID: <3.0.6.32.19991116180559.007b0320@mail.in-gen.net> I need to send a list (or possibly a tuple, I haven't decided which will be easiest) from Python out to an extension module. Here is an example of what one of the python function calls look like: myfunc('name', 2.0, 3, 4, mylist) I know how to get the 1st four arguments into the extension using something along the lines of: PyArg_ParseTuple(args, "sfii", &str1, &float1, &int1, &int2); But how do I get the list (or tuple)? And once I have it, how do I turn the PyObject into a C array? Note: "mylist" may be a list of lists of arbitrary length. Thanks for any pointers, Dean. -- E-Mail: sessile@in-gen.net "I don't want the world... I just want your half." -- TMBG (Anna Ng) From deirdre@deirdre.net Tue Nov 16 22:49:15 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 16 Nov 1999 14:49:15 -0800 (PST) Subject: [Tutor] newbie question 2 In-Reply-To: Message-ID: On Tue, 16 Nov 1999, Joseph J. Strout wrote: > At 5:33 PM -0500 11/16/99, Kevin Liang wrote: > >def numwords(s): > If you're at a point where you can't recognize a parameter to a > function -- and possibly don't even know what parameters and > functions are -- then going through the tutorial, page by page (which > will only take an hour or so) will save you many weeks of > bewilderment. In most languages, the parameters are given type. I felt it odd at first myself. I wouldn't assume that someone doesn't know parameters and functions because the lack of typing throws them. > I've never read it, but it might be a good idea. Start with the > tutorial in any case; it's very good. Agreed on the tutorial. -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net "Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator "That's because the Martians keep shooting things down." -- Harlan Rosenthal , retorting in Risks Digest 20.60 From joe@strout.net Tue Nov 16 23:17:38 1999 From: joe@strout.net (Joseph J. Strout) Date: Tue, 16 Nov 1999 15:17:38 -0800 Subject: [Tutor] newbie question 2 In-Reply-To: References: Message-ID: At 2:49 PM -0800 11/16/99, Deirdre Saoirse wrote: >In most languages, the parameters are given type. I felt it odd at first >myself. I wouldn't assume that someone doesn't know parameters and >functions because the lack of typing throws them. Ah, I thought he was asking about the parameter to string.split. Didn't even notice the parameter in the def statement. You're right, that's probably the one he was asking about. Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' From arcege@shore.net Tue Nov 16 23:38:46 1999 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 16 Nov 1999 18:38:46 -0500 (EST) Subject: [Tutor] Converting from Python list or tuple to C array In-Reply-To: <3.0.6.32.19991116180559.007b0320@mail.in-gen.net> from "sessile@in-gen.net" at "Nov 16, 99 06:05:59 pm" Message-ID: <199911162338.SAA12131@northshore.shore.net> > I need to send a list (or possibly a tuple, I haven't > decided which will be easiest) from Python out to an > extension module. Here is an example of what one of the > python function calls look like: > > myfunc('name', 2.0, 3, 4, mylist) > > I know how to get the 1st four arguments into the extension > using something along the lines of: > > PyArg_ParseTuple(args, "sfii", &str1, &float1, &int1, &int2); > > But how do I get the list (or tuple)? And once I have it, how > do I turn the PyObject into a C array? Note: "mylist" may be a > list of lists of arbitrary length. > > Thanks for any pointers, > Dean. You will want to get the value back using "O" in the format string. PyObject *mylist; PyArg_ParseTuple(args, "sfiiO", &str1, &float1, &int1, &int2, &mylist); if (!PySequence_Check(mylist)) { PyErr_SetString(PyExc_TypeError, "expected sequence"); return NULL; } You will have to decide exactly what is expected of mylist.. the C code isn't as forgiving aa Python. For example, do you want it to be a list of strings, tuple of either strings or integers, a recursive list of integers or strings or floats (union). You can do what ever you want, but you need to be clear in the C code. I'll assume a sequence of integers (could be a list or a tuple). PyObject *item; int *intarr, arrsize, index; ... /* how many elements are in the Python object */ arrsize = PyObject_Length(mylist); /* create a dynamic C array of integers */ intarr = (int *)malloc(sizeof(int)*arrsize); for (index = 0; index < arrsize; index++) { /* get the element from the list/tuple */ item = PySequence_Getitem(mylist, index); /* we should check that item != NULL here */ /* make sure that it is a Python integer */ if (!PyInt_Check(item)) { free(intarr); /* free up the memory before leaving */ PyErr_SetString(PyExc_TypeError, "expected sequence of integers"); return NULL; } /* assign to the C array */ intarr[index] = PyInt_AsLong(item); } /* now use intarr and arrsize in you extension */ I hope this helps. Let me know if you need further hints and tips. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From Taro.Ogawa.73439858@navy.gov.au Wed Nov 17 02:05:05 1999 From: Taro.Ogawa.73439858@navy.gov.au (Taro.Ogawa.73439858@navy.gov.au) Date: Wed, 17 Nov 1999 12:05:05 +1000 Subject: [Tutor] SEC: UNCLASSIFIED:-Object Ancestry Message-ID: <4A25682C.0007BC69.00@nschq-e-navy.navy.gov.au> Yola, Is there a nice way to determine which classes an object inherits from, short of putting in capability queries or using __init__ to add a reference to that class to an inherit_list variable? TIA, --OH. From arcege@shore.net Wed Nov 17 03:10:03 1999 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 16 Nov 1999 22:10:03 -0500 (EST) Subject: [Tutor] SEC: UNCLASSIFIED:-Object Ancestry In-Reply-To: <4A25682C.0007BC69.00@nschq-e-navy.navy.gov.au> from "Taro.Ogawa.73439858@navy.gov.au" at "Nov 17, 99 12:05:05 pm" Message-ID: <199911170310.WAA11849@northshore.shore.net> > Is there a nice way to determine which classes an object inherits from, short of > putting > in capability queries or using __init__ to add a reference to that class to an > inherit_list > variable? Each instance has an "__class__" attribute which references its class object, and each class has a "__bases__" attribute which is a tuple of the inherited classes, if any. There are also two standard, built-in functions which can test for inheritance: isinstance() and issubclass(). >>> class A: ... pass ... >>> class B(A): ... pass ... >>> a, b = A(), B() >>> a.__class__ >>> a.__class__ is A 1 >>> A.__bases__ () >>> b.__class__ >>> B.__bases__ (,) >>> B.__bases__[0] is A 1 >>> A in b.__class__.__bases__ 1 >>> isinstance(a, A) 1 >>> isinstance(a, B) 0 >>> isinstance(b, B) 1 >>> isinstance(b, A) 1 >>> issubclass(B, A) 1 >>> issubclass(A, B) 0 >>> The isinstance() function also works with types. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From alan.gauld@bt.com Wed Nov 17 10:38:01 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 17 Nov 1999 10:38:01 -0000 Subject: [Tutor] newbie question 2 Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EF9@mbtlipnt02.btlabs.bt.co.uk> > def numwords(s): > list = string.split(s) > return len(list) > > What does the (s) mean ? Thanks.. Uh oh,. another one from my tutorial... If you go back to the top of the Modules page (called "Making it even it even easier")you'll find the following explanation: ------------------------------------ Using Functions Before considering how to create functions let's look at how we use the many, many functions that come with any programming language (often called the library). We've already seen some functions in use and listed others in the operators section. Now we'll consider what these have in common and how we can use them in our programs. The basic structure of a function is as follows: aValue = someFunction(anArgument, another, etc...) That is a variable takes on a value obtained by calling a function. The function can accept 0 or many arguments which it treats like internal variables. Functions can call other functions internally. Let's consider some examples in our various languages to see how this works: -------------------------------- The key is in the last paragraph. It sounds like you feel that is insufficient. If so please mail me directly and I'll incorporate your feedback into the tutor. Thanks, Aan G. From SKS@Sierra.net Thu Nov 18 16:40:34 1999 From: SKS@Sierra.net (Adam T.) Date: Thu, 18 Nov 1999 08:40:34 -0800 Subject: [Tutor] newbie Message-ID: <000d01bf31e3$a3898860$d5e287cf@oem> This is a multi-part message in MIME format. ------=_NextPart_000_000A_01BF31A0.94B547E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ok, So I'm new to python. I've started learning QBASIC and It's coming = along well. but I understand python is better. Could someone please give = me a list of the basic commands (PRINT, WRITE, INPUT, LOOP, Etc...)? and = also, I'd like to know about any compilers for python that I can get. =20 Any newbie help is greatly appreciated. Thanx sks@sierra.net =20 Adam ------=_NextPart_000_000A_01BF31A0.94B547E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

ok, So I'm new to python. I've = started learning=20 QBASIC and It's coming along well. but I understand python is better. = Could=20 someone please give me a list of the basic commands (PRINT, WRITE, = INPUT, LOOP,=20 Etc...)? and also, I'd like to know about any compilers for python that = I can=20 get.  
   Any newbie help is = greatly=20 appreciated. Thanx       sks@sierra.net  
          &nbs= p;            = ;            =        =20 Adam
------=_NextPart_000_000A_01BF31A0.94B547E0-- From rbowman@montana.com Fri Nov 19 14:01:35 1999 From: rbowman@montana.com (bowman) Date: Fri, 19 Nov 1999 07:01:35 -0700 (MST) Subject: [Tutor] RE:. newbie (Adam T.) In-Reply-To: <199911190608.BAA05397@python.org> Message-ID: > along well. but I understand python is better. Could someone please give = > me a list of the basic commands (PRINT, WRITE, INPUT, LOOP, Etc...)? and = > also, I'd like to know about any compilers for python that I can get. =20 http://www.python.org One stop shopping: The complete language reference, the library reference, a tutuorial, links to download the distro for whatever platform you are using, and much more. BTW, how did you find this list without finding the site? From fflores@arnet.com.ar Sun Nov 21 01:09:24 1999 From: fflores@arnet.com.ar (FFlores) Date: Sat, 20 Nov 1999 22:09:24 -0300 Subject: [Tutor] Another newbie: looking for GUIs Message-ID: <05a7334120115b9MAIL1@mail1.arnet.com.ar> Is there a good GUI that I could use to execute a program in Windows 95? How do I create a window, for example? Do I have to use the Win32 API? (please tell me no...) --Pablo Flores http://draseleq.conlang.org/ From spirou@carolo.net Sun Nov 21 02:07:40 1999 From: spirou@carolo.net (Denis) Date: Sun, 21 Nov 1999 03:07:40 +0100 Subject: [Tutor] Another newbie: looking for GUIs References: <05a7334120115b9MAIL1@mail1.arnet.com.ar> Message-ID: <383753EC.44A5B216@carolo.net> FFlores wrote: > > Is there a good GUI that I could use to execute a program > in Windows 95? The (up to now) standard is Tkinter Have a look at http://www.python.org/topics/tkinter Alternatives exist. > How do I create a window, for example? for a Hello World window : http://www.pythonware.com/library/tkinter/introduction/hello-tkinter.htm > Do I have to use the Win32 API? (please tell me no...) no ;-) Denis From picasso@videotron.ca Mon Nov 22 19:21:29 1999 From: picasso@videotron.ca (Oscar Picasso) Date: Mon, 22 Nov 1999 14:21:29 -0500 Subject: [Tutor] Reading big files Message-ID: <3.0.6.32.19991122142129.007a2660@pop.videotron.ca> Hi, I have a PDF file I want to read. I used the following code. f=open('D:\\Documents\\MyFile') If I: s=f.read() len(s) I get 768, the lenght of s. However my file is around 5Mo. I expected he string s to content all the characters of my files. If I do : f=open('D:\\Documents\\MyFile') l=f.readlines() len(l) I get 4. My file is supposed to have several thousand of lines. I expected l to contain all the lines of the files. Where I am wrong. Is the file too big. Has it a special character in it that doesn't allow to read the entire content. I'm working with python 1.5.2 on Windows98. Any help appreciated. ****************************************************** Oscar Picasso picasso@videotron.ca ****************************************************** From EJB9969@aol.com Wed Nov 24 01:00:53 1999 From: EJB9969@aol.com (EJB9969@aol.com) Date: Tue, 23 Nov 1999 20:00:53 EST Subject: [Tutor] This is my 1st time making programs, I need help!!! Message-ID: <0.8d80241a.256c92c5@aol.com> Can you give me detailed instructions on how to work your program: "Python for Windows 95/98 and NT" I would really appreciate it. From alan.gauld@bt.com Wed Nov 24 12:00:04 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 24 Nov 1999 12:00:04 -0000 Subject: [Tutor] Reading big files Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB202DF5F17@mbtlipnt02.btlabs.bt.co.uk> > I have a PDF file I want to read. I used the following code. > > f=open('D:\\Documents\\MyFile') You'll need to open it in binary mode: f=open('D:\\Documents\\MyFile', 'rb') Actually I assume your file ends in .pdf so you'll need that too! f=open('D:\\Documents\\MyFile.PDF', 'rb') Make sure explorer view settings are set to show the full filename, the default hides known extensions.... Then you'll need to find a reference for the internal format of the PDF file and decode the binary bytes that you read. > Where I am wrong. Is the file too big. Has it a special > character in it that doesn't allow to read the entire content. It probably has some kind of binary character combination that looks like EOF to Python. One thing to try is open the file using debug from a DOS prompt: C:> debug foo.pdf Use 'd' at the prompt to dump a listing of the file in hex. There is also an ASCII listing on the right. Compare the characters on the right with the hex patterns on the left - that may help you decode the PDF format sufficiently well to extract the text you want.... Alan G. From warren@nightwares.com Wed Nov 24 15:12:23 1999 From: warren@nightwares.com (Warren 'The Howdy Man' Ockrassa) Date: Wed, 24 Nov 1999 09:12:23 -0600 Subject: [Tutor] This is my 1st time making programs, I need help!!! References: <0.8d80241a.256c92c5@aol.com> Message-ID: <383C0057.D355246A@nightwares.com> EJB9969@aol.com wrote: > Can you give me detailed instructions on how to work your program: > "Python for Windows 95/98 and NT" 1. Go to http://www.python.org/ . 2. Read its content. --WthmO Bad news hits hard. Only The Indigestible punches back. http://www.the-indigestible.com/ From neilconway@home.com Sat Nov 27 05:07:05 1999 From: neilconway@home.com (Neil Conway) Date: Sat, 27 Nov 1999 00:07:05 -0500 (EST) Subject: [Tutor] Break, multiple loops Message-ID: Hello all. I was wondering - is there a way to break cleanly out of multiple loops? The exact same as a 'break' statement, but out of *all* loops. i.e --- while 1: while 2: super_break --- A normal break statement just leaps out of the first 'while' (if I'm not mistaken). I would like a statement that leaps out of both loops. In 'Programming Python' (pg. 193), they have a somewhat similar dilemma, and they use an 'exitflag' variable to check if the first loop has been broken, and if it has, execute another 'break'. This seems messy to me: isn't there a better way? Especially if I want to leap out of, say, 10 loops with 1 'super_break' statement. Thanks in advance, Neil Conway ---------------------------------- E-Mail: Neil Conway Date: 27-Nov-1999 Time: 00:00:22 This message was sent by XFMail ---------------------------------- From Emile van Sebille" Message-ID: <082c01bf38ea$7371be00$01ffffc0@worldnet.att.net> Neil, I'm not sure if this is a 'clean' way to do it, but it is clear... try: while 1: while 2: dostuff() raise "Exitting..." except "Exitting...": pass Emile van Sebille emile@fenx.com ------------------- ----- Original Message ----- From: Neil Conway To: Sent: Friday, November 26, 1999 9:07 PM Subject: [Tutor] Break, multiple loops > Hello all. > > I was wondering - is there a way to break cleanly out of multiple loops? The > exact same as a 'break' statement, but out of *all* loops. i.e > --- > while 1: > while 2: > super_break > --- > A normal break statement just leaps out of the first 'while' (if I'm not > mistaken). I would like a statement that leaps out of both loops. > > In 'Programming Python' (pg. 193), they have a somewhat similar dilemma, and > they use an 'exitflag' variable to check if the first loop has been broken, and > if it has, execute another 'break'. This seems messy to me: isn't there a > better way? Especially if I want to leap out of, say, 10 loops with 1 > 'super_break' statement. > > Thanks in advance, > > Neil Conway > > ---------------------------------- > E-Mail: Neil Conway > Date: 27-Nov-1999 > Time: 00:00:22 > > This message was sent by XFMail > ---------------------------------- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > > From ivanlan@callware.com Sat Nov 27 15:29:13 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Sat, 27 Nov 1999 08:29:13 -0700 Subject: [Tutor] Break, multiple loops References: <082c01bf38ea$7371be00$01ffffc0@worldnet.att.net> Message-ID: <383FF8C9.B4F2859F@callware.com> Hi All-- Emile van Sebille wrote: > > Neil, > > I'm not sure if this is a 'clean' way to do it, but it is clear... > > try: > while 1: > while 2: > dostuff() > raise "Exitting..." > except "Exitting...": > pass > Looks damn clean to me. Much nicer than a flag, I think, and exceptionally readable. I like it. -ly y'rs, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours ---------------------------------------------- From newsreporter@rciinfo.com Mon Nov 29 03:02:59 1999 From: newsreporter@rciinfo.com (News Reporter) Date: Mon, 29 Nov 1999 3:02:59 PM -0500 Subject: [Tutor] Finding Good Human Resource Candidates Message-ID: <199911291502.YND4953@rciinfo.com> The competition for finding good Human Resource candidates if fierce! However, there is an edge - and we want you to have it FREE! BestJobsUSA.com will run all of your Human Resource category positions free. No catch. Nothing to buy. No obligation whatsoever. At BestJobsUSA.com, we recognize our business is dependent upon getting results for our Human Resource clients. This is just another way to keep you aware of our services. E-mail your Human Resource category positions to us at: mailto:RCI@BestJobsUSA.com. We'll have it up and running within 48 hours. If this isn't your function please forward on to the appropriate person. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- We also want to make you aware of our WebRunner resume retrieval technology. WebRunner will deliver resumes that meet your specific job criteria quickly and cost effectively. This service is available now for the low cost of $400.00 per search. Simply provide us with the with job description, or key words (competitors you would like to target…) and we do all the work. For full information, contact Gregg Lowenstein at mailto:glowenstein@rcimedia.com or telephone at (561)686-6800, ext. 314 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This information has been e-mailed to keep you apprised of recruitment-advertising opportunities. If this information is not suitable for your area of responsibility or if you want to be removed from our distribution list, please e-mail mailto:nothankyou@rcimedia.com?subject=HR From atp@bahianet.com.br Mon Nov 29 21:59:54 1999 From: atp@bahianet.com.br (Alexandre Passos) Date: Mon, 29 Nov 1999 19:59:54 -0200 Subject: [Tutor] TKinter Message-ID: <003301bf3ab5$13138080$0c5bdfc8@the-user> Has someone got a link to some __downloadable__ tutorial of TKinter? From ralphalberti@worldnet.att.net Mon Nov 29 23:54:17 1999 From: ralphalberti@worldnet.att.net (Ralph Alberti) Date: Mon, 29 Nov 1999 18:54:17 -0500 Subject: [Tutor] TKinter References: <003301bf3ab5$13138080$0c5bdfc8@the-user> Message-ID: <38431229.7B60A603@worldnet.att.net> Have you seen this: http://starship.python.net/crew/fredrik/tkintro/Introduction.htm --Ralph Alexandre Passos wrote: > > Has someone got a link to some __downloadable__ tutorial of TKinter? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From da@ski.org Mon Nov 1 17:15:07 1999 From: da@ski.org (David Ascher) Date: Mon, 1 Nov 1999 09:15:07 -0800 (Pacific Standard Time) Subject: [Tutor] Is python just a scripting language? In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB202DF5EBA@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Mon, 1 Nov 1999 alan.gauld@bt.com wrote: > There should be compiled scripts too - files ending in .pyc > > These load slightly faster than scripts and can be distributed > if, for some reason, you want to protect your source code from > scrutiny. Just FYI, they're not designed to protect the user from reading them, and are easily 'uncompiled'. > The freeze tool for producing executables is somewhat limited > and produces rather big files since, as far as I can tell, > it basically bundles up the interpreter and all required units > into a big binary! (I think its only for Windows too) Freeze also works on Unix. --david