From richard_chamberlain@ntlworld.com Sun Oct 1 17:03:56 2000 From: richard_chamberlain@ntlworld.com (Richard Chamberlain) Date: Sun, 1 Oct 2000 17:03:56 +0100 Subject: [Tutor] winsound References: <7f.a531b0e.2707a312@aol.com> Message-ID: <000801c02bc1$385a5320$4400a8c0@richardc> Hi, I'm not really having an issue with winsound, perhaps because I'm on 1.5.2 and win98 (you're two steps ahead already :-). import winsound winsound.PlaySound("c:/windows/media/chord.wav",winsound.SND_ASYNC|winsound. SND_LOOP) winsound.PlaySound("c:/windows/media/chord.wav",winsound.SND_PURGE) Hope that helps Richard ----- Original Message ----- From: To: Sent: Saturday, September 30, 2000 9:12 PM Subject: [Tutor] winsound > Hello, > > I'm having difficulty getting the SND_LOOP flag to work. The sound will play > if I use SND_ASYNC, but only once. I'd like to loop the sound and then be > able to stop it with SND_PURGE. Any help is greatly appreciated. > > Python 1.6 on Windows ME > > Thanks Al > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Mon Oct 2 03:46:18 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 1 Oct 2000 19:46:18 -0700 (PDT) Subject: [Tutor] Re: Network In-Reply-To: <20001002011314.UONU29936.n17-svc.kimo.com@k13.svc.kimo.com.tw> Message-ID: On Mon, 2 Oct 2000, Jerry wrote: > long time no see...how are you? Doing ok; going crazy over homework right now... *grin* > now I have a question..the question is > "now I want to know the appearance of my lan > example I want to know the IP address , > physicol address,hostname...How to use python to > write...thank you".. You can use the functions in the socket module, I think: http://python.org/doc/current/lib/module-socket.html However, I haven't done too much network programming, so I'm forwarding this to the other tutors --- they should have more experience with this. From Greg.Furmanek@hit.cendant.com Mon Oct 2 18:00:50 2000 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Mon, 2 Oct 2000 13:00:50 -0400 Subject: [Tutor] Sending e-mails Message-ID: Hi I was wondering if there is an easy way to send mail messages from the Python script. At this time I am using mailx command and it works pretty well, but I would like to do this without resorting to external programs. The Wolf From insyte@emt-p.org Mon Oct 2 18:19:38 2000 From: insyte@emt-p.org (Ben Beuchler) Date: Mon, 2 Oct 2000 12:19:38 -0500 Subject: [Tutor] Sending e-mails In-Reply-To: ; from Greg.Furmanek@hit.cendant.com on Mon, Oct 02, 2000 at 01:00:50PM -0400 References: Message-ID: <20001002121937.A16394@emt-p.org> On Mon, Oct 02, 2000 at 01:00:50PM -0400, Furmanek, Greg wrote: > Hi I was wondering if there is an easy way to > send mail messages from the Python script. > > At this time I am using mailx command and it works > pretty well, but I would like to do this without > resorting to external programs. smtplib works well. -- Ben Beuchler insyte@bitstream.net MAILER-DAEMON (612) 321-9290 x101 Bitstream Underground www.bitstream.net From marcel@punto.it Mon Oct 2 18:27:57 2000 From: marcel@punto.it (Marcel Preda) Date: Mon, 2 Oct 2000 19:27:57 +0200 (CEST) Subject: [Tutor] Sending e-mails In-Reply-To: Message-ID: On Mon, 2 Oct 2000, Furmanek, Greg wrote: > Hi I was wondering if there is an easy way to > send mail messages from the Python script. > > At this time I am using mailx command and it works > pretty well, but I would like to do this without > resorting to external programs. > smtplib module lab02:~# python Python 1.5.2 (#0, Sep 13 1999, 09:12:57) [GCC 2.95.1 19990816 (release)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import smtplib >>> print smtplib.__doc__ SMTP/ESMTP client class. Author: The Dragon De Monsyne ... ... PM From FxItAL@aol.com Mon Oct 2 21:55:28 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Mon, 02 Oct 2000 16:55:28 EDT Subject: [Tutor] Deselecting Radio Buttons Message-ID: <76.3867dcf.270a5040@aol.com> Hello, It must be possible to deselect a radio button after one has selected it. Could someone tell me how? Thanks for your help, Al PMVar = IntVar() PMBut = Radiobutton(root, text="Select for / P.M.", value=2, variable=PMVar, padx=50) PMBut.grid(row=1, column=2,sticky=E) PM = PMVar.get() From griff@netdoor.com Mon Oct 2 22:13:42 2000 From: griff@netdoor.com (R. A.) Date: Mon, 02 Oct 2000 16:13:42 -0500 Subject: [Tutor] Python equivalent of Java Vecor? Message-ID: <39D8FA86.55CAE21E@netdoor.com> I've been asked another Python question that's over my head, so I asked the querant to re-phrase it a bit so I could ask y'all. Here is his question: "Does Python have something equivalent to Java's Vector? For instance, most of the time if you want to use an array you have to declare the size up front. Java has a Vector class which is an array of objects which grows as you add things to it. "Just curiousity on my part really, but if you are serious about using Python productively, you probably need to answer that. In Java, for instance, if I want an array of String I say "String tmp[]=new String[5]" and I have an array of Strings with 5 slots. If I didn't know how many Strings I was going to have though, I could say "Vector tmp=new Vector()" then every time I wanted to add a String, say "String tmpvalue" I could say "tmp.addElement(tmpvalue)". Then, I could say "tmp.size()" to see how many elements were in the Vector, and I can even to a "tmp.elementAt(int x)" to retrieve a value. So, I think the terminology would be that Java supports dynamic arrays of objects. I was wondering if Python had the equivalent." Appreciatively, Rob Andrews -- GIT/P/TW d---(++) s++:s a? C+++++ U$>+++ P+ L+>++++ E@ W++ N++ o? K- w$ ?O ?M ?V PS+++ PE Y+@ PGP- t+@ 5 X@ R+ tv+ b+++ DI+@ D+ Q3A++ e++* h* r y++* UF+++ From shaleh@valinux.com Mon Oct 2 22:20:04 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 02 Oct 2000 14:20:04 -0700 (PDT) Subject: [Tutor] Python equivalent of Java Vecor? In-Reply-To: <39D8FA86.55CAE21E@netdoor.com> Message-ID: > > "Does Python have something equivalent to Java's Vector? For instance, > most of the time if you want to use an array you have to declare the > size up front. Java has a Vector class which is an array of objects > which grows as you add things to it. > this is called a list in Python parlance. >>> foo = ['foo', 'bar', 'baz'] >>> foo[0] 'foo' >>> len(foo) 3 >>> foo.append('whaz') >>> foo ['foo', 'bar', 'baz', 'whaz'] >>> len(foo) 4 Lists can hold heterogenous items or homogenous items. Any decent python book or tutorial will cover this at length. So you know, a Vector is another word for arrays. From scarblac@pino.selwerd.nl Tue Oct 3 00:46:16 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 3 Oct 2000 01:46:16 +0200 Subject: [Tutor] Python equivalent of Java Vecor? In-Reply-To: <39D8FA86.55CAE21E@netdoor.com>; from griff@netdoor.com on Mon, Oct 02, 2000 at 04:13:42PM -0500 References: <39D8FA86.55CAE21E@netdoor.com> Message-ID: <20001003014616.A26222@pino.selwerd.nl> On Mon, Oct 02, 2000 at 04:13:42PM -0500, R. A. wrote: > I've been asked another Python question that's over my head, so I asked > the querant to re-phrase it a bit so I could ask y'all. Here is his > question: > > "Does Python have something equivalent to Java's Vector? For instance, > most of the time if you want to use an array you have to declare the > size up front. Java has a Vector class which is an array of objects > which grows as you add things to it. > > "Just curiousity on my part really, but if you are serious about using > Python productively, you probably need to answer that. In Java, for > instance, if I want an array of String I say "String tmp[]=new > String[5]" and I have an array of Strings with 5 slots. If I didn't > know how many Strings I was going to have though, I could say "Vector > tmp=new Vector()" then every time I wanted to add a String, say "String > tmpvalue" I could say "tmp.addElement(tmpvalue)". Then, I could say > "tmp.size()" to see how many elements were in the Vector, and I can even > to a "tmp.elementAt(int x)" to retrieve a value. So, I think the > terminology would be that Java supports dynamic arrays of objects. I > was wondering if Python had the equivalent." Yes. And Python's is far better. They're usually called lists, they're first-class citizens so they're supported by language syntax, and they can hold any kind of object. tmp = [] # Make tmp a new, empty list tmp.append(tmpvalue) # Append tmpvalue to tmp, whatever type it is len(tmp) # Returns the number of items in tmp tmp[3] # Returns element 3 (numbering starts at 0) tmp.index("bla") # Finds the index of "bla", or -1 if it's not in the # list tmp.sort() # Sort the list Et cetera. Python supports "dynamic arrays of objects" just as well as it supports integers. Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Tue Oct 3 03:48:11 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Oct 2000 19:48:11 -0700 (PDT) Subject: [Tutor] Python equivalent of Java Vecor? In-Reply-To: <39D8FA86.55CAE21E@netdoor.com> Message-ID: > "Does Python have something equivalent to Java's Vector? For instance, > most of the time if you want to use an array you have to declare the > size up front. Java has a Vector class which is an array of objects > which grows as you add things to it. Sure --- Python has as a basic type the list. Here's how to construct an empty list: mylist = [] Getting the length it easy too: print len(mylist) Appending to it is similar to Java: mylist.append(42) mylist.append("Hello") Getting at an arbitrary element is like an array operator: ### >>> mylist = ['this', 'is', 'a', 'test'] >>> mylist[1] 'is' ### Doing an iteraton over a list uses a simple 'for' loop: for element in mylist: print element I'm not sure what the consensus is on making a presizing array --- I use this: mylist = [0] * 10 to get a zeroed list of 10 elements. Good luck! From nicolas.baurin@univ-orleans.fr Tue Oct 3 11:13:30 2000 From: nicolas.baurin@univ-orleans.fr (nicolas baurin) Date: Tue, 03 Oct 2000 12:13:30 +0200 Subject: [Tutor] Tkinter: link button to executable Message-ID: <39D9B149.668BF5E7@univ-orleans.fr> Hello to all of you, i'm trying to create a button with Tkinter; when pressed it it must launch an executable (here c:/wordpad .exe); for this i've discovered the sys module and the system() method my code fail;here it is # File: hello2.py from Tkinter import * import sys class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) self.exe= Button(frame, text="Hello", command=self.go) self.exe.pack(side=LEFT) def go(self): sys.system("c:/wordpad.exe") #print "go" root = Tk() app = App(root) root.mainloop() The windows appear but when i press the button exe i got error message from the system line declaration ...: Name Error system Idem if i do :from sys import * ,followed by: system("c:/wordpad.exe") Thanks in advance, -- Nicolas Baurin Doctorant Institut de Chimie Organique et Analytique, UPRES-A 6005 http://www.univ-orleans.fr/SCIENCES/ICOA/ Université d'Orléans, BP 6759 45067 ORLEANS Cedex 2, France Tel: (33+) 2 38 49 45 77 From scarblac@pino.selwerd.nl Tue Oct 3 11:23:21 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 3 Oct 2000 12:23:21 +0200 Subject: [Tutor] Tkinter: link button to executable In-Reply-To: <39D9B149.668BF5E7@univ-orleans.fr>; from nicolas.baurin@univ-orleans.fr on Tue, Oct 03, 2000 at 12:13:30PM +0200 References: <39D9B149.668BF5E7@univ-orleans.fr> Message-ID: <20001003122321.A27473@pino.selwerd.nl> On Tue, Oct 03, 2000 at 12:13:30PM +0200, nicolas baurin wrote: > The windows appear but when i press the button exe i got error message > from the system line declaration > > ...: Name Error system > > Idem if i do :from sys import * > ,followed by: system("c:/wordpad.exe") system() is in the os module, not the sys module. So use "import os" and "os.system". Remco From dyoo@hkn.eecs.berkeley.edu Tue Oct 3 17:31:03 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 3 Oct 2000 09:31:03 -0700 (PDT) Subject: [Tutor] Tkinter: link button to executable In-Reply-To: <39D9B149.668BF5E7@univ-orleans.fr> Message-ID: > sys.system("c:/wordpad.exe") > The windows appear but when i press the button exe i got error message > from the system line declaration > > ...: Name Error system Ah! You're thinking of os.system(), not sys.system(). Easy to confuse the two. From FxItAL@aol.com Tue Oct 3 21:10:04 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Tue, 03 Oct 2000 16:10:04 EDT Subject: [Tutor] Freeze Message-ID: Hello I've downloaded both Python 1.5.2 and 1.6 on different machines and neither have the freeze.py file. Can someone tell me where to get it? Thanks Al From wilkins@iinet.net.au Tue Oct 3 15:19:36 2000 From: wilkins@iinet.net.au (Richard Wilkins) Date: Tue, 3 Oct 2000 22:19:36 +0800 Subject: [Tutor] Re:Freeze Message-ID: VGhlIGluc3RhbGxlciBtYWRlIGJ5IEdvcmRvbiBNY01pbGxhbiwgSSd2ZSBub3QgdXNlZCBpdCwg c28gSSBtaWdodCBiZSBkb2luZyB0aGUgd3JvbmcgdGhpbmcgYnkgYWR2ZXJ0aXNpbmcgaXQuLi5i dXQgb2ggd2VsbCwgSXQncyB3b3J0aCBhIHRyeS4NCg0KV2l0aGluIHRoZSBwYWNrYWdlIGlzIGZy ZWV6ZSwgb3IgeW91IGNhbiB1c2UgdGhlIG90aGVyIHNjcmlwdHMgdG8gY3JlYXRlIGV4ZWN1dGFi bGVzLiBIb3BlIGl0IGhlbHBzDQoNCkFuZHJldyBXaWxraW5zDQp0b29kbGVzQGRhdGFibG9ja3Mu bmV0 From wilkins@iinet.net.au Tue Oct 3 16:00:13 2000 From: wilkins@iinet.net.au (Richard Wilkins) Date: Tue, 3 Oct 2000 23:00:13 +0800 Subject: [Tutor] Re: Freeze... Message-ID: SGVoIEknbSBzbyBzbG93LCBJIGZvcmdvdCB0byBpbmNsdWRlIHRoZSBhZGRyZXNzISA6KQ0KDQpo dHRwOi8vd3d3Lm1jbWlsbGFuLWluYy5jb20= From fredrik.eriksson@flowsystems.se Wed Oct 4 14:13:11 2000 From: fredrik.eriksson@flowsystems.se (Fredrik Eriksson) Date: Wed, 4 Oct 2000 15:13:11 +0200 Subject: [Tutor] Web client Message-ID: <51168A252970D311896200508B7163621D4C8B@slow.flowsystems.se> I want to build a simple web client that logs in to a free web service to send a sms. What it need to do is get the first web page, fill in the form and send the information, get the next web page and do the same thing and then disconnect. But this requires a handling of cookies and I can't find anything for that in Python? Cheers, Fredrik From dyoo@hkn.eecs.berkeley.edu Wed Oct 4 16:30:36 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 4 Oct 2000 08:30:36 -0700 (PDT) Subject: [Tutor] Web client In-Reply-To: <51168A252970D311896200508B7163621D4C8B@slow.flowsystems.se> Message-ID: On Wed, 4 Oct 2000, Fredrik Eriksson wrote: > I want to build a simple web client that logs in to a free web service to > send a sms. What it need to do is get the first web page, fill in the form > and send the information, get the next web page and do the same thing and > then disconnect. > But this requires a handling of cookies and I can't find anything for that > in Python? I believe there's a Cookie.py library in the Vaults of Parnassus: http://www.timo-tasi.org/python/Cookie.py It should be useful for handling cookies, but I'm not quite sure how to use it. Does anyone else have experience with this? From bwisti@hotmail.com Wed Oct 4 19:46:58 2000 From: bwisti@hotmail.com (Brian Wisti) Date: Wed, 04 Oct 2000 11:46:58 PDT Subject: [Tutor] Web client Message-ID: Hi, I've used that version of Cookie.py. It works well enough, but I've only used it for server-side stuff (reading and setting cookies - not having my script pretend it's a browser-type stuff). The documentation for how to use it is in the file itself. If you do want to try a Cookie module, I'd suggest moving on to Python 2.0. It includes a much more refined Cookie module that has already proved for me to use with my scripts. True, Python 2.0 is beta, but it's probably at least as stable as the Cookie.py package that's floating around. Hope this helps! Brian Wisti >From: Daniel Yoo >To: Fredrik Eriksson >CC: tutor@python.org >Subject: Re: [Tutor] Web client >Date: Wed, 4 Oct 2000 08:30:36 -0700 (PDT) > >On Wed, 4 Oct 2000, Fredrik Eriksson wrote: > > > I want to build a simple web client that logs in to a free web service >to > > send a sms. What it need to do is get the first web page, fill in the >form > > and send the information, get the next web page and do the same thing >and > > then disconnect. > > But this requires a handling of cookies and I can't find anything for >that > > in Python? > >I believe there's a Cookie.py library in the Vaults of Parnassus: > > http://www.timo-tasi.org/python/Cookie.py > >It should be useful for handling cookies, but I'm not quite sure how to >use it. Does anyone else have experience with this? > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://www.python.org/mailman/listinfo/tutor _________________________________________________________________________ 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 spirou@aragne.com Wed Oct 4 21:03:59 2000 From: spirou@aragne.com (Denis) Date: Wed, 4 Oct 2000 22:03:59 +0200 Subject: [Tutor] Web client In-Reply-To: <51168A252970D311896200508B7163621D4C8B@slow.flowsystems.se>; from fredrik.eriksson@flowsystems.se on Wed, Oct 04, 2000 at 03:13:11PM +0200 References: <51168A252970D311896200508B7163621D4C8B@slow.flowsystems.se> Message-ID: <20001004220359.C22875@aragne.com> Le Wed, Oct 04, 2000 at 03:13:11PM +0200, Fredrik Eriksson pianota: > I want to build a simple web client that logs in to a free web > service to send a sms. What it need to do is get the first web > page, fill in the form and send the information, get the next > web page and do the same thing and then disconnect. > But this requires a handling of cookies and I can't find anything > for that in Python? Everyone here will send you links about cookie.py because you asked for it. But I think you'd better have a look at httplib and control the headers yourself. http://www.python.org/doc/current/lib/module-httplib.html Tell us what you think of it. Have fun. -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From FxItAL@aol.com Wed Oct 4 21:42:39 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Wed, 04 Oct 2000 16:42:39 EDT Subject: [Tutor] Python 1.6 BUG Message-ID: Hello All, I've had Python 1.6 installed on my new system for about a week. While running a script from the RUN box using -i. The DOS box will inconsistantly not close. I must use the Ctrl-Alt-Del, which responds slowly. After this happens Windows will not shut down. A reset and reboot is required. This script runs fine on my old system with Windows 95 with Python 1.5.2. I uninstalled 1.6 and installed 1.5.2 and all is well. FYI, Al From bangersontoast@yahoo.com Wed Oct 4 21:52:44 2000 From: bangersontoast@yahoo.com (danny stockton) Date: Wed, 4 Oct 2000 13:52:44 -0700 (PDT) Subject: [Tutor] u know Message-ID: <20001004205244.1253.qmail@web4306.mail.yahoo.com> Yo this is from team omega 4 tutorials __________________________________________________ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Thu Oct 5 06:34:59 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 4 Oct 2000 22:34:59 -0700 (PDT) Subject: [Tutor] Python 1.6 BUG In-Reply-To: Message-ID: On Wed, 4 Oct 2000 FxItAL@aol.com wrote: > I've had Python 1.6 installed on my new system for about a week. While > running a script from the RUN box using -i. The DOS box will > inconsistantly not close. I must use the Ctrl-Alt-Del, which responds > slowly. After this happens Windows will not shut down. A reset and > reboot is required. > > This script runs fine on my old system with Windows 95 with Python > 1.5.2. Weird! Does the same thing happen with the Python 2.0 betas? I don't have a Windows system to test this on; what does -i do? Thanks for the heads up. From claudia_dallas@yahoo.com Thu Oct 5 15:48:34 2000 From: claudia_dallas@yahoo.com (claudia flores) Date: Thu, 5 Oct 2000 07:48:34 -0700 (PDT) Subject: [Tutor] (no subject) Message-ID: <20001005144834.8514.qmail@web3903.mail.yahoo.com> I'm very new to this all i know is windows (bad i know) but i want to start from scratch to learn how to program the best languages can you recommend any links or books to get started!! claudia __________________________________________________ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/ From FxItAL@aol.com Thu Oct 5 16:21:20 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Thu, 5 Oct 2000 11:21:20 EDT Subject: [Tutor] Julian Calender Message-ID: <9b.b3006ea.270df670@aol.com> Hello All, Is it possible to convert two integers to a Julian Calender? ex. 10, 5 to 279 Thanks Al From marcel@punto.it Thu Oct 5 16:40:05 2000 From: marcel@punto.it (Marcel Preda) Date: Thu, 5 Oct 2000 17:40:05 +0200 (CEST) Subject: [Tutor] Julian Calender In-Reply-To: <9b.b3006ea.270df670@aol.com> Message-ID: On Thu, 5 Oct 2000 FxItAL@aol.com wrote: > Hello All, > > Is it possible to convert two integers to a Julian Calender? > ex. 10, 5 to 279 > > Thanks Al >>> import time >>> time.strftime("%j",time.localtime(time.time())); '279' current julian day look at the `mktime' function in the same modul ,`time' to create a date. PM From dyoo@hkn.eecs.berkeley.edu Thu Oct 5 19:48:56 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 5 Oct 2000 11:48:56 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: <20001005144834.8514.qmail@web3903.mail.yahoo.com> Message-ID: On Thu, 5 Oct 2000, claudia flores wrote: > I'm very new to this all i know is windows (bad i know) but i want to > start from scratch to learn how to program the best languages can you > recommend any links or books to get started!! That's ok that you come from a Windows background --- it's not as if it were a cardinal sin. *grin* You'll want to install the Python interpreter. If you wait a few days, I think that the 2.0final should be released. 2.0 is a big improvement from Python 1.52 (the current version). However, you should be able to work with 1.52 well. Here's the link to it: http://python.org/download/download_windows.html You'll just need py152.exe, which includes everything you need to get started. Here are a few references to Python introductory material: http://python.org/doc/Intros.html In particular, I really like two of the tutorials here: http://www.honors.montana.edu/~jjc/easytut/easytut/ http://members.xoom.com/alan_gauld/tutor/tutindex.htm If you have any questions, send them our way, and we'll be happy to answer them. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Thu Oct 5 19:54:28 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 5 Oct 2000 11:54:28 -0700 (PDT) Subject: [Tutor] Python 1.6 BUG In-Reply-To: <62.7c42f79.270df554@aol.com> Message-ID: On Thu, 5 Oct 2000 FxItAL@aol.com wrote: > I don't know about the Beta's, I'm not that experianced yet to be beta > testing. I have a hard enough time with what is known as working:-) > > The -i is used when you have a Python file on your desktop and you what to > keep the DOS screen displayed so you can read any errors after you close your > script. ex. python -i script.py. Hmmm... ok, actually I do have access to a Windows machine, so I'll see if the same thing happens with 2.0. From ChristopherNolen@aol.com Fri Oct 6 15:53:33 2000 From: ChristopherNolen@aol.com (ChristopherNolen@aol.com) Date: Fri, 6 Oct 2000 10:53:33 EDT Subject: [Tutor] ? Message-ID: I am very new to programming. I have been experimenting with python on my box at home running slackware. I would also like to use it while I am at the office but I only have windows98 here. I downloaded python and have everything up and running. My question is: How do I get my programs to run? I have written the area calculation program from the 'learn how to program' pages to my notepad. Now I just need info on how to get it to run! Thanks!cmn From shaleh@valinux.com Fri Oct 6 16:10:53 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 06 Oct 2000 08:10:53 -0700 (PDT) Subject: [Tutor] ? In-Reply-To: Message-ID: On 06-Oct-2000 ChristopherNolen@aol.com wrote: > I am very new to programming. I have been experimenting with python on my box > at home running slackware. I would also like to use it while I am at the > office but I only have windows98 here. I downloaded python and have > everything up and running. > My question is: How do I get my programs to run? I have written the area > calculation program from the 'learn how to program' pages to my notepad. Now > I just need info on how to get it to run! > Start, Run, type 'command'. This gives you a DOS window. Then do python myprog.py. You can also associate .py files to be run by the python interpreter. From dyoo@hkn.eecs.berkeley.edu Fri Oct 6 17:50:10 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 6 Oct 2000 09:50:10 -0700 (PDT) Subject: [Tutor] ? In-Reply-To: Message-ID: On Fri, 6 Oct 2000, Sean 'Shaleh' Perry wrote: > On 06-Oct-2000 ChristopherNolen@aol.com wrote: > > I am very new to programming. I have been experimenting with python on my box > > at home running slackware. I would also like to use it while I am at the > > office but I only have windows98 here. I downloaded python and have > > everything up and running. > > My question is: How do I get my programs to run? I have written the area > > calculation program from the 'learn how to program' pages to my notepad. Now > > I just need info on how to get it to run! > > > > Start, Run, type 'command'. This gives you a DOS window. Then do python > myprog.py. > > You can also associate .py files to be run by the python interpreter. Also, check Josh Cogliati's tutorial --- it has a section on running Python programs. It echos what Shaleh says, and also shows common error messages that you might run into. http://www.honors.montana.edu/~jjc/easytut/easytut/ Tell us if this works for you. Good luck! From ewe2@can.org.au Fri Oct 6 23:26:01 2000 From: ewe2@can.org.au (Sean Dwyer) Date: Sat, 7 Oct 2000 09:26:01 +1100 Subject: [Tutor] Programming Python Message-ID: <20001007092601.A241@can.org.au> I just bought "Programming Python", not realising that a new edition is on the way pending python 2.0's final release. The version used in the book and on the CD is 1.3. I know there have been many changes since (and I have all the errata just in case), but how much of the book do you think will be applicable still? And a bit of information: I made a suggestion about useful content on the _next_ Programming Python CD to Frank Wilson, the technical editor-in-chief, and the good news is that there will be more useful goodies on the new CD including add-ons like Pmw and interesting python applications :) Guess I'll buy that one too :) Sean -- Sean Dwyer CAN Admin Web: http://ewe2.cvis.com.au/ From nothingisgoingtochangemyworld@yahoo.com Sat Oct 7 02:22:46 2000 From: nothingisgoingtochangemyworld@yahoo.com (Joseph Stubenrauch) Date: Fri, 6 Oct 2000 18:22:46 -0700 (PDT) Subject: [Tutor] Python 1.6 BUG Message-ID: <20001007012246.20492.qmail@web1906.mail.yahoo.com> Strange, I have been experiencing the same bug myself. Here's the low down for me: Python 1.6 with win95 I am running a little Tkinter program The command line I use is simply: "python foo.py" About 25-35% of the time, when I close the Tkinter window, DOS seems to "freeze" and never returns to the c:\ command prompt. I have to ctrl-alt-delete repeatedly and shut down "winoldapp" to get rid of the window and then shell back into DOS and keep working. It's a bit of a pain, since I have the habit of testing EVERYTHING in tiny little stages, so I change one little thing, test it ... freeze ... ARGH! Change one more tiny thing, test it ... freeze ... ARGH! However, sometimes it seems to behave and doesn't bother me for an entire several hour session of python work. That's my report on the problem. Cheers, Joe __________________________________________________ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/ From ewe2@can.org.au Sat Oct 7 02:48:42 2000 From: ewe2@can.org.au (Sean Dwyer) Date: Sat, 7 Oct 2000 12:48:42 +1100 Subject: [Tutor] Programming Python Message-ID: <20001007124841.A1414@can.org.au> I just bought "Programming Python", not realising that a new edition is on the way pending python 2.0's final release. The version used in the book and on the CD is 1.3. I know there have been many changes since (and I have all the errata just in case), but how much of the book do you think will be applicable still? And a bit of information: I made a suggestion about useful content on the _next_ Programming Python CD to Frank Wilson, the technical editor-in-chief, and the good news is that there will be more useful goodies on the new CD including add-ons like Pmw and interesting python applications :) Guess I'll buy that one too :) Sean -- Sean Dwyer CAN Admin Web: http://ewe2.cvis.com.au/ From ewe2@can.org.au Sat Oct 7 03:05:38 2000 From: ewe2@can.org.au (Sean Dwyer) Date: Sat, 7 Oct 2000 13:05:38 +1100 Subject: [Tutor] Programming Python In-Reply-To: <20001007124841.A1414@can.org.au>; from Sean Dwyer on Sat, Oct 07, 2000 at 12:48:42PM +1100 References: <20001007124841.A1414@can.org.au> Message-ID: <20001007130538.A1481@can.org.au> apologies for the repeated post - i've been having strange error messages from the list system :( sean -- Sean Dwyer CAN Admin Web: http://ewe2.cvis.com.au/ From CaroleMangin@hotmail.com Sat Oct 7 19:24:49 2000 From: CaroleMangin@hotmail.com (CaroleMangin@hotmail.com) Date: Sat, 07 Oct 2000 20:24:49 +0200 Subject: [Tutor] domain name www.newsgroups.vg is again available... Message-ID: <20001007182744.684AB1D543@dinsdale.python.org> www.newsgroups.vg on speednames at 17h40 this 08/10/00 Just have a look at : http://www.speednames.com/search.asp?assoid=2660 @+ Carole... From dyoo@hkn.eecs.berkeley.edu Sat Oct 7 20:33:57 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 7 Oct 2000 12:33:57 -0700 (PDT) Subject: [Tutor] Programming Python In-Reply-To: <20001007124841.A1414@can.org.au> Message-ID: On Sat, 7 Oct 2000, Sean Dwyer wrote: > I just bought "Programming Python", not realising that a new edition > is on the way pending python 2.0's final release. The version used in > the book and on the CD is 1.3. I know there have been many changes > since (and I have all the errata just in case), but how much of the > book do you think will be applicable still? I think the core of the material will be relevant. Personally, though, I liked Learning Python a lot more than Programming Python. I like a book that I can hold in the palm of my hand. *grin* From CMNOLEN@aol.com Sat Oct 7 21:53:01 2000 From: CMNOLEN@aol.com (CMNOLEN@aol.com) Date: Sat, 7 Oct 2000 16:53:01 EDT Subject: [Tutor] stopping at 100 entries Message-ID: <4f.1c6baf9.2710e72d@aol.com> Hi- I am working through the 'Learning to Program Python' exercises. I had no trouble with the first exercise, a program to accept entries of numbers, tallying and reporting the sum until 100 is met or exceeded. I am now attempting to write one that will accept 100 entries, tracking the sum. I cannot seem to come up with a block that will stop the calculations after the 100th(or 10th or 5th etc.) entry. A point in the right direction would be greatly appreciated!cmn From lgwb@no_spam.home.com Sat Oct 7 22:21:05 2000 From: lgwb@no_spam.home.com (Michael Schmitt) Date: Sat, 7 Oct 2000 16:21:05 -0500 Subject: [Tutor] stopping at 100 entries - Use " for i in range(100)" Message-ID: <002a01c030a4$80836b40$0a0a0a0a@c175700-a.mntp1.il.home.com> How about this: ######################################## total = 0 for i in range(100): total = total + input("next number please:") print "The sum is now " , total ######################################## Michael Schmitt -----Original Message----- From: CMNOLEN@aol.com To: tutor@python.org Date: Saturday, October 07, 2000 3:54 PM Subject: [Tutor] stopping at 100 entries >Hi- >I am working through the 'Learning to Program Python' exercises. I had no >trouble with the first exercise, a program to accept entries of numbers, >tallying and reporting the sum until 100 is met or exceeded. I am now >attempting to write one that will accept 100 entries, tracking the sum. I >cannot seem to come up with a block that will stop the calculations after the >100th(or 10th or 5th etc.) entry. A point in the right direction would be >greatly appreciated!cmn > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://www.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Sat Oct 7 22:27:38 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 7 Oct 2000 14:27:38 -0700 (PDT) Subject: [Tutor] stopping at 100 entries In-Reply-To: <4f.1c6baf9.2710e72d@aol.com> Message-ID: On Sat, 7 Oct 2000 CMNOLEN@aol.com wrote: > I am working through the 'Learning to Program Python' exercises. I had no > trouble with the first exercise, a program to accept entries of numbers, > tallying and reporting the sum until 100 is met or exceeded. I am now > attempting to write one that will accept 100 entries, tracking the sum. I > cannot seem to come up with a block that will stop the calculations after the > 100th(or 10th or 5th etc.) entry. A point in the right direction would be > greatly appreciated!cmn Hello! I'll try to go from an indirect angle. Imagine if we wanted to go through a list of names: ### >>> for name in ['herimone', 'potter', 'weasley']: ... print "Hello,", name ... Hello, herimone Hello, potter Hello, weasley ### The for/in loop is very useful, and easy to use. Also, Python makes it very easy to construct a list of increasing numbers: ### >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for x in range(3): ... print x ... 0 1 2 ### For your problem, the trick is to construct a list of items, but ignore the iterating variable. ### >>> for dontcare in range(5): ... print "hello hello" ... hello hello hello hello hello hello hello hello hello hello ### Hope this helps! From lgwb@no_spam.home.com Sat Oct 7 22:33:47 2000 From: lgwb@no_spam.home.com (Michael Schmitt) Date: Sat, 7 Oct 2000 16:33:47 -0500 Subject: [Tutor] sorry - indentation not pasted properly Message-ID: <003d01c030a6$469ef1e0$0a0a0a0a@c175700-a.mntp1.il.home.com> Sorry the code should have been as follows. It seems the tabs did not paste properly when copied from my editor. ######################################## total = 0 for i in range(100): total = total + input("next number please:") print "The sum is now " , total ######################################## Michael Schmitt From dyoo@hkn.eecs.berkeley.edu Sat Oct 7 22:56:30 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 7 Oct 2000 14:56:30 -0700 (PDT) Subject: [Tutor] Cool messages from the past Message-ID: I thought it might be fun to look at tutor@python.org posts from a few years ago, to see what it was like back then. After reading a few of them, I feel _really_ impressed by the topics and techniques that the patriarchs (no disrespect intended! *grin*) used. As an example of one of the idioms, take a look at: http://www.python.org/pipermail/tutor/1999-March/002547.html Has anyone thought about going through the archives, and doing a compilation of them? Perhaps we could glean some sort of "cookbook" that might help new programmers with very beautiful techniques. From wilson@visi.com Sun Oct 8 03:05:51 2000 From: wilson@visi.com (Timothy Wilson) Date: Sat, 7 Oct 2000 21:05:51 -0500 (CDT) Subject: [Tutor] techniques for OO design Message-ID: Hi everyone, I'm continuing to dabble with Python whenever I can. I struggle, as I suspect many who have worked with procedure programming languages in the past have, with the implementing OOP princples. I've created a few rather simple OO programs and I can see the beauty in it. I'm wondering if any of you can suggest a method (pun intended) for thinking about how to structure an OO program. I understand that many people work with UML, but that's more than I have time for right now. Are there some key questions that can be asked in the design phase? A simple graphing scheme perhaps? I'd love to hear what techniques others use. -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 rbl@hal.cwru.edu Sun Oct 8 13:01:11 2000 From: rbl@hal.cwru.edu (Robin B. Lake) Date: Sun, 8 Oct 2000 08:01:11 -0400 (EDT) Subject: [Tutor] techniques for OO design Message-ID: <200010081201.IAA11181@hal.cwru.edu> Although I'm a grey-beard at programming, I had my first real clean-paper chance to specify an object oriented approach (with Python in mind) last week. It involves a streaming-media scheduling application, wherein both content (live video, tapes, and MPEG-encoded "assets"), the equipment to deliver the media (machines, encoders, networks, disk space), and the people to operate the system all have to be scheduled. First, I simply listed the "objects" (by class): machines, staff, networks, media sources, etc. Then I sub-listed the specific instances of each class of objects: Machines: encoders, video juke boxes, viewing rooms, ... Then, I identified the "operations" (methods?) to cover ALL objects: "Add an object", "Repair an object", "Schedule an object", ... I use Lake's Second Law of Software Physics --- "For every operation there should be an equal and opposite re-operation." Schedule/Reschedule/Unschedule, Add/Remove, ... Then, I listed the functional requirements to implement a system using the "objects" and "operations". No design yet, just a list. Like "Provide a user interface", "Prepare a usage chart", "Identify schedule conflicts", "Tally requests", ... Then, the first bit of design. Think about a working system in your mind's eye; consider a high-level of design and implementation, such as "User Interface should be a Web browser", so add to the functional requirements "Accept HTML/XML commands" and "Issue an HTML/XML Web page". At this stage, I get the user's sign off on the functional specs. Next to be done is a User Manual --- yep, before coding the first line, tell the story that's in your mind's eye. It will serve you down the line as well as give the user some (false?) sense of security that you know what you are doing. THEN, I'd start with some piece of the system and write the test code. Maybe it's just something that tests adding to and removing from a list or dictionary. (see "extreme programming" at www.xprogramming.com) Build and test one piece at a time, ALWAYS KEEPING A RUNNING SYSTEM. Rather like building a house on a sound foundation. Of course things will change as the systems gets built ... the specs and drawings and location and interaction of things will move around as you see how the house/system REALLY works. Enjoy. It all goes much better if you have someone working with you. Cheers, Rob Lake rbl@hal.cwru.edu > From tutor-admin@python.org Sat Oct 7 22:06:52 2000 > Delivered-To: tutor@python.org > X-Authentication-Warning: isis.visi.com: wilson owned process doing -bs > To: tutor@python.org > MIME-Version: 1.0 > Subject: [Tutor] techniques for OO design > X-BeenThere: tutor@python.org > X-Mailman-Version: 2.0beta6 > List-Help: > List-Post: > List-Subscribe: , > > List-Id: Discussion for learning programming with Python > List-Unsubscribe: , > > List-Archive: > > Hi everyone, > > I'm continuing to dabble with Python whenever I can. I struggle, as I > suspect many who have worked with procedure programming languages in the > past have, with the implementing OOP princples. I've created a few rather > simple OO programs and I can see the beauty in it. > > I'm wondering if any of you can suggest a method (pun intended) for thinking > about how to structure an OO program. I understand that many people work > with UML, but that's more than I have time for right now. Are there some key > questions that can be asked in the design phase? A simple graphing scheme > perhaps? > > I'd love to hear what techniques others use. > > -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/ > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From steve@spvi.com Sun Oct 8 15:54:57 2000 From: steve@spvi.com (Steve Spicklemire) Date: Sun, 8 Oct 2000 09:54:57 -0500 (EST) Subject: [Tutor] techniques for OO design In-Reply-To: <200010081201.IAA11181@hal.cwru.edu> (rbl@hal.EPBI.CWRU.Edu) References: <200010081201.IAA11181@hal.cwru.edu> Message-ID: <200010081454.JAA99947@mercury.spvi.com> Excellent example!... If you're looking for a good book I've really enjoyed Coad's Object Models : Strategies, Patterns and Applications (Yourdon Press Computing Series) by Peter Coad, Mark Mayfield (Contributor), David North (Contributor) It's done in a 'story telling' kind of way.. with lots of pictures and diagrams. My Kind Of Book! ;-) His basic approach is to factor the problem into separate domians, and object 'archetypes' or patterns. There's also a lot of discussion about these kinds of issues revolving around ZPatterns in the zope-dev mailing list.. Also.. Robin... I don't know if you've looked a Zope... but IMHO you should ;-). (And look at ZPatterns!) take care, -steve >>>>> "Robin" == Robin B Lake writes: Robin> Although I'm a grey-beard at programming, I had my first Robin> real clean-paper chance to specify an object oriented Robin> approach (with Python in mind) last week. It involves a Robin> streaming-media scheduling application, wherein both Robin> content (live video, tapes, and MPEG-encoded "assets"), the Robin> equipment to deliver the media (machines, encoders, Robin> networks, disk space), and the people to operate the system Robin> all have to be scheduled. .. Robin> Cheers, Rob Lake rbl@hal.cwru.edu >> Hi everyone, >> >> I'm continuing to dabble with Python whenever I can. I >> struggle, as I suspect many who have worked with procedure >> programming languages in the past have, with the implementing >> OOP princples. I've created a few rather simple OO programs and >> I can see the beauty in it. >> >> I'm wondering if any of you can suggest a method (pun intended) >> for thinking about how to structure an OO program. I understand >> that many people work with UML, but that's more than I have >> time for right now. Are there some key questions that can be >> asked in the design phase? A simple graphing scheme perhaps? >> >> I'd love to hear what techniques others use. >> >> -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/ >> >> >> _______________________________________________ Tutor maillist >> - Tutor@python.org http://www.python.org/mailman/listinfo/tutor >> Robin> _______________________________________________ Tutor Robin> maillist - Tutor@python.org Robin> http://www.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Mon Oct 9 10:58:27 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Oct 2000 10:58:27 +0100 Subject: [Tutor] techniques for OO design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D35C@mbtlipnt02.btlabs.bt.co.uk> > I'm wondering if any of you can suggest a method (pun > intended) for thinking about how to structure an OO program. The best book that I know of for starting out in OO is Coad/Yourdon's Object Oriented Analysis. They present a very clear and simple view of how to do OO and an eaqually simple notation to go with it. The good news is the notation is very similar to UML so the relearning is minimal. The other things I find helpful are: 1/ Use "Responsibility Driven Design" - think about what each object is responsible for. 2/ DO NOT THINK ABOUT DATA! OO Design should be driven by desired behaviours, the data is there to support that behaviour. 3/ CRC cards are very useful 5x3 cards with a title line for the *C*lass name and the rest split vertically. One side holds the *R*esponsibilities and the other holds the *C*ollaborators. - Hence CRC... You can then play with these cards(or 'post-it's) on a table/whiteboard until the shape of your system comes together. > I understand that many people work with UML, UML is a notation which originated with OO but can be used in almost any software or systems design role. Its very useful for professional designs but for small projects is probably overkill. You still need to understand what you are doing with it too, like any notation it only captures the output of your design not how you got there! HTH, Alan G. From alan.gauld@bt.com Mon Oct 9 10:43:16 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Oct 2000 10:43:16 +0100 Subject: [Tutor] Programming Python Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D35B@mbtlipnt02.btlabs.bt.co.uk> > I just bought "Programming Python", not realising that a new > edition is on the > way pending python 2.0's final release. The version used in > the book and on > the CD is 1.3. I know there have been many changes since (and > I have all the > errata just in case), but how much of the book do you think > will be applicable > still? Virtually all of it. I'm still using PP in Python 1.6 and its almost always applicable. The only thing you might find is that some of the things are now deprecated and others have been superceded by more recent alternatives. The vast majority is still OK tho' Alan G. From alan.gauld@bt.com Mon Oct 9 11:01:40 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Oct 2000 11:01:40 +0100 Subject: [Tutor] techniques for OO design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D35D@mbtlipnt02.btlabs.bt.co.uk> > Robin B. Lake > Sent: Sunday, October 08, 2000 1:01 PM > At this stage, I get the user's sign off on the functional > specs. Next to be done is a User Manual ... That's a really powerful tool. It ties in very well with UseCases for capturing requirements but also serves to tie down the User Interface early which is effective in reducing requirements creep! Alan G. From droux@tuks.co.za Mon Oct 9 20:44:19 2000 From: droux@tuks.co.za (Danie Roux) Date: Mon, 9 Oct 2000 15:44:19 -0400 Subject: [Tutor] Calling ancestors __init__ Message-ID: <20001009154419.A30375@emily.up.ac.za> The beauty of OO programming is the ability to let the parent to it's own setup. In Smalltalk this is super (arguments) How do I do that in Python? Currently I call from the child object: ancestor.__init__ (args) But this seems wrong. -- Danie Roux *shuffle* Adore Unix From steve@spvi.com Mon Oct 9 14:57:48 2000 From: steve@spvi.com (Steve Spicklemire) Date: Mon, 9 Oct 2000 08:57:48 -0500 (EST) Subject: [Tutor] Calling ancestors __init__ In-Reply-To: <20001009154419.A30375@emily.up.ac.za> (message from Danie Roux on Mon, 9 Oct 2000 15:44:19 -0400) References: <20001009154419.A30375@emily.up.ac.za> Message-ID: <200010091357.IAA05373@mercury.spvi.com> >>>>> "Danie" == Danie Roux writes: Danie> The beauty of OO programming is the ability to let the Danie> parent to it's own setup. In Smalltalk this is super Danie> (arguments) Danie> How do I do that in Python? Currently I call from the child Danie> object: Danie> ancestor.__init__ (args) It goes something like this: class Foo: def __init__(self, blah blah.... ): self.blah = blah .... class Bar(Foo): def __init__(self, foop, foop.....): Foo.__init__(self, blah, blah...) self.foo = foop .... -steve Danie> But this seems wrong. Danie> -- Danie Roux *shuffle* Adore Unix Danie> _______________________________________________ Tutor Danie> maillist - Tutor@python.org Danie> http://www.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Mon Oct 9 17:40:11 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Oct 2000 17:40:11 +0100 Subject: [Tutor] Calling ancestors __init__ Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D364@mbtlipnt02.btlabs.bt.co.uk> > The beauty of OO programming is the ability to let the parent > to it's own > setup. In Smalltalk this is super (arguments) I guess you could fake this (a bit) in Python by: class Foo(Bar): super = Bar def __init__(self): self.super.__init__(self) # do something def doit(self): self.super.doit(self) # do the polymorphic thing > How do I do that in Python? Currently I call from the child object: > > ancestor.__init__ (args) That's the usual way, it does mean that if you change the superclass you have to change all the calls to it, whereas the self.super technique means only one change - otherwise there's no advantage. Alan G. From CMNOLEN@aol.com Mon Oct 9 18:31:43 2000 From: CMNOLEN@aol.com (CMNOLEN@aol.com) Date: Mon, 9 Oct 2000 13:31:43 EDT Subject: [Tutor] while and for Message-ID: <22.c3c3446.27135aff@aol.com> I asked earlier for guidance in writing a program to total input from 100 entries. It worked great. Now I want the program to contain an 'Enter 0 to quit' line. Also I would like a running count of the entries to show in the 'The sum is now' line. I am stuck. I guess these questions are so basic most print doesn't answer them?I am stuck! I am using: ######################################################### total = 0 for i in range(100): total = total + input("Please enter your next number: ") print "The sum is now", total ######################################################### From marcel@punto.it Mon Oct 9 18:58:31 2000 From: marcel@punto.it (Marcel Preda) Date: Mon, 9 Oct 2000 19:58:31 +0200 (CEST) Subject: [Tutor] while and for In-Reply-To: <22.c3c3446.27135aff@aol.com> Message-ID: On Mon, 9 Oct 2000 CMNOLEN@aol.com wrote: > I asked earlier for guidance in writing a program to total input from 100 > entries. It worked great. Now I want the program to contain an 'Enter 0 to > quit' line. Also I would like a running count of the entries to show in the > 'The sum is now' line. I am stuck. I guess these questions are so basic most > print doesn't answer them?I am stuck! > > I am using: > ######################################################### > total = 0 > for i in range(100): > total = total + input("Please enter your next number: ") > print "The sum is now", total > ######################################################### have to use `raw_input' function, after convert to int >>> for i in range(100): ... new=raw_input("Enter the new value (0 to quit):") ... if new=='0': ... break ... total=total + int(new) ... Enter the new value (0 to quit):1 Enter the new value (0 to quit):3 Enter the new value (0 to quit):6 Enter the new value (0 to quit):7 Enter the new value (0 to quit):0 >>> total 17 PM From shaleh@valinux.com Mon Oct 9 21:18:39 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 09 Oct 2000 13:18:39 -0700 (PDT) Subject: [Tutor] Cool messages from the past In-Reply-To: Message-ID: > > Has anyone thought about going through the archives, and doing a > compilation of them? Perhaps we could glean some sort of "cookbook" that > might help new programmers with very beautiful techniques. > sounds like you just volunteered yourself Daniel (-: From scarblac@pino.selwerd.nl Tue Oct 10 00:20:06 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 10 Oct 2000 01:20:06 +0200 Subject: [Tutor] while and for In-Reply-To: <22.c3c3446.27135aff@aol.com>; from CMNOLEN@aol.com on Mon, Oct 09, 2000 at 01:31:43PM -0400 References: <22.c3c3446.27135aff@aol.com> Message-ID: <20001010012006.A16352@pino.selwerd.nl> On Mon, Oct 09, 2000 at 01:31:43PM -0400, CMNOLEN@aol.com wrote: > I asked earlier for guidance in writing a program to total input from 100 > entries. It worked great. Now I want the program to contain an 'Enter 0 to > quit' line. Also I would like a running count of the entries to show in the > 'The sum is now' line. I am stuck. I guess these questions are so basic most > print doesn't answer them?I am stuck! > > I am using: > ######################################################### > total = 0 > for i in range(100): > total = total + input("Please enter your next number: ") > print "The sum is now", total > ######################################################### To break out of a loop, you use 'break'. Something like: total = 0 for i in range(100): inp = input("Please enter your next number, or 0 to exit: ") if inp == 0: break total = total + inp print "The sum is now", total Should work. Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Tue Oct 10 00:32:24 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Oct 2000 16:32:24 -0700 (PDT) Subject: [Tutor] while and for In-Reply-To: <22.c3c3446.27135aff@aol.com> Message-ID: On Mon, 9 Oct 2000 CMNOLEN@aol.com wrote: > I asked earlier for guidance in writing a program to total input from > 100 entries. It worked great. Now I want the program to contain an > 'Enter 0 to quit' line. Also I would like a running count of the > entries to show in the 'The sum is now' line. I am stuck. I guess > these questions are so basic most print doesn't answer them?I am > stuck! What I find helpful is pretend that everything works perfectly, and see what I expect to see during a sample run. For me, doing this helps me see what details I'm forgetting, or what I really want the program to do. Let's try it for your program. # program begins Please enter your next number: 1 The sum is now 1 = 1 Please enter your next number: 2 The sum is now 1+2 = 3 Please enter your next number: 42 The sum is now 1+2+42 = 45 Please enter your next number: 0 Goodbye! # program ends If we want our program to behave this way, we'll want to keep a "running sum" string as well as a running total. It would look something like this: sumstring = '' num = input('Please enter your next number: ') while (we're not done yet): # <-- This needs to be defined somehow sumstring = sumstring + num + '+' # ... other stuff num = input('Please enter your next number: ') As you can see, as we continue going through the loop, our sumstring will keep track of all the numbers we've ever seen. It'll grow like this: '' --> '1+' --> '1+2+' --> '1+2+42+' So when you print out that sumstring, you'll probably want to chop off the trailing plus sign. Now that I look back at your question, I might be completely misunderstanding what you mean by 'running count'. *grin* If so, sorry about that! Could you clarify? From rbl@hal.cwru.edu Tue Oct 10 01:01:15 2000 From: rbl@hal.cwru.edu (Robin B. Lake) Date: Mon, 9 Oct 2000 20:01:15 -0400 (EDT) Subject: [Tutor] Cool messages from the past Message-ID: <200010100001.UAA25782@hal.cwru.edu> Better yet, write a Python script that (a) extracts facts from each posting and (b) categorizes each posting by content. :=}}} Cheers, Rob Lake rbl@hal.cwru.edu > From tutor-admin@python.org Mon Oct 9 16:18:47 2000 > Delivered-To: tutor@python.org > X-Priority: 3 (Normal) > Content-Transfer-Encoding: 8bit > MIME-Version: 1.0 > To: Daniel Yoo > Subject: RE: [Tutor] Cool messages from the past > Cc: tutor@python.org > X-BeenThere: tutor@python.org > X-Mailman-Version: 2.0beta6 > List-Help: > List-Post: > List-Subscribe: , > > List-Id: Discussion for learning programming with Python > List-Unsubscribe: , > > List-Archive: > > > > > Has anyone thought about going through the archives, and doing a > > compilation of them? Perhaps we could glean some sort of "cookbook" that > > might help new programmers with very beautiful techniques. > > > > sounds like you just volunteered yourself Daniel (-: > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From wesc@deirdre.org Mon Oct 9 22:12:46 2000 From: wesc@deirdre.org (Wesley Chun) Date: Mon, 9 Oct 2000 14:12:46 -0700 Subject: [Tutor] Re: EVENT: Python course in Silicon Valley Message-ID: <200010092112.OAA20040@adelie.deirdre.org> hey folks, there are a few more seats available in this class if you are interested. we completed the first week doing all the intro stuff, and tomorrow night is when we start digging into Python. the URL is below, or their phone numbers are: 800-660-UNEX or 831-427-6600. -wesley > From wesc Fri Sep 22 11:18:34 2000 > To: tutor@python.org > Subject: EVENT: Python course in Silicon Valley > > below is an announcement for another Python course i'm giving for > UC Santa Cruz for Fall 2000 quarter. 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 > those completely new to programming period. this class is ten- > tatively scheduled for sometime late next year, not to mention a > Python Programming II class, which covers more advanced stuff > that we don't get a chance to address in the first class. > > let me know if you have any questions. hope to see some > of you in class this quarter!! > > -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 > > What: intro to Python, data types, statements, errors and > exception handling, functions and modules, OOP and > classes, execution environment, regular expressions, > network/Internet programming, 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?function=detail&X_Number=X444.3 > > (if the above link fails, just go to the Events page > at http://www.python.org ) > > -- > * "Core Python Programming", Prentice Hall PTR, TBP Fall 2000 > > * Silicon Valley/SF Bay Area Python UG: http://www.baypiggies.org > > * wesley.j.chun :: cyberweb.consulting :: silicon.valley, ca > * http://www.roadkill.com/~wesc/cyberweb/ From rickdoksa@penn.com Tue Oct 10 06:09:52 2000 From: rickdoksa@penn.com (Richard E. Doksa) Date: Mon, 9 Oct 2000 22:09:52 -0700 Subject: [Tutor] help Message-ID: <001001c03278$55bba8c0$129df5cd@doksa> This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C0323D.A638AD60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable hi im new to programming and cant find help anywhere where i live i was = wondering can anyone tell me what is wrong with this program i wrote. it = is only a program to answer a simple question. input =3D feline print raw_input("what kind of animal is a cat?") if input =3D=3D feline: print "thats right!" if input !=3D feline: print "try again" it somewhat works but isnt right what im i doing wrong? thanks rick~> ------=_NextPart_000_000D_01C0323D.A638AD60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
hi im new to programming and cant find = help=20 anywhere where i live i was wondering can anyone tell me what is wrong = with this=20 program i wrote. it is only a program to answer a simple = question.
 
input =3D feline
print = raw_input("what=20 kind of animal is a cat?")
if input =3D=3D feline:
 print = "thats=20 right!"
if input !=3D feline:
 print "try again"
 
it somewhat works but isnt = right what im=20 i doing wrong?
 
thanks
rick~>
------=_NextPart_000_000D_01C0323D.A638AD60-- From wilson@visi.com Tue Oct 10 03:33:03 2000 From: wilson@visi.com (Timothy Wilson) Date: Mon, 9 Oct 2000 21:33:03 -0500 (CDT) Subject: [Tutor] help In-Reply-To: <001001c03278$55bba8c0$129df5cd@doksa> Message-ID: On Mon, 9 Oct 2000, Richard E. Doksa wrote: > hi im new to programming and cant find help anywhere where i live i was wondering can anyone tell me what is wrong with this program i wrote. it is only a program to answer a simple question. > > input = feline > print raw_input("what kind of animal is a cat?") > if input == feline: > print "thats right!" > if input != feline: > print "try again" Try this: input = raw_input("What kind of animal is a cat? ") if input == 'feline': print "That\'s right!" else: print "Try again." 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 dyoo@hkn.eecs.berkeley.edu Tue Oct 10 03:52:32 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Oct 2000 19:52:32 -0700 (PDT) Subject: [Tutor] while and for In-Reply-To: <87.13df548.2713bbbd@aol.com> Message-ID: On Mon, 9 Oct 2000 CMNOLEN@aol.com wrote: > 'You have entered 3 numbers totaling 45.' or > 'The total is 45. You have entered 3 numbers.' Another hint: try to to write your program so it's _almost_ right: have it keep summing totals until the user enters zero. After you get that working, it shouldn't be too bad to have it print a running count as well. This is the "I'm faking it now, but I'll fix it soon" method. *grin* The faking method actually works pretty well --- you know exactly what your program isn't supposed to do yet, and you'll get a running program that you can improve on until things finally do work. > And I really do appreciate your help! By the way do you have any > favorite books for a beginning programmer? Thank You! cmn Ah! A reading list! I'd highly recommend George Polya's "How to Solve It". It's a wonderful book that explains a "heuristic" way of approaching problems. Although Polya does it with math, it's not too much of a stretch to apply his tips to computer programming. I think that every programmer should be familiar with it. Another classic is Jon Bentley's "Programming Pearls", but you might want to wait on that one until you're more comfortable with programming. Which reminds me; I must finish reading it too! *grin* Finally, you might want to look at Douglas Hofstadter's "Godel, Escher, Bach" for recreational, mind-bending reading. It has been described as a "philosophy book disguised as a CS book disguised as literature". It's very good. Good luck! From griff@netdoor.com Tue Oct 10 04:04:52 2000 From: griff@netdoor.com (R. A.) Date: Mon, 09 Oct 2000 22:04:52 -0500 Subject: [Tutor] help References: <001001c03278$55bba8c0$129df5cd@doksa> Message-ID: <39E28754.4BD56B81@netdoor.com> Richard, I'm really new at this, too, so someone else will probably provide a better answer than mine. However, here goes: # declare a variable named *animaltype* animaltype = "feline" # ask for input, assigning the input to the variable *input* input = raw_input("what kind of animal is a cat?") # if *input* is equivalent to *animaltype*, print *that's right* if input == animaltype: print "that's right!" # otherwise, print *try again* else: print "try again" There's a slightly more sophisticated example on one of my web pages, if you care to glance at it: http://www2.netdoor.com/~griff/magicword.html Rob Andrews > "Richard E. Doksa" wrote: > > hi im new to programming and cant find help anywhere where i live i > was wondering can anyone tell me what is wrong with this program i > wrote. it is only a program to answer a simple question. > > input = feline > print raw_input("what kind of animal is a cat?") > if input == feline: > print "thats right!" > if input != feline: > print "try again" > > it somewhat works but isnt right what im i doing wrong? > > thanks > rick~> -- GIT/P/TW d---(++) s++:s a? C+++++ U$>+++ P+ L+>++++ E@ W++ N++ o? K- w$ ?O ?M ?V PS+++ PE Y+@ PGP- t+@ 5 X@ R+ tv+ b+++ DI+@ D+ Q3A++ e++* h* r y++* UF+++ From dyoo@hkn.eecs.berkeley.edu Tue Oct 10 04:05:31 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Oct 2000 20:05:31 -0700 (PDT) Subject: [Tutor] help In-Reply-To: <001001c03278$55bba8c0$129df5cd@doksa> Message-ID: On Mon, 9 Oct 2000, Richard E. Doksa wrote: > hi im new to programming and cant find help anywhere where i live i > was wondering can anyone tell me what is wrong with this program i > wrote. it is only a program to answer a simple question. > > input = feline > print raw_input("what kind of animal is a cat?") > if input == feline: > print "thats right!" > if input != feline: > print "try again" The only problem is that Python can't tell that you literally mean the word "feline". For all it knows, you might have a feline variable. You're probably getting a NameError, which is a symptom of accidently forgetting about this. To make it unambiguous, you should quote 'feline' as a string: if input == 'feline': print "that's right!" if input != 'feline': print "try again" Other things to point out: you probably don't want to use 'input' as a variable name, since there's already an input() function (similar to raw_input). It's usually safer to give a distinctive name to your variables... hmmm... a good name might be 'animal'. Timothy Wilson caught a few other things in his response, so take a look at his program for other things. If you have any questions, please feel free to ask us; we'll be glad to help. Good luck with your learning! From deirdre@deirdre.net Tue Oct 10 05:28:29 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 9 Oct 2000 21:28:29 -0700 (PDT) Subject: [Tutor] stopping at 100 entries In-Reply-To: Message-ID: On Sat, 7 Oct 2000, Daniel Yoo wrote: > Imagine if we wanted to go through a list of names: > > ### > >>> for name in ['herimone', 'potter', 'weasley']: > ... print "Hello,", name > ... > Hello, herimone That's Hermione. :) (her-MY-oh-knee) Speaking as another woman with a difficult-to-pronounce name.... -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "More damage has been caused by innocent program crashes than by malicious viruses, but they don't make great stories." -- Jean-Louis Gassee, Be Newsletter, Issue 69 From rishi@musicurry.com Tue Oct 10 06:13:24 2000 From: rishi@musicurry.com (Rishi Maker) Date: Tue, 10 Oct 2000 10:43:24 +0530 Subject: [Tutor] MysqlDB Message-ID: <20001010104324.A6739@musicurry.com> can anybody tell me where to find manual of MySQLdb module thank you -- --------------------------------------------------------------------------- Signature Follows :- Rishi Maker |------------Quote Of The Mail----------------| Senior Developer |If you don't have time to do it right, where | rishi@musicurry.com |are you going to find the time to do it over?| Tel-Res : 91-22-5374892 | | Tel-Off : 91-22-4603751/52 | | ICQ-UIN : 56551784 | | www.rishimaker.com | | ------------------------------------------------------------------------------- | ----:----:----:-----:----:----:----:----:----:----:----:----:| --------| guru, n: A computer owner who can read the manual. |------- | ----:----:----:-----:----:----:----:----:----:----:----:----:| ------------------------------------------------------------------------------- CopyLeft Rishi Maker ------------------------------------------------------------------------------- From dyoo@hkn.eecs.berkeley.edu Tue Oct 10 06:26:38 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Oct 2000 22:26:38 -0700 (PDT) Subject: [Tutor] stopping at 100 entries In-Reply-To: Message-ID: On Mon, 9 Oct 2000, Deirdre Saoirse wrote: > On Sat, 7 Oct 2000, Daniel Yoo wrote: > > > Imagine if we wanted to go through a list of names: > > > > ### > > >>> for name in ['herimone', 'potter', 'weasley']: > > ... print "Hello,", name > > ... > > Hello, herimone > > That's Hermione. :) (her-MY-oh-knee) > Speaking as another woman with a difficult-to-pronounce name.... Oh my, I did it again! *sob* I have a very hard time with names. A few days ago, I spelled "Ron" as "Rob". I'd better make this Python-relevant. misspeled = 'Rob' corrected = misspeled[0:-1] + 'n' I was curious; is there a python module that, given a list of words and a misspelled word, returns back the "most similar" word? I do remember reading about an algorithm that would give the "distance" between two words, but I haven't found it in Parnassus. From dyoo@hkn.eecs.berkeley.edu Tue Oct 10 07:04:24 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Oct 2000 23:04:24 -0700 (PDT) Subject: [Tutor] MysqlDB In-Reply-To: <20001010104324.A6739@musicurry.com> Message-ID: On Tue, 10 Oct 2000, Rishi Maker wrote: > can anybody tell me where to find manual of MySQLdb module The Python Database API 2.0 should help you get started: http://python.org/topics/database/DatabaseAPI-2.0.html MySQLdb follows the standard pretty closely, I think. The only thing that you'll need to worry about is figuring out how to create the connection in the first place. Just in case, here's a small example of doing SQL stuff: import MySQLdb conn = MySQLdb.connect(db='test', user='dyoo', passwd='**obscured**') cursor = conn.cursor() cursor.execute("select * from names") results = cursor.fetchall() print results For more details, take a look at: http://dustman.net/andy/python/MySQLdb/0.2.2/MySQLdb-0.2.2.tar.gz which contains the documentation for MySQLdb as well as its source code. From SBrunning@trisystems.co.uk Tue Oct 10 08:35:14 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Tue, 10 Oct 2000 08:35:14 +0100 Subject: [Tutor] stopping at 100 entries Message-ID: <31575A892FF6D1118F5800600846864D5B125F@intrepid> > From: Daniel Yoo [SMTP:dyoo@hkn.eecs.berkeley.edu] > I was curious; is there a python module that, given a list of words and a > misspelled word, returns back the "most similar" word? I do remember > reading about an algorithm that would give the "distance" between two > words, but I haven't found it in Parnassus. Daniel, The algorithm that you want is called 'soundex'. I think that I remember a soundex module at Parnassus, but I haven't tried it. 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 norman@earth.ox.ac.uk Tue Oct 10 09:19:26 2000 From: norman@earth.ox.ac.uk (Norman Charnley) Date: Tue, 10 Oct 2000 09:19:26 +0100 (BST) Subject: [Tutor] Copying lists of lists In-Reply-To: <20001010051207.231AB1CD0E@dinsdale.python.org> Message-ID: As the subject line says, I want to make a copy of a list of lists, but I've encountered a problem which I can't understand. First the obvious: >>> a=[1,2,3] >>> b=a[:] >>> b[0]=99 >>> print a,b >>> [1, 2, 3] [99, 2, 3] OK, so far, so good. But: >>> a=[[1,2,3],[4,5,6],[7,8,9]] >>> b=a[:] >>> b[0][0]=99 >>> print a [[99, 2, 3], [4, 5, 6], [7, 8, 9]] >>> print b [[99, 2, 3], [4, 5, 6], [7, 8, 9]] i.e. a is reflecting the change made in b. However, the following does work as I expected: >>> a=[[1,2,3],[4,5,6],[7,8,9]] >>> b=a[:] >>> b[0]=99 >>> print a [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> print b [99, [4, 5, 6], [7, 8, 9]] Help, I'm a little confused, and I'd be grateful for an explanation. If this were C I'd think it was a pointer problem...! Many thanks, Norman ================================================= Dr. Norman Charnley Department of Earth Sciences University of Oxford Oxford OX1 3PR, UK. ================================================== From hakan@netg.se Tue Oct 10 09:29:09 2000 From: hakan@netg.se (Hakan Nilsson) Date: Tue, 10 Oct 2000 10:29:09 +0200 (CEST) Subject: [Tutor] Copying lists of lists In-Reply-To: Message-ID: On Tue, 10 Oct 2000, Norman Charnley wrote: > As the subject line says, I want to make a copy of a list of lists, but > I've encountered a problem which I can't understand. > > First the obvious: > > >>> a=[1,2,3] > >>> b=a[:] > >>> b[0]=99 > >>> print a,b > >>> [1, 2, 3] [99, 2, 3] > > OK, so far, so good. But: > > >>> a=[[1,2,3],[4,5,6],[7,8,9]] > >>> b=a[:] > >>> b[0][0]=99 > >>> print a > [[99, 2, 3], [4, 5, 6], [7, 8, 9]] > >>> print b > [[99, 2, 3], [4, 5, 6], [7, 8, 9]] > > i.e. a is reflecting the change made in b. > > However, the following does work as I expected: > >>> a=[[1,2,3],[4,5,6],[7,8,9]] > >>> b=a[:] > >>> b[0]=99 > >>> print a > [[1, 2, 3], [4, 5, 6], [7, 8, 9]] > >>> print b > [99, [4, 5, 6], [7, 8, 9]] > > Help, I'm a little confused, and I'd be grateful for an explanation. If > this were C I'd think it was a pointer problem...! > > Many thanks, > > Norman When you copy a by setting b = a[:] you get a copy of the first level only, since all items in the list a are new listobjects, all referenses in b point to the same lists as in a. When you do b[0] = 99 you set the first object in b to be a new object, thus not changing anything that has to do with a, but when you do b[0][0] = 99 you change the first element of the first element, and since the first element of a and b point at the same list, this is what happens. What you should check out is the copy module, specifically copy.deepcopy, that will do a full copy of everything in a. /Hakan - Hi! I'm a .signature virus! Copy me into your .signature file to help me spread! From karimy@nipltd.com Tue Oct 10 11:15:46 2000 From: karimy@nipltd.com (karim yaici) Date: Tue, 10 Oct 2000 11:15:46 +0100 Subject: [Tutor] Just to Hello to the folks, this message can be deleted ;-) Message-ID: <39E2EC52.E47F8265@nipltd.com> Hi there, Just to say that I am new to the list. I have started programming in Python a month ago and I haven't stopped since then 'cause I love, it is so simple, so abstract that you can do every thing you like in fewer lines.... I'll try to my best to answer some of your questions and I'll be greatful if evrybody does the same ;-) For a better world. Cheeers, ~Karim~ From arcege@shore.net Tue Oct 10 12:35:32 2000 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 10 Oct 2000 07:35:32 -0400 (EDT) Subject: [Tutor] stopping at 100 entries In-Reply-To: <31575A892FF6D1118F5800600846864D5B125F@intrepid> from "Simon Brunning" at Oct 10, 2000 08:35:14 AM Message-ID: <200010101135.HAA15615@northshore.shore.net> > > > From: Daniel Yoo [SMTP:dyoo@hkn.eecs.berkeley.edu] > > I was curious; is there a python module that, given a list of words and a > > misspelled word, returns back the "most similar" word? I do remember > > reading about an algorithm that would give the "distance" between two > > words, but I haven't found it in Parnassus. > > Daniel, > The algorithm that you want is called 'soundex'. I think that I remember a > soundex module at Parnassus, but I haven't tried it. The soundex module is included in the Python 1.5.2 and Python 1.6 distributions (I didn't check 2.0b2). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dyoo@hkn.eecs.berkeley.edu Tue Oct 10 17:08:21 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 10 Oct 2000 09:08:21 -0700 (PDT) Subject: [Tutor] Just to Hello to the folks, this message can be deleted ;-) In-Reply-To: <39E2EC52.E47F8265@nipltd.com> Message-ID: On Tue, 10 Oct 2000, karim yaici wrote: > Just to say that I am new to the list. I have started programming in > Python a month ago and I haven't stopped since then 'cause I love, it > is so simple, so abstract that you can do every thing you like in fewer > lines.... It's great to have you here. Welcome to the list! From alan.gauld@bt.com Tue Oct 10 17:21:59 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 10 Oct 2000 17:21:59 +0100 Subject: [Tutor] Copying lists of lists Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D374@mbtlipnt02.btlabs.bt.co.uk> > OK, so far, so good. But: > >>> a=[[1,2,3],[4,5,6],[7,8,9]] > >>> b=a[:] > >>> b[0][0]=99 > > However, the following does work as I expected: > >>> a=[[1,2,3],[4,5,6],[7,8,9]] > >>> b=a[:] > >>> b[0]=99 > If this were C I'd think it was a pointer problem...! It is a pointer problem. In python all variables are references(aka pointers) to the data. Thus a is a 'pointer' to a list of 'pointers' to sub lists. When you change b[0] you actually change what b[0] points at whereas when you change b[0][0] the b[0] pointer stays the same (ie the value shared with a[0]). You need to do a deepcopy of the lists to avoid this completely. (I think I saw a deepcopy function or module somewhere, if not it's fairly easy to write - esecially if you use recursion) Alan G. From nicolas.baurin@univ-orleans.fr Tue Oct 10 17:45:29 2000 From: nicolas.baurin@univ-orleans.fr (nicolas baurin) Date: Tue, 10 Oct 2000 18:45:29 +0200 Subject: [Tutor] Output of os.system("c:\myprog.exe") "piped" to a python object ? Message-ID: <39E347A8.1B56EB6C@univ-orleans.fr> Hello to everybody, clearly i'm using os.system() to launch an external program ;i have to "redirect" what comes into the console (standard output of the external program) towards a python object: sys.stdout is not enough since it's applying to the python interpretor... Merci d'avances et bonne soirée, -- Nicolas Baurin Doctorant Institut de Chimie Organique et Analytique, UPRES-A 6005 http://www.univ-orleans.fr/SCIENCES/ICOA/ Université d'Orléans, BP 6759 45067 ORLEANS Cedex 2, France Tel: (33+) 2 38 49 45 77 From DOUGS@oceanic.com Tue Oct 10 18:04:33 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Tue, 10 Oct 2000 07:04:33 -1000 Subject: [Tutor] Output of os.system("c:\myprog.exe") "piped" to a pyt hon object ? Message-ID: <8457258D741DD411BD3D0050DA62365907A38A@huina.oceanic.com> Hi, You don't indicate what platform you are running on. The answer is = somewhat palatform dependant, but what you are looking for is popen() for "pipe open". If you are on a Unix system it and its cousins, popen2() and popen3() work reliably. On Windows there is a solution in the win32all extensions by Mark Hammond. I don't have any experience with it, but = know that it is named similarly. Good luck, -Doug- If you need it and don't have it win32all is available from: http://www.activestate.com/Products/ActivePython/win32all.html > -----Original Message----- > From: nicolas baurin [mailto:nicolas.baurin@univ-orleans.fr] > Sent: Tuesday, October 10, 2000 6:45 AM > To: tutor@python.org > Subject: [Tutor] Output of os.system("c:\myprog.exe") "piped" to a > python object ? >=20 >=20 > Hello to everybody, >=20 > clearly i'm using os.system() to launch an external program=20 > ;i have to > "redirect" what comes into the console (standard output of=20 > the external > program) towards a python object: sys.stdout is not enough since = it's > applying to the python interpretor... >=20 > Merci d'avances et bonne soir=E9e, >=20 > -- > Nicolas Baurin >=20 > Doctorant > Institut de Chimie Organique et Analytique, UPRES-A 6005 > http://www.univ-orleans.fr/SCIENCES/ICOA/ > Universit=E9 d'Orl=E9ans, BP 6759 > 45067 ORLEANS Cedex 2, France > Tel: (33+) 2 38 49 45 77 >=20 >=20 >=20 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor >=20 From marcel@punto.it Tue Oct 10 18:23:59 2000 From: marcel@punto.it (Marcel Preda) Date: Tue, 10 Oct 2000 19:23:59 +0200 (CEST) Subject: [Tutor] Output of os.system("c:\myprog.exe") "piped" to a python object ? In-Reply-To: <39E347A8.1B56EB6C@univ-orleans.fr> Message-ID: On Tue, 10 Oct 2000, nicolas baurin wrote: > Hello to everybody, >=20 > clearly i'm using os.system() to launch an external program ;i have to > "redirect" what comes into the console (standard output of the external > program) towards a python object: sys.stdout is not enough since it's > applying to the python interpretor... >=20 > Merci d'avances et bonne soir=E9e, On Unix you can use `popen' like that: #!/usr/local/python2.0/bin/python import os fileObj=3Dos.popen('/bin/ls') a=3D1 raw_input("will print the result (after Enter):") while (a): a=3DfileObj.readline() print a I dont have here a Win to tel you more about this, look at the popen2 module, if popen don't work... PM From deirdre@deirdre.net Tue Oct 10 18:36:29 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 10 Oct 2000 10:36:29 -0700 (PDT) Subject: [Tutor] Output of os.system("c:\myprog.exe") "piped" to a python object ? In-Reply-To: <39E347A8.1B56EB6C@univ-orleans.fr> Message-ID: On Tue, 10 Oct 2000, nicolas baurin wrote: > clearly i'm using os.system() to launch an external program ;i have to > "redirect" what comes into the console (standard output of the > external program) towards a python object: sys.stdout is not enough > since it's applying to the python interpretor... why not use commands.getoutput() ? -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "More damage has been caused by innocent program crashes than by malicious viruses, but they don't make great stories." -- Jean-Louis Gassee, Be Newsletter, Issue 69 From tourinho@descartes.ucpel.tche.br Tue Oct 10 18:50:45 2000 From: tourinho@descartes.ucpel.tche.br (Gustavo Passos Tourinho) Date: Tue, 10 Oct 2000 14:50:45 -0300 (EST) Subject: [Tutor] Python + Zope Message-ID: Hi all. Im starting with zope and would like to know if anybody knows a book or links about it. Anything about programming zope. Thanks for any help From marcel@punto.it Tue Oct 10 19:05:53 2000 From: marcel@punto.it (Marcel Preda) Date: Tue, 10 Oct 2000 20:05:53 +0200 (CEST) Subject: [Tutor] Python + Zope In-Reply-To: Message-ID: On Tue, 10 Oct 2000, Gustavo Passos Tourinho wrote: > > Hi all. > > Im starting with zope and would like to know if anybody knows a book or > links about it. > > Anything about programming zope. > > Thanks for any help of course www.zope.org, look to Documentation Very useful is `zope' mailing list http://lists.zope.org/mailman/listinfo/zope a zope-list archive http://zope.nipltd.com/public/lists/zope-archive.nsf/ PM From hkaplan@itecorp.com Tue Oct 10 19:11:32 2000 From: hkaplan@itecorp.com (Harvey Kaplan) Date: Tue, 10 Oct 2000 11:11:32 -0700 Subject: [Tutor] IF GOOD @ OOP Will $ to train PYTHON Message-ID: Senior Software Test Automation Engineer Senior software development engineer responsible for defining various test automation strategies, test automation plans, and implementing test automation using state of the art automation techniques for intelligent carrier-class, all photonic switch and associated network management platform (NMS/EMS). Job Description: Senior contracting role co-designing and developing various automation test tools and systems test tools to test and validate a photonic switching system and related network management and element management systems (NMS/EMS). The test automation systems are used to test the system under test (SUT) for high availability environment. Responsible for automating regression test suites for continuous systems regression testing phase. Develop Craft Interface Terminal (GUI based) and EMS (Element Management System) test tools. Requirements (firm): · BSCS/BSEE with 4 years of experience or MSCS/MSEE with 2 years in software development, developing test automation software for embedded systems. · Proficiency with testing methodology and tools for GUI based UNIX Systems. · Analysis, debugging, and fault isolation skills · Background in Object Oriented Methodology. · Good organizational and interpersonal skills and ability to work effectively across organizations. Desirable Skills and Experience · Any Python experience · CORBA · VxWorks · SNMP · Understanding of SONET and Optical Network Technology · Knowledge of TL1 and Bellcore standards Best Regards, Harvey Kaplan Technical Recruiter IT&E Corporation. 111 N. Market Street San Jose, CA 95113 Ph: 408-938-1000 800-707-0985 Fx: 408-947-1816 From sburch@ordway.org Tue Oct 10 19:08:53 2000 From: sburch@ordway.org (Burchill, Scott B.) Date: Tue, 10 Oct 2000 13:08:53 -0500 Subject: [Tutor] Python + Zope Message-ID: I'm having fun with tutorials from http://www.beehive.de. > -----Original Message----- > From: Gustavo Passos Tourinho > > Im starting with zope and would like to know if anybody knows a book or > links about it. > From wilson@visi.com Tue Oct 10 23:25:27 2000 From: wilson@visi.com (Timothy Wilson) Date: Tue, 10 Oct 2000 17:25:27 -0500 (CDT) Subject: [Tutor] clearing the screen Message-ID: Hi everyone, I'm writing a little hangman program for practice. I'd like to clear the screen after each guess so things don't get too cluttered. Am I correct in assuming that that's OS specific? I'm on Linux, so is it something in the os module? Is there a cross-platform solution? -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 lgwb@no_spam.home.com Wed Oct 11 03:05:54 2000 From: lgwb@no_spam.home.com (Michael Schmitt) Date: Tue, 10 Oct 2000 21:05:54 -0500 Subject: forthcoming book on Zope - Re: [Tutor] Python + Zope Message-ID: <004201c03327$c9ac3060$0a0a0a0a@c175700-a.mntp1.il.home.com> Check out http://www.zope.org/Members/michel/ZB/ This is an early draft chapter from a forthcoming book on Zope, to be published by O'Reilly & Associates. -----Original Message----- From: Gustavo Passos Tourinho To: tutor@python.org Date: Tuesday, October 10, 2000 1:18 PM Subject: [Tutor] Python + Zope > >Hi all. > >Im starting with zope and would like to know if anybody knows a book or >links about it. > >Anything about programming zope. > >Thanks for any help > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://www.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Wed Oct 11 03:14:06 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 10 Oct 2000 19:14:06 -0700 (PDT) Subject: [Tutor] IF GOOD @ OOP Will $ to train PYTHON In-Reply-To: Message-ID: Dear Harvey, I'm sure you meant well; however, you're contacting the wrong mailing list. This is purely a tutoring forum. Instead, you may want to email job postings to jobs@python.org or visit: http://python.org/Jobs.html which has more details. I hope this helps. From dyoo@hkn.eecs.berkeley.edu Wed Oct 11 03:22:31 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 10 Oct 2000 19:22:31 -0700 (PDT) Subject: [Tutor] clearing the screen In-Reply-To: Message-ID: On Tue, 10 Oct 2000, Timothy Wilson wrote: > I'm writing a little hangman program for practice. I'd like to clear the > screen after each guess so things don't get too cluttered. Am I correct in > assuming that that's OS specific? I'm on Linux, so is it something in the os > module? Is there a cross-platform solution? Hmmm... What you're asking is a little os-specific. I think you can use the curses module to get at all the Unix platforms: http://python.org/doc/current/lib/module-curses.html Curses gives you terminal independent access to the screen, which is nice. However, I don't have experience with it, but the page above has a link to tutorial material. However, I'm ignorant on how to do terminal control in Windows. Hope this helps! From nicolas.baurin@univ-orleans.fr Wed Oct 11 10:36:09 2000 From: nicolas.baurin@univ-orleans.fr (nicolas baurin) Date: Wed, 11 Oct 2000 11:36:09 +0200 Subject: [Tutor] simultaneous pipe of stdout and stdin of an external program towards python object ? Message-ID: <39E43486.9B89BAD@univ-orleans.fr> Hello people, first i'm working under NT: well i succeed in piping the stdout of my external program towards my python object self.log: pipeout=win32pipe.popen("c:\myprog.exe","r") a=1 while a: a=pipeout.readline() self.log.WriteText(a) Now i'm working on piping the stdin of this same program to this same object (a text window) : i tryed (pipein,pipeout)=win32pipe.popen2("c:\myprog.exe","t") but don't know how to handle it the same way i managed pipeout above(pipeout.readline()). More, i suspect i have to deal with 2 handles : -"pipeout" to link what's inside towards self.log until it ends -"pipein" to link what i put in self.log towards pipein , when pipeout is waiting for pipein Hope i'm clear, Merci d'avances, P.S: Thansk to all of you who link me to this first step =;) -- Nicolas Baurin Doctorant Institut de Chimie Organique et Analytique, UPRES-A 6005 http://www.univ-orleans.fr/SCIENCES/ICOA/ Université d'Orléans, BP 6759 45067 ORLEANS Cedex 2, France Tel: (33+) 2 38 49 45 77 From claudia_dallas@yahoo.com Wed Oct 11 15:07:41 2000 From: claudia_dallas@yahoo.com (claudia flores) Date: Wed, 11 Oct 2000 07:07:41 -0700 (PDT) Subject: [Tutor] Help! Message-ID: <20001011140741.18452.qmail@web3903.mail.yahoo.com> I have a question, i have no idea how to program at all!!! if anyone has any links where i can turn to i would greatly appreciate it , or any books i can turn to!!! __________________________________________________ Do You Yahoo!? Get Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ From scarblac@pino.selwerd.nl Wed Oct 11 15:25:22 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 11 Oct 2000 16:25:22 +0200 Subject: [Tutor] Help! In-Reply-To: <20001011140741.18452.qmail@web3903.mail.yahoo.com>; from claudia_dallas@yahoo.com on Wed, Oct 11, 2000 at 07:07:41AM -0700 References: <20001011140741.18452.qmail@web3903.mail.yahoo.com> Message-ID: <20001011162522.A27558@pino.selwerd.nl> On Wed, Oct 11, 2000 at 07:07:41AM -0700, claudia flores wrote: > I have a question, i have no idea how to program at all!!! if anyone has > any links where i can turn to i would greatly appreciate it , or any books > i can turn to!!! There are a few tutorials out there for people completely new to programming. Your best bet would be to play with some of those and see how you do. Links: http://members.xoom.com/alan_gauld/tutor/tutindex.htm By Alan Gauld, he is on this list too. I get no reply at the moment, is it down? http://www.honors.montana.edu/~jjc/easytut/easytut/ Looks bare and technical but really explains everything well. http://www.idi.ntnu.no/~mlh/python/programming.html This one is pretty short. If you have problems with the tutorials, this is a good place to ask. Hopefully you are already comfortable *using* your computer - you'll need to download and install some software, use a text editor, that sort of thing. Have fun :) Remco Gerlich From nicolas.baurin@univ-orleans.fr Wed Oct 11 16:12:58 2000 From: nicolas.baurin@univ-orleans.fr (nicolas baurin) Date: Wed, 11 Oct 2000 17:12:58 +0200 Subject: [Tutor] hide the interpretor window & sleep process under NT-Linux ? Message-ID: <39E4837A.5C9F138D@univ-orleans.fr> Hello again, i'm seeking for how and where to do to hide the interpretor window when launching my script Second what should i do to sleep a process that i launch with a system.os() command and wake it up later Thanks in advance, -- Nicolas Baurin Doctorant Institut de Chimie Organique et Analytique, UPRES-A 6005 http://www.univ-orleans.fr/SCIENCES/ICOA/ Université d'Orléans, BP 6759 45067 ORLEANS Cedex 2, France Tel: (33+) 2 38 49 45 77 From alan.gauld@bt.com Wed Oct 11 17:19:41 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 11 Oct 2000 17:19:41 +0100 Subject: [Tutor] clearing the screen Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D379@mbtlipnt02.btlabs.bt.co.uk> > I'm writing a little hangman program for practice. After the obligatory plug: My forthcoming book has a case study on writing a hangman game for both text and GUI modes. > I'd like to clear the screen after each guess so things don't get too cluttered. Am > I correct in assuming that that's OS specific? Yes, although you can do a platform independant version which is horrible - just write a loop that scrolls the text off the screen! > I'm on Linux, Try the simplest solution first: os.system("clear") Next easiest: You can use curses but it isn't there on windows by default. If you know the terminal type you can write the escape codes to stdout, which is probably better but much more difficult(unless you like getting into reading termcap databases etc....) Alan g. From alan.gauld@bt.com Wed Oct 11 17:26:09 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 11 Oct 2000 17:26:09 +0100 Subject: [Tutor] Help! Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D37A@mbtlipnt02.btlabs.bt.co.uk> > Links: > http://members.xoom.com/alan_gauld/tutor/tutindex.htm > By Alan Gauld, he is on this list too. I get no reply at the moment, > is it down? Xoom have been taken over by NBCI, their service has been getting unreliable and they insist on sticking adverts everywhere. But that site is now stagnant and the latest version of the tutor is on: http://www.crosswinds.net/~agauld/ There is a Spanish version there too (all but the Case Study) I hope to have a Dutch version soon too. Also I am in the process of updating it with material from my book. The data chapter is almost done (this weekend?). Others will follow. Alan G. From chetumal23@excite.com Wed Oct 11 21:24:52 2000 From: chetumal23@excite.com (john smith smith) Date: Wed, 11 Oct 2000 13:24:52 -0700 (PDT) Subject: [Tutor] which version Message-ID: <26726290.971295892872.JavaMail.imail@doby.excite.com> i am a newbie and was just about to download python when i noticed that there are a number of versions.which version is the best for a newbie. _______________________________________________________ Say Bye to Slow Internet! http://www.home.com/xinbox/signup.html From deirdre@deirdre.net Wed Oct 11 21:24:19 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 11 Oct 2000 13:24:19 -0700 (PDT) Subject: [Tutor] which version In-Reply-To: <26726290.971295892872.JavaMail.imail@doby.excite.com> Message-ID: On Wed, 11 Oct 2000, john smith smith wrote: > i am a newbie and was just about to download python when i noticed that > there are a number of versions.which version is the best for a newbie. I'd get the latest released version (versus any marked development or beta). -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "More damage has been caused by innocent program crashes than by malicious viruses, but they don't make great stories." -- Jean-Louis Gassee, Be Newsletter, Issue 69 From parkw@better.net Wed Oct 11 21:30:44 2000 From: parkw@better.net (William Park) Date: Wed, 11 Oct 2000 16:30:44 -0400 Subject: [Tutor] which version In-Reply-To: <26726290.971295892872.JavaMail.imail@doby.excite.com>; from chetumal23@excite.com on Wed, Oct 11, 2000 at 01:24:52PM -0700 References: <26726290.971295892872.JavaMail.imail@doby.excite.com> Message-ID: <20001011163044.A1470@better.net> On Wed, Oct 11, 2000 at 01:24:52PM -0700, john smith smith wrote: > i am a newbie and was just about to download python when i noticed that > there are a number of versions.which version is the best for a newbie. Python2.0 is about to released. So, wait few days. As for which version for newbie... they are all same. ---William Park, Open Geometry Consulting From dsh8290@rit.edu Wed Oct 11 23:29:40 2000 From: dsh8290@rit.edu (D-Man) Date: Wed, 11 Oct 2000 18:29:40 -0400 Subject: [Tutor] which version In-Reply-To: <26726290.971295892872.JavaMail.imail@doby.excite.com>; from chetumal23@excite.com on Wed, Oct 11, 2000 at 16:24:52 -0400 References: <26726290.971295892872.JavaMail.imail@doby.excite.com> Message-ID: <20001011182940.E14026@dman.rh.rit.edu> Version 1.5.2 is stable and has been around for quite a while. Version 1.6 has recently been released, but I don't know too much about it. Version 2.0 has had several beta/preview releases and will have a final release soon as someone else mentioned. If I were you, I'd wait a few days for version 2.0 to be released to start. -D On Wed, 11 Oct 2000 16:24:52 john smith smith wrote: > i am a newbie and was just about to download python when i noticed that > there are a number of versions.which version is the best for a newbie. > > > > > > _______________________________________________________ > Say Bye to Slow Internet! > http://www.home.com/xinbox/signup.html > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From karimy@nipltd.com Thu Oct 12 13:51:29 2000 From: karimy@nipltd.com (karim yaici) Date: Thu, 12 Oct 2000 13:51:29 +0100 Subject: [Tutor] Test File Uploading using urllib Message-ID: <39E5B3D1.48703A75@nipltd.com> Hi guys, I 'll probably nedd some help on this one or at least few advices. So let me explain you what I am trying to do. I am trying to write kinda testing system (with Python of course!). let's say I have a form with many input fields and a submit button. I want to test if the date that have been provided get added to the database. Instead of going to the web page and type in your data, I used a method "urlpost()" to POST my data to the web page.Basically urlpost has 2 args: (target_URL, dictionary), the dictioanry is of the type {var:value},then it constructs a new url similar to the CGI one "target_URL?var1=val1&var2=val2....etc" and the end I have only to provide the dict* and loop... Fine so far! but what if I want to test that a file get uploaded (for intance, if I had an upload button), I don't think I can POST a file in the same manner as the other inputs, I'll probably have to use a different method with the files.... If someone has got the slightiest idea on where to look or (better!)what to do,I'll be really thankful. Cheers ~Karim~ aka Zinou From DimiVerstraeten@postmaster.co.uk Thu Oct 12 20:05:12 2000 From: DimiVerstraeten@postmaster.co.uk (Dimitri Verstraeten) Date: Thu, 12 Oct 2000 20:05:12 +0100 Subject: [Tutor] Port for Windows 2000 Message-ID: Is Python (version 1.5.2) portable to Windows 2000 (or Windows ME) for that matter ? Are there any drawbacks or problems ? From Nate Bargmann Thu Oct 12 21:25:32 2000 From: Nate Bargmann (Nate Bargmann) Date: Thu, 12 Oct 2000 15:25:32 -0500 Subject: [Tutor] OT Text size in IDLE on Linux Message-ID: <20001012152532.A554@nomad.n0nb.ampr.org> Hello all. I've asked this on the newsgroup and the best response I received was to use the CVS version of Python! I'm using a laptop which has a display locked to 1024x768. The default text in IDLE is quite small (8 pt I think) and even my relatively young eyes are having a tough go at it at times. How might I tell IDLE or Tkinter to enlarge the text? I am using IDLE 0.5 with Python 1.5.2 on Debian GNU/Linux 2.2. All help is appreciated. - Nate >> -- Wireless | Amateur Radio Station N0NB | "None can love freedom Internet | n0nb@networksplus.net | heartily, but good Location | Wichita, Kansas USA EM17hs | men; the rest love not Wichita area exams; ham radio; Linux info @ | freedom, but license." http://www.qsl.net/n0nb/ | -- John Milton From tutor@python.org Thu Oct 12 22:54:12 2000 From: tutor@python.org (Tim Peters) Date: Thu, 12 Oct 2000 17:54:12 -0400 Subject: [Tutor] Port for Windows 2000 In-Reply-To: Message-ID: [Dimitri Verstraeten] > Is Python (version 1.5.2) portable to Windows 2000 (or Windows > ME) for that matter ? The same Windows installer for Python works on Windows 95, 98, ME, NT and 2000. Not CE. If you're going to use 1.5.2 or 1.6, you'll need administrator privileges to install on NT or 2000; in Python 2.0 (currently in final release testing; http://www.pythonlabs.com/) you do not. > Are there any drawbacks or problems ? Sure! For one, you'll be using Windows . Seriously, your question is too broad to even guess at what you're concerned about. Be more specific, if you can. From Mailer-Daemon@kaplan.com Fri Oct 13 01:54:06 2000 From: Mailer-Daemon@kaplan.com (Mailer-Daemon) Date: Thu, 12 Oct 2000 17:54:06 -0700 Subject: NDN: RE: [Tutor] Port for Windows 2000 Message-ID: Sorry. Your message could not be delivered to: matthew hand,Home Office (The name was not found at the remote site. Check that the name has been entered correctly.) From dyoo@hkn.eecs.berkeley.edu Fri Oct 13 05:21:50 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 12 Oct 2000 21:21:50 -0700 (PDT) Subject: [Tutor] OT Text size in IDLE on Linux In-Reply-To: <20001012152532.A554@nomad.n0nb.ampr.org> Message-ID: On Thu, 12 Oct 2000, Nate Bargmann wrote: > I've asked this on the newsgroup and the best response I received was > to use the CVS version of Python! I'm using a laptop which has a display > locked to 1024x768. The default text in IDLE is quite small (8 pt I > think) and even my relatively young eyes are having a tough go at it > at times. How might I tell IDLE or Tkinter to enlarge the text? I > am using IDLE 0.5 with Python 1.5.2 on Debian GNU/Linux 2.2. All help is > appreciated. If you have access to EditorWindow.py in the IDLE source directory, look around on line 130: if sys.platform[:3] == 'win': text['font'] = ("lucida console", 8) Note: that's how they set it for the window console. However, IDLE's just depending on the default for the linux side. Let's change the default: if sys.platform[:3] == 'win': text['font'] = ("lucida console", 8) text['font'] = ("fixed", 20) # Added by dyoo If we manually set the font, it should be much more readable. Note: I just did this to make it work; I know this is bad, since we're hardcoding the font. The CVS version, I'm guessing, adds a menu option to do this font changing, so you don't have to muck through code like we just did. Anyway, hope this helps! From DimiVerstraeten@postmaster.co.uk Fri Oct 13 08:49:33 2000 From: DimiVerstraeten@postmaster.co.uk (Dimitri Verstraeten) Date: Fri, 13 Oct 2000 08:49:33 +0100 Subject: [Tutor] Port for Windows 2000 Message-ID: Maybe a bad choice of words. What I meant was : does Python (the built-in modules, IDLE...) work correctly under Windows 2000 ? -- Dimitri Verstraeten Velle 6 9140 Temse Tel. (03) 711.05.94 From tutor@python.org Fri Oct 13 09:13:17 2000 From: tutor@python.org (Tim Peters) Date: Fri, 13 Oct 2000 04:13:17 -0400 Subject: [Tutor] Port for Windows 2000 In-Reply-To: Message-ID: [Dimitri Verstraeten] > Maybe a bad choice of words. What I meant was : does Python (the > built-in modules, IDLE...) work correctly under Windows 2000 ? Yes! We have a report of the brand-spanking new mmap module failing on Windows ME, and that's the grand total of all outstanding failures in the std Python test suite across all flavors of Windows, excepting CE (there's a Python port for CE too, but it's not mainstream & I never hear anything about it). Python even runs fine on Win64, but unless you're a special friend of Intel's you can't get that yet . There's one other problem, but it's not Python's fault: if you call Python's os.popen() function under Windows 98 and have Norton AntiVirus version 6.10.20 running in auto-protect mode, your machine will freeze after a blue-screen crash. This also happens if you call Microsoft's popen directly from C code (that is, Python has nothing to do with this, but it can *look* like Python's doing). Symantec says they're not going to fix it, and recommends that users buy a newer version of NAV. And that's the level of Python Windows bugs -- rare and obscure as hell. From Mailer-Daemon@kaplan.com Fri Oct 13 12:12:49 2000 From: Mailer-Daemon@kaplan.com (Mailer-Daemon) Date: Fri, 13 Oct 2000 04:12:49 -0700 Subject: NDN: RE: RE: [Tutor] Port for Windows 2000 Message-ID: Sorry. Your message could not be delivered to: matthew hand,Home Office (The name was not found at the remote site. Check that the name has been entered correctly.) From dyoo@hkn.eecs.berkeley.edu Fri Oct 13 09:35:56 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 13 Oct 2000 01:35:56 -0700 (PDT) Subject: [Tutor] Port for Windows 2000 In-Reply-To: Message-ID: On Fri, 13 Oct 2000, Dimitri Verstraeten wrote: > Maybe a bad choice of words. What I meant was : does Python (the > built-in modules, IDLE...) work correctly under Windows 2000 ? Hello! I've had no problems at all with Win2k and Python. I believe they work very nicely; of course, I'm not too much of a Windows user, so you might want to ask other people. As far as I've heard, there aren't any outstanding compatibility issues. From ChristopherNolen@aol.com Fri Oct 13 17:22:36 2000 From: ChristopherNolen@aol.com (ChristopherNolen@aol.com) Date: Fri, 13 Oct 2000 12:22:36 EDT Subject: [Tutor] count Message-ID: <7c.c1390de.271890cc@aol.com> When I run this the last 'print' in the while block prints even when the correct password is entered. I thought the lines in the while block only executed if the while constraints were met. How would I make the last print not show when the proper pasword is entered?thanks cmn count = 0 print "Halt!" input = raw_input("Who goes there? ") while input != "Chris": print "Please move away from my machine!",input,"!!" input = raw_input("Who goes there? ") count = count + 1 print "You have fondled my keys",count,"too many times!" print "Chris, an erroneous password was entered",count,"times!" print "WELCOME TO THE MACHINE, MASTER!" From arcege@shore.net Fri Oct 13 17:43:42 2000 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 13 Oct 2000 12:43:42 -0400 (EDT) Subject: [Tutor] count In-Reply-To: <7c.c1390de.271890cc@aol.com> from "ChristopherNolen@aol.com" at Oct 13, 2000 12:22:36 PM Message-ID: <200010131643.MAA20109@northshore.shore.net> > > When I run this the last 'print' in the while block prints even when the > correct password is entered. I thought the lines in the while block only > executed if the while constraints were met. How would I make the last print > not show when the proper pasword is entered?thanks cmn > > > count = 0 > print "Halt!" > input = raw_input("Who goes there? ") > while input != "Chris": > print "Please move away from my machine!",input,"!!" > input = raw_input("Who goes there? ") > count = count + 1 > print "You have fondled my keys",count,"too many times!" > print "Chris, an erroneous password was entered",count,"times!" > print "WELCOME TO THE MACHINE, MASTER!" The common idiom for this kind of loop is to have the raw_input at the end of the loop: input = raw_input("Who goes there? ") while input != "Chris": count = count + 1 if count > 1: print "You have fondled my keys", count, "too many times!" print "Please move away from my machine!", input, "!!" input = raw_input("Who goes there? ") print "Chris, ... This probably does what you want. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From devanshd@yahoo.com Sun Oct 15 04:00:00 2000 From: devanshd@yahoo.com (Devansh) Date: Sat, 14 Oct 2000 22:00:00 -0500 Subject: [Tutor] Need help in python Message-ID: <00ee01c03654$023d52e0$771511ac@wartburg.edu> This is a multi-part message in MIME format. ------=_NextPart_000_00EB_01C0362A.19135E80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable hi everyone... i m a new student at a college and need some help using python.... this is regarding the "open" command...... here is a section of my code... # open file and read input_file=3Dopen("p7.dat","r") heating_degree_days=3D0 cooling_degree_days=3D0 #loop statement & conditions for i in range(31): temp=3Deval(input_file.readline()) if temp < 60: heating_degree_days=3D(60-temp)+heating_degree_days if temp > 80: cooling_degree_days=3Dtemp-80+cooling_degree_days nothing seems wrong rite? well when i try to run this module from within = python it gives me an IO error saying Traceback (innermost last): File "", line 1, in ? File "C:\WINDOWS\Desktop\Python Test programs\number20.py", line 38, = in ? main() File "C:\WINDOWS\Desktop\Python Test programs\number20.py", line 17, = in main input_file=3Dopen("p7.dat","r") IOError: [Errno 2] No such file or directory: 'p7.dat' but then when i run the program in DOS...it runs perfectly fine.....the = dat. file is in the same directory as the module file.... pls help....need it urgently. Devansh Dhutia P.O.Box 105 222 Ninth St. N.W. Waverly, Iowa 50677-0903 Tel: 319-352-7302 @ : dhutiad@wartburg.edu devanshd@yahoo.com ICQ UIN- 5674041 ------=_NextPart_000_00EB_01C0362A.19135E80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
hi everyone...
 
i m a new student at a college and need = some help=20 using python....
this is regarding the "open"=20 command......
 
here is a section of my = code...
# open file and read
 
   =20 input_file=3Dopen("p7.dat","r")
   =20 heating_degree_days=3D0
    = cooling_degree_days=3D0
 
    #loop statement = &=20 conditions
 
    for i in=20 range(31):
       =20 temp=3Deval(input_file.readline())
      = ; =20 if temp <=20 60:
           = =20 heating_degree_days=3D(60-temp)+heating_degree_days
   =     =20 if temp >=20 80:
           = =20 cooling_degree_days=3Dtemp-80+cooling_degree_days
 
nothing seems wrong rite? well when i = try to run=20 this module from within python it gives me an IO error = saying
 
Traceback (innermost last):
  = File=20 "<string>", line 1, in ?
  File "C:\WINDOWS\Desktop\Python = Test=20 programs\number20.py", line 38, in ?
    = main()
  File=20 "C:\WINDOWS\Desktop\Python Test programs\number20.py", line 17, in=20 main
    input_file=3Dopen("p7.dat","r")
IOError: = [Errno 2]=20 No such file or directory: 'p7.dat'
but then when i run the program in = DOS...it runs=20 perfectly fine.....the dat. file is in the same directory as the module=20 file....
pls help....need it = urgently.
 
 
Devansh Dhutia
P.O.Box 105
222 = Ninth St.=20 N.W.
Waverly, Iowa 50677-0903
Tel: 319-352-7302
@ : dhutiad@wartburg.edu
 &n= bsp;    =20 devanshd@yahoo.com
ICQ UIN- = 5674041
------=_NextPart_000_00EB_01C0362A.19135E80-- _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From deirdre@deirdre.net Sat Oct 14 04:52:52 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 13 Oct 2000 20:52:52 -0700 (PDT) Subject: [Tutor] Need help in python In-Reply-To: <00ee01c03654$023d52e0$771511ac@wartburg.edu> Message-ID: On Sat, 14 Oct 2000, Devansh wrote: > but then when i run the program in DOS...it runs perfectly > fine.....the dat. file is in the same directory as the module file.... > pls help....need it urgently. If you specified the full path in the open statement, that should fix the problem. That said, I don't know Windows, so it's only a guess. :) -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From dyoo@hkn.eecs.berkeley.edu Sat Oct 14 07:20:45 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 13 Oct 2000 23:20:45 -0700 (PDT) Subject: [Tutor] Need help in python In-Reply-To: <00ee01c03654$023d52e0$771511ac@wartburg.edu> Message-ID: On Sat, 14 Oct 2000, Devansh wrote: > nothing seems wrong rite? well when i try to run this module from within python it gives me an IO error saying > > Traceback (innermost last): > File "", line 1, in ? > File "C:\WINDOWS\Desktop\Python Test programs\number20.py", line 38, in ? > main() > File "C:\WINDOWS\Desktop\Python Test programs\number20.py", line 17, in main > input_file=open("p7.dat","r") > IOError: [Errno 2] No such file or directory: 'p7.dat' > > but then when i run the program in DOS...it runs perfectly fine.....the dat. file is in the same directory as the module file.... > pls help....need it urgently. I can't think of anything offhand. Can you Check the capitalization of the file? Unix can be very case-sensitive, so make sure that it's p7.dat, and not P7.DAT. From FxItAL@aol.com Mon Oct 16 11:44:32 2000 From: FxItAL@aol.com (FxItAL@aol.com) Date: Mon, 16 Oct 2000 06:44:32 EDT Subject: [Tutor] Threads & Memory Message-ID: <22.c81cf83.271c3610@aol.com> Hello All, I've written a small timer program that uses two threads to display the current time and continuously compares the actual time to the time set for the alarm. While running this program it seems to slow down any other applications that I'm running at the time. I don't know if this makes a differance but I have not compiled this into a stand alone as yet. If this is a memory managment issue please elaborate in detail as I'm new to programming in general. Python 1.5.2 on Windows 95 on a 233 processor with 64 Mgs of RAM. Thanks for your time, Al From alan.gauld@bt.com Mon Oct 16 11:14:43 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Oct 2000 11:14:43 +0100 Subject: [Tutor] Need help in python Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D386@mbtlipnt02.btlabs.bt.co.uk> > i m a new student at a college and need some help using python.... > this is regarding the "open" command...... > > here is a section of my code... > # open file and read > > input_file=open("p7.dat","r") > nothing seems wrong rite? well when i try to run this module > from within python it gives me an IO error saying > IOError: [Errno 2] No such file or directory: 'p7.dat' I assume that 'from within python' means from IDLE? If so I think IDLE will look for the file in its own directory. Try providing the full path to the file. > but then when i run the program in DOS Were you sitting in the same directory as the file by any chance? Alan G. From DanielKOBRIEN@culford.suffolk.sch.uk Mon Oct 16 17:10:11 2000 From: DanielKOBRIEN@culford.suffolk.sch.uk (DanielKOBRIEN) Date: Mon, 16 Oct 2000 17:10:11 +0100 Subject: [Tutor] (no subject) Message-ID: <16095809302189@culford.suffolk.sch.uk> How do I start to learn how to programme a computer- I have found the website www.python.org.... very confusing. Please reply to danielkobrien@culford.suffolk.sch.uk thanks Daniel From dyoo@hkn.eecs.berkeley.edu Mon Oct 16 17:33:37 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 16 Oct 2000 09:33:37 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: <16095809302189@culford.suffolk.sch.uk> Message-ID: On Mon, 16 Oct 2000, DanielKOBRIEN wrote: > How do I start to learn how to programme a computer- I have found the > website www.python.org.... very confusing. Please reply to > danielkobrien@culford.suffolk.sch.uk Nice to meet you, Daniel. Hmm... same first name... *grin* The page is slightly complicated, but that's because it links to almost everything Python related. For now, you'll want to visit the Introductions section on the Python web site: http://python.org/doc/Intros.html In particular, the "Introductions to Python programming for non-programmers" section is good to go through. Unless you're already familiar with programming, DO NOT look at the official tutorial at: http://python.org/doc/current/tut/tut.html because it's a whirlwind tour of the language. Instead, try something gentle like: Alan Gauld's "Learning to Program": http://members.nbci.com/alan_gauld/tutor/tutindex.htm or Josh Cogliati's "A Nonprogrammers Tutorial for Python" http://www.honors.montana.edu/~jjc/easytut/easytut/ Both of those tutorials are very good. Also, I believe the authors of those tutorials listen in on this mailing list! If you have any questions, don't hesitate in sending your questions our way. Good luck! From karimy@nipltd.com Mon Oct 16 17:37:14 2000 From: karimy@nipltd.com (karim yaici) Date: Mon, 16 Oct 2000 17:37:14 +0100 Subject: [Tutor] (no subject) References: <16095809302189@culford.suffolk.sch.uk> Message-ID: <39EB2EB9.42633903@nipltd.com> Hi, Asking to learn how to programme is a very broad question. I assume you want to start with Python 'cause it's easy and fun ;-) I suggest you have a look at the following: -> http://www.honors.montana.edu/~jjc/easytut/easytut/ (intro to Python) -> http://members.nbci.com/alan_gauld/tutor/tutindex.htm (for Python mewbies) I hope it's gonna help you. The other guys in the list might give you a hint as well (so watch you mailbox ;-) ), Cheers, Karim > How do I start to learn how to programme a computer- I have found the > website www.python.org.... very confusing. Please reply to > danielkobrien@culford.suffolk.sch.uk > thanks > Daniel > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From rod.gray@va.prestige.net Mon Oct 16 17:39:01 2000 From: rod.gray@va.prestige.net (Rod Gray) Date: Mon, 16 Oct 2000 12:39:01 -0400 Subject: [Tutor] (no subject) References: <16095809302189@culford.suffolk.sch.uk> Message-ID: <001301c0378f$aa6a0620$4c1daccf@imp.rcn.net> Go to this link...I found it very helpful. http://members.nbci.com/alan_gauld/tutor/tutindex.htm ----- Original Message ----- From: DanielKOBRIEN To: Sent: Monday, October 16, 2000 12:10 PM Subject: [Tutor] (no subject) > How do I start to learn how to programme a computer- I have found the > website www.python.org.... very confusing. Please reply to > danielkobrien@culford.suffolk.sch.uk > thanks > Daniel > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From curtis.larsen@Covance.Com Mon Oct 16 20:49:34 2000 From: curtis.larsen@Covance.Com (Curtis Larsen) Date: Mon, 16 Oct 2000 14:49:34 -0500 Subject: [Tutor] But Serially, Folks... Message-ID: Probably a silly question, but since I haven't seen it mentioned in any of the Python books thus far (Authors: Read 'opportunity' here), and also bearing in mind that I'm no Linux expert -- not even close -- I will just ask: I'd like to use Python to do some work over a serial port (/dev/ttyS1, to be precise) but the datacomm I'm attempting must set to a particular baud rate, parity, stop-bits, yadda-yadda. So -- how does one do this in Python and ensure that it is so, then put it back the way you found it? Do I call "setserial" before/after I run my module, or some such? (Does Python even have a way of doing this "natively"?) Also - since my datacomm will be *very* async (spew-wait-listen-spew), can someone recommend an existing module for me to use or work from? Perhaps someone already has something similar sitting around? Thanks! Curtis ----------------------------------------------------- Confidentiality Notice: This e-mail transmission may contain confidential or legally privileged information that is intended only for the individual or entity named in the e-mail address. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or reliance upon the contents of this e-mail is strictly prohibited. If you have received this e-mail transmission in error, please reply to the sender, so that we can arrange for proper delivery, and then please delete the message from your inbox. Thank you. begin 644 TEXT.htm M/"%$3T-465!%($A434P@4%5"3$E#("(M+R]7,T,O+T141"!(5$U,(#0N,"!4 M7!E/@T*/$U%5$$@8V]N=&5N=#TB35-(5$U,(#4N,#`N,CDQ M.2XV,S`W(B!N86UE/4=%3D52051/4CX\+TA%040^#0H\0D]$62!B9T-O;&]R M/2-F9F9F9F8@#0IS='EL93TB1D].5#H@,3!P="!!#L@34%21TE.+51/4#H@,G!X(CX-"CQ$258^4')O8F%B;'D@82!S M:6QL>2!Q=65S=&EO;BP@8G5T('-I;F-E($D@:&%V96XG="!S965N(&ET(&UE M;G1I;VYE9"!I;B!A;GD@;V8@#0IT:&4@4'ET:&]N(&)O;VMS('1H=7,@9F%R M)FYB2P@6]U(&9O=6YD(&ET/SPO1$E6/@T*/$1)5CXF;F)S<#L\+T1)5CX- M"CQ$258^1&\@22!C86QL(")S971S97)I86PB(&)E9F]R92]A9G1E2!M;V1U;&4L(&]R('-O;64@2!O9B!D;VEN9R!T:&ES(")N871I=F5L M>2(_*3PO1$E6/@T*/$1)5CXF;F)S<#L\+T1)5CX-"CQ$258^06QS;R`M('-I M;F-E(&UY(&1A=&%C;VUM('=I;&P@8F4@*G9E6YC("AS<&5W+7=A M:70M;&ES=&5N+7-P97&ES=&EN9R!M;V1U;&4@9F]R(&UE('1O('5S92!O Message-ID: On Mon, 16 Oct 2000, Deirdre Saoirse wrote: > > >> Im all new to Python, in fact, I know near nothing about it... Could > > >> someone like tell me what the deal is? Are there any books you can > > >> recomend to someone who wants to learn? Im pretty smart and stuff > > >> with computers (I have RH7 and know a little Perl), so please help me > > >> out! Can you?!? thanx, netowl Dear John, Nice to meet you! (Wow.) Yeah, the tutorial assumes that you just want to hit the language features fast; it doesn't provide too much justification for Python itself. For that, you'll probably want to take a quick glance at the Introductions section here: http://python.org/doc/Intros.html It's the section of the page that might be more relevant for you; it gives overviews, language comparisons, and a lot of short articles that explain Python's position relative to everything else out there. Linux Journal hosts an article by Eric Raymond that explains his enthusiasm for Python: http://www2.linuxjournal.com/lj-issues/issue73/3882.html Also, if you want to take a look at code snippets, you might want to browse through: http://www.vex.net/parnassus/ which acts somewhat like Perl's CPAN archive. If you have any questions, feel free to ask us. Good luck! From dyoo@hkn.eecs.berkeley.edu Tue Oct 17 04:00:42 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 16 Oct 2000 20:00:42 -0700 (PDT) Subject: [Tutor] But Serially, Folks... In-Reply-To: Message-ID: > Also - since my datacomm will be *very* async (spew-wait-listen-spew), > can someone recommend an existing module for me to use or work from? > Perhaps someone already has something similar sitting around? Dear Curtis, I'm out of my problem domain; however, perhaps these links may help. For the serial port accessing, I believe the termios module can help out: http://python.org/doc/current/lib/module-termios.html For the async stuff, there's the async module. *grin* http://python.org/doc/current/lib/module-asyncore.html and you can always do it at a lower level with the signal module: http://python.org/doc/current/lib/module-signal.html Hopefully, someone else more familiar with serial IO can give better advice. Good luck! From yooseong@kldp.org Tue Oct 17 08:47:23 2000 From: yooseong@kldp.org (Yooseong Yang) Date: Tue, 17 Oct 2000 16:47:23 +0900 Subject: [Tutor] Is there any module for docbook?? Message-ID: <20001017164723.A12917@pcel3.snu.ac.kr> Is there a docbooklib module in python stanadar module? -- -- "There Should Be One Obvious Way To Do It" ############################################################################ Yooseong Yang ICQ#65184660 Debian GNU/Linux, Python User KLDP Debian Debian-kr FAQ Project PyKUG Debian Users http://pcel3.snu.ac.kr/~yooseong ############################################################################ From karimy@nipltd.com Tue Oct 17 10:00:00 2000 From: karimy@nipltd.com (karim yaici) Date: Tue, 17 Oct 2000 10:00:00 +0100 Subject: [Tutor] HTML Validator in Python Message-ID: <39EC1510.2C20B65F@nipltd.com> --------------8B62FF1DC0B6E93686A0D57B Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi there, Just a simple question. I've been looking for a kind of HTML validator written in Python, but to the best of my knowledge there is none available. Someone told me to use the formatter module, do you think this may help?. I believe that someone should have had a need to write one at some point. I personnaly started one (very simple indeed ;-)), but I wish to to validate an HTML document against different DTD's (Document Type Definition) provided by W3C....so a more elaborated design is needed. Hope to find an answer... Cheers, Karim. --------------8B62FF1DC0B6E93686A0D57B Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hi there,

