From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 1 00:40:23 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 31 Jul 2000 16:40:23 -0700 (PDT) Subject: [Tutor] Why doesn't this work?? In-Reply-To: Message-ID: On Mon, 31 Jul 2000, Deirdre Saoirse wrote: > On Mon, 31 Jul 2000, Carl Kreider wrote: > > > I agree that 0, 20, 30, and 40 mod 10 yield 0, but since > > when does 10, 50, or 60 mod 10 yield 10? Do I misremember > > how mod works? > > mod is an integer-based function, so yes, you misremembered. Mod actually does work on floating point numbers. The problem that you're encountering has to do with limited precision. That is, the larger the number becomes, the less precise the number becomes. Let's take a look again at that weird case: ttp: T=6.000000 num=60.000000 den=10.000000 ttp=10.000000 In this particularly perverse case, a number like 60.000000000 is probably represented as 59.9999999999999999... or something like that. I'll be very wishy washy at this point --- this means that grabbing the remainder of 60.0 / 10.0 will get you 9.999999999999... as a remainder. Afterwards, when you print it again, you'll get 10.0. Very very evil... Your program is particuarily cool in that it shows this bug clearly --- you might want to keep it! From deirdre@deirdre.net Tue Aug 1 00:30:55 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 31 Jul 2000 16:30:55 -0700 (PDT) Subject: [Tutor] Why doesn't this work?? In-Reply-To: Message-ID: On Mon, 31 Jul 2000, Daniel Yoo wrote: > Mod actually does work on floating point numbers. The problem that > you're encountering has to do with limited precision. That is, the > larger the number becomes, the less precise the number becomes. Let's put it this way: if the results aren't reliable, it doesn't *work.* OK? :) It's one of those things like comparing floating point numbers that appear equal (but aren't) that will get you in a world of hurt if you make assumptions. Much better to use ONLY integers with functions like mod. -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "We can always count on the British. Except for the Revolutionary War they've been perfect." -- Mel Brooks, on the first Concorde flight since the Paris crash. From emo_sofia@yahoo.com Tue Aug 1 01:53:37 2000 From: emo_sofia@yahoo.com (emo sofia) Date: Mon, 31 Jul 2000 17:53:37 -0700 (PDT) Subject: [Tutor] Help on “IF” Statements Message-ID: <20000801005337.25500.qmail@web1806.mail.yahoo.com> Please to help me to use “IF” Statement. I want to study how to program, but I don’t know to use any language and I decide to study Python, it’s pretty language, not hard but very powerful. These days I’m reading Python Tutorial, I understand it but I can’t use “IF” statement. My platform is Win2000 and I use Release 1.6. Here is the example from the tutorial: >>> x = int(raw_input("Please enter a number: ")) >>> if x < 0: ... x = 0 ... print 'Negative changed to zero' ... elif x == 0: ... print 'Zero' ... elif x == 1: ... print 'Single' ... else: ... print 'More' ... I’ve done several attempts: 1. to type it: but the result is err >>> x = int(raw_input("Please enter a number: ")) Please enter a number: Traceback (innermost last): File "", line 1, in ? x = int(raw_input("Please enter a number: ")) ValueError: invalid literal for int(): 2. to copy it (and then to delete the points from the front): >>> if x < 0: x = 0 print 'Negative changed to zero' elif x == 0: print 'Zero' elif x == 1: print 'Single' else: print 'More' Please enter a number: 7 >>> (no error but I can’t see any print result.) Please to explain me about “IF”, I know what it mean and I have used it several times in Excel. A lot of thanks Best wishes, Emo __________________________________________________ Do You Yahoo!? Kick off your party with Yahoo! Invites. http://invites.yahoo.com/ From midnightwright@hotmail.com Tue Aug 1 05:30:15 2000 From: midnightwright@hotmail.com (~* Midnight *~) Date: Mon, 31 Jul 2000 23:30:15 CDT Subject: [Tutor] Just Getting Started, Basic Help. Message-ID: Okay, laugh, frown on me, that's okay, but I'm just getting started. I downloaded Python just yesterday, and when I went to install it wouldn't work. It was like it wasn't a program, wasn't and ".exe" file. I'm not sure what to do but any help would be appreciated. Sorry if I sound stupid, but I'm still learning and I was told Python was the best program for beginners. Thanks to anyone who responds! :) Kelly ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 1 05:36:12 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 31 Jul 2000 21:36:12 -0700 (PDT) Subject: [Tutor] Just Getting Started, Basic Help. In-Reply-To: Message-ID: On Mon, 31 Jul 2000, ~* Midnight *~ wrote: > Okay, laugh, frown on me, that's okay, but I'm just getting started. I > downloaded Python just yesterday, and when I went to install it wouldn't > work. It was like it wasn't a program, wasn't and ".exe" file. I'm not sure > what to do but any help would be appreciated. Sorry if I sound stupid, but > I'm still learning and I was told Python was the best program for beginners. > Thanks to anyone who responds! :) Hello! It sounds like you downloaded the installation for a difference species of computer. *grin* Most likely, you downloaded something like a .tar.gz, which is for UNIX system. Instead, you'll want to get the one for your Windows system. Here's the link: http://www.python.org/download/download_windows.html You'll just need to get py152.exe, and you should be set. Don't worry about asking questions --- we're all learning here. Good luck! From midnightwright@hotmail.com Tue Aug 1 06:45:29 2000 From: midnightwright@hotmail.com (~* Midnight *~) Date: Tue, 01 Aug 2000 00:45:29 CDT Subject: [Tutor] Just Getting Started, Basic Help. Message-ID: Yeah, I am about 99.9% positive I downloaded for Windows. I made sure I clicked on the Windows 95/98 link and downloaded from their main link. I did change the file name, however, from their default. Do you think that could have affected anything? Maybe the download simply messed up somehow. I suppose I could try downloading it again and leaving the file name intact. I'll delete the old one I downloaded and download again and see if that works. Thanks for the help. I'm sure I'll be asking more questions when I get going. Hopefully the "Learning to Program" page will be very clear and not too confusing. Once again, thanks for helping me. ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 1 07:29:02 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 31 Jul 2000 23:29:02 -0700 (PDT) Subject: [Tutor] Help on IF Statements In-Reply-To: <20000801005337.25500.qmail@web1806.mail.yahoo.com> Message-ID: Dear Emo, Hello! Ok, let's take a look. On Mon, 31 Jul 2000, emo sofia wrote: > 1. to type it: but the result is err > >>> x = int(raw_input("Please enter a number: ")) > Please enter a number: > Traceback (innermost last): > File "", line 1, in ? > x = int(raw_input("Please enter a number: ")) > ValueError: invalid literal for int(): Hmm... this appears to work for me: ### >>> x = int(raw_input("Please enter a number: ")) Please enter a number: 23 >>> x 23 ### However, if I press enter at the prompt instead, it'll trigger the same error message: ### >>> x = int(raw_input("Please enter a number: ")) Please enter a number: Traceback (innermost last): File "", line 1, in ? ValueError: invalid literal for int(): ### I'm not quite sure if that's what's happening with your program. You might want to temporarely hard-code values of 'x' into your program, since you're learning about if-statements. Your programs seem fine --- it might just be strangeness with input/output. If you're familiar with your text editor and command prompt, you might want to write your program into a '.py' file, and try using programs with raw_input() there. Doing this might make things easier --- you can correct typos without rewriting the whole section of code. From richard_chamberlain@ntlworld.com Tue Aug 1 07:39:08 2000 From: richard_chamberlain@ntlworld.com (Richard Chamberlain) Date: Tue, 1 Aug 2000 07:39:08 +0100 Subject: [Tutor] =?iso-8859-1?Q?Re:_=5BTutor=5D_Help_on_=22IF=22_Statements?= References: <20000801005337.25500.qmail@web1806.mail.yahoo.com> Message-ID: <000b01bffb83$343d8dc0$b061fea9@richardc> Emo, this works fine: x=int(raw_input("Enter a number:")) if x<0: x=0 print 'Negative changed to zero' elif x == 0: print 'Zero' elif x == 1: print 'Single' else: print 'More' when you say delete the points from the front do you mean the ...? The ... and >>> shouldn't be typed they are python prompts. Type it exactly as it is above and it should work. Richard ----- Original Message ----- From: emo sofia To: Sent: Tuesday, August 01, 2000 1:53 AM Subject: [Tutor] Help on "IF" Statements > > Please to help me to use "IF" Statement. > I want to study how to program, but I don't know to > use any language and I decide to study Python, it's > pretty language, not hard but very powerful. These > days I'm reading Python Tutorial, I understand it but > I can't use "IF" statement. My platform is Win2000 > and I use Release 1.6. > Here is the example from the tutorial: > >>> x = int(raw_input("Please enter a number: ")) > >>> if x < 0: > ... x = 0 > ... print 'Negative changed to zero' > ... elif x == 0: > ... print 'Zero' > ... elif x == 1: > ... print 'Single' > ... else: > ... print 'More' > ... > > I've done several attempts: > > 1. to type it: but the result is err > >>> x = int(raw_input("Please enter a number: ")) > Please enter a number: > Traceback (innermost last): > File "", line 1, in ? > x = int(raw_input("Please enter a number: ")) > ValueError: invalid literal for int(): > > 2. to copy it (and then to delete the points from the > front): > >>> if x < 0: > x = 0 > print 'Negative changed to zero' > elif x == 0: > print 'Zero' > elif x == 1: > print 'Single' > else: > print 'More' > > Please enter a number: 7 > >>> > (no error but I can't see any print result.) > Please to explain me about "IF", I know what it mean > and I have used it several times in Excel. > A lot of thanks > Best wishes, > Emo > > > __________________________________________________ > Do You Yahoo!? > Kick off your party with Yahoo! Invites. > http://invites.yahoo.com/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 1 07:48:45 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 31 Jul 2000 23:48:45 -0700 (PDT) Subject: [Tutor] Just Getting Started, Basic Help. In-Reply-To: Message-ID: On Tue, 1 Aug 2000, ~* Midnight *~ wrote: > Yeah, I am about 99.9% positive I downloaded for Windows. I made sure I > clicked on the Windows 95/98 link and downloaded from their main link. I did > change the file name, however, from their default. Do you think that could > have affected anything? Maybe the download simply messed up somehow. I > suppose I could try downloading it again and leaving the file name intact. I think that did it --- it needs to have the .exe extension for Windows to recognize it as an executable. > I'll delete the old one I downloaded and download again and see if that > works. Thanks for the help. I'm sure I'll be asking more questions when I > get going. Hopefully the "Learning to Program" page will be very clear and > not too confusing. Once again, thanks for helping me. Good luck to you! From kjohnston@rcsi.ie Tue Aug 1 14:42:22 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Tue, 1 Aug 2000 14:42:22 +0100 Subject: [Tutor] CGI and Python Message-ID: <9921C1171939D3119D860090278AECA2DEC617@EXCHANGE> Thank you guys for all your previous help as a result I think I'm getting places with Python. I have almost completed an application which calls on C programs and wish to place it on the Web. Can any of you suggest a good place to start learning about Python and CGI? Are there any good books / on-line tutorials that I should know about? Thanks again! Kate From Moshe Zadka Tue Aug 1 15:03:31 2000 From: Moshe Zadka (Moshe Zadka) Date: Tue, 1 Aug 2000 17:03:31 +0300 (IDT) Subject: [Tutor] CGI and Python In-Reply-To: <9921C1171939D3119D860090278AECA2DEC617@EXCHANGE> Message-ID: On Tue, 1 Aug 2000, Catriona Johnston wrote: > Thank you guys for all your previous help as a result I think I'm getting > places with Python. I have almost completed an application which calls on C > programs and wish to place it on the Web. Can any of you suggest a good > place to start learning about Python and CGI? Are there any good books / > on-line tutorials that I should know about? Start with the CGI chapter in the Library reference. There is also good information in www.python.org->Topics->CGI -- Moshe Zadka There is no IGLU cabal. http://advogato.org/person/moshez From djinni@freedomspace.net Tue Aug 1 16:46:17 2000 From: djinni@freedomspace.net (Djinni) Date: Tue, 1 Aug 2000 11:46:17 -0400 Subject: Fwd: Re: [Tutor] CGI and Python Message-ID: <00080111465703.22301@wolfkin.freedomspace.net> > Thank you guys for all your previous help as a result I think I'm getting > places with Python. I have almost completed an application which calls on C > programs and wish to place it on the Web. Can any of you suggest a good > place to start learning about Python and CGI? Are there any good books / > on-line tutorials that I should know about? > Thanks again! > Kate I dont know if it'll be any good for anyone else but I personally have a liking for the book 'Python Essential Reference' by David M. Beazley. It's a small book, and it's almost identical to the tutor that's on the python.org site. Convienent if you dont have it on your computer already, and need it when you are without net access. -- Dijinn ================================ "I'm nothing but contradictions and I make perfect sense." dijinn@dijinn.net mrandall@fit.edu Crypto: www.dijinn.net/jrandall.txt ------------------------------------------------------- From alan.gauld@bt.com Tue Aug 1 16:16:32 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 1 Aug 2000 16:16:32 +0100 Subject: [Tutor] Help on "IF" Statements Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D25E@mbtlipnt02.btlabs.bt.co.uk> > >>> x = int(raw_input("Please enter a number: ")) > >>> if x < 0: > ... x = 0 > ... print 'Negative changed to zero' > ... elif x == 0: > ... print 'Zero' > ... elif x == 1: > ... print 'Single' > ... else: > ... print 'More' Works OK for me... > I've done several attempts: > > 1. to type it: but the result is err > >>> x = int(raw_input("Please enter a number: ")) > Please enter a number: > Traceback (innermost last): > File "", line 1, in ? > x = int(raw_input("Please enter a number: ")) > ValueError: invalid literal for int(): Thats because you just hit ereturn which is not a valid number so the call to int() fails. To guard against that change: > >>> x = int(raw_input("Please enter a number: ")) to >>> x = raw_input("Please enter a number: ") >>> if not ((len(x) >= 1) and (x[0] >='0') and (x[0] < '9')): ... print 'I said enter a number bozo!' ... else: ... x = int(x) ... if x < 0: # proceed as before... That's still not bombproof but for that you probably want to use exceptions which you haven't covered in the tutor yet :-) Alan G. > > 2. to copy it (and then to delete the points from the > front): Sorry, I don't understand that bit... > Please enter a number: 7 > >>> > (no error but I can't see any print result.) I got 'More' You've understood IF OK, its the conversion of user input to an int thats causing the problem, and how to trap errors(which comes later...) Alan G. From wesc@alpha.ece.ucsb.edu Tue Aug 1 19:32:49 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Tue, 1 Aug 2000 11:32:49 -0700 (PDT) Subject: [Tutor] CGI and Python Message-ID: <200008011832.LAA10879@alpha.ece.ucsb.edu> > From: Catriona Johnston > Date: Tue, 1 Aug 2000 14:42:22 +0100 > > Thank you guys for all your previous help as a result I think I'm getting > places with Python. I have almost completed an application which calls on C > programs and wish to place it on the Web. Can any of you suggest a good > place to start learning about Python and CGI? Are there any good books / > on-line tutorials that I should know about? hi kate, yes, there seems to be a lack of CGI information in the current set of Python books hence the reason why i am making a strong push at a "decent" CGI intro into Core Python Programming, a project i'm working on for Prentice Hall's Core Series. the release date should be sometime late summer or early fall if you can wait that long! aside from the shameless self promotion, let's take a look at what *is* out there right now: --- Mark Lutz's first Python book, Python Programming from O'Reilly has a 2 page CGI example with a couple of paragraphs describing the script which itself has no internal documentation. --- The Quick Python book by Harms and McDonald has a chapter written by Robin Friedrich on HTMLgen, the maintainer of HTMLgen. the HTMLgen module is one which you *may* use in CGI if the HTML you are generating gets more complex or if you just need to generate massive number of pages with common formatting. it can also draw and render objects too. --- Internet Programming with Python, one of the first Python books out there along with the above Lutz book, written mostly by Aaron Watters should have some CGI in it too, but it's out-of-print. --- Brown's Python Annotated Archives has a couple of pages *telling* you about CGI, but doesn't really go into it at all, but *does* have a section on how to set a web *server* in Python which can process CGI. There is also a massive example (the FAQ Wizard script by Guido) which Brown annotates but is long and certainly not an intro to CGI. --- Beazley's Python Essential Reference book is just that... a reference. there is a snippet of CGI code there as well as a brief explanation, but not much more than that. it is for reference, not for learning. This is also applicable to the Python Library Reference by Guido. Neither of O'Reilly's Learning Python or Python Programming on Win32, nor Grayson's Tkinter have anything on CGI. I don't have any idea regarding (Altom and Chapman)'s book or Ivan's book (Ivan?). In contrast, i've been motivated with questions like yours which pop up every now and then to create a separate chapter entrily devoted to CGI pro- gramming and in it, to provide an example that starts out simple and builds to something a little more complex. there will be lots of screen captures too so that you can see what's going on. finally, there will be a more "advanced" section towards the end which does the complicated stuff that everyone wants to do, like cookies, multivalued fields, and file uploads with multipart data. sorry that the book isn't out yet... trying to get the weeds out of it right NOW! ;-) hope this helps!! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, TBP Summer/Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html Python Books: http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From bwisti@hotmail.com Tue Aug 1 20:03:12 2000 From: bwisti@hotmail.com (Brian Wisti) Date: Tue, 01 Aug 2000 12:03:12 PDT Subject: Tangent to Re: [Tutor] CGI and Python Message-ID: >In contrast, i've been motivated with questions like yours which pop up >every now and then to create a separate chapter entrily devoted to CGI pro- >gramming and in it, to provide an example that starts out simple and builds >to something a little more complex. there will be lots of screen captures >too so that you can see what's going on. finally, there will be a more >"advanced" section towards the end which does the complicated stuff that >everyone wants to do, like cookies, multivalued fields, and file uploads >with multipart data. sorry that the book isn't out yet... trying to get >the weeds out of it right NOW! ;-) > I'm looking forward to seeing the book! Got a question, that is almost relevant to the thread. Does anybody know why cookie support isn't built in to the cgi module? I had to dig around to find Cookie.py, which (excellent module that it is) should be in the cgi package somewhere. Just a random thought from the middle of my workday... Later, Brian Wisti ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From wesc@alpha.ece.ucsb.edu Tue Aug 1 20:14:06 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Tue, 1 Aug 2000 12:14:06 -0700 (PDT) Subject: Tangent to Re: [Tutor] CGI and Python Message-ID: <200008011914.MAA11206@alpha.ece.ucsb.edu> > From: "Brian Wisti" > Date: Tue, 01 Aug 2000 12:03:12 PDT > > I'm looking forward to seeing the book! thanks. so am i as well as my spouse! ;-) > > Got a question, that is almost relevant to the thread. Does anybody know > why cookie support isn't built in to the cgi module? I had to dig around to > find Cookie.py, which (excellent module that it is) should be in the cgi > package somewhere. that's a good question... it sounds like it *should* be in there. which Cookie.py module? i thought there was more than one. the one i've seen is comprehensive (this may be a reason why it's not in the cgi module... to keep things small) -- and slightly buggy -- but it's 3 years old so i assume those bugs have been worked out. the other reason why it may not be in there is that not everyone uses cookies in their CGI apps. -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, TBP Summer/Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html Python Books: http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From bwisti@hotmail.com Tue Aug 1 20:27:55 2000 From: bwisti@hotmail.com (Brian Wisti) Date: Tue, 01 Aug 2000 12:27:55 PDT Subject: [Tutor] which Cookie.py (the tangent lives...) Message-ID: >that's a good question... it sounds like it *should* be in there. >which Cookie.py module? i thought there was more than one. the >one i've seen is comprehensive (this may be a reason why it's >not in the cgi module... to keep things small) -- and slightly buggy >-- but it's 3 years old so i assume those bugs have been worked out. >the other reason why it may not be in there is that not everyone uses >cookies in their CGI apps. > >-wesley > I can't quite remember where I downloaded it, so how's this excerpt from the module itself? # Copyright (C) 1998 GTE Internetworking # Author: Timothy O'Malley # $Id: Cookie.py,v 2.15 1999/01/07 21:48:33 timo Exp $ # by Timothy O'Malley As yet another tangent, if this is the buggy one, could somebody point me to a somewhat fresher or more stable one? I'm still new enough to Python that I can't quite make out when a program error belongs to me or a module. Then again, I've programmed long enough to know that the module is generally in better condition than my code ;) Later, Brian Wisti ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From cliffu@earthlink.net Wed Aug 2 03:53:18 2000 From: cliffu@earthlink.net (Cliff Urr) Date: Tue, 1 Aug 2000 22:53:18 -0400 Subject: [Tutor] CGI and Python In-Reply-To: <00080111465703.22301@wolfkin.freedomspace.net> Message-ID: <398754DE.29759.4D0EC6@localhost> The URL below points to an article, "Five Minutes to a Python CGI," in the way cool online magazine, "Web Review," July 7, 2000 issue. http://webreview.com/pub/2000/07/07/feature/index02.html?wwwrrr_20 000707.t From kjohnston@rcsi.ie Wed Aug 2 09:43:34 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Wed, 2 Aug 2000 09:43:34 +0100 Subject: [Tutor] RE: CGI and Python Message-ID: <9921C1171939D3119D860090278AECA2DEC618@EXCHANGE> Thank you all...I now at least have some material to start with...you are right Wesley the library reference is a bit too techhie for a beginner like me, I am looking forward to your book...any chance you could speed it up?? *grin* Ivan's book, 'Teach Yourself Python in 24 Hours' which has got me as far as I am (thanks Ivan :) ) has a small section of about 7 pages describing an excellent example of a simple registration form. Unfortunately this does not cover the deeper aspects of CGI that I need to know about. :( but perhaps I am getting ahead of myself *cringe*. On that note...I shall await Wesley's' book with bated breath and in the meantime exploit your good selves for any advice or pointers I need along the way! Until the next question...happy programming! Kate From dlaskey@laskeycpa.com Wed Aug 2 17:54:46 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Wed, 2 Aug 2000 12:54:46 -0400 Subject: [Tutor] Saving file changes to output Message-ID: <01BFFC81.140DE960@DAN> I've been struggling for the last couple of days on this problem. So it is not as if I am asking the group to do my homework for me. Again, I'm a newbie. I've been studing hard. Maybe I'm just learning impaired. Please be kind. The "data_file" looks like this: 33.04,123196,12,421020,RVN# 179-Ernest Lonard,12528.7 33.04,123196,12,421020,RVN# 196-Hector Gale,2599.7 33.04,123196,12,421230,RVN# 249-Richard George,2300 33.04,123196,12,420000,Total Sales Journal,-17428.4 import sys import string in_file = open("data_file","r") out_file = open("junk2.txt","w") for line in in_file.readlines(): x = string.split(line,',') # read each line of file and split at each "," f1 = x[4] # pull out the fifth position 0,1,2,3,4 of each line f2 = '"' + f1 + '"' # put double quotes " " around this data f3 = x[0]+","+x[1]+","+x[2]+","+x[3]+","+f2+","+x[5] # print f3 # rebuild the file using the new position [4] with double quotes out_file.write(line,f3) out_file.close() in_file.close() #Traceback (innermost last): # File "today.py", line 15, in ? # out_file.write(line,f3) #TypeError: read-only buffer, tuple My objective is to write the changes I made to the data to my out_file. When I put a print statement after the f3 the file looks fine. I just can't get it to print to the junk2.txt file properly. Please help ole kind ones. Dan ----------------------------------------------------------------------------------------------- | Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.--------231-723-8305 / Fax 231-723-6097 | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 ----------------------------------------------------------------------------------------------- From scarblac@pino.selwerd.nl Wed Aug 2 18:14:08 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 2 Aug 2000 19:14:08 +0200 Subject: [Tutor] Saving file changes to output In-Reply-To: <01BFFC81.140DE960@DAN>; from dlaskey@laskeycpa.com on Wed, Aug 02, 2000 at 12:54:46PM -0400 References: <01BFFC81.140DE960@DAN> Message-ID: <20000802191408.A12361@pino.selwerd.nl> On Wed, Aug 02, 2000 at 12:54:46PM -0400, Daniel D. Laskey, CPA wrote: > # rebuild the file using the new position [4] with double quotes > out_file.write(line,f3) Instead of this, put: out_file.write(f3) > out_file.close() > in_file.close() > #Traceback (innermost last): > # File "today.py", line 15, in ? > # out_file.write(line,f3) > #TypeError: read-only buffer, tuple > > My objective is to write the changes I made to the data to my out_file. When I > put a print statement after the f3 the file looks fine. I just can't get it to print > to the junk2.txt file properly. Just use out_file.write(f3), not (line,f3). That writes the line "f3" to the file. You need to add a "\n" to f3 too, to go to the next line. If you write write(line,f3), Python thinks you send the function a tuple, and it doesn't work. -- Remco Gerlich, scarblac@pino.selwerd.nl From dlaskey@laskeycpa.com Wed Aug 2 18:58:48 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Wed, 2 Aug 2000 13:58:48 -0400 Subject: [Tutor] Saving file changes to output Message-ID: <01BFFC89.D0B97F40@DAN> Remco Gerlich [scarblac@pino.selwerd.nl] Remco: It works! My many "thank you"s to you Daniel Yoo [dyoo@hkn.EECS.Berkeley.EDU] and Tim Condit [timc@ans.net] for your mentoring. Thanks again to all of you. Dan ----------------------------------------------------------------------------------------------- | Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.--------231-723-8305 / Fax 231-723-6097 | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 ----------------------------------------------------------------------------------------------- From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 2 19:14:59 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 2 Aug 2000 11:14:59 -0700 (PDT) Subject: [Tutor] Saving file changes to output In-Reply-To: <01BFFC81.140DE960@DAN> Message-ID: On Wed, 2 Aug 2000, Daniel D. Laskey, CPA wrote: > I've been struggling for the last couple of days on this problem. > So it is not as if I am asking the group to do my homework for > me. Again, I'm a newbie. I've been studing hard. Maybe I'm just > learning impaired. Please be kind. Don't apologize; we're not high priests or another authority figure! Don't worry about it --- we're just learning here. Remco Gerlich has already answered your question on that write() call. I just wanted to look at a part of your program, to see if we can shorten it a little: x = string.split(line,',') # read each line of file and split at each "," f1 = x[4] # pull out the fifth position 0,1,2,3,4 of each line f2 = '"' + f1 + '"' # put double quotes " " around this data f3 = x[0]+","+x[1]+","+x[2]+","+x[3]+","+f2+","+x[5] # print f3 # rebuild the file using the new position [4] with double quotes out_file.write(line,f3) There's a slightly shorter way of writing this. Since you're quoting the 5th element (x[4]), you can say: x = string.split(line,',') x[4] = '"' + x[4] + '"' # put double quotes around x[4] f3 = x[0]+","+x[1]+","+x[2]+","+x[3]+","+x[4]+","+x[5] Of course, this can be improved on, but it's already a little better. The reason this is nicer is because we can take advantage of the regularity in the last statement --- we're just rejoining all the elements in that list back together. Appropriately, we can use the string.join() command, which works very closely with splitting. The newest revision looks like this: x = string.split(line,',') x[4] = '"' + x[4] + '"' # quote x[4] f3 = string.join(x, ",") which is a little easier to read. Commenting is often a virtue, but I think you went a little wild on that part. *grin* Hope this helps! From da_woym@hotmail.com Wed Aug 2 21:05:55 2000 From: da_woym@hotmail.com (Jacob Williams) Date: Wed, 02 Aug 2000 20:05:55 GMT Subject: [Tutor] Directory permissions Message-ID: Hello, is there a way to change a dir's read only function to a write only without deleting the folder and it's contents? thanks in advance! ------------------------ | Jacob Williams | | Da_woym@hotmail.com | ------------------------ ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From shaleh@valinux.com Wed Aug 2 21:11:24 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 02 Aug 2000 13:11:24 -0700 (PDT) Subject: [Tutor] Directory permissions In-Reply-To: Message-ID: On 02-Aug-2000 Jacob Williams wrote: > Hello, > > is there a way to change a dir's read only function to a write only without > deleting the folder and it's contents? > thanks in advance! > the answer is: it depends on the OS. in unix there is the chmod call, Windows has directory attributes. That said, have only write access makes little sense and may not work on all systems. From bm_smith@hotmail.com Thu Aug 3 00:46:58 2000 From: bm_smith@hotmail.com (Ben Smith) Date: Wed, 02 Aug 2000 23:46:58 GMT Subject: [Tutor] Idle won't run in Win NT 4 Message-ID: Hi all. Help! I'm a total python newbie, and I'm having trouble getting Idle to run on my NT box. I downloaded Idle 0.5, thinking it would take care of the problem, but it did not. Every time I hit the shortcut or double click the .pyw, my cursor gets a small hourglass for about 10 seconds and then nothing happens. I can't find the process running anywhere. Any suggestions? I've reinstalled twice now with no luck. Thanks a bunch Ben Smith ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 3 07:15:42 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 2 Aug 2000 23:15:42 -0700 (PDT) Subject: [Tutor] Idle won't run in Win NT 4 In-Reply-To: Message-ID: On Wed, 2 Aug 2000, Ben Smith wrote: > Help! I'm a total python newbie, and I'm having trouble getting Idle to run > on my NT box. I downloaded Idle 0.5, thinking it would take care of the > problem, but it did not. Every time I hit the shortcut or double click the > .pyw, my cursor gets a small hourglass for about 10 seconds and then nothing > happens. I can't find the process running anywhere. > > Any suggestions? I've reinstalled twice now with no luck. Hmm... since you've reinstalled already, I'm assuming it's not a problem with Python. However, Python comes with Tk/Tcl as its graphics library, and since IDLE depends on it, problems most likely are coming from there. Try this: ### import Tkinter ### and if you start seeing weird error messages, the problem has to do with those graphics libraries. Sorry this isn't more definite. Email us back with your results at tutor@python.org, and we'll have a better idea of what's happening. From brett42@konaboy.com Fri Aug 4 07:00:18 2000 From: brett42@konaboy.com (Brett) Date: Thu, 03 Aug 2000 20:00:18 -1000 Subject: [Tutor] scripts close window when finished Message-ID: <4.3.2.7.0.20000803195552.00a905f0@mail.turquoise.net> I'm new to python and just started making some simple scripts. I use windows98, and when I run stuff i coded in python a dos window opens and and program goes by too fast for me to read the output. One solution i found was ending them with a 'Z = input('end') line, but this only works when the script gets to the end, and doesnt let me see where a buggy script crashed. What can I do? "Time is an illusion. Lunchtime doubly so." -Hitchhikers Guide to the Galaxy From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 4 09:51:17 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 4 Aug 2000 01:51:17 -0700 (PDT) Subject: [Tutor] scripts close window when finished In-Reply-To: <4.3.2.7.0.20000803195552.00a905f0@mail.turquoise.net> Message-ID: On Thu, 3 Aug 2000, Brett wrote: > I'm new to python and just started making some simple scripts. I use > windows98, and when I run stuff i coded in python a dos window opens and > and program goes by too fast for me to read the output. One solution i > found was ending them with a 'Z = input('end') line, but this only works > when the script gets to the end, and doesnt let me see where a buggy script > crashed. What can I do? This is where the 'try/except' exception handling stuff comes handy. When an exception occurs as a result of an error, it usually causes the system to die with an error message. However, if you've wrapped the offending code with a try/except, you can override the default 'print error and die' behavior: ### try: # some code here that might cause problems or bugginess print 5/0 except: raw_input("Please press enter to continue...") ### Here, I'm just getting it to pause if anything bad happens. Also, since we're just using raw_input/input, we can ignore the return value. Unfortunately, the above doesn't specifically report the exception that occurred. Usually, we'd like more detailed information. To do this, we can use the 'traceback' module, which provides good debugging info: ### try: print 5/0 # or other code that you're writing except: import traceback, sys sys.stderr.write('Error while executing program %s.' % sys.argv[0]) traceback.print_exc(file=sys.stderr) raw_input("Please press enter to continue: ") ### I pillaged the above code from a CGI-tutorial at: http://www.webtechniques.com/archives/1998/02/kuchling/ These error-handling issues occur during CGI programming too, so it's good that you're learning about this. More information on exception handling and that traceback module can be found on these urls: Tutorial section on exception handling: http://www.python.org/doc/current/tut/node10.html Library reference on the 'traceback' module: http://www.python.org/doc/current/lib/module-traceback.html Good luck! From alan.gauld@bt.com Fri Aug 4 11:17:15 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 4 Aug 2000 11:17:15 +0100 Subject: [Tutor] Idle won't run in Win NT 4 Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D273@mbtlipnt02.btlabs.bt.co.uk> > problem, but it did not. Every time I hit the shortcut or > double click the .pyw, my cursor gets a small hourglass for > out 10 seconds and then nothing Try starting a command window(aka DOS Box) and typing C:\python> python tools\idle\idle.py And see if any errors appear. It could be that Python/idle is writing errors to stdout which you can't see. These might give you a clue as to what's going wrong. When you installed idle0.5 did you keep the original version? Is the shortcut pointing at the original or the new version? Alan G. From zuzhang@sarnoff.com Fri Aug 4 19:47:48 2000 From: zuzhang@sarnoff.com (Zuohua Zhang) Date: Fri, 04 Aug 2000 14:47:48 -0400 Subject: [Tutor] what variables are in the memory Message-ID: <398B0FD4.3C580186@sarnoff.com> Dear Sir, How to find out what variable are in the memory? Is there a way to get help info. on functions? Sth like help funcname? Thanks a lot. Zuohua Zhang. From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 4 20:11:12 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 4 Aug 2000 12:11:12 -0700 (PDT) Subject: [Tutor] what variables are in the memory In-Reply-To: <398B0FD4.3C580186@sarnoff.com> Message-ID: On Fri, 4 Aug 2000, Zuohua Zhang wrote: > How to find out what variable are in the memory? > Is there a way to get help info. on functions? Sth like help funcname? If you want to know what variables are available to you, try the vars() command. For example, here's a small interpreter session that shows a somewhat typical example: >>> x = 25 >>> y = "cathedral" >>> z = list("bazaar") >>> vars() {'y': 'cathedral', '__doc__': None, 'z': ['b', 'a', 'z', 'a', 'a', 'r'], 'x': 25, '__name__': '__main__', '__builtins__': } vars(), then, gives you a hash of local variable names. To get all the globals, you'd use globals(). To learn more about these functions, take a look at: http://www.python.org/doc/current/lib/built-in-funcs.html and search under vars() or globals(). About interactive help and documentation: many functions and modules have "documentation" strings. They are named [variable or module].__doc__ and can be printed. For example: ### >>> import string >>> print string.__doc__ Common string manipulations. Public module variables: whitespace -- a string containing all characters considered whitespace lowercase -- a string containing all characters considered lowercase letters uppercase -- a string containing all characters considered uppercase letters letters -- a string containing all characters considered letters digits -- a string containing all characters considered decimal digits hexdigits -- a string containing all characters considered hexadecimal digits octdigits -- a string containing all characters considered octal digits ### Not everything does though. I think the Python designers are planning to add a doc() function in the 2.0 series soon, which should make things easier. Also, you can always call dir(object) to find out some of the attributes of an object; this comes in handy: >>> f = open("foo.txt") >>> dir(f) ['close', 'closed', 'fileno', 'flush', 'isatty', 'mode', 'name', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines'] Hope this is what you're looking for! From wesc@alpha.ece.ucsb.edu Fri Aug 4 20:29:32 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Fri, 4 Aug 2000 12:29:32 -0700 (PDT) Subject: [Tutor] what variables are in the memory Message-ID: <200008041929.MAA04491@alpha.ece.ucsb.edu> > From: Zuohua Zhang > Date: Fri, 04 Aug 2000 14:47:48 -0400 > > How to find out what variable are in the memory? > Is there a way to get help info. on functions? Sth like help funcname? zuo-hua, ni hao! zhi ge wenti hen hao! let's take a look at both your questions: 1. to find out what variables are currently in memory, just use the dir() built-in function: >>> foo = 'xyz' >>> bar = 42 >>> dir() ['__builtins__', '__doc__', '__name__', 'bar', 'foo'] notice that you get *your* variable names as well as the default special variables __builtins__, __doc__, and __name__. you can also get a dictionary of both the variables' names *and* values, you can use globals() (or locals() from inside a function): >>> globals() {'__doc__': None, 'bar': 42, 'foo': 'xyz', '__name__': '__main__', '__builtins__': } there is another built-in function called vars() which without argu- ments works just like locals() (and in the global namespace like globals()), but it can also give information regarding modules which have been imported or class instances, i.e. vars(string). neither locals() nor globals() take arguments. dir() can also take a module or class instance and just give you the list of names (as vars(), locals(), and globals() return dictionaries). 2. yes, you can get help information for functions... with a syntax very similar to "help funcname". you will notice above that there is a built-in __doc__ variable. that is the name of the documentation variable for modules (.py files), functions, and classes. Here is an example with the string.find() function: >>> import string >>> print string.find.__doc__ find(s, sub [,start [,end]]) -> in Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. - - - - - - Now you have to remember that not every internal function has been documented yet. As a programmer, you are responsible for the documentation of your own code (modules, functions, and classes). The first unassigned string in such pieces code will be put in the __doc__ variable: >>> def mult(x, y=3.14): ... '''mult(x,y=3.14) -> float ... mult() takes a pair of numbers (y defaults to 3.14 if ... only one argument passed in) and returns their product.''' ... return x * y ... >>> mult(4) 12.56 >>> mult(4.1) 12.873999999999999 >>> mult(4., 2.) 8.0 >>> mult(4, 2) 8 >>> print mult.__doc__ mult(x,y=3.14) -> float mult() takes a pair of numbers (y defaults to 3.14 if only one argument passed in) and returns their product. hope this helps!! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, TBP Summer/Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html Python Books: http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From charlie@intelligenesis.net Fri Aug 4 20:37:36 2000 From: charlie@intelligenesis.net (Charlie Derr) Date: Fri, 4 Aug 2000 15:37:36 -0400 Subject: [Tutor] what variables are in the memory In-Reply-To: <398B0FD4.3C580186@sarnoff.com> Message-ID: |-----Original Message----- |From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of |Zuohua Zhang |Sent: Friday, August 04, 2000 2:48 PM |To: tutor@python.org |Subject: [Tutor] what variables are in the memory | | |Dear Sir, |How to find out what variable are in the memory? if i understand you correctly the following will work: >>>dir() though that will give you all namespace objects (functions, etc...) - not just variables |Is there a way to get help info. on functions? Sth like help funcname? I think your best bet is to view the html documentation -- i find mine in C:\Python\Doc\ -- depending on your platform (and installation directory), you should be able to find it in a similar subdirectory. Also, it's available on-line http://www.python.org/doc/current/. Use the module index to locate the function you are interested in. good luck, ~c | |Thanks a lot. |Zuohua Zhang. | | |_______________________________________________ |Tutor maillist - Tutor@python.org |http://www.python.org/mailman/listinfo/tutor | From Steven Gilmore" Hi, I have downloaded and installed Apache v1.3 for Win 32 on Windows 98 (for testing only I know, I know I'm asking for it). The interpreter is in my path I also added .py in the httpd.conf like so AddHandler cgi-script .cgi .py got a CGI script from a python CGI tutorial (can't remember which). It's just a simple hello world as usual. error page 500 Internal server error from Apache I've never Apache before or CGI in Python or at all so I probably missed something. Can you helpful people help me? I tried to covered everything in this message if you need more just ask. Thanks Steven Gilmore From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 6 02:43:27 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sat, 5 Aug 2000 18:43:27 -0700 (PDT) Subject: [Tutor] Python CGI and Apache In-Reply-To: <004501bffe94$650b0860$2472f4d1@srgilmor> Message-ID: > I have downloaded and installed Apache v1.3 for Win 32 on Windows 98 (for > testing only I know, I know I'm asking for it). The interpreter is in my > path I also added .py in the httpd.conf like so > > AddHandler cgi-script .cgi .py Most likely, you'll also need to allow CGI's to be accessible from user directories too. By default, CGI's can only run in a cgi-bin directory for security's sake. Try searching for an "Options" section in the httpd.conf. From brett42@konaboy.com Sun Aug 6 07:35:30 2000 From: brett42@konaboy.com (Brett) Date: Sat, 05 Aug 2000 20:35:30 -1000 Subject: [Tutor] finding strings in other strings In-Reply-To: <20000805234237.75EB71CDEF@dinsdale.python.org> Message-ID: <4.3.2.7.0.20000805201812.00a91820@mail.turquoise.net> I was making a little program to rename mp3 files, but didnt want it to effect other files in the same directory. I tried using something like this to have the program only effect mp3 files: files = os.listdir(os.curdir) for x in files: if 'mp3' in x: After having the program screw up a couple of times I checked out the documentation and found out that the first term (in my attempt 'mp3') must have a length of 1 if the second term is a string. I fixed it in this case by using , but i realized this wouldnt work if i wanted to locate something like this in the middle of some strings, like if some members of a list had a two or three character long string in them and I wanted to do stuff only to them. So anyway, is there a way to determine if a string is part of a longer string? Hope you can understand what i'm talking about, had a little trouble figuring out what I wanted to say. "One World, one Web, one Program" - Microsoft promotional ad "Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler From wolfkin@freedomspace.net Sun Aug 6 08:54:55 2000 From: wolfkin@freedomspace.net (Randall Randall) Date: Sun, 06 Aug 2000 03:54:55 -0400 (EDT) Subject: [Tutor] finding strings in other strings In-Reply-To: <4.3.2.7.0.20000805201812.00a91820@mail.turquoise.net> Message-ID: On 06-Aug-2000 Brett wrote: > I was making a little program to rename mp3 files, but didnt want it to > effect other files in the same directory. I tried using something like > this to have the program only effect mp3 files: > > files = os.listdir(os.curdir) > for x in files: > if 'mp3' in x: > > After having the program screw up a couple of times I checked out the > documentation and found out that the first term (in my attempt 'mp3') must > have a length of 1 if the second term is a string. I fixed it in this case > by using , but i realized this wouldnt work if i wanted > to locate something like this in the middle of some strings, like if some > members of a list had a two or three character long string in them and I > wanted to do stuff only to them. So anyway, is there a way to determine if > a string is part of a longer string? Hope you can understand what i'm > talking about, had a little trouble figuring out what I wanted to say. I believe "if string.find('mp3', x) != -1:" will do what you want. -- Randall (wolfkin@freedomspace.net). Crypto key: www.freedomspace.net/~wolfkin/crypto.text On a visible but distant shore, a new image of man; The shape of his own future, now in his own hands.-- Johnny Clegg. From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 6 08:42:04 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 6 Aug 2000 00:42:04 -0700 (PDT) Subject: [Tutor] finding strings in other strings In-Reply-To: <4.3.2.7.0.20000805201812.00a91820@mail.turquoise.net> Message-ID: On Sat, 5 Aug 2000, Brett wrote: > I was making a little program to rename mp3 files, but didnt want it to > effect other files in the same directory. I tried using something like > this to have the program only effect mp3 files: > > files = os.listdir(os.curdir) > for x in files: > if 'mp3' in x: wolfkin@freedomspace.net already mentioned using string.find() to search for substrings. Another alternative to string searching is to use the glob() function within the 'glob' module, which will grab the filenames of all .mp3 files for you. For example: ### >>> from glob import glob >>> glob('*.tex') ['foo.tex', 'abstractalgebra.tex'] ### The 'glob' module is documented here: http://www.python.org/doc/current/lib/module-glob.html From djansen@pobox.com Sun Aug 6 09:41:26 2000 From: djansen@pobox.com (David Jansen) Date: Sun, 6 Aug 2000 17:41:26 +0900 Subject: [Tutor] Tkinter GUI w/o DOS window Message-ID: I went through Alan Gauld's tutorial a few weeks back and the last section shows us a Tkinter GUI for a simple word counting program. It works fine but everytime I run the program, an empty DOS window pops up in the background... Is there a way to fire up the GUI by itself? I realize I could run it from Pythonwin or IDLE but that wouldn't really solve anything. I know this is an OS specific problem but maybe someone else is still using Windows? Thank you, David Jansen from Tkinter import * import document #########################Class Definitions############################### class GrammarApp(Frame): def __init__(self): Frame.__init__(self) self.type = 2 #create variable with default value self.buildUI() def buildUI(self): # First create the application window with title fApp = Frame(0) fApp.wm_title = "Grammar checker" #Now the file information: File name and type fFile = Frame(fApp) Label(fFile, text = "Filename: ").pack(side = "left") self.eName = Entry(fFile) self.eName.insert(INSERT, "test.htm") self.eName.pack(side = "left", padx = 5) # to keep the radio buttons lined up with the # name we need another frame fType = Frame(fFile, borderwidth = 1, relief = SUNKEN) self.rText = Radiobutton(fType, text = "TEXT", variable = self.type, \ value = 2, command = self.doText) self.rText.pack(side = TOP) self.rHTML = Radiobutton(fType, text = "HTML", variable = self.type, \ value = 1, command = self.doHTML) self.rHTML.pack(side = TOP) # make text the default selection self.rText.select() fType.pack(side = "right", padx = 3) fFile.pack(side = "top", fill = X) # the text box holds the output, pad it to give a border self.txtBox = Text(fApp, width = 60, height = 10) self.txtBox.pack(side = TOP, padx = 3, pady = 3) # finally put some command buttons on to do the real work fButts = Frame(fApp) self.bAnal = Button(fButts, text = "Analyze", command = self.AnalyzeEvent) self.bAnal.pack(side = LEFT, anchor = W, padx = 50, pady = 2) self.bReset = Button(fButts, text = "Reset", command = self.doReset) self.bReset.pack(side = LEFT, padx = 10) self.bQuit = Button(fButts, text = "Quit", command = self.doQuitEvent) self.bQuit.pack(side = RIGHT, anchor = E, padx = 50, pady = 2) fButts.pack(side = BOTTOM, fill = X) fApp.pack() ###############Event handling methods################### # time to die... def doQuitEvent(self): import sys sys.exit() # restore default settings def doReset(self): self.txtBox.delete(1.0, END) self.rText.select() # set radio values def doText(self): self.type = 2 def doHTML(self): self.type = 1 # Create the appropriate document type and analyze it # then display the results in the form def AnalyzeEvent(self): filename = self.eName.get() if filename == "": self.txtBox.insert(END, "\nNo filename provided!\n") return if self.type == 2: doc = document.TextDocument(filename) else: doc = document.HTMLDocument(filename) self.txtBox.insert(END, "\nAnalyzing...\n") doc.Analyze() str = doc.format % (filename, doc.c_paragraph, doc.c_line, doc.c_sentence, doc.c_clause, doc.c_words) self.txtBox.insert(END, str) myApp = GrammarApp() myApp.mainloop() From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 6 09:49:05 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 6 Aug 2000 01:49:05 -0700 (PDT) Subject: [Tutor] Tkinter GUI w/o DOS window In-Reply-To: Message-ID: On Sun, 6 Aug 2000, David Jansen wrote: > I went through Alan Gauld's tutorial a few weeks back and the last > section shows us a Tkinter GUI for a simple word counting program. It > works fine but everytime I run the program, an empty DOS window pops > up in the background... Is there a way to fire up the GUI by itself? I > realize I could run it from Pythonwin or IDLE but that wouldn't really > solve anything. I know this is an OS specific problem but maybe > someone else is still using Windows? Good evening! Let's see, in this case, you'll want to use pythonw.exe. pythonw is a Windows-specific Python exectuable that's meant to run gui-based programs --- it doesn't bring up a console window. Take a look at: http://linuxboy.net/python/006/ for details on this. From what I saw on python.faqts, there might be some issues with pythonw (since you have no console, this might make debugging more difficult), so you might want to take a look at faqts to see how people deal with these issues. http://www.faqts.com/knowledge-base/index.phtml/fid/199/lang/ Good luck! From wprotoman@wbinterline.com.br Sun Aug 6 14:49:58 2000 From: wprotoman@wbinterline.com.br (Leonardo Boiko) Date: Sun, 6 Aug 2000 10:49:58 -0300 Subject: [Tutor] Another newbie question Message-ID: <002401bfffad$384c1ac0$248ecbc8@default> Hello everyone, for those who don't know, I'm a teenager and a very newbie to program thing. I'm reading Guido's tuturial (I'm in chapter 9... it's hard :^/ ) but I already made my first program (a tool for AD&D roleplaying game). Well, I want to send it to some friends, so I was wondering... how do I turn a .py or .pyc file in a .exe (Win/32 app)? (K, I dislike Winblows too, but I don't have CDROM so I cannot install my Linux CD... for now...) Note: If someone already answered this question... sorry. I'm reading veery carefully the list files (trying to understand everything), so I'll find it sooner or later. -Leo The certain of the certain makes the crazy man yell From Moshe Zadka Sun Aug 6 14:52:54 2000 From: Moshe Zadka (Moshe Zadka) Date: Sun, 6 Aug 2000 16:52:54 +0300 (IDT) Subject: [Tutor] Another newbie question In-Reply-To: <002401bfffad$384c1ac0$248ecbc8@default> Message-ID: On Sun, 6 Aug 2000, Leonardo Boiko wrote: > Hello everyone, for those who don't know, I'm a teenager and a very newbie > to program thing. I'm reading Guido's tuturial (I'm in chapter 9... it's > hard :^/ ) but I already made my first program (a tool for AD&D roleplaying > game). Well, I want to send it to some friends, so I was wondering... how do > I turn a .py or .pyc file in a .exe (Win/32 app)? Look for Gordon McMillans installer -- search for it from http://www.mcmillan-inc.com -- Moshe Zadka There is no IGLU cabal. http://advogato.org/person/moshez From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 7 04:06:03 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 6 Aug 2000 20:06:03 -0700 (PDT) Subject: [Tutor] Another newbie question In-Reply-To: <002401bfffad$384c1ac0$248ecbc8@default> Message-ID: On Sun, 6 Aug 2000, Leonardo Boiko wrote: > Hello everyone, for those who don't know, I'm a teenager and a very newbie > to program thing. I'm reading Guido's tuturial (I'm in chapter 9... it's > hard :^/ ) but I already made my first program (a tool for AD&D roleplaying Cool! About OOP stuff... hmmm... There's an alternative tutorial that might be a little gentler: Alan Gauld's "Learning to Program" http://members.xoom.com/alan_gauld/tutor/tutindex.htm From alan.gauld@bt.com Mon Aug 7 10:59:20 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 7 Aug 2000 10:59:20 +0100 Subject: [Tutor] scripts close window when finished Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D27A@mbtlipnt02.btlabs.bt.co.uk> > I'm new to python and just started making some simple > scripts. I use windows98, and when I run stuff i coded in > python a dos window opens and program goes by too fast Try starting a DOS window(Start|Programs|MS DOS or Start|Run and type command). Then CD to the directory/folder containing your script and type: C:\myprogs> python myprog.py You should see your program output on screen including any error output. If thats still not catching it try redirecting output to a file: C:\myprogs> python myprog.py > logfile.txt Then view the logfile using notepad or DOS edit. HTH, Alan G. PS. This should definitely be in the FAQ if it isn't already! From kjohnston@rcsi.ie Tue Aug 8 14:12:50 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Tue, 8 Aug 2000 14:12:50 +0100 Subject: [Tutor] Applets not working on Grail :-( Message-ID: <9921C1171939D3119D860090278AECA2DEC62A@EXCHANGE> Dear All, Thank you for your previous help...but I am afraid that I have an additional problem...:( I have installed Grail on Windows. It seemed to work well when I went to the example Grail Applet Demo Collection at http://grail.cnri.reston.va.us/grail/demo/ . This continued to be the case when I saved the applet source code to my own computer along with the corresponding html source code, and then opened this html file on my computer the applets still ran. However, if I alter the applet source code in any way save this change, the applet no longer works, if I then undo the changes and save the file the applet continues to no longer work. I get the following error: - File "<>", line 1 from Tkinter import * ^ SyntaxError: invalid syntax What am I doing wrong? Or what do I have to do to run an applet...Why will saving the file after changing it back to its original code not allow the applet to work? If anyone can please help me on this matter I would be most grateful. Signing off as a perplexed pythonian, kate From elcultural.com@python.org Wed Aug 9 04:31:17 2000 From: elcultural.com@python.org (elcultural.com@python.org) Date: Wed, 9 Aug 2000 05:31:17 +0200 Subject: [Tutor] Actualidad Cultural Message-ID: <28003200083933117750> Actualidad Cultural <body> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td width="10" height="7" valign="top"></td> <td height="28" colspan="2" rowspan="2" valign="middle"><img SRC="http://www.elcultural.com/correo/img/elcultural.jpg" height=13 width=123></td> <td width="78" height="7" valign="top"></td> <td width="5" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> <td width="6" height="7" valign="top"></td> <td width="150" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> <td width="173" height="7" valign="top"></td> </tr> <tr> <td width="10" height="21" valign="top"></td> <td width="78" height="21" valign="top"></td> <td width="5" height="21" valign="top"></td> <td width="9" height="21" valign="top"></td> <td width="6" height="21" valign="top"></td> <td width="150" height="21" valign="top"></td> <td width="9" height="21" valign="top"></td> <td width="9" height="21" valign="top"></td> <td width="173" height="652" rowspan="15" valign="top" bgcolor="#FFFFCC"> <center> <p><a href="http://www.elcultural.com"><img SRC="http://www.elcultural.com/correo/img/logo2.gif" BORDER=0 height=56 width=68></a></p> <p><b><font face="Arial,Helvetica"><font size=-2>Otros Titulares</font></font></b> </p> </center> <p align="left"><font size=-2><font face="Wingdings"> &nbsp;n <font face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/webdelasemana/20000807.asp">Letra lia La revista en Internet para los escritores latinoamericanos</a></font></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n <font face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/bflamenco/entrevistas03.htm">Antonio el Pipa: "Mi meta es morirme bailando"</a></font></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font></font> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/reportaje/230700/1.asp">De sur a sur: creadores africanos vinculados a España</a></font> <center> <p> <p> <p> <p> <p> <p> <p> <br> <table width="142" border="0"> <tr bgcolor="#CCCC99"> <td> <div align="center"><font size="1" face="Arial, Helvetica, sans-serif"><b><a href="http://www.elcultural.com/">EVENTOS RECOMENDADOS</a></b></font></div> </td> </tr> <tr bgcolor="#CCCC99"> <td height="2"> <div align="center"><font size="1" face="Arial, Helvetica, sans-serif"><b><a href="http://www.elcultural.com/contenidos/arquitec/20000720/default.asp">AR QUITECTURA</a></b></font></div> </td> </tr> <tr bgcolor="#CCCC99"> <td height="2"> <div align="center"><font face="Arial, Helvetica, sans-serif" size="1"><b><a href="../contenidos/webdelasemana/20000807.asp">WEB DE LA SEMANA</a></b></font></div> </td> </tr> </table> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">Portada</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Noticias culturales</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/dinamica/index.html">Versi&oacute;n multimedia</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/criticas/default.asp">Cr&iacute;tica de eventos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/cds/default.asp">Rese&ntilde;as de discos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/libros/default.asp">Rese&ntilde;as de libros</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Cartelera de Andaluc&iacute;a</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/eva/index.html">Espacio Virtual de las Artes</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/andalucia/default.asp">Andaluc&iacute;a Cultural</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/entrevista/default.asp">Entrevist as</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/reportaje/default.asp">Reportajes </a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/evento/default.asp">Eventos</a></ font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/denominacion/default.asp">Denomin aci&oacute;n de Origen</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/tema/default.asp">Temas de Actualidad</a></font></font> </center> <img width="144" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> </tr> <tr> <td width="10" height="22" valign="top"></td> <td height="22" colspan="8" valign="top" bgcolor="#FFFFCC"> <table width="100%" border="0" mm_noconvert="TRUE"> <tr> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/cine.asp"><font color="#000099"><b>cine</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/arte.asp"><b><font color="#000099">arte</font></b></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/escena.asp"><font color="#000099"><b>escena</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/musica.asp"><font color="#000099"><b>m&uacute;sica</b></font></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/literatura.asp"><b><font color="#000099">literatura</font></b></a></font></td> </tr> </table></td> <td width="9" height="22" valign="top"></td> </tr> <tr> <td width="10" height="7" valign="top"></td> <td width="4" height="7" valign="top"></td> <td width="121" height="7" valign="top"></td> <td width="78" height="7" valign="top"></td> <td width="5" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> <td width="6" height="7" valign="top"></td> <td width="150" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> <td width="9" height="7" valign="top"></td> </tr> <tr> <td width="10" height="26" valign="top"></td> <td height="26" colspan="8" valign="top"><b><font face="Arial,Helvetica" size="4">Arte entre rejas.</font></b></td> <td width="9" height="26" valign="top"></td> </tr> <tr> <td width="10" height="8" valign="top"></td> <td width="4" height="8" valign="top"></td> <td width="121" height="8" valign="top"></td> <td width="78" height="8" valign="top"></td> <td width="5" height="8" valign="top"></td> <td width="9" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="150" height="96" rowspan="2" valign="top"> <img src="http://www.elcultural.com/correo/img/libportada.jpg" width="150" height="79"></td> <td width="9" height="8" valign="top"></td> <td width="9" height="8" valign="top"></td> </tr> <tr> <td width="10" height="76" valign="top"></td> <td width="4" height="76" valign="top"></td> <td height="76" colspan="3" valign="middle"> <div align="left"> <p><font size="3" face="Arial, Helvetica, sans-serif"><b> </b></font><font size="1" face="Arial, Helvetica, sans-serif">Diversas prisiones espa&ntilde;olas dan luz a su lado oscuro con el fomento de la expresi&oacute;n art&iacute;stica: flamenco, cartelismo, artes pl&aacute;sticas, teatro.</font></p> <p><font size="1" face="Arial, Helvetica, sans-serif"> <a href="../contenidos/reportaje/070800/1.asp">M&aacute;s Informaci&oacute;n</a></font></p> </div> </td> <td width="9" height="76" valign="top"></td> <td width="6" height="76" valign="top"></td> <td width="9" height="76" valign="top"></td> <td width="9" height="76" valign="top"></td> </tr> <tr> <td width="10" height="27" valign="top"></td> <td width="4" height="27" valign="top"></td> <td height="27" colspan="7" valign="top"> <hr WIDTH="350"> </td> <td width="9" height="27" valign="top"></td> </tr> <tr> <td width="10" height="163" valign="top"></td> <td height="163" colspan="8" valign="top"><font size="3" face="Arial, Helvetica, sans-serif"><b>Danza contempor&aacute;nea: la hermana pobre de las artes esc&eacute;nicas andaluzas.</b></font><font size="1" face="Arial, Helvetica, sans-serif"><br> <a href="http://www.elcultural.com/contenidos/reportaje/230700/1.asp"><img src="http://www.elcultural.com/correo/img/20000727_danza3.jpg" width="148" height="105" border="0" align="left"></a><br> Hasta 1986 Andalucía vivía ajena a la danza contemporánea. Quince años después aún queda mucho por hacer, pero al menos se ha creado una pequeña infraestructura que permite la existencia de varias compañías independientes y se consolida la actividad formativa de instuciones públicas o iniciativas privadas como Endanza (Sevilla) o La Nave (Málaga) <a href="../contenidos/tema/270700/1.asp">M&aacute;s Informaci&oacute;n</a></font> </td> <td width="9" height="163" valign="top"></td> </tr> <tr> <td width="10" height="25" valign="top"></td> <td height="25" colspan="8" valign="top"> <hr WIDTH="100%"> </td> <td width="9" height="25" valign="top"></td> </tr> <tr> <td width="10" height="5" valign="top"></td> <td height="35" colspan="3" rowspan="2" valign="top"><font face="Arial,Helvetica"><font size=-1>Mirada atr&aacute;s<br> </font></font><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/matras/040800/1.asp">Jos&eacute; Guerrero, pintor</a></font></td> <td width="5" height="5" valign="top"></td> <td width="9" height="5" valign="top"></td> <td width="6" height="5" valign="top"></td> <td width="150" height="5" valign="top"></td> <td width="9" height="5" valign="top"></td> <td width="9" height="5" valign="top"></td> </tr> <tr> <td width="10" height="30" valign="top"></td> <td width="5" height="30" valign="top"></td> <td width="9" height="30" valign="top"></td> <td height="197" colspan="3" rowspan="4" valign="middle"> <center> <p><font size="2" face="Arial, Helvetica, sans-serif"> La <b>XI Bienal de Flamenco</b> <br> en <i>elcultural.com</i></font><font size="2" face="Arial, Helvetica, sans-serif"><br> <a href="http://www.elcultural.com/bflamenco"><img src="http://www.elcultural.com/correo/img/banner90.gif" width="90" height="90" vspace="2" border="0"></a> </font> </p> </center> </td> <td width="9" height="30" valign="top"></td> </tr> <tr> <td width="10" height="42" valign="top"></td> <td height="42" colspan="3" valign="top"><font face="Arial,Helvetica"><font size=-1>Mirada adelante<br> </font></font><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/madelante/210700/1.asp">Rafael García Forcada, pintor</a></font></td> <td width="5" height="42" valign="top"></td> <td width="9" height="42" valign="top"></td> <td width="9" height="42" valign="top"></td> </tr> <tr> <td width="10" height="53" valign="top"></td> <td height="53" colspan="3" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Evento <br> <a href="http://www.elcultural.com/contenidos/evento/020800/1.asp">Alamar 2000, las culturas del mediterráneo en Almería. </a></font></td> <td width="5" height="53" valign="top"></td> <td width="9" height="53" valign="top"></td> <td width="9" height="53" valign="top"></td> </tr> <tr> <td width="10" height="60" valign="top"></td> <td height="60" colspan="4" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Entrevista</font><br> <a href="http://www.elcultural.com/contenidos/entrevista/250700/1.asp"><font face="Arial, Helvetica, sans-serif" size="2">Eduardo Haro Tecglen, "Asisto con horror a la lucha de los poderes por Internet"</font></a><br> </td> <td width="9" height="60" valign="top"></td> <td width="9" height="60" valign="top"></td> </tr> <tr> <td width="10" height="73" valign="top"></td> <td height="73" colspan="8" valign="top"> <center> <p><font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">portada </a>/ <a href="http://www.elcultural.com/dinamica/index.html">contenidos multimedias de la semana</a> / <a href="mailto:redaccion@elcultural.com">sugerencias</a> / <a href="http://www.elcultural.com/quienes/default.asp"><br> sobre elcultural.com</a>/ <a href="http://www.elcultural.com/prensa/default.asp">dossier de prensa</a></font></font> <br> &nbsp;<br> <font face="Arial,Helvetica"><font size=-2>Si no quieres volver a recibir mensajes de elcultural.com pincha <a href="http://www.elcultural.com/suscripciones/baja.asp">aqu&iacute;</a> y b&oacute;rrate de la Secci&oacute;n Contenidos de Actualidad</font></font> </center> </td> <td width="9" height="73" valign="top"></td> </tr> <tr> <td width="10" height="1" valign="top"><img width="10" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="4" height="1" valign="top"><img width="4" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="121" height="1" valign="top"><img width="121" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="78" height="1" valign="top"><img width="78" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="5" height="1" valign="top"><img width="5" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="9" height="1" valign="top"><img width="9" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="6" height="1" valign="top"><img width="6" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="150" height="1" valign="top"><img width="123" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="9" height="1" valign="top"><img width="9" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="9" height="1" valign="top"><img width="9" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> <td width="173" height="1" valign="top"><img width="173" height="1" src="http://www.elcultural.com/correo/img/transparent.gif"></td> </tr> </table> </body> From insyte@emt-p.org Wed Aug 9 05:26:46 2000 From: insyte@emt-p.org (Ben Beuchler) Date: Tue, 8 Aug 2000 23:26:46 -0500 Subject: [Tutor] pdb tutorial? Message-ID: <20000808232644.A4596@emt-p.org> Are there any good tutorials on the use of pdb? I find the module documentation a bit confusing... Gracias, Ben -- Ben Beuchler insyte@bitstream.net MAILER-DAEMON (612) 321-9290 x101 Bitstream Underground www.bitstream.net From fw9189@bristol.ac.uk Wed Aug 9 10:16:32 2000 From: fw9189@bristol.ac.uk (F Wass) Date: Wed, 9 Aug 2000 10:16:32 +0100 (BST) Subject: [Tutor] Python & Matlab Message-ID: Dear all, does anyone know whether it's possible to call a Python script from the Matlab Command Window? Cheers, Fred From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 9 11:39:13 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 9 Aug 2000 03:39:13 -0700 (PDT) Subject: [Tutor] Python & Matlab In-Reply-To: Message-ID: On Wed, 9 Aug 2000, F Wass wrote: > does anyone know whether it's possible to call a > Python script from the Matlab Command Window? According to the matlab reference manual, you can use '!' to execute system commands; if you're on a UNIX system, you'll be able to call unix('command') and be able to get the errorlevel code when the script finishes. You should be able to use both approaches to call anything, including python programs. However, since I don't have matlab, I have no idea if this works. *grin* Take a look here for details: The unix() command: http://www.utexas.edu/math/Matlab/Manual/unix.html The exclamation mark syntax: http://www.utexas.edu/math/Matlab/Manual/Special.html Matlab entries in the Vaults of Parnassus: http://www.vex.net/parnassus/apyllo.py?find=matlab From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 9 18:22:24 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 9 Aug 2000 10:22:24 -0700 (PDT) Subject: [Tutor] Python & Matlab In-Reply-To: Message-ID: On Wed, 9 Aug 2000, F Wass wrote: > I've tried invoking ordinary .exe files and it works > fine. However, when trying to run Python files (.py) > it won't work. > Do you know if there is a way around this, such as > creating something similar to a .exe file? Hmmm... try sending the command python [your_script].py and see if that works for you. To build .exe files, you can use a distributer like: http://www.mcmillan-inc.com/install1.html From SBrunning@trisystems.co.uk Thu Aug 10 12:09:48 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Thu, 10 Aug 2000 12:09:48 +0100 Subject: [Tutor] Processing Gutenburg texts Message-ID: <31575A892FF6D1118F5800600846864D4C71AE@intrepid> I've put together a simple module for working with Gutenburg text file (see below), and I'd appreciate some advice. (I'm new to Python, so be gentle!) The problem is that Gutenburg texts are not actually all formatted the same way, so what started out as a fairly simple and clean process has turned into a monster, and I'd like to simplify things. The ugliest piece of code has to be the bit which looks for the title and author, but *any* suggestions as to improvements would be welcome. Thanks. # pyGut.py - a class for converting Gutenburg formatted text files # to more user-friendly HTML. # # Requires HTMLgen - thanks, Robin! # A huge number of Gutenburg texts are available from http://promo.net/pg/ # Simon Brunning - sbrunning@bigfoot.com # BTW, this tool totally mangles poetry, and I can't thing of anything to # do about it. import sys, os, string from HTMLgen import HTMLgen class GutDocument: '''Gutenburg to HTML conversion. Use importText to load from Gutenburg formatted text file, and exportHTML to create HTML file.''' def __init__(self): self.title = 'No title' self.author = 'No author' self.textBlocks = [] self.tocLines = {} self.finishedFrontMatter = 0 self.titleFound = 0 self.textBlock = [] self.tocTriggers = ['chapter', 'act', 'stave', 'verse', 'preface', 'introduction', 'appendix', 'book', 'dedication', 'canto', 'dedicatory'] self.lineBreaks = ['\n', '\r\n', '\r'] def importText(self, gutFile): importFile = open(gutFile, 'r') while(1): inLine = importFile.readline() if inLine == '': break # EOF self.storeFragment(inLine) if len(self.textBlocks) == 0: # Empty, end of front-matter not found. self.textBlocks.append('No text found.') def storeFragment(self, fragment): if self.finishedFrontMatter == 0: # Looking for Title & author fragment = string.replace(fragment, 'The ', '') if self.titleFound == 0 \ and string.find(fragment, 'Project Gutenberg Etext of') <> -1: # Title self.title = string.replace(fragment, '*', '') self.title = string.replace(self.title, 'Project Gutenberg Etext of ', '') self.titleFound = 1 if string.find(self.title, ' by ') <> -1: self.title, self.author = tuple(string.split(self.title, ' by ')) if self.title[-1] == ',': self.title = self.title[:-1] if string.find(fragment, '*END*') > -1: # We've finished the front matter self.finishedFrontMatter = 1 elif fragment not in self.lineBreaks: # Continue paragraph if len(string.strip(fragment)): self.textBlock.append(string.strip(fragment)) elif len(self.textBlock): # End of paragraph self.textBlocks.append(string.join(self.textBlock)) for tocTrigger in self.tocTriggers: # Table of contents if string.find(string.lower(self.textBlocks[-1]), tocTrigger) == 0: self.tocLines[len(self.textBlocks)-1] = string.join(self.textBlock) break self.textBlock = [] def exportHTML(self, htmlFileUrl): exportFile = HTMLgen.BasicDocument(title=self.title) exportFile.append(HTMLgen.Heading(1, self.title)) # Heading exportFile.append(HTMLgen.Heading(2, self.author)) # Author entry = HTMLgen.Name('toc', 'Table of Contents:') exportFile.append(entry) exportFile.append(HTMLgen.BR()) sortedTocLines = self.tocLines.keys() sortedTocLines.sort() for tocLine in sortedTocLines: # Table of contents url = '#' + str(tocLine) text = self.tocLines[tocLine] entry = HTMLgen.Href(url, text) exportFile.append(entry) exportFile.append(HTMLgen.BR()) exportFile.append(HTMLgen.HR()) for textBlock in range(len(self.textBlocks)-1): text = self.textBlocks[textBlock] if not self.tocLines.has_key(textBlock): # Ordinary text entry = HTMLgen.Text(text) exportFile.append(entry) else: # toced line url = str(textBlock) # Add the anchor & text entry = HTMLgen.Name(url, text) exportFile.append(entry) exportFile.append(HTMLgen.BR()) entry = HTMLgen.Href('#toc', 'Top') # Link to top exportFile.append(entry) tocElement = sortedTocLines.index(textBlock) if tocElement > 0: # Link to previous url = '#' + str(sortedTocLines[tocElement-1]) entry = HTMLgen.Href(url, 'Previous') exportFile.append(entry) if tocElement < (len(sortedTocLines)-1): # Link to next url = '#' + str(sortedTocLines[tocElement+1]) entry = HTMLgen.Href(url, 'Next') exportFile.append(entry) exportFile.append(HTMLgen.BR(2)) exportFile.write(htmlFileUrl) def clear(self): self.title = 'No title' self.author = 'No author' self.textBlocks = [] self.tocLines = {} self.finishedFrontMatter = 0 self.titleFound = 0 self.textBlock = [] def __str__(self): result = 'ToC:' + os.linesep + \ str(self.tocLines) + os.linesep + \ 'Text Blocks:' + os.linesep + \ str(self.textBlocks) return result def __len__(self): return len(self.textBlocks) def pprint(self): import pprint print 'ToC:' pprint.pprint(self.tocLines) print 'Text Blocks:' pprint.pprint(self.textBlocks) def batchConversion(directory): import glob files = glob.glob(directory + '\*.txt') doc = GutDocument() for file in files: doc.importText(file) htmlFile = string.replace(file, '.txt', '.html', ) doc.exportHTML(htmlFile) doc.clear() if __name__== '__main__': # Running as a script gutDocument = GutDocument() gutDocument.importText(sys.argv[1]) gutDocument.exportHTML(sys.argv[2]) else: # Imported print 'Module pyGut imported.' # Imported Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From wesc@deirdre.org Thu Aug 10 19:53:11 2000 From: wesc@deirdre.org (Wesley Chun) Date: Thu, 10 Aug 2000 11:53:11 -0700 Subject: [Tutor] upcomng UC Santa Cruz Python course(s) Message-ID: <200008101853.LAA17270@adelie.deirdre.org> below is an announcement for another Python course i'm giving for UC Santa Cruz for Fall 2000. it is targeted for those who are familiar with at least one other high-level programming language. for complete newbies, we are working on developing a course for people completely new to programming period. this class is ten- tatively scheduled for the Winter 2000 quarter. after that class, i will be on a long-term vacation, so UCSC will probably not be offering another class until Fall 2001 quarter. hope to see some of you in one of the classes!! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - UC Santa Cruz Extension Python course in Silicon Valley, Fall 2000 When: Tuesdays, October 3 - November 21, 2000, 6:30pm-9:30pm Where: Sunnyvale, CA Who: Wesley Chun, Python instructor and author of Core Python Programming (TBP Fall 2000) What: intro to Python, data types, statements, errors and exception handling, functions and modules, OOP and classes, execution environment, regular expressions, network/Internet progamming, interfacing to your operating system, creating GUIs with Tkinter, intro to JPython, and Extending Python Info: for more info, see the UCSC Extension website: http://www.ucsc-extension.edu/knowledge_is_timeless/qd/softlist.taf?fun ction=detail&X_Number=X444.3 From stevel@softhome.net Thu Aug 10 20:21:09 2000 From: stevel@softhome.net (Steve) Date: Thu, 10 Aug 2000 15:21:09 -0400 Subject: [Tutor] if string contains dictionary key Message-ID: <200008101921.PAA29949@mailhub.networktwo.net> I know I am missing something obvious, but I am having a= difficult time trying to get this to work. s =3D 'This string contains a CLR' d =3D {'CLR ': 'CLEAR', 'CA': 'ACCEPT', 'CR': 'CALL REQUEST'} if s has d.keys(): do stuff From bryan2001@worldnet.att.net Thu Aug 10 20:18:41 2000 From: bryan2001@worldnet.att.net (Bryan Jeffrey) Date: Thu, 10 Aug 2000 15:18:41 -0400 Subject: [Tutor] Hello. Message-ID: <39930010.76E54030@worldnet.att.net> Hello, I'm attempting to learn Python on the advice of a friend. I already know quite a bit of C++, and am interested in learning other languages. Is there a compiler for Python? Where can I find it? Where can I find a few *good* examples of Python source? Do you have any advice to offer? Thanks. --Bryan From tourinho@descartes.ucpel.tche.br Thu Aug 10 20:27:16 2000 From: tourinho@descartes.ucpel.tche.br (Gustavo Passos Tourinho) Date: Thu, 10 Aug 2000 16:27:16 -0300 (EST) Subject: [Tutor] Python x SQL Message-ID: Hi all, Does anyone knows if I can use a DataBase with Python. There is a module? Where can I find information about it? Thanks From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 10 20:37:10 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 10 Aug 2000 12:37:10 -0700 (PDT) Subject: [Tutor] if string contains dictionary key In-Reply-To: <200008101921.PAA29949@mailhub.networktwo.net> Message-ID: On Thu, 10 Aug 2000, Steve wrote: > I know I am missing something obvious, but I am having a difficult > time trying to get this to work. > > s = 'This string contains a CLR' > > d = {'CLR ': 'CLEAR', 'CA': 'ACCEPT', 'CR': 'CALL REQUEST'} > > > if s has d.keys(): > do stuff 'has', unfortunately, isn't a keyword. You probably mean 'in' instead if s in d.keys(): do stuff Because 'in' does an exact check, 's' won't match with anything in 'd' in your example. From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 10 20:43:22 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 10 Aug 2000 12:43:22 -0700 (PDT) Subject: [Tutor] Hello. In-Reply-To: <39930010.76E54030@worldnet.att.net> Message-ID: On Thu, 10 Aug 2000, Bryan Jeffrey wrote: > Hello, I'm attempting to learn Python on the advice of a friend. I > already know quite a bit of C++, and am interested in learning other > languages. > > Is there a compiler for Python? Where can I find it? Where can I find > a few *good* examples of Python source? Dear Brian, Good afternoon! You can get the Python interpreter at the Downloads section in: http://www.python.org/download/ You'll probably want to explore the rest of the www.python.org site, since it has a LOT of information, introductions, and tutorials. Python's an interpreted language, so you won't need to worry about compiling stuff --- it'll automatically byte-compile if it needs to. Since you've already had programming experience, I think you'll find the official tutorial to be pretty good: http://www.python.org/doc/current/tut/tut.html Examples of Python code can be found at the Vaults of Parnassus, which is the Python repository. http://www.vex.net/parnassus/ Also, when you install Python, it also comes with most of the module source code. Source code has a .py extension, so you can look through the Lib directory for "official" examples. Good luck! From genius@idirect.com Thu Aug 10 20:44:09 2000 From: genius@idirect.com (Charles Takacs) Date: Thu, 10 Aug 2000 15:44:09 -0400 Subject: [Tutor] Hello. References: <39930010.76E54030@worldnet.att.net> Message-ID: <39930609.F46CCDF2@idirect.com> Bryan Jeffrey wrote: > > Hello, I'm attempting to learn Python on the advice of a friend. I > already know quite a bit of C++, and am interested in learning other > languages. > > Is there a compiler for Python? Where can I find it? Where can I find > a few *good* examples of Python source? > > Do you have any advice to offer? > > Thanks. > The best place to start is at www.python.org. Best regards Charles > --Bryan > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From wesc@alpha.ece.ucsb.edu Thu Aug 10 20:47:02 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Thu, 10 Aug 2000 12:47:02 -0700 (PDT) Subject: [Tutor] if string contains dictionary key Message-ID: <200008101947.MAA09944@alpha.ece.ucsb.edu> > From: Steve > Date: Thu, 10 Aug 2000 15:21:09 -0400 > > I know I am missing something obvious, but I am having a difficult > time trying to get this to work. > > s = 'This string contains a CLR' > > d = {'CLR ': 'CLEAR', 'CA': 'ACCEPT', 'CR': 'CALL REQUEST'} > > if s has d.keys(): > do stuff close. one problem is that d.keys() will only return a list, i.e. ['CLR', 'CA', 'CR'] (assuming your key is 'CLR', not 'CLR ' as in your example. the other problem is that you are trying to find whether your key is a *substring* of a string, not the string itself. if 's' was just 'CLR', then you could've used: if d.has_key(s): do stuff but that's not how you presented your problem. we need to use some form of string.find() (find, rfind, index, rindex, etc.) to help you out, as in the example below using a loop. you can also take advantage of python's for-else statement with your application: - - - - - import string for eachKey in d.keys(): if string.find(s, eachKey): # or s.find(eachKey) in 1.6+ # do stuff else: print 'no keys found in string "s"' - - - - - the import of the string module and module function call are antiquated with the new string methods in Python 1.6 and higher. hope this helps!! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, TBP Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html Python Books: http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 10 20:48:12 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 10 Aug 2000 12:48:12 -0700 (PDT) Subject: [Tutor] Python x SQL In-Reply-To: Message-ID: On Thu, 10 Aug 2000, Gustavo Passos Tourinho wrote: > Does anyone knows if I can use a DataBase with Python. > There is a module? Where can I find information about it? Yes, there are Python database modules that make SQL convenient. If you're running a Windows system, you'll most likely want to look at the ODBC module: http://www.python.org/windows/win32/odbc.html You'll need to install the PythonWin extension, but it's definitely worth it. It can be found here: http://www.python.org/download/download_windows.html Also, take a look at the topic guide on Databases, so you can get familiar with the database interface. It also has a list of other database modules, so you can find a more vendor-specific module. http://www.python.org/topics/database/ From wesc@alpha.ece.ucsb.edu Thu Aug 10 21:15:17 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Thu, 10 Aug 2000 13:15:17 -0700 (PDT) Subject: [Tutor] if string contains dictionary key Message-ID: <200008102015.NAA10356@alpha.ece.ucsb.edu> > From: Daniel Yoo > Date: Thu, 10 Aug 2000 12:37:10 -0700 (PDT) > > 'has', unfortunately, isn't a keyword. You probably mean 'in' instead > > if s in d.keys(): > do stuff > > Because 'in' does an exact check, 's' won't match with anything in 'd' in > your example. this *would* work if 's' was 'CLR' or an actual key in the dictionary, but unfortunately, that is not the case in steve's example. the key may be a *substring* of 's'. in this case, you need to use one of the string functions/methods to look within the string for the key. but let's say that 's' *was* a potential key. in this case, you can use your example above: "s in d.keys()". However, performance pundits will probly raise some ire with that solu- tion because it is much slower than: "d.has_key(s)" the reason being that first d.keys() has to go thru the entire set of keys of the dictionary. then it has to put them together, creating a list. when the list returns, a check would need to be made as to whether 's' is in that list. with has_key(), it just checks the keys and says yes or no. let's see this in action... here's a script called hasInTest.py: #!/usr/bin/env python import timeit s = 'CLR' # assume string can be a key now d = {'CLR ': 'CLEAR', 'CA': 'ACCEPT', 'CR': 'CALL REQUEST'} def doin(d, s): i = 0 while i < 100000: s in d.keys() i = i + 1 def dohas(d, s): i = 0 while i < 100000: d.has_key(s) i = i + 1 def main(): timeit.timeit(doin, d, s) timeit.timeit(dohas, d, s) if __name__ == '__main__': main() - - - - - - - - i wrote a script called timeit.py that just calls a function and returns the time elapsed to run that function with arguments. running this on a SPARC 5 with Solaris 2.7, you can see that it takes more than 50% longer to use 'in' rather than 'has_key()': % hasInTest.py doin 0:9.11s dohas 0:5.89s let's try one more time: % hasInTest.py doin 0:9.08s dohas 0:5.78s basically, this is one of the cases where there is more than one way of doing something in Python, and if there is, it's always good to go over your code to see if you cna squeeze any more precious run time out of it. hope this helps!! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, TBP Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html Python Books: http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 10 22:23:58 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 10 Aug 2000 14:23:58 -0700 (PDT) Subject: [Tutor] Python x SQL In-Reply-To: Message-ID: On Thu, 10 Aug 2000, Gustavo Passos Tourinho wrote: > Hey... > Thanks for your help. > > I'm using linux. There no problem, isnt it? No problem; I'm using the MySQLdb module myself for my database programming. Here's the link to the module: http://dustman.net/andy/python/MySQLdb/ It works well --- my code often looks something like: conn = MySQLdb.connect(db="test") cursor = conn.cursor() cursor.execute("select * from books") print cursor.fetchall() I don't have experience with other databases like PostgreSQL or Oracle, but they should be pretty similar. From stevel@softhome.net Fri Aug 11 00:04:32 2000 From: stevel@softhome.net (Steve) Date: Thu, 10 Aug 2000 19:04:32 -0400 Subject: [Tutor] if string contains dictionary key:Part Deux In-Reply-To: <200008101947.MAA09944@alpha.ece.ucsb.edu> Message-ID: <200008102304.TAA00892@mailhub.networktwo.net> Thanks Wesley & Daniel! I was going down that path but I wanted to get creative and use= the map or filter command. I couldn't figure out how to pass it both= string.split(s) and d.keys(). I also mis-represented the restraints of my program. The string= should have read s=3D'This string has a CLR in it' because I have another key name 'CLRc', 'CLR ' will always have a= space following it. The dictionary is defined by my program so I= can make it anything I want, but the string is from an input file. = So I can change my key from 'CLR ' to CLR' and, with your help, I= came up with the following. d =3D {'CLR': 'CLEAR', 'CA': 'ACCEPT', 'CR': 'CALL REQUEST'} s=3D'This string has a CLR in it' for x in string.split(s): if d.has_key(x): print d[x] ### or using map ### def f(x): if d.has_key(x): print d[x] map(f,string.split(s)) From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 11 11:35:41 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 11 Aug 2000 03:35:41 -0700 (PDT) Subject: [Tutor] Processing Gutenburg texts In-Reply-To: <31575A892FF6D1118F5800600846864D4C71AE@intrepid> Message-ID: On Thu, 10 Aug 2000, Simon Brunning wrote: > into a monster, and I'd like to simplify things. Let's try to look at code locally, and see if we can get the code a little simpler. However, I have to admit I'm not too good at this stuff -- My own code bulges out a lot... You might want to look at your program from both a low-level and high-level perspective, bounce them around a bit, and see what you'd like to improve. > def importText(self, gutFile): > importFile = open(gutFile, 'r') > while(1): > inLine = importFile.readline() > if inLine == '': break # EOF > self.storeFragment(inLine) > if len(self.textBlocks) == 0: # Empty, end of front-matter not > found. > self.textBlocks.append('No text found.') Instead of the 'while' loop, using a 'for/in' might be a little easier: ### def importText(self, gutFile): for line in open(gutFile).readlines(): self.storeFragment(inLine) if len(self.textBlocks) == 0: self.textBlocks.append('No text found.') ### Because of garbage collection, we don't have to worry too much on explicitly keeping a reference to that open file, so it simplifies the code a bit. I see that storeFragment() handles 3 separate cases: capturing front material, doing regular stuff, and finishing paragraphs. It might be easier to split off the front material searching from the rest of your fragment storing, since it seems to be different in spirit from the other two tasks. Use function decomposition liberally to make things easy to read. From a big perspective, what might be making your program a little long is the line-by-line analysis that is being done. It might be easier to split off the chapters and other book sections if you do string manipulations on the whole text file (read() instead of readlines()). From this big perspective, your program, too, looks at the input in a big way. *grin* We can say that a document is made up of chunks. A chunk is either the front material: everything before that *end* tag. sectioning: any one of your tocTriggers regular text: anything else. You can do this in stages. First chomp off the front material. With everything else, you can start chunking along the sectioning keywords. Finally, you can do local adjustments, like string.strip(), to clean the small things up. I made a small chunker that might help. Don't laugh, it's really bad. ### def makeChunks(msg, trigger): """msg -> list of chunks. For example: makeChunks("This is a short message", " ") -> ['This', ' ', 'is', ' ', 'a', ' ', 'short', ' ', 'message'] """ sentinel = '\0' msg = string.replace(msg, trigger, sentinel+trigger+sentinel) return string.split(msg, sentinel) ### Ok, it's hideous. I admit it. I'm sleepy. *grin* But perhaps it might be useful for you. makeChunks() is a little different from a regular split() because it maintains the splitting element inside the list, in preparation for a scan-through later for key phrases (like sectioning names.) I'm abusi...er... using the null character, becase I'm assuming that it'll never show up naturally in a text file. For your exportHTML(), you should probably split up sections of it into other functions. For example, splitting the table of contents section off in another function will probably make things better. It doesn't matter that it just gets called once --- the idea is to help you see lots of small steps reduced to one large step. From a fast grep through, it looks like certain "phrases" are being repeated --- they might be good candidates for functions, and will reduce its size as well. I gotta go before I konk out to sleep. I hope this is somewhat helpful. Good luck! From gundamone@hotmail.com Sat Aug 12 06:49:20 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Fri, 11 Aug 2000 22:49:20 -0700 Subject: [Tutor] Escape codes and 'return statements' Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0014_01C003E6.630F91A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi this is Albert, I'm currently learning Python and I came across this things called = "escape codes". I understand fairly most of them except for the escape = codes ' \n ' and (linefeed???) and ' \r ' (carriage return). Also, I kinda understand 'return' statements but I would like to = know on how and when to use them properly.Thanks in advance. Albert www.isopod-graphics.com ------=_NextPart_000_0014_01C003E6.630F91A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi this is Albert,
 
    I'm currently = learning Python=20 and I came across this things called "escape codes". I understand fairly = most of=20 them except for the escape codes ' \n ' and (linefeed???) and ' \r ' = (carriage=20 return).
 
    Also, I kinda = understand=20 'return' statements but I would like to know on how and when to use them = properly.Thanks in advance.
 
Albert
www.isopod-graphics.com
 
------=_NextPart_000_0014_01C003E6.630F91A0-- From shndowch@netvision.net.il Fri Aug 11 17:31:19 2000 From: shndowch@netvision.net.il (Bezalel Schendowich, O.D., FIACLE) Date: Fri, 11 Aug 2000 18:31:19 +0200 Subject: [Tutor] Regards to Ivan --24 Hours... Message-ID: <39942A57.324ECD0E@netvision.net.il> The first two hours were a breeze. Now we are beginning to move past the "toes' stage" to the "ankle stage". Python was suggested for my 13 year old. Let's see if I let him in! ------------------------------ Bezalel Schendowich, OD, FIACLE shndowch@netvision.net.il http://www.szmc.org.il/today/news32.htm http://www.clspectrum.com/newarchive/1999/October/1099029.htm http://www.clspectrum.com/newarchive/1999/December/1299044.htm "If I forget thee, O Jerusalem, let my right arm forget her cunning." (T'hil. 137:5) --------------------------------------------------------------------------------------- From arcege@shore.net Fri Aug 11 17:04:08 2000 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 11 Aug 2000 12:04:08 -0400 (EDT) Subject: [Tutor] Escape codes and 'return statements' In-Reply-To: from "Albert Antiquera" at Aug 11, 2000 10:49:20 PM Message-ID: <200008111604.MAA28047@northshore.shore.net> > I'm currently learning Python and I came across this things called = > "escape codes". I understand fairly most of them except for the escape = > codes ' \n ' and (linefeed???) and ' \r ' (carriage return). A little history. Way back when.. you had typewriters that had two seperate operations: carriage return, which moved the roller (called the carriage) back to the beginning of the line; line feed, which moved the roller up one line. There was a handle on the carriage that performed both. Many computer systems evolved with teletypes (a combination of a terminal and a typewriter), card readers and paper-tape punchers, all with similar needs: a carriage return and a line-feed. So most computer systems handle those two systems. Different software vendors developed software to handle EOLN (end-of-line) to mean either "carriage return", "line feed" or "carriage-return/linefeed". The '\r' is the carriage return ASCII character and '\n' is the line-feed character. Windows uses the two combined, UNIX uses '\n' and Macintosh uses '\r'. Most of the time you will not have to worry about it; in Python, the os module has a "linesep" constant which changes for each system, as I described above. The only real time you have to worry is when you deal with multiple platforms and have to convert binary data (the "b" mode in the Python open() function). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From special@buoinet.net Fri Aug 11 16:43:39 2000 From: special@buoinet.net (special@buoinet.net) Date: Fri, 11 Aug 2000 11:43:39 -0400 Subject: [Tutor] $9.95/ mo web hosting Message-ID: Sir: I noticed your website and am simply offering you what could be a much better deal on your web hosting... If you think you might be interested, go to our site: http://www.buoinet.net see what we have to offer... Our hosting plans start at $9.95... Thanks again for your time - you wont be getting any more email from us unless you email us requesting more information. If you represent a web design firm, we offer bulk discounting as well. Very Truly Yours -Mike Carlson www.buoinet.net This message is sent in compliance of the new e-mail bill: SECTION 301. Per Section 301, Paragraph (a)(2)(C) of S. 1618, http://www.senate.gov/~murkowski/commercialemail/S771index.html Further transmissions to you by the sender of this email may be stopped at no cost to you by sending a reply to this email address with the word "remove" in the subject line. From sysadmin@hiretechs.com Fri Aug 11 09:31:51 2000 From: sysadmin@hiretechs.com (sysadmin@hiretechs.com) Date: Fri, 11 Aug 2000 08:31:51 GMT Subject: [Tutor] Brain Dead Message-ID: <20000811083152.18705.qmail@mail.hiretechs.com> Tutor, O.K., I am retarted. I created a simple, little piece of python code. I opened a txt. file from my desktop changed it around, did a little of this and a little of that and everything worked great. Now I am so brain fried that I can't remember how to print the results into a new file. Please when you are done laughing at me. Will you give me a quick reminder. Thanks. Mike Mike Weltz Systems Administrator HireTechs.com sysadmin@hiretechs.com ph. 310-665-3433 fax 310-665-3533 From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 11 19:34:01 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 11 Aug 2000 11:34:01 -0700 (PDT) Subject: [Tutor] Brain Dead In-Reply-To: <20000811083152.18705.qmail@mail.hiretechs.com> Message-ID: On Fri, 11 Aug 2000 sysadmin@hiretechs.com wrote: > O.K., I am retarted. I created a simple, little piece of python code. > I opened a txt. file from my desktop changed it around, did a little of > this and a little of that and everything worked great. Now I am so brain > fried that I can't remember how to print the results into a new file. > Please when > you are done laughing at me. Will you give me a quick reminder. Thanks. Don't worry about it. And we'd never laugh at you --- we're here to help each other. Files can be opened for writing by specifying 'w' (write) or 'a' (append) as the second parameter in an open() call: f = open('secrets.txt', 'w') Afterwards, you can start doing write()'s: f.write('This is a test.') There's a section in the official tutorial that talks about file i/o: Section 7.2 Reading and Writing files: http://www.python.org/doc/current/tut/node9.html#SECTION009200000000000000000 From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 11 20:47:43 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 11 Aug 2000 12:47:43 -0700 (PDT) Subject: [Tutor] Brain Dead In-Reply-To: <20000811100915.20657.qmail@mail.hiretechs.com> Message-ID: On Fri, 11 Aug 2000 sysadmin@hiretechs.com wrote: > Daniel, > > I appreciate your help. This is the code I wrote. > > #!/usr/bin/python > import string > > myfile = open('master.hosts', 'r') > for line in myfile.readlines(): > line = string.replace(line, '#', ';') > if '\t' in line: > line = string.replace(line, string.whitespace, 't\n\r\v\f') > fields = string.split(line) > if ';' in fields[0]: > newline = ';' + fields[1] + '\t\tA\tIN\t' + > fields[0][1:] > else: > newline = fields[1] + '\t\tA\tIN\t' + fields[0] > print newline Right now, all the results get printed out by that 'print' statement. I'm guessing that instead of just printing out newline, you want to write newline into your myfile. You can do this by replacing the print call with a write call. myfile.write(newline) should do the trick. From gundamone@hotmail.com Sat Aug 12 03:15:17 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Fri, 11 Aug 2000 22:15:17 EDT Subject: [Tutor] Mutable and Immutable data types/objects Message-ID: Sorry for this very very very newbie question: What does mutable and immutable data types in Python really mean??What can Mutable data types/objects can do that Immutable types cannot do and vice versa? again, sorry if this is very basic Albert www.isopod-graphics.com ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From shaleh@valinux.com Sat Aug 12 19:52:05 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Sat, 12 Aug 2000 11:52:05 -0700 (PDT) Subject: [Tutor] Mutable and Immutable data types/objects In-Reply-To: Message-ID: On 12-Aug-2000 Albert Antiquera wrote: > Sorry for this very very very newbie question: > What does mutable and immutable data types in Python really mean??What can > Mutable data types/objects can do that Immutable types cannot do and vice > versa? > starting simply: mutable means 'able to be changed', immutable is its reverse 'constant' simple example: # lists are mutable >>> list = [1, 2, 3] >>> list[0] = 4 >>> list [4, 2, 3] # tuples are not >>> tuple = (1, 2, 3) >>> tuple[0] = 4 Traceback (innermost last): File "", line 1, in ? TypeError: object doesn't support item assignment So, the next obvious question is 'why?'. The reason for having both a constant data type and a mutable one is two fold: speed and expressability. Sometimes while coding an algorithm has parts which will not change -- constant coefficients, the value of pi, etc. The language allows you to reflect this and avoid accidental changing of these values. While allowing for this, the language also has the opportunity to optimize the constant values, since it knows they will never change. Python does this with strings to help string processing be faster. An example: in other languages if you have: string = "dog" string[2] = 't' print string "dot" Python will not allow this. There are ways to accomplish in the language of course. Hope this helps. From rickdoksa@penn.com Sun Aug 13 00:03:09 2000 From: rickdoksa@penn.com (Richard E. Doksa) Date: Sat, 12 Aug 2000 16:03:09 -0700 Subject: [Tutor] help Message-ID: <000f01c004b1$7c420d80$0f9bf5cd@0019634874> This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C00476.CF216C20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable i got a sample program from python.org on makeing a calculator and i = cant make python except some of the code. i dont know when to push enter = and when not to.sometimes i enter the code just like the example and i = still get errors? i am just starting out with python please send me = anything you think will help me? also i was told that python is a good language to start out on is that = true? i have never done any programing before and i would like to learn = as many languages as possible where should i start? = thank you=20 rick = doksa ------=_NextPart_000_000C_01C00476.CF216C20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
i got a sample program from python.org = on makeing a=20 calculator and i cant make python except some of the code. i dont know = when to=20 push enter and when not to.sometimes i enter the code just like the = example and=20 i still get errors? i am just starting out with python please send me = anything=20 you think will help me?
also i was told that python is a good = language to=20 start out on is that true? i have never done any programing before and i = would=20 like to learn as many languages as possible where should i = start?
 
          &nbs= p;            = ;            =             &= nbsp;           &n= bsp;           =20 thank you
 
          &nbs= p;            = ;            =             &= nbsp;           &n= bsp;     =20 rick doksa
------=_NextPart_000_000C_01C00476.CF216C20-- From success@tfnisp.com Sun Aug 13 21:55:48 2000 From: success@tfnisp.com (Success Mountain) Date: Sun, 13 Aug 2000 20:55:48 Subject: [Tutor] Your Boat has arrived! Message-ID: <20000814004149.CC54D1CF27@dinsdale.python.org> Thousands of people around the country have found Financial Relief by building their very own Home Based Business right out of their living rooms without spending a dime. The Company is called The Free Network and they are giving people across the country their very own businesses for FREE!! That's right for FREE!! There is no catch. No commitments. The Free Network understands that life today is not easy. They also know that many people want their own businesses but lack the resources to do so. They have solved the problem for you. All you need to do is take advantage of it. You can own your own Internet Company, Paging Company, Long Distance Company, Wireless Company or your own Virtuall Mall, ALL FOR FREE!! You are invited to review an opportunity that is changing the pace of online business...and it's FREE! How would you like to get paid every time someone visits your online mall and makes a purchase...and we'll give you your own online mall for FREE! View an online presentation now! http://dev.www.earnware.com/createweb/buzz/ To find out more information or to speak to a live person email your name and number and we will get back to you. At the Free Network, We want you to succeed! Our reputation is on the line. Visit our Website and take a look for yourself. http://www.thefreenetwork.com/summit Remember, this offer is FREE! Please accept our deepest apologies, if you received this email unsolicited, and you can be removed automatically below. *********** All REMOVE requests AUTOMATICALLY honored upon receipt. mailto:sszewczuk@tfnmail.com/?subject=REMOVE From gundamone@hotmail.com Mon Aug 14 03:41:13 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Sun, 13 Aug 2000 22:41:13 EDT Subject: [Tutor] Programming exercises online Message-ID: Hi, I've been reading Ivan Van Laningham's book "Teach Yourself Python" and I'd say that it's a pretty good book to those who are absolutely beginners.However, the book doesn't have practice exercises(by that I mean it doesn't have a section about sample problems to be solved by using Python coding) so I'm kinda seeing myself reading on without much practice. So, I guess what I'm asking is: Does anybody knows a site that has a list or tutorials on Python ***PLUS*** practice exercises that I can sharpen my skills at??? Thanks in advance. Albert, www.isopod-graphics.com ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 14 08:26:14 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 14 Aug 2000 00:26:14 -0700 (PDT) Subject: [Tutor] Programming exercises online In-Reply-To: Message-ID: On Sun, 13 Aug 2000, Albert Antiquera wrote: > I've been reading Ivan Van Laningham's book "Teach Yourself Python" and > I'd say that it's a pretty good book to those who are absolutely > beginners.However, the book doesn't have practice exercises(by that I mean > it doesn't have a section about sample problems to be solved by using Python > coding) so I'm kinda seeing myself reading on without much practice. So, I > guess what I'm asking is: Does anybody knows a site that has a list or > tutorials on Python ***PLUS*** practice exercises that I can sharpen my > skills at??? Thanks in advance. Good evening! Although the link is down at the time I'm posting, there's a book called "How To Think Like a Computer Scientist" which has been "translated" from Java to Python: http://yhslug.tux.org/obp/thinkCS/thinkCSpy Until they bring the site back up, you might want to look at the original thinkCS book, and get inspiration from its practice exercises: http://www.cs.colby.edu/~downey/ost/ Also, there's some more educational material at the CP4E (Computer Programming for Everyone) project: http://www.python.org/sigs/edu-sig/ and I'm sure that the edu-sig people would be more than happy to suggest sample problems for you. *grin* What part are you learning now? Perhaps we might be able to suggest a few problems as well. What are your interests? From SBrunning@trisystems.co.uk Mon Aug 14 09:07:25 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Mon, 14 Aug 2000 09:07:25 +0100 Subject: [Tutor] help Message-ID: <31575A892FF6D1118F5800600846864D4C71BD@intrepid> Rick, I'm sure that there will be many people ready to help, but we'll need a little more info. Please give us either the code that doesn't work, or the *exact* URL where you found it - we haven't got time to go looking! We'll want the errors that you are getting, too. I think that Python is a good first language. One piece of advice from an old-timer (though new to Python), - forget this 'as many languages as possible' business. Firstly, learn one language at a time, and secondly, you won't need to know very many. It's better to know three or for well than 20 badly. Provided that they are the right three or four, that is! Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk > -----Original Message----- > From: Richard E. Doksa [SMTP:rickdoksa@penn.com] > Sent: Sunday, August 13, 2000 12:03 AM > To: Tutor@python.org > Subject: [Tutor] help > > i got a sample program from python.org on makeing a calculator and i cant > make python except some of the code. i dont know when to push enter and > when not to.sometimes i enter the code just like the example and i still > get errors? i am just starting out with python please send me anything you > think will help me? > also i was told that python is a good language to start out on is that > true? i have never done any programing before and i would like to learn as > many languages as possible where should i start? > > > thank you > > rick > doksa > > > > ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 14 08:58:17 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 14 Aug 2000 00:58:17 -0700 (PDT) Subject: [Tutor] help In-Reply-To: <000f01c004b1$7c420d80$0f9bf5cd@0019634874> Message-ID: On Sat, 12 Aug 2000, Richard E. Doksa wrote: > i got a sample program from python.org on makeing a calculator and i > cant make python except some of the code. i dont know when to push > enter and when not to.sometimes i enter the code just like the example > and i still get errors? i am just starting out with python please send The very beginning is usually a little difficult; don't worry too much about it. Python depends a lot on indentation, so you might get errors because of indentation errors. There are also a bunch of small things that you'll get used to, once you see them. It makes things much easier if you work with a nice text editor, such as IDLE or Emacs, because those editors handle indentation almost automatically for you. Anyway, I'll try to guess at your problems, and show why they're buggy. Here's a pretty tediously silly interpreter session with explanations headed by '###': ### I want to learn how to use the 'if' statement. ### >>> name = raw_input("Please enter your name") Please enter your nameDanny ### Hmm, that looked weird, but that's just because I forgot to put a ### color or space in my raw_input call. ### ### raw_input("Enter name: ") ### ### would look ok. >>> if name == danny File "", line 1 if name == danny ^ SyntaxError: invalid syntax ### This happened because it looks like I'm trying to use a 'danny' ### variable, but it hasn't been created yet. I really meant to compare ### against the _string_ "danny". I must remember to quote strings. >>> if name == "danny" File "", line 1 if name == "danny" ^ SyntaxError: invalid syntax ### Whoops. Forgot the colon --- 'if' statements need to show that you're ### starting the 'if' block by using a colon. >>> if name == "danny": ... print "Hello to myself" File "", line 2 print "Hello to myself" ^ SyntaxError: invalid syntax ### That was silly --- I forgot to indent my print statement; this is ### because the 'if' needs to take in a block of instructions, even if ### there's just one statement in the block. However, I could have just ### done: ### ### if name == "danny": print "Hello to myself" ### ### on one line, and it would have worked too. (This only works for ### one-liners.) >>> if name == "danny": ... print "Hello to myself" ... >>> ### Hey, nothing happened. Oh, that's because 'Danny' is capitalized ### and 'danny' isn't. Grrr. >>> if name == "Danny": ... print "Hello to myself" ... Hello to myself >>> ### Ah, finally! I hope this highlighed some of the problems you were getting, but of course I can only guess. If you can show us the error messages that you're getting, we can help explain them. > me anything you think will help me? also i was told that python is a > good language to start out on is that true? i have never done any > programing before and i would like to learn as many languages as > possible where should i start? One thing at a time! *grin* It's good that you're trying to learn as quickly as you can. Yes, Python's a good language to start with. If someone hasn't directed you to a Python tutorial yet, take a look at these: Josh Cogliati's Non-Programmer's Tutorial for Python: http://www.honors.montana.edu/~jjc/easytut/easytut/ Alan Gauld's Learning to Program: http://members.xoom.com/alan_gauld/tutor/tutindex.htm Once you're gotten fluent with Python, you might want to look at something entirely different, like Scheme. Scheme's another programming language from the Lisp family. Most likely, it will take you completely by surprise when you see it. Here's a link to one of their sites: http://www.cs.rice.edu/CS/PLT/Teaching/ You can pretty much branch off anywhere your interest leads you to. Try to apply what you've learned, so that you can better understand the techniques. Anyway, sorry for the length of this message; I babble a lot. Good luck! From wilson@visi.com Mon Aug 14 15:06:11 2000 From: wilson@visi.com (Timothy Wilson) Date: Mon, 14 Aug 2000 09:06:11 -0500 (CDT) Subject: [Tutor] Programming exercises online In-Reply-To: Message-ID: On Sun, 13 Aug 2000, Albert Antiquera wrote: > So, I > guess what I'm asking is: Does anybody knows a site that has a list or > tutorials on Python ***PLUS*** practice exercises that I can sharpen my > skills at??? Thanks in advance. Hi Albert, One of the things I've had fun with lately is using Python to solve the weekly puzzle on public radio's Weekend Edition program. I created a module that contains some useful functions for word games and use those functions along with some custom code each week to try to figure out the puzzle. My puzzle module has functions for loading my system's dictionary into a Python list, filtering a list of words for all words of a given length, finding the longest word or words in a given list, etc. It's been good exercise. You can see the weekly puzzle at http://www.npr.org/programs/wesun/puzzle/ Not every puzzle is of the type that can be solved (at least partially) by using Python, but many are. Using my module, I can usually solve the straight-forward ones in a few minutes. Good luck and have fun. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From oosteep@sjtc.whirlpool.com Mon Aug 14 17:37:13 2000 From: oosteep@sjtc.whirlpool.com (Erik Oosterwal) Date: Mon, 14 Aug 2000 12:37:13 -0400 Subject: [Tutor] Re: Tutor digest, Vol 1 #391 - 6 msgs References: <20000814160649.5F0EB1CD70@dinsdale.python.org> Message-ID: <39982039.CBCD85CA@sjtc.whirlpool.com> tutor-request@python.org wrote: > > > Message: 1 > From: "Success Mountain" > To: > Date: Sun, 13 Aug 2000 20:55:48 > Subject: [Tutor] Your Boat has arrived! > > Thousands of people around the country have found Financial List-admin, Can you set up the list so that spam doesn't get through? It's annoying to get a digest filled with it. Thanks, Erik. -- +----------------------------------------------------------+ EADGBE | Erik Oosterwal - Data Acquisition Engineer | ||O||| 6 | oosteep@sjtc.whirlpool.com | |O|O|| 7 | http://www.geocities.com/oosterwal | ||||O| 8 | My views may not coincide with the views of my employer. | |||||| 9 +----------------------------------------------------------+ E7#9 From nothingisgoingtochangemyworld@yahoo.com Mon Aug 14 20:10:41 2000 From: nothingisgoingtochangemyworld@yahoo.com (Joseph Stubenrauch) Date: Mon, 14 Aug 2000 12:10:41 -0700 (PDT) Subject: [Tutor] A few newbie questions about Tkinter (disregard previous) Message-ID: <20000814191041.9120.qmail@web1903.mail.yahoo.com> (warning, longish question) Hello all, First, I'd like to thank everyone for the help I have received so far on this list. I started using python to make a program that simulates "flash cards" for the French, German, and Latin classes I am taking in college. I am running Python on a windows 95 box. The program so far allows the user to choose a vocabulary list (for instance, German Vocab Chapter 14), and then presents the user with the words in random order. When the correct translation in english is entered, the word is removed from the vocab list. If not, the word remains in the list to be randomly asked later. Once the user has correctly translated all the words, a score is presented totalling how many words were asked, how many times the user was incorrect, and which words were missed, etc. The program works fine and dandy for me. However, my German Professor has offered to hire me to fine tune the program and add GUI to it so that other students can use it. (When I gave the program to others students just as an EXE file, they had problems copying from disk into a directory, so I need to make things SIMPLE and point-click-easy). SOOOOO ... (yeah, the question finally!), I have started to try and add GUI to the program. However, I am encountering trouble and would appreciate it if someone can point me in the right direction. I am trying to make a dialogue box pop up with a word randomly chosen from a list. Below is an entry widget. The user then enters the answer. If the answer is correct, a third dialogue box below says "correct" and the word is removed from the list. The entry field clears. And the first dialogue box then displays another randomly chosen word. I have had no problem with getting it to run through once, but I can't figure out how to make it destroy or change the first dialogue box for the next word in the list. I am a bit confused, I suppose, as to how things work in the "loop" of Tkinter ... where to place methods, commands, etc. Any suggestions? Perhaps just some pseudo-code to give me some pointers? Additionally, is it possible to have the cursor jump from entry widget to entry widget when the user presses "tab"? I have been looking about to see if this is possible but I am not sure yet. Thanks in advance for your help. Sorry the question was so long winded, though I still have the feeling I wasn't clear enough. Cheers, Joe __________________________________________________ Do You Yahoo!? Yahoo! Mail – Free email you can access from anywhere! http://mail.yahoo.com/ From gastevens69@hotmail.com Mon Aug 14 20:49:58 2000 From: gastevens69@hotmail.com (Gregory Stevens) Date: Mon, 14 Aug 2000 14:49:58 -0500 Subject: [Tutor] commands Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C005FE.EA8B3E80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Where can I get a list of commands for python? I would really appreciate = it. THANKS ------=_NextPart_000_0005_01C005FE.EA8B3E80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Where can I get a list of commands for = python? I=20 would really appreciate it. THANKS
------=_NextPart_000_0005_01C005FE.EA8B3E80-- From gundamone@hotmail.com Sun Aug 13 16:07:47 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Sun, 13 Aug 2000 11:07:47 -0400 Subject: [Tutor] Numbers appearing as strings in program Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C00516.B66278A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi to all, I've written this simple calculator program but I've got a problem with = it: The NUMBERS are "turning" to STRINGS!! I'm not sure what is wrong = cuz I'm new to Python. Does the built in statement 'raw_input' only = support strings???If so, how can I get numbers as input from the user? = Here is the script calculator.py: #---------------------------------Begin = Script--------------------------------------------- #!/usr/local/bin/python # Author: Albert P. Antiquera, 2000 # Program : Simple calculator import sys def add(x,y): sum =3D x + y print "The sum of", x , "and" , y ,"is:", sum =20 def sub(x,y): dif =3D x - y print "The difference of", x , "minus", y , "is:", dif =20 def mul(x,y): pro =3D x * y print "The product of", x , "times", y , "is:", pro =20 def div(x,y): quo =3D x / y print "The quotient of", x , "divided by", y , "is:", quo =20 print "Press A for Addition" print " S for Subtraction" print " M for Multiplication" print " D for Division" choice =3D raw_input("Enter what kind of operation you want:") if (choice =3D=3D 'A'): x =3D raw_input("Enter a value for X:") y =3D raw_input("Enter a value for Y:") add(x,y) =20 elif (choice =3D=3D 'S'): x =3D raw_input("Enter a value for X:") y =3D raw_input("Enter a value for Y:") sub(x,y) elif (choice =3D=3D 'M'): x =3D raw_input("Enter a value for X:") y =3D raw_input("Enter a value for Y:") mul(x,y) elif (choice =3D=3D 'D'): x =3D raw_input("Enter a value for X:") y =3D raw_input("Enter a value for Y:") div(x,y) else: print "Wrong input.Make sure key is in UPPER CASE" =20 #------------------------------End of = Script-------------------------------- Another thing, the Addition function works but instead of adding the = numbers like (1 + 1 =3D 2) it concatenates it like (1 + 1 =3D 11). The = rest of the functions don't work at all. Any help would be deeply = appreciated. Thanks, Albert URL: www.isopod-graphics.com email: albert@isopod-graphics.com ------=_NextPart_000_0011_01C00516.B66278A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi to all,
 
I've written this simple calculator = program but=20 I've got a problem with it: The NUMBERS are "turning" to STRINGS!! I'm = not sure=20 what is wrong cuz I'm new to Python. Does the built in statement = 'raw_input'=20 only support strings???If so, how can I get numbers as input from the = user? Here=20 is the script calculator.py:
 
#---------------------------------Begin = Script---------------------------------------------
#!/usr/local/bin/python
# Author: = Albert P.=20 Antiquera, 2000
# Program : Simple calculator
import sys
 
def add(x,y):
 sum =3D x + = y
 print=20 "The sum of", x , "and" , y ,"is:", sum
 
def = sub(x,y):
 dif=20 =3D x - y
 print "The difference of", x , "minus", y , "is:",=20 dif
 
def mul(x,y):
 pro =3D x * y
 print = "The product=20 of", x , "times", y , "is:", pro
 
def div(x,y):
 quo = =3D x /=20 y
 print "The quotient of", x , "divided by", y , "is:",=20 quo
 
print "Press A for Addition"
print=20 "      S for Subtraction"
print=20 "      M for Multiplication"
print=20 "      D for Division"
choice =3D = raw_input("Enter=20 what kind of operation you want:")
 
if (choice =3D=3D 'A'):
 x =3D = raw_input("Enter a=20 value for X:")
 y =3D raw_input("Enter a value for=20 Y:")
 add(x,y)
 
elif (choice =3D=3D 'S'):
 x = =3D=20 raw_input("Enter a value for X:")
 y =3D raw_input("Enter a = value for=20 Y:")
 sub(x,y)
elif (choice =3D=3D 'M'):
 x =3D = raw_input("Enter a=20 value for X:")
 y =3D raw_input("Enter a value for=20 Y:")
 mul(x,y)
elif (choice =3D=3D 'D'):
 x =3D = raw_input("Enter a=20 value for X:")
 y =3D raw_input("Enter a value for=20 Y:")
 div(x,y)
else:
 print "Wrong input.Make sure = key is in=20 UPPER CASE"
 
#------------------------------End of=20 Script--------------------------------
 
Another thing, the Addition function = works but=20 instead of adding the numbers like (1 + 1 =3D 2) it concatenates it like = (1 + 1 =3D=20 11). The rest of the functions don't work at all. Any help would be = deeply=20 appreciated.
 
Thanks,
Albert
 
URL: www.isopod-graphics.com
em= ail: albert@isopod-graphics.com=
------=_NextPart_000_0011_01C00516.B66278A0-- From deirdre@deirdre.net Mon Aug 14 21:17:55 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 14 Aug 2000 13:17:55 -0700 (PDT) Subject: [Tutor] commands In-Reply-To: Message-ID: On Mon, 14 Aug 2000, Gregory Stevens wrote: > Where can I get a list of commands for python? http://www.python.org/doc/current/lib/lib.html -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "We can always count on the British. Except for the Revolutionary War they've been perfect." -- Mel Brooks, on the first Concorde flight since the Paris crash. From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 14 22:30:08 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 14 Aug 2000 14:30:08 -0700 (PDT) Subject: [Tutor] Numbers appearing as strings in program In-Reply-To: Message-ID: > I've written this simple calculator program but I've got a problem > with it: The NUMBERS are "turning" to STRINGS!! I'm not sure what is > wrong cuz I'm new to Python. Does the built in statement 'raw_input' > only support strings???If so, how can I get numbers as input from the > user? Here is the script calculator.py: You got it --- raw_input() will always return a string back to you. Don't worry; there are a few ways to get the numbers back. For example, you can use the int() or float() functions on those strings, which will return the numerical values of those strings. On an unrelated topic, since you're always reading in 'x' and 'y' for the operations, you can optimize slightly by making a small input function of your own. Here's one that can take care of the number conversions for you, so you don't have to worry about it: ### def readNumbers(): x = raw_input("Enter a value for X:") y = raw_input("Enter a value for Y:") return (float(x), float(y)) ### After you make a function like readNumbers(), you can use it like this in your program: ### if (choice == 'A'): x, y = readNumbers() add(x,y) ### and it should make things easier for you. If you find yourself repeating the same code, it's usually a prime target for making a convenient function. > Another thing, the Addition function works but instead of adding the > numbers like (1 + 1 = 2) it concatenates it like (1 + 1 = 11). The > rest of the functions don't work at all. Any help would be deeply > appreciated. The reason that's happening is because of the string stuff --- addition for strings is defined to be string contatenation. And since raw_input was giving you back strings. It's a different bug, but from the same source. String addition is really useful if you want to put two strings together: ### >>> "Hello" + " world!" 'Hello world!' ### But you have to be careful not to expect number addition when you have strings: ### >>> "1" + "1" '11' ### And trying to mix the two just doesn't work: ### >>> 1 + "1" Traceback (innermost last): File "", line 1, in ? TypeError: number coercion failed ### If you have any questions on this, email us back. Good luck to you! From gundamone@hotmail.com Sun Aug 13 18:50:25 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Sun, 13 Aug 2000 13:50:25 -0400 Subject: [Tutor] 'return' statements Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_001E_01C0052D.6E8BD960 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've finished the calculator program I was making thanks to the help of = Daniel Yoo. One statement that continue to elude me to fully understand = it is the 'return' statement. On some text they said 'return' is a = "goback to the start of the function" another said that it is a = "terminator" of a function. Can somebody explain it and please provide = some examples like when to use ' 0 ' and ' 1 ' after a return statement = and also this usage (Thanks, Daniel for this very useful function!!): def readNum(): x =3D raw_input("Enter a value for X:") y =3D raw_input("Enter a value for Y:") return (float (x),float(y)) <<<<<<<<<<<
I've finished the calculator program I = was making=20 thanks to the help of Daniel Yoo. One statement that continue to elude = me to=20 fully understand it is the 'return' statement. On some text they said = 'return'=20 is a "goback to the start of the function" another said that it is a=20 "terminator" of a function. Can somebody explain it and please provide = some=20 examples like when to use ' 0 ' and ' 1 ' after a return statement and = also this=20 usage (Thanks, Daniel for this very useful function!!):
 
  def=20 readNum():
     x =3D raw_input("Enter a value = for=20 X:")
     y =3D raw_input("Enter a value for=20 Y:")
     return (float (x),float(y))   = <<<<<<<<<<<<what exactly is return = doing=20 here?????
 
another example:
 
def julian_leap(y = =3D2000):
    if (y%4) =3D=3D = 0:
        = return 1=20 <<<< I guess this says "true" but I'm not really = sure
    return 0 = <<< what is=20 this returning????
 
I'm sorry if I've been flooding your = mailboxes with=20 questions but I really appreciate the help!!
Albert
 
URL: www.isopod-graphics.com
em= ail: albert@isopod-graphics.com=
------=_NextPart_000_001E_01C0052D.6E8BD960-- From deirdre@deirdre.net Tue Aug 15 00:02:58 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 14 Aug 2000 16:02:58 -0700 (PDT) Subject: [Tutor] 'return' statements In-Reply-To: Message-ID: On Sun, 13 Aug 2000, Albert Antiquera wrote: > I've finished the calculator program I was making thanks to the help > of Daniel Yoo. One statement that continue to elude me to fully > understand it is the 'return' statement. On some text they said > 'return' is a "goback to the start of the function" another said that > it is a "terminator" of a function. Can somebody explain it and please > provide some examples like when to use ' 0 ' and ' 1 ' after a return > statement and also this usage (Thanks, Daniel for this very useful > function!!): Return returns to the calling function, with or without parameters. > def readNum(): > x = raw_input("Enter a value for X:") > y = raw_input("Enter a value for Y:") > return (float (x),float(y)) <<<<<<<<<<< Message-ID: On Sun, 13 Aug 2000, Albert Antiquera wrote: > I've finished the calculator program I was making thanks to the help > of Daniel Yoo. One statement that continue to elude me to fully > understand it is the 'return' statement. On some text they said > 'return' is a "go back to the start of the function" another said that > it is a "terminator" of a function. Can somebody explain it and please > provide some examples like when to use ' 0 ' and ' 1 ' after a return > statement and also this usage (Thanks, Daniel for this very useful > function!!): No problem. About 'return': All functions will give back a value to the "calling" function. Even when you don't say anything like "return", functions will at least send back the "None" object. Take a look: ### >>> def doNothing(): ... pass ... >>> x = doNothing() >>> print x None ### What a 'return' statement allows you to do is specify what sort of value you want your functions to give back. For example: ### >>> def square(x): return x * x ... >>> square(5) 25 >>> square(square(5)) 625 ### Also, 'return' does a quick exit out of the function. ### >>> def testReturn(): ... return "I've returned!" ... print "I'll never get here." ... >>> x = testReturn() >>> x "I've returned!" ### What I was doing in: > def readNum(): > x = raw_input("Enter a value for X:") > y = raw_input("Enter a value for Y:") > return (float (x),float(y)) <<<<<<<<<<< another example: > > def julian_leap(y =2000): > if (y%4) == 0: > return 1 <<<< I guess this says "true" but I'm not really sure > return 0 <<< what is this returning???? It's literally either returning the number 1 or 0. There isn't a distinct "true" or "false" data type; Python conveniently reuses 1 and 0 to represent Truth. ### >>> 'A' == 'A' 1 >>> 'A' == 'B' 0 ### So you can abuse the language by doing something like: ### >>> ('A' == 'A') + ('A' == 'B') 1 ### From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 15 02:01:18 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 14 Aug 2000 18:01:18 -0700 (PDT) Subject: [Tutor] commands In-Reply-To: Message-ID: On Mon, 14 Aug 2000, Gregory Stevens wrote: > Where can I get a list of commands for python? I would really > appreciate it. THANKS Take a look at the library reference --- it shows the majority of the functions and modules in Python: http://www.python.org/doc/current/lib/lib.html From spirou@aragne.com Tue Aug 15 02:05:26 2000 From: spirou@aragne.com (Denis) Date: Tue, 15 Aug 2000 03:05:26 +0200 Subject: [Tutor] A few newbie questions about Tkinter (disregard previous) In-Reply-To: <20000814191041.9120.qmail@web1903.mail.yahoo.com>; from nothingisgoingtochangemyworld@yahoo.com on Mon, Aug 14, 2000 at 12:10:41PM -0700 References: <20000814191041.9120.qmail@web1903.mail.yahoo.com> Message-ID: <20000815030526.A4086@aragne.com> --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Le Mon, Aug 14, 2000 at 12:10:41PM -0700, Joseph Stubenrauch pianota: > Any suggestions? Perhaps just some pseudo-code to > give me some pointers? > Do you use Tkinter variables ? (StringVar) Are you sure dialogs are the best way ? Why not a single form with a left and right side, a status and so on ? > presses "tab"? set the takefocus property of your desired widgets to 1 if needed I attach some "cut&try" code so that you can play with it. Have fun, P.S. You could also ckeck http://www.browsebooks.com/Grayson/ You'll find the source code of the book. Have a look at Example_12_1.py : it's about a Navigation class ... and try to find someone to offer you the book :-) -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="takefocus.py" Content-Transfer-Encoding: 8bit #!/usr/bin/env python # #------------------------------------------------ # Sample program to show the takefocus property # and some other features of Tkinter # # by Spirou # http://www.p3b.org #------------------------------------------------ # from Tkinter import * root = Tk() # callbacks def shownext(event): """ show the next word in the book """ global pointer pointer = pointer + 1 if pointer > len(book)-1: pointer = 1 var1.set(book[pointer]) var2.set('') return var1.get() def die(event): """ Quit """ root.quit() # a book and a pointer book = ["Mot français", "programmer", "variable", "objet", "afficher", "dictionnaire"] pointer = 0 # and two Tkvariables for the Entries var1 = StringVar() var1.set(book[pointer]) var2 = StringVar() var2.set("English Translation") # a big superior frame f1 = Frame(root, bg="darkslateblue", highlightthickness = 2, highlightcolor = "blue", width=400, height=240 ) # a small one for the buttons f2 = Frame(root, bg="darkslateblue", highlightthickness = 2, highlightcolor = "blue", width=400, height=60 ) # 2 frames in the big superior, with the entries fa = Frame(f1, bg="lightslateblue", ## takefocus = 1, highlightthickness = 2, highlightcolor = "violet", width=100, height=240 ) fb = Frame(f1, bg="lightslateblue", ## takefocus = 1, highlightthickness = 2, highlightcolor = "violet", width=100, height=240 ) f1.pack(side=TOP, expand=YES, fill=BOTH) f2.pack(side=TOP, expand=NO, fill=X) fa.pack(side=LEFT, expand=YES, fill=BOTH) fb.pack(side=RIGHT, expand=YES, fill=BOTH) t1 = Entry(fa, textvariable = var1, takefocus = 0, # so, it won't get the focus highlightthickness = 1, highlightcolor = "red", width=25 ) t2 = Entry(fb, textvariable = var2, ## takefocus = 1, # this one will get the focus (default value) highlightthickness = 1, highlightcolor = "red", width=25 ) t1.pack() t2.pack() # two buttons, one to move the cursor ahead, the other to quit b1 = Button(f2, text="next", highlightthickness = 2, highlightcolor = "red" ) b1.bind('', shownext) b1.bind('', shownext) b1.bind('', shownext) b2 = Button(f2, text="quit", highlightthickness = 2, highlightcolor = "red" ) b2.bind('', die) b2.bind('', die) b2.bind('', die) b2.pack(side=RIGHT) b1.pack(side=RIGHT) # and go root.wm_title("Tabs & Tkinter Variables") root.wm_minsize(400, 300) root.mainloop() --qDbXVdCdHGoSgWSk-- From sven.hohage@zeitspringer.de Tue Aug 15 14:41:53 2000 From: sven.hohage@zeitspringer.de (Sven Hohage) Date: Tue, 15 Aug 2000 15:41:53 +0200 Subject: [Tutor] Python space-invaders Message-ID: <399948A0.D43F8F8F@zeitspringer.de> Hallo, I'm learning python and I'd like to know the adress of a tutorial in which you are building the old arcade- game space-invader with python. Or is someone knowing another tutorial which is building a game or a larger project?? Thanks. From michaelbaker@operamail.com Tue Aug 15 18:36:07 2000 From: michaelbaker@operamail.com (michaelbaker@operamail.com) Date: Tue, 15 Aug 2000 10:36:07 -0700 Subject: [Tutor] sorting objects with embedded data In-Reply-To: <20000815134520.82E741D02B@dinsdale.python.org> Message-ID: <3.0.6.32.20000815103607.00826890@operamail.com> I'm using python with blender (http://www.blender.nl) - an amazing freeware 3d modeling and animation package. I'm trying to sort a bunch of objects based on their positions in the Z axis direction. example: cubes=[[cube.001],[cube.002],[cube.003],[cube.004],[cube.005]] # each cube object contains coordinate data accessible through 3 # methods? LocX, LocY, LocZ - these correspond to the x, y and # z axes respectively. Here's what I've got: buffer=[] for a in cubes: buffer.append(a.LocZ) buffer.sort() # this returns a sorted list of z coordinate values - great, but I # need to access the x and y coordinate data based on the sorted z # data - now I need to sort the cubes list based on the sorting # of the buffer list. # Is it possible to sort the cubes list in-place based on the # embedded LocZ numerical data? thanks in advance - check out blender, it's amazing. From DOUGS@oceanic.com Tue Aug 15 19:08:10 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Tue, 15 Aug 2000 08:08:10 -1000 Subject: [Tutor] sorting objects with embedded data Message-ID: <8457258D741DD411BD3D0050DA62365907A2BE@huina.oceanic.com> I can give part of a possible answer. I'd point you in the direction of setting up a subclass for the cube object. You might explore if the work is already done or being done, but it would make sense that there was a __cmp__ method of the object that would rank two cubes correctly. You probably also have to implement some of the other magic methods (gurus please pipe up here) such as __getattr__. If subclassing 'cube' isn't working, creating a 'cubes' class that would encapsulate the sort behaviour probably is the way to go. Maybe subclassing UserList as a start. Hope this helps, -Doug- > -----Original Message----- > From: michaelbaker@operamail.com [mailto:michaelbaker@operamail.com] > Sent: Tuesday, August 15, 2000 7:36 AM > To: tutor@python.org > Subject: [Tutor] sorting objects with embedded data > > > I'm using python with blender (http://www.blender.nl) - an > amazing freeware > 3d modeling and animation package. I'm trying to sort a bunch > of objects > based on their positions in the Z axis direction. > > example: > > cubes=[[cube.001],[cube.002],[cube.003],[cube.004],[cube.005]] > > # each cube object contains coordinate data accessible through 3 > # methods? LocX, LocY, LocZ - these correspond to the x, y and > # z axes respectively. Here's what I've got: > > buffer=[] > > for a in cubes: > buffer.append(a.LocZ) > > buffer.sort() > > # this returns a sorted list of z coordinate values - great, but I > # need to access the x and y coordinate data based on the sorted z > # data - now I need to sort the cubes list based on the sorting > # of the buffer list. > > # Is it possible to sort the cubes list in-place based on the > # embedded LocZ numerical data? > > thanks in advance - check out blender, it's amazing. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 15 20:27:54 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Tue, 15 Aug 2000 12:27:54 -0700 (PDT) Subject: [Tutor] sorting objects with embedded data In-Reply-To: <3.0.6.32.20000815103607.00826890@operamail.com> Message-ID: On Tue, 15 Aug 2000 michaelbaker@operamail.com wrote: > I'm using python with blender (http://www.blender.nl) - an amazing freeware > 3d modeling and animation package. I'm trying to sort a bunch of objects > based on their positions in the Z axis direction. An easy way to do this is to tell the sort() specifically how to compare two items based on LocZ. sort() can take in an optional parameter that allows you to redefine the sorting order. Here's a sample comparison function: ### def cmpLocZ(cube1, cube2): return cmp(cube1.LocZ, cube2.LocZ) ### Once you have something like this, you can pass this off to the sorting routine. ### buffer.sort(cmpLocZ) ### and things should work well. From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 16 00:59:10 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Tue, 15 Aug 2000 16:59:10 -0700 (PDT) Subject: [Tutor] RE: PIL In-Reply-To: Message-ID: On Tue, 15 Aug 2000, Nick wrote: > What do you use for images? send me some code over, i still cant display a > bitmap yet!! Dear Nick, Unfortunately, I have little experience with PIL, so I've forwarded your message to the tutors at tutor@python.org; they should be better equipped to answer your question. PIL, however, is used to create images, but not to display them. For display on your screen, you'll want to used a graphics toolkit like Tkinter. It's by the same folks at Pythonware, and should already be installed for you. I took a quick look at the tkinter documentation, and came up with this code: ### from Tkinter import * photo = PhotoImage(file="freebsd.gif") canvas = Canvas() canvas.create_image(photo.width()/2, photo.height()/2, image=photo) canvas.pack() mainloop() ### Again, a warning: I have almost no experience with Tk, so the code above may be a very dumb way of doing things; hopefully, others on the tutor list can give better examples. It sounds like you're interested in doing GUI stuff; in that case, take a look at: http://www.pythonware.com/library/tkinter/introduction/ Again, if you have any questions, feel free to ask tutor@python.org. From elcultural.com@python.org Wed Aug 16 16:54:22 2000 From: elcultural.com@python.org (elcultural.com@python.org) Date: Wed, 16 Aug 2000 17:54:22 +0200 Subject: [Tutor] Actualidad cultural en Internet Message-ID: <2215220008316155422420> Actualidad Cultural <body> <style type="text/css"> <!-- .sinsubrayado { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; font-style: normal; font-weight: bold; text-decoration: none; text-align: centre; color: #000000} --> </style> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td width="7" height="18" valign="top"></td> <td width="126" height="37" colspan="3" rowspan="2" valign="middle"><img SRC="http://www.elcultural.com/correo/img/elcultural.jpg" height=13 width=123></td> <td width="79" height="18" valign="top"></td> <td width="4" height="18" valign="top"></td> <td width="6" height="18" valign="top"></td> <td width="36" height="18" valign="top"></td> <td width="12" height="18" valign="top"></td> <td width="92" height="18" valign="top"></td> <td width="12" height="18" valign="top"></td> <td width="172" height="18" valign="top"></td> </tr> <tr> <td width="7" height="19" valign="top"></td> <td width="79" height="19" valign="top"></td> <td width="4" height="19" valign="top"></td> <td width="6" height="19" valign="top"></td> <td width="36" height="19" valign="top"></td> <td width="12" height="19" valign="top"></td> <td width="92" height="19" valign="top"></td> <td width="12" height="19" valign="top"></td> <td width="172" height="617" rowspan="16" valign="top" bgcolor="#FFFFCC"> <center><p><a href="http://www.elcultural.com"><img SRC="http://www.elcultural.com/correo/img/logo2.gif" BORDER=0 height=56 width=68></a></p> <p><b><font face="Arial,Helvetica"><font size=-2>Otros Titulares</font></font></b> </p> </center> <p align="left"><font size=-2><font face="Wingdings"> &nbsp;n<font face="Arial, Helvetica, sans-serif" size="1"> <a href="http://elcultural.com/contenidos/tema/270700/1.asp">Danza contempor&aacute;nea en Andaluc&iacute;a, la hermana pobre de las artes esc&eacute;nicas</a></font></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font> </font> <font face="Arial,Helvetica"><font size=-1><a href="http://www.elcultural.com/contenidos/reportaje/230700/1.asp"><font size="1">De sur a sur, creadores africanos en Espa&ntilde;a</font></a></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font><font size=-2><font face="Wingdings"><font face="Arial, Helvetica, sans-serif" size="1"><a href="http://www.elcultural.com/contenidos/denominacion/310700/1.asp">Chano Dom&iacute;nguez, jazzeando por Buler&iacute;as</a></font></font></font> </font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font></font><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/contenidos/entrevista/250700/1.asp">Eduardo Haro Tecglen, "Asisto con horror a la lucha de los poderes por Internet"</a></font> <p align="left"><font size="1" face="Arial, Helvetica, sans-serif"><br> </font> <p align="left"> <center> <center> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">Portada</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Noticias culturales</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/dinamica/index.html">Versi&oacute;n multimedia</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/criticas/default.asp">Cr&iacute;tica de eventos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/cds/default.asp">Rese&ntilde;as de discos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/libros/default.asp">Rese&ntilde;as de libros</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Cartelera de Andaluc&iacute;a</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/eva/index.html">Espacio Virtual de las Artes</a></font></font> <br> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/arquitec/20000720/default.asp">Ar quitectura </a></font><br> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/webdelasemana/default.asp">Web de la Semana</a></font><br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/andalucia/default.asp">Andaluc&iacute;a Cultural</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/entrevista/default.asp">Entrevist as</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/reportaje/default.asp">Reportajes </a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/evento/default.asp">Eventos</a></ font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/denominacion/default.asp">Denomin aci&oacute;n de Origen</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/tema/default.asp">Temas de Actualidad</a></font></font> </center> </center></td> </tr> <tr> <td width="7" height="22" valign="top"></td> <td width="355" height="22" colspan="9" valign="top" bgcolor="#FFFFCC"><table width="100%" border="0" mm_noconvert="TRUE"> <tr> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/cine.asp"><font color="#000099"><b>cine</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/arte.asp"><b><font color="#000099">arte</font></b></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/escena.asp"><font color="#000099"><b>escena</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/musica.asp"><font color="#000099"><b>m&uacute;sica</b></font></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/literatura.asp"><b><font color="#000099">literatura</font></b></a></font></td> </tr> </table></td> <td width="12" height="22" valign="top"></td> </tr> <tr> <td width="7" height="8" valign="top"></td> <td width="104" height="8" valign="top"></td> <td width="7" height="8" valign="top"></td> <td width="15" height="8" valign="top"></td> <td width="79" height="8" valign="top"></td> <td width="4" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="36" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="92" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> </tr> <tr> <td width="7" height="136" valign="top"></td> <td width="355" height="136" colspan="9" valign="top"><b><font face="Arial, Helvetica, sans-serif" size="3">Juan Manuel de Prada: &quot;Concibo el paraíso bajo la especie de una biblioteca"</font><font face="Arial, Helvetica, sans-serif" size="4"><br> </font><font size="1" face="Arial, Helvetica, sans-serif"> <a href="http://elcultural.com/contenidos/entrevista/20000707/1.asp"><img src="http://www.elcultural.com/correo/img/prada.jpg" width="100" height="90" align="left" border="0"></a>Año y medio después de ganar el Planeta, Juan Manuel de Prada regresa al primer plano literario con una monumental novela biográfica sobre la escritora Ana María Martínez Sagi. Las esquinas del aire (Planeta) es un cruce de géneros que rescata del olvido a una figura fascinante que alternó la poesía con el lanzamiento de jabalina, y la militancia feminista con el periodismo. <a href="http://elcultural.com/contenidos/entrevista/20000707/1.asp">M&aacute;s Informaci&oacute;n</a></font></b></td> <td width="12" height="136" valign="top"></td> </tr> <tr> <td width="7" height="25" valign="top"></td> <td width="355" height="25" colspan="9" valign="top"> <hr WIDTH="350"></td> <td width="12" height="25" valign="top"></td> </tr> <tr> <td width="7" height="48" valign="top"></td> <td width="355" height="48" colspan="9" valign="top"> <p><font size="4" face="Arial, Helvetica, sans-serif">M&aacute;laga acoge una muestra del creador ecuatoriano Oswaldo Guayasam&iacute;n</font><font size="1" face="Arial, Helvetica, sans-serif"> </font></p> </td> <td width="12" height="48" valign="top"></td> </tr> <tr> <td width="7" height="105" valign="top"></td> <td width="251" height="105" colspan="7" valign="top"><font size="1" face="Arial, Helvetica, sans-serif">La exposición - que ya se presentó la pasada primavera en Córdoba y Sevilla -reúne 83 óleos y acrílicos que se complementa con una serie de paneles explicativos sobre su proyecto más ambicioso: La Capilla del hombre. Con una gran fuerza plástica y un enorme valor simbólico los cuadros de Guayasamín suo si hace falta, como en su disco "Imán".<br> <b><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/contenidos/evento/090800/1.asp">M&aacute;s Informaci&oacute;n</a></font></b> </font></td> <td width="12" height="105" valign="top"></td> <td width="92" height="105" valign="top"> <p align="center"><a href="http://elcultural.com/contenidos/evento/090800/1.asp"><img src="http://www.elcultural.com/correo/img/guayasamin.jpg" width="81" height="101" border="0"></a></p> </td> <td width="12" height="105" valign="top"></td> </tr> <tr> <td width="7" height="25" valign="top"></td> <td width="355" height="25" colspan="9" valign="top"> <hr WIDTH="100%"></td> <td width="12" height="25" valign="top"></td> </tr> <tr> <td width="7" height="4" valign="top"></td> <td width="104" height="4" valign="top"></td> <td width="7" height="4" valign="top"></td> <td width="15" height="4" valign="top"></td> <td width="79" height="4" valign="top"></td> <td width="4" height="4" valign="top"></td> <td width="6" height="4" valign="top"></td> <td width="140" height="109" colspan="3" rowspan="4" valign="top"> <table width="100%" border="0" cellspacing="1" cellpadding="01" mm_noconvert="TRUE"> <tr> <td> <div align="center"><span class="nombreseccion"><font face="Arial, Helvetica, sans-serif" size="2"><b>Eventos recomendados</b></font></span></div> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3613," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Almer&iacute;a</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3923," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">C&aacute;diz</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3971," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">C&oacute;rdoba</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4078," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Granada</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4056," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Huelva</font> </a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4074," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">Ja&eacute;n</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4090," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">M&aacute;laga</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3681," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">Sevilla</font></a></span></div> </td> </tr> </table> </td> </tr> </table></td> <td width="12" height="4" valign="top"></td> </tr> <tr> <td width="7" height="41" valign="top"></td> <td width="209" height="41" colspan="5" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Denominaci&oacute;n de Origen<br> <font size="1"><a href="http://elcultural.com/contenidos/denominacion/140800/1.asp">Enrique Santana (Pintor) </a></font></font></td> <td width="6" height="41" valign="top"></td> <td width="12" height="41" valign="top"></td> </tr> <tr> <td width="7" height="42" valign="top"></td> <td width="205" height="42" colspan="4" valign="top"><font face="Arial,Helvetica"><font size=-1>Reportaje<br> <font size="1"><a href="http://elcultural.com/contenidos/reportaje/070800/1.asp">Arte entre rejas, talentos en la c&aacute;rcel</a></font><br> </font></font></td> <td width="4" height="42" valign="top"></td> <td width="6" height="42" valign="top"></td> <td width="12" height="42" valign="top"></td> </tr> <tr> <td width="7" height="22" valign="top"></td> <td width="205" height="38" colspan="4" rowspan="2" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Entrevista<br> </font><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/bflamenco/entrevistas03.htm">Antonio El Pipa: &quot;Mi meta es morirme bailando&quot;</a></font> <font face="Arial, Helvetica, sans-serif" size="2"> </font></td> <td width="4" height="22" valign="top"></td> <td width="6" height="22" valign="top"></td> <td width="12" height="22" valign="top"></td> </tr> <tr> <td width="7" height="16" valign="top"></td> <td width="4" height="16" valign="top"></td> <td width="6" height="16" valign="top"></td> <td width="140" height="120" colspan="3" rowspan="4" valign="top"><a href="http://www.elcultural.com/bflamenco/index.htm"><b><font face="Arial, Helvetica, sans-serif" size="1" class="sinsubrayado"> <center> </center> </font></b></a> <div align="center"> <p><b><font size="1" face="Arial, Helvetica, sans-serif">En elcultural.com</font></b> </p> </div> <div align="center"><a href="http://www.elcultural.com/bflamenco"><img width="90" height="90" src="http://www.elcultural.com/correo/img/banner90.gif" border="0"></a></div> </td> <td width="12" height="16" valign="top"></td> </tr> <tr> <td width="7" height="35" valign="top"></td> <td width="205" height="35" colspan="4" valign="top"><font size="2" face="Arial, Helvetica, sans-serif">Web de la Semana</font><font size="1" face="Arial, Helvetica, sans-serif">: <br> <a href="http://elcultural.com/contenidos/webdelasemana/20000814.asp">Centro Andaluz de Flamenco</a></font></td> <td width="4" height="35" valign="top"></td> <td width="6" height="35" valign="top"></td> <td width="12" height="35" valign="top"></td> </tr> <tr> <td width="7" height="27" valign="top"></td> <td width="205" height="27" colspan="4" valign="top"> <hr> </td> <td width="4" height="27" valign="top"></td> <td width="6" height="27" valign="top"></td> <td width="12" height="27" valign="top"></td> </tr> <tr> <td width="7" height="42" valign="top"></td> <td width="104" height="50" rowspan="2" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Mirada adelante </font><br> <font size="2" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/contenidos/madelante/140800/1.asp"><font size="1">&Aacute;ngel Sanzo, pianista</font></a></font></td> <td width="7" height="42" valign="top"></td> <td width="94" height="42" colspan="2" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Mirada atr&aacute;s<br> <a href="http://elcultural.com/contenidos/matras/040800/1.asp"><font size="1">Jos&eacute; Guerrero, pintor </font></a></font></td> <td width="4" height="42" valign="top"></td> <td width="6" height="42" valign="top"></td> <td width="12" height="42" valign="top"></td> </tr> <tr> <td width="7" height="8" valign="top"></td> <td width="7" height="8" valign="top"></td> <td width="15" height="8" valign="top"></td> <td width="79" height="8" valign="top"></td> <td width="4" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="36" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="92" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="172" height="8" valign="top"></td> </tr> <tr> <td width="7" height="53" valign="top"></td> <td width="539" height="53" colspan="11" valign="top"> <center> <p><font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">portada </a>/ <a href="http://www.elcultural.com/dinamica/index.html">contenidos multimedias de la semana</a> / <a href="mailto:redaccion@elcultural.com">sugerencias</a> / <a href="http://www.elcultural.com/quienes/default.asp">sobre elcultural.com</a>/ <a href="http://www.elcultural.com/prensa/default.asp">dossier de prensa</a></font></font> <br> &nbsp;<br> <font face="Arial,Helvetica"><font size=-2>Si no quieres volver a recibir mensajes de elcultural.com pincha <a href="http://www.elcultural.com/suscripciones/baja.asp">aqu&iacute;</a> y b&oacute;rrate de la Secci&oacute;n Contenidos de Actualidad</font></font> </center></td> </tr> <tr> <td width="7" height="1" valign="top"><img width="7" height="1" src="transparent.gif"></td> <td width="104" height="1" valign="top"><img width="104" height="1" src="transparent.gif"></td> <td width="7" height="1" valign="top"><img width="7" height="1" src="transparent.gif"></td> <td width="15" height="1" valign="top"><img width="15" height="1" src="transparent.gif"></td> <td width="79" height="1" valign="top"><img width="79" height="1" src="transparent.gif"></td> <td width="4" height="1" valign="top"><img width="4" height="1" src="transparent.gif"></td> <td width="6" height="1" valign="top"><img width="6" height="1" src="transparent.gif"></td> <td width="36" height="1" valign="top"><img width="36" height="1" src="transparent.gif"></td> <td width="12" height="1" valign="top"><img width="12" height="1" src="transparent.gif"></td> <td width="92" height="1" valign="top"><img width="92" height="1" src="transparent.gif"></td> <td width="12" height="1" valign="top"><img width="12" height="1" src="transparent.gif"></td> <td width="172" height="1" valign="top"><img width="172" height="1" src="transparent.gif"></td> </tr> </table> </body> From tuckerg@acm.org Wed Aug 16 21:57:28 2000 From: tuckerg@acm.org (G. Alan Tucker) Date: Thu, 17 Aug 2000 05:57:28 +0900 Subject: [Tutor] Actualidad cultural en Internet References: <2215220008316155422420> Message-ID: <399B0038.452232B9@acm.org> Is there any way to get this SPAM off the list? - g > elcultural.com@python.org wrote: > > [Image] [Image] > > cine arte escena música literatura Otros > Titulares > Juan Manuel de Prada: "Concibo el paraíso bajo la especie de una > biblioteca" n Danza > [Image] Año y medio después de ganar el Planeta, Juan Manuel de contemporánea > Prada regresa al primer plano literario con una en Andalucía, > monumental novela biográfica sobre la escritora Ana María la hermana > Martínez Sagi. Las esquinas del aire (Planeta) es un cruce de pobre de las > géneros que rescata del olvido a una figura fascinante que artes > alternó la poesía con el lanzamiento de jabalina, y la escénicas > militancia feminista con el periodismo. Más Información > n De sur a > sur, > creadores > africanos en > -------------------------------------------- España > > n Chano > Málaga acoge una muestra del creador ecuatoriano Oswaldo Domínguez, > Guayasamín jazzeando por > Bulerías > > La exposición - que ya se presentó la pasada [Image] n Eduardo > primavera en Córdoba y Sevilla -reúne 83 óleos y Haro Tecglen, > acrílicos que se complementa con una serie de "Asisto con > paneles explicativos sobre su proyecto más horror a la > ambicioso: La Capilla del hombre. Con una gran lucha de los > fuerza plástica y un enorme valor simbólico los poderes por > cuadros de Guayasamín suo si hace falta, como en Internet" > su disco "Imán". > Más Información > Portada > Noticias > culturales > Versión > ---------------------------------------------------------------- multimedia > Crítica de > Denominación de Origen Eventos recomendados eventos > Enrique Santana (Pintor) Almería Cádiz Reseñas de > Córdoba Granada discos > Huelva Jaén Reseñas de > Reportaje Málaga Sevilla libros > Arte entre rejas, talentos en Cartelera de > la cárcel Andalucía > Espacio > Entrevista Virtual de > Antonio El Pipa: "Mi meta es las Artes > morirme bailando" Ar quitectura > En elcultural.com > Web de la > Web de la Semana: [Image] Semana > Centro Andaluz de Flamenco Andalucía > Cultural > ----------------------------- Entrevist as > Reportajes > Mirada Mirada atrás Eventos > adelante José Guerrero, Denomin ación > pintor de Origen > Ángel Temas de > Sanzo, Actualidad > pianista > portada / contenidos multimedias de la semana / sugerencias / sobre elcultural.com/ > dossier de prensa > > Si no quieres volver a recibir mensajes de elcultural.com pincha aquí y bórrate de > la Sección Contenidos de Actualidad > [Image][Image] [Image][Image][Image][Image][Image][Image][Image][Image][Image][Image] > _______________________________________________ Tutor maillist - -- These || G. Alan Tucker || Failure is not an option. . . Opinions || Tokyo, Japan || Are My Own || tuckerg@acm.org || It comes standard with Windows From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 16 22:25:19 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 16 Aug 2000 14:25:19 -0700 (PDT) Subject: [Tutor] Actualidad cultural en Internet In-Reply-To: <399B0038.452232B9@acm.org> Message-ID: On Thu, 17 Aug 2000, G. Alan Tucker wrote: > Is there any way to get this SPAM off the list? - g Perhaps the list maintainer could make it so subscription is necessary to post to the mailing list. I don't know --- would this prevent people from casually using tutor@python.org for help? I've heard that Mailman has a few anti-spamming features, but I've never tinkered successfully with it. From v1rus13@home.com Thu Aug 17 03:27:29 2000 From: v1rus13@home.com (Josh Stone) Date: Wed, 16 Aug 2000 19:27:29 -0700 Subject: [Tutor] I want to learn the python lang. Message-ID: I want to learn the python lang. I have already downloaded the python 1.5.2 and have no idea on how to use it. Please help me. What newsgroup should I subscribe to? Or could you help me straight up. JS From wilson@visi.com Thu Aug 17 05:19:53 2000 From: wilson@visi.com (Timothy Wilson) Date: Wed, 16 Aug 2000 23:19:53 -0500 (CDT) Subject: [Tutor] I want to learn the python lang. In-Reply-To: Message-ID: On Wed, 16 Aug 2000, Josh Stone wrote: > I want to learn the python lang. I have already downloaded the python 1.5.2 > and have no idea on how to use it. Please help me. What newsgroup should I > subscribe to? Or could you help me straight up. A good place to start is always the documentation at http://www.python.org/doc/ I would also recommend Ivan's book "Learning Python in 24 Hours." -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From alan.gauld@bt.com Thu Aug 17 11:37:16 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 17 Aug 2000 11:37:16 +0100 Subject: [Tutor] Escape codes and 'return statements' Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D295@mbtlipnt02.btlabs.bt.co.uk> > Hi this is Albert, > > I'm currently learning Python and I came across this > things called "escape codes". I understand fairly most of > them except for the escape codes ' \n ' and (linefeed???) and > ' \r ' (carriage return). I assume you are confused about the difference? Back in the mists of computing time(up until the late 1970's) computers had teletypes for input/output Teletypes had rolls of paper on which the printing was done and you could issue a linefeed to move the roll up one line at a time. This was mechanically much more efficient than moving up and moving the carriage back each time so if you wanted 3 blank lines you issued 3 linefeeds. They also had carriage return to bring the printhead back to the beginning of the line. Thus typically the user would type(or the program would output) a carriage return followed by one or more line feeds. These two motions got encapsulated in ASCII by the control chararacters ^J(linefeed) and ^M(carriage return/linefeed) With the advent of VDUs the need for a separate linefeed diminished and mostly we just use carriage return/linefeed as a single 'newline' command. Thus '\r' is a pure linefeed with no c/r and '\n' combines both motions. I'm not sure if there is a character for c/r only (which can be usefgul for controlling old printers which can only use one color per line - multiple passes allows multiple colors in a line, for example) Does that help in any way? Mostly you just need to use '\n'.... Alan G. > Also, I kinda understand 'return' statements but I would > like to know on how and when to use them properly.Thanks in advance. Oooh thats a religious question. :-) Simply put return causes an immediate return from the current function. Purists like to see a single return statement per function. Those of us brought up on C tend to use them rather more liberally! Alan G. From alan.gauld@bt.com Thu Aug 17 11:45:35 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 17 Aug 2000 11:45:35 +0100 Subject: [Tutor] help Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D297@mbtlipnt02.btlabs.bt.co.uk> > also i was told that python is a good language to start out > on is that true? Yes. > i have never done any programing before and > i would like to learn as many languages as possible where > should i start? Check the python website for several beginners tutorials(under Intros) My preference is, of course, for my own one :-) http://www.crosswinds.net/~agauld/ Designed for beginners and using 3 languages to illustrate the concepts. Alan G. From alan.gauld@bt.com Thu Aug 17 11:42:45 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 17 Aug 2000 11:42:45 +0100 Subject: [Tutor] Escape codes and 'return statements' Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D296@mbtlipnt02.btlabs.bt.co.uk> > "carriage-return/linefeed". The '\r' is the carriage return ASCII > character and '\n' is the line-feed character. Windows uses the two > combined, UNIX uses '\n' and Macintosh uses '\r'. Whoops,my other mail on this topic got these all mixed up. Ignore my definitions use these ones. The history bits of the other post are OK though... Sorry folks, I'm just catching up from a long trip, still brain numb. Alan G. From alan.gauld@bt.com Thu Aug 17 12:35:59 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 17 Aug 2000 12:35:59 +0100 Subject: [Tutor] Programming exercises online Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D29A@mbtlipnt02.btlabs.bt.co.uk> > beginners.However, the book doesn't have practice > exercises(by that I mean it doesn't have a section > about sample problems to be solved by using Python My tutor has some exercises buried in the text. By that I mean it doesn't have a speif section with numbered excercises etc but it does throughout the text say things like: "You may want to try extending this to...." or "Can you think of a way to make this do...." If that sounds helpful try: http://www.crosswinds.net/~agauld Alan G From alan.gauld@bt.com Thu Aug 17 12:49:38 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 17 Aug 2000 12:49:38 +0100 Subject: [Tutor] help Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D29B@mbtlipnt02.btlabs.bt.co.uk> > old-timer (though new to Python), - forget this 'as many languages as > possible' business. Firstly, learn one language at a time, > and secondly, you won't need to know very many. Hmm, I'm afraid I disagree with this. Most of the bigger projects I've worked on(*) had more than 3 languages within the single project. The most complex had at least 7 languages being used. Also each language teaches you somethjing about programming. For example the Smalltalk view of OOP is very different to the C++/Java/Object Pascal view. And LISP does it differently again. Similarly languages like Haskell and Prolog take a still different approach. But all of these approaches can be used in vanilla C, say, once you are aware they exist! If you are stuck with only a few languages - especially if they are all imperative in nature you will be faced with the real danger of "If all you have is a hammer every problem looks like a nail" > It's better to know three or four well than 20 > badly. I do agree however that you should know 3 or four very well. And knowing 20 badly, in the sense of trying to force every language to behave like the ones you know already is no good. But you can learn and use lots of languages at a less than expert level and still understand the underlying concepts that make them different. (eg the massive use of mixins in Lisp) > Provided that they are the right three or four, that is! Which is the difficult bit. How do you define 'rightness'? Is FOCUS right? or COBOL? or C++? Both are very effective languages for their particular domain but would probably not help a web developer very much... Or do you go with the marketability, in which case it might be: VB, C++ and Java. But I doubt you'd get any big insight or improvement in programming skill by learning those three! Alan G. (*) By bigger I mean more than say, 100,000 lines of code. Certainly every project of more than 1,000,000 LOC will use multiple languages, its almost impossible to avoid. Whether it be (COBOL, REXX, JCL, SQL) on MVS or (C++, Perl, Shell, SQL) on Unix or whatever. From genius@idirect.com Thu Aug 17 16:21:36 2000 From: genius@idirect.com (Charles Takacs) Date: Thu, 17 Aug 2000 11:21:36 -0400 Subject: [Tutor] I want to learn the python lang. References: Message-ID: <399C0300.2A64383@idirect.com> The best place to start is at Python Home Page: There are some very good Tutorials there. http://wwww.python org I would highly reccommend Alan Gauld's Tutoril for start. You can download it and use it off line from here: http://www.crosswinds.net/~agauld/ Look alsoat the NEWSGROUP: comp.lang.python godd luck Charles Josh Stone wrote: > > I want to learn the python lang. I have already downloaded the python 1.5.2 > and have no idea on how to use it. Please help me. What newsgroup should I > subscribe to? Or could you help me straight up. > > JS > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From michaelbaker@operamail.com Thu Aug 17 18:24:50 2000 From: michaelbaker@operamail.com (michaelbaker@operamail.com) Date: Thu, 17 Aug 2000 10:24:50 -0700 Subject: [Tutor] Re: I want to learn the python lang. In-Reply-To: <20000817160309.B16B61D1CF@dinsdale.python.org> Message-ID: <3.0.6.32.20000817102450.00849120@operamail.com> >From: "Josh Stone" >To: >Date: Wed, 16 Aug 2000 19:27:29 -0700 >charset="iso-8859-1" >Subject: [Tutor] I want to learn the python lang. > >I want to learn the python lang. I have already downloaded the python 1.5.2 >and have no idea on how to use it. Please help me. What newsgroup should I >subscribe to? Or could you help me straight up. > >JS I'm a newbie too and I've had good luck with 'Learning Python' from O'Reilly - it covers generic programming concepts and C similarities as you learn Python tricks - cool :] From dlaskey@laskeycpa.com Thu Aug 17 19:04:14 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Thu, 17 Aug 2000 14:04:14 -0400 Subject: [Tutor] Problem with strings Message-ID: <01C00854.2A3279C0@DAN> Objective: 1) To read a file called "s8288_ps.txt"; 2) search through the file line by line for the text "Totals for 4I"; and 3) send the results of the search line by line to a newfile called "junk2.txt" Code: # import sys and string import sys import string # open the file in_file = open("s8288_ps.txt","r") # create the file you want to export the data to out_file = open("junk2.txt","w+") # read each line in the file for line in in_file.readlines(): # grab each line if 'Totals for 4I' in line: print a # write the new file you created to the file "junk2.txt" out_file.write(a) out_file.close() in_file.close() Error message: Traceback (innermost last): File "today4.py", line 15, in ? if 'Totals for 4I' in line: TypeError: string member test needs char left operand Thanks, Dan --------------------------------------------------------------------------------------- | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.------231-723-8305 Voice | 231-723-6097 Fax | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 --------------------------------------------------------------------------------------- From subal@appmicro.com Thu Aug 17 19:36:12 2000 From: subal@appmicro.com (subal smith) Date: Thu, 17 Aug 2000 11:36:12 -0700 Subject: [Tutor] MacPython Help! Message-ID: <399C309C.ECC3D844@appmicro.com> I am a begginer programmer and need some help setting up python to work on my Mac. I have downloaded Python 1.5.2 and have custom installed it for a PPC. I followed a tutorial and created a "Hello World" script with simple text and saved it as a .py in the same directory as the Interpreter. The tutorial say's I should be able to drop the .py file onto the Interpreter and it will Open and Run. BUT It Doesn't. Do you have any idea what I did or am doing wrong? HELP? ThanX Subal From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 17 20:00:33 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 17 Aug 2000 12:00:33 -0700 (PDT) Subject: [Tutor] Problem with strings In-Reply-To: <01C00854.2A3279C0@DAN> Message-ID: On Thu, 17 Aug 2000, Daniel D. Laskey, CPA wrote: Hello! Let's take a look at the error message: > if 'Totals for 4I' in line: [omitted code] > Error message: > Traceback (innermost last): > File "today4.py", line 15, in ? > if 'Totals for 4I' in line: > TypeError: string member test needs char left operand This requires a little explanation on that error message: the 'if/in' will look through each element in 'line', seeing if it matches up with 'Totals for 4I'. The problem is that 'line' is a sequence of letters, so this search will compare against every single _letter_. That's why it's saying that weird 'member test needs char left operand'. The same error occurs if you try something like: ### >>> 'monkey' in 'this is a zoo of animals' Traceback (innermost last): File "", line 1, in ? TypeError: string member test needs char left operand >>> 't' in 'this is a zoo of animals' 1 >>> 'x' in 'this is a zoo of animals' 0 ### What you had above, then, could be translated as: if ('Totals for 4I' == line[0] or 'Totals for 4I' == line[1] or ...) So it doesn't quite work. In this case, you'll want to use the string finding routine, string.find(). It will search for a sub-string within a larger string, and will return the position where it finds it. If it can't find it, it'll return -1. Here's a sample of it in action: ### >>> string.find('this is an alphabeta word', 'alphabeta') 11 >>> string.find('bonobos are indigenous', 'mammal') -1 ### Be careful --- I often accidently reverse the order of the arguments. From spirou@aragne.com Thu Aug 17 20:54:03 2000 From: spirou@aragne.com (Denis) Date: Thu, 17 Aug 2000 21:54:03 +0200 Subject: [Tutor] Problem with strings In-Reply-To: <01C00854.2A3279C0@DAN>; from dlaskey@laskeycpa.com on Thu, Aug 17, 2000 at 02:04:14PM -0400 References: <01C00854.2A3279C0@DAN> Message-ID: <20000817215403.A26745@aragne.com> Le Thu, Aug 17, 2000 at 02:04:14PM -0400, Daniel D. Laskey, CPA pianota: > Objective: > 1) To read a file called "s8288_ps.txt"; > 2) search through the file line by line for the text "Totals for 4I"; and > 3) send the results of the search line by line to a newfile called "junk2.txt" > You can't search for a string in a string using in You could search for a "char", like this: if 'h' in 'Python': print 'hello' as the error message says : > TypeError: string member test needs char left operand but you can't do that > if 'Totals for 4I' in line: You could play with the re module. Since you want to import the string module (why ?), use instead the string.find() method -------------------------------- >>> import string >>> print string.find.__doc__ find(s, sub [,start [,end]]) -> in Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. --------------------------------- Check your variable a that comes from nowhere (did you mean a = line ?) and look out : the indentation here is crucial (out_file.write(a)) You're on the good way ! Denis > Code: > # import sys and string > import sys > import string > > # open the file > in_file = open("s8288_ps.txt","r") > > # create the file you want to export the data to > out_file = open("junk2.txt","w+") > > # read each line in the file > for line in in_file.readlines(): > # grab each line > if 'Totals for 4I' in line: > print a > # write the new file you created to the file "junk2.txt" > out_file.write(a) > out_file.close() > in_file.close() > > Error message: > Traceback (innermost last): > File "today4.py", line 15, in ? > if 'Totals for 4I' in line: > > Thanks, > Dan > --------------------------------------------------------------------------------------- > | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com > | Daniel D. Laskey Company, P.C.------231-723-8305 Voice > | 231-723-6097 Fax > | Certified Public Accountants > | 507 Water Street > | Manistee, MI 49660 > --------------------------------------------------------------------------------------- > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From james217b@bicycling.com Thu Aug 17 20:57:06 2000 From: james217b@bicycling.com (James Barr) Date: 17 Aug 2000 19:57:06 -0000 Subject: [Tutor] code Message-ID: <20000817195706.12123.qmail@musone.chek.com> This is day one of python programming for me, and I was wondering if anyone could let me know where I might be able to look at some source code for basic applications? Any help would be much appreciated, thanks! James _________________________________________________________________Get your own free e-mail. you@bikezone.com you@mountainbike.com you@bicycling.com http://www.bikezone.com/myzone/emailcentral/ From cwebster@nevada.edu Thu Aug 17 21:11:59 2000 From: cwebster@nevada.edu (Corran Webster) Date: Thu, 17 Aug 2000 13:11:59 -0700 Subject: [Tutor] MacPython Help! In-Reply-To: <399C309C.ECC3D844@appmicro.com> References: <399C309C.ECC3D844@appmicro.com> Message-ID: At 11:36 AM -0700 17/8/00, subal smith wrote: >I am a begginer programmer and need some help setting up python to work >on my Mac. I have downloaded Python 1.5.2 and have custom installed it >for a PPC. I followed a tutorial and created a "Hello World" script with >simple text and saved it as a .py in the same directory as the >Interpreter. The tutorial say's I should be able to drop the .py file >onto the Interpreter and it will Open and Run. BUT It Doesn't. >Do you have any idea what I did or am doing wrong? The problem is that SimpleText does not create files of type "TEXT" (becuse SimpleText files can have styles as well as plain text). MacPython isn't set up to deal with these file types. The solution is fairly simple, however: use the Python IDE included in 1.5.2. This will allow you to create and run files of the correct format easily, even interactively if you like. Regards, Corran From wilson@visi.com Thu Aug 17 22:32:26 2000 From: wilson@visi.com (Timothy Wilson) Date: Thu, 17 Aug 2000 16:32:26 -0500 (CDT) Subject: [Tutor] code In-Reply-To: <20000817195706.12123.qmail@musone.chek.com> Message-ID: On 17 Aug 2000, James Barr wrote: > This is day one of python programming for me, and I was wondering if anyone could let me know where I might be able to look at some source code for basic applications? Welcome to the list. Is there a particular type of application you're interested in? -Tim Hmmm... bicycling.com. What do you ride? -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 18 04:16:58 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 17 Aug 2000 20:16:58 -0700 (PDT) Subject: [Tutor] code In-Reply-To: <20000817195706.12123.qmail@musone.chek.com> Message-ID: On 17 Aug 2000, James Barr wrote: > This is day one of python programming for me, and I was wondering if > anyone could let me know where I might be able to look at some source > code for basic applications? Hello! I've seen snippets of examples in the introductions page on python.org. Here's the link to it: http://python.org/doc/Intros.html You should probably take a look at the tutorials on the Intros page; they're really good, and will help you get an orientation of what this Python stuff is all about. Also, when you download Python, you also get the source to many of the 'modules' that make up the Python library. It's always neat to see how the gurus write code. If you're interested, take a look at the Lib/ directory where you installed Python, along with the Library reference to tell you what each module does: http://python.org/doc/current/lib/lib.html If you run into any difficulties, free free to talk to us. Good luck! From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 18 04:28:33 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 17 Aug 2000 20:28:33 -0700 (PDT) Subject: [Tutor] MacPython Help! In-Reply-To: <399C309C.ECC3D844@appmicro.com> Message-ID: On Thu, 17 Aug 2000, subal smith wrote: > I am a begginer programmer and need some help setting up python to work > on my Mac. I have downloaded Python 1.5.2 and have custom installed it > for a PPC. I followed a tutorial and created a "Hello World" script with > simple text and saved it as a .py in the same directory as the > Interpreter. The tutorial say's I should be able to drop the .py file > onto the Interpreter and it will Open and Run. BUT It Doesn't. > Do you have any idea what I did or am doing wrong? Unfortunately, I'm not a Macintosh user, so I'm not quite sure how things work there. It might be that your script really is running, but may be finishing and quitting too fast to see. In that case, try this code: it'll wait until you press enter: ### print "Hello World!" tmp = raw_input("Please press enter to quit") ### You might want to talk to other Macintosh users at this mailing list: http://www.python.org/sigs/pythonmac-sig/ They'd probably be able to help you with Macintosh-Python stuff. Also, here's a site with a few MacPython links: http://dmoz.org/Computers/Systems/Macintosh/Development/Languages/Python/ From Danie Roux Fri Aug 18 09:16:09 2000 From: Danie Roux (Danie Roux) Date: Fri, 18 Aug 2000 10:16:09 +0200 (SAST) Subject: [Tutor] "Forward" declarations Message-ID: Hi all, How do I use a variable that is only declared later on in the file? Is global what I'm looking for? My question then is does 'global' make the variable global within the module or across the whole program? Danie. From SBrunning@trisystems.co.uk Fri Aug 18 09:06:08 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Fri, 18 Aug 2000 09:06:08 +0100 Subject: [Tutor] "Forward" declarations Message-ID: <31575A892FF6D1118F5800600846864D5B1012@intrepid> > From: Danie Roux [SMTP:s9806673@student.up.ac.za] > How do I use a variable that is only declared later on in the file? Is > global what I'm looking for? > > My question then is does 'global' make the variable global within the > module or across the whole program? > (Disclaimer - I don't know what I'm talking about.) I don't think that there is any such thing as 'declaring' a variable in Python - the first time you assign to a variable, it is created. If you try to refer to a variable that you have not yet assigned to, you get a name error. It doesn't matter *what* might happen further down the module, if you have not yet assigned to a name, you'll get a name error. (Remember, Python is interpreted, not compiled. Any code that has not yet been executed is just so much ASCII text.) Global makes a variable global within a module, but only once the global statement has been executed. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 18 10:53:40 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 18 Aug 2000 02:53:40 -0700 (PDT) Subject: [Tutor] "Forward" declarations In-Reply-To: Message-ID: On Fri, 18 Aug 2000, Danie Roux wrote: > How do I use a variable that is only declared later on in the file? Is > global what I'm looking for? > > My question then is does 'global' make the variable global within the > module or across the whole program? Yes, when you use the global statement, it tells Python to treat that variable as a global. There's a weird reason why it's necessary. It's a little hard to explain without seeing it. Here's code that demonstrates the problem (I'll be changing function() in these examples a lot.): ### g = "This is a global variable" def function(): print g g = "I will cause trouble!" print g if __name__ == '__main__': function() print g ### Looks coy and innocent, but here's what happens when you try to run it: ### [dyoo@einfall python]$ python trickyscope.py Traceback (innermost last): File "trickyscope.py", line 10, in ? function() File "trickyscope.py", line 4, in function print g NameError: g ### What happens is that when a function gets defined, Python performs a quick scan through to see which variables are local. In a function, if you do any assignments to a variable, it's a local variable. Because it sees the 'g = "I will cause trouble!"', it will assume that g is locally defined, and treats it as such. That's why we see that error message later, when it actually tries to resolve what g is within function(). If you want it to treat g as the global, then you'll need to use the global statement to inform Python to override the default rules: ### def function(): global g print g g = "I will cause trouble!" print g ### Then things will work as expected: ### [dyoo@einfall python]$ python trickyscope.py This is a global variable I will cause trouble! I will cause trouble! ### Next, if you had initially put: ### def function(): g = "I will cause trouble!" print g ### Here's what happens: ### [dyoo@einfall python]$ python trickyscope.py I will cause trouble! This is a global variable ### This is because of the assignment --- it'll treat g as local inside function(). So the global isn't affected, as we see when we come out of function(). Now, here's the kicker: ### def function(): print g ### ### [dyoo@einfall python]$ python trickyscope.py This is a global variable This is a global variable ### No assignment == g stays global. Is this evil or what? *grin* These weird situations are rare, to say the least. In any case, you should avoid reusing the name of a global anyway. I usually use globals as constants; I never reassign them. Because of that, I've never run into this situation in real code. Most likely, as long as you're not abusing global variables, you'll be ok. It is good to be aware of this; it's perverse, but it makes sense if you construct a model of what's happening. Good luck! From kjohnston@rcsi.ie Fri Aug 18 16:30:29 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Fri, 18 Aug 2000 16:30:29 +0100 Subject: [Tutor] Shelve Help! Message-ID: <9921C1171939D3119D860090278AECA2DEC643@EXCHANGE> Dear all, I have the following error traceback from this line of code: code: db = shelve.open('DataBase', 'w') error: Traceback (most recent call last): File "/users/kjohnston/programs/sequence.py", line 83, in ? main() File "/users/kjohnston/programs/sequence.py", line 69, in main seq.store() File "/users/kjohnston/programs/sequence.py", line 36, in store db = shelve.open('DataBase', 'w') File "/usr/local/lib/python1.6/shelve.py", line 157, in open return DbfilenameShelf(filename, flag) File "/usr/local/lib/python1.6/shelve.py", line 147, in __init__ Shelf.__init__(self, anydbm.open(filename, flag)) File "/usr/local/lib/python1.6/anydbm.py", line 83, in open raise error, "db type could not be determined" anydbm.error: db type could not be determined I am afraid I have no idea why I am getting this error, the DataBase file exists in the same directory as the program is ran from. Any help as always is appreciated. Thank you, Kate From subal@appmicro.com Fri Aug 18 16:47:08 2000 From: subal@appmicro.com (subal smith) Date: Fri, 18 Aug 2000 08:47:08 -0700 Subject: [Tutor] MacPython Help! Message-ID: <399D5A7B.BD8066EF@appmicro.com> I was hoping somebody could help me set up MacPython. I have installed it for my PPC but I don't understand how to run the .py files I create with BBEdit with the interpreter. The "Using Python 1.5 on the Mac" says I should be able to save the file in the same directory as the interpreter then drop it on the interpreter to have it run. BUT the interpreter does not recognize the files and will not let me drop them on it. Is there anybody that could give me a simple example of how to save and run Python scripts on a Mac. Also I wondered if, IDE, which was installed on my Mac is the same thing as IDLE. Thank you for helping a lost soul. Subal From alan.gauld@bt.com Fri Aug 18 18:01:02 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 18 Aug 2000 18:01:02 +0100 Subject: [Tutor] "Forward" declarations Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2A7@mbtlipnt02.btlabs.bt.co.uk> > How do I use a variable that is only declared later on in the file? Is > global what I'm looking for? Nope. Global brings a variable name from outside your function into your function(rather than creating a local) You can't use a variable before its created. You create one by assigning. Thus: foo = spam + 1 # error spam doesn't exist yet. foo = 5 + 7 # you just created foo with value 12 spam = foo # OK you created spam and gave it the same value as foo For more info on use of names and 'global' in Python try the namespaces chapter in my tutor or the official tutor: Alan G. http://www.crosswinds.net/~agauld From subal@enabledsites.com Fri Aug 18 18:35:42 2000 From: subal@enabledsites.com (Subal Smith) Date: Fri, 18 Aug 2000 10:35:42 -0700 Subject: [Tutor] MacPython Help! Message-ID: Hello, I was hoping somebody could help me set up MacPython. I have installed it for my PPC but I don't understand how to run the .py files I create with BBEdit with the interpreter. The "Using Python 1.5 on the Mac" says I should be able to save the file in the same directory as the interpreter then drop it on the interpreter to have it run. BUT the interpreter does not recognize the files and will not let me drop them on it. I did however save the file in BBEdit as an interpreter document and was able to then drop it on the interpreter and it ran. Is this how it's done? Is there anybody that could give me a simple example of how to save and run Python scripts on a Mac. Also I wondered if, IDE, which was installed on my Mac is the same thing as IDLE. Thank you for helping a lost soul. -- Subal Smith Web Developer www.enabledsites.com subal@enabledsites.com 831.464.9258 From billb@mousa.demon.co.uk Fri Aug 18 18:19:20 2000 From: billb@mousa.demon.co.uk (Bill Bedford) Date: Fri, 18 Aug 2000 18:19:20 +0100 Subject: [Tutor] MacPython Help! In-Reply-To: <399D5A7B.BD8066EF@appmicro.com> References: <399D5A7B.BD8066EF@appmicro.com> Message-ID: <119007082319159219951@mousa.demon.co.uk> At 8:47 am -0700 18/08/00, subal smith wrote: >I was hoping somebody could help me set up MacPython. I have installed >it for my PPC but I don't understand how to run the .py files I create >with BBEdit with the interpreter. The "Using Python 1.5 on the Mac" says >I should be able to save the file in the same directory as the >interpreter then drop it on the interpreter to have it run. BUT the >interpreter does not recognize the files and will not let me drop them >on it. >Is there anybody that could give me a simple example of how to save and >run Python scripts on a Mac. This should work with any file of type 'TEXT', check what type of file BBEdit is saving and if that is OK, then rebuild the desktop. >Also I wondered if, IDE, which was installed on my Mac is the same >thing as IDLE. No. IDLE does not work on the Mac (Tk issues) but it can be found in the :Tools folder. -- Bill Bedford "Why bother with such a big stone arch?" "It's just showing off. There's probably a sticker on the back saying 'My Other Grave Is A Porch'". From steve@spvi.com Fri Aug 18 18:55:13 2000 From: steve@spvi.com (Steve Spicklemire) Date: Fri, 18 Aug 2000 12:55:13 -0500 (EST) Subject: [Tutor] MacPython Help! In-Reply-To: (message from Subal Smith on Fri, 18 Aug 2000 10:35:42 -0700) References: Message-ID: <200008181755.MAA29567@mercury.spvi.com> Hi Subal In BBEdit you can save a file with the create 'Pyth'. Go to 'preferences'->FileTypes-> and 'add' a new file type. Just browse to the PythonInterpreter and it should find the correct type. You can also set the file type with ResEdit. There is also a script in the distribution that sets the file type, it's called 'fixfiletypes.py'. You might try that. -steve >>>>> "Subal" == Subal Smith writes: Subal> Hello, I was hoping somebody could help me set up Subal> MacPython. I have installed it for my PPC but I don't Subal> understand how to run the .py files I create with BBEdit Subal> with the interpreter. The "Using Python 1.5 on the Mac" Subal> says I should be able to save the file in the same Subal> directory as the interpreter then drop it on the Subal> interpreter to have it run. BUT the interpreter does not Subal> recognize the files and will not let me drop them on it. I Subal> did however save the file in BBEdit as an interpreter Subal> document and was able to then drop it on the interpreter Subal> and it ran. Is this how it's done? Is there anybody that Subal> could give me a simple example of how to save and run Subal> Python scripts on a Mac. Also I wondered if, IDE, which Subal> was installed on my Mac is the same thing as IDLE. Thank Subal> you for helping a lost soul. -- Subal Smith Web Developer Subal> www.enabledsites.com subal@enabledsites.com 831.464.9258 Subal> _______________________________________________ Tutor Subal> maillist - Tutor@python.org Subal> http://www.python.org/mailman/listinfo/tutor From DOUGS@oceanic.com Fri Aug 18 19:18:51 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Fri, 18 Aug 2000 08:18:51 -1000 Subject: [Tutor] Shelve Help! Message-ID: <8457258D741DD411BD3D0050DA62365907A2C9@huina.oceanic.com> > Dear all, > I have the following error traceback from this line of code: > code: db = shelve.open('DataBase', 'w') First, I don't think you want the 'w' as part of the open. As far as I know shelves are opened read/write with no additional parameter accepted. -------------snip--------- > File "/usr/local/lib/python1.6/anydbm.py", line > 83, in open > raise error, "db type could not be determined" > anydbm.error: db type could not be determined > > I am afraid I have no idea why I am getting this error, the > DataBase file > exists in the same directory as the program is ran from. Usually when this happens to me it means I didn't close the shelve correctly the last time I used it. On the other hand it could be related to the above inclusion of a 'w'. I've never found a way to recover a shelve if it is corrupted like this. Its one of my frustrations with shelves. On the other hand, if you get your program fully debugged it never seems to happen. One of the ways to work through the debug process might be to make a backup of the shelve every time you get ready to open it. That way, if it doesn't get closed you have something to revert to. > Any help as always is appreciated. > Thank you, Hope this wasn't off base. -Doug- > Kate > From gwperry@tva.gov Fri Aug 18 19:29:10 2000 From: gwperry@tva.gov (Perry, George W.) Date: Fri, 18 Aug 2000 14:29:10 -0400 Subject: [Tutor] Parsing Strings Message-ID: <2DACABE127B3D1119FC40000F8014EFC0184C779@chachaois4.cha.tva.gov> Is there a module with functionality similar to the REXX parse statement? Thanks George Perry From dlaskey@laskeycpa.com Fri Aug 18 19:50:26 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Fri, 18 Aug 2000 14:50:26 -0400 Subject: [Tutor] Strings and file saving Message-ID: <01C00924.04FAECC0@DAN> HEY YOU GUYS!! Objective: 1) Read this ASCII file that is space deliminated; 2) Pull out only the lines that have a '$' characters in the line; 3) Save the data to a new file. # ----------- Code ----------- # import sys and string import sys import string # get the appropriate data file in_file = open("data_file","r") # create the file to export the data to out_file = open("junk2.txt","w+") # read each line in the file for line in in_file.readlines(): if string.find(line,'$')>= 0: # # "print line" works well # #print line a = line # # write the new file you created to the file "junk2.txt" out_file.write(a) out_file.close() in_file.close() # ----------- End of Code -------------- Traceback (innermost last): File "today6.py", line 19, in ? out_file.write(a) NameError: a I think I am a classic case of PDD ... Python Deficit Disorder :). At best I'm one of those slow learners, so bear with me, please. Dan --------------------------------------------------------------------------------------- | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.------231-723-8305 Voice | 231-723-6097 Fax | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 --------------------------------------------------------------------------------------- From shaleh@valinux.com Fri Aug 18 20:15:35 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 18 Aug 2000 12:15:35 -0700 (PDT) Subject: [Tutor] Parsing Strings In-Reply-To: <2DACABE127B3D1119FC40000F8014EFC0184C779@chachaois4.cha.tva.gov> Message-ID: On 18-Aug-2000 Perry, George W. wrote: > Is there a module with functionality similar to the REXX parse statement? > what is the "REXX" parse statement? To modules to look at in python are 'string' and 're'. BTW, my father's name is George A. Perry, he works for ftsclant I believe. (-: From shaleh@valinux.com Fri Aug 18 20:20:02 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 18 Aug 2000 12:20:02 -0700 (PDT) Subject: [Tutor] Strings and file saving In-Reply-To: <01C00924.04FAECC0@DAN> Message-ID: ># read each line in the file > for line in in_file.readlines(): > if string.find(line,'$')>= 0: ># # "print line" works well ># #print line > a = line ># # write the new file you created to the file "junk2.txt" > out_file.write(a) > out_file.close() > in_file.close() a only exists in the if block, which out_file.write() is not in. This is probably a logic error. Even if a did exist, if the if was not true, you would write an empty line or worse, the last line in a. To ensure a does exist do the following: a = "" if blah: a = do_string_stuff out_file.write(a) The same idea is often used to make an empty list, dictionary, etc for a loop to populate. From timc@ans.net Fri Aug 18 20:27:36 2000 From: timc@ans.net (Tim Condit) Date: Fri, 18 Aug 2000 15:27:36 -0400 (EDT) Subject: [Tutor] Strings and file saving In-Reply-To: <01C00924.04FAECC0@DAN> Message-ID: Hi Dan, I took out all the comments, ran it again, and it sort of works for me: import sys import string in_file = open("data_file","r") out_file = open("junk2.txt","w+") for line in in_file.readlines(): if string.find(line,'$')>= 0: a = line out_file.write(a) out_file.close() in_file.close() ---------------------------------------- [timc@neutrino ~] cat data_file hi there I'm a line with a $ sign. and I'm not. ---------------------------------------- [timc@neutrino ~] python dan.py [timc@neutrino ~] cat junk2.txt hi there I'm a line with a $ sign. hi there I'm a line with a $ sign. hi there I'm a line with a $ sign. ---------------------------------------- Okay, so on first glance, what appears to be happening is that all three lines are matching.. I don't have time to look at it much closer at the moment, though. Odd that I got a different result than you with no modification. good luck, Tim Condit UUNet Network Quality Services 734-214-7548 tcondit@uu.net On Fri, 18 Aug 2000, Daniel D. Laskey, CPA wrote: > HEY YOU GUYS!! > > Objective: > 1) Read this ASCII file that is space deliminated; > 2) Pull out only the lines that have a '$' characters in the line; > 3) Save the data to a new file. > > # ----------- Code ----------- > # import sys and string > import sys > import string > > # get the appropriate data file > in_file = open("data_file","r") > > # create the file to export the data to > out_file = open("junk2.txt","w+") > > # read each line in the file > for line in in_file.readlines(): > if string.find(line,'$')>= 0: > # # "print line" works well > # #print line > a = line > # # write the new file you created to the file "junk2.txt" > out_file.write(a) > out_file.close() > in_file.close() > # ----------- End of Code -------------- > > Traceback (innermost last): > File "today6.py", line 19, in ? > out_file.write(a) > NameError: a > > I think I am a classic case of PDD ... Python Deficit Disorder :). > At best I'm one of those slow learners, so bear with me, please. > > Dan > > --------------------------------------------------------------------------------------- > | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com > | Daniel D. Laskey Company, P.C.------231-723-8305 Voice > | 231-723-6097 Fax > | Certified Public Accountants > | 507 Water Street > | Manistee, MI 49660 > --------------------------------------------------------------------------------------- > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From DOUGS@oceanic.com Fri Aug 18 20:45:57 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Fri, 18 Aug 2000 09:45:57 -1000 Subject: [Tutor] Strings and file saving Message-ID: <8457258D741DD411BD3D0050DA62365907A2CB@huina.oceanic.com> > I think I am a classic case of PDD ... Python Deficit Disorder :). > At best I'm one of those slow learners, so bear with me, please. > > Dan Its more ADD (not attention, algorithm). I used to be there too, and still am for more advanced questions. It's a condition that is cured by exposure to cool solutions. Usually administered in a boring set of college classes, but much easier on the stomach if taken in measured doses of reading Python code by the gurus. > Objective: > 1) Read this ASCII file that is space deliminated; You got this right > 2) Pull out only the lines that have a '$' characters in the line; This needs a new idea. Try this: # outside of the loop set up a variable to hold the results result = "" # in this case I'm going to build a string because # thats what I need to write out. The readlines # method gave you a list of strings, so if you # really needed to work with hat list you could make # this result = [], the empty list. # read each line in the file for line in in_file.readlines(): if '$' in line: # Untested but I think this does the same thing # your test did. Its probably faster if it works. > # # "print line" works well > # #print line > a = line # its usually nicer to use a descriptive variable # name. Six months from now you'll know why. result = result + line # put the current line on the end of # the result till now. If result was # a list this would be result.append(line) # by the time you're program gets to here the variable 'result' holds # everything you want. > 3) Save the data to a new file. I'd put together all the result and write it in one fell swoop to the file. That may just be me. It should be possible to do it the way you had it within the inner loop. I think its faster if its all done at once. More comments below though. out_file.write(result) # should do it, just be sure its at the right indent level. > > # ----------- Code ----------- > # import sys and string > import sys > import string > > # get the appropriate data file > in_file = open("data_file","r") > > # create the file to export the data to > out_file = open("junk2.txt","w+") > > # read each line in the file > for line in in_file.readlines(): > if string.find(line,'$')>= 0: > # # "print line" works well > # #print line > a = line > # # write the new file you created to the file "junk2.txt" > out_file.write(a) > out_file.close() > in_file.close() > # ----------- End of Code -------------- > > Traceback (innermost last): > File "today6.py", line 19, in ? > out_file.write(a) > NameError: a The reason this gives a traceback is that the first time through the test loop the line didn't have a '$' in it. Therefore 'a' was not set, in fact that line of code wasn't even run. You've put the write statement at the same indent level as the if that is finding the '$' character. This means you're trying to write for every line in the input. You just want to write for every line that has the '$' so the write as you have it would have to be inside the test. The way it is, if the first line had a $, you wouldn't have gotten the traceback, it would have run, but you would have gotten a repeat of the first line for every non-'$' line read. each '$' line would have been repeated in this way. Hope this has been helpful. This tutor list is definately the best place to work on these kinds of questions. -Doug- From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 18 21:03:34 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 18 Aug 2000 13:03:34 -0700 (PDT) Subject: [Tutor] Strings and file saving In-Reply-To: <01C00924.04FAECC0@DAN> Message-ID: > # read each line in the file > for line in in_file.readlines(): > if string.find(line,'$')>= 0: > # # "print line" works well > # #print line > a = line > # # write the new file you created to the file "junk2.txt" > out_file.write(a) The error is one of indentation --- you have the out_file.write(a) as a statement after the if block. This means that it'll try to write that line, regardless if it found a line. Let's say that our first line didn't have a '$'. We'll pass right by that if statement, and... > Traceback (innermost last): > File "today6.py", line 19, in ? > out_file.write(a) > NameError: a Good luck to you. From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 18 23:37:19 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 18 Aug 2000 15:37:19 -0700 (PDT) Subject: [Tutor] Parsing Strings In-Reply-To: <2DACABE127B3D1119FC40000F8014EFC0184C779@chachaois4.cha.tva.gov> Message-ID: On Fri, 18 Aug 2000, Perry, George W. wrote: > Is there a module with functionality similar to the REXX parse statement? I'm not familiar with REXX's parse statement. I took a look at: http://www.spnc.demon.co.uk/rexx/rexcmdbd.htm to get a feel for what the parse command does. From what it looks like, you could possibly use string.split(), but that's an unsatisfactory answer. There is no built-in that does all that REXX's parse does, unfortunately. However, this will interest you: I did find something by Tim Peters: http://starship.python.net/crew/amk/archives/early-poo/000049.html where he talks about a REXX parse module implementation that he wrote. You might want to talk to him about it. The source code looks like it's all there, so you should be able to work with it. From dyoo@hkn.EECS.Berkeley.EDU Sat Aug 19 01:44:40 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 18 Aug 2000 17:44:40 -0700 (PDT) Subject: [Tutor] code In-Reply-To: <20000817195706.12123.qmail@musone.chek.com> Message-ID: On 17 Aug 2000, James Barr wrote: > This is day one of python programming for me, and I was wondering if > anyone could let me know where I might be able to look at some source > code for basic applications? Followup: Ah, Parnassus is back up! That's a relief. Ok, you'll want to look here for applications: http://www.vex.net/parnassus/ It's called the Vaults of Parnassus, and it holds the repository for 3rd party Python code. It's quite good. From jstok@bluedog.apana.org.au Sat Aug 19 05:10:33 2000 From: jstok@bluedog.apana.org.au (Jason Stokes) Date: Sat, 19 Aug 2000 14:10:33 +1000 Subject: [Tutor] Parsing Strings References: Message-ID: <399E08B9.E04C8D11@bluedog.apana.org.au> Sean 'Shaleh' Perry wrote: > > On 18-Aug-2000 Perry, George W. wrote: > > Is there a module with functionality similar to the REXX parse statement? > > > > what is the "REXX" parse statement? To modules to look at in python are > 'string' and 're'. It's a simple pattern matching syntax that can be used to split text into variables according to a pattern (eg "parse pull"), match text, and so on. It's easy to split a string with individual tokens separated by whitespace into a set of variables using "parse". The answer is yes, using the regular expression package "re." The regular expression syntax is more complex than the parse syntax, but also more powerful. At a pinch you could write your own "parse" module, since it's easy enough to translate parse statements into regular expressions. From peterc73@pacbell.net Sat Aug 19 05:23:42 2000 From: peterc73@pacbell.net (Peter Curran) Date: Fri, 18 Aug 2000 21:23:42 -0700 Subject: [Tutor] cgi question Message-ID: <002601c00995$488b7510$c158c93f@pcurran> Hello everyone. I am having a problem with the feedback.py program which begins on page 276 of O'Reilly's Learning Python. Basically, the script processes input from an HTML form, returns a confirmtation form, and writes the input to disk. I've typed the script in exactly as it appears, checked it for errors within the Python IDE, referenced the path and name of the script in the ACTION attribute of my HTML form. The form displays ok in the browser, so I input my data and click "submit." Instead of displaying the results from "gush" or "whimper" -- the routines which process the cgi input, the whole python script appears in the browser -- just exactly as it appears in the Python IDE. If this is clue enough for you, stop reading. Otherwise, read on. I noticed that the O'Reilly explanation on pg. 279 says: "To start, the first line of the program needs to refer to the python executable. ... The second line includes import cgi ..." I'm confused because the first line of the script IS the import cgi line, and there IS NO other first line in the book. Is something missing from their code snippet, or have I neglected to do something very basic to scripting with Python? Anyone know what the first line ought to be, or what I'm doing wrong? Thanks in advance to whomever answers, thanks also to the list admins. Via con huevos. Peter Curran UniLink Inc. (415) 751-1285 (h/w) (415) 378-9663 (m) (425) 928-5312 (f) From spirou@aragne.com Sat Aug 19 05:58:14 2000 From: spirou@aragne.com (Denis) Date: Sat, 19 Aug 2000 06:58:14 +0200 Subject: [Tutor] cgi question In-Reply-To: <002601c00995$488b7510$c158c93f@pcurran>; from peterc73@pacbell.net on Fri, Aug 18, 2000 at 09:23:42PM -0700 References: <002601c00995$488b7510$c158c93f@pcurran> Message-ID: <20000819065814.B29464@aragne.com> Le Fri, Aug 18, 2000 at 09:23:42PM -0700, Peter Curran pianota: > Hello everyone. > > I noticed that the O'Reilly explanation on pg. 279 says: "To start, the > first line of the program needs to refer to the python executable. ... > The second line includes import cgi ..." > Yes, you have to prepend a #!path_to_python as a first line for example : #!c:\python\python.exe or #!/usr/bin/env python or whatever Check the access rights on the file, too. Good luck. Denis -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From dyoo@hkn.EECS.Berkeley.EDU Sat Aug 19 06:04:17 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 18 Aug 2000 22:04:17 -0700 (PDT) Subject: [Tutor] cgi question In-Reply-To: <002601c00995$488b7510$c158c93f@pcurran> Message-ID: > Instead of displaying the results from "gush" or "whimper" -- the > routines which process the cgi input, the whole python script appears in > the browser -- just exactly as it appears in the Python IDE. If this is > clue enough for you, stop reading. Otherwise, read on. Stopped. *grin* Ok, the answer depends on what server you're running on; What's happening is that your web server is treating those files as plain text, and not as executable content. You'll need to do some additional setup to associate .py files as CGI scripts. If you're using IIS, take a look at section 8.1 in the Python FAQ for details: http://www.python.org/doc/FAQ.html#8.1 If it's Apache, you'll want to first tell Python that ".py" is a perfectly good extension for a cgi script. Look at httpd.conf for a line that says "AddHandler cgi-script", and add another extension to the list, like this: ### # To use CGI scripts: AddHandler cgi-script .cgi .py ### After this, you might still need to do a few more changes to Apache, since CGI privleges are usually only allowed in certain directories, for safety's sake. For me, this is /home/httpd/cgi-bin, but you can add more permissible settings, I think, using the ScriptAlias configuration line or the ExecCGI option. It might be best, though, just to make sure that your scripts work in cgi-bin first. Place them there, and see if they work. You can always relax your security restrictions afterwards, when you feel more comfortable. Finally, if you're running on a UNIX system, you'll need to add in the front of your script something like: #!/usr/bin/env python at the front of the file, before anything else. That line tells the system how to execute your Python program. The reason for this is because any language can be used to run a CGI script. Analogously, the Perl people usually put #!/usr/bin/perl -w From Moshe Zadka Sat Aug 19 10:31:02 2000 From: Moshe Zadka (Moshe Zadka) Date: Sat, 19 Aug 2000 12:31:02 +0300 (IDT) Subject: [Tutor] Strings and file saving In-Reply-To: <01C00924.04FAECC0@DAN> Message-ID: On Fri, 18 Aug 2000, Daniel D. Laskey, CPA wrote: > import sys > import string > > # get the appropriate data file > in_file = open("data_file","r") > > # create the file to export the data to > out_file = open("junk2.txt","w+") > > # read each line in the file > for line in in_file.readlines(): > if string.find(line,'$')>= 0: > # # "print line" works well Instead of: > # #print line > a = line > # # write the new file you created to the file "junk2.txt" > out_file.write(a) Why not just: > out_file.write(line) (Your problem was that you tried to call out_file.write(a) before you ever assigned to a: your first line had no '$'. Be thankful, for otherwise you'd have a nasty bug: a line with a '$' would be printed from when it was read until the next one was read, once for every line. IOW, the output for: 1$ 2 3$ Would be 1$ 1$ 3$ Instead of 1$ 3$ -- Moshe Zadka There is no IGLU cabal. http://advogato.org/person/moshez From John Seymour" This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C009C6.544422E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am haveing a problem getting Idle to work properly on my windows = system. Any help will be appreciated.=20 I have downloaded python 1.52 for windows. I have windows 98SE. The = program runs fine but every time I close Idle I get an invalid page = fault in arhook32.dll. I have done some traceing in system information = and arhook32.dll is listed as a system hook. The file belongs to = earthlink5.0. I am running a dual boot system with windows and linux. I can use python = fine in linux, but would like to be able to use it in windows also. = Thank you. ------=_NextPart_000_0007_01C009C6.544422E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am haveing a problem getting Idle to = work=20 properly on my windows system. Any help will be appreciated. =
I have downloaded python 1.52 for = windows. I have=20 windows 98SE. The program runs fine but every time I close Idle I get an = invalid=20 page fault in arhook32.dll. I have done some traceing in system = information and=20 arhook32.dll is listed as a system hook. The file belongs to=20 earthlink5.0.
I am running a dual boot system with = windows and=20 linux. I can use python fine in linux, but would like to be able to use = it in=20 windows also. Thank you.
------=_NextPart_000_0007_01C009C6.544422E0-- From tim_one@email.msn.com Sat Aug 19 19:18:56 2000 From: tim_one@email.msn.com (Tim Peters) Date: Sat, 19 Aug 2000 14:18:56 -0400 Subject: [Tutor] Problem running idle in windows In-Reply-To: <000a01c009e7$dcbdde60$341445cf@computer> Message-ID: [John Seymour] > I am haveing a problem getting Idle to work properly on my windows > system. Any help will be appreciated. > I have downloaded python 1.52 for windows. I have windows 98SE. The > program runs fine but every time I close Idle I get an invalid page > fault in arhook32.dll. Sounds annoying but harmless to me. Do yourself a favor and try to live with it: tracking down Windows conflicts can consume your life <0.4 wink>. > I have done some traceing in system information and arhook32.dll is > listed as a system hook. The file belongs to earthlink5.0. Probably explains why I've never heard of this before! It's probably a conflict between the Earthlink software and the Tk display routines (which are what draw the IDLE windows), and would require a bona fide Tk expert's help to resolve. Here in Pythonland, we don't write Tk (Scriptics does), we just use it . > I am running a dual boot system with windows and linux. I can use > python fine in linux, but would like to be able to use it in windows > also. Thank you. If you don't have any real use for the earthlink stuff, uninstalling it will probably make the problem go away. Else, as above, you need to find someone expert in the internals of both arhook32.dll and Tk; Python almost certainly has nothing to do with this (and I assume you can run Python scripts fine from a DOS box, right?). From dyoo@hkn.EECS.Berkeley.EDU Sat Aug 19 21:02:35 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sat, 19 Aug 2000 13:02:35 -0700 (PDT) Subject: [Tutor] Re: [Python-Help] practice problems In-Reply-To: <008401c009f7$659353a0$352a06d5@BillJamesll> Message-ID: On Sat, 19 Aug 2000, JamesBill wrote: > Is there any way that, you could send me some example problems or > practice excercises. So that, I can try to solve them? Hello! You might want to ask the tutor@python.org list too about this one too. I'll forward the message there too, so others might give some input on these ones. For some of these problems, it'll be useful to know that you can turn a string into a list of characters: >>> list("this is a list") ['t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'l', 'i', 's', 't'] and you can turn it back by using string.join(). As a disclaimer, these example problems are not my own; I just remember hearing them, and found them cute, so here goes: 1. Let's say I have a list of words, and I want to find all the "Hebrew" words. We'll define a "Hebrew" word to be one without any vowels. For example: "xyzzy" could be considered a Hebrew word, if we don't count 'y' as a vowel. Can you write a program to tell the user if a word has the Hebrew nature or not? 2. Have you heard of ROT13? It's a very funny encryption scheme that scrambles a word in a Caesar-cypher style. Each letter of a word will be "rotated" by 13, that is: a -> n b -> o ... m -> z n -> a o -> b For example: >> rot13("foobar") 's b b o n e' >>> rot13("alphatransparency") 'n y c u n g e n a f c n e r a p l' (Hmm... I forgot to tell string.join() not to use spaces in joining. Ooops.) Can you write a program that will give back the ROT13 of a word? What's also neat about this problem is that if you ROT13 something twice, you'll get back your original word. >>> rot13("sbbone") 'f o o b a r' Also, ROT13 is used in USENET newsgroups a lot, when sensitive material is being expressed. The ord() and chr() functions might be useful in solving this problem. 3. This one is challenging: There's a classical CS problem called the anagram solver. Let me see if I can paraphrase the question properly. First, I'd better say what an anagram is, just for clarity: an anagram is a rearrangement of the letter of a word, so that it too is a word. I have examples of anagrams below. Let's say that you're given a list of dictionary words, one per line. Also, let's say that you'd like to find all of the anagrams of a single word. Your program should lookup the words in the dictionary, and show which words are anagrams. For example, here are a few anagrams: liens, lines defrost, frosted earls, lares, laser, reals pares, parse, pears, rapes, reaps, spare, spear drawer, redraw, rewar, warder, warred alger, glare, lager, large, regal I don't know, I've always found this program fun, because it has nothing to do with math, and once you figure out how to do it, it's not hard. There is a direct way to solve this, but you'll find that it will go too slow if the dictionary is huge. There's a very nice way of solving this problem, and it involves using sort(). If you need a hint, then email us again. Good luck! From andreq@mindgate.net Sun Aug 20 08:25:20 2000 From: andreq@mindgate.net (Andre Quintos) Date: Sun, 20 Aug 2000 15:25:20 +0800 Subject: [Tutor] newbie problems with running scripts Message-ID: <002f01c00a77$d30f86d0$a51ea2d0@andre> Hi. I biought this book from O'reilly called Learning Python and am following all their excercises. So I went to the python.org site and downloaded everything I needed (I use a Win2K system). I have installed the python 1.5.2 and pythonwin. I use these programs with the excercises in the book. While in pythonwin, I create the file called myfile.py which contains the following: title = "The Meaning of Life" The book then tells me to do this: >>>import myfile.py >>>print myfile.title When I do the first statement I get this error in pythonwin: Traceback (innermost last): File "", line 1, in ? ImportError: No module named py What could be the problem here? Is it a problem with the installation of the programs or the problem with the code? Or is there something I should do to make python and pythonwin work properly in win2k? Thanks for the help (in advance) Andre those who believe in free will make the best puppets of all. -- Lucifer #3 From richard_chamberlain@ntlworld.com Sun Aug 20 08:56:01 2000 From: richard_chamberlain@ntlworld.com (Richard Chamberlain) Date: Sun, 20 Aug 2000 08:56:01 +0100 Subject: [Tutor] newbie problems with running scripts References: <002f01c00a77$d30f86d0$a51ea2d0@andre> Message-ID: <399F8F11.1C671690@ntlworld.com> Hi Andre, Firstly you should import with the extension so it should be: import myfile Secondly you might find that python cannot find your file. The reason is that python looks in certain directories. There are two ways for you to get round this. The easiest way for you is to use import on one of the pythonwin menus. The other way is to do this at the interactive shell: import sys print sys.path That should give you a list of locations python is looking in. sys.path.append('c:\\location\\to\\your\\file') should enable you to type just: import myfile Richard Andre Quintos wrote: > > Hi. > > I biought this book from O'reilly called Learning Python and am following > all their excercises. So I went to the python.org site and downloaded > everything I needed (I use a Win2K system). > > I have installed the python 1.5.2 and pythonwin. I use these programs with > the excercises in the book. > > While in pythonwin, I create the file called myfile.py which contains the > following: > > title = "The Meaning of Life" > > The book then tells me to do this: > > >>>import myfile.py > >>>print myfile.title > > When I do the first statement I get this error in pythonwin: > > Traceback (innermost last): > File "", line 1, in ? > ImportError: No module named py > > What could be the problem here? Is it a problem with the installation of the > programs or the problem with the code? Or is there something I should do to > make python and pythonwin work properly in win2k? > > Thanks for the help (in advance) > > Andre > > those who believe in free will make the best puppets of all. > -- Lucifer #3 > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From richard_chamberlain@ntlworld.com Sun Aug 20 09:11:13 2000 From: richard_chamberlain@ntlworld.com (Richard Chamberlain) Date: Sun, 20 Aug 2000 09:11:13 +0100 Subject: [Tutor] newbie problems with running scripts References: <002f01c00a77$d30f86d0$a51ea2d0@andre> <399F8F11.1C671690@ntlworld.com> Message-ID: <399F92A1.C115CFC8@ntlworld.com> Sorry that should have read shouldn't import with the extension or should import without the extension take your pick Richard Richard Chamberlain wrote: > > Hi Andre, > > Firstly you should import with the extension so it should be: > > import myfile > > Secondly you might find that python cannot find your file. The reason is > that python looks in certain directories. There are two ways for you to > get round this. The easiest way for you is to use import on one of the > pythonwin menus. The other way is to do this at the interactive shell: > > import sys > print sys.path > > That should give you a list of locations python is looking in. > > sys.path.append('c:\\location\\to\\your\\file') > > should enable you to type just: > > import myfile > > Richard > > Andre Quintos wrote: > > > > Hi. > > > > I biought this book from O'reilly called Learning Python and am following > > all their excercises. So I went to the python.org site and downloaded > > everything I needed (I use a Win2K system). > > > > I have installed the python 1.5.2 and pythonwin. I use these programs with > > the excercises in the book. > > > > While in pythonwin, I create the file called myfile.py which contains the > > following: > > > > title = "The Meaning of Life" > > > > The book then tells me to do this: > > > > >>>import myfile.py > > >>>print myfile.title > > > > When I do the first statement I get this error in pythonwin: > > > > Traceback (innermost last): > > File "", line 1, in ? > > ImportError: No module named py > > > > What could be the problem here? Is it a problem with the installation of the > > programs or the problem with the code? Or is there something I should do to > > make python and pythonwin work properly in win2k? > > > > Thanks for the help (in advance) > > > > Andre > > > > those who believe in free will make the best puppets of all. > > -- Lucifer #3 > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://www.python.org/mailman/listinfo/tutor > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From andreq@mindgate.net Sun Aug 20 10:05:04 2000 From: andreq@mindgate.net (Andre Quintos) Date: Sun, 20 Aug 2000 17:05:04 +0800 Subject: [Tutor] newbie problems with running scripts References: <002f01c00a77$d30f86d0$a51ea2d0@andre> <399F8F11.1C671690@ntlworld.com> Message-ID: <003a01c00a85$ed47aec0$fe1ea2d0@andre> Hi Richard. Thanks for the advice. I tried your suggestions but I still get the same error kind of errors. Thanks again. Does anyone out there use pythonwin on windows 2000? Andre ----- Original Message ----- From: "Richard Chamberlain" To: "Andre Quintos" Cc: Sent: Sunday, August 20, 2000 3:56 PM Subject: Re: [Tutor] newbie problems with running scripts > Hi Andre, > > Firstly you should import with the extension so it should be: > > import myfile > > Secondly you might find that python cannot find your file. The reason is > that python looks in certain directories. There are two ways for you to > get round this. The easiest way for you is to use import on one of the > pythonwin menus. The other way is to do this at the interactive shell: > > import sys > print sys.path > > That should give you a list of locations python is looking in. > > sys.path.append('c:\\location\\to\\your\\file') > > should enable you to type just: > > import myfile > > Richard > > > Andre Quintos wrote: > > > > Hi. > > > > I biought this book from O'reilly called Learning Python and am following > > all their excercises. So I went to the python.org site and downloaded > > everything I needed (I use a Win2K system). > > > > I have installed the python 1.5.2 and pythonwin. I use these programs with > > the excercises in the book. > > > > While in pythonwin, I create the file called myfile.py which contains the > > following: > > > > title = "The Meaning of Life" > > > > The book then tells me to do this: > > > > >>>import myfile.py > > >>>print myfile.title > > > > When I do the first statement I get this error in pythonwin: > > > > Traceback (innermost last): > > File "", line 1, in ? > > ImportError: No module named py > > > > What could be the problem here? Is it a problem with the installation of the > > programs or the problem with the code? Or is there something I should do to > > make python and pythonwin work properly in win2k? > > > > Thanks for the help (in advance) > > > > Andre > > > > those who believe in free will make the best puppets of all. > > -- Lucifer #3 > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://www.python.org/mailman/listinfo/tutor > From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 20 10:37:46 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 20 Aug 2000 02:37:46 -0700 (PDT) Subject: [Tutor] newbie problems with running scripts In-Reply-To: <003a01c00a85$ed47aec0$fe1ea2d0@andre> Message-ID: On Sun, 20 Aug 2000, Andre Quintos wrote: > I tried your suggestions but I still get the same error kind of errors. Where are you storing myfile.py? This is important, since Python needs to be told where to look for modules. By default, it's just going to look at the standard distribution's /Lib/ directory, as well as the current directory. You need to override the default paths, so that Python will be able to see myfile.py too. Once you have the paths set up right, then everything should work. Theoretically. *grin* I think there are two ways of setting up the paths, the first through the system registry, and the second through the PYTHONPATH environment variable. I'm only familiar with the environment variable way, so I'll talk about that one only. If you're not familiar with setting up environment variables, read ahead. Otherwise, please forgive me for being pedantic. I'll assume that your installation is stored in 'C:\Program Files\Python1.5'. Right click on My Computer, and go to the Properties screen. You should see a tab called Environmental Variables. (it should be right next to the User Profiles tab, I think.) Once you're there, add a new environment variable called PYTHONPATH, with the value 'C:\[wherever your document path is].' Afterwards, move myfile.py into your document path, and you should be fine with the imports. You can always add more paths to PYTHONPATH, if you like storing your modules somewhere else. I hope this is helpful. From JamesBill@freenet.de Sun Aug 20 12:10:04 2000 From: JamesBill@freenet.de (JamesBill) Date: Sun, 20 Aug 2000 13:10:04 +0200 Subject: [Tutor] practice problems Message-ID: <000c01c00a97$31e36720$853706d5@BillJamesll> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C00AA7.F4813AE0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, Is there any may that, you could send me some example problems or = practice exercises. So that, I may try to solve them? ------=_NextPart_000_0009_01C00AA7.F4813AE0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello,
Is there any may that, you could send = me some=20 example problems or practice exercises.  So that, I may try to = solve=20 them?
------=_NextPart_000_0009_01C00AA7.F4813AE0-- From FxItAL@aol.com Sun Aug 20 18:52:57 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Sun, 20 Aug 2000 13:52:57 EDT Subject: [Tutor] Newbie question on Self, Master and others. Message-ID: <20000820175300.610651CEAD@dinsdale.python.org> Hello All, I'm some experiance with VB and am new to Python. In reviewing some code examples I've come across the "def __init__()" function with several different, what seems to me are argument options. IE: self, master, master=None. Would someone explain what these are for and how they are Python interprets them. Thanks for your time, Al From FxItAL@aol.com Sun Aug 20 19:10:46 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Sun, 20 Aug 2000 14:10:46 EDT Subject: [Tutor] Newbie question on passing a variable Message-ID: <20000820181055.30D571D012@dinsdale.python.org> Hello All, I've written the following to try and get input from the user. This works fine, my problem is passing it the variable InputMin in the other module - timer1.py. from Tkinter import * root = Tk() root.title('Top Level') e = StringVar() global e d = Entry(root, textvariable=e, width=10) d.pack() var = e.get() def z(): var = e.get() import timer1 timer1.TimeFunc(var) f = Button(root, text='Print',command=z) f.pack(side=RIGHT) root.mainloop() Thie timer1.py module: def TimeFunc(var): from time import * me = time() you=localtime(me) ClockMin=you[4] #Represents Minute on Clock ClockHour=you[3] #Represents Hour on Clock InputMin=var InputHour=you[3] if ClockMin Message-ID: <3.0.6.32.20000820115020.00829210@operamail.com> >Message: 6 >From: "Andre Quintos" >To: "Richard Chamberlain" >Cc: >Subject: Re: [Tutor] newbie problems with running scripts >Date: Sun, 20 Aug 2000 17:05:04 +0800 >charset="iso-8859-1" > >Hi Richard. > >Thanks for the advice. > >I tried your suggestions but I still get the same error kind of errors. > >Thanks again. > >Does anyone out there use pythonwin on windows 2000? > >Andre Andre. I'm win95 and had the same problem - I changed the autoexec.bat file to include the path to my modules - I assume win2k uses an autoexec.bat file as well?? here's the line I added to the top of my autoexec.bat file: SET PYTHONPATH=C:\PROGRA~1\PYTHON\MODULES this path is Program Files\Python\Modules everything worked just fine after a restart :) m baker From isopodgraphics@hotmail.com Sun Aug 20 19:49:13 2000 From: isopodgraphics@hotmail.com (isopod graphics) Date: Sun, 20 Aug 2000 18:49:13 GMT Subject: [Tutor] Outputting to text files Message-ID: Hi Guys, It's been a while since I asked a question(about a week now!he he he!. Now I've stumbled to another problem that I'm sure other have easily avoided; here it goes: I'm writing a program that does some math calculations like slope calculaion etc., now I wanna save or output the results to a text file.How do I go about doing that?I know how to read from a text file and print it on the screen but I don't know how to save the results to a new file. Another one (sorry about this very simple Algebra question) how do you compute the y-intercept if you were just given the coordinates of 2 points (x1,y1 and x2,y2)? thanks, Albert www.isopod-graphics.com ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From scarblac@pino.selwerd.nl Sun Aug 20 20:11:25 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 20 Aug 2000 21:11:25 +0200 Subject: [Tutor] Outputting to text files In-Reply-To: ; from isopodgraphics@hotmail.com on Sun, Aug 20, 2000 at 06:49:13PM +0000 References: Message-ID: <20000820211125.A1731@pino.selwerd.nl> On Sun, Aug 20, 2000 at 06:49:13PM +0000, isopod graphics wrote: > It's been a while since I asked a question(about a week now!he he he!. > Now I've stumbled to another problem that I'm sure other have easily > avoided; here it goes: I'm writing a program that does some math > calculations like slope calculaion etc., now I wanna save or output the > results to a text file.How do I go about doing that? Similar to reading from a file, except you open the file for "w" (write) instead of "r" (read): f = open("menu","w") f.write("spam, spam, spam and eggs\n") f.write("spam, eggs, spam, spam, bacon and spam\n") f.close() You can also open it "a" to append to a file (if you open for write, the first thing that happens is that the old file is emptied, if it exists). > Another one (sorry about this very simple Algebra > question) how do you compute the y-intercept if you were just given the > coordinates of 2 points (x1,y1 and x2,y2)? I'm not sure what the y-intercept is. You mean the point in the middle of those two? That's just the average point, ie ((x1+x2)/2, (y1+y2)/2). -- Remco Gerlich, scarblac@pino.selwerd.nl From scarblac@pino.selwerd.nl Sun Aug 20 20:20:12 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 20 Aug 2000 21:20:12 +0200 Subject: [Tutor] Newbie question on passing a variable In-Reply-To: <20000820181055.30D571D012@dinsdale.python.org>; from FxItAL@aol.com on Sun, Aug 20, 2000 at 02:10:46PM -0400 References: <20000820181055.30D571D012@dinsdale.python.org> Message-ID: <20000820212012.B1731@pino.selwerd.nl> On Sun, Aug 20, 2000 at 02:10:46PM -0400, FxItAL@aol.com wrote: > Hello All, > > I've written the following to try and get input from the user. This works fine, my problem is passing it the variable InputMin in the other module - timer1.py. > > from Tkinter import * > > root = Tk() > root.title('Top Level') > > e = StringVar() > global e This isn't necessary, you don't declare it inside something, it's already global in the module. > d = Entry(root, textvariable=e, width=10) > d.pack() > var = e.get() > > def z(): > var = e.get() > import timer1 > timer1.TimeFunc(var) > f = Button(root, text='Print',command=z) > f.pack(side=RIGHT) > > root.mainloop() Try to think of some better variable names. I'm already getting confused a bit about d, var, e, z and f :). var is a string. if you want to use it as an int, use something like 'var = int(e.get())'. > > Thie timer1.py module: > > def TimeFunc(var): > from time import * > me = time() > you=localtime(me) > ClockMin=you[4] #Represents Minute on Clock > ClockHour=you[3] #Represents Hour on Clock > InputMin=var > InputHour=you[3] > if ClockMin while ClockMin you=localtime(me) ClockMin=you[4] > ClockHour=you[3] > print "great" > > If I use only these two lines: > > def TimeFunc(var): > print var > > it works. > > I know this is alot to ask but any help will be greatly appreciated. Well, I can't test it out here, and you don't say what goes wrong, but that could be it. It seems that the function of the while loop is to wait until some minutes have past; you should use time.sleep() for that (it waits for a number of seconds). -- Remco Gerlich, scarblac@pino.selwerd.nl From gundamone@hotmail.com Sun Aug 20 20:26:30 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Sun, 20 Aug 2000 15:26:30 EDT Subject: [Tutor] Integer to String possible???? Message-ID: Hi Guys, From my last question I couldn't save to a txt file. I had some improvements and I could save part of the result (strings) in to the text file; but now I couldn't include the integer part because the ".writelines()"method doesn't like it. Is there a way to get around this?Possibly a way to convert an Integer to a String? Thanks, Albert ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com From scarblac@pino.selwerd.nl Sun Aug 20 20:30:25 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 20 Aug 2000 21:30:25 +0200 Subject: [Tutor] Newbie question on Self, Master and others. In-Reply-To: <20000820175300.610651CEAD@dinsdale.python.org>; from FxItAL@aol.com on Sun, Aug 20, 2000 at 01:52:57PM -0400 References: <20000820175300.610651CEAD@dinsdale.python.org> Message-ID: <20000820213025.C1731@pino.selwerd.nl> On Sun, Aug 20, 2000 at 01:52:57PM -0400, FxItAL@aol.com wrote: > I'm some experiance with VB and am new to Python. In reviewing some code > examples I've come across the "def __init__()" function with several > different, what seems to me are argument options. IE: self, master, > master=None. Would someone explain what these are for and how they are > Python interprets them. __init__() is the object's constructor. It's called when the object is created, to initialize it. Some objects need a few arguments to initialize itself. The first argument, 'self', is always needed for every method, since it tells the method for which object it's called. So in some class class Spam: def __init__(self, arg): self.something = arg The 'arg' is given to the __init__ function when a new instance is made; like instance = Spam("whee") # instance.something is now "whee" So, in your case the object needs to be handed some "master" object when to initialize the new instance. What it's for exactly depend on the class you're talking about, I don't know. If it says "master = None", that means the argument is optional, and that master is None if no argument is given. -- Remco Gerlich, scarblac@pino.selwerd.nl From mrnall@hotmail.com Sun Aug 20 20:44:25 2000 From: mrnall@hotmail.com (Tim Nall) Date: Sun, 20 Aug 2000 14:44:25 -0500 Subject: [Tutor] Is Python fast enough and capable of.. ? Message-ID: <39A03519.D9D470A3@prodigy.net> Hi All, My name is Tim Nall. I am in St. Louis, Missouri, USA. I am an utter newbie, *both* to python and to this list. If there is a FAQ I should read before posting, please avert your eyes from any faux pas I may commit, and point me in the proper direction. :-) I want to ask a very long and involved question. I'm asking this because -- if python is inappropriate for the programming task I must complete, then (unfortunately) I need to move on to another scripting language immediately. Please forgive me if this seems impolite. I am somewhat squeezed between a rock and a hard place. :-) By the way, unforunately I also have no knowledge of any other scripting language (PERL, etc.) I am thinking that Python is the way to go because of its allegedly kinder, gentler learning curve, and the ease with which other programmers should be able to maintain or extend this at a later date. If you have trouble reading the following info, I sympathize. I had trouble writing it. I am in fact embarassed by the necessity of imposing so tremendous a set of questions upon strangers. However -- I need my job. :-) In fact, I'm aware that the entire message that follows might very well be considered inappropriate by some people on some lists. If that is the case for the gentle readers of this list, again I ask you to lower the curtain of grace over me and my posting. :-) I have been asked to write a (Python?) process which would accomplish the following in a very fast and robust manner. The nontrivial difficulties presented from the following scenario are mostly caused by the inability of users running PICK programs against a PICK database to communicate with anything other than that PICK database. So here goes: I am the only programmer at a business which is very phone-oriented. This business uses a PICK database which resides on a UNIX system. Tomorrow I will get hardware and shell information about the UNIX system; I do not have it at this moment. Please note that I am embarassingly ignorant of many important details about the task I have been asked to accomplish. In particular, at present I have little or no info about the phone system posited below. Assume the presence of a phone system which, upon receiving an incoming call, extracts info such as the caller's phone number (and perhaps other info, entered by the caller on a touch-tone phone), and sends that info to a particular port (we'll call it port #239) in string format. Assume a (Python?) process which must continuously perform all three of the following: 1) Listen at Port #239 and receive the incoming strings. Note that at peak business-time this may involve receiving and processing perhaps as many as 150 or 250 incoming calls (i.e., strings from the phone system) in an apparently simultaneous manner. 2) Upon receiving strings, write them out immediately to a UNIX file in a prescribed manner. 3) Perhaps (??) it may be necessary to immediately return that string to the phone sytem for the phone system's use. 4) Check a UNIX directory for newly-written files (details described later in this message). If it finds any UNIX files which are intended for reading by the Python program (as determined by file location and/or file name) it must: A) read that UNIX file, B) extract a string of info, and C) pass that info back to the phone sytem. UNIX files intended for the Python process to read might (for example) be written out by a PICK program in response to a user's decision to forward an incoming call. Assume many users at dumb terminals, utilizing PICK programs against a PICK database. These users are *not* capable of reading from or writing to UNIX files. They are not capable of receiving strings sent by the phone system. At this point it seems necessary to assume a continuously-running PICK program on a PC. This program is capable of reading from and writing to *both* UNIX and PICK files, to act as a link between the incoming info (on UNIX files) and the PICK database (and hence, to the users at their dumb terminals). The PC is *not* capable of communicating directly with the phone system (i.e, is not capable of sending a string to a given port). The PICK program running at this PC is not capable of listening to a given port for information. Writing the necessary PICK program to process UNIX and PICK files is not considered to be an obstacle. So the scenario is as follows: A) Incoming calls reach the phone system. B) Phone sytem sends string to port #239 where it is grabbed by the Python process. C) Python process gets specific info from string (phone number, perhaps other info as entered by caller) and writes info out to a UNIX file. It may also (??) be necessary for the Python process to immediately return that string to the phone system. D) A PICK program running on PC reads the newly-written UNIX file, again extracts necesary info, performs other operations which are irrelevant to the task of the Python process, and finally writes related info out to a PICK file which is accessible by the users at their terminals. E) A given users chooses to access the info (that was just written by a PICK program to a PICK file) when his/her phone rings. Info includes customer name, location, etc. This info is displayed on the terminal. The info is acompanied by a list of options, including "forward this call to another user, forward to voice mail.." etc. F) If the user must communicate with the phone sytem, his/her response will be written out to a PICK file, which is read and processed by the PICK program running continuously on a PC, which then writes info out to a UNIX file, which is then read by the Python process, which forwards the string to the phone system. G) Repeat steps A through F continuously. Whew! Any and all comments by people kind and brave enough to do so will be deeply appreciated. My first question would be, "Is this doable, in a timely manner?" Other questions would follow, I suppose. Many thanks for your supreme kindness and patience, Tim Nall From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 20 21:54:46 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 20 Aug 2000 13:54:46 -0700 (PDT) Subject: [Tutor] Integer to String possible???? In-Reply-To: Message-ID: On Sun, 20 Aug 2000, Albert Antiquera wrote: > From my last question I couldn't save to a txt file. I had some > improvements and I could save part of the result (strings) in to the text > file; but now I couldn't include the integer part because the > ".writelines()"method doesn't like it. Is there a way to get around > this?Possibly a way to convert an Integer to a String? Hello! Use the str() function on the integer, and it should work. str() works with practically everything. >> str(42) '42' >>> str("forty two") 'forty two' >>> str([4, 2]) '[4, 2]' Hope this helps! From gundamone@hotmail.com Sun Aug 20 22:19:45 2000 From: gundamone@hotmail.com (Albert Antiquera) Date: Sun, 20 Aug 2000 17:19:45 EDT Subject: [Tutor] Solved Int to String/Problem about Overwriting Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_1fac_49a2$72f Content-Type: text/plain; format=flowed Hi guys! Thanks for the help on that Integer to String conversion(I knew what str() was but I just forgot all about it;))Anyway, I got the program to work but I got one more problem: When I say 'n' to the 'save file?' part, it erases whatever was saved on that file before. I know it has something to do with the 'open("slope.txt","wb")' part but when I change "wb" to "rb" I get an error. Here's the code if anybody wants to inspect it (I also put it as an attachment if you got trouble reading it here): #!E:/Python/Python.exe #Author: Albert Antiquera #Program: Find the slope and Y-intercept (coming) #IMPORTANT!!!: There is a bug here that I haven't figured out yet: Whwn you say 'N' to the # 'save file?' question, it erases whatever was on the file when you last saved # it. I know it got something to do with that first 'open' command. import sys def slope(): x1 = input("Enter a value for X1: ") x2 = input("Enter a value for X2: ") y1 = input("Enter a value for Y1: ") y2 = input("Enter a value for Y2: ") slp = (y2-y1)/(x2-x1) conv = str(slp) print "The slope is:", conv outp = open("slope.txt", "wb") #I HAVE TO FIGURE THIS ONE OUT SO IT WON'T OVERWRITE" val = "-----BEGIN OUTPUT FILE---------------\n" val2 ="The Slope is:%s\n" %(conv,) val3 ="------END OUTPUT FILE----------------" inp = [val,val2,val3] choice = raw_input("Do you want to save the result to a file?(Y or N):") if choice == 'y': outp.writelines(inp) print "1 file was saved!!" else: print "No File was Saved!!" sys.exit(0) print"------------------SLOPE PROGRAM--------------------------" slope() print"---------------END OF SLOPE PROGRAM----------------------" Thanks!!!! Albert ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com ------=_NextPart_000_1fac_49a2$72f Content-Type: text/plain; name="slope.py"; format=flowed Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="slope.py" #!E:/Python/Python.exe #Author: Albert Antiquera #Program: Find the slope and Y-intercept (coming) #IMPORTANT!!!: There is a bug here that I haven't figured out yet: Whwn you say 'N' to the # 'save file?' question, it erases whatever was on the file when you last saved # it. I know it got something to do with that first 'open' command. import sys def slope(): x1 = input("Enter a value for X1: ") x2 = input("Enter a value for X2: ") y1 = input("Enter a value for Y1: ") y2 = input("Enter a value for Y2: ") slp = (y2-y1)/(x2-x1) conv = str(slp) print "The slope is:", conv outp = open("slope.txt", "wb") #I HAVE TO FIGURE THIS ONE OUT SO IT WON'T OVERWRITE" val = "-----BEGIN OUTPUT FILE---------------\n" val2 ="The Slope is:%s\n" %(conv,) val3 ="------END OUTPUT FILE----------------" inp = [val,val2,val3] choice = raw_input("Do you want to save the result to a file?(Y or N):") if choice == 'y': outp.writelines(inp) print "1 file was saved!!" else: print "No File was Saved!!" sys.exit(0) print"------------------SLOPE PROGRAM--------------------------" slope() print"---------------END OF SLOPE PROGRAM----------------------" ------=_NextPart_000_1fac_49a2$72f-- From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 20 22:28:47 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 20 Aug 2000 14:28:47 -0700 (PDT) Subject: [Tutor] Outputting to text files In-Reply-To: Message-ID: On Sun, 20 Aug 2000, isopod graphics wrote: > calculations like slope calculaion etc., now I wanna save or output the > results to a text file.How do I go about doing that?I know how to read from > a text file and print it on the screen but I don't know how to save the You can open up a file for writing into: ### >>> out = open('output.txt', 'w') ### That second argument means, "open this for writing". Analogously, you can open a file for reading with the 'r' option. From this, we can start doing write()'s using 'out', and things should be ok. ### >>> in = open('output.txt', 'r') File "", line 1 in = open('output.txt', 'r') ^ SyntaxError: invalid syntax ### Whoops! That was silly of me -- 'in' is a special keyword. (for/in) Um... let's try 'input'. ### >>> input = open('output.txt', 'r') >>> input.read() 'Bonobos are cute.' ### > results to a new file. Another one (sorry about this very simple Algebra > question) how do you compute the y-intercept if you were just given the > coordinates of 2 points (x1,y1 and x2,y2)? Ah, line equations! The y-intercept is the place where the line hits the y-axis. At this point, x=0. All we need to do is write a function that uses x as a parameter, and we should be ok. From algebra, here's the generic function that covers lines: y(x) --> mx + b The problem is, it's too generic! What we need to do is find out what 'm' and 'b' are. These are "constants", and every line corresponds to a unique pair of 'm' and 'b'. Thankfully, we can do this, because we have two points. Those two points correspond to these equations: y_1 = m * x_1 + b # (Equation 1) y_2 = m * x_2 + b # (Equation 2) Algebra tells us that we can "solve" the equation at this point ("two equations, two unknowns"). Remember, we are looking for the values of 'm' and 'b'. We just need to choose which one we want to go after first, and things will fall into place. Let's go after 'm'. b = y_1 - m * x_1 # I'm isolating 'b' from equation 1 y_2 = m * x_2 + b # Repeating equation 2. I will now substitute. y_2 = m * x_2 + y_1 - m * x_1 # Our goal is to go after 'm' m * x_2 - m * x_1 = y_2 - y_1 # Just moving stuff around. m = (y_2 - y_1) / (x_2 - x_1) # There's m! Finally! Ok, now that we have 'm', it's almost trivial to get b: just plug it in: b = y_1 - m * x_1 # Repeating the isolation from # equation 1. Substitute. b = y_1 - (y_2 - y_1)/(x_2 - x_1) * x_1 # There's b! Our original goal was to find the y-intercept. We now have the equation of the line: y(x) -> m*x + b And the y intercept occurs when y is zero, so: y(0) -> m*0 + b y(0) -> b That is, the 'y' intercept is 'b'. The python function to calculate y intercepts, then, is: def yIntercept(x_1, y_1, x_2, y_2): x_1, y_1, x_2, y_2 = map(float, [x_1, y_1, x_2, y_2]) # tricky! return y_1 - (y_2 - y_1)/(x_2 - x_1) * x_1 The tricky line just forces all of those values to be floating point. The reason I'm doing this is because we don't want integer division --- we want to work with an approximation to real-valued math. I'm just guaranteeing that we're working with floating point, by doing the conversions. Let's test it out: ### >>> yIntercept(0, 0, 1, 1) # Just to see if it works 0.0 >>> yIntercept(2, 3, 2, 4) Traceback (innermost last): File "", line 1, in ? File "", line 3, in yIntercept ZeroDivisionError: float division >>> yIntercept(2, 3, 3, 4) 1.0 ### But because it's an approximation to real math, you might get weird values sometimes --- be careful of floating point math. Ok, sorry about the length of the message. ASCII text isn't an easy medium to work mathematics with... *grin* From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 20 22:50:27 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 20 Aug 2000 14:50:27 -0700 (PDT) Subject: [Tutor] Solved Int to String/Problem about Overwriting In-Reply-To: Message-ID: > was but I just forgot all about it;))Anyway, I got the program to work but I > got one more problem: When I say 'n' to the 'save file?' part, it erases > whatever was saved on that file before. I know it has something to do with Right. (Write. *grin*) Write mode will zero out the file --- it assumes you want to start from scratch. You'll want to open the file using "append" mode to maintain what was in the file. open('slope.txt', 'a') should do it. From dlaskey@laskeycpa.com Mon Aug 21 03:55:38 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey) Date: Sun, 20 Aug 2000 22:55:38 -0400 Subject: [Tutor] Integer to String possible???? Message-ID: <01C00AF9.C9B52400@o1c-113.i2k.com> Albert: I've had the same problem. I tried it and it works. # --------------Answer1.py--------------------------- # # create and empty data_file # open the data file called data_file data_file = raw_input('File to open? ') in_file = open(data_file,"r") # read the in_file text = in_file.read() # print the file to the screen print text # create the file to export the data to # you need the double or single quotes around the name to save the file out_file = open("new_file.txt","w+") # write the new file you created to the file "new_file.txt" out_file.write(text) out_file.close() in_file.close() Keep working at it and sending in your questions. It helps me, too. Dan -----Original Message----- From: Albert Antiquera [SMTP:gundamone@hotmail.com] Sent: Sunday, August 20, 2000 3:27 PM To: tutor@python.org Subject: [Tutor] Integer to String possible???? Hi Guys, From my last question I couldn't save to a txt file. I had some improvements and I could save part of the result (strings) in to the text file; but now I couldn't include the integer part because the ".writelines()"method doesn't like it. Is there a way to get around this?Possibly a way to convert an Integer to a String? Thanks, Albert ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor From s349929@student.uq.edu.au Mon Aug 21 06:12:16 2000 From: s349929@student.uq.edu.au (Suzanne Little) Date: Mon, 21 Aug 2000 15:12:16 +1000 (GMT+1000) Subject: [Tutor] copying Message-ID: Hello, I've run across a bit of a problem and I'm hoping that either it's all my fault because I've done something silly or someone can suggest a solution. Over the weekend I was very excited to find the generic shallow and deep copying operations because they were exactly what I needed at that point in my coding. I got the functions working on some basic examples but when I sat down to try it out on the real thing I've found that since I'm using kjSets as one of the data types in my list deepcopy doesn't work. Sample code from an investigation session is below. My question: Is there anyway of getting around this? I really need deepcopy to work regardless of what you give it since I'm getting it to copy the __dict__ of an object. Am I likely to run into this problem again with other objects? Alternatively is there another way that I can take a 'snapshot' of the __dict__ and put it into a stack? Thanks for any and all help, Suzanne Python 1.5.2 (#1, Nov 25 1999, 16:33:11) [GCC 2.95.2 19991024 (release)] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> from kjbuckets import * >>> from copy import * >>> s = kjSet(1,2,3) >>> c = copy(s) Traceback (innermost last): File "", line 1, in ? File "/opt/local/PACKAGES/Python-1.5.2/lib/python1.5/copy.py", line 72, in copy raise error, \ copy.error: un(shallow)copyable object of type >>> g = kjGraph((1,2),(2,3)) >>> c2 = copy(g) Traceback (innermost last): File "", line 1, in ? File "/opt/local/PACKAGES/Python-1.5.2/lib/python1.5/copy.py", line 72, in copy raise error, \ copy.error: un(shallow)copyable object of type -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 21 07:40:29 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 20 Aug 2000 23:40:29 -0700 (PDT) Subject: [Tutor] copying In-Reply-To: Message-ID: > My question: Is there anyway of getting around this? I really need > deepcopy to work regardless of what you give it since I'm getting it to > copy the __dict__ of an object. Am I likely to run into this problem again > with other objects? It appears that kjSets have a different way of copying: s = kjSet([1, 2, 3, 4]) s2 = kjSet(s) However, this seems a bit irregular --- you're right, it would be nice to be able to call copy() on them. kjSets do support repr(), so you could potentially use repr() to save an object, but that might be inconvenient. I'll take a closer look at the source code and see if there's a better workaround. From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 21 08:32:46 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 00:32:46 -0700 (PDT) Subject: [Tutor] copying In-Reply-To: Message-ID: > I've run across a bit of a problem and I'm hoping that either it's > all my fault because I've done something silly or someone can suggest a > solution. Over the weekend I was very excited to find the generic shallow > and deep copying operations because they were exactly what I needed at > that point in my coding. I got the functions working on some basic > examples but when I sat down to try it out on the real thing I've found > that since I'm using kjSets as one of the data types in my list deepcopy > doesn't work. Sample code from an investigation session is below. > > My question: Is there anyway of getting around this? I really need > deepcopy to work regardless of what you give it since I'm getting it to > copy the __dict__ of an object. Am I likely to run into this problem again > with other objects? Ok, I found a workaround, and it's not quite bad. If you look at the source for the copy module, Lib/copy.py, you'll actually see a LOT of workarounds for the base types. What I've done is write up a small module, called "kjcopy.py", that imitates them. Load it up before you do any copying, and things should work ok, at least of kjSets: ### kjcopy.py import kjbuckets import copy def _copy_kjSet(x): return kjbuckets.kjSet(x) copy._copy_dispatch[type(kjbuckets.kjSet())] = _copy_kjSet ### Here's it in action: ### >>> from kjbuckets import * >>> from copy import * >>> import kjcopy >>> s = kjSet([1, 2, 3, 4, 5]) >>> s2 = copy(s) >>> s.add(42) >>> s kjSet([1, 2, 3, 4, 5, 42]) >>> s2 kjSet([1, 2, 3, 4, 5]) ### To whoever wrote copy.copy(), thank you for the readable code! *grin* I haven't gotten around to patching up copy() for the other kjTypes, but it should look very similar. From kjohnston@rcsi.ie Mon Aug 21 09:24:16 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Mon, 21 Aug 2000 09:24:16 +0100 Subject: [Tutor] RE: Shelve Help! Message-ID: <9921C1171939D3119D860090278AECA2DEC645@EXCHANGE> Hi Doug, Thank you for replying to my SOS! I have managed to narrow the problem down somewhat...there is no dbm module nor any other type when I check. So I went to reinstall python to include these modules. I altered the Modules/Setup file to include them. ran make clean and then ./configure and then make. However when I ran make I got an error saying that I do not have the following file: ndbm.h. I ran a search for this file and located it in the following places: /usr/include/db1/ndbm.h /usr/glibc-2.1.3.orig/glibc-2.1.3/db/ndbm.h /glibc-2.0/db/ndbm.h how do I tell make that the ndbm.h is present at these locations? thanks again! kate > Dear all, > I have the following error traceback from this line of code: > code: db = shelve.open('DataBase', 'w') First, I don't think you want the 'w' as part of the open. As far as I know shelves are opened read/write with no additional parameter accepted. -------------snip--------- > File "/usr/local/lib/python1.6/anydbm.py", line > 83, in open > raise error, "db type could not be determined" > anydbm.error: db type could not be determined > > I am afraid I have no idea why I am getting this error, the > DataBase file > exists in the same directory as the program is ran from. Usually when this happens to me it means I didn't close the shelve correctly the last time I used it. On the other hand it could be related to the above inclusion of a 'w'. I've never found a way to recover a shelve if it is corrupted like this. Its one of my frustrations with shelves. On the other hand, if you get your program fully debugged it never seems to happen. One of the ways to work through the debug process might be to make a backup of the shelve every time you get ready to open it. That way, if it doesn't get closed you have something to revert to. > Any help as always is appreciated. > Thank you, Hope this wasn't off base. -Doug- > Kate > From kjohnston@rcsi.ie Mon Aug 21 13:59:13 2000 From: kjohnston@rcsi.ie (Catriona Johnston) Date: Mon, 21 Aug 2000 13:59:13 +0100 Subject: [Tutor] RE:Shelve Help! Message-ID: <9921C1171939D3119D860090278AECA2DEC64A@EXCHANGE> For all of you out there puzzled by my query...I seem to have found the reason for the problem if not the solution :( If anyone knows of a patch or other fix please let me know! Thanks again all, kate [ Bug #111802 ] anydbm cannot verify shelve database type Date: 2000-Aug-13 10:05 Submitted By: none Assigned To: none Category: Modules Priority: 5 Bug Group: Trash Resolution: None Summary: anydbm cannot verify shelve database type Original Submission: When opening an existing "shelve" database file. An exception is raised from anydbm saying "the database type could not be determined". From dlaskey@laskeycpa.com Mon Aug 21 18:35:28 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Mon, 21 Aug 2000 13:35:28 -0400 Subject: [Tutor] Reading lines Message-ID: <01C00B74.D97F89E0@DAN> Dear Tutor: # --------------------------------------------------- # import sys and string import sys import string # print the following statement print "Enter the name of the datafile file to convert:" # ask the name of the data_file to use data_file = raw_input('File name to process? ') # read the data_file and put it into a file called in_file in_file = open(data_file,"r") # create the file to export the data to out_file = open("junk.txt","w+") # read the file in_file line by line lines = in_file.readlines() # I want it to search through each line of the file # strip out the lines that has 'Total' on it # then find each line that has '$' on the line and keep it # so I can use it i = {} for i in range(0,len(lines)): string.find('Total')<= 0 string.find('$')>= 0 # # end of processFile() function # # write the results to the new file out_file.writelines(lines) out_file.close() in_file.close() # --------------------------------------------------- Traceback (innermost last): File "question1.py", line 25, in ? string.find('Total')<= 0 TypeError: function requires at least 2 arguments; 1 given Are there any examples of how this can be accomplished? Why am I having sooooo.. much trouble? Dan --------------------------------------------------------------------------------------- | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.------231-723-8305 Voice | 231-723-6097 Fax | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 --------------------------------------------------------------------------------------- From scarblac@pino.selwerd.nl Mon Aug 21 19:01:00 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 21 Aug 2000 20:01:00 +0200 Subject: [Tutor] Reading lines In-Reply-To: <01C00B74.D97F89E0@DAN>; from dlaskey@laskeycpa.com on Mon, Aug 21, 2000 at 01:35:28PM -0400 References: <01C00B74.D97F89E0@DAN> Message-ID: <20000821200100.A3451@pino.selwerd.nl> On Mon, Aug 21, 2000 at 01:35:28PM -0400, Daniel D. Laskey, CPA wrote: > Dear Tutor: > > # --------------------------------------------------- > # import sys and string > import sys > import string > > # print the following statement > print "Enter the name of the datafile file to convert:" > > # ask the name of the data_file to use > data_file = raw_input('File name to process? ') > > # read the data_file and put it into a file called in_file > in_file = open(data_file,"r") > > # create the file to export the data to > out_file = open("junk.txt","w+") > > # read the file in_file line by line > lines = in_file.readlines() # Keep a list of lines you want to keep too: resultlines = [] > # I want it to search through each line of the file > # strip out the lines that has 'Total' on it > # then find each line that has '$' on the line and keep it > # so I can use it > i = {} > for i in range(0,len(lines)): > string.find('Total')<= 0 > string.find('$')>= 0 # Change this for loop to: for line in lines: if string.find(line, 'Total') > -1: continue # Move on, skip this line if string.find(line, '$') > -1: resultlines.append(line) # Keep it > # # end of processFile() function # > > # write the results to the new file > out_file.writelines(lines) And write 'resultlines' instead. > out_file.close() > in_file.close() > > # --------------------------------------------------- > Traceback (innermost last): > File "question1.py", line 25, in ? > string.find('Total')<= 0 > TypeError: function requires at least 2 arguments; 1 given > > Are there any examples of how this can be accomplished? > Why am I having sooooo.. much trouble? Inside the for loop, you still need to tell Python what to do exactly; you didn't tell it where to look for 'Total', so it gave an error. You also didn't do anything with the result. -- Remco Gerlich, scarblac@pino.selwerd.nl From spirou@aragne.com Mon Aug 21 19:27:00 2000 From: spirou@aragne.com (Denis) Date: Mon, 21 Aug 2000 20:27:00 +0200 Subject: [Tutor] Reading lines In-Reply-To: <01C00B74.D97F89E0@DAN>; from dlaskey@laskeycpa.com on Mon, Aug 21, 2000 at 01:35:28PM -0400 References: <01C00B74.D97F89E0@DAN> Message-ID: <20000821202700.C5523@aragne.com> Le Mon, Aug 21, 2000 at 01:35:28PM -0400, Daniel D. Laskey, CPA pianota: > Dear Tutor: > > # --------------------------------------------------- > # import sys and string > import sys > import string > > # print the following statement > print "Enter the name of the datafile file to convert:" > > # ask the name of the data_file to use > data_file = raw_input('File name to process? ') > > # read the data_file and put it into a file called in_file > in_file = open(data_file,"r") > > # create the file to export the data to > out_file = open("junk.txt","w+") > > # read the file in_file line by line > lines = in_file.readlines() > > # I want it to search through each line of the file > # strip out the lines that has 'Total' on it > # then find each line that has '$' on the line and keep it > # so I can use it > i = {} if you do that, i is a dictionary (?) I guess you meant i = [] to make it an empty list, but there is no need to do so. > for i in range(0,len(lines)): i will take values from 0 to n-1 where n is the number of lines > string.find('Total')<= 0 string.find('$')>= 0 You wanted to do something like : # for every line in list of lines for line in lines: #if, searching that line, we don't find 'Total' if (string.find(line, 'Total') < 0 #and, searching that line, we do find '$' and string.find(line, '$')>= 0): # (parentheses let me cut the line where I want) # then write the line to out_file out_file.write(line) > # # end of processFile() function # if you want a function, you know you have to define it : def processFile(in, out): action comes here > TypeError: function requires at least 2 arguments; 1 given Pretty explicit ... print string.find.__doc__ Cordialement'ly y'rs. -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From shaleh@valinux.com Mon Aug 21 19:40:42 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 21 Aug 2000 11:40:42 -0700 (PDT) Subject: [Tutor] practice problems In-Reply-To: <000c01c00a97$31e36720$853706d5@BillJamesll> Message-ID: On 20-Aug-2000 JamesBill wrote: > Hello, > Is there any may that, you could send me some example problems or practice > exercises. So that, I may try to solve them? on www.python.org you could find plenty of tutorial type info. Beyond that, find simple programs and try to re-write them as python apps. Also, many colleges post their homework online. Just because it says to use C or Java does not mean that python can't be used. From dlaskey@laskeycpa.com Mon Aug 21 21:20:08 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA) Date: Mon, 21 Aug 2000 16:20:08 -0400 Subject: [Tutor] more spliting strings Message-ID: <01C00B8B.CA31E0C0@DAN> Dear Tutor: From the help I received from Remco, Amoreira and Denis, my little = program searches a text file and gets rid of the lines with 'Total' in = it and only reads the lines with a '$' in it. Now I have to split this file up, but the file doesn't have any comma or = tab deliminators. It is a fixed length delimated file. I only want the first 6 characters and the last 13 characters. Then I = want to add a date to the file in the first position. # ---------------------------------------- # import sys and string import sys import string # print the following statement print "Enter the name of the datafile file to convert:" # ask the name of the data_file to use data_file =3D raw_input('File name to process? ') # read the data_file and put it into a file called in_file in_file =3D open(data_file,"r") # create the file to export the data to out_file =3D open("junk.txt","w+") # read the file in_file line by line lines =3D in_file.readlines() # keep the list of lines=20 resultlines =3D [] # search through each line of the file for line in lines: # search for lines with 'Total' in it if string.find(line,'Total') >-1: # move on and skip this line continue=09 if string.find(line,'$') >-1: # keep the line resultlines.append(line) # # end of processFile() function # # How do I get the program to read the data from the process # above and the perform the string manipulation I need? a =3D ['08/18/00'] good_data =3D a + "," + line[:6] + "," + line[-13:] # write the results to the new file out_file.writelines(good_data) #out_file.write(good_data) out_file.close() in_file.close() # ---------------------------------------- #Traceback (innermost last): # File "today7.py", line 36, in ? # good_data =3D a + "," + line[:6] + "," + line[-13:] #TypeError: illegal argument type for built-in operation Thanks, Dan -------------------------------------------------------------------------= -------------- | Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com | Daniel D. Laskey Company, P.C.------231-723-8305 Voice | = 231-723-6097 Fax | Certified Public Accountants | 507 Water Street | Manistee, MI 49660 -------------------------------------------------------------------------= -------------- From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 21 21:43:33 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 13:43:33 -0700 (PDT) Subject: [Tutor] RE: Shelve Help! In-Reply-To: <9921C1171939D3119D860090278AECA2DEC645@EXCHANGE> Message-ID: On Mon, 21 Aug 2000, Catriona Johnston wrote: > Modules/Setup file to include them. ran make clean and then ./configure and > then make. However when I ran make I got an error saying that I do not have > the following file: ndbm.h. I ran a search for this file and located it in > the following places: > /usr/include/db1/ndbm.h > /usr/glibc-2.1.3.orig/glibc-2.1.3/db/ndbm.h > /glibc-2.0/db/ndbm.h > how do I tell make that the ndbm.h is present at these locations? You can indicate to the system where those header files are with the optional parameters "-I/usr/include/db1". Most likely, you'll also need to point to the system where to find the corresponding library files too. I'll have to take a guess and say that it's "-L/usr/lib/db1". Search through Modules/Setup to: ### dbm dbmmodule.c # dbm(3) may require -lndbm or similar ### and add those '-I' and '-L' options in there. I'll also follow their recommendation, and add the '-lndbm' in there too. ### dbm dbmmodule -I/usr/include/db1 -L/usr/lib/db1 -lndbm ### Hopefully, doing a 'make' and 'make install' should be painless then. Analogously, when I added gdbm support to my Python installation, I changed my gdbm line to: ### gdbm gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm ### I hope this helps! From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 21 22:00:42 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 14:00:42 -0700 (PDT) Subject: [Tutor] more spliting strings In-Reply-To: <01C00B8B.CA31E0C0@DAN> Message-ID: > >From the help I received from Remco, Amoreira and Denis, my little > program searches a text file and gets rid of the lines with 'Total' in > it and only reads the lines with a '$' in it. > > Now I have to split this file up, but the file doesn't have any comma > or tab deliminators. It is a fixed length delimated file. > > I only want the first 6 characters and the last 13 characters. Then I > want to add a date to the file in the first position. Let's see what was causing the error: > good_data = a + "," + line[:6] + "," + line[-13:] This actually looks almost right --- you need to make sure that when you're doing string concatenation that all of things you're adding up are strings. Since 'a' is defined as: a = ['08/18/00'] this explains that "TypeError" --- 'a' is not a string, but a list. However, the first item in a, a[0], is a string. good_data = a[0] + "," + line[:6] + "," + line[-13:] will work. It looks awkward to have a list with one item, unless you really wanted that. If not, it's simplest just to say: a = '08/18/00' Also, the date is not Y2K compliant, so you might want a = '08/18/2000' instead. *grin* Good luck! From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 22 01:36:42 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 17:36:42 -0700 (PDT) Subject: [Tutor] practice problems In-Reply-To: Message-ID: On Mon, 21 Aug 2000, Sean 'Shaleh' Perry wrote: > > On 20-Aug-2000 JamesBill wrote: > > Hello, > > Is there any may that, you could send me some example problems or practice > > exercises. So that, I may try to solve them? Hello again! What part do you want to practice though? Also, what sort of stuff would you like to program; we might be able to make the example problem interesting for you... *grin* From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 22 02:29:43 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 18:29:43 -0700 (PDT) Subject: [Tutor] copying In-Reply-To: Message-ID: On Tue, 22 Aug 2000, Suzanne Little wrote: > Thank you very much! I've got the KjDict and deepcopies working after > seeing your code and my function works again. :) I've only got a fairly > superficial understanding though but as I understand the copy module the > extra functions will only work for things that can be copied (ie: have a > copying mechanism) and will need to be written specifically each time. Is > this correct? So I could have problems with other entries in the __dict__ > if they aren't catered for. Yes, that sounds right. The base types seems covered for copy.copy(), so I hadn't known that copy() had that limitation. Because the kjbuckets stuff is an extension class, copy() doesn't know what to do with it unless we tell it what to do. For regular classes, copy should do fine --- copy() also covers the normal user-defined classes. The only things that cause difficulty with the copy module seem to be the extension classes, so you shouldn't have too much to worry about. > Again thank you so much for your assistance, No problem, that was a fun problem to chase after, and I learned a little bit in the process... *grin* From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 22 02:52:51 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 21 Aug 2000 18:52:51 -0700 (PDT) Subject: [Tutor] Newbie question on passing a variable In-Reply-To: <20000820181055.30D571D012@dinsdale.python.org> Message-ID: On Sun, 20 Aug 2000 FxItAL@aol.com wrote: > I've written the following to try and get input from the user. This > works fine, my problem is passing it the variable InputMin in the > other module - timer1.py. Dear Al, I know this will sound silly, but I'm still not quite sure what the problem is. I don't mean to be flippant --- I'm just uncertain at what's happening. Because of this, I'll concentrate on TimeFunc(), and see if I can see a bug. > def TimeFunc(var): > from time import * Just to make sure, the indentation of the 'from' needs to match up with the rest of the body. Otherwise, it'll complain about a SyntaxError, I think. > me = time() > you=localtime(me) > ClockMin=you[4] #Represents Minute on Clock > ClockHour=you[3] #Represents Hour on Clock > InputMin=var > InputHour=you[3] > if ClockMin while ClockMin you=localtime(me) ClockMin=you[4] > ClockHour=you[3] > print "great" There's some indentation weirdness going on from my email client, which could either be in the program itself or in the email message. Can you send this section of code again? Also, try to keep your line lengths short in the code. Oh, as a local optimization, you can just do: you = localtime(time()) and that will remove the need for a "me" variable. You might want to rename 'you' though to something more... um... time-like. *grin* From what it looks like, your program is "spin-waiting", which is a term for looping and looping until something happens. Be aware that this is generally not a good thing, because it really slows your computer down. You can add in a short interval of time.sleep() as follows: sleep(60) into the while loop, and have it poll every 60 seconds instead of every few milliseconds. This is better, since that's how often the minutes and hours change anyway. > If I use only these two lines: > > def TimeFunc(var): > print var > it works. Can you show us the exact error message that happens when you try out that TimeFunc()? My brain isn't parsing Python rigidly enough to discover the bug, so an error report will make things easier to fix. From alan.gauld@bt.com Tue Aug 22 11:51:12 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 22 Aug 2000 11:51:12 +0100 Subject: [Tutor] newbie problems with running scripts Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2A8@mbtlipnt02.btlabs.bt.co.uk> > I tried your suggestions but I still get the same error kind > of errors.... > > import myfile Just a guess but after changing the import statement to lose the .py did you save the file and reload it in pythonwin? That seems to make a difference sometimes, although IDLE has no such problem. A;so which version of pythonwin are you using (ie which winall version did you install?) And have you tried using IDLE instead? I actually prefer IDLE to Pythonwin in the latest incarnation (altho the pythonwin debugger is better) Alan G. From alan.gauld@bt.com Tue Aug 22 12:02:48 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 22 Aug 2000 12:02:48 +0100 Subject: [Tutor] Solved Int to String/Problem about Overwriting Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2A9@mbtlipnt02.btlabs.bt.co.uk> > the 'open("slope.txt","wb")' part but when I change "wb" to You want append('a') mode and you don't want binary mode('b') - you're writing strings after all! thus: open("slope.txt","a") Beware of eventually filling your disk with an enormous file tho... Maybe you want to create a new file every day/month/year etc? That way you can archive the old one... Alan G. From alan.gauld@bt.com Tue Aug 22 12:15:29 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 22 Aug 2000 12:15:29 +0100 Subject: [Tutor] Newbie question on Self, Master and others. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2AA@mbtlipnt02.btlabs.bt.co.uk> > I'm some experiance with VB and am new to Python. In > reviewing some code examples I've come across the "def > __init__()" function with several different, what seems to me > are argument options. IE: self, master, master=None. Would init() is the Python constructor mechaniusm(which ISTR doesn't exist in VB!). When you create a new object the init method gets called automagically. The self, master, etc are all variables like any other but any function(method) defined within a class causes Python to use the first parameter as a placeholder for the object. Thus: class Foo: def __init__(bar): # do something def jiggle(baz,spam): # do some other thing f = Foo() # f gets a reference to the new FOO object # Foo.__init__(f) gets called behind the scenes # thus bar gets the value of f, which is the new object f.jiggle('burble') # calls Foo.jiggle(f,'burble') in a friendly way By *convention* the first parameter in a method is called 'self' (because it will be populated by Python with a reference to the current object - the one owning the method. Thus normally you'd see the above example as: class Foo: def __init__(self): # do something def jiggle(self, spam): # do some other thing f = Foo() f.jiggle('burble') The master=None bit simply says that master is a parameter, which if no value is provided it will take the value None. ie: >>> def sayHello(name='World'): ... print 'Hello ' + name ... >>> sayHello('Alan') # I provide a value Hello Alan >>> sayHello() # no value so use default Hello World >>> This stuff is covered in my online tutor at: http://www.crosswinds.net/~agauld/ Look under 'modules & functions' for the default args and under 'OOP' for __init__() stuff. HTH, Alan G. From peterc73@pacbell.net Tue Aug 22 17:50:32 2000 From: peterc73@pacbell.net (Peter Curran) Date: Tue, 22 Aug 2000 09:50:32 -0700 Subject: [Tutor] Newbie - Premature end of script headers Message-ID: <000201c00c59$16fce8f0$1259c93f@pcurran> Python cognoscenti: When I upload a cgi script I've written to an Apache server, I get an Internal Server Error with "premature end of script headers" as the detail. The script works OK in pythonwin on my NT4 machine, but I'm wondering if I need something more for Apache. I have the appropriate shebang at the top of the script, so I'm puzzled. This is the routine that should be triggered: def massprops(data): print "Content-type: text/html\n\n" print print "Hello" print "

Props Here

" print "" This is the code that should call that routine: if __name__ == '__main__': sys.stderr = sys.stdout form = cgi.FieldStorage() data = FeedBackData(form) if data.user == 'Peter': massprops(data) else: pimpslap(data) MANY thanks in advance to who(m)ever responds!! I really appreciate it. Peter Curran UniLink Inc. (415) 751-1285 (h/w) (415) 378-9663 (m) (425) 928-5312 (f) From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 22 17:59:21 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Tue, 22 Aug 2000 09:59:21 -0700 (PDT) Subject: [Tutor] Newbie question on passing a variable In-Reply-To: <200008221020.DAA30445@hkn.EECS.Berkeley.EDU> Message-ID: On Tue, 22 Aug 2000 FxItAL@aol.com wrote: > Thanks for your response. I've brought it all together to simplify things. It loads fine but when I enter a number and push the "Action Button" I receive the following: > Exception in Tkinter callback > Traceback (innermost last): > File "D:\Python\Lib\lib-tk\Tkinter.py",line 764, in __call__ > File "data.py",line 20, in ActionButCmd > while ClockMin NameError: ClockMin I actually didn't get that error message; I got a different one based on the indentation at the very beginning of the while loop: ### inconsistent dedent Traceback (innermost last): File "", line 1, in ? File "/usr/tmp/python-27557Yp1", line 21 ClockMin=Hour_Min[4] ### That particular line also refers to "me", but should have been "time()". Once I corrected it, your program executed. I'll repost it here: ### from Tkinter import * from time import * root = Tk() root.title('Top Level') UserEntry = StringVar() EntryBox = Entry(root, textvariable=UserEntry, width=10) EntryBox.pack() var = UserEntry.get() Hour_Min=localtime(time()) ClockMin=Hour_Min[4] ClockHour=Hour_Min[3] InputMin=var InputHour=Hour_Min[3] def ActionButCmd(): while ClockMin; from mrnall@prodigy.net on Sun, Aug 20, 2000 at 02:44:25PM -0500 References: <39A03519.D9D470A3@prodigy.net> Message-ID: <20000822114404.A11539@valinux.com> (original message left out) Python.org has many great pieces of info which will help you with the port reading and what not. Another great feature of python is that if it does turn out to be too slow, it is fairly trivial to a) replace it with c/c++ code or b) rewrite portions in c/c++ and use python as glue. This let's you write the code rapidly, then fix any performance issues you may run into. I see no reason why python could not handle this task (or why it would do any worse than other script languages). You may end up using a non script implementation, at least in parts to gain the speed and robustness you seek. From scarblac@pino.selwerd.nl Tue Aug 22 21:10:39 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 22 Aug 2000 22:10:39 +0200 Subject: [Tutor] Is Python fast enough and capable of.. ? In-Reply-To: <20000822114404.A11539@valinux.com>; from shaleh@valinux.com on Tue, Aug 22, 2000 at 11:44:04AM -0700 References: <39A03519.D9D470A3@prodigy.net> <20000822114404.A11539@valinux.com> Message-ID: <20000822221039.B5154@pino.selwerd.nl> On Tue, Aug 22, 2000 at 11:44:04AM -0700, Sean 'Shaleh' Perry wrote: > (original message left out) > > Python.org has many great pieces of info which will help you with the port > reading and what not. > > Another great feature of python is that if it does turn out to be too slow, it > is fairly trivial to a) replace it with c/c++ code or b) rewrite portions in > c/c++ and use python as glue. This let's you write the code rapidly, then fix > any performance issues you may run into. > > I see no reason why python could not handle this task (or why it would do any > worse than other script languages). You may end up using a non script > implementation, at least in parts to gain the speed and robustness you seek. That's what I expect too. If Python isn't fast enough, other scripting languages won't be fast enough either. But it would still be useful to do it in Python before a C version. But noone here seems to have a lot of experience with this sort of thing, you (the original poster) should probably ask on the main Python list, this one is more for beginner questions, learning the language and so on. -- Remco Gerlich, scarblac@pino.selwerd.nl From rickp@telocity.com Tue Aug 22 22:15:14 2000 From: rickp@telocity.com (Rick Pasotto) Date: Tue, 22 Aug 2000 17:15:14 -0400 Subject: [Tutor] initialization window Message-ID: <20000822171514.H20359@tc.telocity.com> I've written a program that, as part of its startup processing, scans a file to build a dictionary. Since this can take several seconds, I'd like to put up a window explaining the delay. The main program is defined as a class and I haven't been able to figure out how to popup this secondary window at the appropriate time. Perhaps part of what I'm asking is for the sequence of events. How can/should I rearrange the program so that: 1) if the file doesn't exist, popup error explanation and exit 2) if it does exist, popup delay explanation and destroy it when the dictionary has been built (or wait for user to press a 'dismiss' button) and then display regular window? To further complicate what I'd like to do, could this delay explanation window double as an 'about' window (with the file reading code wrapped in an if-statement) to be called from a menu item? example current stub code: import Tkinter * class prog(win): def __init__(self,win): def proc1(self): def proc2(self): etc. def main(): root = Tk() prog(root) root.mainloop() if __name__ == '__main__': main() -- "Must the citizen ever for a moment, or in the least degree, resign his conscience to the legislator? Why has every man a conscience, then? I think that we should be men first, and subjects afterward." -- Henry David Thoreau Rick Pasotto email: rickp@vnet.net From c.gruschow@prodigy.net Wed Aug 23 08:42:00 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Wed, 23 Aug 2000 02:42:00 -0500 Subject: [Tutor] can someone explain to me Lambda functions/statements, preferably with examples, I don't get it Message-ID: <007e01c00cd5$a1299c40$3cdf6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_007B_01C00CAB.B6A85540 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable can someone explain to me Lambda functions/statements, preferably with = examples, I don't get it, I don't understand how to use them either thank you c.gruschow@prodigy.net ------=_NextPart_000_007B_01C00CAB.B6A85540 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

can someone explain to me Lambda functions/statements, preferably = with=20 examples, I don't get it, I don't understand how to use them either

thank you

c.gruschow@prodigy.net<= /P>

 

------=_NextPart_000_007B_01C00CAB.B6A85540-- From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 23 10:02:12 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 23 Aug 2000 02:02:12 -0700 (PDT) Subject: [Tutor] can someone explain to me Lambda functions/statements, preferably with examples, I don't get it In-Reply-To: <007e01c00cd5$a1299c40$3cdf6520@gruschow> Message-ID: > can someone explain to me Lambda functions/statements, preferably with > examples, I don't get it, I don't understand how to use them either I'll try, but this message will be slightly long to give a good explaination. lambda allows you to make on-the-fly functions. This only makes sense once you see that functions, like data, can be passed around. I'll need to take a slight detour for this. Say that we had the following list: ### >>> l = range(20) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] ### Let's say that I'd like to get a new list, with only the even numbers. We could do this: ### >>> def onlyEvens(L): ... result = [] ... for x in L: ... if (x % 2 == 0): ... result.append(x) ... return result ... >>> onlyEvens(l) [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] ### What if we wanted to change this so it only gave us back the odds? Well, we could do cut-and-paste: ### def onlyOdds(L): result = [] for x in L: if (x % 2 == 1): result.append(x) return result ### This isn't bad. However, what programmers often do is try to generalize things. In those two functions, we're looking at every element in a list, and doing some sort of check. We could write these tests out simply as: def isEven(x): return (x % 2 == 0) def isOdd(x): return (x % 2 == 1) onlyEvens(), then, will look like this: ### def onlyEvens(L): result = [] for x in L: if isEven(x): result.append(x) return result ### and onlyOdds() will be one line different. Now here's the jump --- why not allow the program to send not only the list, but the criterion for knowing which items to keep? Why can't we write something like: ### def myfilter(f, L): result = [] for x in L: if f(x): result.append(x) return result ### It turns out that this works. Functions can be passed around, just like lists and strings and ints. Now that we know we can write myfilter, then to get all the odd numbers, we'd just need to do this: ### >>> myfilter(isOdd, l) [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] >>> myfilter(isEven, l) [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] ### No messiness involved. And very reusable. So now we have something that will filter out items from a list. This is actually really powerful, since this suddenly gives us amazing power over lists, and not just lists of integers. Take a look: ### >>> import string >>> def isLowercase(x): return string.lower(x) == x >>> myfilter(isLowercase, ['This', 'is', 'A', 'tEst', 'of', 'the', 'emergency', 'Broadcast', 'systeM']) ['is', 'of', 'the', 'emergency'] ### To get back to the original question, lambda is used when you want to pass a function to one of these function-eating functions. Heck, this might be a one-shot thing that you're doing. In this case, you can do something like: ### >>> myfilter(lambda x: 't' in x, ['This', 'is', 'A', 'tEst', 'of', 'the', 'emergency', 'Broadcast', 'systeM']) ['tEst', 'the', 'Broadcast', 'systeM'] ### which pulls out all the words that have the letter 't' in them. I could have written 'containsTheLowercaseLetterT()' as a separate function. This is an example where the lambda stuff comes in handy --- it's short, it's quick, and you don't need to type so much. The problem is that it's localized --- if you find yourself retyping the same lambda over, then it must be so generally useful that you should grant it the life of a real function. Also, lambdas are also limited to a single expression. This really limits them to simple tests. Finally, Python already gives you a bunch of built-ins that do things to lists. It does have a 'filter()' command. Furthermore, it has 'map()', which is even more impressive: ### >>> map(lambda x: x + x, ['i', 'will', 'be', 'double', 'talking']) ['ii', 'willwill', 'bebe', 'doubledouble', 'talkingtalking'] ### Play around with it; you'll have fun. *grin* I hope this helps. From c.gruschow@prodigy.net Wed Aug 23 08:49:18 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Wed, 23 Aug 2000 02:49:18 -0500 Subject: [Tutor] another ?-->if I created test.py how do I run test.py in hello.py and also how do I run it again in hello.py? Message-ID: <009a01c00cd6$a509ee40$3cdf6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_0097_01C00CAC.BB73A380 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable another ?-->if I created test.py how do I run test.py in hello.py and = also how do I run it again in hello.py? thank you c.gruschow@prodigy.net ------=_NextPart_000_0097_01C00CAC.BB73A380 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

another ?-->if I created test.py how do I run test.py in hello.py = and also=20 how do I run it again in hello.py?

thank you

c.gruschow@prodigy.net<= /P>

 

------=_NextPart_000_0097_01C00CAC.BB73A380-- From jazariel@tiscalinet.it Wed Aug 23 09:49:37 2000 From: jazariel@tiscalinet.it (Thomas Schulze) Date: Wed, 23 Aug 2000 08:49:37 GMT Subject: [Tutor] Indovinello - The Game of Numbers Message-ID: <20000823.8493700@CorelLinux.> Ciao, In a post some time ago I mentioned a small game I was trying to program= =20 to learn Python. I discovered that Python is indeed powerful so I got=20 carried away somewhat and implemented more and more ideas. The hardest=20 part is getting used to objects. In the beginning it was merely a=20 translation of a Pascal program, but now it's quite modular. Now it is somewhat beyond a tutorial problem but maybe not ready to=20 announce it somewhere more formally. So I'm looking for some volunteers = to play it and take a look at the source code and installation. (I'm to= o=20 shy to say beta tester here). It is a console application where you have= =20 to guess a number. Initially it tells you only whether your guess was to= o=20 small or too large but every time you win it gets more complex including= =20 all kinds of special numbers. Right now 42 conditions are included. Indovinello is Italian and means riddle. The subtitle is borrowed from=20 Conway/Guy: The Book of numbers who borrowed it from the bible. If you drop me a mail, I send you a gz file which should also be=20 understood by WinZip. The only thing I ask for is any kind of response. Thomas Schulze From steve@spvi.com Wed Aug 23 11:41:12 2000 From: steve@spvi.com (Steve Spicklemire) Date: Wed, 23 Aug 2000 05:41:12 -0500 (EST) Subject: [Tutor] can someone explain to me Lambda functions/statements, preferably with examples, I don't get it In-Reply-To: <007e01c00cd5$a1299c40$3cdf6520@gruschow> (c.gruschow@prodigy.net) References: <007e01c00cd5$a1299c40$3cdf6520@gruschow> Message-ID: <200008231041.FAA56969@mercury.spvi.com> Hi Charles, Lambda is used to make a 'quick' function: e.g., You could create a 'normal' function say foo: def foo(x): return x - 3*x + 4*x**2 and then use foo in another situation where a function is required: print map(foo, [1,2,3,4,5]) would result in: [2, 12, 30, 56, 90] a shorter definition would be using lambda (same function) bar = lambda x : x - 3*x + 4*x**2 print map(bar, [1,2,3,4,5]) would produce the same result... of course, now you could just skip defining 'bar' and use the function directly in the 'map'... print map(lambda x : x - 3*x + 4*x**2, [1,2,3,4,5]) and get the same result again... Basically lamda x, y, z, .... : (single line fuction of x, y, z ...) is equivalant to: def foo(x, y, z, ...): return (same single line function of x, y, z, ...) except the lambda version doesn't have (or need) a 'name'. does that help? -steve From steve@spvi.com Wed Aug 23 11:36:02 2000 From: steve@spvi.com (Steve Spicklemire) Date: Wed, 23 Aug 2000 05:36:02 -0500 (EST) Subject: [Tutor] can someone explain to me Lambda functions/statements, preferably with examples, I don't get it In-Reply-To: <007e01c00cd5$a1299c40$3cdf6520@gruschow> (c.gruschow@prodigy.net) References: <007e01c00cd5$a1299c40$3cdf6520@gruschow> Message-ID: <200008231036.FAA56954@mercury.spvi.com> Hi Charles, Lambda is used to make a function: e.g., You could say def foo(x): return x - 3*x + 4*x**2 and then use foo in another situation where a function is required: print map(foo, [1,2,3,4,5]) [2, 12, 30, 56, 90] a shorter definition would be using lambda bar = lambda x : x - 3*x + 4*x**2 print map(bar, [1,2,3,4,5]) From gbaronio@siosistemi.it Wed Aug 23 14:49:07 2000 From: gbaronio@siosistemi.it (Gianmarco Baronio) Date: Wed, 23 Aug 2000 15:49:07 +0200 Subject: [Tutor] reading file contenent 032 octal value Message-ID: <39A3D653.E0C784B0@siosistemi.it> This is a cryptographically signed message in MIME format. --------------ms29F1AC95EFB82A58EC12ACC0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello everybody, I'm working in Windows :-( I've to read the content of a file that includes the octal value 032 in some position; to generate similar file i do: >>> somefile=open("c:\\pippo.txt",'w') >>> somefile.write("some text \032 rest of file") >>> somefile.close() then, I try to read the content of pippo.txt and print it: >>> somefile=open("c:\\pippo.txt",'r') >>> content=somefile.read() >>> print content some text why does it stop before EOF? I tried to do the same with linux and all goes right!!! It is exclusivly a problem in pythonwin? Can you help me? Thanks --------------ms29F1AC95EFB82A58EC12ACC0 Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIH9AYJKoZIhvcNAQcCoIIH5TCCB+ECAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC BcUwggKpMIICEqADAgECAgMCMHwwDQYJKoZIhvcNAQEEBQAwgZQxCzAJBgNVBAYTAlpBMRUw EwYDVQQIEwxXZXN0ZXJuIENhcGUxFDASBgNVBAcTC0R1cmJhbnZpbGxlMQ8wDQYDVQQKEwZU aGF3dGUxHTAbBgNVBAsTFENlcnRpZmljYXRlIFNlcnZpY2VzMSgwJgYDVQQDEx9QZXJzb25h bCBGcmVlbWFpbCBSU0EgMTk5OS45LjE2MB4XDTAwMDIyOTEyMDEwMVoXDTAxMDIyODEyMDEw MVowSDEfMB0GA1UEAxMWVGhhd3RlIEZyZWVtYWlsIE1lbWJlcjElMCMGCSqGSIb3DQEJARYW Z2Jhcm9uaW9Ac2lvc2lzdGVtaS5pdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAzzdh dtamiMyRC7A7eZJgZiB8/HESCZ6OSL+GYkX0wgdvV3BuEhh9T7UJSICH6+r9g9Dc0QlXswuT dAM89Pku0kepdkS/wbINyJH61brQqB70U9M14RVbNAXzRFJtnX4lACVGWjxTxe+alHt4q4Aw v7v7A0amkTzK7SHgPIOQatMCAwEAAaNUMFIwIQYDVR0RBBowGIEWZ2Jhcm9uaW9Ac2lvc2lz dGVtaS5pdDAMBgNVHRMBAf8EAjAAMB8GA1UdIwQYMBaAFIir8WCDZlX05FjHRh3AYb0j18OM MA0GCSqGSIb3DQEBBAUAA4GBAJNTdfbJj52Wrs9MHUsY8pOORQIuYIx/LO0kh1T77Vg3UTyr I/L8uKGgmVtyAsNxVe9fPPkI2ec82skX2YgLQEfigIyDxW5quXcgGx/IdxQuZYDMrXNiSJmI y85s+Qh3svBUnuHkUytvRyXR8MzppilouPytubGSNcShpJWb0PZZMIIDFDCCAn2gAwIBAgIB CzANBgkqhkiG9w0BAQQFADCB0TELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2Fw ZTESMBAGA1UEBxMJQ2FwZSBUb3duMRowGAYDVQQKExFUaGF3dGUgQ29uc3VsdGluZzEoMCYG A1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEkMCIGA1UEAxMbVGhhd3Rl IFBlcnNvbmFsIEZyZWVtYWlsIENBMSswKQYJKoZIhvcNAQkBFhxwZXJzb25hbC1mcmVlbWFp bEB0aGF3dGUuY29tMB4XDTk5MDkxNjE0MDE0MFoXDTAxMDkxNTE0MDE0MFowgZQxCzAJBgNV BAYTAlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxFDASBgNVBAcTC0R1cmJhbnZpbGxlMQ8w DQYDVQQKEwZUaGF3dGUxHTAbBgNVBAsTFENlcnRpZmljYXRlIFNlcnZpY2VzMSgwJgYDVQQD Ex9QZXJzb25hbCBGcmVlbWFpbCBSU0EgMTk5OS45LjE2MIGfMA0GCSqGSIb3DQEBAQUAA4GN ADCBiQKBgQCzaVqX1NAWC3q1xV3pIZwjcs0STEv3fs/H+8pyJPRCUqxXleN7YXoXhOf9cjk4 lLTq7WWnkgZeveBl9hm7lHl2TD65aHB1hBz0EXQAvAUsTwkDFzHM9EHUcsamXeKIRLCLLsRN 8fDWhT5s85WUeJF+QOmc0Y0VV47Cc+Uw3kb1TwIDAQABozcwNTASBgNVHRMBAf8ECDAGAQH/ AgEAMB8GA1UdIwQYMBaAFHJJwnM0xlX0C3ZygX539IfnxrIOMA0GCSqGSIb3DQEBBAUAA4GB AGvGWekx+um27LED2N9ycv6RYEjqxlXde/BnjsZhcOdtwqU32J23FyhWBYvdXHVvxpGQxmxm cRPQEHxrkW+G4CE2LcHX6rIJrc8tbcaDUpv7u/6ch538t+l0kuRcl678fqzKDW9yemcsa3P1 hvmd9QBu9B0Hzp2egmMp75MJflXeMYIB9zCCAfMCAQEwgZwwgZQxCzAJBgNVBAYTAlpBMRUw EwYDVQQIEwxXZXN0ZXJuIENhcGUxFDASBgNVBAcTC0R1cmJhbnZpbGxlMQ8wDQYDVQQKEwZU aGF3dGUxHTAbBgNVBAsTFENlcnRpZmljYXRlIFNlcnZpY2VzMSgwJgYDVQQDEx9QZXJzb25h bCBGcmVlbWFpbCBSU0EgMTk5OS45LjE2AgMCMHwwCQYFKw4DAhoFAKCBsTAYBgkqhkiG9w0B CQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wMDA4MjMxMzQ5MDdaMCMGCSqGSIb3 DQEJBDEWBBRrkWD+PMg8BFw1iSiIAj7WkmG00zBSBgkqhkiG9w0BCQ8xRTBDMAoGCCqGSIb3 DQMHMA4GCCqGSIb3DQMCAgIAgDAHBgUrDgMCBzANBggqhkiG9w0DAgIBQDANBggqhkiG9w0D AgIBKDANBgkqhkiG9w0BAQEFAASBgMtCeK5DO63Mt7WvLSz1B5GQOEPAK4Hjj0hXJxiwYnz+ MpEf+po9F5llJ78iMfoCj05P1xfF3azYlrFfe07FeYaH8WP3hc7ck19lu2enMIuR8mr9jz8H AOfv2sPKRoniEgT1M+gRWWWwXAMu7cKUhEi/1xKkg0WYE4MS7tXeb992 --------------ms29F1AC95EFB82A58EC12ACC0-- From scarblac@pino.selwerd.nl Wed Aug 23 15:33:09 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 23 Aug 2000 16:33:09 +0200 Subject: [Tutor] reading file contenent 032 octal value In-Reply-To: <39A3D653.E0C784B0@siosistemi.it>; from gbaronio@siosistemi.it on Wed, Aug 23, 2000 at 03:49:07PM +0200 References: <39A3D653.E0C784B0@siosistemi.it> Message-ID: <20000823163309.A6331@pino.selwerd.nl> On Wed, Aug 23, 2000 at 03:49:07PM +0200, Gianmarco Baronio wrote: > Hello everybody, > > I'm working in Windows :-( > > I've to read the content of a file that includes the octal value 032 in > some position; to generate similar file i do: > > >>> somefile=open("c:\\pippo.txt",'w') > >>> somefile.write("some text \032 rest of file") > >>> somefile.close() > > then, I try to read the content of pippo.txt and print it: > > >>> somefile=open("c:\\pippo.txt",'r') > >>> content=somefile.read() > >>> print content > some text > > why does it stop before EOF? It doesn't, 032 *is* EOF ;) Probably there won't be a problem if you open it as binary, try open("c:\\pippo.txt","rb"). -- Remco Gerlich, scarblac@pino.selwerd.nl From jazariel@libero.it Wed Aug 23 15:59:56 2000 From: jazariel@libero.it (Thomas Schulze) Date: Wed, 23 Aug 2000 16:59:56 +0200 Subject: [Tutor] Indovinello - The Game of Numbers In-Reply-To: <20000823.8493700@CorelLinux.> References: <20000823.8493700@CorelLinux.> Message-ID: <00082317042000.00481@CorelLinux> On Wed, 23 Aug 2000, I wrote: > If you drop me a mail, I send you a gz file which should also be > understood by WinZip. The only thing I ask for is any kind of response. What I was trying to say there is that if you decide to try the game I would greatly appreciate if you actually give me some feedback. That is also the reason why I don't attach the file right now, besides the wish not to clutter the mailboxes of those who are not interested. Thanks, Thomas From dyoo@hkn.EECS.Berkeley.EDU Wed Aug 23 20:31:44 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 23 Aug 2000 12:31:44 -0700 (PDT) Subject: [Tutor] another ?-->if I created test.py how do I run test.py in hello.py and also how do I run it again in hello.py? In-Reply-To: <009a01c00cd6$a509ee40$3cdf6520@gruschow> Message-ID: On Wed, 23 Aug 2000, Charles Gruschow, Jr. wrote: > another ?-->if I created test.py how do I run test.py in hello.py and > also how do I run it again in hello.py? I'm not quite sure if this is what you mean, but you can use execfile("test.py") inside your hello.py file, and that'll execute test.py for you. However, this is something uncommon to me. Can you explain to us why you want to do this? From c.gruschow@prodigy.net Wed Aug 23 21:57:42 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Wed, 23 Aug 2000 15:57:42 -0500 Subject: [Tutor] another ?-->if I created test.py how do I run test.pyin hello.py and also how do I run it again in hello.py? References: Message-ID: <004201c00d44$c9104dc0$c6df6520@gruschow> I just thought that if you have a block of code that works on its own, you could use that block in a different program if you wanted. I wanted to know how to originally call that block of code, and how to use it again in the same program if you wanted to. Like for example if you created an option off a pull down menu that executes a python program, how do you get it so that you can execute that option again. BTW, thank you very much for your assistance so far. Thanks, Charles W. Gruschow, Jr. c.gruschow@prodigy.net p.s. I am learning quite a bit considering I only just got Python last Friday. :) ----- Original Message ----- From: Daniel Yoo To: Charles Gruschow, Jr. Cc: Sent: Wednesday, August 23, 2000 2:31 PM Subject: Re: [Tutor] another ?-->if I created test.py how do I run test.pyin hello.py and also how do I run it again in hello.py? > On Wed, 23 Aug 2000, Charles Gruschow, Jr. wrote: > > > another ?-->if I created test.py how do I run test.py in hello.py and > > also how do I run it again in hello.py? > > > I'm not quite sure if this is what you mean, but you can use > > execfile("test.py") > > inside your hello.py file, and that'll execute test.py for you. However, > this is something uncommon to me. Can you explain to us why you want to > do this? > From c.gruschow@prodigy.net Wed Aug 23 22:06:02 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Wed, 23 Aug 2000 16:06:02 -0500 Subject: [Tutor] Thanks for your help so far on the lambda statement, I think I am beginning to get it. Message-ID: <005801c00d45$f252efc0$c6df6520@gruschow> Thanks for your help so far on the lambda statement, I think I am beginning to get it. Charles W. Gruschow, Jr. c.gruschow@prodigy.net p.s. btw, I also like Monty Python stuff, especially "The Holy Grail" From DOUGS@oceanic.com Wed Aug 23 22:23:04 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Wed, 23 Aug 2000 11:23:04 -1000 Subject: [Tutor] another ?-->if I created test.py how do I run test.py in hello.py and also how do I run it again in hello.py? Message-ID: <8457258D741DD411BD3D0050DA62365907A2E1@huina.oceanic.com> This one is one of the great features of Python, the modularity. Usually you want to structure your programs in small lumps of functionality in modules. Some people suggest on the order of one class per file, or module. I think that is extreme and usually have up to ten classes or related functions in one module. The structure might look like this: #-------file: mymodule.py import spam,eggs # whatever library modules are needed. def afunction(var1): # some good code def another(var2): # more useful stuff #------ might be more functions or classes def test(): # something which tests this module def main(): # I'd use a main if this is a module that is expected to be # run as an application outstuff = afunction(theInput) another(outstuff) # making it up for the example if __name__ == '__main__': main() # This is if its an application, not a library of functions #----------end of file Lets say that the function 'another' is good stuff that you want to use in another of your programs. You would do the following in the new file: import mymodule # and then to run it: mymodule.another(theInput) #----------------- This is the same semantics as is used to call all the Python libraries functions so it should be familiar. Hope this is what you were asking. -Doug- > -----Original Message----- > From: Charles Gruschow, Jr. [mailto:c.gruschow@prodigy.net] > Sent: Wednesday, August 23, 2000 10:58 AM > To: Daniel Yoo > Cc: tutor@python.org > Subject: Re: [Tutor] another ?-->if I created test.py how do I run > test.pyin hello.py and also how do I run it again in hello.py? > > > I just thought that if you have a block of code that works > on its own, you > could use that block in a different program if you wanted. I > wanted to know > how to originally call that block of code, and how to use it > again in the > same program if you wanted to. Like for example if you > created an option > off a pull down menu that executes a python program, how do > you get it so > that you can execute that option again. > > BTW, thank you very much for your assistance so far. > > Thanks, > > Charles W. Gruschow, Jr. > c.gruschow@prodigy.net > > p.s. I am learning quite a bit considering I only just got Python last > Friday. :) > > > > > ----- Original Message ----- > From: Daniel Yoo > To: Charles Gruschow, Jr. > Cc: > Sent: Wednesday, August 23, 2000 2:31 PM > Subject: Re: [Tutor] another ?-->if I created test.py how do > I run test.pyin > hello.py and also how do I run it again in hello.py? > > > > On Wed, 23 Aug 2000, Charles Gruschow, Jr. wrote: > > > > > another ?-->if I created test.py how do I run test.py in > hello.py and > > > also how do I run it again in hello.py? > > > > > > I'm not quite sure if this is what you mean, but you can use > > > > execfile("test.py") > > > > inside your hello.py file, and that'll execute test.py for > you. However, > > this is something uncommon to me. Can you explain to us > why you want to > > do this? > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From gwperry@tva.gov Thu Aug 24 17:31:10 2000 From: gwperry@tva.gov (Perry, George W.) Date: Thu, 24 Aug 2000 12:31:10 -0400 Subject: [Tutor] Getting Userid From System Message-ID: <2DACABE127B3D1119FC40000F8014EFC0184C786@chachaois4.cha.tva.gov> Is there a module to obtain the current user name from the system? I.e. the unix userid or the Windows network logon ID. Thanks George Perry From shaleh@valinux.com Thu Aug 24 19:27:48 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 24 Aug 2000 11:27:48 -0700 Subject: [Tutor] Getting Userid From System In-Reply-To: <2DACABE127B3D1119FC40000F8014EFC0184C786@chachaois4.cha.tva.gov>; from gwperry@tva.gov on Thu, Aug 24, 2000 at 12:31:10PM -0400 References: <2DACABE127B3D1119FC40000F8014EFC0184C786@chachaois4.cha.tva.gov> Message-ID: <20000824112748.A13304@valinux.com> On Thu, Aug 24, 2000 at 12:31:10PM -0400, Perry, George W. wrote: > Is there a module to obtain the current user name from the system? I.e. the > unix userid or the Windows network logon ID. > import os print os.getuid() # only works on unix I do not know of an easy way to get the Windows ID. There is a win32 module, perhaps there is a windows call you can make? In python's OS and SYS module there is a variable that allows you to check the OS you are running on. import os if os.name == 'win': user = win_getuid() # function you wrote else: # this will bomb on mac and a few others, but as long as you dont care user = os.getuid() print "User is %s" % (user) From FxItAL@aol.com Thu Aug 24 15:45:53 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Thu, 24 Aug 2000 10:45:53 EDT Subject: [Tutor] GUI not responding Message-ID: <20000824144612.041071CE3A@dinsdale.python.org> Hello All, I have a GUI that accepts Input from the user when the function "ActionBut" is called. My problem is, even though the program runs on the DOS screen the GUI locks up unitl the "while" loop ends. Any advice is greatly appreciated, Thanks Al Here's what is causing the lock up: def ActionButCmd(): global ClockMin, ClockHour, InputMin, InputHour, var var = UserEntry.get() Hour_Min=localtime(time()) ClockMin=Hour_Min[4] ClockHour=Hour_Min[3] InputMin=var InputHour=Hour_Min[3] if ClockMin=InputMin: print "END" From chetumal23@excite.com Fri Aug 25 19:10:11 2000 From: chetumal23@excite.com (john smith smith) Date: Fri, 25 Aug 2000 11:10:11 -0700 (PDT) Subject: [Tutor] newbe Message-ID: <18499600.967227011978.JavaMail.imail@doby.excite.com> where do i get started with learning python _______________________________________________________ Say Bye to Slow Internet! http://www.home.com/xinbox/signup.html From shaleh@valinux.com Fri Aug 25 19:14:49 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 25 Aug 2000 11:14:49 -0700 (PDT) Subject: [Tutor] newbe In-Reply-To: <18499600.967227011978.JavaMail.imail@doby.excite.com> Message-ID: On 25-Aug-2000 john smith smith wrote: > where do i get started with learning python > 1) python.org, lots of stuff here 2) questions on this list 3) buy a book, O'reilly has two good python books From Carey@meditrac.co.za Fri Aug 25 19:14:32 2000 From: Carey@meditrac.co.za (Carey Caldecott) Date: Fri, 25 Aug 2000 20:14:32 +0200 Subject: [Tutor] newbie2 Message-ID: okay, so buying a book is great, but i need visual examples. are there any online study-guides? From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 25 20:12:06 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 25 Aug 2000 12:12:06 -0700 (PDT) Subject: [Tutor] newbe In-Reply-To: <18499600.967227011978.JavaMail.imail@doby.excite.com> Message-ID: On Fri, 25 Aug 2000, john smith smith wrote: > where do i get started with learning python Good afternoon! One of the best places to get started is by reading some of the intros on the Python site: http://python.org/doc/Intros.html You don't need to get a book. The tutorials by Josh Cogliati and Alan Gauld are really good: http://www.honors.montana.edu/~jjc/easytut/easytut/ http://members.xoom.com/alan_gauld/tutor/tutindex.htm Email us with any questions. Good luck! From sburch@ordway.org Fri Aug 25 20:29:02 2000 From: sburch@ordway.org (Burchill, Scott B.) Date: Fri, 25 Aug 2000 14:29:02 -0500 Subject: [Tutor] newbe Message-ID: I have been having fun reading this tutorial for the complete beginner. It's goes pretty fast so hang onto your hat :) http://yhslug.tux.org/obp/thinkCS/thinkCSpy/ sbb > -----Original Message----- > From: john smith smith [mailto:chetumal23@excite.com] > Sent: Friday, August 25, 2000 1:10 PM > To: tutor@python.org > Subject: [Tutor] newbe > > > where do i get started with learning python > > > > > > _______________________________________________________ > Say Bye to Slow Internet! > http://www.home.com/xinbox/signup.html From lizliao@yahoo.com Fri Aug 25 21:44:23 2000 From: lizliao@yahoo.com (Lin Zhang) Date: Fri, 25 Aug 2000 13:44:23 -0700 (PDT) Subject: [Tutor] invode executable Message-ID: <20000825204423.27132.qmail@web5304.mail.yahoo.com> I like to invoke a Fortran executable from within Python group. I know this can be easily done in UNIX shell script. How does one do it with Python script in MS-OS and UNIX system? Eventually I like to collect input from user through WEB, run the fortran exe on server, and return the output to user through WEB in HTML format. Is Python equipped to do that? If yes, shoud one utilize CGI or ASP? Thanks! __________________________________________________ Do You Yahoo!? Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ From dyoo@hkn.EECS.Berkeley.EDU Fri Aug 25 22:07:17 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Fri, 25 Aug 2000 14:07:17 -0700 (PDT) Subject: [Tutor] newbe In-Reply-To: Message-ID: > I am unable to access the second link you have supplied us 'newbies' > with... LOL Ouch. It should come back up soon --- silly Net problems... grrr. (It was up last night, I swear! *grin*) > Yup, *groan* a total newbie to programming. That's ok; that's what we're here for. Let's see... here's another link if you want to see what other people have asked: The Python FAQTS page: http://www.faqts.com/knowledge-base/index.phtml/fid/199/ and this one I'm sure it up at the time I'm posting this. From c.gruschow@prodigy.net Sat Aug 26 05:04:21 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Fri, 25 Aug 2000 23:04:21 -0500 Subject: [Tutor] I have been playing with Ivan Lan Laningham's mandelbrot and julia set creators written with Python, they are neat! Message-ID: <004e01c00f12$b7d39a60$17df6520@gruschow> I have been playing with Ivan Lan Laningham's mandelbrot and julia set creators written with Python, they are neat! c.gruschow@prodigy.net From c.gruschow@prodigy.net Sat Aug 26 05:06:39 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Fri, 25 Aug 2000 23:06:39 -0500 Subject: [Tutor] can python calculate the digits of pi or e?,has this been done before?,how? Message-ID: <005801c00f13$0a227700$17df6520@gruschow> can python calculate the digits of pi or e?,has this been done before?,how? c.gruschow@prodigy.net From c.gruschow@prodigy.net Sat Aug 26 05:12:36 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Fri, 25 Aug 2000 23:12:36 -0500 Subject: [Tutor] yet another ?,sorry,is Python good for relative beginners like me?,is Python better than other languages? Message-ID: <006201c00f13$de8187c0$17df6520@gruschow> yet another ?,sorry,is Python good for relative beginners like me?,is Python better than other languages? (like Visual Basic, C++, or others?) c.gruschow@prodigy.net p.s. I like Ivan Van Laningham's book: "Teach Yourself Python in 24 Hours" that I found a couple days ago. From wilson@visi.com Sat Aug 26 05:20:02 2000 From: wilson@visi.com (Timothy Wilson) Date: Fri, 25 Aug 2000 23:20:02 -0500 (CDT) Subject: [Tutor] can python calculate the digits of pi or e?,has this been done before?,how? In-Reply-To: <005801c00f13$0a227700$17df6520@gruschow> Message-ID: On Fri, 25 Aug 2000, Charles Gruschow, Jr. wrote: > can python calculate the digits of pi or e?,has this been done before?,how? If you're asking whether Python is capable of performing the calculations, then sure, no problem. If you're wondering how to use those numbers in your programs, then your can just: Python 1.5.2 (#1, May 9 2000, 15:05:56) [GCC 2.95.3 19991030 (prerelease)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import math >>> print math.pi 3.14159265359 >>> print math.e 2.71828182846 >>> -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From amoreira@mercury.ubi.pt Sat Aug 26 09:12:01 2000 From: amoreira@mercury.ubi.pt (amoreira@mercury.ubi.pt) Date: Sat, 26 Aug 2000 09:12:01 +0100 Subject: [Tutor] can python calculate the digits of pi or e?,has this been done before?,how? References: <005801c00f13$0a227700$17df6520@gruschow> Message-ID: <39A77BD1.BFE5BD46@mercury.ubi.pt> "Charles Gruschow, Jr." wrote: > > can python calculate the digits of pi or e?,has this been done before?,how? > > c.gruschow@prodigy.net > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor Hi! As for the digits of pi, you can try pi.py, in the standard dource distribution. I have it in [...]/Python-1.5.2/Demo/scripts/pi.py where Python-1.5.2 is the root of the source distribution. Cheers! Ze From dlaskey@laskeycpa.com Sat Aug 26 18:18:18 2000 From: dlaskey@laskeycpa.com (Daniel D. Laskey) Date: Sat, 26 Aug 2000 13:18:18 -0400 Subject: [Tutor] Example prog Message-ID: <01C00F60.1E3D8840@o1c-145.i2k.com> I recently purchased "Programming Python" and I'm working through the examples. On page 83 Mark has a simple program called pack1.py. What am I doing wrong? Page 83, Programming Python import sys marker = '::::::' for name in sys.argv[1:]: input = open(name, 'r') print marker + name print input.read(), C:\python>python pack1.py *.txt > stuff.txt Traceback (innermost last): File "pack1.py", line 5, in ? input = open(name, 'r') IOError: [Errno 2] No such file or directory: '*.txt' Daniel D. Laskey, CPA dlaskey@laskeycpa.com From elcultural.com@python.org Sat Aug 26 18:48:08 2000 From: elcultural.com@python.org (elcultural.com@python.org) Date: Sat, 26 Aug 2000 19:48:08 +0200 Subject: [Tutor] Actualidad cultural en Internet Message-ID: <208492000862617488950> Actualidad Cultural <html> <style type="text/css"> <!-- .sinsubrayado { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; font-style: normal; font-weight: bold; text-decoration: none; text-align: centre; color: #000000} --> </style> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td width="6" height="19" valign="top"></td> <td width="124" height="43" colspan="3" rowspan="2" valign="middle"><img SRC="http://www.elcultural.com/correo/img/elcultural.jpg" height=13 width=123></td> <td width="82" height="19" valign="top"></td> <td width="4" height="19" valign="top"></td> <td width="6" height="19" valign="top"></td> <td width="25" height="19" valign="top"></td> <td width="5" height="19" valign="top"></td> <td width="6" height="19" valign="top"></td> <td width="104" height="19" valign="top"></td> <td width="12" height="19" valign="top"></td> <td width="172" height="19" valign="top"></td> </tr> <tr> <td width="6" height="24" valign="top"></td> <td width="82" height="24" valign="top"></td> <td width="4" height="24" valign="top"></td> <td width="6" height="24" valign="top"></td> <td width="25" height="24" valign="top"></td> <td width="5" height="24" valign="top"></td> <td width="6" height="24" valign="top"></td> <td width="104" height="24" valign="top"></td> <td width="12" height="24" valign="top"></td> <td width="172" height="631" rowspan="16" valign="top" bgcolor="#FFFFCC"> <center><p><a href="http://www.elcultural.com"><img SRC="http://www.elcultural.com/correo/img/logo2.gif" BORDER=0 height=56 width=68></a></p> <p><b><font face="Arial,Helvetica"><font size=-2>Otros Titulares</font></font></b> </p> </center> <p align="left"><font size=-2><font face="Wingdings"> &nbsp;n<font face="Arial, Helvetica, sans-serif" size="1"> </font><font face="Arial,Helvetica"><font size=-1><font size="1"><a href="http://elcultural.com/contenidos/reportaje/070800/1.asp">Arte entre rejas, talentos en la c&aacute;rcel</a></font></font></font><font face="Arial, Helvetica, sans-serif" size="2"> </font><font face="Arial, Helvetica, sans-serif" size="1"> </font></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font><font size=-2><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/bflamenco/entrevistas03.htm">Antonio El Pipa: &quot;Mi meta es morirme bailando&quot;</a></font> </font> </font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font><font face="Arial, Helvetica, sans-serif" size="2"><font size="1"><a href="http://elcultural.com/contenidos/denominacion/140800/1.asp">Enrique Santana (Pintor) </a></font></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font><font size=-2><font size=-2><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/contenidos/madelante/140800/1.asp"><font size="1">&Aacute;ngel Sanzo, pianista</font></a></font></font></font> <font face="Arial, Helvetica, sans-serif" size="2"></font></font> <p align="left"><font size=-2><font face="Wingdings">&nbsp;n </font><font size=-2><font face="Wingdings"><font face="Arial, Helvetica, sans-serif" size="1"><a href="http://elcultural.com/contenidos/tema/270700/1.asp">Danza contempor&aacute;nea en Andaluc&iacute;a, la hermana pobre de las artes esc&eacute;nicas</a></font></font></font> </font> <p align="left"><font size="1" face="Arial, Helvetica, sans-serif"><br> </font> <p align="left"> <center> <center> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">Portada</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Noticias culturales</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/dinamica/index.html">Versi&oacute;n multimedia</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/criticas/default.asp">Cr&iacute;tica de eventos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/cds/default.asp">Rese&ntilde;as de discos</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/resenas/libros/default.asp">Rese&ntilde;as de libros</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com">Cartelera de Andaluc&iacute;a</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/eva/index.html">Espacio Virtual de las Artes</a></font></font> <br> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/arquitec/20000720/default.asp">Ar quitectura </a></font><br> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/flamenco/default.asp">Flamenco </a></font> <br> <font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/webdelasemana/default.asp">Web de la Semana</a></font><br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/andalucia/default.asp">Andaluc&iacute;a Cultural</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/entrevista/default.asp">Entrevist as</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/reportaje/default.asp">Reportajes </a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/evento/default.asp">Eventos</a></ font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/denominacion/default.asp">Denomin aci&oacute;n de Origen</a></font></font> <br> <font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/contenidos/tema/default.asp">Temas de Actualidad</a></font></font> </center> </center></td> </tr> <tr> <td width="6" height="22" valign="top"></td> <td width="356" height="22" colspan="10" valign="top" bgcolor="#FFFFCC"><table width="100%" border="0" mm_noconvert="TRUE"> <tr> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/cine.asp"><font color="#000099"><b>cine</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/arte.asp"><b><font color="#000099">arte</font></b></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/escena.asp"><font color="#000099"><b>escena</b></font></a></font></td> <td><font size="2" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/temas/musica.asp"><font color="#000099"><b>m&uacute;sica</b></font></a></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.elcultural.com/temas/literatura.asp"><b><font color="#000099">literatura</font></b></a></font></td> </tr> </table></td> <td width="12" height="22" valign="top"></td> </tr> <tr> <td width="6" height="8" valign="top"></td> <td width="103" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="9" height="8" valign="top"></td> <td width="82" height="8" valign="top"></td> <td width="4" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="25" height="8" valign="top"></td> <td width="5" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="104" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> </tr> <tr> <td width="6" height="136" valign="top"></td> <td width="356" height="136" colspan="10" valign="top"><b><font face="Arial, Helvetica, sans-serif" size="3">MANOLO SANL&Uacute;CAR: &quot;</font><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="3">Soy un artista entregado a mi cultura con vocaci&oacute;n religiosa</font></font></font></font></font></font></font><font face="Arial, Helvetica, sans-serif" size="3">"</font><font face="Arial, Helvetica, sans-serif" size="4"><br> </font><font size="1" face="Arial, Helvetica, sans-serif"> <a href="http://www.elcultural.com/contenidos/entrevista/20000822/1.asp"><img src="http://www.elcultural.com/correo/img/sanlucar.jpg" width="100" height="85" align="left" border="0"></a></font></b><font size="2" face="Arial, Helvetica, sans-serif"><font size="1">Bautizado como Manuel Mu&ntilde;oz Alc&oacute;n es uno de los grandes maestros de la guitarra flamenca de todos los tiempos. Pero la maestr&iacute;a no surge de la noche a la ma&ntilde;ana y Manolo Sanl&uacute;car se la ha ganado a pulso, con tes&oacute;n, trabajo y sobre todo un esp&iacute;ritu de investigaci&oacute;n incansable.</font></font><font size="1" face="Arial, Helvetica, sans-serif"> <a href="http://elcultural.com/contenidos/entrevista/20000707/1.asp"></a></font ><b><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/entrevista/20000822/1.asp"><br> M&aacute;s Informaci&oacute;n</a></font></b></td> <td width="12" height="136" valign="top"></td> </tr> <tr> <td width="6" height="25" valign="top"></td> <td width="356" height="25" colspan="10" valign="top"><hr WIDTH="350"></td> <td width="12" height="25" valign="top"></td> </tr> <tr> <td width="6" height="48" valign="top"></td> <td width="356" height="48" colspan="10" valign="top"> <p><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="4">Etnimusic 2000</font></font></font></font><font size="4" face="Arial, Helvetica, sans-serif">, un viaje sonoro con el mar mediterr&aacute;neo como tel&oacute;n de fondo </font></p> </td> <td width="12" height="48" valign="top"></td> </tr> <tr> <td width="6" height="105" valign="top"></td> <td width="246" height="105" colspan="8" valign="top"><font face="Arial, Helvetica, sans-serif" size="1">La fiebre por las músicas del mundo está teniendo también efectos en Andalucía. Para este mes de septiembre la cita está en la Playa del Peñón del Cuervo en Málaga, donde se celebra la primera edición de Etnimusic. Un viaje sonoro que se inicia en Cuba y finaliza en Escocia después de haber hecho escala en la India, el Magreb, Senegal, Macedonia, Rumania, Francia, Asturias y Galicia.</font><font size="1" face="Arial, Helvetica, sans-serif"> <b><font size="1" face="Arial, Helvetica, sans-serif"><a href="http://www.elcultural.com/contenidos/evento/20000823/1.asp">M&aacute;s Informaci&oacute;n</a></font></b> </font></td> <td width="6" height="105" valign="top"></td> <td width="104" height="105" valign="top"><a href="http://www.elcultural.com/contenidos/evento/20000823/1.asp"><img src="http://www.elcultural.com/correo/img/etnimusic.jpg" width="98" height="101" border="0"></a></td> <td width="12" height="105" valign="top"></td> </tr> <tr> <td width="6" height="25" valign="top"></td> <td width="356" height="25" colspan="10" valign="top"><hr WIDTH="100%"></td> <td width="12" height="25" valign="top"></td> </tr> <tr> <td width="6" height="4" valign="top"></td> <td width="103" height="4" valign="top"></td> <td width="12" height="4" valign="top"></td> <td width="9" height="4" valign="top"></td> <td width="82" height="4" valign="top"></td> <td width="4" height="4" valign="top"></td> <td width="6" height="4" valign="top"></td> <td width="140" height="118" colspan="4" rowspan="4" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="01" mm_noconvert="TRUE"> <tr> <td> <div align="center"><span class="nombreseccion"><font face="Arial, Helvetica, sans-serif" size="2"><b>Eventos recomendados</b></font></span></div> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3613," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Almer&iacute;a</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3923," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">C&aacute;diz</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3971," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">C&oacute;rdoba</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4078," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Granada</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4056," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">Huelva</font> </a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4074," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">Ja&eacute;n</font></a></span></div> </td> </tr> <tr> <td width="45%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,4090," class="titular"><font size="2" face="Arial, Helvetica, sans-serif">M&aacute;laga</font></a></span></div> </td> <td width="55%"> <div align="center"><span class="titular"><a href="http://www.elcultural.com/buscador/resultados.asp?Mf4G22S=,3681," class="titular"><font face="Arial, Helvetica, sans-serif" size="2">Sevilla</font></a></span></div> </td> </tr> </table> </td> </tr> </table></td> <td width="12" height="4" valign="top"></td> </tr> <tr> <td width="6" height="34" valign="top"></td> <td width="210" height="34" colspan="5" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Denominaci&oacute;n de Origen<br> <font size="1"><a href="http://elcultural.com/contenidos/denominacion/20000821/1.asp">Manuel Hidalgo (Compositor) </a></font></font></td> <td width="6" height="34" valign="top"></td> <td width="12" height="34" valign="top"></td> </tr> <tr> <td width="6" height="50" valign="top"></td> <td width="210" height="50" colspan="5" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Entrevista<br> <a href="http://elcultural.com/contenidos/entrevista/20000707/1.asp"><font size="1">Juan Manuel de Prada: &quot;Concibo el para&iacute;so bajo la especie de una biblioteca&quot; </font></a><br> </font></td> <td width="6" height="50" valign="top"></td> <td width="12" height="50" valign="top"></td> </tr> <tr> <td width="6" height="30" valign="top"></td> <td width="210" height="47" colspan="5" rowspan="2" valign="top"><font face="Arial,Helvetica"><font size=-1>Evento<br> <font size="1"><a href="http://elcultural.com/contenidos/evento/090800/1.asp">M&aacute;laga acoge una muestra de Oswaldo Guayasam&iacute;n</a></font></font></font></td> <td width="6" height="30" valign="top"></td> <td width="12" height="30" valign="top"></td> </tr> <tr> <td width="6" height="17" valign="top"></td> <td width="6" height="17" valign="top"></td> <td width="25" height="17" valign="top"></td> <td width="115" height="120" colspan="3" rowspan="4" valign="top"><div align="center"> <p><b><font size="1" face="Arial, Helvetica, sans-serif">En elcultural.com</font></b> </p> </div> <div align="center"><a href="http://www.elcultural.com/bflamenco"><img width="90" height="90" src="http://www.elcultural.com/correo/img/banner90.gif" border="0"></a></div></td> <td width="12" height="17" valign="top"></td> </tr> <tr> <td width="6" height="34" valign="top"></td> <td width="206" height="34" colspan="4" valign="top"><font size="2" face="Arial, Helvetica, sans-serif">Web de la Semana</font><font size="1" face="Arial, Helvetica, sans-serif">: <br> <a href="http://elcultural.com/contenidos/webdelasemana/20000821.asp">Fotoporta l, un buscador hispano de fotograf&iacute;a</a></font></td> <td width="4" height="34" valign="top"></td> <td width="6" height="34" valign="top"></td> <td width="25" height="34" valign="top"></td> <td width="12" height="34" valign="top"></td> </tr> <tr> <td width="6" height="26" valign="top"></td> <td width="216" height="26" colspan="6" valign="top"> <hr></td> <td width="25" height="26" valign="top"></td> <td width="12" height="26" valign="top"></td> </tr> <tr> <td width="6" height="43" valign="top"></td> <td width="103" height="43" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Mirada atr&aacute;s<br> <a href="http://www.elcultural.com/contenidos/matras/20000821/1.asp"><font size="1">Rafael Cansino Assens, escritor </font></a></font></td> <td width="12" height="43" valign="top"></td> <td width="101" height="43" colspan="4" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Mirada adelante </font><br> <font size="2" face="Arial, Helvetica, sans-serif"><a href="http://elcultural.com/contenidos/madelante/140800/1.asp"><font size="1">&Aacute;ngel Sanzo, pianista</font></a></font></td> <td width="25" height="43" valign="top"></td> <td width="12" height="43" valign="top"></td> </tr> <tr> <td width="6" height="8" valign="top"></td> <td width="103" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="9" height="8" valign="top"></td> <td width="82" height="8" valign="top"></td> <td width="4" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="25" height="8" valign="top"></td> <td width="5" height="8" valign="top"></td> <td width="6" height="8" valign="top"></td> <td width="104" height="8" valign="top"></td> <td width="12" height="8" valign="top"></td> <td width="172" height="8" valign="top"></td> </tr> <tr> <td width="6" height="50" valign="top"></td> <td width="540" height="50" colspan="12" valign="top"><center> <p><font face="Arial,Helvetica"><font size=-2><a href="http://www.elcultural.com/">portada </a>/ <a href="http://www.elcultural.com/dinamica/index.html">contenidos multimedias de la semana</a> / <a href="mailto:redaccion@elcultural.com">sugerencias</a> / <a href="http://www.elcultural.com/quienes/default.asp">sobre elcultural.com</a>/ <a href="http://www.elcultural.com/prensa/default.asp">dossier de prensa</a></font></font> <br> &nbsp;<br> <font face="Arial,Helvetica"><font size=-2>Si no quieres volver a recibir mensajes de elcultural.com pincha <a href="http://www.elcultural.com/suscripciones/baja.asp">aqu&iacute;</a> y b&oacute;rrate de la Secci&oacute;n Contenidos de Actualidad</font></font> </center></td> </tr> <tr> <td width="6" height="1" valign="top"><img width="6" height="1" src="transparent.gif"></td> <td width="103" height="1" valign="top"><img width="103" height="1" src="transparent.gif"></td> <td width="12" height="1" valign="top"><img width="12" height="1" src="transparent.gif"></td> <td width="9" height="1" valign="top"><img width="9" height="1" src="transparent.gif"></td> <td width="82" height="1" valign="top"><img width="82" height="1" src="transparent.gif"></td> <td width="4" height="1" valign="top"><img width="4" height="1" src="transparent.gif"></td> <td width="6" height="1" valign="top"><img width="6" height="1" src="transparent.gif"></td> <td width="25" height="1" valign="top"><img width="25" height="1" src="transparent.gif"></td> <td width="5" height="1" valign="top"><img width="5" height="1" src="transparent.gif"></td> <td width="6" height="1" valign="top"><img width="6" height="1" src="transparent.gif"></td> <td width="104" height="1" valign="top"><img width="104" height="1" src="transparent.gif"></td> <td width="12" height="1" valign="top"><img width="12" height="1" src="transparent.gif"></td> <td width="172" height="1" valign="top"><img width="172" height="1" src="transparent.gif"></td> </tr> </table> </body> From amoreira@mercury.ubi.pt Sun Aug 27 02:25:51 2000 From: amoreira@mercury.ubi.pt (amoreira@mercury.ubi.pt) Date: Sun, 27 Aug 2000 02:25:51 +0100 Subject: [Tutor] Example prog References: <01C00F60.1E3D8840@o1c-145.i2k.com> Message-ID: <39A86E1F.36CF69AD@mercury.ubi.pt> Hi! Your invocation of the script, where you say > C:\python>python pack1.py *.txt > stuff.txt tries to open all files with .txt extension in the current directory. If you don't have any, the script ends with that error message. Are you sure to have a .txt file in the working dir? I hope that that's it! Cheers, Ze "Daniel D. Laskey" wrote: > > I recently purchased "Programming Python" and I'm working through the examples. > On page 83 Mark has a simple program called pack1.py. What am I doing wrong? > > Page 83, Programming Python > > import sys > marker = '::::::' > > for name in sys.argv[1:]: > input = open(name, 'r') > print marker + name > print input.read(), > > C:\python>python pack1.py *.txt > stuff.txt > > Traceback (innermost last): > File "pack1.py", line 5, in ? > input = open(name, 'r') > IOError: [Errno 2] No such file or directory: '*.txt' > > Daniel D. Laskey, CPA > dlaskey@laskeycpa.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 27 10:22:20 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 27 Aug 2000 02:22:20 -0700 (PDT) Subject: [Tutor] Example prog In-Reply-To: <39A86E1F.36CF69AD@mercury.ubi.pt> Message-ID: On Sun, 27 Aug 2000 amoreira@mercury.ubi.pt wrote: > Hi! > Your invocation of the script, where you say > > C:\python>python pack1.py *.txt > stuff.txt > tries to open all files with .txt extension in the current directory. If > you don't have any, the script ends with that error message. Are you > sure to have a .txt file in the working dir? > I hope that that's it! What's happening is that Windows systems do not substitute '*.txt' for the files in the directory --- this behavior is in contrast to UNIX, and is really unfortunate. Every Windows program apparently has to do this wildcard expansion manually. Thankfully, Python provides a nice module that does a lot of the work that UNIX does in doing wildcard substitutions. It's called the 'glob' module, so you should be able to do something like this: ### globfileargs.py import glob def getGlobbedFilenames(args): results = [] for a in args: l = glob.glob(a) if len(l) > 0: results = results + l return results import sys if __name__ == '__main__': print "Here's sys.argv[1:]:", sys.argv[1:] args = getGlobbedFilenames(sys.argv[1:]) print "And here is an expanded list of the files we can match:" print args ### For example: ### [dyoo@einfall dyoo]$ python globfiles.py '*.py' Here's sys.argv[1:]: ['*.py'] And here is an expanded list of the files we can match: ['globfiles.py', 'graph.py'] ### Hopefully, this should fix things for you. From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 27 10:47:28 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 27 Aug 2000 02:47:28 -0700 (PDT) Subject: [Tutor] can python calculate the digits of pi or e?,has this been done before?,how? In-Reply-To: <005801c00f13$0a227700$17df6520@gruschow> Message-ID: On Fri, 25 Aug 2000, Charles Gruschow, Jr. wrote: > can python calculate the digits of pi or e?,has this been done > before?,how? There's a very very cool way of calculating Pi using a "Monty Carlo" method. That is, we can get Pi's value through random numbers! I haven't tried it out myself yet, but let me see if I can remember it... Here's the general idea --- let's call it the dart throwing method: Ok, so you know that a circle's area is (Pi * r**2). Draw a circle of radius 1: *** * * * * *** |--| 1 Our center. Ok, now draw a square that surrounds that circle. The square itself has sides of length 2. 2 ------- | *** | |* *| |* *| | *** | ------- |--| 1 Our dartboard. We can see that our picture can be divided into two sections --- the region inside the circle, and the region outside of the circle. Now imagine sampling random dots on this picture. You're throwing darts. Some of the darts will be in the circle, while others will fall outside the circle. You can write a program that simulates dart throwing, and can count how many go inside or outside the circle. Probablistically, the ratio between those two counts should approximate the ratio between the _areas_ of inside and outside. That is, area of inside/area of outside == (number of points in circle)/(number of points outside circle) But we already know that the area inside our circle == Pi, and the area of the outside is (area of square - circle) == 4 - Pi. There might be an easier way to simplify the algebra, or a simpler way of looking at this problem, so you might want to play around with it for a while. I hope this gives you enough to make a Pi finding program. You might need to throw a lot of darts to get accuracy out of this thing, but you should get a reasonable approximation this way. The whrandom module, which has functions to get random numbers, should be really helpful with this. Here's the link to it: http://python.org/doc/current/lib/module-whrandom.html If you need more help with this method, email again to tutor@python.org. Good luck! From dyoo@hkn.EECS.Berkeley.EDU Sun Aug 27 10:56:19 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 27 Aug 2000 02:56:19 -0700 (PDT) Subject: [Tutor] I have been playing with Ivan Lan Laningham's mandelbrot and julia set creators written with Python, they are neat! In-Reply-To: <004e01c00f12$b7d39a60$17df6520@gruschow> Message-ID: On Fri, 25 Aug 2000, Charles Gruschow, Jr. wrote: > I have been playing with Ivan Lan Laningham's mandelbrot and julia set > creators written with Python, they are neat! Cool, can you email us the link too? I'd like to see it. From c.gruschow@prodigy.net Sun Aug 27 23:51:22 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Sun, 27 Aug 2000 17:51:22 -0500 Subject: [Tutor] re: I have been playing with mandelbrot and julia set creators written with Python References: Message-ID: <001701c01079$54131d80$58df6520@gruschow> These were written by Ivam Van Laningham in his book "Teach Yourself Python In 24 Hours". The website he has relating to the book, I hope its ok if I give this out, is: http://www.pauahtun.org/TYPython/ He talks about Mandelbrot and Julia sets in chapter 23. according to my understanding: mandelbrot set is: z=z^2+c z starts out at 0j (j being the square root of -1, "the imaginary number") you pick a value of c (a complex number such as -0.5+0.8j) the values of c come from the y-axis(the complex plane) and the x-axis(the real plane) intersection plane we limit ourselves to a field of 160,000 points picked out from -2.0 to 2.0 on both axes julia set is also: z=z^2+c but: c stays at a constant value the initial z changes depending upon which point on the x-y plane we choose as our starting point the number of iterations it takes to reach an absolute value of z of greater than 2.0 gives us our color the more iterations it takes the slower the attraction toward infinity (the object of these sets is to look for infinite attractors) the values that don't approach infinity or approach infinity very slowly are in our set, and they are colored black for each point in the Mandelbrot set there is a corresponding Julia set the Mandelbrot set is claimed to be bigger than our universe c.gruschow@prodigy.net ----- Original Message ----- From: Daniel Yoo To: Charles Gruschow, Jr. Cc: Sent: Sunday, August 27, 2000 4:56 AM Subject: Re: [Tutor] I have been playing with Ivan Lan Laningham's mandelbrotand julia set creators written with Python, they are neat! > On Fri, 25 Aug 2000, Charles Gruschow, Jr. wrote: > > > I have been playing with Ivan Lan Laningham's mandelbrot and julia set > > creators written with Python, they are neat! > > Cool, can you email us the link too? I'd like to see it. > > From c.gruschow@prodigy.net Mon Aug 28 00:04:07 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Sun, 27 Aug 2000 18:04:07 -0500 Subject: [Tutor] I found a neat module called real.py Message-ID: <002701c0107b$1b650140$58df6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_0023_01C01051.31CEB680 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0024_01C01051.31CEB680" ------=_NextPart_001_0024_01C01051.31CEB680 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable this module I found the other day, I was looking for something to learn = from, I looked at this site called "The Vaults of Parnassus". Vaults:=20 http://www.vex.net/parnassus/ it creates a number category called real you can do neat things with it like have it calculate pi to 50 decimal = places and it will give the error it will also do log,log10,fact,e,berns,etc. real.py comes from: http://www.vex.net/parnassus/apyllo.py/684222876 > =20 1999/10 =20 real-accurate.py 1.11 - Ideal real number math - a library = that introduces a new class, called Real, of abitrarily precise numbers, = allowing computations with "infinite" precision. =20 =20 or: http://www.vex.net/parnassus/apyllo2.py/3267957 or: ftp://ftp.python.org/pub/www.python.org/ftp/python/contrib-09-Dec-1999/Da= taStructures/=20 ------=_NextPart_001_0024_01C01051.31CEB680 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

this module I found the other day, I was looking = for=20 something to learn from, I looked at this site called "The Vaults of=20 Parnassus".

Vaults:

http://www.vex.net/parnassus/<= /FONT>

 

it creates a number category called = real

you can do neat things with it like have it = calculate pi to=20 50 decimal places and it will give the error

it will also do = log,log10,fact,e,berns,etc.

 

 

real.py comes from:

http://www.vex.= net/parnassus/apyllo.py/684222876

> =  
 1999/10 
3D** 
 real-accurate.py= =20 1.11 -  Ideal real number math - a library that = introduces a=20 new class, called Real, of abitrarily precise numbers, = allowing=20 computations with "infinite" precision. <more>=20 =  
<= /P>

or: http://www.vex.n= et/parnassus/apyllo2.py/3267957
or:
ftp://ftp.python.org/pub/www.python.org/ftp/python= /contrib-09-Dec-1999/DataStructures/=20
 
------=_NextPart_001_0024_01C01051.31CEB680-- ------=_NextPart_000_0023_01C01051.31CEB680 Content-Type: image/gif; name="bultmp2.gif" Content-Transfer-Encoding: base64 Content-Location: http://www.vex.net/parnassus/gfx/bultmp2.gif R0lGODlhFAAUAPZ/AFw0GDKOfpqOApIeSohWOHKaMr7KDvYyioSoKAd7nIY+LrrOls6SirY2fu5q noiaFFxEHH6mNtbcBmpeMqYyToqUWFSaX6qyDnA+FiWJh4agJJ6uWtp2Wto2lpa2Js6KhqoeZp5y AsLMCJSuGJJKGvKykpWVBPD47GCaTBaCkK4+fpa2TuDgArzEAnY2Mv5IxsTWHFI6FkeTZogqTpZm OnqaJn5EGIqmSKJCKv52/opCNv72/pRYQIqoJP6asv5g7HZ6Sv6y/oZyQuJCWv5Gjpq+Mv46rqrC ToqKUo42Xv5yysreurpGUromVv6D/poyRsJGfvKO2vrCqoaiRqo+Tr4WYn42GpYuRmYuMqLCdmY+ ElpOJrLKLsJCojKKenqGTpqaCqbGJm6iRsqanmKiXq5GOpBERP7++5CuRo6uKnqiNmqeRn4yRpYu YsAygJKaCtraAqayav5Oxt46qv66/v6K/srWFI6WENLaEnI+KiqKgsLGCoZGRjqSelqeYv///yH5 BAEAAH8ALAAAAAAUABQAAAfqgH+Cg4MZhoSIiX9+eDAwKYqKASwrWxdikYgpMGkxABUhfpmDRTAT EHl8Nw8Bo2R4X1oKbGYEGmoZkX0saDEKVDMzPEIPCAmJGXhoEBhWZW0DfARIGhHHhFweWzYkOEwN IE88NBVgooRFQFhJKl1zHW5VTRRPEeeDaBEndE5BP25QjLx4MaaFBUQZwNw4U8LHjhw/XgzhAMNa oj4mspz5cKZOjgMKuIyApAiFiSVSdjhxQmSDiFaREtR4cOKMEicf4KAY9SeFiRVnHESBYYznHxkm Frg4soek0QJ34uzpY3RQCjFi1lTd+icQACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVy IQAAOw== ------=_NextPart_000_0023_01C01051.31CEB680-- From c.gruschow@prodigy.net Mon Aug 28 00:09:25 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Sun, 27 Aug 2000 18:09:25 -0500 Subject: [Tutor] how do you format/fix/convert types of numbers when you print them? Message-ID: <004501c0107b$d85bf1a0$58df6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_0042_01C01051.EEBC7F20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable how do you format/fix/convert types of numbers when you print them? how do you convert one number type to another? how do you print only a certain number of decimal places? sorry if these ?'s sound too beginnerish (is that a word? :) ) to you c.gruschow@prodigy.net ------=_NextPart_000_0042_01C01051.EEBC7F20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

how do you format/fix/convert types of numbers when you print = them?

how do you convert one number type to another?

how do you print only a certain number of decimal places?

sorry if these ?'s sound too beginnerish (is that = a word? :)=20 ) to you

c.gruschow@prodigy.net<= /P>

 

------=_NextPart_000_0042_01C01051.EEBC7F20-- From c.gruschow@prodigy.net Mon Aug 28 00:12:40 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Sun, 27 Aug 2000 18:12:40 -0500 Subject: [Tutor] is there a site that lists programming projects for you to try to figure out? Message-ID: <005b01c0107c$4d0164e0$58df6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_0058_01C01052.636B1A20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable is there a site that lists programming projects for you to try to figure = out? c.gruschow@prodigy.net ------=_NextPart_000_0058_01C01052.636B1A20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

is there a site that lists programming projects for you to try to = figure=20 out?

c.gruschow@prodigy.net

 

------=_NextPart_000_0058_01C01052.636B1A20-- From rufmetal@interlog.com Mon Aug 28 00:12:21 2000 From: rufmetal@interlog.com (Christopher Keelan) Date: Sun, 27 Aug 2000 19:12:21 -0400 Subject: [Tutor] Why am I getting an infinite loop? Message-ID: <00082719145000.06559@localhost.localdomain> I'm working through an exercise in O'Reilly's "Learning Python". Here's the code --- l=[1,2,4,8,16,32,64] d=5 i = 0 print 'length of list is', len(l) while i < len(l): if 2**d == l[i]: print 'at index', i break i = i+1 else: print d, 'not found' --- When I test it by running the script, I get an infinite loop at the print statemnt. Any ideas why this is happening? Thanks in advance. - Chris From spirou@aragne.com Mon Aug 28 00:40:15 2000 From: spirou@aragne.com (Denis) Date: Mon, 28 Aug 2000 01:40:15 +0200 Subject: [Tutor] Why am I getting an infinite loop? In-Reply-To: <00082719145000.06559@localhost.localdomain>; from rufmetal@interlog.com on Sun, Aug 27, 2000 at 07:12:21PM -0400 References: <00082719145000.06559@localhost.localdomain> Message-ID: <20000828014015.F30648@aragne.com> Le Sun, Aug 27, 2000 at 07:12:21PM -0400, Christopher Keelan pianota: > I'm working through an exercise in O'Reilly's "Learning Python". > > When I test it by running the script, I get an infinite loop at the print > statemnt. Any ideas why this is happening? > Just an indentation problem : Idle 0.6 wouldn't let you write that : there's a automagic dedent when you write a break statement. > Here's the code > --- > l=[1,2,4,8,16,32,64] > d=5 > i = 0 > > print 'length of list is', len(l) > while i < len(l): > if 2**d == l[i]: > print 'at index', i > break > i = i+1 > else: > print d, 'not found' > --- try this as your while loop > --- while i < len(l): if 2**d == l[i]: print 'at index', i break i = i+1 else: print d, 'not found' > --- Logic, isn't it ? ;-) Greetings from here. -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From spirou@aragne.com Mon Aug 28 00:52:07 2000 From: spirou@aragne.com (Denis) Date: Mon, 28 Aug 2000 01:52:07 +0200 Subject: [Tutor] how do you format/fix/convert types of numbers when you print them? In-Reply-To: <004501c0107b$d85bf1a0$58df6520@gruschow>; from c.gruschow@prodigy.net on Sun, Aug 27, 2000 at 06:09:25PM -0500 References: <004501c0107b$d85bf1a0$58df6520@gruschow> Message-ID: <20000828015207.G30648@aragne.com> Le Sun, Aug 27, 2000 at 06:09:25PM -0500, Charles Gruschow, Jr. pianota: > how do you format/fix/convert types of numbers when you print them? > > how do you convert one number type to another? > > how do you print only a certain number of decimal places? look at this interactive session log, check the docs for further information. >>> a = 112.25689 >>> print a 112.25689 >>> print type(a) >>> b = int(a) >>> print b 112 >>> print type(b) >>> c = float(b) >>> print c 112.0 >>> print type(c) >>> print "%d" % b 112 >>> print "%04d" % b 0112 >>> print "%4d" % b 112 >>> print "%4d" % a 112 >>> print "%.2f" % a 112.26 Play with the interpreter, that one of the pleasures of Python. ;-) -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From spirou@aragne.com Mon Aug 28 00:58:51 2000 From: spirou@aragne.com (Denis) Date: Mon, 28 Aug 2000 01:58:51 +0200 Subject: [Tutor] is there a site that lists programming projects for you to try to figure out? In-Reply-To: <005b01c0107c$4d0164e0$58df6520@gruschow>; from c.gruschow@prodigy.net on Sun, Aug 27, 2000 at 06:12:40PM -0500 References: <005b01c0107c$4d0164e0$58df6520@gruschow> Message-ID: <20000828015851.H30648@aragne.com> Le Sun, Aug 27, 2000 at 06:12:40PM -0500, Charles Gruschow, Jr. pianota: > is there a site that lists programming projects for you to try to figure out? There are lots of things you can do for yourself : - suppress your old .bak files - check your logs - sort your images - build a web page - count your work hours - ... Do you need assignments ? ;-) -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From david.phoon@acnielsen.com.au Mon Aug 28 06:08:13 2000 From: david.phoon@acnielsen.com.au (Phoon, David) Date: Mon, 28 Aug 2000 16:08:13 +1100 Subject: [Tutor] help for tkinter Message-ID: <509FE401C620D311A3890001FA68BA955364D3@ACNSYDMSX10.acnielsen.com.au> hi I did the following and got what was expected, a dialog box to show tkinter is present and ok. however how do you use or make a canvas to draw the arc as below?within the winPython ide >>> import _tkinter >>> >>> import Tkinter >>> Tkinter._test() >>> xy = 20,20,30,180 >>> canvas.create_arc(xy,start=0,extent=270,fill ="red") Traceback (innermost last): File "", line 0, in ? thanks david Phoon From c.gruschow@prodigy.net Mon Aug 28 06:45:07 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Mon, 28 Aug 2000 00:45:07 -0500 Subject: [Tutor] re: Monte Python method you suggested for pi References: Message-ID: <000d01c010b3$20cbee40$8ddf6520@gruschow> program I figured out is below: I used the real.py module from: ##real.py was obtained from ftp://ftp.python.org/pub/www.python.org/ftp/python/contrib-09-Dec-1999/DataS tructures/real-accurate.pyar ##from the Vaults of Parnassus website (using real.py module: pi(1000)=3.1415926535897932384626433832795028841971693 993751058209749445923078164062862089986280348253 421170679821480865132823066470938446095505822317 253594081284811174502841027019385211055596446229 4895493038196442881097566593344612847564823378678 31652712019091456485669234603486104543266482133936 072602491412737245870066063155881748815209209628292 54091715364367892590360011330530548820466521384146951 941511609433057270365759591953092186117381932611793105 1185480744623799627495673518857527248912279381830119491 298336733624406566430860213949463952247371907021798609437 027705392171762931767523846748184676694051320005681271452635 6082778577134275778960917363717872146844090122495343014654958537 10507922796892589235420199561121290219608640344181598136297747713 0996051870721134999999837297804995105973173281609631859502445945534 690830264252230825334468503526193118817101000313783875288658753320838 14206171776691473035982534904287554687311595628638823537875937519577818 5778053217122680661300192787661119590921642019894+-2 (the +-2 is error n last digit)(pi to a thousand decimal places)) Did you mean something like this: ##There's a very very cool way of calculating Pi using a "Monty Carlo" ##method. That is, we can get Pi's value through random numbers! I haven't ##tried it out myself yet, but let me see if I can remember it... Here's the ##general idea --- let's call it the dart throwing method: ## ## ##Ok, so you know that a circle's area is (Pi * r**2). Draw a circle of ##radius 1: ## ## *** ## * * ## 1 ## ##Our center. Ok, now draw a square that surrounds that circle. The square ##itself has sides of length 2. ## ## 2 ## ------- ## | *** | ## |* *| ## |* *| ## | *** | ## ------- ## |--| ## 1 ## ##Our dartboard. We can see that our picture can be divided into two ##sections --- the region inside the circle, and the region outside of the ##circle. ## ##Now imagine sampling random dots on this picture. You're throwing darts. ##Some of the darts will be in the circle, while others will fall outside ##the circle. You can write a program that simulates dart throwing, and can ##count how many go inside or outside the circle. ## ## ##Probablistically, the ratio between those two counts should approximate ##the ratio between the _areas_ of inside and outside. That is, ## ##area of inside/area of outside == ## (number of points in circle)/(number of points outside circle) ## ##But we already know that the area inside our circle == Pi, and the area of ##the outside is (area of square - circle) == 4 - Pi. ## ## ##There might be an easier way to simplify the algebra, or a simpler way of ##looking at this problem, so you might want to play around with it for a ##while. ## ## ## * * ## *** ## |--| ## 1 ## ##Our center. Ok, now draw a square that surrounds that circle. The square ##itself has sides of length 2. ## ## 2 ## ------- ## | *** | ## |* *| ## |* *| ## | *** | ## ------- ## |--| ## 1 ## ##Our dartboard. We can see that our picture can be divided into two ##sections --- the region inside the circle, and the region outside of the ##circle. ## ##Now imagine sampling random dots on this picture. You're throwing darts. ##Some of the darts will be in the circle, while others will fall outside ##the circle. You can write a program that simulates dart throwing, and can ##count how many go inside or outside the circle. ## ## ##Probablistically, the ratio between those two counts should approximate ##the ratio between the _areas_ of inside and outside. That is, ## ##area of inside/area of outside == ## (number of points in circle)/(number of points outside circle) ## ##But we already know that the area inside our circle == Pi, and the area of ##the outside is (area of square - circle) == 4 - Pi. ## ## ##There might be an easier way to simplify the algebra, or a simpler way of ##looking at this problem, so you might want to play around with it for a ##while. ## ## ##I hope this gives you enough to make a Pi finding program. You might need ##to throw a lot of darts to get accuracy out of this thing, but you should ##get a reasonable approximation this way. The whrandom module, which has ##functions to get random numbers, should be really helpful with this. ## ##area in=pi, area out=4-pi,pi/(4-pi)=ratio,ratio*(4-pi)=pi,4*ratio-pi*ratio=pi ##4*ratio=pi+pi*ratio,4*ratio=pi(1+ratio),(4*ratio)/(1+ratio)=pi ##3.659792366325487694478707269257069621324770947309660129799649133113166238 050709740338287247078949605+-1 ##would be ideal ratio to 100 decimal places ##real.py was obtained from ftp://ftp.python.org/pub/www.python.org/ftp/python/contrib-09-Dec-1999/DataS tructures/real-accurate.pyar ##from the Vaults of Parnassus website import whrandom from whrandom import * import real from real import * seed(x=0,y=0,z=0) ptin,ptout=0,0 for a in range(1,1000): seed(x=0,y=0,z=0) xt,yt=uniform(-1.0,1.0),uniform(-1.0,1.0) rsqr,r=xt**2+yt**2,sqrt(rsqr) if rsqr==1: #print xt,yt,r,"on circle" ptin=ptin+1 if rsqr<1: #print xt,yt,r,ptin,"inside circle" ptin=ptin+1 if rsqr>1: #print xt,yt,r,ptout,"outside circle" ptout=ptout+1 if ptout>0: print a,ptin,ptout,float(ptin)/float(ptout) fptin=float(ptin) fptout=float(ptout) ptrat=fptin/fptout print fptin,fptout,ptrat,(4*ptrat)/(1+ptrat) ----- Original Message ----- From: Daniel Yoo To: Charles Gruschow, Jr. Cc: Sent: Sunday, August 27, 2000 4:47 AM Subject: Re: [Tutor] can python calculate the digits of pi or e?,has thisbeen done before?,how? > On Fri, 25 Aug 2000, Charles Gruschow, Jr. wrote: > > > can python calculate the digits of pi or e?,has this been done > > before?,how? > > > There's a very very cool way of calculating Pi using a "Monty Carlo" > method. That is, we can get Pi's value through random numbers! I haven't > tried it out myself yet, but let me see if I can remember it... Here's the > general idea --- let's call it the dart throwing method: > > > Ok, so you know that a circle's area is (Pi * r**2). Draw a circle of > radius 1: > > *** > * * > * * > *** > |--| > 1 > > Our center. Ok, now draw a square that surrounds that circle. The square > itself has sides of length 2. > > 2 > ------- > | *** | > |* *| > |* *| > | *** | > ------- > |--| > 1 > > Our dartboard. We can see that our picture can be divided into two > sections --- the region inside the circle, and the region outside of the > circle. > > Now imagine sampling random dots on this picture. You're throwing darts. > Some of the darts will be in the circle, while others will fall outside > the circle. You can write a program that simulates dart throwing, and can > count how many go inside or outside the circle. > > > Probablistically, the ratio between those two counts should approximate > the ratio between the _areas_ of inside and outside. That is, > > area of inside/area of outside == > (number of points in circle)/(number of points outside circle) > > But we already know that the area inside our circle == Pi, and the area of > the outside is (area of square - circle) == 4 - Pi. > > > There might be an easier way to simplify the algebra, or a simpler way of > looking at this problem, so you might want to play around with it for a > while. > > > I hope this gives you enough to make a Pi finding program. You might need > to throw a lot of darts to get accuracy out of this thing, but you should > get a reasonable approximation this way. The whrandom module, which has > functions to get random numbers, should be really helpful with this. > Here's the link to it: > > http://python.org/doc/current/lib/module-whrandom.html > > If you need more help with this method, email again to tutor@python.org. > Good luck! > From c.gruschow@prodigy.net Mon Aug 28 06:48:40 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Mon, 28 Aug 2000 00:48:40 -0500 Subject: [Tutor] the last message I sent, I meant Monte Carlo not Monte Python, oops... :) Message-ID: <001a01c010b3$9ef942e0$8ddf6520@gruschow> This is a multi-part message in MIME format. ------=_NextPart_000_0017_01C01089.B5383EA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable the last message I sent, I meant Monte Carlo not Monte Python, oops... = :) ------=_NextPart_000_0017_01C01089.B5383EA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

the last message I sent, I meant Monte Carlo not Monte Python, = oops...=20 :)

------=_NextPart_000_0017_01C01089.B5383EA0-- From dyoo@hkn.EECS.Berkeley.EDU Mon Aug 28 07:10:18 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Sun, 27 Aug 2000 23:10:18 -0700 (PDT) Subject: [Tutor] re: Monte Python method you suggested for pi In-Reply-To: <000d01c010b3$20cbee40$8ddf6520@gruschow> Message-ID: > the last message I sent, I meant Monte Carlo not Monte Python, > oops... :) Actually, that name is oddly appropriate... *grin* There's a slight bug in the program --- it has to do with the way the tuple assignment works. The line: > rsqr,r=xt**2+yt**2,sqrt(rsqr) will compute the two values on the right hand side first, and _then_ do the tuple assignments afterwards. The problem is that at the time Python computes the right hand side, 'rsqr' isn't known. To fix this, you'll have to do it the non-tricky way to have the same effect. The rest of the program looks good! I couldn't help but try my own hand at this. I found a way of simplifying the logic --- just compare the ratio between the circle and the whole area. That is, Pi / 4 = (# of points in circle) / (total points) which can be restated as: Pi = 4 * (# of points in circle) / (total points) Here's the program that implements this: ### pi.py (pie pie!) from whrandom import random from math import sqrt def makePoint(): x = (random() * 2) - 1 y = (random() * 2) - 1 return (x,y) def insideCircle(p): x, y = p return sqrt(x**2 + y**2) < 1 def getPi(iterations): count = 0 for i in xrange(iterations): if insideCircle(makePoint()): count = count + 1 return 4 * count / float(iterations) ### And a few sample runs: ### >>> getPi(10) 3.6 >>> getPi(100) 3.32 >>> getPi(1000) 3.144 >>> getPi(10000) 3.1132 >>> getPi(100000) 3.14792 >>> getPi(1000000) # After a long long long time... 3.141808 ### So this isn't quite an efficient way of calculating Pi, but it does work. From spirou@aragne.com Mon Aug 28 08:56:14 2000 From: spirou@aragne.com (Denis) Date: Mon, 28 Aug 2000 09:56:14 +0200 Subject: [Tutor] help for tkinter In-Reply-To: <509FE401C620D311A3890001FA68BA955364D3@ACNSYDMSX10.acnielsen.com.au>; from david.phoon@acnielsen.com.au on Mon, Aug 28, 2000 at 04:08:13PM +1100 References: <509FE401C620D311A3890001FA68BA955364D3@ACNSYDMSX10.acnielsen.com.au> Message-ID: <20000828095614.A2386@aragne.com> Le Mon, Aug 28, 2000 at 04:08:13PM +1100, Phoon, David pianota: > > hi I did the following and got what was expected, a dialog box to show > tkinter is present and ok. however how do you use or make a canvas to draw > the arc as below?within the winPython ide > >>> import Tkinter If you import Tkinter you will have to qualify all the widgets. Usually, everything from Tkinter is imported : from Tkinter import * > >>> Tkinter._test() > >>> xy = 20,20,30,180 > >>> canvas.create_arc(xy,start=0,extent=270,fill ="red") > Traceback (innermost last): > File "", line 0, in ? There, you call a method on an object that is not intanciated yet. Try something like : root = Tk() cv = Canvas(root) cv.pack(expand=YES, fill=BOTH) xy = 20,20,30,180 # not very large, but it's as you like it cv.create_arc(xy, start=0, extent=270, fill="red") etc. You should have a look at those pages : http://www.pythonware.com/library/tkinter/introduction/index.htm http://www.manning.com/Grayson/index.html http://www.oreillynet.com/pub/a/python/excerpts/chpt20/index.html and some others. Have fun -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From rufmetal@interlog.com Mon Aug 28 16:30:03 2000 From: rufmetal@interlog.com (Christopher Keelan) Date: Mon, 28 Aug 2000 08:30:03 -0700 (PDT) Subject: [Tutor] re: Why am I getting an infinite loop? Message-ID: <20000828153003.C573930CB@sitemail.everyone.net> ----- Original Message ----- From: "Denis" > Just an indentation problem : > Idle 0.6 wouldn't let you write that : Ah, but I work with Python mode in emacs, which assumes that I'm smarter than that. Oops. > there's a automagic dedent when you write a break statement. Well, I now have one in my brain. Live and learn. > Greetings from here. Thanks and hello. - Chris _____________________________________________________________ Want a new web-based email account ? ---> http://www.firstlinux.net From jon@alphatec.iol.ie Mon Aug 28 19:22:48 2000 From: jon@alphatec.iol.ie (John O'Neill) Date: Mon, 28 Aug 2000 19:22:48 +0100 Subject: [Tutor] (no subject) Message-ID: <003201c0111c$fcae1f00$6200a8c0@john> This is a multi-part message in MIME format. ------=_NextPart_000_002F_01C01125.5A18A2C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable =20 ------=_NextPart_000_002F_01C01125.5A18A2C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
  
------=_NextPart_000_002F_01C01125.5A18A2C0-- From lizliao@yahoo.com Tue Aug 29 00:03:02 2000 From: lizliao@yahoo.com (Lin Zhang) Date: Mon, 28 Aug 2000 16:03:02 -0700 (PDT) Subject: [Tutor] how to invoke a fortran executable on MS-DOS system? Message-ID: <20000828230302.14431.qmail@web5302.mail.yahoo.com> I thought I posted this last friday, but did not get a copy to myself. Does anyone know how to invoke a fortran executable on MS-DOS system from a python script? I know this can be done easily on unix with shell script. __________________________________________________ Do You Yahoo!? Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 29 00:45:57 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 28 Aug 2000 16:45:57 -0700 (PDT) Subject: [Tutor] how to invoke a fortran executable on MS-DOS system? In-Reply-To: <20000828230302.14431.qmail@web5302.mail.yahoo.com> Message-ID: On Mon, 28 Aug 2000, Lin Zhang wrote: > I thought I posted this last friday, but did not get a > copy to myself. > > Does anyone know how to invoke a fortran executable on > MS-DOS system from a python script? I know this can be > done easily on unix with shell script. Whoops, I didn't see your previous email. Ok, to access any system command or script, you should be able to use the os.system() command: ### >>> import os >>> os.system("ls") #pico07694# cs188 exam_template.html mbox resume GNUstep cs198 exams messages rgb00001.pat # and lots of other files ### Any other commands should work as well --- you might need to indicate the full path of your Fortran program. There's an alternative command, os.popen(), but I can't say how well it'll work on Windows; I've heard that Windows's implementation is broken. However, Python 2.0, which will be coming out soon, should have a fixed popen(). The documentation for os.system can be found here: http://python.org/doc/current/lib/os-process.html#l2h-915 From SBrunning@trisystems.co.uk Tue Aug 29 09:25:07 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Tue, 29 Aug 2000 09:25:07 +0100 Subject: [Tutor] Example prog Message-ID: <31575A892FF6D1118F5800600846864D5B1077@intrepid> Daniel, I don't think that what you are doing will work under windows. Linux shells will automagically expand arguments like *.txt, so the python module will receive a list of files. This doesn't happen under windows, so you'll have to expand the argument yourself, probably using the glob module. See for an example of this. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk > -----Original Message----- > From: Daniel D. Laskey [SMTP:dlaskey@laskeycpa.com] > Sent: Saturday, August 26, 2000 6:18 PM > To: 'tutor@python.org' > Subject: [Tutor] Example prog > > I recently purchased "Programming Python" and I'm working through the > examples. > On page 83 Mark has a simple program called pack1.py. What am I doing > wrong? > > Page 83, Programming Python > > import sys > marker = '::::::' > > for name in sys.argv[1:]: > input = open(name, 'r') > print marker + name > print input.read(), > > C:\python>python pack1.py *.txt > stuff.txt > > Traceback (innermost last): > File "pack1.py", line 5, in ? > input = open(name, 'r') > IOError: [Errno 2] No such file or directory: '*.txt' > > Daniel D. Laskey, CPA > dlaskey@laskeycpa.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > > > > ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From c.gruschow@prodigy.net Tue Aug 29 10:15:16 2000 From: c.gruschow@prodigy.net (Charles Gruschow, Jr.) Date: Tue, 29 Aug 2000 04:15:16 -0500 Subject: [Tutor] concerning Monte Python method you suggested for pi, also PiPoem I found References: Message-ID: <004d01c01199$a9a05760$53df6520@gruschow> I did a little statistics on that program. 10000 loops of 10000 "arrows" (used getPi(10000) 10000 times) It took about 4 hours. One ?--->why are all our ratios coming out to 3 or 4 digits, is it because we are dividing by 10000? This method doesn't seem too accurate or quick, does it. Thanks, c.gruschow@prodigy.net P.S. do do these statistics I pasted output into a text file and then opened the text file in Excel,I had Excel interpret spaces as the field breaks. 9989 3.1508 average(mean) pi 9990 3.1372 3.14161896 3.141592654 9991 3.1172 count 100*(ave/pi) 9992 3.1128 10000 100.0008374 9993 3.158 max ave-pi 9994 3.144 3.2084 2.63064E-05 9995 3.1584 min 9996 3.1452 3.0744 9997 3.1476 median 9998 3.1376 3.142 9999 3.164 mode 10000 3.1416 #NUM! standard deviation population 0.016459693 variance population 0.000270921 ave. absolute deviations 0.013152446 P.P.S. I found following off Ivan Van Laningham's website for his book "Teach Yourself Python in 24 hours"(http://www.pauahtun.org/TYPython/) [ #!/usr/local/bin/python # Contribution to the forever lasting discussion on indentation! # After Petrarca, Shakespeare, Milton, Drs. P and many, many others, # a sonnet has 14 lines and a certain rhyme scheme. # Jacques Bens presented in 1965 in Paris the pi-sonnet with # 3,1,4,1 and 5 lines, but the ultimate pi-poem I found in # Brown's Python Annotated Archives p. 12: # Based on a algorithm of Lambert Meertens (remember those days of the # B -> ABC-programming language!!!) import sys def main(): k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L while 1: p, q, k = k*k, 2L*k+1L, k+1L a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 d, d1 = a/b, a1/b1 while d == d1: output(d) a, a1 = 10L*(a%b), 10L*(a1%b1) d, d1 = a/b, a1/b1 def output(d): sys.stdout.write(`int(d)`) sys.stdout.flush() main() # Reading/writing Python source often gives me the impression of # reading/writing a poem! # Layout, indentation, rythm, I like the look and feel! # What does this tiny program do? It is not a sonnet, even not a # pi-sonnet, but it surely produces Pi! # The poem ( sorry, the program) needs some explanation. # As a mathematician I recognize the continued fraction, odd/even, # squares and all that matters. # But it is a miracle! A few lines of Python code producing # a infinity of pi-digits! # Jaap Spies # Hogeschool Drenthe # Keep Peace in Mind ] ----- Original Message ----- From: Daniel Yoo To: Charles Gruschow, Jr. Cc: Sent: Monday, August 28, 2000 1:10 AM Subject: Re: [Tutor] re: Monte Python method you suggested for pi > > > the last message I sent, I meant Monte Carlo not Monte Python, > > oops... :) > > Actually, that name is oddly appropriate... *grin* > > > There's a slight bug in the program --- it has to do with the way the > tuple assignment works. The line: > > > rsqr,r=xt**2+yt**2,sqrt(rsqr) > > will compute the two values on the right hand side first, and _then_ do > the tuple assignments afterwards. The problem is that at the time Python > computes the right hand side, 'rsqr' isn't known. To fix this, you'll > have to do it the non-tricky way to have the same effect. > > > The rest of the program looks good! I couldn't help but try my own hand > at this. I found a way of simplifying the logic --- just compare the > ratio between the circle and the whole area. That is, > > Pi / 4 = (# of points in circle) / (total points) > > which can be restated as: > > Pi = 4 * (# of points in circle) / (total points) > > Here's the program that implements this: > > ### pi.py (pie pie!) > from whrandom import random > from math import sqrt > > def makePoint(): > x = (random() * 2) - 1 > y = (random() * 2) - 1 > return (x,y) > > def insideCircle(p): > x, y = p > return sqrt(x**2 + y**2) < 1 > > def getPi(iterations): > count = 0 > for i in xrange(iterations): > if insideCircle(makePoint()): > count = count + 1 > return 4 * count / float(iterations) > ### > > > And a few sample runs: > > ### > >>> getPi(10) > 3.6 > >>> getPi(100) > 3.32 > >>> getPi(1000) > 3.144 > >>> getPi(10000) > 3.1132 > >>> getPi(100000) > 3.14792 > >>> getPi(1000000) > # After a long long long time... > 3.141808 > ### > > So this isn't quite an efficient way of calculating Pi, but it does work. > From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 29 10:50:48 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Tue, 29 Aug 2000 02:50:48 -0700 (PDT) Subject: [Tutor] Re: concerning Monte Python method you suggested for pi, also PiPoem I found In-Reply-To: <004d01c01199$a9a05760$53df6520@gruschow> Message-ID: On Tue, 29 Aug 2000, Charles Gruschow, Jr. wrote: > I did a little statistics on that program. > 10000 loops of 10000 "arrows" (used getPi(10000) 10000 times) > It took about 4 hours. > One ?--->why are all our ratios coming out to 3 or 4 digits, is it because > we are dividing by 10000? Exactly --- For every additional power of 10 we dedicate, we get one more digit of un-precision. *grin* It's a very bad method if you want to get Pi quickly. Nevertheless, it is pretty cool to get Pi out of randomness, no? > This method doesn't seem too accurate or quick, does it. A traditional method of getting Pi involves summing up a partial sum (the derivation comes from trigonometic identities), and I'm sure there are many other methods that perform far better than dart throwing. My Calculus is rusty, but I can look it up again in my dusty textbook, if you want. I do remember seeing a very interesting method of getting Pi rapidly using some sort of sequence-accelerating function. It's in the book, "Structure and Interpretation of Computer Programs", the best CS textbook, period. I heartily recommend it --- it's the best book on programming that I've ever read. The language they use in the book is Scheme, which is a wonderful medium for getting ideas across. The authors are Abelson and Sussman. If I have time, I'll see if that Pi-accelerator translates well to Python. From timc@ans.net Tue Aug 29 16:15:11 2000 From: timc@ans.net (Tim Condit) Date: Tue, 29 Aug 2000 11:15:11 -0400 (EDT) Subject: [Tutor] starting python within script Message-ID: Hi, I'm curious about the two ways I see python started from inside scripts. These are the locations on my desktop computer at work: #!/usr/bin/env python #!/usr/local/bin/python One of these creates a .pyc byte compiled file. The other doesn't. What is the advantage of one over the other? I recall seeing something about this somewhere, but (obviously) don't recall where it was. Which way do people prefer to call python from within scripts, and why? Thanks, Tim Condit UUNet Network Quality Services 734-214-7548 tcondit@uu.net From scarblac@pino.selwerd.nl Tue Aug 29 16:38:31 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 29 Aug 2000 17:38:31 +0200 Subject: [Tutor] starting python within script In-Reply-To: ; from timc@ans.net on Tue, Aug 29, 2000 at 11:15:11AM -0400 References: Message-ID: <20000829173831.A14480@pino.selwerd.nl> On Tue, Aug 29, 2000 at 11:15:11AM -0400, Tim Condit wrote: > I'm curious about the two ways I see python started from inside scripts. > These are the locations on my desktop computer at work: > > #!/usr/bin/env python > #!/usr/local/bin/python > > One of these creates a .pyc byte compiled file. The other doesn't. What is > the advantage of one over the other? /usr/local/bin/ is a hardcoded path, it may not work everywhere; sometimes Python is in /usr/bin, sometimes in /usr/local/bin, then in /opt/python, etc. "env" is a program that starts another program, it looks "python" up in PATH and starts it. So that env line finds Python wherever it is, if it's in your PATH. So "env" works on more computers, but it can't be used if Python isn't in the path (like on some web servers). Env is always in /usr/bin/env. I think the rule is "use /usr/bin/env python, if you can." But the thing about creating .pyc files is weird. When I try it, neither produces a .pyc files. Those should never be created when the Python file is run from the command line, but only when the script is imported from another script (I don't know why that is). Are you sure that is what happens? -- Remco Gerlich, scarblac@pino.selwerd.nl From gwperry@tva.gov Tue Aug 29 18:42:11 2000 From: gwperry@tva.gov (Perry, George W.) Date: Tue, 29 Aug 2000 13:42:11 -0400 Subject: [Tutor] Interpret Statement Message-ID: <2DACABE127B3D1119FC40000F8014EFC0184C790@chachaois4.cha.tva.gov> Some interpreted languages have an Interpret statement that allows you to build a statement on the fly, and execute it. Does Python have something similar? George Perry From timc@ans.net Tue Aug 29 18:59:13 2000 From: timc@ans.net (Tim Condit) Date: Tue, 29 Aug 2000 13:59:13 -0400 (EDT) Subject: [Tutor] starting python within script In-Reply-To: <20000829173831.A14480@pino.selwerd.nl> Message-ID: On Tue, 29 Aug 2000, Remco Gerlich wrote: > On Tue, Aug 29, 2000 at 11:15:11AM -0400, Tim Condit wrote: > > I'm curious about the two ways I see python started from inside scripts. > > These are the locations on my desktop computer at work: > > > > #!/usr/bin/env python > > #!/usr/local/bin/python > > > > One of these creates a .pyc byte compiled file. The other doesn't. What is > > the advantage of one over the other? > > /usr/local/bin/ is a hardcoded path, it may not work everywhere; sometimes > Python is in /usr/bin, sometimes in /usr/local/bin, then in /opt/python, > etc. > > "env" is a program that starts another program, it looks "python" up in > PATH and starts it. So that env line finds Python wherever it is, if it's > in your PATH. > > So "env" works on more computers, but it can't be used if Python isn't in > the path (like on some web servers). Env is always in /usr/bin/env. > > I think the rule is "use /usr/bin/env python, if you can." > okay. > But the thing about creating .pyc files is weird. When I try it, neither > produces a .pyc files. Those should never be created when the Python file > is run from the command line, but only when the script is imported from > another script (I don't know why that is). Are you sure that is what > happens? > No, I'm not. I thought that's what was happening, but after some experimenting, found that you were right - the file was only created when I import a file in the form of a module. Sorry about the confusion, and thanks for the info. > -- > Remco Gerlich, scarblac@pino.selwerd.nl > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > Tim Condit UUNet Network Quality Services 734-214-7548 tcondit@uu.net From shaleh@valinux.com Tue Aug 29 19:12:22 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 29 Aug 2000 11:12:22 -0700 (PDT) Subject: [Tutor] Interpret Statement In-Reply-To: <2DACABE127B3D1119FC40000F8014EFC0184C790@chachaois4.cha.tva.gov> Message-ID: On 29-Aug-2000 Perry, George W. wrote: > Some interpreted languages have an Interpret statement that allows you to > build a statement on the fly, and execute it. Does Python have something > similar? > geisha [~] $ python Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> code = 'print \'Hi Mom\'' >>> exec(code) Hi Mom >>> From timc@ans.net Tue Aug 29 19:26:45 2000 From: timc@ans.net (Tim Condit) Date: Tue, 29 Aug 2000 14:26:45 -0400 (EDT) Subject: [Tutor] Interpret Statement In-Reply-To: <2DACABE127B3D1119FC40000F8014EFC0184C790@chachaois4.cha.tva.gov> Message-ID: Hi, This is tangential to the topic, but you might find it useful. In emacs (or Xemacs if you prefer, which I do), with Python mode installed, you can do - that's control-c twice - from your working buffer (emacs calls text windows frames; the contents of the frame is stored in the buffer) to execute the contents of the buffer. It shows up in it's own buffer, so you can view it separately. In addition to that, you can run the interpreter from within emacs by typing Installing python-mode is not hard to do if you've got emacs installed. Or at least it's not hard to do on a Unix box. Emacs on windows shouldn't be any more difficult, but I've not done it. Here are some pointers: www.python.org/emacs/python-mode/ www.xemacs.org/ www.gnu.org/software/emacs/emacs.html HTH, Tim Condit UUNet Network Quality Services 734-214-7548 tcondit@uu.net On Tue, 29 Aug 2000, Perry, George W. wrote: > Some interpreted languages have an Interpret statement that allows you to > build a statement on the fly, and execute it. Does Python have something > similar? > > George Perry > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From lizliao@yahoo.com Tue Aug 29 20:30:30 2000 From: lizliao@yahoo.com (Lin Zhang) Date: Tue, 29 Aug 2000 12:30:30 -0700 (PDT) Subject: [Tutor] Fortran exe worked! Next,get user's input via WEB? Message-ID: <20000829193030.17560.qmail@web5304.mail.yahoo.com> Thanks Dan. It worked! I was actually in the right section of the reference document, but was not literal enough to get the right syntax. If only the document would give some sample statements! It wouldn't tarnish its "academic image", would it? Now eventually I like to collect user input through WEB for the fortran exe, execute the exe on the server, and return the output in HTML format through WEB to the user. This is how I plan to ensure that the users always get the official and updated version of the program. Is Python equipped to do that? If yes, should I go through cgi route or asp route? Just want to get some feeling before I start the project and really study Python(was thinking about using JAVA). Thanks! __________________________________________________ Do You Yahoo!? Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ From dyoo@hkn.EECS.Berkeley.EDU Tue Aug 29 22:48:14 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Tue, 29 Aug 2000 14:48:14 -0700 (PDT) Subject: [Tutor] Fortran exe worked! Next,get user's input via WEB? In-Reply-To: <20000829193030.17560.qmail@web5304.mail.yahoo.com> Message-ID: On Tue, 29 Aug 2000, Lin Zhang wrote: > Thanks Dan. It worked! I was actually in the right > section of the reference document, but was not literal > enough to get the right syntax. If only the document > would give some sample statements! It wouldn't tarnish > its "academic image", would it? Hmmm... I guess the reference documentation couldn't hurt with a few examples. I think we'd have to talk to the doc-sig people; they're responsible for the Python documentation. You can contact them here: http://www.python.org/sigs/doc-sig/ > Now eventually I like to collect user input through > WEB for the fortran exe, execute the exe on the > server, and return the output in HTML format through > WEB to the user. This is how I plan to ensure that the > users always get the official and updated version of > the program. Is Python equipped to do that? If yes, > should I go through cgi route or asp route? Just want > to get some feeling before I start the project and > really study Python(was thinking about using JAVA). I believe Python, or another scripting language like Perl, would work very well. I'm not so sure about Java --- it's in its own little Javaverse, and makes it a little harder to play with other languages. A glue language, like Python or Perl, would probably be nicer for this task. Enough subjective opinions... *grin* Have you heard of pyfort? Clever people have written some python-fortran bindings to make the interaction between those two languages easier. Let's see... here's the link: http://sourceforge.net/projects/pyfortran I think it assumes that you have the original Fortran sources available. I haven't used it myself, but perhaps it'll be useful for you. Good luck! From alan.gauld@bt.com Wed Aug 30 17:32:17 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 30 Aug 2000 17:32:17 +0100 Subject: [Tutor] Fortran exe worked! Next,get user's input via WEB? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2E1@mbtlipnt02.btlabs.bt.co.uk> > Now eventually I like to collect user input through > WEB for the fortran exe, execute the exe on the > server, and return the output in HTML format through > WEB to the user. You'll need to use popen() for that. Its not there in vanilla Python on Windows but ISTR that the winall package includes a popen implementation. > the program. Is Python equipped to do that? If yes, yes, emminently > should I go through cgi route or asp route? I'd love a definitive explanation of the relative merits. I've tried some mental excercises to work out which yields vest performance under which circumstances but its non trivial - so many permutations! I'd tend to go for which ever was most 'natural' on my web server - thus ASP on IIS and CGI on most anything else. Another pure python approach is to use zope but it has a fairly steep learning curve all of its own.... http://www.zope.org/ Alan g. From mjboylan@sover.net Wed Aug 30 15:27:41 2000 From: mjboylan@sover.net (Michael J. Boylan) Date: Wed, 30 Aug 2000 14:27:41 Subject: [Tutor] (no subject) Message-ID: <3.0.1.16.20000830142741.3b07c568@mail.sover.net> I am just starting to learn python, and am stuck on a simple programming exercise. "Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100". Seems simple, but I can't get it. Any help? thanks, Mike From deng@ms.shlftdc.net.cn Thu Aug 31 02:00:01 2000 From: deng@ms.shlftdc.net.cn (deng wei) Date: Thu, 31 Aug 2000 9:0:1 +0800 Subject: [Tutor] (no subject) Message-ID: <20000831001004968.AAA301.197@deng> Hi: Here is a question in the python munual 3.1.3. The example said: a = ['spam', 'eggs', 100, 1234]; a[0]='spam',a[1]='eggs',a[2]=100 and a[4]=1234; It then said: a[0:2]=[1,12] I think it's a error assignment. 'Cause I believe a[0:2]=['spam','eggs',100]; Why? Any comments are Welcome.Thanks in advance. From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 31 02:55:01 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 30 Aug 2000 18:55:01 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: <3.0.1.16.20000830142741.3b07c568@mail.sover.net> Message-ID: > "Write a program that continually reads in numbers from the user and adds > them together until the sum reaches 100". > > Seems simple, but I can't get it. Any help? This message will go through the steps in building this program, so don't read the whole thing if you want to try your hand at it. I find that building up a partial solution, and working on that, is sometimes easier than going top-down. Let's first build a frame for this program. The code that corresponds to: "continually [read numbers] until the sum reaches 100" fits naturally with the idea of a 'while' loop --- repeat a behavior, until a certain condition is met: ### while sum < 100: # we'll need to fill this in with some sort of action ### We need to define what "sum" is. Let's set it, at the beginning, to zero: ### sum = 0 while sum < 100: # we'll need to fill this in with some sort of action ### So we have that. Next, we need to work on the part that "reads numbers from the user." This can be done using either raw_input() or input(). For this instance, using input() will be easier, because we're working strictly with numerical input. Returning to our 'while' loop: ### sum = 0 while sum < 100: number = input("Please enter a number: ") ### If we try running the program at this point, it will never get out of the loop, because sum will always be less than 100. We see the need to add our number to the sum we have so far. ### sum = 0 while sum < 100: number = input("Please enter a number: ") sum = sum + number ### This fragment does what you want --- it adds numbers up until it hits a sum of 100. It would be nice to see a running total of the sum, just to see it working. A small print statement can be added in the beginning of the while loop: ### sum = 0 while sum < 100: print "Sum so far:", sum number = input("Please enter a number: ") sum = sum + number ### I hope this helps! From rickp@telocity.com Thu Aug 31 03:06:22 2000 From: rickp@telocity.com (Rick Pasotto) Date: Wed, 30 Aug 2000 22:06:22 -0400 Subject: [Tutor] python tutorial Message-ID: <20000830220622.N478@tc.niof.net> Part I of a python tutorial has been posted to: http://linux.com/development -- "Moderation in temper is always a virtue; but moderation in principle is always a vice." -- Thomas Paine, _The Rights of Man_ (1791) Rick Pasotto email: rickp@vnet.net From dyoo@hkn.EECS.Berkeley.EDU Thu Aug 31 03:19:51 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 30 Aug 2000 19:19:51 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: <20000831001004968.AAA301.197@deng> Message-ID: > Here is a question in the python munual 3.1.3. > The example said: > a = ['spam', 'eggs', 100, 1234]; > a[0]='spam',a[1]='eggs',a[2]=100 and a[4]=1234; > It then said: > a[0:2]=[1,12] > I think it's a error assignment. > 'Cause I believe a[0:2]=['spam','eggs',100]; > Why? When you try something like: a[0:2] this will take a[0] and a[1]. It's a little weird at first, but it actually simplifies program logic that works with arrays. You'll need to write a few programs, though, before it makes sense. The '[]' operator will make a slice starting at the left element, all the way up to, but not including, the right element. Oh, also, a[:2] is the same thing as a[0:2], and can be read as "take the first 2 elements of 'a'". If you're curious, the range() function has similar behavior: ### >>> range(0) [] >>> range(1) [0] >>> range(2) [0, 1] ### From deng@ms.shlftdc.net.cn Thu Aug 31 05:37:33 2000 From: deng@ms.shlftdc.net.cn (deng wei) Date: Thu, 31 Aug 2000 12:37:33 +0800 Subject: [Tutor] (no subject) Message-ID: <20000831034738421.AAA259.331@wd> Hi: How to run a python script in Python GUI under Windows98??? I had tried these: >>> file.py and >>> >> import file and >>> #! file.py Anyone who knows??? thanks in advance. From Moshe Zadka Thu Aug 31 08:27:26 2000 From: Moshe Zadka (Moshe Zadka) Date: Thu, 31 Aug 2000 10:27:26 +0300 (IDT) Subject: [Tutor] (no subject) In-Reply-To: <3.0.1.16.20000830142741.3b07c568@mail.sover.net> Message-ID: On Wed, 30 Aug 2000, Michael J. Boylan wrote: > I am just starting to learn python, and am stuck on a simple programming > exercise. > > "Write a program that continually reads in numbers from the user and adds > them together until the sum reaches 100". > > Seems simple, but I can't get it. Any help? Programming is about taking a problem and dividing it into smaller problems, and then solve them. So let's divide the problem 1. Read numbers from the user. See input(), raw_input() and int() in the library reference. 2. Add numbers -- this should be easy 3. Do something continuously until something happens -- see tutorial about the while loop -- Moshe Zadka There is no IGLU cabal. http://advogato.org/person/moshez From bertrandbus@hotmail.com Thu Aug 31 09:16:06 2000 From: bertrandbus@hotmail.com (Bertrand BARRET) Date: Thu, 31 Aug 2000 08:16:06 GMT Subject: [Tutor] Http Server with Python Message-ID: Hi, I'm looking for a sample of code of a simple HTTP Server in Python.(i want just the basic code) Where can I find it ? Sincerely, Bertrand. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com. From scarblac@pino.selwerd.nl Thu Aug 31 09:32:26 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 31 Aug 2000 10:32:26 +0200 Subject: [Tutor] Http Server with Python In-Reply-To: ; from bertrandbus@hotmail.com on Thu, Aug 31, 2000 at 08:16:06AM +0000 References: Message-ID: <20000831103226.A18410@pino.selwerd.nl> On Thu, Aug 31, 2000 at 08:16:06AM +0000, Bertrand BARRET wrote: > I'm looking for a sample of code of a simple HTTP Server in Python.(i want > just the basic code) > Where can I find it ? You want the SimpleHTTPServer and BaseHTTPServer modules as they come with the standard Python distribution. If the source code isn't in your Lib/ dir, you should get Python's source distribution instead of a binary one. -- Remco Gerlich, scarblac@pino.selwerd.nl From amoreira@mercury.ubi.pt Thu Aug 31 09:56:22 2000 From: amoreira@mercury.ubi.pt (amoreira@mercury.ubi.pt) Date: Thu, 31 Aug 2000 09:56:22 +0100 Subject: [Tutor] (no subject) References: <20000831001004968.AAA301.197@deng> Message-ID: <39AE1DB6.E343A62E@mercury.ubi.pt> deng wei wrote: > > Hi: > Here is a question in the python munual 3.1.3. > The example said: > a = ['spam', 'eggs', 100, 1234]; > a[0]='spam',a[1]='eggs',a[2]=100 and a[4]=1234; > It then said: > a[0:2]=[1,12] > I think it's a error assignment. > 'Cause I believe a[0:2]=['spam','eggs',100]; > Why? > Any comments are Welcome.Thanks in advance. Hello! No, that's not the way slices go. before the second assignment, a[0:2] is ['spam','eggs'], not, as you say, ['spam','eggs',100]. In general, list[n1:n2] returns the slice of list that starts at position n1 (first position in the list is #0) and ends *just before* n2. So when you say a[0:2]=[1,12] you are saying that you wnat the first two elements of a be assigned numbers 1 and 12. Check it out with examples: >>> a=['spam','eggs',100,1234] >>> a[0:2] ['spam', 'eggs'] >>> a[0:1] ['spam'] >>> a[0] 'spam' Oh, just another thing: the semi-colons ';' at the end of a line are unnecessary. You just need them to separate different instructions set in the same line. Hope it helped Cheers, Ze From wbateman@epicrealm.com Thu Aug 31 16:05:10 2000 From: wbateman@epicrealm.com (Wes Bateman) Date: Thu, 31 Aug 2000 10:05:10 -0500 (CDT) Subject: [Tutor] Grep equiv. Message-ID: Hello all: Sorry if this is a question I should have figured out on my own...but I haven't :) I've written only one useful Python script (which ran in sub 1 second, or approx. .2 seconds actually, versus another script doing the same thing I wrote in BASH which took 52 seconds to run! I'm sold :) ) Anyhow, I've been jumping through hoops trying to slice sections of strings and use if comparrisons to do the same thing I used grep for in BASH. Is there a nice, easy, fast way of saying "if this line/string/variable/array/whatever contains 'xxx' then do 'something'" With something being spit it out, return true, or whatever. Doesn't matter. Anyhow, thanks for any help :) Wes A struggling python beginner, trying to buck the system in a building full of c, perl, awk, java, and other assorted programmers - none of whom use python (yet ;) ) From amoreira@mercury.ubi.pt Thu Aug 31 16:26:13 2000 From: amoreira@mercury.ubi.pt (amoreira@mercury.ubi.pt) Date: Thu, 31 Aug 2000 16:26:13 +0100 Subject: [Tutor] Grep equiv. References: Message-ID: <39AE7915.F4A38A7@mercury.ubi.pt> Hello! Wes Bateman wrote: > > Hello all: > > Sorry if this is a question I should have figured out on my own. no problem. > Is there a nice, easy, fast way of saying "if this > line/string/variable/array/whatever contains 'xxx' then do 'something'" There are several ways. Check out the string module and the functions string.find() and string.index(): >>> import string >>> string.find('Hello, Ze','Z') 7 >>> string.find('Hello, Ze','lo') 3 >>> string.find('Hello, Ze','H') 0 >>> string.find('Hello, Ze','W') -1 string.index() is more or less the same but returns an error if no match is found, instead of the silent -1 returned by string.find. There is also the re module, with more advanced pattern matching possibilities. Hope it helps So long! Ze From alan.gauld@bt.com Thu Aug 31 17:33:11 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 31 Aug 2000 17:33:11 +0100 Subject: [Tutor] Grep equiv. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D2E8@mbtlipnt02.btlabs.bt.co.uk> > Is there a nice, easy, fast way of saying "if this > line/string/variable/array/whatever contains 'xxx' then do > 'something'" For literal strings use string.search() For regular expressions use re.search() eg: import re if re.search('[pP]ython','My python script'): print 'found it!' There are also substitution functions for search/replace operations... Read the re module docs. Alan G. > > With something being spit it out, return true, or whatever. Doesn't > matter. > > Anyhow, thanks for any help :) > > Wes > A struggling python beginner, trying to buck the system in a > building full > of c, perl, awk, java, and other assorted programmers - none > of whom use > python (yet ;) ) > > > From lizliao@yahoo.com Thu Aug 31 18:11:32 2000 From: lizliao@yahoo.com (Lin Zhang) Date: Thu, 31 Aug 2000 10:11:32 -0700 (PDT) Subject: [Tutor] Number Sum Up Message-ID: <20000831171132.6004.qmail@web5305.mail.yahoo.com> Something like the following (in a .py file) should work: n=0 while n<100: n = n+float(raw_input("Please enter a number: ")) print "The summation of your input: ", n Cheers! --- "Michael J. Boylan" wrote: > I am just starting to learn python, and am stuck on > a simple programming > exercise. > > "Write a program that continually reads in numbers > from the user and adds > them together until the sum reaches 100". > > Seems simple, but I can't get it. Any help? > > thanks, > > Mike > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor __________________________________________________ Do You Yahoo!? Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ From arcege@shore.net Thu Aug 31 18:20:30 2000 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 31 Aug 2000 13:20:30 -0400 (EDT) Subject: [Tutor] Grep equiv. In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D2E8@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at Aug 31, 2000 05:33:11 PM Message-ID: <200008311720.NAA25827@northshore.shore.net> > > > Is there a nice, easy, fast way of saying "if this > > line/string/variable/array/whatever contains 'xxx' then do > > 'something'" > > For literal strings use string.search() > > For regular expressions use re.search() > > eg: > > import re > if re.search('[pP]ython','My python script'): > print 'found it!' > > > There are also substitution functions for search/replace operations... > Read the re module docs. There is also the "grep" module which gives you differing types of regular expressions (does not support pcre). If there is no need to use regular expressions, then use the string module. The overhead (even in Perl) of using a regular expression engine is not always desirable. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From rick@niof.net Thu Aug 31 20:19:50 2000 From: rick@niof.net (Rick Pasotto) Date: Thu, 31 Aug 2000 15:19:50 -0400 Subject: [Tutor] Grep equiv. In-Reply-To: <200008311720.NAA25827@northshore.shore.net>; from arcege@shore.net on Thu, Aug 31, 2000 at 01:20:30PM -0400 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D2E8@mbtlipnt02.btlabs.bt.co.uk> <200008311720.NAA25827@northshore.shore.net> Message-ID: <20000831151950.A29795@tc.niof.net> On Thu, Aug 31, 2000 at 01:20:30PM -0400, Michael P. Reilly wrote: > > > > > Is there a nice, easy, fast way of saying "if this > > > line/string/variable/array/whatever contains 'xxx' then do > > > 'something'" > > > > For literal strings use string.search() > > > > For regular expressions use re.search() > > There is also the "grep" module which gives you differing types of > regular expressions (does not support pcre). > > If there is no need to use regular expressions, then use the string > module. The overhead (even in Perl) of using a regular expression > engine is not always desirable. If there is no need for regular expressions and all he needs to know is true/false is there any reason not to use: if word in string: do_something() -- "Prohibition...goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation and makes a crime out things that are not crimes. A prohibition law strikes a blow at the very principles upon which our government was founded." -- Abraham Lincoln, Dec. 1840 Rick Pasotto email: rickp@vnet.net From arcege@shore.net Thu Aug 31 20:31:55 2000 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 31 Aug 2000 15:31:55 -0400 (EDT) Subject: [Tutor] Grep equiv. In-Reply-To: <20000831151950.A29795@tc.niof.net> from "Rick Pasotto" at Aug 31, 2000 03:19:50 PM Message-ID: <200008311931.PAA20995@northshore.shore.net> > > On Thu, Aug 31, 2000 at 01:20:30PM -0400, Michael P. Reilly wrote: > > > > > > > Is there a nice, easy, fast way of saying "if this > > > > line/string/variable/array/whatever contains 'xxx' then do > > > > 'something'" > > > > > > For literal strings use string.search() > > > > > > For regular expressions use re.search() > > > > There is also the "grep" module which gives you differing types of > > regular expressions (does not support pcre). > > > > If there is no need to use regular expressions, then use the string > > module. The overhead (even in Perl) of using a regular expression > > engine is not always desirable. > > If there is no need for regular expressions and all he needs to know is > true/false is there any reason not to use: > > if word in string: > do_something() > The "in" works on elements in a sequence, not a slice, so the contents of word must be a character, not a string. The string.find or string.match functions will search for substrings. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From wbateman@epicrealm.com Thu Aug 31 17:23:10 2000 From: wbateman@epicrealm.com (Wes Bateman) Date: Thu, 31 Aug 2000 11:23:10 -0500 (CDT) Subject: [Tutor] Grep equiv. In-Reply-To: <39AE7915.F4A38A7@mercury.ubi.pt> Message-ID: Still not able to get exactly what I want. Really a result exactly like grep does is what I'm looking for. I want to examine a file, line by line, and return the lines that contain a string that I was searching for. To do this using string.find, I tried the following. This searches for the string 'sdb' in a file, and I only want it to kick back the lines that contain the string. I think that it's looking at the whole file, if it contains the string, it spits the whole file back, if it doesn't contain the string, it returns nothing. How can I break up the piece that I'm feeding the string.find into lines, so that I can tell it what to do line by line? I tried to use string.splitfields(line) to break it up, but it used a whitespace delimeter and divided each line up. If I did this the string.find choked on the list variable type. Which raises other questions I have about how I can perform a particular function on all of the items in a list ( variable[0], variable[1], variable[2], etc.) in one pass? Further, what would be the preferred way to suck a file in, put each line in a variable, and each field in each line inside of that? I understand that I can nest lists, so maybe like file[0] is first line of file and inside of that there could be several fields? How would I reference them and how could I get them into a structure like that? Eventually I want to take say the third field from each line that matches my "grep-like" function and add them. Thanks :) Wes #!/usr/bin/python import sys import string import re filename = sys.argv[1] file = open(filename) for line in file.readlines(): result = string.find(line,'sdb') if result != '-1' : print line file.close() From poste_br@yahoo.com Thu Aug 31 22:25:43 2000 From: poste_br@yahoo.com (Guilherme) Date: Thu, 31 Aug 2000 18:25:43 -0300 Subject: [Tutor] Python Message-ID: I would like to know if python can be used to program CGI scripts, and where can I find a good tutorial on python? Thanks!!! poste_br@yahoo.com _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From FxItAL@aol.com Thu Aug 31 22:31:43 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Thu, 31 Aug 2000 17:31:43 EDT Subject: [Tutor] A timer of some sort. Message-ID: <20.ae48cb6.26e028bf@aol.com> Hello, Does anyone know of a timer or a timimg module that I can use to activate a loop at 15 minute intervals? Thanks for your time, Al From insyte@emt-p.org Thu Aug 31 22:36:52 2000 From: insyte@emt-p.org (Ben Beuchler) Date: Thu, 31 Aug 2000 16:36:52 -0500 Subject: [Tutor] Grep equiv. In-Reply-To: ; from wbateman@epicrealm.com on Thu, Aug 31, 2000 at 11:23:10AM -0500 References: <39AE7915.F4A38A7@mercury.ubi.pt> Message-ID: <20000831163651.B10809@emt-p.org> On Thu, Aug 31, 2000 at 11:23:10AM -0500, Wes Bateman wrote: > Still not able to get exactly what I want. Really a result exactly like > grep does is what I'm looking for. I want to examine a file, line by > line, and return the lines that contain a string that I was searching > for. To do this using string.find, I tried the following. This searches > for the string 'sdb' in a file, and I only want it to kick back the lines > that contain the string. I had better (easier to manage) results with the string.count() function: cat > testing line one line two line one line three line four ^D petra:~$ python Python 1.5.2 (#2, Jun 29 2000, 21:39:35) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import string >>> thefile = open('testing') >>> contents = thefile.readlines() >>> >>> for each in contents: ... if string.count(each, 'one'): ... print each ... line one line one >>> -- Ben Beuchler insyte@bitstream.net MAILER-DAEMON (612) 321-9290 x101 Bitstream Underground www.bitstream.net From shaleh@valinux.com Thu Aug 31 22:36:06 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 31 Aug 2000 14:36:06 -0700 (PDT) Subject: [Tutor] Python In-Reply-To: Message-ID: On 31-Aug-2000 Guilherme wrote: > I would like to know if python can be used to program CGI scripts, and > where can I find a good tutorial on python? > Thanks!!! > > It is called "www.python.org" go, search it. There are archives of this list, docs, tutorials, etc. Try that. From sburch@ordway.org Thu Aug 31 22:40:26 2000 From: sburch@ordway.org (Burchill, Scott B.) Date: Thu, 31 Aug 2000 16:40:26 -0500 Subject: [Tutor] Grep equiv. Message-ID: > -----Original Message----- > From: Wes Bateman [mailto:wbateman@epicrealm.com] > > #!/usr/bin/python > > import sys > import string > import re > > filename = sys.argv[1] > > file = open(filename) > for line in file.readlines(): > result = string.find(line,'sdb') > if result != '-1' : > print line > file.close() > Wes, You are so close. You are using the for loop to check each line in the file and that is working great. It's the "if result" line where the problem is. string.find returns a *number* and you are checking it against a string, '-1'. There are two possible From sburch@ordway.org Thu Aug 31 22:43:32 2000 From: sburch@ordway.org (Burchill, Scott B.) Date: Thu, 31 Aug 2000 16:43:32 -0500 Subject: [Tutor] Grep equiv. Message-ID: > -----Original Message----- > From: Wes Bateman [mailto:wbateman@epicrealm.com] > > #!/usr/bin/python > > import sys > import string > import re > > filename = sys.argv[1] > > file = open(filename) > for line in file.readlines(): > result = string.find(line,'sdb') > if result != '-1' : > print line > file.close() > Wes, You are so close. You are using the for loop to check each line in the file and that is working great. It's the "if result" line where the problem is. string.find returns a *number* and you are checking it against a string, '-1'. There are two possible solutions : > result = str(string.find(line,'sdb')) > if result != '-1' : -or- > result = string.find(line,'sdb') > if result != -1 : Either of these will make your script pick the correct lines to print. sbb PS sorry for the previous incomplete posting :) From wbateman@epicrealm.com Thu Aug 31 17:58:35 2000 From: wbateman@epicrealm.com (Wes Bateman) Date: Thu, 31 Aug 2000 11:58:35 -0500 (CDT) Subject: [Tutor] Grep equiv. In-Reply-To: Message-ID: Haha! I got it now, makes perfect sense. Knowing so little makes it hard to pick out errors like that. I knew exactly what you meant when I read the first "incomplete" message, and I went and got it to work. I chose the latter of your examples, before I even received it. :) Very cool :) I figured I that I was misunderstanding what the variable "line" was referring to. Based on that assumption, I wasn't looking hard at the quotes around -1 :) Thanks :) Wes > Wes, > > You are so close. You are using the for loop to check each line in the > file and that is working great. It's the "if result" line where the problem > is. > > string.find returns a *number* and you are checking it against a > string, '-1'. There are two possible solutions : > > > result = str(string.find(line,'sdb')) > > if result != '-1' : > > -or- > > > result = string.find(line,'sdb') > > if result != -1 : > > Either of these will make your script pick the correct lines to print. > > sbb > > PS sorry for the previous incomplete posting :) > From amoreira@mercury.ubi.pt Thu Aug 31 23:23:56 2000 From: amoreira@mercury.ubi.pt (amoreira@mercury.ubi.pt) Date: Thu, 31 Aug 2000 23:23:56 +0100 Subject: [Tutor] Grep equiv. References: Message-ID: <39AEDAFC.BDEDF400@mercury.ubi.pt> Hi there! Scott already answered about the trouble with "if result!='-1'". let me try to answer your other questions. Wes Bateman wrote: > > > I tried to use string.splitfields(line) to break it up, but it used a > whitespace delimeter and divided each line up. If I did this the > string.find choked on the list variable type. Which raises other > questions I have about how I can perform a particular function on all of > the items in a list ( variable[0], variable[1], variable[2], etc.) in one > pass? This is the map function: >>> l=[0,1,2,3,4] >>> def f(x): ... return x**2 ... >>> map(f,l) [0, 1, 4, 9, 16] > > Further, what would be the preferred way to suck a file in, put each line > in a variable, and each field in each line inside of that? I understand > that I can nest lists, so maybe like file[0] is first line of file and > inside of that there could be several fields? How would I reference them > and how could I get them into a structure like that? The way you read it in your script dows just that, but you have to assign to a variable to keep it: file=open(filename) lines=file.readlines() The hole file was read and you now have a list called lines such that lines[0] is the fisrt line of the file, line[1] is the second line of the file, and so on. There are other ways as well. Check the tutorial. Wich one is best depends on what you want to do and what you want to do it to. For instance, it's probably not a good idea to read in one deep gulp a 2 million line file. That's what happens if you use readlines to read it. > > Eventually I want to take say the third field from each line that matches > my "grep-like" function and add them. > You can add the 3rd fields of each line with import string s=0 for line in lines: #lines is the list read above s=s+ float(string.split(lines)[2]) This assumes that the fields are separated with whitespace. string.split splits line into fields, and field #3 is is the one with index 2 (1st position has index 0, 2nd position has index 1..... n-th position has index n-1). float converts the string into a number, it possible. That is: float('3') returns 3.0; float('hello!') returns an error. Cheers, and good luck! Ze From fdsopfj@dns.thenet.co.jp Thu Aug 31 17:44:16 2000 From: fdsopfj@dns.thenet.co.jp (fdsopfj@dns.thenet.co.jp) Date: Thu, 31 Aug 2000 16:44:16 Subject: [Tutor] (no subject) Message-ID: <280.61322.114434@mail.mindspring.com> 1 888 591 8773 1 888 591 8773 Dustin Communications OUR COMPANY HAS OVER 5 YEARS PROVEN E MAIL BLASTING EXPERIENCE! WORK SMARTER BY HAVING QUALIFIED PEOPLE PHONE YOU, ALREADY PREPARED TO BUY. PUT YOUR COLD CALLING DAYS TO AN END. WHY NOT E MAIL OUT YOUR AD TO A 250,000 DIFFERENT ADDRESSES FOR ONLY $495.00 US. IF 250,000, IS NOT BIG ENOUGH JOB FOR YOU, TRY US FOR SENDING YOUR AD TO OVER 1 MILLION DIFFERENT ADDRESSES FOR ONLY $925.00. We accept PAYMENT BY Cheque by Fax. FOR FURTHER information please call 888 591 8773 DUSTIN COMMUNICATIONS TORONTO _________________________________________________________________