Just a simple question.  I've been looking for a kind of HTML validator written in Python, but to the best of my knowledge there is none available.

Someone told me to use the formatter module, do you think this may help?. I believe that someone  should have had a need to write one at some point. I personnaly started one (very simple indeed ;-)), but I wish to to validate an HTML document against different DTD's (Document Type Definition) provided by W3C....so a more elaborated design is needed.

Hope to find an answer...

Cheers,

Karim. --------------8B62FF1DC0B6E93686A0D57B-- From rod.gray@va.prestige.net Tue Oct 17 15:39:31 2000 From: rod.gray@va.prestige.net (Rod Gray) Date: Tue, 17 Oct 2000 10:39:31 -0400 Subject: [Tutor] Please help.... Message-ID: <000c01c03848$0f9508c0$4c1daccf@imp.rcn.net> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C03826.8858AF40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm a new python guy so I'm having trouble figuring this out. = Yesterday, thie following code worked fine...setting up a chat server on = port 4000 is it's purpose: ________________________________________ # import needed modules: from socket import * # get sockets, for well, sockets import string # string functions import time # for sleep(1) function # define global variables HOST =3D '' # Symbolic name meaning the = local host PORT =3D 4000 # Arbitrary non-privileged = server endl =3D "\r\n" # standard terminal line ending userlist =3D [] # list of connected users done =3D 0 # set to 1 to shut this down kAskName =3D 0 # some constants used to flag kWaitName =3D 1 # the state of each user kOK =3D 2 # class to store info about connected users class User: def __init__(self): self.name =3D "" self.addr =3D "" self.conn =3D None self.step =3D kAskName def Idle(self):=20 if self.step =3D=3D kAskName: self.AskName() def AskName(self): self.conn.send("Name? ") self.step =3D kWaitName def HandleMsg(self, msg): print "Handling message: ",msg global userlist =20 # if waiting for name, record it if self.step =3D=3D kWaitName: # try to trap garb initiall sent by some = telnets: if len(msg) < 2 or msg=3D=3D"#": return print "Setting name to: ",msg self.name =3D msg self.step =3D kOK self.conn.send("Hello, "+self.name+endl) broadcast(self.name+" has connected."+endl) return # check for commands if msg =3D=3D "quit": broadcast(self.name+" has quit.\n") self.conn.close() userlist.remove(self) return # otherwise, broadcast msg broadcast( self.name+": "+msg+endl ) # routine to check for incoming connections def pollNewConn(): try: conn, addr =3D s.accept() except: return None print "Connection from", addr conn.setblocking(0) user =3D User(); user.conn =3D conn user.addr =3D addr return user # routine to broadcast a message to all connected users def broadcast(msg): for u in userlist: u.conn.send(msg) # MAIN PROGRAM # set up the server s =3D socket(AF_INET, SOCK_STREAM) s.bind(HOST, PORT) s.setblocking(0) s.listen(1) print "Waiting for connection(s)..." # loop until done, handling connections and incoming messages while not done: time.sleep(1) # sleep to reduce processor usage u =3D pollNewConn() # check for incoming connections if u: userlist.append(u) print len(userlist),"connection(s)" for u in userlist: # check all connected users u.Idle() try: data =3D u.conn.recv(1024) data =3D filter(lambda x: x>=3D' ' and x<=3D'z', = data) data =3D string.strip(data) if data: print "From",u.name,': ['+data+']' u.HandleMsg(data) if data =3D=3D "shutdown": done=3D1 except: pass for u in userlist: u.conn.close() _____________________________________________________ Today when I run it, I get the following error: _____________________________________________________ Traceback (most recent call last): File "./server.py", line 99 in ? s.bind(HOST, PORT) TypeError: bind requires exactly 1 argument; 2 given _____________________________________________________ While I understand the error...I don't understand why I get it now and = not before with NO code alterations. Rod ------=_NextPart_000_0009_01C03826.8858AF40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

I'm a new python guy so I'm having = trouble figuring=20 this out.  Yesterday, thie following code worked fine...setting up = a chat=20 server on port 4000 is it's purpose:
________________________________________
 
# import needed modules:
 
from socket import=20 *            # = get=20 sockets, for well, sockets
import=20 string           &= nbsp;           &n= bsp;  =20 # string functions
import=20 time           &nb= sp;           &nbs= p;            = ;=20 # for sleep(1) function
 
# define global variables
 
HOST =3D=20 ''            = ;            =       =20 # Symbolic name meaning the local host
PORT =3D=20 4000           &nb= sp;           &nbs= p;    =20 # Arbitrary non-privileged server
endl =3D=20 "\r\n"           &= nbsp;      =20 # standard terminal line ending
 
userlist =3D=20 []            = ;      =20 # list of connected users
done =3D=20 0            =             &= nbsp;      =20 # set to 1 to shut this down
 
kAskName =3D=20 0            =        =20 # some constants used to flag
kWaitName =3D=20 1            =       =20 #       the state of each user
kOK =3D=20 2
 

# class to store info about = connected=20 users
 
class=20 User:
        def=20 __init__(self):
         =       =20 self.name =3D=20 ""
           &= nbsp;   =20 self.addr =3D=20 ""
           &= nbsp;   =20 self.conn =3D=20 None
           = ;    =20 self.step =3D kAskName
 
        def=20 Idle(self):=20
           &nb= sp;   =20 if self.step =3D=3D kAskName: self.AskName()
 
        def=20 AskName(self):
         &= nbsp;     =20 self.conn.send("Name?=20 ")
           &= nbsp;   =20 self.step =3D kWaitName
 
        def=20 HandleMsg(self,=20 msg):
          &nbs= p;    =20 print "Handling message:=20 ",msg
          &nbs= p;    =20 global=20 userlist
          &= nbsp;    =20
           &nb= sp;   =20 # if waiting for name, record=20 it
           &= nbsp;   =20 if self.step =3D=3D=20 kWaitName:
          = ;            =  =20 # try to trap garb initiall sent by some=20 telnets:
          &= nbsp;           &n= bsp;=20 if len(msg) < 2 or msg=3D=3D"#":=20 return
          &nb= sp;           &nbs= p;=20 print "Setting name to:=20 ",msg
          &nbs= p;            = ;=20 self.name =3D=20 msg
           =              = self.step =3D=20 kOK
           =              = self.conn.send("Hello,=20 "+self.name+endl)
        &nbs= p;            = ;  =20 broadcast(self.name+" has=20 connected."+endl)
        &nbs= p;            = ;  =20 return
 
          &nbs= p;    =20 # check for=20 commands
          &= nbsp;    =20 if msg =3D=3D=20 "quit":
          &n= bsp;           &nb= sp;=20 broadcast(self.name+" has=20 quit.\n")
          =             &= nbsp;=20 self.conn.close()
        &nbs= p;            = ;  =20 userlist.remove(self)
        =             &= nbsp;  =20 return
 
          &nbs= p;    =20 # otherwise, broadcast=20 msg
           =     =20 broadcast( self.name+": "+msg+endl )
 

# routine to check for incoming=20 connections
 
def=20 pollNewConn():
       =20 try:
           = ;    =20 conn, addr =3D s.accept()
       =20 except:
          &n= bsp;    =20 return None
        print = "Connection=20 from", addr
       =20 conn.setblocking(0)
        user = =3D=20 User();
        user.conn =3D=20 conn
        user.addr =3D=20 addr
        return = user
 

# routine to broadcast a message to = all=20 connected users
 
def=20 broadcast(msg):
        for u in=20 userlist:
          =      =20 u.conn.send(msg)
 

# MAIN PROGRAM
 

# set up the server
 
s =3D socket(AF_INET, = SOCK_STREAM)
s.bind(HOST,=20 PORT)
s.setblocking(0)
s.listen(1)
print "Waiting for=20 connection(s)..."
 
# loop until done, handling connections = and=20 incoming messages
 
while not=20 done:
       =20 time.sleep(1)          = #=20 sleep to reduce processor = usage
        u=20 =3D pollNewConn()       # check for = incoming=20 connections
        if=20 u:
           &= nbsp;   =20 userlist.append(u)
        &nb= sp;      =20 print len(userlist),"connection(s)"
 
        for u in=20 userlist:      # check all connected=20 users
          &nbs= p;    =20 u.Idle()
          &= nbsp;    =20 try:
           = ;            = =20 data =3D=20 u.conn.recv(1024)
        &nbs= p;            = ;  =20 data =3D filter(lambda x: x>=3D' ' and x<=3D'z',=20 data)
          &nbs= p;            = ;=20 data =3D=20 string.strip(data)
        &nb= sp;           &nbs= p;  =20 if=20 data:
          &nbs= p;            = ;        =20 print "From",u.name,':=20 ['+data+']'
         &nbs= p;            = ;         =20 u.HandleMsg(data)
        &nbs= p;            = ;          =20 if data =3D=3D "shutdown":=20 done=3D1
          &= nbsp;    =20 except:
          &n= bsp;           &nb= sp;=20 pass
 
for u in=20 userlist:
       =20 u.conn.close()
 
_____________________________________________________
 
 
Today when I run it, I get the = following=20 error:
 
_____________________________________________________
Traceback (most recent call = last):
    File "./server.py", = line 99 in=20 ?
        = s.bind(HOST,=20 PORT)
TypeError: bind requires exactly 1 = argument; 2=20 given
_____________________________________________________
 
While I understand the error...I don't = understand=20 why I get it now and not before with NO code alterations.
 
Rod
------=_NextPart_000_0009_01C03826.8858AF40-- From alan.gauld@bt.com Tue Oct 17 15:59:44 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 17 Oct 2000 15:59:44 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D39D@mbtlipnt02.btlabs.bt.co.uk> > I suggest you have a look at the following: > -> http://members.nbci.com/alan_gauld/tutor/tutindex.htm (for Python > mewbies) Please don't look there anymore. That site is stagnant and will not be kept up to date with changes (actually I'll probably stick the zipped version on occasionally) The real site is: http://www.crosswinds.net/~agauld/ I have started to update the site with stuff from my book and to increase the amount of BASIC and Tcl material such that every principle is illustrated in at least 2 out of the 3 languages. Python remains the mainstream language however. Alan G. From dyoo@hkn.eecs.berkeley.edu Tue Oct 17 18:10:56 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Oct 2000 10:10:56 -0700 (PDT) Subject: [Tutor] Please help.... In-Reply-To: <000c01c03848$0f9508c0$4c1daccf@imp.rcn.net> Message-ID: On Tue, 17 Oct 2000, Rod Gray wrote: > I'm a new python guy so I'm having trouble figuring this out. > Yesterday, thie following code worked fine...setting up a chat server > on port 4000 is it's purpose > s.bind(HOST, PORT) > While I understand the error...I don't understand why I get it now and > not before with NO code alterations. I'm guessing that you updated to Python 2.0. The bind() method got more strict with the new version of Python. According to the reference documentation: ### bind (address) Bind the socket to address. The socket must not already be bound. (The format of address depends on the address family -- see above.) Note: This method has historically accepted a pair of parameters for AF_INET addresses instead of only a tuple. This was never intentional and will no longer be available in Python 1.7. ### (http://python.org/doc/current/lib/socket-objects.html) So having bind accept two arguments was a small bug. The designers have fixed it, but at the expense of breaking old code. From claudia_dallas@yahoo.com Tue Oct 17 21:47:24 2000 From: claudia_dallas@yahoo.com (claudia flores) Date: Tue, 17 Oct 2000 13:47:24 -0700 (PDT) Subject: [Tutor] what programs is good for newbies Message-ID: <20001017204724.2958.qmail@web3904.mail.yahoo.com> My name is claudia and i would like to know what computer program is good to start that is easy and easy to learn i have no clue to computer programming , dont know what all those codes mean and how they work any info is appreciated thax __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Wed Oct 18 00:14:48 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Oct 2000 16:14:48 -0700 (PDT) Subject: [Tutor] Threads & Memory In-Reply-To: <22.c81cf83.271c3610@aol.com> Message-ID: On Mon, 16 Oct 2000 FxItAL@aol.com wrote: > I've written a small timer program that uses two threads to display > the current time and continuously compares the actual time to the time > set for the alarm. I'm not sure if it's a memory allocation thing. Could you show us the program? Perhaps it's doing a "polling" type loop that can take up a lot of CPU; even though it's threaded, it may still be greedy with resources. Can you check to see that it's not polling? Otherwise, I'm not sure why it would slow everything else down. Show us the program, and I'm sure we can figure out what's happening. Good luck! From scarblac@pino.selwerd.nl Wed Oct 18 00:20:27 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 18 Oct 2000 01:20:27 +0200 Subject: [Tutor] what programs is good for newbies' In-Reply-To: <20001017204724.2958.qmail@web3904.mail.yahoo.com>; from claudia_dallas@yahoo.com on Tue, Oct 17, 2000 at 01:47:24PM -0700 References: <20001017204724.2958.qmail@web3904.mail.yahoo.com> Message-ID: <20001018012027.A19663@pino.selwerd.nl> On Tue, Oct 17, 2000 at 01:47:24PM -0700, claudia flores wrote: > My name is claudia and i would like to know what computer program is good > to start that is easy and easy to learn i have no clue to computer > programming , dont know what all those codes mean and how they work any > info is appreciated thax Well, this is just too vague to give an answer to :-). You have a computer. What do you want to do with it? Once we have some idea what you're trying to do, we can offer help. If you want to learn how to program, there are several Python tutorials for complete newbies, like http://www.crosswinds.net/~agauld/ . Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Wed Oct 18 00:28:45 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Oct 2000 16:28:45 -0700 (PDT) Subject: [Tutor] what programs is good for newbies In-Reply-To: <20001017204724.2958.qmail@web3904.mail.yahoo.com> Message-ID: On Tue, 17 Oct 2000, claudia flores wrote: > My name is claudia and i would like to know what computer program is > good to start that is easy and easy to learn i have no clue to > computer programming , dont know what all those codes mean and how > they work any info is appreciated thax Dear Claudia, Hello, nice to meet you! Before we start, what's your experience with computers? It will be very good if you know how to use a text editor, so if you're still unfamiliar with it, try playing around with Notepad: save files, open them up, and make sure that you feel comfortable about this. It will make programming much nicer if you're not fighting the computer for control... *grin* Python is a programming language: you can write programs for the computer to execute. Writing programs can be very recreational. For example, this program: ### name = 'claudia' print 'Hello', name, 'nice to meet you!' ### is a very simple greeting program that says: Hello claudia nice to meet you! But of course, you can get the computer to do more interesting stuff as well. You'll probably want to start of with one of the great tutorials on this page: http://python.org/doc/Intros.html In particular: http://www.honors.montana.edu/~jjc/easytut/easytut/ and http://www.crosswinds.net/~agauld/ are very good. If you have any questions, just email the tutor@python.org list again, and we'll be happy to talk about them. Good luck! From alan.gauld@bt.com Wed Oct 18 17:30:50 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 18 Oct 2000 17:30:50 +0100 Subject: [Tutor] RE book info Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3A3@mbtlipnt02.btlabs.bt.co.uk> Some more blatant self promotion but I just noticed today that my book is now available for orders on Amazon and has a due date of 8th December. :-) Also for those who care, the new Ruby[1] book is now available and shipping. Alan g. [1] For Ruby info see: http://www.ruby-lang.org/en/index.html Its a lot like Python with some Perly bits tagged on and very consistent - and virtually no usable docs unless you read Japanese! From deirdre@deirdre.net Wed Oct 18 17:59:55 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 18 Oct 2000 09:59:55 -0700 (PDT) Subject: [Tutor] RE book info In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D3A3@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Wed, 18 Oct 2000 alan.gauld@bt.com wrote: > Some more blatant self promotion but I just noticed today > that my book is now available for orders on Amazon and has > a due date of 8th December. :-) Woohoo! Congratulations. As I've written a few books here and there, I know what a source of pride this can be. -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From dyoo@hkn.eecs.berkeley.edu Thu Oct 19 05:28:22 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 18 Oct 2000 21:28:22 -0700 (PDT) Subject: [Tutor] RE book info In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D3A3@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Wed, 18 Oct 2000 alan.gauld@bt.com wrote: > Some more blatant self promotion but I just noticed today > that my book is now available for orders on Amazon and has > a due date of 8th December. :-) Very cool! Another book for my bulging bookshelf! *grin* From Pollock974@aol.com Thu Oct 19 11:16:20 2000 From: Pollock974@aol.com (Pollock974@aol.com) Date: Thu, 19 Oct 2000 06:16:20 EDT Subject: [Tutor] Just wondering Message-ID: Hello, I am a complete newbie at Python and i have a couple of questions. First of all i bought a book called "Teach Yourself Python in 24 Hours" by Ivan Van Laningham. I was just wondering if anybody's read it and if its worth reading. Second, this is a program for printing the ascii table. 1. #!/usr/local/bin/python 2. 3. i = 0 4. while i < 256: 5. print chr(i), 6. if i != 0 and i % 8 == 0: 7. print 8. i = i +1 Now i have 2 questions. First of all i may be wrong but isn't the 1st line a location on a Unix platform? Im running Windoze 98 and was wondering if i needed that line of code. Second, when i look at the code it seems that the 6th and 7th line aren't needed, but when i run it without it, it prints 1 character on each line. I was wondering how that tells python to print more than 1 character on a line. Now this isnt a life or death situation, it's just been on my mind. I looked in the book but i couldnt find anything. Any help would be greatly appreciated. From scarblac@pino.selwerd.nl Thu Oct 19 11:26:11 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 19 Oct 2000 12:26:11 +0200 Subject: [Tutor] Just wondering In-Reply-To: ; from Pollock974@aol.com on Thu, Oct 19, 2000 at 06:16:20AM -0400 References: Message-ID: <20001019122611.A2677@pino.selwerd.nl> On Thu, Oct 19, 2000 at 06:16:20AM -0400, Pollock974@aol.com wrote: > Hello, Hi! > I am a complete newbie at Python and i have a couple of questions. First > of all i bought a book called "Teach Yourself Python in 24 Hours" by Ivan > Van Laningham. I was just wondering if anybody's read it and if its worth > reading. Second, this is a program for printing the ascii table. > > 1. #!/usr/local/bin/python > 2. > 3. i = 0 > 4. while i < 256: > 5. print chr(i), > 6. if i != 0 and i % 8 == 0: > 7. print > 8. i = i +1 > > Now i have 2 questions. First of all i may be wrong but isn't the 1st > line a location on a Unix platform? Im running Windoze 98 and was wondering > if i needed that line of code. No, it's not used on Windows. That said, keeping the line makes it more portable. You might want to give your code to someone else, who might run a Unix. Some editors can also recognize it, and go into "Python-mode" automatically. > Second, when i look at the code it seems that > the 6th and 7th line aren't needed, but when i run it without it, it prints 1 > character on each line. I was wondering how that tells python to print more > than 1 character on a line. Now this isnt a life or death situation, it's > just been on my mind. I looked in the book but i couldnt find anything. Any > help would be greatly appreciated. The "print chr(i)," ends with a comma. Usually print goes to the next line after the print, but the comma puts a space at the end and then stays at the same line. Lines 6 and 7 say "if i isn't 0 and can be divided by 8, print nothing and go to the next line". The effect is that you get 8 characters per line, with spaces in between. Remco Gerlich From marcel@punto.it Thu Oct 19 11:40:10 2000 From: marcel@punto.it (Marcel Preda) Date: Thu, 19 Oct 2000 12:40:10 +0200 (CEST) Subject: [Tutor] Just wondering In-Reply-To: Message-ID: On Thu, 19 Oct 2000 Pollock974@aol.com wrote: > Hello, > I am a complete newbie at Python and i have a couple of questions. First > of all i bought a book called "Teach Yourself Python in 24 Hours" by Ivan > Van Laningham. I was just wondering if anybody's read it and if its worth > reading. Second, this is a program for printing the ascii table. > > 1. #!/usr/local/bin/python > 2. > 3. i = 0 > 4. while i < 256: > 5. print chr(i), > 6. if i != 0 and i % 8 == 0: > 7. print > 8. i = i +1 > > Now i have 2 questions. First of all i may be wrong but isn't the 1st > line a location on a Unix platform? Im running Windoze 98 and was wondering > if i needed that line of code. Second, when i look at the code it seems that > the 6th and 7th line aren't needed, but when i run it without it, it prints 1 > character on each line. I was wondering how that tells python to print more > than 1 character on a line. Now this isnt a life or death situation, it's > just been on my mind. I looked in the book but i couldnt find anything. Any > help would be greatly appreciated. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > #1 YES(is a Unix platform) you dont need it, but it will not do semething wrong #2 looks like after every 8 characters the script insert a newLine, so if you don't need... Abot MORE THAN ONE (#3) By default `print' add a `\n' You have tu use `,' if want to skip `\n' >>> for i in range(0,1): ... print 'a' ... print 'b' ... a b >>> for i in range(0,1): ... print 'a', ... print 'b' ... a b PM __ To be or not to be. -- Shakespeare To do is to be. -- Nietzsche To be is to do. -- Sartre Do be do be do. -- Sinatra ___ From scott@zenplex.com Thu Oct 19 14:00:45 2000 From: scott@zenplex.com (Scott Ralph) Date: Thu, 19 Oct 2000 09:00:45 -0400 Subject: [Tutor] Python and SQL Message-ID: <39EEF07D.E742E40B@zenplex.com> I'm still very much in the learning stage of Python but I'm ready to try out my newly learned skills on something more then just Hello World. We currently have a java programmer on staff who is working on Java Database connectivity. Can I do the same under python? I'm looking for tools to work with a SQL database such as PostgreSQL and MySQL. Any comments would be a big help. Thanks All Scott -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scott Ralph Zenplex, Inc. 317 Madison Ave Suite 1500 New York, NY 10017 212.499.0668 http://www.zenplex.com From karimy@nipltd.com Thu Oct 19 14:20:59 2000 From: karimy@nipltd.com (karim yaici) Date: Thu, 19 Oct 2000 14:20:59 +0100 Subject: [Tutor] Python and SQL References: <39EEF07D.E742E40B@zenplex.com> Message-ID: <39EEF53B.1E1E4FC3@nipltd.com> Hi Scott, Though I've just started with Python,I can tell you thay there are tools in Python to interact with DB's. At least I know that MySQL does exist, because I worked with it. However, It seems that there is only a linux version of it called MYSQLdb (RPMs or tar source code) .You can find it on http://starship.python.net/crew/adustman/MySQLdb.html Zope (Open Source web application server) ,which is written in Python, uses MySQL and PostgreSQL, so there should be some modules aroud there to do the job (www.zope.org). Perhaps someone else (more experimented ;-) )can help you with other DB's!(I've heard that there is a MySQLad 'adapter', but don't know where to get it from ;-)) Cheers, Karim From johnnyflynn@hotmail.com Thu Oct 19 17:08:41 2000 From: johnnyflynn@hotmail.com (John Flynn) Date: Thu, 19 Oct 2000 12:08:41 EDT Subject: [Tutor] basic question Message-ID: I am new to programming and am extremely interested in learning it with Python. My question is what is tcl and why was it installed with python 1.5.2 but I don't see it installed with 2.0. I found an excellent tutor program that teaches people who know nothing about programming how to program in tcl. Is this a waste of time if the language I want to use is Python. Do I have to keep my old version of Tcl when I upgrade to 2.0. Or do I have to uninstall it first? Thanks alot and Ilook forward to joing the tremendous group of programmers in the world. _________________________________________________________________________ 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 shaleh@valinux.com Thu Oct 19 17:28:22 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 19 Oct 2000 09:28:22 -0700 (PDT) Subject: [Tutor] basic question In-Reply-To: Message-ID: The only reason tcl MIGHT be involved is that python has a interface to tk, the GUI toolkit that tcl (and other langs) use. You do NOT need to know tcl to program in python. Whether or not learning that language would be beneficial is anothe story. Some people believe that you learn new ways to think with each language. From alan.gauld@bt.com Thu Oct 19 17:23:51 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 19 Oct 2000 17:23:51 +0100 Subject: [Tutor] Just wondering Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3A8@mbtlipnt02.btlabs.bt.co.uk> > of all i bought a book called "Teach Yourself Python in 24 > Hours" by Ivan Van Laningham. Congratulations, good choice. > I was just wondering if anybody's read it and > if its worth reading. Hmmm, but shouldn''t you have asked this *before* you bought it? :-) The answer is yes, it is probably the best complete beginners guide currently available. (I hope to change that soon :-) If you still have questions while reading the book Ivan has a web page and you can post here. I see somebody else answered the code questions. Alan G. From jclevieux@sud2000.com Thu Oct 19 21:29:05 2000 From: jclevieux@sud2000.com (Jean-Claude Levieux) Date: Thu, 19 Oct 2000 22:29:05 +0200 Subject: [Tutor] Python 2.0 Message-ID: <5.0.0.25.2.20001019222023.02e9ddc8@pop.sud2000.com> Hi, I just tried to compile Python 2.0. on BSDI BSD/OS 4.0.1 After a lot of warnings like : ......... in file included from ../Include/pyport.h:84, from ../Include/Python.h:54, from python.c:3: /usr/include/math.h:177: warning: function declaration isn't a prototype /usr/include/math.h:257: warning: function declaration isn't a prototype ........ The compile failed with this message : /usr/home/......./Python-2.0/Objects/fileobject.c:274: undefined reference to `TELL64' *** Error code 1 Stop. *** Error code 1 Coul you help me, please. Thanks in advance ----------------------------------------------- Jean-Claude Levieux jclevieux@sud2000.com www.sud2000.com/ From arthur.watts@gbst.com Fri Oct 20 00:20:03 2000 From: arthur.watts@gbst.com (Arthur Watts) Date: Fri, 20 Oct 2000 09:20:03 +1000 Subject: [Tutor] Python Books - One Man's Opinion Message-ID: <1CDB101F0CB6D311882F0000F80639240193CF83@aquarius.bne.star.com.au> Guys, Please note: all prices quoted below represent the amount that I paid in Australian dollars. Our dollar is currently around $US 0.52, so please don't flame me about the price you paid. I've included this to give you an idea of relative pricing : please check Amazon etc for current prices. I noticed a query about Python books on the list, so here's my two cents (that's Aust currency : your mileage may vary..) worth : 1. The O'Reilly 'bibles' : Learning Python and Programming Python. As a Perl programmer, I immediately leapt upon the latter as a Python equivalent to Larry Wall's Camel book, Programming Perl. After grinding my way through Mark Lutz' quite large (880 pages) book, I admit that I went back to the comparative safety of Perl. It was only after spending some more time with Python (and reading a lot of other material) that I was able to grasp certain parts of this book. Learning Python is, arguably, the best of the current crop of Python books available. If you've read through the introductory stuff on the Python Home page and feel that Python may be what you are after, I heartily recommend it as the next step. Learning Python : $69.95 Rating : **** Programming Python : $99.95 Rating: **** 2. The SAMS Book, 'Teach Yourself Python in 24 Hours'. A lot of industry professionals avoid anything with a title like this, and often for good reason. I agree that the 'Dummies' series has no place in a serious programmers bookshelf, but I have found several of the SAMS series (Shell Programming, for example) to be reasonable treatments of often complex subjects. The author of TY Python in 24 Hrs has adopted a common approach - he assumes that the reader is computer-literate, but knows little of programming. He covers a lot of ground in a relatively small book, and its a reasonable introductory text and good value for money. Teach Yourself Python in 24 Hours : $39.95 Rating : *** 3. Python and Tkinter Programming : a difficult book to critique, as I am new to Graphics programming and still a long way from being an expert Python programmer ! Perhaps someone else can provide an opinion ? Unsure of the price .. I think it was about $90 Rating : N/A 4. Python Essential Reference , David M Beazley (New Riders, 2000). Easily my personal favourite. The author freely admits that the information contained can be found via the Python Home page, but I would argue that you'd need to spend plenty of time trying to find some of it. The book manages to be both compact and comprehensive (not unlike the language itself..), and uses one/two line examples to illustrate various syntactical descriptions. This book won;t teach you how to program in Python, but it will help you immensely once you get the basics sorted. Python Essential Reference : $60.20 Rating : ***** I have read that there are other, more beginner-friendly titles on the way, but they haven't arrived in my technical bookstore as yet : no room for all the Linux and Java titles :} Enjoy, Arthur Arthur Watts Systems Integrator GBST Holdings Ltd 'Good programmers know what to use, great programmers know what to re-use' : Old Jungle Saying From deirdre@deirdre.net Fri Oct 20 00:55:36 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 19 Oct 2000 16:55:36 -0700 (PDT) Subject: [Tutor] A little example for MySql Message-ID: I hadn't used the MySql bindings before, so I created a little example that I thought was clearer than the one included with Andy Dustman's MySql bindings for python. You may need to change the db, user and pass though. #!/usr/bin/python # Written by Deirdre Saoirse Moen, TiVo, Inc. # Feel free to use for any purpose import MySQLdb import traceback import sys def tryordie(stmt): global cursor try: cursor.execute(stmt) except: print traceback.print_exc() mydb.close() sys.exit() # begin main program here try: mydb = MySQLdb.Connect(db='test', user='foo', passwd='bar') cursor = mydb.cursor() except: print "\n\n" traceback.print_exc() sys.exit() # try and create the table, but if it doesn't exist, don't harf stmt = "CREATE TABLE COLORS (COLOR varchar(32) DEFAULT '' NOT NULL)" try: cursor.execute(stmt) except: pass stmt = "DELETE FROM COLORS" tryordie(stmt) stmt = "INSERT INTO COLORS VALUES ('red')" tryordie(stmt) stmt = "INSERT INTO COLORS VALUES ('blue')" tryordie(stmt) stmt = "INSERT INTO COLORS VALUES ('yellow')" tryordie(stmt) # grand finale test stmt = "select * from COLORS" tryordie(stmt) try: resultSet = cursor.fetchall() for i in xrange(0, len(resultSet)): print "Color number",i,"is", resultSet[i][0] except: pass mydb.close() -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From wheelege@tsn.cc Fri Oct 20 09:27:25 2000 From: wheelege@tsn.cc (wheelege) Date: Fri, 20 Oct 2000 18:27:25 +1000 Subject: [Tutor] Python Books - One Man's Opinion References: <1CDB101F0CB6D311882F0000F80639240193CF83@aquarius.bne.star.com.au> Message-ID: <00a401c03a6f$942e0a40$a410fea9@glen> I'd like to add Alan Grayson's book to that list and put it at 5 stars. Great book! And no I'm not paid, I've just been reading it for the last couple of days :) From jclevieux@sud2000.com Fri Oct 20 09:41:41 2000 From: jclevieux@sud2000.com (Jean-Claude Levieux) Date: Fri, 20 Oct 2000 10:41:41 +0200 Subject: [Tutor] Python 2.0 Message-ID: <5.0.0.25.2.20001020104120.023c0bc8@pop.sud2000.com> Hi, I just tried to compile Python 2.0. on BSDI BSD/OS 4.0.1 After a lot of warnings like : ......... in file included from ../Include/pyport.h:84, from ../Include/Python.h:54, from python.c:3: /usr/include/math.h:177: warning: function declaration isn't a prototype /usr/include/math.h:257: warning: function declaration isn't a prototype ........ The compile failed with this message : /usr/home/......./Python-2.0/Objects/fileobject.c:274: undefined reference to `TELL64' *** Error code 1 Stop. *** Error code 1 Coul you help me, please. Thanks in advance ----------------------------------------------- Jean-Claude Levieux jclevieux@sud2000.com www.sud2000.com/ _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor ----------------------------------------------- Jean-Claude Levieux jclevieux@sud2000.com www.sud2000.com/ From zakir@nortelnetworks.com Fri Oct 20 21:30:35 2000 From: zakir@nortelnetworks.com (Zakir Hussain) Date: Fri, 20 Oct 2000 16:30:35 -0400 Subject: [Tutor] Need help!! I am a new python user Message-ID: This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C03AD4.99CF6EC0 Content-Type: text/plain; charset="iso-8859-1" I am trying to subtract two values but instead of subtracting it give me an error Traceback (innermost last): File "", line 1, in ? test() File "d:\Python\metrics.py", line 151, in test z.process_metrics_file() File "d:\Python\metrics.py", line 136, in process_metrics_file self.calc_time() File "d:\Python\metrics.py", line 115, in calc_time tot_min = (`end_min`) - (`start_min`) TypeError: bad operand type(s) for - can you please help me with that ? Here is the Example code fragment start_min = self.sessions[self.current_entry[5]]['start'][0][4] end_min = self.sessions[self.current_entry[5]]['end'][0][4] #start_min's value is 40 #end_min's value is 50 so now I am trying to subtract start min if (end_min > start_min): total_min = end_min - start_min print start_min print end_min Also if I try to add the velues it concatinates them e.g: end_min + start_min = 5040 ------_=_NextPart_001_01C03AD4.99CF6EC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Need help!! I am a new python user

I am trying to subtract two values = but  instead of subtracting it give me an error

Traceback (innermost last):
  File = "<pyshell#1>", line 1, in ?
    test()
  File = "d:\Python\metrics.py", line 151, in test
    = z.process_metrics_file()
  File = "d:\Python\metrics.py", line 136, in = process_metrics_file
    = self.calc_time()
  File = "d:\Python\metrics.py", line 115, in calc_time
    tot_min =3D = (`end_min`) - (`start_min`)
TypeError: bad operand type(s) for = -



can you please help me with that = ?

Here is the Example code = fragment

start_min =3D = self.sessions[self.current_entry[5]]['start'][0][4]
end_min =3D = self.sessions[self.current_entry[5]]['end'][0][4]

#start_min's value is 40
#end_min's value is 50
so now I am trying to subtract start = min

if (end_min > start_min):
         &nb= sp;  total_min =3D end_min - = start_min       
       =20
        print start_min
        =         print end_min

Also if I try to add the velues it = concatinates them
e.g:  end_min + start_min =3D = 5040


------_=_NextPart_001_01C03AD4.99CF6EC0-- From bwinton@tor.dhs.org Fri Oct 20 23:19:37 2000 From: bwinton@tor.dhs.org (Blake Winton) Date: Fri, 20 Oct 2000 18:19:37 -0400 Subject: [Tutor] Need help!! I am a new python user In-Reply-To: References: Message-ID: <20001020181937.B3934@tor.dhs.org> * Zakir Hussain [001020 15:34]: > tot_min = (`end_min`) - (`start_min`) > TypeError: bad operand type(s) for - > > start_min = self.sessions[self.current_entry[5]]['start'][0][4] > end_min = self.sessions[self.current_entry[5]]['end'][0][4] > > #start_min's value is 40 > #end_min's value is 50 That's not entirely true... The actual values aren't 40 and 50, but "40", and "50". You have two strings, which you can't subtract. > Also if I try to add the velues it concatinates them > e.g: end_min + start_min = 5040 This also makes sense, since "adding" two strings will concatenate them. What you _really_ want to do is convert them to integers. Look up the atoi function in the String module. Later, Blake. -- 9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07 From alan.gauld@bt.com Mon Oct 23 10:22:57 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 23 Oct 2000 10:22:57 +0100 Subject: [Tutor] Python Books - One Man's Opinion Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3A9@mbtlipnt02.btlabs.bt.co.uk> > I'd like to add Alan Grayson's book to that list Is that meant to be John Grayson's book on Tkinter?[*] Or is there another one by Alan Grayson? If so what's its title (and subject scope) coz I've never seen it? Curiously yours, Alan G. [*] If so I'd rate it 3 stars, it covers a niche area(Tkinter) reasonably well but starts from a pretty high platform - assuming you already know Tkinter basics - and misses some reference material. My standard reference for programming Tkinter remains the O'Reilly nutshell guide to Tcl/Tk! From zakir@nortelnetworks.com Mon Oct 23 14:09:28 2000 From: zakir@nortelnetworks.com (Zakir Hussain) Date: Mon, 23 Oct 2000 09:09:28 -0400 Subject: [Tutor] How to traverse a dictionary Message-ID: This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C03CF2.79BC7540 Content-Type: text/plain; charset="iso-8859-1" I have a dictionary with keys that are different names of sessions and each key contains START TIME and END TIME I want to go through dictionary and perform some calculations. I can't figure out how to go through the dictionary from the start to end Here is the example #This is where I am creating the dictionary def process_new_dictionary(self): if not(self.sessions.has_key(self.current_entry[5])): splitted_time = split(self.current_entry[0], '.') t = [splitted_time] self.sessions[self.current_entry[5]]= {'start':t, 'end':t} if (self.sessions.has_key(self.current_entry[5])): splitted_time2 = split(self.current_entry[0], '.') t2 = [splitted_time2] self.sessions[self.current_entry[5]]['end'] = t2 This is where I am trying to do the calculation but I want to go through the entire dictionary and calculate the time for each session. I don't know if I should use a while loop or something else and how to use it. If you can help me with that I will be very thakful def calc_time(self): if (start_hour > end_hour): temp_hour = end_hour + 24 total_hour = total_hour + (temp_hour - start_hour) print 'total hour', total_hour ------_=_NextPart_001_01C03CF2.79BC7540 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable How to traverse a dictionary

I have a dictionary with keys that are = different names of sessions and each key contains START TIME and END = TIME
I want to go through dictionary and = perform some calculations. I can't figure out how to go through the = dictionary from the start

to end

Here is the example

#This is where I am creating the = dictionary
def = process_new_dictionary(self):
         &nb= sp;  if not(self.sessions.has_key(self.current_entry[5])):
         &nb= sp;          splitted_time = =3D split(self.current_entry[0], '.')
         &nb= sp;          t =3D = [splitted_time]
         &nb= sp;          = self.sessions[self.current_entry[5]]=3D {'start':t, 'end':t}
         &nb= sp;         
         &nb= sp;  if (self.sessions.has_key(self.current_entry[5])):
         &nb= sp;          = splitted_time2 =3D split(self.current_entry[0], '.')
         &nb= sp;          t2 =3D = [splitted_time2]
         &nb= sp;          = self.sessions[self.current_entry[5]]['end'] =3D t2


This is where I am trying to do the = calculation but I want to go through the entire dictionary and = calculate the time
for each session. I don't know if I = should use a while loop or something else and how to use it.
If you can help me with that I will = be very thakful


def calc_time(self):
if (start_hour > end_hour):
         &nb= sp;  temp_hour =3D end_hour + 24
         &nb= sp;  total_hour =3D total_hour + (temp_hour - start_hour)


print 'total hour', total_hour


------_=_NextPart_001_01C03CF2.79BC7540-- From scott@zenplex.com Mon Oct 23 18:15:19 2000 From: scott@zenplex.com (Scott Ralph) Date: Mon, 23 Oct 2000 13:15:19 -0400 Subject: [Tutor] Hot Folders? Message-ID: <39F47227.F5F51331@zenplex.com> Hello, I'd like to create a hot folder program in Python.. I'm still in the learning stage so any help would be great. Basically I would have a folder on my server that if and when a file hits it it will do something.. My problem is I'm not sure were to start. How can I code in my script a sort of watcher routine that will monitor this folder? Also how can I check if the file is actually done coping into the folder? Thanks All Scott From Carissa.Stahl@icn.siemens.com Mon Oct 23 18:44:14 2000 From: Carissa.Stahl@icn.siemens.com (Stahl, Carissa) Date: Mon, 23 Oct 2000 13:44:14 -0400 Subject: [Tutor] joining mailing list Message-ID: Please place me on your mailing list... carissa.stahl@icn.siemens.com From gerrit@nl.linux.org Mon Oct 23 19:29:10 2000 From: gerrit@nl.linux.org (gerrit@nl.linux.org) Date: Mon, 23 Oct 2000 20:29:10 +0200 Subject: [Tutor] How to traverse a dictionary In-Reply-To: ; from zakir@nortelnetworks.com on Mon, Oct 23, 2000 at 09:09:28AM -0400 References: Message-ID: <20001023202910.A1969@nl.linux.org> > I have a dictionary with keys that are different names of sessions and each > key contains START TIME and END TIME > I want to go through dictionary and perform some calculations. I can't > figure out how to go through the dictionary from the start > to end >>> d = {"a": "first", "b": "second", "c": "third"} >>> d.items() [('b', 'second'), ('c', 'third'), ('a', 'first')] >>> for key, value in d.items(): ... print "key is", key, "value is", value ... key is b value is second key is c value is third key is a value is first It isn't alfabetically because of the efficient way in which python stores its dictionairies. Don't worry 'bout that! regards, Gerrit. -- **************************************************************************** * Save Mother Earth! -- Earth First! -- visit http://www.earthfirst.org/! **************************************************************************** From deirdre@deirdre.net Mon Oct 23 19:29:37 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 23 Oct 2000 11:29:37 -0700 (PDT) Subject: [Tutor] joining mailing list In-Reply-To: Message-ID: On Mon, 23 Oct 2000, Stahl, Carissa wrote: > Please place me on your mailing list... You're there..let us know if we can help you. :) -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From Desai.Dinakar@mayo.edu Mon Oct 23 20:03:39 2000 From: Desai.Dinakar@mayo.edu (dinakar desai) Date: Mon, 23 Oct 2000 14:03:39 -0500 (CDT) Subject: [Tutor] help with lseek of os In-Reply-To: <20001023202910.A1969@nl.linux.org> Message-ID: Hello All: I am posting for the first time. few weeks back I started with python and I know C++. I would like to seek to particular location in file depending on size of record (which are stored as binary file). In C++, I do it with seekg(pos * sizeof(record)). I looked into python os module and there is function lseek. I do not know what it expects for "file descriptor", pos and how. can anyone please explain and give an short example with filename like "myfile" Thank you. Dinakar From shaleh@valinux.com Mon Oct 23 20:28:56 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 23 Oct 2000 12:28:56 -0700 (PDT) Subject: [Tutor] help with lseek of os In-Reply-To: Message-ID: On 23-Oct-2000 dinakar desai wrote: > Hello All: > > I am posting for the first time. few weeks back I started with python and > I know C++. I would like to seek to particular location in file depending > on size of record (which are stored as binary file). In C++, I do it with > seekg(pos * sizeof(record)). > I looked into python os module and there is function lseek. I do not know > what it expects for "file descriptor", pos and how. can anyone > please explain and > give an short example with filename like "myfile" > pos = 1 fp = open(filename, 'r') fp.seek(pos * record_size, 0) # seek from beginning # 1 means current, 2 means from end or fd = fp.fileno() import os os.lseek(fd, pos, 0) basically, python's open is like fopen(), you have to ask the fp for its fileno. Python: essential reference by New Riders is a great "look up this fact" book for python. It is rather like the camel book from ORA, but small and readable. From wheelege@tsn.cc Mon Oct 23 12:19:43 2000 From: wheelege@tsn.cc (wheelege) Date: Mon, 23 Oct 2000 21:19:43 +1000 Subject: [Tutor] Hmmm maybe, indeed I could be Message-ID: <000301c03d38$c84c9960$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_005E_01C03D36.F636F8E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hmm maybe I am wrong in my assumption of the author. It has the picture of a chinese-type asian person on the front. It really suits me because I have covered python basics but am only = really interested in Tkinter. Sorry for the confusion (if any) :) ------=_NextPart_000_005E_01C03D36.F636F8E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hmm maybe I am wrong in my assumption of the author.

It has = the=20 picture of a chinese-type asian person on the front.

It really = suits me=20 because I have covered python basics but am only really
interested in = Tkinter.

Sorry for the confusion (if any) :)
------=_NextPart_000_005E_01C03D36.F636F8E0-- From dyoo@hkn.eecs.berkeley.edu Tue Oct 24 07:33:39 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 23 Oct 2000 23:33:39 -0700 (PDT) Subject: [Tutor] Hot Folders? In-Reply-To: <39F47227.F5F51331@zenplex.com> Message-ID: On Mon, 23 Oct 2000, Scott Ralph wrote: > I'd like to create a hot folder program in Python.. I'm still in the > learning stage so any help would be great. Basically I would have a > folder on my server that if and when a file hits it it will do > something.. My problem is I'm not sure were to start. How can I code > in my script a > > sort of watcher routine that will monitor this folder? Also how can I > check if the file is actually done coping into the folder? Wow! I've never done this before, so I don't know what's traditionally done to do monitoring. One idea is to have your program sleep for a while, and then every once in a while, check to see if things in your directory are changing. Here's some pseudocode: dircontents = getDirContents() while 1: newcontents = getDirContents() if dircontents != newcontents: doSomething() dircontents = newcontents sleep(1000) This won't work unless we define getDirContents(), but that shouldn't be too bad. You can do directory stuff with the 'os.path' module. From a quick scanthrough, the 'dircache' module also looks useful for this stuff. This looks like an interesting program! I hope this helps get you started. From scott@zenplex.com Tue Oct 24 14:21:28 2000 From: scott@zenplex.com (Scott Ralph) Date: Tue, 24 Oct 2000 09:21:28 -0400 Subject: [Tutor] Hot Folders? References: Message-ID: <39F58CD8.C39A7003@zenplex.com> Daniel Yoo wrote: > On Mon, 23 Oct 2000, Scott Ralph wrote: > > > I'd like to create a hot folder program in Python.. I'm still in the > > learning stage so any help would be great. Basically I would have a > > folder on my server that if and when a file hits it it will do > > something.. My problem is I'm not sure were to start. How can I code > > in my script a > > > > sort of watcher routine that will monitor this folder? Also how can I > > check if the file is actually done coping into the folder? > > Wow! I've never done this before, so I don't know what's traditionally > done to do monitoring. One idea is to have your program sleep for a > while, and then every once in a while, check to see if things in your > directory are changing. Here's some pseudocode: > > dircontents = getDirContents() > while 1: > newcontents = getDirContents() > if dircontents != newcontents: > doSomething() > dircontents = newcontents > sleep(1000) > > This won't work unless we define getDirContents(), but that shouldn't be > too bad. You can do directory stuff with the 'os.path' module. From a > quick scanthrough, the 'dircache' module also looks useful for this stuff. > > This looks like an interesting program! I hope this helps get you > started. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor Thanks for the input. I was trying to use atime to check for status of a file based on last access time and I was getting no where. I was thinking this >> If a file was being copied in I would check every 10sec if the file is older then 10sec file copy complete. Anyway thanks for the input this is a start. I will pass on my progress. Thanks Scott -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scott Ralph Zenplex, Inc. 317 Madison Ave Suite 1500 New York, NY 10017 212.499.0668 http://www.zenplex.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From adustman@comstar.net Tue Oct 24 19:42:05 2000 From: adustman@comstar.net (Andy Dustman) Date: Tue, 24 Oct 2000 14:42:05 -0400 (EDT) Subject: [Tutor] Re: A little example for MySql In-Reply-To: Message-ID: There are actually a lot of things about that example I don't care for. One is a gratituous use of try ... except clauses (i.e. the except does what the Python interpreter does when there is no except). Another is the use of * in SQL and default columns on INSERT. And then there are several single-row INSERTs into the same table. So here's a modified version that uses a few more features of Python, MySQL, and MySQLdb, and, IMHO, is a lot more comprehensible. #!/usr/bin/python import MySQLdb mydb = MySQLdb.Connect(db='test') cursor = mydb.cursor() # create a new table, dropping the old one if it exists stmt = "DROP TABLE IF EXISTS COLORS" cursor.execute(stmt) stmt = """CREATE TABLE COLORS ( COLOR varchar(32) DEFAULT '' NOT NULL, NCOLOR INT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (NCOLOR) )""" cursor.execute(stmt) # multi-row insert colors = ( ('red',), ('blue',), ('yellow',), ) stmt = "INSERT INTO COLORS (COLOR) VALUES (%s)" cursor.executemany(stmt, colors) # grand finale test stmt = "select NCOLOR, COLOR from COLORS" cursor.execute(stmt) resultSet = cursor.fetchall() for i, color in resultSet: print "Color number",i,"is", color mydb.close() -- andy dustman | programmer | comstar.net is part of the Globix network telephone: 770.485.6025 / 706.549.7689 | icq: 32922760 | pgp: 0xc72f3f1d "Therefore, sweet knights, if you may doubt your strength or courage, come no further, for death awaits you all, with nasty, big, pointy teeth!" From deirdre@deirdre.net Tue Oct 24 19:49:43 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 24 Oct 2000 11:49:43 -0700 (PDT) Subject: [Tutor] Re: A little example for MySql In-Reply-To: Message-ID: On Tue, 24 Oct 2000, Andy Dustman wrote: > There are actually a lot of things about that example I don't care > for. One is a gratituous use of try ... except clauses (i.e. the > except does what the Python interpreter does when there is no except). > Another is the use of * in SQL and default columns on INSERT. And then > there are several single-row INSERTs into the same table. Yeah, I could have used multi-row inserts but I chose not to; I think a single row insert is easier to understand but, for a simple example, having one of each might have been a better idea. Still, either way, the examples (either of ours) are more concise and comprehensible than what ships with the MySql bindings. -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From conways5@earthlink.net Wed Oct 25 03:48:08 2000 From: conways5@earthlink.net (The Conways) Date: Tue, 24 Oct 2000 19:48:08 -0700 Subject: [Tutor] Python 2.0 newbie questions Message-ID: <001201c03e2e$023c5520$0cddaec7@conway> This is a multi-part message in MIME format. ------=_NextPart_000_000F_01C03DF3.552E0340 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am sorry to bother you but I am getting confused after reading the = tutorials. I am hoping that I can get some instructions that will make = sense to my small brain. I download and installed python 2.0 with the windows installer. I am = running it on a Win 98se. I have been reading the tutorials and trying = to make sense of them in reference to python 2.0. =20 I have been wondering if it was wise to download this version??? The installation program installed two icons in the start menu. One for = python and one for the python gui (What is the python gui?). =20 I know that python works in the interactive mode because I tried it. My question is what do I do next? Some of the tutorials and readme files talk having MS VC++ and others = talk about pcbuild.?????? I tried adding python to the autoexec.bat but it didn't seem to run at = the c prompt. What do I need to do to get it to run the hello.py text file that I = saved???? Thanks for your time Jim Conway PS Which version of python will be explained in Alan Gauld's new = book??? ------=_NextPart_000_000F_01C03DF3.552E0340 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am sorry to bother you but I am getting confused = after=20 reading the tutorials.  I am hoping that I = can get=20 some instructions that will make sense to my small = brain.
I download and installed python 2.0 with the windows = installer.  I am running it on a Win 98se.  I have been = reading the=20 tutorials and  trying to make sense of them in reference to python=20 2.0. 
 
I have been wondering if it was wise to download = this=20 version???
 
The installation program installed two icons in the = start=20 menu.  One for python and one for the python gui (What is the = python=20 gui?). 
I know that python works in the interactive mode = because I=20 tried it.
 
My question is what do I do next?
Some of the tutorials and readme files talk having = MS VC++ and=20 others talk about pcbuild.??????
 
I tried adding python to the autoexec.bat but it = didn't seem=20 to run at the c prompt.
What do I need to do to get it to run the hello.py = text file=20 that I saved????
 
Thanks for your time
 
Jim Conway
 
PS  Which version of python will be explained = in Alan=20 Gauld's new book???
------=_NextPart_000_000F_01C03DF3.552E0340-- From wheelege@tsn.cc Wed Oct 25 04:58:34 2000 From: wheelege@tsn.cc (wheelege) Date: Wed, 25 Oct 2000 13:58:34 +1000 Subject: [Tutor] Python 2.0 newbie questions References: <001201c03e2e$023c5520$0cddaec7@conway> Message-ID: <003f01c03e37$d96a0020$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_003C_01C03E8B.AA55CD60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Well, it really depends on which tutorial you are looking through. I = hope no-one minds me jumping in here and answering this :) Python 2 is better for alot of things, and the way I understand it is = that in some instances 1.6 is more leniant so some 1.6 py scripts will = not work in 2.0, but overall 2.0 is much better. In the file menu in the interactive python interpreter, click on new = and type in or copy and paste your program (careful with the indents) or = just click on open to open it. Then in the Edit you can run the = program. I hope this helps. ----- Original Message -----=20 From: The Conways=20 To: tutor@python.org=20 Sent: Wednesday, October 25, 2000 12:48 PM Subject: [Tutor] Python 2.0 newbie questions I am sorry to bother you but I am getting confused after reading the = tutorials. I am hoping that I can get some instructions that will make = sense to my small brain. I download and installed python 2.0 with the windows installer. I am = running it on a Win 98se. I have been reading the tutorials and trying = to make sense of them in reference to python 2.0. =20 I have been wondering if it was wise to download this version??? The installation program installed two icons in the start menu. One = for python and one for the python gui (What is the python gui?). =20 I know that python works in the interactive mode because I tried it. My question is what do I do next? Some of the tutorials and readme files talk having MS VC++ and others = talk about pcbuild.?????? I tried adding python to the autoexec.bat but it didn't seem to run at = the c prompt. What do I need to do to get it to run the hello.py text file that I = saved???? Thanks for your time Jim Conway PS Which version of python will be explained in Alan Gauld's new = book??? ------=_NextPart_000_003C_01C03E8B.AA55CD60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Well, it really depends on which tutorial you are looking=20 through.  I hope no-one minds me jumping in here and answering this = :)
  Python 2 is better for alot of things, and the way I = understand it=20 is that in some instances 1.6 is more leniant so some 1.6 py scripts = will not=20 work in 2.0, but overall 2.0 is much better.
  In the file menu in the interactive python interpreter, = click on new=20 and type in or copy and paste your program (careful with the indents) or = just=20 click on open to open it.  Then in the Edit you can run the = program.
 
  I hope this helps.
 
 
----- Original Message -----
From:=20 The=20 Conways
Sent: Wednesday, October 25, = 2000 12:48=20 PM
Subject: [Tutor] Python 2.0 = newbie=20 questions

I am sorry to bother you but I am getting confused = after=20 reading the tutorials.  I am hoping that I = can get=20 some instructions that will make sense to my small = brain.
I download and installed python 2.0 with the = windows=20 installer.  I am running it on a Win 98se.  I have been = reading the=20 tutorials and  trying to make sense of them in reference to = python=20 2.0. 
 
I have been wondering if it was wise to download = this=20 version???
 
The installation program installed two icons in = the start=20 menu.  One for python and one for the python gui (What is the = python=20 gui?). 
I know that python works in the interactive mode = because I=20 tried it.
 
My question is what do I do next?
Some of the tutorials and readme files talk having = MS VC++=20 and others talk about pcbuild.??????
 
I tried adding python to the autoexec.bat but it = didn't seem=20 to run at the c prompt.
What do I need to do to get it to run the hello.py = text file=20 that I saved????
 
Thanks for your time
 
Jim Conway
 
PS  Which version of python will be explained = in Alan=20 Gauld's new book???
------=_NextPart_000_003C_01C03E8B.AA55CD60-- From gtnorton@earthlink.net Wed Oct 25 06:45:52 2000 From: gtnorton@earthlink.net (Glenn T. Norton) Date: Tue, 24 Oct 2000 22:45:52 -0700 Subject: [Tutor] Python 2.0 newbie questions References: <001201c03e2e$023c5520$0cddaec7@conway> Message-ID: <39F6738F.DF4C22A4@earthlink.net> I also run Windows. here's how to run your scripts : You can just run them through IDLE as descibed by the previous reply , or............ First make sure your path is set. Here's what I have(on Win98): SET PATH=C:\PYTHON20;%PATH% I can't remember if the installer put it here or not, but anyway... Create a folder in the Python directory, such as "mypython". Create the file, such as "hello.py" Save it in the "mypython" directory. Go to the command line, IDLE or PythonWin and at the prompt, type... import os os.chdir('C:\PYTHON20\MYPYTHON') #make sure to include the single quotes import hello Good luck, G.T. Norton The Conways wrote: > I am sorry to bother you but I am getting confused after reading the > tutorials. I am hoping that I can get some instructions that will > make sense to my small brain.I download and installed python 2.0 with > the windows installer. I am running it on a Win 98se. I have been > reading the tutorials and trying to make sense of them in reference > to python 2.0. I have been wondering if it was wise to download this > version??? The installation program installed two icons in the start > menu. One for python and one for the python gui (What is the python > gui?).I know that python works in the interactive mode because I tried > it. My question is what do I do next?Some of the tutorials and readme > files talk having MS VC++ and others talk about pcbuild.?????? I tried > adding python to the autoexec.bat but it didn't seem to run at the c > prompt.What do I need to do to get it to run the hello.py text file > that I saved???? Thanks for your time Jim Conway PS Which version of > python will be explained in Alan Gauld's new book??? From dsh8290@rit.edu Wed Oct 25 15:41:43 2000 From: dsh8290@rit.edu (D-Man) Date: Wed, 25 Oct 2000 10:41:43 -0400 Subject: [Tutor] Python 2.0 newbie questions In-Reply-To: <39F6738F.DF4C22A4@earthlink.net>; from gtnorton@earthlink.net on Wed, Oct 25, 2000 at 01:45:52 -0400 References: <001201c03e2e$023c5520$0cddaec7@conway> <39F6738F.DF4C22A4@earthlink.net> Message-ID: <20001025104143.A19324@dman.rh.rit.edu> I haven't been in windows for a while, but I believe that if your mime types are set up properly, you can just double-click on the .py file (in explorer). Also, from the command line you can type (if the path is set) > python myfile.py (if the path is not set) > C:\path\to\python\install\dir\python myfile.py (replace 'C' with the appropriate drive letter) Does windows have an equivalent of the Unix '#!'? If so that can be used to make your python script executable like any other program. DIgression to Unix features: on a unix box, make the first line of the .py file "#!/usr/bin/env python" and set the permissions to 'executable' (chmod u+x myfile.py) then you can run it like ./myfile.py Wouldn't it be nice if windows could run shell/python scripts as arbitrarily as this (using #!)? -D On Wed, 25 Oct 2000 01:45:52 Glenn T. Norton wrote: > I also run Windows. here's how to run your scripts : > You can just run them through IDLE as descibed by the previous reply , > or............ > First make sure your path is set. Here's what I have(on Win98): SET > PATH=C:\PYTHON20;%PATH% > I can't remember if the installer put it here or not, but anyway... > Create a folder in the Python directory, such as "mypython". > Create the file, such as "hello.py" > Save it in the "mypython" directory. > Go to the command line, IDLE or PythonWin and at the prompt, type... > import os > os.chdir('C:\PYTHON20\MYPYTHON') #make sure to include the single > quotes > import hello > > Good luck, > G.T. Norton > > > The Conways wrote: > > > I am sorry to bother you but I am getting confused after reading the > > tutorials. I am hoping that I can get some instructions that will > > make sense to my small brain.I download and installed python 2.0 with > > the windows installer. I am running it on a Win 98se. I have been > > reading the tutorials and trying to make sense of them in reference > > to python 2.0. I have been wondering if it was wise to download this > > version??? The installation program installed two icons in the start > > menu. One for python and one for the python gui (What is the python > > gui?).I know that python works in the interactive mode because I tried > > it. My question is what do I do next?Some of the tutorials and readme > > files talk having MS VC++ and others talk about pcbuild.?????? I tried > > adding python to the autoexec.bat but it didn't seem to run at the c > > prompt.What do I need to do to get it to run the hello.py text file > > that I saved???? Thanks for your time Jim Conway PS Which version of > > python will be explained in Alan Gauld's new book??? > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From dwainh@corp.earthlink.net Wed Oct 25 17:41:40 2000 From: dwainh@corp.earthlink.net (Dwain Hargrave) Date: Wed, 25 Oct 2000 11:41:40 -0500 Subject: [Tutor] simple copy within a python script Message-ID: <39F70D44.B86AFC84@corp.earthlink.net> Writing a python script to find a string in a file and replace it with another. But before I manipulate the file I want to make a copy of the file. How within the python script can I do this? Working on a Unix platform. -- Dwain Hargrave Unix Systems Administrator Earthlink Inc. From dwainh@corp.earthlink.net Wed Oct 25 17:58:03 2000 From: dwainh@corp.earthlink.net (Dwain Hargrave) Date: Wed, 25 Oct 2000 11:58:03 -0500 Subject: [Tutor] many appologies Message-ID: <39F7111B.C3E9AFAA@corp.earthlink.net> Sorry, I didn't dig deeper into the documentation before spamming the question. I found this... 4.46. How do I copy a file? Most of the time this will do: infile = open("file.in", "rb") outfile = open("file.out", "wb") outfile.write(infile.read()) However for huge files you may want to do the reads/writes in pieces (or you may have to), and if you dig deeper you may find other technical problems. Again... sorry. :) -- Dwain Hargrave Unix Systems Administrator Earthlink Inc. From mbc2@netdoor.com Wed Oct 25 18:09:19 2000 From: mbc2@netdoor.com (Brad Chandler) Date: Wed, 25 Oct 2000 12:09:19 -0500 Subject: [Tutor] simple copy within a python script References: <39F70D44.B86AFC84@corp.earthlink.net> Message-ID: <002101c03ea6$50a8b1e0$111c0d0a@spb.state.ms.us> > Writing a python script to find a string in a file and replace it with > another. But before I manipulate the file I want to make a copy of the > file. How within the python script can I do this? Working on a Unix > platform. If you just want to make a duplicate of the file, you can import the shutil module and use the following: shutil.copy2(frompath,topath) The shutil.copy2 will retain the original access, modified, etc.. dates whereas the shutil.copy will change all of those. Brad Chandler From dwainh@corp.earthlink.net Wed Oct 25 22:20:11 2000 From: dwainh@corp.earthlink.net (Dwain Hargrave) Date: Wed, 25 Oct 2000 16:20:11 -0500 Subject: [Tutor] working with os module Message-ID: <39F74E8B.D22F7C39@corp.earthlink.net> If I have a range of directories named "log1" through "log15" in a UNIX environment. I want to cd to the the log1 directory to work with some files and add another sub-directory, then cd to log2... How can this be accomplished. This is the train of thought I was going. I'm very new to python. Resisting the urge by my peers to use Perl. #! /usr/bin/python import sys, os x = 0 for x in range(1,16): if x < 16: os.chdir("/fake/structure/log") os.mkdir("archive") print "Added /fake/structure/log", x <-- side question how would I have it move to the left one space else: print "------------" print "I'm all done" -- Dwain Hargrave Unix Systems Administrator Earthlink Inc. From danialorena@yahoo.com Wed Oct 25 22:27:03 2000 From: danialorena@yahoo.com (Dania Lorena) Date: Wed, 25 Oct 2000 14:27:03 -0700 (PDT) Subject: [Tutor] I want to sign up... Message-ID: <20001025212703.99497.qmail@web10408.mail.yahoo.com> For tutoring in python. My name is Dania Martinez danialorena@yahoo.com __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/ From deirdre@deirdre.net Wed Oct 25 22:37:33 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 25 Oct 2000 14:37:33 -0700 (PDT) Subject: [Tutor] working with os module In-Reply-To: <39F74E8B.D22F7C39@corp.earthlink.net> Message-ID: On Wed, 25 Oct 2000, Dwain Hargrave wrote: > If I have a range of directories named "log1" through "log15" in a > UNIX environment. > > I want to cd to the the log1 directory to work with some files and add > another sub-directory, then cd to log2... You can have it move directories without actually using cd (unlike, say, php). > How can this be accomplished. This is the train of thought I was > going. I'm very new to python. Resisting the urge by my peers to use > Perl. > > #! /usr/bin/python > > import sys, os > > x = 0 > > for x in range(1,16): > if x < 16: > os.chdir("/fake/structure/log") > os.mkdir("archive") s = Added /fake/structure/log" + x print s > print "Added /fake/structure/log", x <-- side question how would I > have it move to the left one space -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From deirdre@deirdre.net Wed Oct 25 22:48:21 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 25 Oct 2000 14:48:21 -0700 (PDT) Subject: [Tutor] working with os module In-Reply-To: Message-ID: On Wed, 25 Oct 2000, Deirdre Saoirse wrote: ::sigh:: > s = Added /fake/structure/log" + x s = "Added /fake/structure/log" + x > print s -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From SBrunning@trisystems.co.uk Thu Oct 26 08:54:13 2000 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Thu, 26 Oct 2000 08:54:13 +0100 Subject: [Tutor] simple copy within a python script Message-ID: <31575A892FF6D1118F5800600846864D5B1339@intrepid> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C03F21.EEEEA7E4 Content-Type: text/plain Dwain, You might find the attached script useful - it allows you to set up a simple text file containing a list of from and to values (tab separated by default), and to apply those replacements to multiple files. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk <> > -----Original Message----- > From: Dwain Hargrave [SMTP:dwainh@corp.earthlink.net] > Sent: Wednesday, October 25, 2000 5:42 PM > To: 'tutor@python.org' > Subject: [Tutor] simple copy within a python script > > Writing a python script to find a string in a file and replace it with > another. But before I manipulate the file I want to make a copy of the > file. How within the python script can I do this? Working on a Unix > platform. > > -- > Dwain Hargrave > Unix Systems Administrator > Earthlink Inc. > > > > > _______________________________________________ > 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. ------_=_NextPart_000_01C03F21.EEEEA7E4 Content-Type: application/octet-stream; name="multirep.py" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="multirep.py" #!/usr/bin/env python # Module : multirep.py # Synopsis : Multiple replacements # Programmer : Simon Brunning - sbrunning@bigfoot.com # Date : 20/09/2000 # Notes : Thanks to Fredrik Lundh for the MultiReplace class, = which I have butchered. '''Perform multiple replacements. Takes a list of delimited from and to values from a replacements file, and replaces the from values with the to values in the target file(s). The target files are not changed - new version(s) of the target file(s) are written, with the filename prefixed. Usage : Python multirep.py [options] replacementsfile targetfile(s) Options: -h =3D help -d =3D delimiter (defaults to tabs, s =3D spaces, c =3D = commas) -p =3D prefix for new files (defaults to 'New') -c =3D case insensitive match -w =3D replace whole words only''' import sys, re def multirep(arguments): import getopt, glob, operator =20 # Split arguments list into options and arguments options, arguments =3D getopt.getopt(arguments, '?hd:p:wc') # Set defaults delimiter =3D '\t' prefix =3D 'New' wholeWords =3D None caseInsensitive =3D None # Options - override defaults ond show help =20 for option, value in options: if option[-1] in '?h': print; print __doc__ elif option[-1] =3D=3D 'd': # Specify delimiter if value =3D=3D 's': delimiter =3D ' ' elif value =3D=3D 'c': delimiter =3D ',' elif option[-1] =3D=3D 'p': # Specify prefix prefix =3D value elif option[-1] =3D=3D 'w': # Whole words wholeWords =3D 1 elif option[-1] =3D=3D 'c': # case insensitive caseInsensitive =3D 1 # 1st argument is the replacements file try: replacementsFile =3D arguments[0] except IndexError: print; print __doc__ return # Expand remaining arguments into target file list try: targetFiles =3D reduce(operator.add, map(glob.glob, = arguments[1:])) except TypeError: print; print __doc__ return except AssertionError: print; print 'Invalid replacements file.' return # Build replacement object from replacements file multiReplace =3D getReplacements(replacementsFile, delimiter, = wholeWords, caseInsensitive) # Perform replacement on each file for file in targetFiles: replaceFile(file, multiReplace, prefix) def getReplacements(replacementsFile, delimiter=3D'\t', = wholeWords=3DNone, caseInsensitive=3DNone): =20 replacementsFile =3D open(replacementsFile, 'r') # Open = replacements file. replacements =3D {} # Empty dictionary for replacements # For each =20 while 1: line =3D replacementsFile.readline() if line =3D=3D '': # EOF break replacement =3D line.split(delimiter) # Split line assert len(replacement) > 1 # There should be both a from and = to value while replacement[1][-1] in '\r\n': # Strip newlines replacement[1] =3D replacement[1][:-1] replacements[replacement[0]] =3D replacement[1] # Add to = dictionary replacementsFile.close() # Close replacements file return MultiReplace(replacements, wholeWords, caseInsensitive) # = Build replacement object from dictionary def replaceFile(file, multiReplace, prefix=3D'New'): import os infile =3D open(file, 'rb') filedata =3D infile.read() infile.close() filedata =3D multiReplace.replace(filedata) =20 outfile =3D os.path.join(os.path.dirname(file), # To-file name ' '.join((prefix, os.path.basename(file)))) outfile =3D open(outfile, 'wb') outfile.write(filedata) outfile.close() class MultiReplace: def __init__(self, replacements, wholeWords=3DNone, = caseInsensitive=3DNone): self.wholeWords =3D wholeWords self.charMap =3D None self.replacements =3D replacements =20 # Assume char to char mapping... if not wholeWords: charMap =3D map(chr, range(256)) for fromVal, toVal in replacements.items(): if len(fromVal) <> 1 or len(toVal) <> 1: break if caseInsensitive: charMap[ord(fromVal.upper())] =3D toVal charMap[ord(fromVal.lower())] =3D toVal else: charMap[ord(fromVal)] =3D toVal else: self.charMap =3D "".join(charMap) return # String to string mapping - use a regular expression =20 fromVals =3D replacements.keys() fromVals.sort() # lexical order if not wholeWords: # Build re pattern rePattern =3D '|'.join(map(re.escape, fromVals)) else: rePattern =3D r'\b(' + '|'.join(map(re.escape, fromVals)) + = r')\b' =20 if caseInsensitive: # Compile re self.rePattern =3D re.compile(rePattern, re.I) else: self.rePattern =3D re.compile(rePattern) def replace(self, string): # apply replacement to string =20 if self.charMap: # Char to char mapping return string.translate(self.charMap) # String to string mapping =20 return self.rePattern.sub(self.__replaceInMatch, string) =20 def __replaceInMatch(self, match): item =3D match.group(0) return self.replacements.get(item, item) =20 if __name__ =3D=3D '__main__': multirep(sys.argv[1:]) ------_=_NextPart_000_01C03F21.EEEEA7E4-- From jcosby@wolfenet.com Thu Oct 26 17:19:48 2000 From: jcosby@wolfenet.com (Jon Cosby) Date: Thu, 26 Oct 2000 09:19:48 -0700 Subject: [Tutor] Python and CGI Message-ID: In running a CGI script in Personal Web Server and Python 2.0, I'm getting the error message The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: C:\Program Files\Python20\python.exe: can't open file 'C:\Inetpub\wwwroot\GetLink.cgi' The Local path is C:\Inetpub\wwwroot\cgi-bin\GetLink.cgi. Can anybody tell me what the problem is here? Jon Cosby Email: jcosby@wolfenet.com Website: http://www.wolfenet.com/~jcosby From shaleh@valinux.com Thu Oct 26 17:54:38 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 26 Oct 2000 09:54:38 -0700 (PDT) Subject: [Tutor] Python and CGI In-Reply-To: Message-ID: EVERY cgi must do: print "Content-type: text/html\n" before ANY printing occurs. Note there should be TWO \n's, print does one of them for you. From dwainh@corp.earthlink.net Thu Oct 26 20:02:59 2000 From: dwainh@corp.earthlink.net (Dwain Hargrave) Date: Thu, 26 Oct 2000 14:02:59 -0500 Subject: [Tutor] os module continued References: Message-ID: <39F87FE2.1219855C@corp.earthlink.net> Deirdre Saoirse wrote: > On Wed, 25 Oct 2000, Deirdre Saoirse wrote: > > ::sigh:: > > > s = Added /fake/structure/log" + x > s = "Added /fake/structure/log" + x Didn't work... why? Because it seemed to be treating x as a number > > print s import sys, os x = 0 for x in range(1,16): if x < 16: s = "/fake/structure/log%d" % (x) <-- this line solved my problem to get it to changed directories os.chdir(s) os.mkdir("archive") print "Added", s print "------------" print "I'm all done" -- Dwain Hargrave Unix Systems Administrator Earthlink Inc. From deirdre@deirdre.net Thu Oct 26 20:16:02 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 26 Oct 2000 12:16:02 -0700 (PDT) Subject: [Tutor] Re: os module continued In-Reply-To: <39F87FE2.1219855C@corp.earthlink.net> Message-ID: On Thu, 26 Oct 2000, Dwain Hargrave wrote: > > s = "Added /fake/structure/log" + x > > Didn't work... why? Because it seemed to be treating x as a number Ah, right, str(x) (yesterday was a very long day on very little sleep) > s = "/fake/structure/log%d" % (x) <-- this line solved my problem Yes, you can also use %s (for numbers, there's no distinction and it doesn't seem to be a performance hit) -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "You had thesaurus flakes for breakfast again, didn't you?" -- Eric Williams From dsh8290@rit.edu Thu Oct 26 20:53:04 2000 From: dsh8290@rit.edu (D-Man) Date: Thu, 26 Oct 2000 15:53:04 -0400 Subject: [Tutor] os module continued In-Reply-To: <39F87FE2.1219855C@corp.earthlink.net>; from dwainh@corp.earthlink.net on Thu, Oct 26, 2000 at 15:02:59 -0400 References: <39F87FE2.1219855C@corp.earthlink.net> Message-ID: <20001026155304.B22852@dman.rh.rit.edu> That's one solution. Another is to convert x to a string: s = "Added /fake/structure/log" + `x` or s = "Added /fake/structure/log" + str( x ) The backquotes in the first example are a shortcut to call the str() funciton in the second example. -D On Thu, 26 Oct 2000 15:02:59 Dwain Hargrave wrote: > > s = "Added /fake/structure/log" + x > > Didn't work... why? Because it seemed to be treating x as a number > > s = "/fake/structure/log%d" % (x) <-- this line solved my problem From scarblac@pino.selwerd.nl Thu Oct 26 21:03:22 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 26 Oct 2000 22:03:22 +0200 Subject: [Tutor] os module continued In-Reply-To: <20001026155304.B22852@dman.rh.rit.edu>; from dsh8290@rit.edu on Thu, Oct 26, 2000 at 03:53:04PM -0400 References: <39F87FE2.1219855C@corp.earthlink.net> <20001026155304.B22852@dman.rh.rit.edu> Message-ID: <20001026220322.A5814@pino.selwerd.nl> On Thu, Oct 26, 2000 at 03:53:04PM -0400, D-Man wrote: > > That's one solution. > Another is to convert x to a string: > > s = "Added /fake/structure/log" + `x` > > or > > s = "Added /fake/structure/log" + str( x ) > > > The backquotes in the first example are a shortcut to call the str() funciton in the second example. Actually, the backquotes call repr(), which is often subtly different from str(). str() is meant to be seen by users, whereas repr() is meant as a representation that could be used by Python (eval(repr(x)) == x, ideally). Compare repr() and str() of a string, or of a floating point number in 1.6 or 2.0... -- Remco Gerlich From alan.gauld@bt.com Fri Oct 27 11:07:58 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 27 Oct 2000 11:07:58 +0100 Subject: [Tutor] Python 2.0 newbie questions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3B7@mbtlipnt02.btlabs.bt.co.uk> > My question is what do I do next? I assume the 'Python GUI' is simply a shortcut to IDLE which is a nicer environment for writing Python than the DOS box or notepad. > What do I need to do to get it to run the hello.py text file > that I saved???? From the command prompt(DOS or Start|Run) type: C:> python hello.py You should see the output of your script (or an error message if you got it wrong!) > PS Which version of python will be explained in Alan Gauld's > new book??? Python 1.5.2 is included on the CD ROM and recommended for the examples. Python v2 is included on the CD but the reader is recommended to wait till they have completed the book before 'upgrading'. The reason is simple: I haven't had time to check all the code works without change in Python 2. I expect it will since it is only a basic subset. I don't teach or use anything very exotic in the book since I'm trying to demonstrate techniques that work in any language, not just Python. If enough copies sell to warrant a second edition it will be based on Python 2 (or maybe 3 by that time?!) I'm currently reviewing the typset page proofs BTW and to my very biased eyes it looks good. :-) Alan G. From alan.gauld@bt.com Fri Oct 27 11:11:50 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 27 Oct 2000 11:11:50 +0100 Subject: [Tutor] Python 2.0 newbie questions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3B8@mbtlipnt02.btlabs.bt.co.uk> > First make sure your path is set. Here's what I have(on Win98): SET > PATH=C:\PYTHON20;%PATH% > Create a folder in the Python directory, such as "mypython". > Create the file, such as "hello.py" > Save it in the "mypython" directory. In which case you should also add to your AUTOEXEC: SET PYTHONPATH=C:\PYTHON20\MYPYTHON Then you don't need to do this: > Go to the command line, IDLE or PythonWin and at the prompt, type... > import os > os.chdir('C:\PYTHON20\MYPYTHON') #make sure to include the single > quotes Since Python now knows where to look for your modules when you do: > import hello HTH, Alan G. From gerrit.haase@t-online.de Sat Oct 28 02:41:45 2000 From: gerrit.haase@t-online.de (Gerrit Haase) Date: Sat, 28 Oct 2000 03:41:45 +0200 Subject: [Tutor] I want to sign up... In-Reply-To: <20001025212703.99497.qmail@web10408.mail.yahoo.com> Message-ID: <39FA4AF9.1804.4B5E9E@localhost> Von: Dania Lorena An: tutor@python.org Betreff: [Tutor] I want to sign up... Datum: Wed, 25 Oct 2000 14:27:03 -0700 (PDT) > For tutoring in python. > My name is Dania Martinez > danialorena@yahoo.com > I see, there is no answer yet, so I do it: look here to subscribe: http://www.python.org/mailman/listinfo/tutor - gph - -- Gerrit Peter Haase From gerrit.haase@t-online.de Sat Oct 28 02:44:57 2000 From: gerrit.haase@t-online.de (Gerrit Haase) Date: Sat, 28 Oct 2000 03:44:57 +0200 Subject: [Tutor] joining mailing list In-Reply-To: Message-ID: <39FA4BB9.10495.4E4E03@localhost> Von: "Stahl, Carissa" An: "'tutor@python.org'" Betreff: [Tutor] joining mailing list Datum: Mon, 23 Oct 2000 13:44:14 -0400 > Please place me on your mailing list... > carissa.stahl@icn.siemens.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor I see, there is no answer yet, so I do it: look here to subscribe: http://www.python.org/mailman/listinfo/tutor - gph - -- Gerrit Peter Haase From wheelege@tsn.cc Sat Oct 28 04:05:08 2000 From: wheelege@tsn.cc (wheelege) Date: Sat, 28 Oct 2000 13:05:08 +1000 Subject: [Tutor] tkinter newbie problem Message-ID: <003a01c0408b$e1e3ac00$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_0037_01C040DF.B2E04220 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all. This is probably so mind-numbingly simple but hey - I'm a = newbie. can anyone see any problems with this? from Tkinter import * root =3D Tk() root.title("I'm a Tkinter Program !") mBar =3D Frame(root, relief=3DRAISED, borderwidth=3D2) mBar.pack(fill=3DX) CmdBtn =3D makeCommandMenu() mBar.tk_menuBar(CmdBtn)#, CasBtn, ChkBtn, RadBtn, NoMenu) def makeCommandMenu(): CmdBtn =3D Menubutton(mBar, text=3D'Button Commands', underline=3D0) CmdBtn.pack(side=3DLEFT, padx=3D"2m") CmdBtn.menu =3D Menu(CmdBtn) CmdBtn.menu.add_command(label=3D"Undo") CmdBtn.menu.entryconfig(0, state=3DDISABLED) CmdBtn.menu.add_command(label=3D'New...', underline=3D0, = command=3Dnew_file) CmdBtn.menu.add_command(label=3D'Open...', underline=3D0, = command=3Dopen_file) CmdBtn.menu.add_command(label=3D'Wild Font', underline=3D0, font=3D('Tempus Sans ITC', 14), = command=3Dstub_action) CmdBtn.menu.add_command(bitmap=3D"@bitmaps/RotateLeft") CmdBtn.menu.add('separator') CmdBtn.menu.add_command(label=3D'Quit', underline=3D0, background=3D'white', = activebackground=3D'green', command=3DCmdBtn.quit) print 'bitch' CmdBtn['menu'] =3D CmdBtn.menu return CmdBtn root.mainloop() This is almost exactly copied from John Grayson's book, but I cut some = things from it. I'm using Python 2.0. It keeps telling me there is an error with the = makeCommandMenu thing, says there is no such variable as mbar. Help! ------=_NextPart_000_0037_01C040DF.B2E04220 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hi all.  This is probably so mind-numbingly simple but = hey -=20 I'm a newbie.
 
can anyone see any problems with this?
 
from Tkinter import *
root =3D Tk()
root.title("I'm a Tkinter = Program=20 !")
 
mBar =3D Frame(root, relief=3DRAISED,=20 borderwidth=3D2)
mBar.pack(fill=3DX)
CmdBtn =3D=20 makeCommandMenu()
mBar.tk_menuBar(CmdBtn)#, CasBtn, ChkBtn, RadBtn,=20 NoMenu)
def makeCommandMenu():
    CmdBtn =3D=20 Menubutton(mBar, text=3D'Button Commands', = underline=3D0)
   =20 CmdBtn.pack(side=3DLEFT, padx=3D"2m")
    CmdBtn.menu = =3D=20 Menu(CmdBtn)
   =20 CmdBtn.menu.add_command(label=3D"Undo")
   =20 CmdBtn.menu.entryconfig(0, state=3DDISABLED)
   =20 CmdBtn.menu.add_command(label=3D'New...', underline=3D0,=20 command=3Dnew_file)
    = CmdBtn.menu.add_command(label=3D'Open...',=20 underline=3D0, command=3Dopen_file)
   =20 CmdBtn.menu.add_command(label=3D'Wild Font',=20 underline=3D0,
         &= nbsp;           &n= bsp;     =20 font=3D('Tempus Sans ITC', 14), = command=3Dstub_action)
   =20 CmdBtn.menu.add_command(bitmap=3D"@bitmaps/RotateLeft")
  &n= bsp;=20 CmdBtn.menu.add('separator')
   =20 CmdBtn.menu.add_command(label=3D'Quit',=20 underline=3D0,
         &= nbsp;           &n= bsp;     =20 background=3D'white',=20 activebackground=3D'green',
       =             &= nbsp;       =20 command=3DCmdBtn.quit)
    print = 'bitch'
   =20 CmdBtn['menu'] =3D CmdBtn.menu
    return = CmdBtn
root.mainloop()
This is almost exactly copied from John Grayson's book, but I cut = some=20 things from it.
I'm using Python 2.0.  It keeps telling me there is an error = with the=20 makeCommandMenu thing,
says there is no such variable as mbar.
 
Help!
------=_NextPart_000_0037_01C040DF.B2E04220-- From gtnorton@earthlink.net Sat Oct 28 04:35:44 2000 From: gtnorton@earthlink.net (Glenn T. Norton) Date: Fri, 27 Oct 2000 20:35:44 -0700 Subject: [Tutor] Python 2.0 newbie questions References: <5104D4DBC598D211B5FE0000F8FE7EB20751D3B8@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <39FA4990.B6E6040F@earthlink.net> alan.gauld@bt.com wrote: > > First make sure your path is set. Here's what I have(on Win98): SET > > PATH=C:\PYTHON20;%PATH% > > > Create a folder in the Python directory, such as "mypython". > > Create the file, such as "hello.py" > > Save it in the "mypython" directory. > > >In which case you should also add to your AUTOEXEC: > >SET PYTHONPATH=C:\PYTHON20\MYPYTHON > Then you don't need to do this: > Go to the command line, IDLE or PythonWin and at the prompt, type... > import os > os.chdir('C:\PYTHON20\MYPYTHON') #make sure to include the single > quotes Is this in anyway wrong? meaning is it dangerous or flatout wrong to import modules this way?. I just find that it's a little quicker to use "import os/os.chdir(' ')" and include the path in the IDLE path browser than to add to my already bloated AUTOEXEC and reboot windows everytime I create a new project folder. Looking forward to the your book. Regards, gtnorton > > > From wheelege@tsn.cc Sat Oct 28 15:40:35 2000 From: wheelege@tsn.cc (wheelege) Date: Sun, 29 Oct 2000 00:40:35 +1000 Subject: [Tutor] really really silly question Message-ID: <004301c040ed$0907b220$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_0040_01C04140.DA25DA00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I saw the sleep command in the python documentation and tried to use = it - but no matter how hard I try I get an error saying the variable = 'sleep' does not exist. Help! ------=_NextPart_000_0040_01C04140.DA25DA00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  I saw the sleep command in the python documentation and = tried to use=20 it - but no matter how hard I try I get an error saying the variable = 'sleep'=20 does not exist.  Help!
------=_NextPart_000_0040_01C04140.DA25DA00-- From DOUGS@oceanic.com Sat Oct 28 15:57:07 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sat, 28 Oct 2000 04:57:07 -1000 Subject: [Tutor] really really silly question Message-ID: <8457258D741DD411BD3D0050DA62365907A3DB@huina.oceanic.com> There are no silly or stupid questions in this group. Feel free to ask away. > I saw the sleep command in the python documentation > and tried to use it - but no matter how hard I try I > get an error saying the variable 'sleep' does not exist. Sleep is a part of the time module. That means time has to be imported before sleep will be recognized as a valid name. Here's an example #!/usr/bin/env python import time print "The beginning of time." time.sleep(5.9) # not sure the documents mention that fractions work too print "The end of time." > Help! Hope this did. -Doug- From wheelege@tsn.cc Sat Oct 28 17:01:20 2000 From: wheelege@tsn.cc (wheelege) Date: Sun, 29 Oct 2000 03:01:20 +1100 Subject: [Tutor] really really silly question References: <8457258D741DD411BD3D0050DA62365907A3DB@huina.oceanic.com> Message-ID: <005b01c040f8$50fb7de0$a410fea9@glen> Thanks alot. Floating point integers work in the sleep function, otherwise I wouldn't be able to use it. I'm making an arkanoid game - it's going pretty cool right now, and I am learning alot. Hope everyone can bear with me :) Glen From nothingisgoingtochangemyworld@yahoo.com Sat Oct 28 19:57:40 2000 From: nothingisgoingtochangemyworld@yahoo.com (Joseph Stubenrauch) Date: Sat, 28 Oct 2000 11:57:40 -0700 (PDT) Subject: [Tutor] silly TK top-level widget question Message-ID: <20001028185740.20747.qmail@web1904.mail.yahoo.com> Hello. I am sure the answer is staring me in the face, but I cannot figure this out. At one point in my program, I want a new top-level window to be created. Then, I want the user to be able to click a button (in addition to the X in the top right corner) that will close that new window. What is the command to just close the toplevel window. When I use quit, it closes down the whole program and returns me to DOS. Thanks in advance, Joe __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Sat Oct 28 20:21:50 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 12:21:50 -0700 (PDT) Subject: [Tutor] really really silly question In-Reply-To: <004301c040ed$0907b220$a410fea9@glen> Message-ID: On Sun, 29 Oct 2000, wheelege wrote: > I saw the sleep command in the python documentation and tried to use > it - but no matter how hard I try I get an error saying the variable > 'sleep' does not exist. Help! The sleep command's part of the time module, so you'll need to import time first: import time time.sleep(10) # sleep for 10 seconds or from time import sleep sleep(10) Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Oct 28 20:31:48 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 12:31:48 -0700 (PDT) Subject: [Tutor] tkinter newbie problem In-Reply-To: <003a01c0408b$e1e3ac00$a410fea9@glen> Message-ID: On Sat, 28 Oct 2000, wheelege wrote: > Hi all. This is probably so mind-numbingly simple but hey - I'm a > newbie. Don't worry about it. > can anyone see any problems with this? What's happening is that, within makeCommandMenu(), it doesn't know about variables declared outside of the function, at least unless you explicitly say that they were defined outside. This isolation is intensional --- it's good practice to explicitly pass the variables you need in the parameter list. In any case, there are a few ways of fixing this. The easiest thing to do is to tell Python to relax: mBar was declared outside of the function. We do this by saying: global mBar in the beginning of your makeCommandMenu function. The other way to fix it is to change makeCommandMenu() to take mBar as its parameter. This is better for larger programs, because then makeCommandMenu will work with any frame that you construct. ### CmdBtn = makeCommandMenu(mBar) def makeCommandMenu(mBar): # and then the rest of the stuff that you had before... ### From wheelege@tsn.cc Sun Oct 29 02:28:10 2000 From: wheelege@tsn.cc (wheelege) Date: Sun, 29 Oct 2000 13:28:10 +1100 Subject: [Tutor] calling functions with buttons - why doesn't this work?? Message-ID: <001d01c0414f$e23acca0$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_001A_01C041AC.14FBCAC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable There are alot of things I don't understand about Tkinter. I was trying to call a function from a button, and it wouldn't work. So = I wrote this little thing and even it doesn't work. When it is run it = executes hi() but not when the button is pressed. Help? As a side = note, why isn't my window title 'yo'? Here is the code... from Tkinter import * root =3D Tk() root.title =3D 'yo' def hi(): print 'hi' f =3D Frame(root) b =3D Button(text=3D'hi', command=3Dhi()) f.pack() b.pack() ------=_NextPart_000_001A_01C041AC.14FBCAC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
There are alot of things I don't understand about Tkinter.
 
I was trying to call a function from a button, and it wouldn't = work. =20 So I wrote this little thing and even it doesn't work.  When it is = run it=20 executes hi() but not when the button is pressed.  Help?  As a = side=20 note, why isn't my window title 'yo'?
 
Here is the code...
 
from Tkinter import *
root =3D Tk()
root.title =3D 'yo'
 
def hi():
    print 'hi'
 
f =3D Frame(root)
b =3D Button(text=3D'hi',=20 command=3Dhi())
f.pack()
b.pack()
------=_NextPart_000_001A_01C041AC.14FBCAC0-- From as79cs@netscape.net Sun Oct 29 02:53:09 2000 From: as79cs@netscape.net (as79cs@netscape.net) Date: Sat, 28 Oct 2000 22:53:09 -0400 Subject: [Tutor] Python 2.0 Message-ID: <6AC68366.43D9738F.0005DBA6@netscape.net> What's the link for downloading Python 2.0 for Windows 2000? From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 04:09:15 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 21:09:15 -0700 (PDT) Subject: [Tutor] Python 2.0 In-Reply-To: <6AC68366.43D9738F.0005DBA6@netscape.net> Message-ID: On Sat, 28 Oct 2000 as79cs@netscape.net wrote: > What's the link for downloading Python 2.0 for Windows 2000? The installation for Python on Windows is uniform --- it'll work for Windows 95/98/NT/2000 with no problems (hopefully!). Here's the link to it: http://www.pythonlabs.com/products/python2.0/download_python2.0.html Just choose the Windows installer, and you should be all set. If you have more questions, feel free to ask us. Good luck! From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 04:14:29 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 21:14:29 -0700 (PDT) Subject: [Tutor] calling functions with buttons - why doesn't this work?? In-Reply-To: <001d01c0414f$e23acca0$a410fea9@glen> Message-ID: On Sun, 29 Oct 2000, wheelege wrote: > I was trying to call a function from a button, and it wouldn't work. > So I wrote this little thing and even it doesn't work. When it is run > it executes hi() but not when the button is pressed. Help? As a side > note, why isn't my window title 'yo'? > f = Frame(root) > b = Button(text='hi', command=hi()) It's a subtle problem: the problem is that the command taken by Button needs to be a function. However, hi() will just call the hi() function, returning whatever hi() does. You'll want to give your button the function 'hi', not the result of what happens when you call 'hi'. To fix this, you'll want: b = Button(text='hi', command=hi) It doesn't look like much of a change, but, semantically, it's a big difference! Take a look at this interpreter session: ### >>> x = hi() hi >>> x ## 'x' contains the None value, since 'hi()' doesn't ## explicitly return anything. Now let's contrast ## this with 'hi'. >>> x = hi >>> x ### Hope this clears things up. From wheelege@tsn.cc Sun Oct 29 05:26:57 2000 From: wheelege@tsn.cc (wheelege) Date: Sun, 29 Oct 2000 16:26:57 +1100 Subject: [Tutor] I'm just full of questions today Message-ID: <007901c04168$dbba5580$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_0076_01C041C5.0E8C1C80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've been trying to get global variables to help me, the way I've been = getting around it is to pass local variables to a function through = arguments - but that is going to get very unwieldy and messy. So, I = decided to change my little section of code to give me an error about = using a local variable before assignment. I think the error is because = I tell it to change the value of the 's' variable to 's' + 1, which is = using its own value to define itself which it might not like. Not sure = though. And, as a side note - why isn't my window title 'yo'? Anyway, here is the little bit of code : from Tkinter import * root =3D Tk() root.title =3D "yo" s =3D 7 f =3D Frame(root) b =3D Button(root, text=3D'hi', command=3Dhi) f.pack() b.pack() def hi(): s =3D s + 1 print s ------=_NextPart_000_0076_01C041C5.0E8C1C80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  I've been trying to get global variables to help me, the way = I've=20 been getting around it is to pass local variables to a function through=20 arguments - but that is going to get very unwieldy and messy.  So, = I=20 decided to change my little section of code to give me an error about = using a=20 local variable before assignment.  I think the error is because I = tell it=20 to change the value of the 's' variable to 's' + 1, which is using its = own value=20 to define itself which it might not like.  Not sure though.
 
And, as a side note - why isn't my window title 'yo'?
 
Anyway, here is the little bit of code :
 
from Tkinter import *
root =3D Tk()
root.title =3D "yo"
 
s =3D 7
 
f =3D Frame(root)
b =3D Button(root, text=3D'hi',=20 command=3Dhi)
f.pack()
b.pack()
 
def hi():
    s =3D s + 1
    = print=20 s
------=_NextPart_000_0076_01C041C5.0E8C1C80-- From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 05:04:42 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 22:04:42 -0700 (PDT) Subject: [Tutor] I'm just full of questions today In-Reply-To: <007901c04168$dbba5580$a410fea9@glen> Message-ID: On Sun, 29 Oct 2000, wheelege wrote: > I've been trying to get global variables to help me, the way I've > been getting around it is to pass local variables to a function > through arguments - but that is going to get very unwieldy and messy. Global variables... nooo! *grin* One way to create callbacks that use local variables is to do a lambda. For example: ### def hi(name): print "Hello " + name + "!" # later on... b = Button(root, text='hi', command= lambda name="wheelege": hi(name)) ### Yes, this is admittedly ugly. What the lambda part is doing is creating an anonymous function with a default argument --- this gets around the fact that callbacks need to be functions that don't take arguments. If you're new to Python, this is probably the first time you've seen this. If so, email us again, and one of the tutors can give a more leisurely explanation of lambda and function passing. > So, I decided to change my little section of code to give me an error > about using a local variable before assignment. I think the error is > because I tell it to change the value of the 's' variable to 's' + 1, Don't forget about the 'global' thing that you asked about last time. > And, as a side note - why isn't my window title 'yo'? That part I'm not quite sure. You might want to look at the Tkinter documentation and check how to change the titles of frames. I'm not sure that saying f.title = "yo" is enough; you can say f.foobarish = "yo" and it wouldn't complain, but at the same time, it wouldn't do anything either. From wheelege@tsn.cc Sun Oct 29 06:23:15 2000 From: wheelege@tsn.cc (wheelege) Date: Sun, 29 Oct 2000 17:23:15 +1100 Subject: [Tutor] I'm just full of questions today References: Message-ID: <009a01c04170$b9200580$a410fea9@glen> That isn't the first time I have seen the lambda thing but I am still confused about it. I did have a look at the way to change the title of a Toplevel widget (window), and that is how it says to do it. I'll think about that later though :) Okay, so this line: b = Button(root, text='hi', command= lambda name="wheelege": hi(name)) Says, make a button, call it b, have the parent 'root', the text 'hi', and it's command is to call the function hi with the argument of 'wheelege'? Hmm....problem is, I'm trying to get about 50 arguments in there. Well, not 50 but close to it. Isn't there a way to say, eg x = int(global) ## not the right syntax, sure, but you know what I'm trying to say x = 7 And x would be global? Or isn't that applicable with Tkinter? I had an experiment with the StringVar() and IntVar() commands/methods/tk thingies but they just ended up confusing me. If I could just define everything as global then it would all be good - and I could reference those variables from anywhere in the script (so to speak). Another way to solve this, is to assign local variables the values of the vaiables that I want global. In this case, I am keeping the values of the x0,y0,x1,y1 coords for a bunch of shapes in a bunch of different lists and things. I have all the methods working fine, and everything gels (thus far) except I cannot change the values of these variables (or get their value) from inside a function/callback (the same thing?). SO what I tried initially was to re-assign the values to local variables, but alas I was foiled because I could not get them - I was always attacked with a 'variable does not exist' error. Anyway - I could ramble forever, Thanks for your help! From DOUGS@oceanic.com Sun Oct 29 06:32:25 2000 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sat, 28 Oct 2000 20:32:25 -1000 Subject: [Tutor] I'm just full of questions today Message-ID: <8457258D741DD411BD3D0050DA62365907A3DE@huina.oceanic.com> Boy was I glad to see Daniel answer this first. :-) Laid the groundwork well. Let me try to lay on a bit more. By the way, I've rearranged the flow of questions in what I hope is an instructive way. [wheelage wrote:] > That isn't the first time I have seen the lambda thing but > I am still confused about it. I am too. Thats why I like to avoid them and make the functions explicit. When I need to do a callback I prefer: class Command: def __init__(self, func, *args, **kw): self.func = func self.args = args self.kw = kw def __call__(self, *args, **kw): args = self.args + args kw.update(self.kw) return apply(self.func, args, kw) It's used like this, for example: Command(modem_form.exit,'Account') modem_form.exit is a function, 'Account' is a parameter passed to it. The above is not original to me and I've lost the attribution for which I apologize sincerely. There are some juicy bits in that little bit of code that, when understood, can go a long way to reaching the Python Zen. [wheelage again] > If I could just define everything as global then it would > all be good - and I could reference those variables from > anywhere in the script (so to speak). > > Another way to solve this, is to assign local variables the > values of the variables that I want global. You need to reexamine your concept of globals. You had code that looked like: s = 7 def hi(): s = s + 1 print s It would probably do you good to go to the Tutorial to read the section on namespaces (9.2 Python Scopes and Name Spaces). Actually having just read it it may just confuse you, but its worth the attempt. From that you might get that there are three and only three namespaces in Python; I think called builtin, global, and local. Builtin is the fundamental stuff that is always in Python when the interpreter starts. Global is what gets loaded in when you run your script/program. Local is defined on a per function basis, so for example, when the code within the def hi(): block is run it has its own namespace. In lay language that means it doesn't know about variables that were defined in the Global space, such as s, so you get a NameError. So the purpose of the global statement is to tell a local namespace that a variable from the global namespace should be used. In other words (whew!): s = 7 def hi(): global s s = s + 1 print s > Hmm....problem is, I'm trying to get about 50 arguments in > there. Well, > not 50 but close to it. The following is advice I'm giving with the expectation that you will ignore it. I know I ignored it for a long time and had to learn the hard way. Daniel also already subtly warned you off (Daniel Yoo: "Global variables... nooo! *grin*"). DON'T USE GLOBALS. DON'T USE THE GLOBAL STATEMENT. (ok, get the point ;-)) Learn to use an object to hold all that important stuff and pass it around. Better yet, write code in an object oriented way. An example of a crude way: class holder: __init__(self): pass from Tkinter import * root = Tk() root.title = "yo" holder.s = 7 f = Frame(root) hi_command = Command(hi,holder) b = Button(root, text='hi', command=hi) f.pack() b.pack() def hi(stuff): stuff.s = stuff.s + 1 print stuff.s > x0,y0,x1,y1 coords for a bunch of shapes in a bunch of > different lists and > things. I have all the methods working fine, and everything > gels (thus far) > except I cannot change the values of these variables (or get > their value) > from inside a function/callback (the same thing?). SO what I tried > initially was to re-assign the values to local variables, but > alas ... What you describe here are objects. Give them life and pass them around and let them do all the work. ;-) I hope this was not too professorial and actually helpful. I also hope that it is factual and expect better minds to correct any errors I've made. -Doug- From wheelege@tsn.cc Sun Oct 29 07:50:02 2000 From: wheelege@tsn.cc (Glen Wheeler) Date: Sun, 29 Oct 2000 18:50:02 +1100 Subject: [Tutor] Re: I'm just full of questions today Message-ID: <00c401c0417c$d8dd3620$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_00C1_01C041D9.0BB69E40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable You guys should get paid for this :) I had a read through that chapter and everything is much clearer! I = realise now what everyone means :) I haven't tried using classes to any decent extent, and I was = considering making a lot of classes that only hold data (I think they are = attributes?) that tell the script what is going on at the time. Like bdir is the direction of the ball atm (right now its a string but I will make it a bearing (true) soon, gotta get paddle movement right) and it would be = much easier to just use a ball class and then it would be ball.bdir...hmmm = why am I saying this instead of doing it? Better now before the code becomes = giant :) Here is what I did in regard to lambda ... PaddleLeft =3D Button(ButtonFrame, text=3D'left', command=3D lambda lpx1=3Dpx1, lpx2=3Dpx2, lpy1=3Dpy1, lpy2=3Dpy2:PaddleMotion('left', lpx1, lpx2, lpy1, lpy2)) PaddleLeft is a button, which is meant to move the paddle left. Here is = the PaddleMotion function (or the bit that applies). I'm only using a = button now instead of an event because it is easier - its probably going to = either use (click and drag with mouse) or something similar when I = get around to doing it. def PaddleMotion(dir, lpx1, lpx2, lpy1, lpy2): if dir =3D=3D 'left': lpx1 =3D lpx1 - 30 lpx2 =3D lpx2 - 30 Screen.coords(paddle, lpx1, lpy1, lpx2, lpy2) So it moves left. I have to re-assign the values of everything again so that it will keep moving with repeating presses of the button. I promise to give everyone a copy of the script once its finished - you don't want it now when its got a billion comments in it, and doesn't = even achieve anything useful anyway. Not to say that when it is finished it = will be useful - but hey, at least I will have an arkanoid clone :) I know I am going to look at this script in a week and find a million = ways to optimise it, actually I can do some thigns to optimise it right now - = but I think it's better big, so I can get a clearer understanding of it. I do have a question, don't worry. I am asking about threads - I read = about them in the python documentation and in some books, but I am not sure = how to incorporate them. Basically I am using one big mega-for loop to run the entire program, but in that there will be some other for loops. And I = can see the problem that when I get to those loops they are going to iterate = and finish and my main loop will pause - this is bad, cos the mainloop moves = my little ball. So I am wondering, is it feasable to use threads to do two = or more loops at the same time? Sorry if I seem tiresome, but it seems everywhere I look I see a different definition of a thread, and a = different way to use them. Thanks alot, Glen. ------=_NextPart_000_00C1_01C041D9.0BB69E40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
You guys should get paid for this :)

I had a read through = that=20 chapter and everything is much clearer!  I realise
now what = everyone=20 means :)

I haven't tried using classes to any decent extent, and = I was=20 considering
making a lot of classes that only hold data (I think they = are=20 attributes?)
that tell the script what is going on at the time.  = Like=20 bdir is the
direction of the ball atm (right now its a string but I = will make=20 it a
bearing (true) soon, gotta get paddle movement right) and it = would be=20 much
easier to just use a ball class and then it would be = ball.bdir...hmmm=20 why am
I saying this instead of doing it?  Better now before the = code=20 becomes giant
:)

Here is what I did in regard to lambda=20 ...

PaddleLeft =3D Button(ButtonFrame, text=3D'left',=20 command=3D
          = ;         =20 lambda lpx1=3Dpx1, lpx2=3Dpx2, = lpy1=3Dpy1,
lpy2=3Dpy2:PaddleMotion('left', lpx1,=20 lpx2, lpy1, lpy2))

PaddleLeft is a button, which is meant to move = the=20 paddle left.  Here is the
PaddleMotion function (or the bit that = applies).  I'm only using a button
now instead of an event = because it is=20 easier - its probably going to either
use <B1-Motion> (click = and drag=20 with mouse) or something similar when I get
around to doing = it.

def=20 PaddleMotion(dir, lpx1, lpx2, lpy1, lpy2):
    if dir = =3D=3D=20 'left':
        lpx1 =3D lpx1 -=20 30
        lpx2 =3D lpx2 -=20 30
    Screen.coords(paddle, lpx1, lpy1, lpx2, = lpy2)

So=20 it moves left.  I have to re-assign the values of everything again=20 so
that it will keep moving with repeating presses of the = button.

I=20 promise to give everyone a copy of the script once its finished - = you
don't=20 want it now when its got a billion comments in it, and doesn't = even
achieve=20 anything useful anyway.  Not to say that when it is finished it = will
be=20 useful - but hey, at least I will have an arkanoid clone :)

I = know I am=20 going to look at this script in a week and find a million ways
to = optimise=20 it, actually I can do some thigns to optimise it right now - but
I = think it's=20 better big, so I can get a clearer understanding of it.

I do have = a=20 question, don't worry.  I am asking about threads - I read = about
them in=20 the python documentation and in some books, but I am not sure how=20 to
incorporate them.  Basically I am using one big mega-for loop = to run=20 the
entire program, but in that there will be some other for = loops.  And=20 I can
see the problem that when I get to those loops they are going = to=20 iterate and
finish and my main loop will pause - this is bad, cos the = mainloop moves my
little ball.  So I am wondering, is it = feasable to use=20 threads to do two or
more loops at the same time?  Sorry if I = seem=20 tiresome, but it seems
everywhere I look I see a different definition = of a=20 thread, and a different
way to use them.

Thanks=20 alot,

Glen.
------=_NextPart_000_00C1_01C041D9.0BB69E40-- From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 06:59:51 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Oct 2000 23:59:51 -0700 (PDT) Subject: [Tutor] I'm just full of questions today In-Reply-To: <009a01c04170$b9200580$a410fea9@glen> Message-ID: On Sun, 29 Oct 2000, wheelege wrote: > Hmm....problem is, I'm trying to get about 50 arguments in there. Well, > not 50 but close to it. Isn't there a way to say, eg Hint: if you're going to have fifty variables, you might consider using a single list structure instead. Otherwise, you will be in severe pain typing all of those variables. So instead of: somefunction(x1, x2, ..., x50) using lists will make that hideous expression much more compact: somefunction(x_list) And it's fairly straighforward to create and use lists: square = [ (0,0), (1,0), (1,1), (0,1) ] triangle = [ (0,0), (1,0), (0,1) ] shapes = [square, triangle] # ... etc first_coord = square[0] # retrieving the first coordinate x, y = first_coord # and breaking it down into x and y You really really want to work with lists if you're dealing with long sequences, expecially sequences of coordinates. If you're unfamiliar with lists, email us, and we can show you how lists work. From wheelege@tsn.cc Sun Oct 29 08:06:42 2000 From: wheelege@tsn.cc (Glen Wheeler) Date: Sun, 29 Oct 2000 19:06:42 +1100 Subject: [Tutor] I'm just full of questions today References: Message-ID: <00d601c0417f$2d493b80$a410fea9@glen> Would it be ok to use a list in a class? Like, say I am manipulating block7 it would be in class Blocks and the attriute would be block7, which is a list of the coords. Is that a good way to do it? From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 07:15:20 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 29 Oct 2000 00:15:20 -0700 (PDT) Subject: [Tutor] I'm just full of questions today In-Reply-To: <00d601c0417f$2d493b80$a410fea9@glen> Message-ID: On Sun, 29 Oct 2000, Glen Wheeler wrote: > Would it be ok to use a list in a class? > > Like, say I am manipulating block7 > > it would be in class Blocks and the attriute would be block7, which is > a list of the coords. Is that a good way to do it? Sure, that would work well. From dyoo@hkn.eecs.berkeley.edu Sun Oct 29 07:30:45 2000 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 29 Oct 2000 00:30:45 -0700 (PDT) Subject: [Tutor] Re: I'm just full of questions today In-Reply-To: <00c401c0417c$d8dd3620$a410fea9@glen> Message-ID: > def PaddleMotion(dir, lpx1, lpx2, lpy1, lpy2): > if dir == 'left': > lpx1 = lpx1 - 30 > lpx2 = lpx2 - 30 > Screen.coords(paddle, lpx1, lpy1, lpx2, lpy2) > > So it moves left. I have to re-assign the values of everything again so > that it will keep moving with repeating presses of the button. That looks ok. You can definitely make things look nicer if you apply some OOP on that Paddle. Here's a really quick sketch of what it might look like: #### class Paddle: def __init__(self, x1, x2, y1, y2): """Initialize a Paddle with inital coordinates x1, x2, y1, and y2.""" self.x1, self.x2, self.y1, self.y2 = x1, x2, y1, y2 def move(self, offset): self.x1, self.x2 = self.x1 - offset, self.x2 - offset ### Then you can create an instance of a paddle and use it to hold the paddle's coordinates: mypaddle = Paddle(0, 10, 0, 3) # construct a paddle mypaddle.move(-30) # tell it to move -30 print mypaddle.x1, mypaddle.x2 # and show the results of the move() One other advantage of object orientation, and objects in general, is that it'll allow you to escape a certain troublesome situation. Let's take a look at your function again: > def PaddleMotion(dir, lpx1, lpx2, lpy1, lpy2): > if dir == 'left': > lpx1 = lpx1 - 30 > lpx2 = lpx2 - 30 > Screen.coords(paddle, lpx1, lpy1, lpx2, lpy2) There's a small problem here becase any changes you make to lpx1, lpx2, lpy1, and lpy2 will be local to PaddleMotion. This might make more sense with a short, unrelated example: ### >>> def printSquare(x): ... x = x * x ... print x ... >>> num = 5 >>> printSquare(num) 25 >>> num ### Notice that nothing happens to num. That's because when we call printSquare(num), Python does something like this: x = num (now x contains the value of num, since num contains an "immutable" numeric type) x = x * x print x Within that exchange of values to parameters, x gets a copy of whatever num contained, and within the function, nothing happens to num. This is how local variables provide isolation; often, it's very helpful, but not when you want a function to modify the state of a set of variables. One way to fix this is to explicitly return those values back with the return statement: ### def PaddleMotion(dir, lpx1, lpx2, lpy1, lpy2): if dir == 'left': lpx1 = lpx1 - 30 lpx2 = lpx2 - 30 Screen.coords(paddle, lpx1, lpy1, lpx2, lpy2) return (lpx1, lpx2, lpy1, lpy2) ### and call PaddleMotion like this: x1,x2,y1,y2 = PaddleMotion('left', x1, x2, y1, y2) But already this is a little long to read. The easier approach is to accumulate those coordinates into a class, and provide methods to change the state of an instance. Hope this helps! From shadow88@intergate.bc.ca Mon Oct 30 14:35:43 2000 From: shadow88@intergate.bc.ca (shadow88@intergate.bc.ca) Date: Mon, 30 Oct 2000 09:35:43 -0500 (EST) Subject: [Tutor] Attn: Corporate Traing Coordinator - Windows 2000 Courseware Content Message-ID: <20001030143543.A6C381CE3C@dinsdale.python.org> As you restructure your IT training program and consider how you might imagine the best way of providing content for your courses, you'll find yourself appreciating course content that is already prepared and ready for immediate use in your curriculum. We design and develop books and curriculum that support Systems Engineering technologies and certifications including: · A+ · Network+ · i-Net+ · MCSE · MCDBA (Full course descriptions are available) Some of our books have been top 10 best sellers through Amazon.com. Included with this letter are descriptions of the books that we sell (see Study Guide Descriptions). I thought you might also be interested to hear about our adaptive and non-adaptive test engine slated to be available 3rd quarter, 2000. The engine is designed for practice and study. Test questions and answers are easily added, edited or deleted. We can help you with your high-tech training needs including books, books on CD, Instructor led classes and distance learning products. We also create custom high-tech curriculum for companies. We are a one-stop solution for high-tech educational content, training and resources. We offer distance learning and instructor lead products for both individuals and groups and our education solutions meet typical corporate and learning center needs. We are a Microsoft Solution Provider (MSP), Microsoft Certified Technical Education Center (CTEC) and a Computer Technology Industry Association Certified Training Center (CompTIA). We partner with a major University, an international leader in adult-instructor-lead and distance learning, to offer graduate and undergraduate credit for many of our courses. Please feel free to contact me in the meantime. I look forward to speaking with you further. Casey Lea, Creative Director or Domhnall Adams, CS DCGNA, CS and Associates 780-998-4066 From alan.gauld@bt.com Tue Oct 31 11:21:40 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 31 Oct 2000 11:21:40 -0000 Subject: [Tutor] Python 2.0 newbie questions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3BC@mbtlipnt02.btlabs.bt.co.uk> > > >In which case you should also add to your AUTOEXEC: > > >SET PYTHONPATH=C:\PYTHON20\MYPYTHON > > > Then you don't need to do this: > > import os > > os.chdir('C:\PYTHON20\MYPYTHON') #make sure to > > Is this in anyway wrong? meaning is it dangerous or flatout wrong No, its not wrong but its not very portable to have that hard path in your program. If anyone else trires to use it they will be forced to keep their modules in that exact same folder... PYTHONPATH means you can create a single place for all your Python modules and then use them in all new projects. Thus I have a folder: E:\PROJECTS\PYTHON Under that I create a LIB folder which I add to my PYTHONPATH: SET PYTHONPATH=E:\PROJECTS\PYTHON\LIB Now for each froject, spam say, I create a new project folder: E:\PROJECTS\PYTHON\SPAM And place the top level and experimental code there. But once I get a module working I move it to the LIB folder where Python can see it, not just for the current project but for every project, thus enabling reuse. Doing it your way you have to a) hard code the folder name into any program thats going to import the module and b) can only import modules from one folder at a time, which reduces(eliminates!) reuse across projects. > to import modules this way?. I just find that it's a > little quicker to use > "import os/os.chdir(' ')" and include the path in the IDLE path > browser > than to add to my already bloated AUTOEXEC and reboot windows > everytime I create a new project folder. Try this then: Create a batch file containing the set PYTHONPATH=.... called setpypath.bat Call that from AUTOEXEC.BAT. Then while programming update that file then just execute it: C:\PROJDIR> C:\SETPYPATH.BAT That will reset the environment and next time python runs it will correctly find your modules. No need for a reboot. Of course the next time you reboot all the changes will automatically be picked up too. HTH, Alan G. PS It might be necessary in AUTOEXEC to use CALL to exec the SETPYPATH.BAT, I can't remember if thats still needed in Win9x DOS. From alan.gauld@bt.com Tue Oct 31 11:27:25 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 31 Oct 2000 11:27:25 -0000 Subject: [Tutor] calling functions with buttons - why doesn't this wor k?? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D3BD@mbtlipnt02.btlabs.bt.co.uk> > There are alot of things I don't understand about Tkinter. Join the club. :-) > doesn't work. When it is run it executes hi() but not when Thats because of the ()... > def hi(): > print 'hi' > > f = Frame(root) > b = Button(text='hi', command=hi()) b = Button(text='hi', command=hi) hi is the function object. hi() executes the function and stores the return value in the command option. In your case hi() returns 'None' so clicking the button executes the empty (none) command. As to why the title doesn't work, I'm not sure but from memory, isn't the title set as a function: root.title('Hi') rather than by assignment as you have done? Alan G.