From toodles@yifan.net Thu Mar 1 00:14:56 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Thu, 1 Mar 2001 08:14:56 +0800 Subject: [Tutor] >> Best setup for animation? << In-Reply-To: <3A9D509B.DCA827DE@thestate.com> Message-ID: <FPEHJJPEEOIPMAHOADBKGEAOCCAA.toodles@yifan.net> Hi Chris, Pygame allows you to blit surfaces, but you don't need to do this as the screen isn't updated until you say so, it works on a virtual screen anyway. Take a quick squizz at the docs. As for the question "which one is better...?", well I can't answer that, because I haven't had enough experience in TKinter. In fact I haven't had much experience in anything programming, but Pygame is very cool. Andrew > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Chris McCormick > Sent: Thursday, 1 March 2001 3:25 AM > To: tutor@python.org > Subject: [Tutor] >> Best setup for animation? << > > > Hi again, > So, I've been writing a program with Python and Tkinter. It does > some simple animation, but it is all procedural. That is to say, I have > several agents moving around my canvas, and they all *take turns* moving > and being re-displayed. I'm not sure how to do animation the way I > would do it in directX, which is as follows: > > 1. Create a primary surface(canvas). > 2. Draw everything in its initial state. > 3. Process AI. > 4. Move everything to its next-frame state on a *hidden* surface. > 5. Make the canvas point to the hidden surface, so all moves are seen > at once. > > Thus, my question is two-fold: > > 1. Is there a way to create two canvases, and switch between them to > create a blitting effect? I have to admit that I'm a little fuzzy on > exactly how packing works, and maybe there's a way to display all > updated objects at once with *one* canvas? > 2. Before I go much farther, is the Python Tkinter combo the best setup > for game-type animation? I've also started looking at wxPython and > PyGame, which uses something called SDL. > > I'd like to settle on an evironment and really concentrate on the AI. > I'd stick with Tkinter if only I could get it to blit. > > Thanks in advance for any help (or pointers to help) you can provide, > Chris > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From drivel_drool@bigfoot.com Thu Mar 1 00:50:06 2001 From: drivel_drool@bigfoot.com (Charlie Derr) Date: Wed, 28 Feb 2001 19:50:06 -0500 Subject: [Tutor] what's wrong with this code In-Reply-To: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> Message-ID: <LOBBJCAMDNLNCGCCHGEIOELKJLAA.drivel_drool@bigfoot.com> This is a multi-part message in MIME format. ------=_NextPart_000_0165_01C0A1BF.A60A9230 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Just reverse the assignment line temperature = input("What is the temperature of the spam?") ~c -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Katharine Stoner Sent: Wednesday, February 28, 2001 6:55 PM To: python tutor Subject: [Tutor] what's wrong with this code What's wrong with this code? I don't understand. Please help. input("What is the temperature of the spam?") = temperature if temperature > 50: print "The salad is properly cooked." else: print "Cook the salad some more." -Cameron Stoner ------=_NextPart_000_0165_01C0A1BF.A60A9230 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN = class=3D492094600-01032001>Just=20 reverse the assignment line</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D492094600-01032001></SPAN></FONT> </DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D492094600-01032001></SPAN></FONT> </DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D492094600-01032001>temperature =3D input("What is the = temperature of the=20 spam?")</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D492094600-01032001></SPAN></FONT> </DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D492094600-01032001> ~c</SPAN></FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px"> <DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr><FONT = face=3DTahoma=20 size=3D2>-----Original Message-----<BR><B>From:</B> = tutor-admin@python.org=20 [mailto:tutor-admin@python.org]<B>On Behalf Of </B>Katharine=20 Stoner<BR><B>Sent:</B> Wednesday, February 28, 2001 6:55 = PM<BR><B>To:</B>=20 python tutor<BR><B>Subject:</B> [Tutor] what's wrong with this=20 code<BR><BR></DIV></FONT> <DIV><FONT face=3DArial size=3D2>What's wrong with this code? I=20 don't understand. Please help.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>input("What is the temperature of the = spam?") =3D=20 temperature</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> if temperature = >=20 50:<BR> print "The salad is = properly=20 cooked."<BR> =20 else:<BR> print "Cook the = salad some=20 more."</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Cameron=20 Stoner</FONT></DIV></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_0165_01C0A1BF.A60A9230-- From lumbricus@gmx.net Thu Mar 1 00:51:54 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Thu, 1 Mar 2001 01:51:54 +0100 (MET) Subject: [Tutor] what's wrong with this code References: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> Message-ID: <14902.983407914@www31.gmx.net> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0A1AF.963E7C00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit > What's wrong with this code? I don't understand. Please help. > > input("What is the temperature of the spam?") = temperature > > if temperature > 50: > print "The salad is properly cooked." > else: > print "Cook the salad some more." > > -Cameron Stoner > try "temperature=input("What...")" ;-) assignments go: assign value (on the right side of the assignment operator) to variable (on the left side) just like in C or AFAIK any other language. input() is evaluated and the result assigned to variable "temperature". greeeetz jö! -- Sent through GMX FreeMail - http://www.gmx.net ------=_NextPart_000_0005_01C0A1AF.963E7C00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>What's wrong with this code? I=20 don't understand. Please help.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>input("What is the temperature of the = spam?") =3D=20 temperature</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> if temperature >=20 50:<BR> print "The salad is = properly=20 cooked."<BR> =20 else:<BR> print "Cook the = salad some=20 more."</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Cameron = Stoner</FONT></DIV></BODY></HTML> ------=_NextPart_000_0005_01C0A1AF.963E7C00-- _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From tescoil@irtc.net Thu Mar 1 01:57:02 2001 From: tescoil@irtc.net (Tesla Coil) Date: Wed, 28 Feb 2001 19:57:02 -0600 Subject: [Tutor] what's wrong with this code References: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> Message-ID: <3A9DAC6E.892B8D6E@irtc.net> > what's wrong with this code? I don't understand. Please help. > > input("What is the temperature of the spam?") = temperature > > if temperature > 50: > print "The salad is properly cooked." > else: > print "Cook the salad some more." # Three things: # 1). Correct syntax of the first line: temperature = input("What is the temperature of the spam? ") # # 2). Don't indent the whole conditional loop: if temperature > 50: print "the salad is properly cooked." else: print "Cook the salad some more." # # 3). The salad is still "properly cooked" # at a temperature of 12000... From arcege@shore.net Thu Mar 1 00:59:12 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 28 Feb 2001 19:59:12 -0500 (EST) Subject: [Tutor] what's wrong with this code In-Reply-To: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> from Katharine Stoner at "Feb 28, 2001 5:55: 7 pm" Message-ID: <E14YHR2-0004Qn-00@nautilus.shore.net> > What's wrong with this code? I don't understand. Please help. > > input("What is the temperature of the spam?") = temperature > > if temperature > 50: > print "The salad is properly cooked." > else: > print "Cook the salad some more." Quickly, I see two things. The first is basic to programming so it may take newbies a little to understand. Assignment statements consist a left-hand-side and a right-hand-side. The right-hand-side is the value to be assigned and the left-hand-side is the place being "saved" to. In your code above, the place you are saving the value to, "temperature" is on the right. The second could be just a problem with the mailer. But in Python, indentation is important. The "if/else" statement must line up with the "input" assignment. temperature = input("What is the temperature of the spam?") if temperature > 50: print "The salad is properly cooked." else: print "Cook the salad some more." The statements just after "if" and "else" would be indented, but the "if" and "else" and "temperatre = ..." lines are to be in the same column. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From kalle@gnupung.net Thu Mar 1 01:12:08 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 1 Mar 2001 02:12:08 +0100 Subject: [Tutor] what's wrong with this code In-Reply-To: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer>; from kstoner@netins.net on Wed, Feb 28, 2001 at 05:55:07PM -0600 References: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> Message-ID: <20010301021208.A28215@father> --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Katharine Stoner: > What's wrong with this code? I don't understand. Please help. It's not much, in fact. Look ahead... > input("What is the temperature of the spam?") =3D temperature This is where it's wrong. The variable should be on the left side in the assignment: temperature =3D input("What is the temperature of the spam?") > if temperature > 50: > print "The salad is properly cooked." > else: > print "Cook the salad some more." This should work. Peace, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --Dxnq1zWXvFF0Q93v Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6naHodNeA1787sd0RAgKVAKCVpMEYddjMyIcLyiPd9gUBJjkDNwCdHtVS ryEML4NmYiYZ5h+3RFIdZ9U= =NSgn -----END PGP SIGNATURE----- --Dxnq1zWXvFF0Q93v-- From kstoner@netins.net Thu Mar 1 04:53:19 2001 From: kstoner@netins.net (Katharine Stoner) Date: Wed, 28 Feb 2001 22:53:19 -0600 Subject: [Tutor] code won't work now Message-ID: <000801c0a20b$898f8c40$1152b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0A1D9.3E4ECA20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, day =3D input("On a scale of 1 to 10, how was your day?") if day =3D=3D (fine): #used double equals to make=20 fine =3D "The salad is properly cooked." print fine else: print "Cook the salad some more." What is wrong with this? I had it working and then saved it and now it = doesn't work in the GUI. Help please. -Cameron Stoner ------=_NextPart_000_0005_01C0A1D9.3E4ECA20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>day =3D input("On a scale of 1 to 10, = how was your=20 day?")<BR>if day =3D=3D (fine):<BR>#used double equals to make=20 <BR> fine =3D "The salad is properly=20 cooked."<BR> print fine<BR>else:<BR> = print=20 "Cook the salad some more."</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2><BR>What is wrong with this? I = had it working=20 and then saved it and now it doesn't work in the GUI. Help=20 please.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Cameron = Stoner</FONT></DIV></BODY></HTML> ------=_NextPart_000_0005_01C0A1D9.3E4ECA20-- From dyoo@hkn.eecs.berkeley.edu Thu Mar 1 04:56:51 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 28 Feb 2001 20:56:51 -0800 (PST) Subject: [Tutor] Two More Questions In-Reply-To: <F26FQG101s7hpJm8Otp00001a44@hotmail.com> Message-ID: <Pine.LNX.4.21.0102282054350.5133-100000@c82114-a.pinol1.sfba.home.com> On Wed, 28 Feb 2001, Britt Green wrote: > >doesn't work; as an optimization step, if Python sees that a module's > >already loaded, it'll ignore any more 'import Blah' calls. So we really > >do need to force the issue, by using reload(): > > > > >>> reload(Classes) > ><module 'Classes' from 'Classes.pyc'> > > > >That's a wild shot in the dark, but perhaps this is what's happening for > >you. > > I quit out of IDLE and reloaded my files, and they worked fine. So if I make > changes to the file "Classes.py", I need to make the file calling it reload > it to get it to recognize those changes, correct? Ah, good, so that was probably it. I think there's also an IDLE option or command to have it do the reload(), but perhaps I'm mistaken on that. > Hmm...I guess what I was looking for was a way to call a class > constructor that contained a multiline string. For example, say I have > this class: > x > class Rooms: > def __init__(self, name, number description): > self.name = name > self.number = number > self.description = description > > Now I when I call this class, if I wanted to have, say, a paragraph of > text for the description, how would I enter it? I've tried a few > different ways with the triple quotes, but Python seems to not like > it. Can you show us one of your example calls? From deirdre@deirdre.net Thu Mar 1 04:51:39 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 28 Feb 2001 20:51:39 -0800 (PST) Subject: [Tutor] code won't work now In-Reply-To: <000801c0a20b$898f8c40$1152b1cf@oemcomputer> Message-ID: <Pine.LNX.4.31.0102282051160.26941-100000@emperor.deirdre.org> On Wed, 28 Feb 2001, Katharine Stoner wrote: > day = input("On a scale of 1 to 10, how was your day?") This should be raw_input, not input > What is wrong with this? I had it working and then saved it and now > it doesn't work in the GUI. Help please. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kstoner@netins.net Thu Mar 1 04:56:24 2001 From: kstoner@netins.net (Katharine Stoner) Date: Wed, 28 Feb 2001 22:56:24 -0600 Subject: [Tutor] wrong code Message-ID: <000c01c0a20c$0e2fe120$db52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0A1D9.ACFE5C60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi,=20 day =3D input("On a scale of 1 to 10, how was your day?") if day =3D=3D fine: #used double equals to make =20 print "The salad is properly cooked." else: print "Cook the salad some more." ------=_NextPart_000_0009_01C0A1D9.ACFE5C60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi, </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>day =3D input("On a scale of 1 to 10, = how was your=20 day?")</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>if day =3D=3D fine:<BR>#used double = equals to=20 make <BR> print "The salad is = properly=20 cooked."<BR>else:<BR> print "Cook the salad some=20 more."</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML> ------=_NextPart_000_0009_01C0A1D9.ACFE5C60-- From dyoo@hkn.eecs.berkeley.edu Thu Mar 1 05:10:58 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 28 Feb 2001 21:10:58 -0800 (PST) Subject: [Tutor] code won't work now In-Reply-To: <000801c0a20b$898f8c40$1152b1cf@oemcomputer> Message-ID: <Pine.LNX.4.21.0102282106460.5352-100000@c82114-a.pinol1.sfba.home.com> On Wed, 28 Feb 2001, Katharine Stoner wrote: > day = input("On a scale of 1 to 10, how was your day?") > if day == (fine): > #used double equals to make > fine = "The salad is properly cooked." > print fine > else: > print "Cook the salad some more." > > > What is wrong with this? I had it working and then saved it and now > it doesn't work in the GUI. Help please. The only line that signals a warning for me is this one: > if day == (fine): You probably meant to write: ### if day == "fine": ### instead; you'll want to compare your day to the string "fine". Without the quotes, Python will unsuccessfully try to look for a variable named 'fine', throw up its hands, and give a NameError. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu Mar 1 05:19:00 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 28 Feb 2001 21:19:00 -0800 (PST) Subject: [Tutor] what's wrong with this code In-Reply-To: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> Message-ID: <Pine.LNX.4.21.0102282103320.5352-100000@c82114-a.pinol1.sfba.home.com> On Wed, 28 Feb 2001, Katharine Stoner wrote: > What's wrong with this code? I don't understand. Please help. > > input("What is the temperature of the spam?") = temperature > > if temperature > 50: > print "The salad is properly cooked." > else: > print "Cook the salad some more." Although Python's error messages are terse, they do help in finding out what's happening with a program. Let's take a look: ### >>> input("temperature?") = temperature SyntaxError: can't assign to function call ### In Python, the '=' sign doesn't quite mean 'equality'; rather, it's more of an 'assignment' than anything else. Whenever you see '=', think about an arrowhead pointing toward the left: # pseudocode input("temperature?") <---- temperature which is closer to what's happening. However, by doing this, we see that the flow is going in the wrong direction; we can fix this by switching the roles of the input() and the temperature: # still pseudocode temperature <---- input("temperature?") which is better; the value coming out of the input() function goes into the temperature variable. In real Python code, then, we do this: temperature = input("temperature?") This is a confusing notation at first, but it's used by a few other programming languages, which is probably why Python uses it too. If you have more questions, please feel free to ask! From dyoo@hkn.eecs.berkeley.edu Thu Mar 1 05:35:40 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 28 Feb 2001 21:35:40 -0800 (PST) Subject: [Tutor] Two More Questions In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5D8@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <Pine.LNX.4.21.0102282058180.5352-100000@c82114-a.pinol1.sfba.home.com> On Wed, 28 Feb 2001 alan.gauld@bt.com wrote: > > >>> string.center('''hello world. > > ... this is a test.''', 45) > > ' hello world.\012this is a test. ' > > ### > > > > Hmmm... but it depends on the function if it handles a > > multi-line string properly or not. string.center() > > certainly didn't handle that nicely. > Now whether thats what you expected centre to do so is another > matter, it certainly won't centre each line, but it doesn't > claim to do so. Very true! But I still would like it to do something different. *grin* Let me see if I can "fix" it: ### >>> def mycenter(multiline, colwidth): ... lines = string.split(multiline, '\n') ... newlines = [string.center(l, colwidth) for l in lines] ... return string.join(newlines, '\n') ... >>> print mycenter("""Hello world! ... This is a test ... of centering a ... multiline.""", 45) Hello world! This is a test of centering a multiline. ### Ah, this is better. Subjectively speaking, of course. *grin* From jcm@bigskytel.com Thu Mar 1 08:05:14 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 1 Mar 2001 01:05:14 -0700 Subject: [Tutor] wrong code In-Reply-To: <000c01c0a20c$0e2fe120$db52b1cf@oemcomputer>; from kstoner@netins.net on Wed, Feb 28, 2001 at 10:56:24PM -0600 References: <000c01c0a20c$0e2fe120$db52b1cf@oemcomputer> Message-ID: <20010301010514.A5299@bigskytel.com> * Katharine Stoner <kstoner@netins.net>: > day = input("On a scale of 1 to 10, how was your day?") what you want to use is raw_input(), not input(). raw_input() returns the input as a string, while input() evaluates the input as a python expression. Observe the following interpreter session (the 5+5 is what I typed at the prompt): >>> x = input("what is 10? ") What is 10? 5+5 >>> print x 10 >>> x = raw_input("what is 10? ") What is 10? 5+5 >>> print x 5+5 See: http://www.python.org/doc/current/lib/built-in-funcs.html > if day == fine: This wont work because fine doesn't exist. What you meant was "fine" (quotes included). "fine" is a string, while fine is a keyword. > #used double equals to make > print "The salad is properly cooked." > else: > print "Cook the salad some more." David From alan.gauld@bt.com Thu Mar 1 10:25:00 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 1 Mar 2001 10:25:00 -0000 Subject: [Tutor] list digest strangeness Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5D9@mbtlipnt02.btlabs.bt.co.uk> I've just unsubbed from the list and resubbed with my new email address. So far as I can tell my options are identically set but whereas I used to get the digest as a mail with lots of attachments I now get a single attachment. When I open that attachment I get the set of attachments I used to get in the top level message. Is this just happening to me or has there been a global change in the tutor digest mechanism? If the latter, it's bad - please put it back as it was. If it's me, how do I fix it? Alan G. From kalle@gnupung.net Thu Mar 1 13:02:01 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 1 Mar 2001 14:02:01 +0100 Subject: [Tutor] wrong code In-Reply-To: <000c01c0a20c$0e2fe120$db52b1cf@oemcomputer>; from kstoner@netins.net on Wed, Feb 28, 2001 at 10:56:24PM -0600 References: <000c01c0a20c$0e2fe120$db52b1cf@oemcomputer> Message-ID: <20010301140201.A29788@father> --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Katharine Stoner: [snip] This shoud work about right if you add a variable: fine =3D 10 day =3D input("On a scale of 1 to 10, how was your day?") if day =3D=3D fine: #used double equals to make =20 print "The salad is properly cooked." else: print "Cook the salad some more." You could also change the condition a bit: fine =3D 8 if day >=3D fine: This will print "The salad is properly cooked." if input is 8, 9, 10 or anything higher than that. Peace, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --YiEDa0DAkWCtVeE4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6nkhJdNeA1787sd0RAtiGAJ4rO7MvdCCPFGCHHWPvYMB+nHwyegCgmzjV 79EBimfLGMaERk8CcajnGZg= =HDCK -----END PGP SIGNATURE----- --YiEDa0DAkWCtVeE4-- From pdiaz88@terra.es Thu Mar 1 17:12:15 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Thu, 1 Mar 2001 18:12:15 +0100 Subject: [Tutor] CGI with python question Message-ID: <01030118121500.00644@tajo> Hi folks, I'm doing some CGI python scripts. One of them needs to access a MySQL database on the localhost. i have experience dealing with MySQLdb so this is not a problem. Actually the problem is that I need to fetch the username-password-host-db tuple from a file in /etc. Of course, this file must be root-only readable, so nobody except the root can read this sensitive information. On the other hand, I don't want to have cgi's in my system with root priviledges (I dont know if this is even posible with apache). Considering this, I planned my cgi to do the following: - The script is initially suid root - Once is called, reads the /etc files - Inmediatly after this, changes is euid to Nobody via os.setuid - Do the rest of the job, including interacting with the MySQL server Does this schema looks ok in security terms?. If not, what other schema should I follow? I've also been playing with suid python scripts, but I wasn't able to make the perform root privileged actions. Example: test.py: ------- #!/usr/bin/python import os print os.geteuid() os.setuid(0) print os.geteuid() f = open("/etc/shadow" ) print "ALL OK" -------- # chmod +x test.py # ls -la test.py -rwxr-xr-x 1 root root 120 Mar 1 18:07 test.py # ./test.py 0 0 ALL OK # chmod u+s test.py # ls -la test.py -rwsr-xr-x 1 root root 120 Mar 1 18:07 test.py # su pdiaz $ ./test.py 1000 Traceback (innermost last): File "./test.py", line 5, in ? os.setuid(0) OSError: [Errno 1] Operation not permitted $ What I'm doing wrong? Thanks Pedro From dsh8290@rit.edu Thu Mar 1 19:04:33 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 1 Mar 2001 14:04:33 -0500 Subject: [Tutor] what's wrong with this code In-Reply-To: <14902.983407914@www31.gmx.net>; from lumbricus@gmx.net on Thu, Mar 01, 2001 at 01:51:54AM +0100 References: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer> <14902.983407914@www31.gmx.net> Message-ID: <20010301140433.B24127@harmony.cs.rit.edu> On Thu, Mar 01, 2001 at 01:51:54AM +0100, J=F6rg W=F6lke wrote: | | assignments go: assign value (on the right side of the assignment opera= tor) | to variable (on the left side) just like in C or AFAIK any other langua= ge. Off topic, but FYI anyways : I think it is Ada that uses this kind of notation for assignment : expression -> identifier Some sort of design language that my former apartmentmate, a Computer Engineering Technology major, used had this sort of syntax, and I think it is derived from or at least heavily influenced by Ada. -D From kwindus@LanMinds.Com Thu Mar 1 19:54:28 2001 From: kwindus@LanMinds.Com (Karen Windus) Date: Thu, 1 Mar 2001 11:54:28 -0800 (PST) Subject: [Tutor] Files, directories and syntax Message-ID: <Pine.GSO.4.21.0103011143010.21918-100000@lanshark.lanminds.com> Hi - I'm somewhat new to python. I am trying to change a line in every html file in a directory if there is a match on the text string I'm searching for. So I'm using glob to match a file pattern. Then I want to loop through every file, loop through every line, so a search on the regexp that I've set up and if there is a match, at this point, I just would be happy with printing out some debugging code and then closing (and eventaully saving) the file. When I run the following code now, I get a syntax error on 'file = open(i,"rw")' I guess I'm not sure how to populate the file object (when I try and OPEN a file in other words) with the actual name of the file. So I'm using i in a loop. Is that wrong? In other languages that would work I think. Anyway, I don't know if I'm on the right track or not. Here's what I have so far: #! /usr/bin/env python def change_lines(directory = None): import glob,re result = [] filepattern = '*.{html}' filelist = glob.glob1(directory,filepattern) regexp = re.compile(r"Your Turn") for i in filelist: file=open(i,"rw") print "We opened a file" for file in filelist: lines = filenames.readlines() for line in lines: result = regexp.search(line) if result == None: print "Result was equal to None" elif 'Your' in line or 'Turn' in line: print "we had a match" print result else: print "Nothing happened" return result file.close() change_lines() Thanks, Karen From shaleh@valinux.com Thu Mar 1 20:08:40 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 01 Mar 2001 12:08:40 -0800 (PST) Subject: [Tutor] Files, directories and syntax In-Reply-To: <Pine.GSO.4.21.0103011143010.21918-100000@lanshark.lanminds.com> Message-ID: <XFMail.20010301120840.shaleh@valinux.com> > > Here's what I have so far: > would you resend with the file as an attachment. The indentation appears to be compleletely missing. If this is actually how it looks in the original file, the problem lies in the fact that python defines code blocks with indentation. So, you have: def change_line(directory = None): the next line must be at least indented one space from the letter 'd' in def. Preferably more. So with the line following an if, etc. From kwindus@hotmail.com Thu Mar 1 20:40:58 2001 From: kwindus@hotmail.com (Karen Windus) Date: Thu, 01 Mar 2001 20:40:58 Subject: [Tutor] Files, directories and syntax Message-ID: <F196ZS08i7M4BAyxJMX000025e7@hotmail.com> I've been asked to resend this as an attachment. Actually, I'll just repaste into this document and hope that works. I was sending the last message from my shell account so I guess pine didn't like my attempts to indent (the script is indented, although I don't know if it is correctly). #! /usr/bin/env python def change_lines(directory = None): import glob, re result = [] filepattern = '*.{html}' filelist = glob.glob1(directory, filepattern) regexp = re.compile(r"Your Turn") for i in filelist: file = open(i,"rw") print "We opened a file" for file in filelist: lines = filenames.readlines() for line in lines: result = regexp.search(line) if result == None: print "Result was equal to None" elif 'Your' in line or 'Turn' in line: print "we had a match" print result else: print "Nothing happened" return result file.close() change_lines() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From shaleh@valinux.com Thu Mar 1 20:52:26 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 01 Mar 2001 12:52:26 -0800 (PST) Subject: [Tutor] Files, directories and syntax In-Reply-To: <F196ZS08i7M4BAyxJMX000025e7@hotmail.com> Message-ID: <XFMail.20010301125226.shaleh@valinux.com> On 01-Mar-2001 Karen Windus wrote: > I've been asked to resend this as an attachment. Actually, I'll just repaste > into this document and hope that works. I was sending the last message from > my shell account so I guess pine didn't like my attempts to indent (the > script is indented, although I don't know if it is correctly). > if what I see matches your code, no it is not. I played with it some, and you have other issues as well. >#! /usr/bin/env python > > def change_lines(directory = None): > import glob, re > result = [] > filepattern = '*.{html}' > filelist = glob.glob1(directory, filepattern) > regexp = re.compile(r"Your Turn") > for i in filelist: > file = open(i,"rw") > print "We opened a file" > for file in filelist: but you just opened 'file' as a file object and now you are using it as an entry from list (again). You have two 'for foo in filelist' loops here. You really need to read this line by line an make sure you have what you want. Feel free to mail me personally and we can solve your issues once you think the logic out a little more. From dyoo@hkn.eecs.berkeley.edu Fri Mar 2 00:54:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 1 Mar 2001 16:54:05 -0800 (PST) Subject: [Tutor] Files, directories and syntax In-Reply-To: <F196ZS08i7M4BAyxJMX000025e7@hotmail.com> Message-ID: <Pine.LNX.4.21.0103011644000.3017-100000@c82114-a.pinol1.sfba.home.com> On Thu, 1 Mar 2001, Karen Windus wrote: > I've been asked to resend this as an attachment. Actually, I'll just > repaste into this document and hope that works. I was sending the last > message from my shell account so I guess pine didn't like my attempts > to indent (the script is indented, although I don't know if it is > correctly). There's a small indentation bug right here: > for i in filelist: > file = open(i,"rw") You'll need to indent to mark of the block that the for loop is going over. Also, if you want to make the file both readable and writable, perhaps you can use: file = open(i, 'r+') I'm not quite sure if 'rw' will work as a mode; apparently, Python will ignore the 'w' and just treat it as a readable file: ### >>> f = open('foo.txt', 'rw') >>> f.read() 'this is a test of the emergency broadcast system.\012' >>> f.seek(0) >>> f.write('updating') Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: [Errno 9] Bad file descriptor ### Hmmm. So use 'r+' instead, if you want the file both readable and updatable. If you want to see the gory details, the reference page on: http://python.org/doc/current/lib/built-in-funcs.html talks a little more about the modes open() will accept. > for line in lines: > result = regexp.search(line) Same indentation issue here. Whenever we give Python a statement that ends in ':', we're telling it that we're about to start a new "block". Don't worry, this jars everyone who starts in Python; it'll take some practice to get a feel for it. Good luck to you. From arthur.watts@gbst.com Fri Mar 2 01:55:24 2001 From: arthur.watts@gbst.com (Arthur Watts) Date: Fri, 2 Mar 2001 11:55:24 +1000 Subject: [Tutor] Tip : building Apache modules under Compaq Tru-64 Unix (formerly Digital Unix / OSF1) Message-ID: <1CDB101F0CB6D311882F0000F806392402F16386@aquarius.bne.star.com.au> Guys, Those of us with Tru-64 often run into some interesting problems when buiilding Open Source software, particularly software which does not come with a configure script. The recent upgrade to v5.0 of Tru-64 caught out a lot of the configure scripts, but this tip is for those who have to 'wing it' completely. Current Apache releases contain the facility to build your httpd executable with support for dynamically linked modules (DSO). This means that your httpd executable no longer gets bigger with each successive module added to it. This is accomplished via the 'apxs' tool. PyApache is a module designed to speed up the execution of Python CGI scripts running under the Apache webserver. It comes with a single README containing a line which shows you how the suggested APXS command. Because of the nature of the Tru-64 compilation/linking environment, the supplied script will *not* work properly. To build PyApache under Tru-64, save this in a script called 'apxs.sh' or similar : #!/bin/ksh PYTHON="/usr/local/python-1.5.2" PYVER="python1.5" PYTHONLIB=$PYTHON/lib/$PYVER PYINC=${PYTHON}/include APACHEBIN=/usr/local/pyapache/bin echo "Building ${MODULE}" $APACHEBIN/apxs \ -c \ -Wl,"-shared -expect_unresolved '*'" \ # essential for Tru-64 -I${PYINC} \ -L${PYTHONLIB} \ -L${PYTHONLIB}/config \ -lpython1.5 \ -lm \ -lpthread \ ${MODULE}.c if [ $? -eq 0 ]; then echo "Installing ${MODULE}" $APACHEBIN/apxs \ -i \ -a \ ${MODULE}.so fi The net payoff for this effort was an increase from 15 requests/second to over 58 requests/sec on our Alpha. Definitely worth it ! Note that the script above should work for most Apache modules which support DSO - you'll just need to change the include and library paths. Other options such as threading may or may not suit your environment. Your version of Python may differ, and so may the location of your Apache executables. Some installs have apxs in apache/sbin instead of apache/bin, but thats purely personal choice. If the build works, you should see apxs output indicating that httpd.conf is being updated. Please consult the apxs manpage (under apache/man) for further details re the options you need to pass apxs. The above script uses Korn shell syntax - it may need to be modified if you prefer another shell. Don't forget to read the INSTALL and README files to ensure that all necessary configuration is done before restarting Apache. Finally, my apologies for the size of this post ! Regards, Arthur Arthur Watts Software Engineer GBST Automation Global Banking & Securities Transactions Telephone + 61 7 3331 5555 mailto: arthur.watts@gbst.com www.gbst.com From toxx@post.com Fri Mar 2 02:34:40 2001 From: toxx@post.com (t.d) Date: Thu, 1 Mar 2001 21:34:40 -0500 (EST) Subject: [Tutor] dictionary Message-ID: <384505273.983500480751.JavaMail.root@web394-mc> hi evreyone, could you explain me how to do when i want following: i have file which contain dictionary. and i wrote some code and import the dictionary from that file and i want to add entry to existing dictionary and after this to save the change to original file. sincerely, ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From tim@johnsons-web.com Fri Mar 2 04:59:52 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Thu, 1 Mar 2001 19:59:52 -0900 Subject: [Tutor] Memory Gotchas? References: <384505273.983500480751.JavaMail.root@web394-mc> Message-ID: <01030120033105.01210@shecom> Hello All: I would appreciate being pointed towards documentation on Python memory allocation. I'm especially interested in avoiding coding mistakes which could lead to memory leaks. Any Info would be appreciated. Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From dyoo@hkn.eecs.berkeley.edu Fri Mar 2 05:14:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 1 Mar 2001 21:14:16 -0800 (PST) Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <3A9C7C27.CE91E1D0@jam.rr.com> Message-ID: <Pine.LNX.4.21.0102272308540.25253-100000@hkn.eecs.berkeley.edu> On Tue, 27 Feb 2001, R. A. wrote: > Your post seems thoughtful, and hardly flameworthy. This list is an > exceptional resource, and it's nice to see that others appreciate it > enough to express concern. I find nothing to criticize about Python > Tutor, but you do remind us of a few significant points. (apologies in advance for the Perl reference) I find the following quote from the Camel book quite ironic and appropriate: "Like Perl itself, comp.lang.perl.misc is meant to be useful, and no question is too silly to ask. [Footnote: Of course, some questions are too silly to answer, especially those already answered in the FAQ.]" And that's one way to handle new people: toss them out the door with a pointer to the FAQ. Not to say that reading FAQ's isn't useful, but it can be a little rough at first. Let's make people feel at ease when they're asking questions. Of course, we should encourage people to use the FAQ and search for resources, but I think it don't hurt to also give them something to look at. From tim@johnsons-web.com Fri Mar 2 05:46:24 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Thu, 1 Mar 2001 20:46:24 -0900 Subject: [Tutor] My two cents worth re Python Newbies References: <Pine.LNX.4.21.0102272308540.25253-100000@hkn.eecs.berkeley.edu> Message-ID: <01030120500806.01210@shecom> Hello: On Thu, 01 Mar 2001, Daniel Yoo wrote: > > Let's make people feel at ease when they're asking questions. Of course, > we should encourage people to use the FAQ and search for resources, but I > think it don't hurt to also give them something to look at. My Two Cents Worth as a Python Newbie: I guess that I could learn Python without any help from this list. After all, there is a *lot* of resources out there - but it would take me longer. Making use of the list has saved me time, and I have been able to pass those "savings" on by helping others in other ways. That's all folks!! great list, keep up the good work. :>) -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From sheila@thinkspot.net Fri Mar 2 05:51:58 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 01 Mar 2001 21:51:58 -0800 Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au> References: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au> Message-ID: <3439F4C6B44@kserver.org> I've been an online participant in many web discussion boards, newsgroups, and mailing lists. While I appreciate the importance of a FAQ and the ability to use search engines and so forth (I am a Usenet moderator, and a mailing list owner), of all the groups and forums I participate in, I do not enjoy those that repeatedly and tersely point newbies to the FAQ nearly as much as those where every question is patiently answered (or, at worst, ignored). Even when I've tried to find an answer first, I always thinking someone may still harp on me when I ask a question. When posting, you always have to "justify" your question, by first explaining all the trouble you've gone to in order to find your answer. The assumption, is that the dim-witted newbie doesn't know enough, or is too lazy, to find the answer themself. In other words: we assume the worst about the newbie, before we even meet him. It sets up an "us vs. them" type of atmosphere. My absolute favorite forum, is the Community Forums at FutureQuest.net (http://www.aota.net/cgi-bin/Ultimate.cgi), where I host my website. I just love participating in that community, because I have never seen an impatient reply, a pointer to RTFM, but only helpful, encouraging responses. I am never afraid to ask for help there. Up to this point, this Tutor list has seemed very much like that, as well. I would hate to see it change. This list is described as a "tutor" list for those who are new to the language and need help. I would recommend, that: (1) if you don't have the patience to reply to a post, because it is in a FAQ or could be found by a search, then simply don't reply. (2) if you reply, point the user to the FAQ or other search, with some remark such as: "You will find more on this topic here <URL>, and you may find much additional information there." or something like, "Here is a URL you may like to add to your bookmarks, for future reference." or something gentle, like that. I've been a subscriber to this list for over a month now, and I don't see that the traffic is too high, that it is necessary to change the policies somehow, to enforce a call to read the FAQ. I also don't think that there should be a pre-requisite to asking questions on this list, such as ability to use a search engine effectively. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Wed, 28 Feb 2001 12:43:53 +1000, Arthur Watts <arthur.watts@gbst.com> wrote about [Tutor] My two cents worth re Python Newbies: :Guys, : : I know that this post may attract the odd flame, but please read it :in its entirety before you begin your reply. : : The majority of posts to the Tutor mailing lists are from people who :have tried to resolve a particular problem before resorting to the list. :Some, however, are simply 'noise'. I find the patient, thoughtful replies :given by the good souls on this list to be a real eye-opener, and I commend :you for your warmth and dedication when responding to newbie enquiries. My :own view is that the list should be for people who are able to : : : a. Read : b. Use a Net search engine : c. Navigate to www.python.org : d. Use the skills detailed above to find other Python resources : : If people still need to ask questions, then I'm willing to bet that :the answer will be something which enlightens the majority of the list :recipients. Python is growing at a phenomenal rate, but we need to keep the :'information <-> noise' ratio to a minimum, and a Tutor digest filled with :questions such as 'Is Python any good for CGI / GUI programming / :pre-schoolers ?' does neither the author nor the Python community any good. :This is all covered at python.org (OK, some thought may be required re the :pre-schoolers ..). As for the people who balatantly ask for someone to do :their Uni assignment for them, I think the moderators have been way too :polite / lenient ! : : I realise that some may brand me elitist, but I am far from it : I :still have a lot to learn re. Python and other Open Source products. The key :is that I am prepared to actually cut some code or attempt to configure a :product before I fire off a posting re. a particular issue. We need to :welcome thinking people to the Python community, and filter out those who :have a problem with RTFM. : : I welcome any constructive criticism on this subject. I don't own :the list and I'm willing to accept the decision of other subscribers, be it :ever so painful :} : :Regards, : :Arthur : :Arthur Watts :Software Engineer GBST Automation :Global Banking & Securities Transactions : :Telephone + 61 7 3331 5555 :mailto: arthur.watts@gbst.com :www.gbst.com : : : : : : : : :_______________________________________________ :Tutor maillist - Tutor@python.org :http://mail.python.org/mailman/listinfo/tutor From deirdre@deirdre.net Fri Mar 2 07:09:57 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Mar 2001 23:09:57 -0800 (PST) Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <Pine.LNX.4.21.0102272308540.25253-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.31.0103012308260.9383-100000@emperor.deirdre.org> On Thu, 1 Mar 2001, Daniel Yoo wrote: > And that's one way to handle new people: toss them out the door with a > pointer to the FAQ. Not to say that reading FAQ's isn't useful, but > it can be a little rough at first. Right. There are those for whom the words in the FAQ are Greek. This is a home for them. I have learned a lot by helping others, which is why I've stayed with it. I've sometimes tossed off a solution to see someone else post something better. ::shrug:: > Let's make people feel at ease when they're asking questions. Of > course, we should encourage people to use the FAQ and search for > resources, but I think it don't hurt to also give them something to > look at. Exactly. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From deirdre@deirdre.net Fri Mar 2 07:13:57 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Mar 2001 23:13:57 -0800 (PST) Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <3439F4C6B44@kserver.org> Message-ID: <Pine.LNX.4.31.0103012310510.9383-100000@emperor.deirdre.org> On Thu, 1 Mar 2001, Sheila King wrote: > (1) if you don't have the patience to reply to a post, because it is in a FAQ > or could be found by a search, then simply don't reply. There are a number of reasons I don't reply to specific posts: 1) Often, especially lately, I've simply been too busy. 2) The user asks a Windows-specific question that I don't know the answer to. 3) I'd need to actually open an interpreter and futz for a couple minutes and, while I could easily answer some questions, that takes too much interruption. On the other hand, I don't see questions going unanswered (at least not for long), so I think that the system works pretty well. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From sheila@thinkspot.net Fri Mar 2 07:25:42 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 01 Mar 2001 23:25:42 -0800 Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <Pine.LNX.4.31.0103012310510.9383-100000@emperor.deirdre.org> References: <3439F4C6B44@kserver.org> <Pine.LNX.4.31.0103012310510.9383-100000@emperor.deirdre.org> Message-ID: <3994B4748A4@kserver.org> On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse <deirdre@deirdre.net> wrote about Re: [Tutor] My two cents worth re Python Newbies: :On the other hand, I don't see questions going unanswered (at least not :for long), so I think that the system works pretty well. Well, that's kind of what I was saying, only much more succinct. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From deirdre@deirdre.net Fri Mar 2 07:22:57 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Mar 2001 23:22:57 -0800 (PST) Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <3994B4748A4@kserver.org> Message-ID: <Pine.LNX.4.31.0103012321490.9383-100000@emperor.deirdre.org> On Thu, 1 Mar 2001, Sheila King wrote: > On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse <deirdre@deirdre.net> > wrote about Re: [Tutor] My two cents worth re Python Newbies: > > :On the other hand, I don't see questions going unanswered (at least not > :for long), so I think that the system works pretty well. > > Well, that's kind of what I was saying, only much more succinct. That's the problem with having had Horrible Hugh as an English teacher: he could cut 50% out of anyone's writing without changing the meaning. And here I am trying to get my Master's degree in novel writing. I'm ruined, I say. :) -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From scarblac@pino.selwerd.nl Fri Mar 2 07:30:48 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Fri, 2 Mar 2001 08:30:48 +0100 Subject: [Tutor] My two cents worth re Python Newbies In-Reply-To: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au>; from arthur.watts@gbst.com on Wed, Feb 28, 2001 at 12:43:53PM +1000 References: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au> Message-ID: <20010302083048.A1489@pino.selwerd.nl> On Wed, Feb 28, 2001 at 12:43:53PM +1000, Arthur Watts wrote: > The majority of posts to the Tutor mailing lists are from people who > have tried to resolve a particular problem before resorting to the list. > Some, however, are simply 'noise'. I find the patient, thoughtful replies > given by the good souls on this list to be a real eye-opener, and I commend > you for your warmth and dedication when responding to newbie enquiries. My > own view is that the list should be for people who are able to : > > a. Read > b. Use a Net search engine > c. Navigate to www.python.org > d. Use the skills detailed above to find other Python resources My own view is that the list should be for people who are new to Python and want to learn it, and that's all. Someone on comp.lang.python asked what a text editor was and got some good replies. On the other hand sometimes extremely difficult questions will be answered real quickly as well. That's what I like about the Python community. > I realise that some may brand me elitist, but I am far from it : I > still have a lot to learn re. Python and other Open Source products. The key > is that I am prepared to actually cut some code or attempt to configure a > product before I fire off a posting re. a particular issue. We need to > welcome thinking people to the Python community, and filter out those who > have a problem with RTFM. This is where I totally disagree. What we need to do is help people learn Python. That's what this list does. If they have a problem with thinking or RTFM, we can teach them. If you don't want to waste time explaining stuff that is obvious to you, then don't. Filtering out people because they're not intelligent enough according to you is the most elitist idea I've heard this week. The *last* thing the community needs is people who point out "RTFM" to every question they see... -- Remco Gerlich From deirdre@deirdre.net Fri Mar 2 07:34:41 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Mar 2001 23:34:41 -0800 (PST) Subject: [Tutor] Tip : building Apache modules under Compaq Tru-64 Unix (formerly Digital Unix / OSF1) In-Reply-To: <1CDB101F0CB6D311882F0000F806392402F16386@aquarius.bne.star.com.au> Message-ID: <Pine.LNX.4.31.0103012333590.9383-100000@emperor.deirdre.org> On Fri, 2 Mar 2001, Arthur Watts wrote: > Those of us with Tru-64 often run into some interesting problems > when buiilding Open Source software, particularly software which does > not come with a configure script. The recent upgrade to v5.0 of Tru-64 > caught out a lot of the configure scripts, but this tip is for those > who have to 'wing it' completely. Thanks. I remember when I was using 32 and 64 bit IRIX and the info was hard to find to get certain things to work. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kalle@gnupung.net Fri Mar 2 10:38:01 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 2 Mar 2001 11:38:01 +0100 Subject: [Tutor] Memory Gotchas? In-Reply-To: <01030120033105.01210@shecom>; from tim@johnsons-web.com on Thu, Mar 01, 2001 at 07:59:52PM -0900 References: <384505273.983500480751.JavaMail.root@web394-mc> <01030120033105.01210@shecom> Message-ID: <20010302113801.A2295@father> --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Tim Johnson: > Hello All: > I would appreciate being pointed towards documentation on Python > memory allocation. >=20 > I'm especially interested in avoiding coding mistakes which could lead to > memory leaks. Well, there are basically two kinds of memory leaks in python programs. 1) Circular references [a good description here, anyone?] Basically, they are not a very big problem with the GC in 2.0, but may well bite you in 1.5.2. More about them in the FAQ: http://www.python.org/doc/FAQ.html#6.14 A module by Tim Peters to detect them: http://www.python.org/ftp/python/contrib-09-Dec-1999/System/Cyclops.py 2) Memory leaks in C modules. This can be due to bad reference counting (not Py_DECREF()ing enough) or just ordinary C memory leaks (malloc() without free()). Also note that the opposite is also possible, leading to segmentation fault= s. HTH, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --5mCyUwZo2JvN/JJP Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6n3gJdNeA1787sd0RAsEMAKC6VQg8qoeVjrBS3pqK89mNb1mq4ACgvUT4 cU4keSE4qwolO2QltClo784= =NNeH -----END PGP SIGNATURE----- --5mCyUwZo2JvN/JJP-- From NHYTRO@compuserve.com Fri Mar 2 11:07:41 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Fri, 2 Mar 2001 06:07:41 -0500 Subject: [Tutor] Customising TK Apps. Message-ID: <200103020607_MC2-C74E-6FDA@compuserve.com> Hi Python- Tutor list! I was wondering if one is able to customize TK applications, for example the little "tk" that appears in the frame bar of a TK application, my = introductory Python book from O=B4reily does not explain this feature. Thanks Sharriff From gcs@agentsinside.com Fri Mar 2 11:09:53 2001 From: gcs@agentsinside.com (GCS) Date: Fri, 2 Mar 2001 12:09:53 +0100 Subject: [Tutor] Database connectivity Message-ID: <20010302120953.A927@esparrall.udg.es> Hello, Can someone point me out with a good documentation how to connect to Postgres? I can not find any of them in the library reference. Is it supported? Regards, Laszlo From Lindsay.Davies@moonshine.co.uk Fri Mar 2 11:32:12 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Fri, 2 Mar 2001 11:32:12 +0000 Subject: [Tutor] Database connectivity In-Reply-To: <20010302120953.A927@esparrall.udg.es> References: <20010302120953.A927@esparrall.udg.es> Message-ID: <p05010416b6c5344f939c@[195.102.186.233]> On 2/3/01, GCS wrote about '[Tutor] Database connectivity': >Hello, > >Can someone point me out with a good documentation how to connect to Postgres? >I can not find any of them in the library reference. Is it supported? Here are some pointers... http://www.python.org/topics/database/DatabaseAPI-2.0.html http://www.python.org/topics/database/ http://www.druid.net/pygresql/ http://popy.sourceforge.net/ Best wishes, Lindsay From alan.gauld@bt.com Fri Mar 2 11:24:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 2 Mar 2001 11:24:29 -0000 Subject: [Tutor] Memory Gotchas? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5E2@mbtlipnt02.btlabs.bt.co.uk> > I would appreciate being pointed towards documentation on Python > memory allocation. Well, in principle you shouldn't need to worry since the garbage collector will do it for you. If you try to be too clever and anticipate what the GC does you run the risk of writing code that won't work as expected in later versiuons of Python. Its usually better to just trust the GC... But if you must find out whats happening under the hood you can look at the Python Reference Manual about the Garbage Collector. ISTR it has pretty good descriptions of just what is colleted and when. > I'm especially interested in avoiding coding mistakes which > could lead to memory leaks. AFAIK, aside from circular references, there aren't too many possibilities. Its not like C/C++ Alan g. From alan.gauld@bt.com Fri Mar 2 11:20:35 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 2 Mar 2001 11:20:35 -0000 Subject: [Tutor] dictionary Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5E1@mbtlipnt02.btlabs.bt.co.uk> > i have file which contain dictionary. and i wrote some code > and import the dictionary from that file I assume you have a file containing some kind of paired information rather than a python dictionary? Maybe it looks like: ------------ SomeKey: A string that matches the key AnotherKey: A string that matcher another key ...etc. ------------ You have written a file that reads this file - maybe into a Python dictionary? I'll assume so... > and i want to add entry to existing > dictionary and after this to save the > change to original file. Add to the dictionary as normal Python: filedict['BrandNew'] = 'Yet another string' Then save the entire dictionary by closing the file, opening it in read mode and writing out your dictionary: close(infile) outfile = open('MyDictionaryFile.txt','w') for key in filedict.getkeys(): outfile.writeline(key + filedict[key]) close(outfile) Or am I making lots of wrong assumptions? Alan g. From dyoo@hkn.eecs.berkeley.edu Fri Mar 2 12:24:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 2 Mar 2001 04:24:37 -0800 (PST) Subject: [Tutor] Customising TK Apps. In-Reply-To: <200103020607_MC2-C74E-6FDA@compuserve.com> Message-ID: <Pine.LNX.4.21.0103020402170.891-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Sharriff Aina wrote: > I was wondering if one is able to customize TK applications, for example > the little "tk" that appears in the frame bar of a TK application, my=20 > introductory Python book from O=B4reily does not explain this feature. I took a quick look at a Tkinter-based game called PySol: http://wildsau.idv.uni-linz.ac.at/mfx/pysol/ They have source code available, which is great, because it's one of the most impressive demonstrations of Tkinter use that I've seen. (Plus a great time waster. *grin*) In the PySol source code, it appears that they use the call: wm_set_icon(top, app.dataloader.findIcon()) (in src/main.py) and their definition of wm_set_icon() is this: ### src/tk/tkutil.py def wm_set_icon(window, filename): if not filename: return if os.name =3D=3D "posix": window.wm_iconbitmap("@" + filename) window.wm_iconmask("@" + filename) ### wm_iconbitmap() and wm_iconmask() do appear to be real functions, from a quick interpreter check: ### >>> x =3D Tkinter.Tk() >>> x.wm_iconbitmap <method Wm.wm_iconbitmap of Tk instance at 80929d8> >>> x.wm_iconmask =20 <method Wm.wm_iconmask of Tk instance at 80929d8> ### This is all a large guess though, because I'm inexperienced with Tk stuff. = =20 It does seem to be doing something, though, because in Linux, that part of the code seems responsible for changing the icon. Can you check to see that PySol does change its icon appropriately on a Windows system too? If so, then we're on the right track. If not, you'll still have a fun solitare game installed on your system. *grin* Good luck! From livelikemad@yahoo.com Fri Mar 2 15:01:32 2001 From: livelikemad@yahoo.com (Chris McCormick) Date: Fri, 2 Mar 2001 07:01:32 -0800 (PST) Subject: [Tutor] TK icons, and a dumb question. :-) Message-ID: <20010302150132.89261.qmail@web10510.mail.yahoo.com> Someone was asking about the window icon in Tkinter. I'm a newbie, so I don't know how to do it myself, but there's a great reference called the Tkinter Life Preserver at the Python site: --> http://www.python.org/doc/life-preserver It has a section on the Tk window manager class (Tkinter.Wm). I think this is what you need to learn. It's at http://www.python.org/doc/life-preserver/WindowMgr.html. Then come back and tell us all how to do it. :-) Oh, and a dumb question - if you get the list in digest format, is there any way to resond to a particular thread/e-mail? - Chris (who is still working on getting reasonable animation out of Tkinter, dagnabit) __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From mbc2@netdoor.com Fri Mar 2 15:45:07 2001 From: mbc2@netdoor.com (Brad Chandler) Date: Fri, 2 Mar 2001 09:45:07 -0600 Subject: [Tutor] Database connectivity References: <20010302120953.A927@esparrall.udg.es> Message-ID: <002601c0a32f$c206f480$111c0d0a@spb.state.ms.us> ----- Original Message ----- From: "GCS" <gcs@agentsinside.com> To: <tutor@python.org> Sent: Friday, March 02, 2001 5:09 AM Subject: [Tutor] Database connectivity > Hello, > > Can someone point me out with a good documentation how to connect to Postgres? > I can not find any of them in the library reference. Is it supported? > > Regards, Laszlo I use PyGreSQL and have been very pleased with it. There are several others out there and I've tried one other (I can't remember the name) but couldn't get it to work. If you installed Python from source, you should have no problem compiling PyGreSQL. But if you installed from an rpm, you might need the development rpm as well (if there is one). You might also need the PostgreSQL source, I'm not sure. I installed both python and postgres from source so I'm not sure how it PyGreSQL would compile if had I used RPMs. Brad From tim@johnsons-web.com Fri Mar 2 16:57:54 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Fri, 2 Mar 2001 07:57:54 -0900 Subject: [Tutor] Memory Gotchas? References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5E2@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01030207591209.01210@shecom> Hi Alan: On Fri, 02 Mar 2001, alan.gauld@bt.com wrote: <snip> > But if you must find out whats happening under the hood > you can look at the Python Reference Manual about the > Garbage Collector. ISTR it has pretty good descriptions > of just what is colleted and when. Thanks............... > > I'm especially interested in avoiding coding mistakes which > > could lead to memory leaks. > > AFAIK, aside from circular references, there aren't too many > possibilities. Its not like C/C++ Yippee!! Regards :) -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From alan.gauld@bt.com Fri Mar 2 17:11:30 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 2 Mar 2001 17:11:30 -0000 Subject: [Tutor] TK icons, and a dumb question. :-) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5E8@mbtlipnt02.btlabs.bt.co.uk> > It has a section on the Tk window manager class > (Tkinter.Wm). I think this is what you need to learn. > It's at > http://www.python.org/doc/life-preserver/WindowMgr.html. > Unfortunately the icon changing window manager functions only seem to work under *nix/X windows not the MS variety :-( > Oh, and a dumb question - if you get the list in > digest format, is there any way to resond to a > particular thread/e-mail? Well I'm using the digest and I just hit reply to the open message. Have you turned on MIME format rather than inline text? Alan g. From bobhicks@adelphia.net Fri Mar 2 17:16:33 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Fri, 02 Mar 2001 12:16:33 -0500 Subject: [Tutor] Changing modes? In-Reply-To: <E14YsvV-0008V2-00@mail.python.org> Message-ID: <B6C53FA1.17DB%bobhicks@adelphia.net> I would like to change from digest to individual mode on this list... - Bob > From: tutor-request@python.org > Reply-To: tutor@python.org > Date: Fri, 02 Mar 2001 12:01:09 -0500 > To: tutor@python.org > Subject: Tutor digest, Vol 1 #625 - 16 msgs > > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-request@python.org > > You can reach the person managing the list at > tutor-admin@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: My two cents worth re Python Newbies (Deirdre Saoirse) > 2. Re: My two cents worth re Python Newbies (Sheila King) > 3. Re: My two cents worth re Python Newbies (Deirdre Saoirse) > 4. Re: My two cents worth re Python Newbies (Remco Gerlich) > 5. Re: Tip : building Apache modules under Compaq Tru-64 Unix > (formerly Digital Unix / OSF1) (Deirdre Saoirse) > 6. Re: Memory Gotchas? (Kalle Svensson) > 7. Customising TK Apps. (Sharriff Aina) > 8. Database connectivity (GCS) > 9. Re: Database connectivity (Lindsay Davies) > 10. RE: Memory Gotchas? (alan.gauld@bt.com) > 11. RE: dictionary (alan.gauld@bt.com) > 12. Re: Customising TK Apps. (Danny Yoo) > 13. TK icons, and a dumb question. :-) (Chris McCormick) > 14. Re: Database connectivity (Brad Chandler) > 15. RE: Memory Gotchas? (Tim Johnson) > > --__--__-- > > Message: 1 > Date: Thu, 1 Mar 2001 23:13:57 -0800 (PST) > From: Deirdre Saoirse <deirdre@deirdre.net> > To: Sheila King <sheila@thinkspot.net> > cc: <tutor@python.org> > Subject: Re: [Tutor] My two cents worth re Python Newbies > > On Thu, 1 Mar 2001, Sheila King wrote: > >> (1) if you don't have the patience to reply to a post, because it is in a FAQ >> or could be found by a search, then simply don't reply. > > There are a number of reasons I don't reply to specific posts: > > 1) Often, especially lately, I've simply been too busy. > > 2) The user asks a Windows-specific question that I don't know the answer > to. > > 3) I'd need to actually open an interpreter and futz for a couple minutes > and, while I could easily answer some questions, that takes too much > interruption. > > On the other hand, I don't see questions going unanswered (at least not > for long), so I think that the system works pretty well. > > -- > _Deirdre deirdre@deirdre.net http://www.deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > > > --__--__-- > > Message: 2 > From: Sheila King <sheila@thinkspot.net> > To: Deirdre Saoirse <deirdre@deirdre.net> > Cc: <tutor@python.org> > Subject: Re: [Tutor] My two cents worth re Python Newbies > Date: Thu, 01 Mar 2001 23:25:42 -0800 > > On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse <deirdre@deirdre.net> > wrote about Re: [Tutor] My two cents worth re Python Newbies: > > :On the other hand, I don't see questions going unanswered (at least not > :for long), so I think that the system works pretty well. > > Well, that's kind of what I was saying, only much more succinct. > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > > > --__--__-- > > Message: 3 > Date: Thu, 1 Mar 2001 23:22:57 -0800 (PST) > From: Deirdre Saoirse <deirdre@deirdre.net> > To: Sheila King <sheila@thinkspot.net> > cc: <tutor@python.org> > Subject: Re: [Tutor] My two cents worth re Python Newbies > > On Thu, 1 Mar 2001, Sheila King wrote: > >> On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse >> <deirdre@deirdre.net> >> wrote about Re: [Tutor] My two cents worth re Python Newbies: >> >> :On the other hand, I don't see questions going unanswered (at least not >> :for long), so I think that the system works pretty well. >> >> Well, that's kind of what I was saying, only much more succinct. > > That's the problem with having had Horrible Hugh as an English teacher: he > could cut 50% out of anyone's writing without changing the meaning. > > And here I am trying to get my Master's degree in novel writing. > > I'm ruined, I say. :) > > -- > _Deirdre deirdre@deirdre.net http://www.deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > > > --__--__-- > > Message: 4 > Date: Fri, 2 Mar 2001 08:30:48 +0100 > From: Remco Gerlich <scarblac@pino.selwerd.nl> > To: tutor@python.org > Subject: Re: [Tutor] My two cents worth re Python Newbies > > On Wed, Feb 28, 2001 at 12:43:53PM +1000, Arthur Watts wrote: >> The majority of posts to the Tutor mailing lists are from people who >> have tried to resolve a particular problem before resorting to the list. >> Some, however, are simply 'noise'. I find the patient, thoughtful replies >> given by the good souls on this list to be a real eye-opener, and I commend >> you for your warmth and dedication when responding to newbie enquiries. My >> own view is that the list should be for people who are able to : >> >> a. Read >> b. Use a Net search engine >> c. Navigate to www.python.org >> d. Use the skills detailed above to find other Python resources > > My own view is that the list should be for people who are new to Python and > want to learn it, and that's all. > > Someone on comp.lang.python asked what a text editor was and got some good > replies. On the other hand sometimes extremely difficult questions will be > answered real quickly as well. That's what I like about the Python community. > >> I realise that some may brand me elitist, but I am far from it : I >> still have a lot to learn re. Python and other Open Source products. The key >> is that I am prepared to actually cut some code or attempt to configure a >> product before I fire off a posting re. a particular issue. We need to >> welcome thinking people to the Python community, and filter out those who >> have a problem with RTFM. > > This is where I totally disagree. What we need to do is help people learn > Python. That's what this list does. If they have a problem with thinking or > RTFM, we can teach them. If you don't want to waste time explaining stuff > that is obvious to you, then don't. > > Filtering out people because they're not intelligent enough according to you > is the most elitist idea I've heard this week. > > The *last* thing the community needs is people who point out "RTFM" to every > question they see... > > -- > Remco Gerlich > > > --__--__-- > > Message: 5 > Date: Thu, 1 Mar 2001 23:34:41 -0800 (PST) > From: Deirdre Saoirse <deirdre@deirdre.net> > To: Arthur Watts <arthur.watts@gbst.com> > cc: "'tutor@python.org'" <tutor@python.org> > Subject: Re: [Tutor] Tip : building Apache modules under Compaq Tru-64 Unix > (formerly Digital Unix / OSF1) > > On Fri, 2 Mar 2001, Arthur Watts wrote: > >> Those of us with Tru-64 often run into some interesting problems >> when buiilding Open Source software, particularly software which does >> not come with a configure script. The recent upgrade to v5.0 of Tru-64 >> caught out a lot of the configure scripts, but this tip is for those >> who have to 'wing it' completely. > > Thanks. I remember when I was using 32 and 64 bit IRIX and the info was > hard to find to get certain things to work. > > -- > _Deirdre deirdre@deirdre.net http://www.deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > > > --__--__-- > > Message: 6 > Date: Fri, 2 Mar 2001 11:38:01 +0100 > From: Kalle Svensson <kalle@gnupung.net> > To: tutor@python.org > Subject: Re: [Tutor] Memory Gotchas? > > > --5mCyUwZo2JvN/JJP > Content-Type: text/plain; charset=us-ascii > Content-Disposition: inline > Content-Transfer-Encoding: quoted-printable > > Sez Tim Johnson: >> Hello All: >> I would appreciate being pointed towards documentation on Python >> memory allocation. >> =20 >> I'm especially interested in avoiding coding mistakes which could lead to >> memory leaks. > > Well, there are basically two kinds of memory leaks in python programs. > > 1) Circular references > [a good description here, anyone?] > Basically, they are not a very big problem with the GC in 2.0, but may well > bite you in 1.5.2. > More about them in the FAQ: http://www.python.org/doc/FAQ.html#6.14 > A module by Tim Peters to detect them: > http://www.python.org/ftp/python/contrib-09-Dec-1999/System/Cyclops.py > > 2) Memory leaks in C modules. > This can be due to bad reference counting (not Py_DECREF()ing enough) or > just ordinary C memory leaks (malloc() without free()). > Also note that the opposite is also possible, leading to segmentation fault= > s. > > HTH, > Kalle > --=20 > Email: kalle@gnupung.net | You can tune a filesystem, but you > Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) > PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD > > --5mCyUwZo2JvN/JJP > Content-Type: application/pgp-signature > Content-Disposition: inline > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.4 (GNU/Linux) > Comment: For info see http://www.gnupg.org > > iD8DBQE6n3gJdNeA1787sd0RAsEMAKC6VQg8qoeVjrBS3pqK89mNb1mq4ACgvUT4 > cU4keSE4qwolO2QltClo784= > =NNeH > -----END PGP SIGNATURE----- > > --5mCyUwZo2JvN/JJP-- > > > --__--__-- > > Message: 7 > Date: Fri, 2 Mar 2001 06:07:41 -0500 > From: Sharriff Aina <NHYTRO@compuserve.com> > To: "INTERNET:tutor@python.org" <tutor@python.org> > Subject: [Tutor] Customising TK Apps. > > Hi Python- Tutor list! > > I was wondering if one is able to customize TK applications, for example > the little "tk" that appears in the frame bar of a TK application, my = > > introductory Python book from O=B4reily does not explain this feature. > > > Thanks > > > Sharriff > > > > --__--__-- > > Message: 8 > Date: Fri, 2 Mar 2001 12:09:53 +0100 > From: GCS <gcs@agentsinside.com> > To: tutor@python.org > Subject: [Tutor] Database connectivity > > Hello, > > Can someone point me out with a good documentation how to connect to Postgres? > I can not find any of them in the library reference. Is it supported? > > Regards, Laszlo > > > --__--__-- > > Message: 9 > Date: Fri, 2 Mar 2001 11:32:12 +0000 > To: tutor@python.org > From: Lindsay Davies <Lindsay.Davies@moonshine.co.uk> > Subject: Re: [Tutor] Database connectivity > > On 2/3/01, GCS wrote about '[Tutor] Database connectivity': >> Hello, >> >> Can someone point me out with a good documentation how to connect to >> Postgres? >> I can not find any of them in the library reference. Is it supported? > > Here are some pointers... > > http://www.python.org/topics/database/DatabaseAPI-2.0.html > http://www.python.org/topics/database/ > http://www.druid.net/pygresql/ > http://popy.sourceforge.net/ > > Best wishes, > > Lindsay > > > > --__--__-- > > Message: 10 > From: alan.gauld@bt.com > To: tim@johnsons-web.com, tutor@python.org > Subject: RE: [Tutor] Memory Gotchas? > Date: Fri, 2 Mar 2001 11:24:29 -0000 > >> I would appreciate being pointed towards documentation on Python >> memory allocation. > > Well, in principle you shouldn't need to worry since > the garbage collector will do it for you. If you try > to be too clever and anticipate what the GC does you > run the risk of writing code that won't work as expected > in later versiuons of Python. Its usually better to > just trust the GC... > > But if you must find out whats happening under the hood > you can look at the Python Reference Manual about the > Garbage Collector. ISTR it has pretty good descriptions > of just what is colleted and when. > >> I'm especially interested in avoiding coding mistakes which >> could lead to memory leaks. > > AFAIK, aside from circular references, there aren't too many > possibilities. Its not like C/C++ > > Alan g. > > > --__--__-- > > Message: 11 > From: alan.gauld@bt.com > To: toxx@post.com, tutor@python.org > Subject: RE: [Tutor] dictionary > Date: Fri, 2 Mar 2001 11:20:35 -0000 > >> i have file which contain dictionary. and i wrote some code >> and import the dictionary from that file > > I assume you have a file containing some kind of > paired information rather than a python dictionary? > Maybe it looks like: > ------------ > SomeKey: A string that matches the key > AnotherKey: A string that matcher another key > ...etc. > ------------ > > You have written a file that reads this file > - maybe into a Python dictionary? I'll assume > so... > > >> and i want to add entry to existing >> dictionary and after this to save the >> change to original file. > > Add to the dictionary as normal Python: > > filedict['BrandNew'] = 'Yet another string' > > Then save the entire dictionary by closing the file, > opening it in read mode and writing out your dictionary: > > close(infile) > outfile = open('MyDictionaryFile.txt','w') > for key in filedict.getkeys(): > outfile.writeline(key + filedict[key]) > close(outfile) > > Or am I making lots of wrong assumptions? > > Alan g. > > > --__--__-- > > Message: 12 > Date: Fri, 2 Mar 2001 04:24:37 -0800 (PST) > From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu> > To: Sharriff Aina <NHYTRO@compuserve.com> > cc: "INTERNET:tutor@python.org" <tutor@python.org> > Subject: Re: [Tutor] Customising TK Apps. > > On Fri, 2 Mar 2001, Sharriff Aina wrote: > >> I was wondering if one is able to customize TK applications, for example >> the little "tk" that appears in the frame bar of a TK application, my=20 >> introductory Python book from O=B4reily does not explain this feature. > > I took a quick look at a Tkinter-based game called PySol: > > http://wildsau.idv.uni-linz.ac.at/mfx/pysol/ > > They have source code available, which is great, because it's one of the > most impressive demonstrations of Tkinter use that I've seen. (Plus a > great time waster. *grin*) > > > In the PySol source code, it appears that they use the call: > > wm_set_icon(top, app.dataloader.findIcon()) > > (in src/main.py) > > and their definition of wm_set_icon() is this: > > ### src/tk/tkutil.py > def wm_set_icon(window, filename): > if not filename: > return > if os.name =3D=3D "posix": > window.wm_iconbitmap("@" + filename) > window.wm_iconmask("@" + filename) > ### > > > wm_iconbitmap() and wm_iconmask() do appear to be real functions, from a > quick interpreter check: > > ### >>>> x =3D Tkinter.Tk() >>>> x.wm_iconbitmap > <method Wm.wm_iconbitmap of Tk instance at 80929d8> >>>> x.wm_iconmask =20 > <method Wm.wm_iconmask of Tk instance at 80929d8> > ### > > > This is all a large guess though, because I'm inexperienced with Tk stuff. = > =20 > It does seem to be doing something, though, because in Linux, that part of > the code seems responsible for changing the icon. > > Can you check to see that PySol does change its icon appropriately on a > Windows system too? If so, then we're on the right track. If not, you'll > still have a fun solitare game installed on your system. *grin* > > > Good luck! > > > > --__--__-- > > Message: 13 > Date: Fri, 2 Mar 2001 07:01:32 -0800 (PST) > From: Chris McCormick <livelikemad@yahoo.com> > To: tutor@python.org > Subject: [Tutor] TK icons, and a dumb question. :-) > > Someone was asking about the window icon in Tkinter. > I'm a newbie, so I don't know how to do it myself, but > there's a great reference called the Tkinter Life > Preserver at the Python site: --> > http://www.python.org/doc/life-preserver > > It has a section on the Tk window manager class > (Tkinter.Wm). I think this is what you need to learn. > It's at > http://www.python.org/doc/life-preserver/WindowMgr.html. > > Then come back and tell us all how to do it. :-) > > Oh, and a dumb question - if you get the list in > digest format, is there any way to resond to a > particular thread/e-mail? > > - Chris (who is still working on getting reasonable > animation out of Tkinter, dagnabit) > > __________________________________________________ > Do You Yahoo!? > Get email at your own domain with Yahoo! Mail. > http://personal.mail.yahoo.com/ > > > --__--__-- > > Message: 14 > From: "Brad Chandler" <mbc2@netdoor.com> > To: <tutor@python.org> > Subject: Re: [Tutor] Database connectivity > Date: Fri, 2 Mar 2001 09:45:07 -0600 > > ----- Original Message ----- > From: "GCS" <gcs@agentsinside.com> > To: <tutor@python.org> > Sent: Friday, March 02, 2001 5:09 AM > Subject: [Tutor] Database connectivity > > >> Hello, >> >> Can someone point me out with a good documentation how to connect to > Postgres? >> I can not find any of them in the library reference. Is it supported? >> >> Regards, Laszlo > > I use PyGreSQL and have been very pleased with it. There are several others > out there and I've tried one other (I can't remember the name) but couldn't > get it to work. If you installed Python from source, you should have no > problem compiling PyGreSQL. But if you installed from an rpm, you might > need the development rpm as well (if there is one). You might also need the > PostgreSQL source, I'm not sure. I installed both python and postgres from > source so I'm not sure how it PyGreSQL would compile if had I used RPMs. > > Brad > > > > --__--__-- > > Message: 15 > From: Tim Johnson <tim@johnsons-web.com> > To: alan.gauld@bt.com, > tim@johnsons-web.com, > tutor@python.org > Subject: RE: [Tutor] Memory Gotchas? > Date: Fri, 2 Mar 2001 07:57:54 -0900 > > Hi Alan: > On Fri, 02 Mar 2001, alan.gauld@bt.com wrote: > <snip> >> But if you must find out whats happening under the hood >> you can look at the Python Reference Manual about the >> Garbage Collector. ISTR it has pretty good descriptions >> of just what is colleted and when. > Thanks............... >>> I'm especially interested in avoiding coding mistakes which >>> could lead to memory leaks. >> >> AFAIK, aside from circular references, there aren't too many >> possibilities. Its not like C/C++ > Yippee!! > Regards :) > -- > Tim Johnson > ----------- > "Of all manifestations of power, > restraint impresses the most." > -Thucydides > > > > --__--__-- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest From rob@jam.rr.com Fri Mar 2 17:23:21 2001 From: rob@jam.rr.com (R. A.) Date: Fri, 02 Mar 2001 11:23:21 -0600 Subject: [Tutor] Changing modes? References: <B6C53FA1.17DB%bobhicks@adelphia.net> Message-ID: <3A9FD709.84710F4B@jam.rr.com> You may change your mode at the following URL: http://mail.python.org/mailman/listinfo/tutor Rob Robert L Hicks wrote: > > I would like to change from digest to individual mode on this list... > > - Bob > > > From: tutor-request@python.org > > Reply-To: tutor@python.org > > Date: Fri, 02 Mar 2001 12:01:09 -0500 > > To: tutor@python.org > > Subject: Tutor digest, Vol 1 #625 - 16 msgs > > > > Send Tutor mailing list submissions to > > tutor@python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://mail.python.org/mailman/listinfo/tutor > > or, via email, send a message with subject or body 'help' to > > tutor-request@python.org > > > > You can reach the person managing the list at > > tutor-admin@python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Tutor digest..." > > > > > > Today's Topics: > > > > 1. Re: My two cents worth re Python Newbies (Deirdre Saoirse) > > 2. Re: My two cents worth re Python Newbies (Sheila King) > > 3. Re: My two cents worth re Python Newbies (Deirdre Saoirse) > > 4. Re: My two cents worth re Python Newbies (Remco Gerlich) > > 5. Re: Tip : building Apache modules under Compaq Tru-64 Unix > > (formerly Digital Unix / OSF1) (Deirdre Saoirse) > > 6. Re: Memory Gotchas? (Kalle Svensson) > > 7. Customising TK Apps. (Sharriff Aina) > > 8. Database connectivity (GCS) > > 9. Re: Database connectivity (Lindsay Davies) > > 10. RE: Memory Gotchas? (alan.gauld@bt.com) > > 11. RE: dictionary (alan.gauld@bt.com) > > 12. Re: Customising TK Apps. (Danny Yoo) > > 13. TK icons, and a dumb question. :-) (Chris McCormick) > > 14. Re: Database connectivity (Brad Chandler) > > 15. RE: Memory Gotchas? (Tim Johnson) > > > > --__--__-- > > > > Message: 1 > > Date: Thu, 1 Mar 2001 23:13:57 -0800 (PST) > > From: Deirdre Saoirse <deirdre@deirdre.net> > > To: Sheila King <sheila@thinkspot.net> > > cc: <tutor@python.org> > > Subject: Re: [Tutor] My two cents worth re Python Newbies > > > > On Thu, 1 Mar 2001, Sheila King wrote: > > > >> (1) if you don't have the patience to reply to a post, because it is in a FAQ > >> or could be found by a search, then simply don't reply. > > > > There are a number of reasons I don't reply to specific posts: > > > > 1) Often, especially lately, I've simply been too busy. > > > > 2) The user asks a Windows-specific question that I don't know the answer > > to. > > > > 3) I'd need to actually open an interpreter and futz for a couple minutes > > and, while I could easily answer some questions, that takes too much > > interruption. > > > > On the other hand, I don't see questions going unanswered (at least not > > for long), so I think that the system works pretty well. > > > > -- > > _Deirdre deirdre@deirdre.net http://www.deirdre.net > > "I love deadlines. I like the whooshing sound they make as they fly by." > > - Douglas Adams > > > > > > > > --__--__-- > > > > Message: 2 > > From: Sheila King <sheila@thinkspot.net> > > To: Deirdre Saoirse <deirdre@deirdre.net> > > Cc: <tutor@python.org> > > Subject: Re: [Tutor] My two cents worth re Python Newbies > > Date: Thu, 01 Mar 2001 23:25:42 -0800 > > > > On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse <deirdre@deirdre.net> > > wrote about Re: [Tutor] My two cents worth re Python Newbies: > > > > :On the other hand, I don't see questions going unanswered (at least not > > :for long), so I think that the system works pretty well. > > > > Well, that's kind of what I was saying, only much more succinct. > > > > -- > > Sheila King > > http://www.thinkspot.net/sheila/ > > http://www.k12groups.org/ > > > > > > > > --__--__-- > > > > Message: 3 > > Date: Thu, 1 Mar 2001 23:22:57 -0800 (PST) > > From: Deirdre Saoirse <deirdre@deirdre.net> > > To: Sheila King <sheila@thinkspot.net> > > cc: <tutor@python.org> > > Subject: Re: [Tutor] My two cents worth re Python Newbies > > > > On Thu, 1 Mar 2001, Sheila King wrote: > > > >> On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse > >> <deirdre@deirdre.net> > >> wrote about Re: [Tutor] My two cents worth re Python Newbies: > >> > >> :On the other hand, I don't see questions going unanswered (at least not > >> :for long), so I think that the system works pretty well. > >> > >> Well, that's kind of what I was saying, only much more succinct. > > > > That's the problem with having had Horrible Hugh as an English teacher: he > > could cut 50% out of anyone's writing without changing the meaning. > > > > And here I am trying to get my Master's degree in novel writing. > > > > I'm ruined, I say. :) > > > > -- > > _Deirdre deirdre@deirdre.net http://www.deirdre.net > > "I love deadlines. I like the whooshing sound they make as they fly by." > > - Douglas Adams > > > > > > > > --__--__-- > > > > Message: 4 > > Date: Fri, 2 Mar 2001 08:30:48 +0100 > > From: Remco Gerlich <scarblac@pino.selwerd.nl> > > To: tutor@python.org > > Subject: Re: [Tutor] My two cents worth re Python Newbies > > > > On Wed, Feb 28, 2001 at 12:43:53PM +1000, Arthur Watts wrote: > >> The majority of posts to the Tutor mailing lists are from people who > >> have tried to resolve a particular problem before resorting to the list. > >> Some, however, are simply 'noise'. I find the patient, thoughtful replies > >> given by the good souls on this list to be a real eye-opener, and I commend > >> you for your warmth and dedication when responding to newbie enquiries. My > >> own view is that the list should be for people who are able to : > >> > >> a. Read > >> b. Use a Net search engine > >> c. Navigate to www.python.org > >> d. Use the skills detailed above to find other Python resources > > > > My own view is that the list should be for people who are new to Python and > > want to learn it, and that's all. > > > > Someone on comp.lang.python asked what a text editor was and got some good > > replies. On the other hand sometimes extremely difficult questions will be > > answered real quickly as well. That's what I like about the Python community. > > > >> I realise that some may brand me elitist, but I am far from it : I > >> still have a lot to learn re. Python and other Open Source products. The key > >> is that I am prepared to actually cut some code or attempt to configure a > >> product before I fire off a posting re. a particular issue. We need to > >> welcome thinking people to the Python community, and filter out those who > >> have a problem with RTFM. > > > > This is where I totally disagree. What we need to do is help people learn > > Python. That's what this list does. If they have a problem with thinking or > > RTFM, we can teach them. If you don't want to waste time explaining stuff > > that is obvious to you, then don't. > > > > Filtering out people because they're not intelligent enough according to you > > is the most elitist idea I've heard this week. > > > > The *last* thing the community needs is people who point out "RTFM" to every > > question they see... > > > > -- > > Remco Gerlich > > > > > > --__--__-- > > > > Message: 5 > > Date: Thu, 1 Mar 2001 23:34:41 -0800 (PST) > > From: Deirdre Saoirse <deirdre@deirdre.net> > > To: Arthur Watts <arthur.watts@gbst.com> > > cc: "'tutor@python.org'" <tutor@python.org> > > Subject: Re: [Tutor] Tip : building Apache modules under Compaq Tru-64 Unix > > (formerly Digital Unix / OSF1) > > > > On Fri, 2 Mar 2001, Arthur Watts wrote: > > > >> Those of us with Tru-64 often run into some interesting problems > >> when buiilding Open Source software, particularly software which does > >> not come with a configure script. The recent upgrade to v5.0 of Tru-64 > >> caught out a lot of the configure scripts, but this tip is for those > >> who have to 'wing it' completely. > > > > Thanks. I remember when I was using 32 and 64 bit IRIX and the info was > > hard to find to get certain things to work. > > > > -- > > _Deirdre deirdre@deirdre.net http://www.deirdre.net > > "I love deadlines. I like the whooshing sound they make as they fly by." > > - Douglas Adams > > > > > > > > --__--__-- > > > > Message: 6 > > Date: Fri, 2 Mar 2001 11:38:01 +0100 > > From: Kalle Svensson <kalle@gnupung.net> > > To: tutor@python.org > > Subject: Re: [Tutor] Memory Gotchas? > > > > > > --5mCyUwZo2JvN/JJP > > Content-Type: text/plain; charset=us-ascii > > Content-Disposition: inline > > Content-Transfer-Encoding: quoted-printable > > > > Sez Tim Johnson: > >> Hello All: > >> I would appreciate being pointed towards documentation on Python > >> memory allocation. > >> =20 > >> I'm especially interested in avoiding coding mistakes which could lead to > >> memory leaks. > > > > Well, there are basically two kinds of memory leaks in python programs. > > > > 1) Circular references > > [a good description here, anyone?] > > Basically, they are not a very big problem with the GC in 2.0, but may well > > bite you in 1.5.2. > > More about them in the FAQ: http://www.python.org/doc/FAQ.html#6.14 > > A module by Tim Peters to detect them: > > http://www.python.org/ftp/python/contrib-09-Dec-1999/System/Cyclops.py > > > > 2) Memory leaks in C modules. > > This can be due to bad reference counting (not Py_DECREF()ing enough) or > > just ordinary C memory leaks (malloc() without free()). > > Also note that the opposite is also possible, leading to segmentation fault= > > s. > > > > HTH, > > Kalle > > --=20 > > Email: kalle@gnupung.net | You can tune a filesystem, but you > > Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) > > PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD > > > > --5mCyUwZo2JvN/JJP > > Content-Type: application/pgp-signature > > Content-Disposition: inline > > > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.0.4 (GNU/Linux) > > Comment: For info see http://www.gnupg.org > > > > iD8DBQE6n3gJdNeA1787sd0RAsEMAKC6VQg8qoeVjrBS3pqK89mNb1mq4ACgvUT4 > > cU4keSE4qwolO2QltClo784= > > =NNeH > > -----END PGP SIGNATURE----- > > > > --5mCyUwZo2JvN/JJP-- > > > > > > --__--__-- > > > > Message: 7 > > Date: Fri, 2 Mar 2001 06:07:41 -0500 > > From: Sharriff Aina <NHYTRO@compuserve.com> > > To: "INTERNET:tutor@python.org" <tutor@python.org> > > Subject: [Tutor] Customising TK Apps. > > > > Hi Python- Tutor list! > > > > I was wondering if one is able to customize TK applications, for example > > the little "tk" that appears in the frame bar of a TK application, my = > > > > introductory Python book from O=B4reily does not explain this feature. > > > > > > Thanks > > > > > > Sharriff > > > > > > > > --__--__-- > > > > Message: 8 > > Date: Fri, 2 Mar 2001 12:09:53 +0100 > > From: GCS <gcs@agentsinside.com> > > To: tutor@python.org > > Subject: [Tutor] Database connectivity > > > > Hello, > > > > Can someone point me out with a good documentation how to connect to Postgres? > > I can not find any of them in the library reference. Is it supported? > > > > Regards, Laszlo > > > > > > --__--__-- > > > > Message: 9 > > Date: Fri, 2 Mar 2001 11:32:12 +0000 > > To: tutor@python.org > > From: Lindsay Davies <Lindsay.Davies@moonshine.co.uk> > > Subject: Re: [Tutor] Database connectivity > > > > On 2/3/01, GCS wrote about '[Tutor] Database connectivity': > >> Hello, > >> > >> Can someone point me out with a good documentation how to connect to > >> Postgres? > >> I can not find any of them in the library reference. Is it supported? > > > > Here are some pointers... > > > > http://www.python.org/topics/database/DatabaseAPI-2.0.html > > http://www.python.org/topics/database/ > > http://www.druid.net/pygresql/ > > http://popy.sourceforge.net/ > > > > Best wishes, > > > > Lindsay > > > > > > > > --__--__-- > > > > Message: 10 > > From: alan.gauld@bt.com > > To: tim@johnsons-web.com, tutor@python.org > > Subject: RE: [Tutor] Memory Gotchas? > > Date: Fri, 2 Mar 2001 11:24:29 -0000 > > > >> I would appreciate being pointed towards documentation on Python > >> memory allocation. > > > > Well, in principle you shouldn't need to worry since > > the garbage collector will do it for you. If you try > > to be too clever and anticipate what the GC does you > > run the risk of writing code that won't work as expected > > in later versiuons of Python. Its usually better to > > just trust the GC... > > > > But if you must find out whats happening under the hood > > you can look at the Python Reference Manual about the > > Garbage Collector. ISTR it has pretty good descriptions > > of just what is colleted and when. > > > >> I'm especially interested in avoiding coding mistakes which > >> could lead to memory leaks. > > > > AFAIK, aside from circular references, there aren't too many > > possibilities. Its not like C/C++ > > > > Alan g. > > > > > > --__--__-- > > > > Message: 11 > > From: alan.gauld@bt.com > > To: toxx@post.com, tutor@python.org > > Subject: RE: [Tutor] dictionary > > Date: Fri, 2 Mar 2001 11:20:35 -0000 > > > >> i have file which contain dictionary. and i wrote some code > >> and import the dictionary from that file > > > > I assume you have a file containing some kind of > > paired information rather than a python dictionary? > > Maybe it looks like: > > ------------ > > SomeKey: A string that matches the key > > AnotherKey: A string that matcher another key > > ...etc. > > ------------ > > > > You have written a file that reads this file > > - maybe into a Python dictionary? I'll assume > > so... > > > > > >> and i want to add entry to existing > >> dictionary and after this to save the > >> change to original file. > > > > Add to the dictionary as normal Python: > > > > filedict['BrandNew'] = 'Yet another string' > > > > Then save the entire dictionary by closing the file, > > opening it in read mode and writing out your dictionary: > > > > close(infile) > > outfile = open('MyDictionaryFile.txt','w') > > for key in filedict.getkeys(): > > outfile.writeline(key + filedict[key]) > > close(outfile) > > > > Or am I making lots of wrong assumptions? > > > > Alan g. > > > > > > --__--__-- > > > > Message: 12 > > Date: Fri, 2 Mar 2001 04:24:37 -0800 (PST) > > From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu> > > To: Sharriff Aina <NHYTRO@compuserve.com> > > cc: "INTERNET:tutor@python.org" <tutor@python.org> > > Subject: Re: [Tutor] Customising TK Apps. > > > > On Fri, 2 Mar 2001, Sharriff Aina wrote: > > > >> I was wondering if one is able to customize TK applications, for example > >> the little "tk" that appears in the frame bar of a TK application, my=20 > >> introductory Python book from O=B4reily does not explain this feature. > > > > I took a quick look at a Tkinter-based game called PySol: > > > > http://wildsau.idv.uni-linz.ac.at/mfx/pysol/ > > > > They have source code available, which is great, because it's one of the > > most impressive demonstrations of Tkinter use that I've seen. (Plus a > > great time waster. *grin*) > > > > > > In the PySol source code, it appears that they use the call: > > > > wm_set_icon(top, app.dataloader.findIcon()) > > > > (in src/main.py) > > > > and their definition of wm_set_icon() is this: > > > > ### src/tk/tkutil.py > > def wm_set_icon(window, filename): > > if not filename: > > return > > if os.name =3D=3D "posix": > > window.wm_iconbitmap("@" + filename) > > window.wm_iconmask("@" + filename) > > ### > > > > > > wm_iconbitmap() and wm_iconmask() do appear to be real functions, from a > > quick interpreter check: > > > > ### > >>>> x =3D Tkinter.Tk() > >>>> x.wm_iconbitmap > > <method Wm.wm_iconbitmap of Tk instance at 80929d8> > >>>> x.wm_iconmask =20 > > <method Wm.wm_iconmask of Tk instance at 80929d8> > > ### > > > > > > This is all a large guess though, because I'm inexperienced with Tk stuff. = > > =20 > > It does seem to be doing something, though, because in Linux, that part of > > the code seems responsible for changing the icon. > > > > Can you check to see that PySol does change its icon appropriately on a > > Windows system too? If so, then we're on the right track. If not, you'll > > still have a fun solitare game installed on your system. *grin* > > > > > > Good luck! > > > > > > > > --__--__-- > > > > Message: 13 > > Date: Fri, 2 Mar 2001 07:01:32 -0800 (PST) > > From: Chris McCormick <livelikemad@yahoo.com> > > To: tutor@python.org > > Subject: [Tutor] TK icons, and a dumb question. :-) > > > > Someone was asking about the window icon in Tkinter. > > I'm a newbie, so I don't know how to do it myself, but > > there's a great reference called the Tkinter Life > > Preserver at the Python site: --> > > http://www.python.org/doc/life-preserver > > > > It has a section on the Tk window manager class > > (Tkinter.Wm). I think this is what you need to learn. > > It's at > > http://www.python.org/doc/life-preserver/WindowMgr.html. > > > > Then come back and tell us all how to do it. :-) > > > > Oh, and a dumb question - if you get the list in > > digest format, is there any way to resond to a > > particular thread/e-mail? > > > > - Chris (who is still working on getting reasonable > > animation out of Tkinter, dagnabit) > > > > __________________________________________________ > > Do You Yahoo!? > > Get email at your own domain with Yahoo! Mail. > > http://personal.mail.yahoo.com/ > > > > > > --__--__-- > > > > Message: 14 > > From: "Brad Chandler" <mbc2@netdoor.com> > > To: <tutor@python.org> > > Subject: Re: [Tutor] Database connectivity > > Date: Fri, 2 Mar 2001 09:45:07 -0600 > > > > ----- Original Message ----- > > From: "GCS" <gcs@agentsinside.com> > > To: <tutor@python.org> > > Sent: Friday, March 02, 2001 5:09 AM > > Subject: [Tutor] Database connectivity > > > > > >> Hello, > >> > >> Can someone point me out with a good documentation how to connect to > > Postgres? > >> I can not find any of them in the library reference. Is it supported? > >> > >> Regards, Laszlo > > > > I use PyGreSQL and have been very pleased with it. There are several others > > out there and I've tried one other (I can't remember the name) but couldn't > > get it to work. If you installed Python from source, you should have no > > problem compiling PyGreSQL. But if you installed from an rpm, you might > > need the development rpm as well (if there is one). You might also need the > > PostgreSQL source, I'm not sure. I installed both python and postgres from > > source so I'm not sure how it PyGreSQL would compile if had I used RPMs. > > > > Brad > > > > > > > > --__--__-- > > > > Message: 15 > > From: Tim Johnson <tim@johnsons-web.com> > > To: alan.gauld@bt.com, > > tim@johnsons-web.com, > > tutor@python.org > > Subject: RE: [Tutor] Memory Gotchas? > > Date: Fri, 2 Mar 2001 07:57:54 -0900 > > > > Hi Alan: > > On Fri, 02 Mar 2001, alan.gauld@bt.com wrote: > > <snip> > >> But if you must find out whats happening under the hood > >> you can look at the Python Reference Manual about the > >> Garbage Collector. ISTR it has pretty good descriptions > >> of just what is colleted and when. > > Thanks............... > >>> I'm especially interested in avoiding coding mistakes which > >>> could lead to memory leaks. > >> > >> AFAIK, aside from circular references, there aren't too many > >> possibilities. Its not like C/C++ > > Yippee!! > > Regards :) > > -- > > Tim Johnson > > ----------- > > "Of all manifestations of power, > > restraint impresses the most." > > -Thucydides > > > > > > > > --__--__-- > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > End of Tutor Digest > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- The Useless Python Repository has received an XHTML face-lift! http://www.lowerstandard.com/python/pythonsource.html From marty55@home.com Fri Mar 2 19:52:27 2001 From: marty55@home.com (Marty Pitts) Date: Fri, 2 Mar 2001 11:52:27 -0800 Subject: [Tutor] Loops and User Input Message-ID: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> This is a multi-part message in MIME format. ------=_NextPart_000_001D_01C0A30F.410A39C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm a python newbie and I have been going through Mr. Gauld's book and = have a question. Following an exercise to understand loops, the following came about: for i in range(2, 13): for j in range(1, 13): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D 12: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " Which works fine. However, when I add user input to let the range be dependant on this = input like this: multiplier =3D input("Which mulitplier value do you want to use? ") for i in range(2, multiplier + 1): for j in range(1, multiplier + 1): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D multiplier: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " Using any input just returns to a prompt in 'idle'. Any help will be appreciated. Thanks, ------=_NextPart_000_001D_01C0A30F.410A39C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>I'm a python newbie and I = have been going=20 through Mr. Gauld's book and have a question.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Following an exercise to understand = loops, the=20 following came about:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>for i in range(2, = 13):<BR> for j=20 in range(1, 13):<BR> if i =3D=3D 2 = and j =3D=3D=20 1:<BR> print=20 "---------------------------------- "<BR> = =20 print "This table is the",i,"multiple=20 table"<BR> print = "---------------------------------- "<BR> = =20 print "%d x %d =3D %d" % (j, i, j * i)<BR> if i =3D=3D = 12:<BR> break<BR> = print=20 "---------------------------------- "<BR> print "This = table is=20 the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Which works fine.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>However, when I add user input to let = the range be=20 dependant on this input like this:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>multiplier =3D input("Which mulitplier = value do you=20 want to use? ")<BR>for i in range(2, multiplier + = 1):<BR> for=20 j in range(1, multiplier + 1):<BR> = if i =3D=3D=20 2 and j =3D=3D 1:<BR> = print=20 "---------------------------------- "<BR> = =20 print "This table is the",i,"multiple=20 table"<BR> print = "---------------------------------- "<BR> = =20 print "%d x %d =3D %d" % (j, i, j * i)<BR> if i =3D=3D = multiplier:<BR> = break<BR> =20 print "---------------------------------- "<BR> print = "This=20 table is the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Using any input just returns to a = prompt in=20 'idle'.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Any help will be = appreciated.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV></BODY></HTML> ------=_NextPart_000_001D_01C0A30F.410A39C0-- From tim@johnsons-web.com Fri Mar 2 20:58:13 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Fri, 2 Mar 2001 11:58:13 -0900 Subject: [Tutor] Updating an FTP file References: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> Message-ID: <0103021205060C.01210@shecom> Hello: I'd like to be able to append a line to a file at an FTP site. #with the following command: cmd2 = 'RETR cpwd.txt' # read 'buffer' line_buffer= [] #the following code will return line_buffer with lines read from the file ftp.retrlines(cmd2,lines.append) # I can then add the new line: lines.append("this is the new line") #here's where I 'hit the wall': # How do I 'write' the update list of line back to the # remote file. BTW: have been looking at documentation for ftplib, but can't seem to get focus on the appropriate method. Sorry to be so dense..... Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From arcege@shore.net Fri Mar 2 21:21:56 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 2 Mar 2001 16:21:56 -0500 (EST) Subject: [Tutor] Memory Gotchas? In-Reply-To: <01030120033105.01210@shecom> from Tim Johnson at "Mar 1, 2001 7:59:52 pm" Message-ID: <E14Ywzs-0000np-00@nautilus.shore.net> > Hello All: > I would appreciate being pointed towards documentation on Python > memory allocation. > > I'm especially interested in avoiding coding mistakes which could lead to > memory leaks. > > Any Info would be appreciated. > Regards Some people have mentioned the obvious circular references that 2.0 has tried to help with. There is another area that most programs won't have to deal with, but sometimes may have to. If a program uses the sys.exc_traceback or the result of sys.exc_info(). Keeping a reference to the traceback will keep a reference to _all_ the called functions' local scopes at that time, including references to all the local variable objects. A common idiom for introspection is to use sys.exc_info()[2].tb_frame. f_back to find out the calling function. Using this may (depending on when and how you use the values) keep a lot of objects around even after the functions have returned and the variables should have been destroyed. The just of this is that the traceback keeps a copy of the complete execution stack up to that point. Keeping a reference to it, or to a frame in it, keeps all that information in memory. (Boy... looking at this, I just realized how confusing this discussion is. The main advice I would suggest here is: don't use the traceback object unless you really need to.) -Arcege PS: The sys module has a very useful function called "getrefcount", which returns the number of references to an object (plus one for the function argument): >>> import sys >>> x = (1, ) >>> sys.getrefcount( x ) 2 >>> sys.getrefcount( (1,) ) 1 -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dyoo@hkn.eecs.berkeley.edu Fri Mar 2 21:36:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 2 Mar 2001 13:36:11 -0800 (PST) Subject: [Tutor] Loops and User Input In-Reply-To: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> Message-ID: <Pine.LNX.4.21.0103021331050.1046-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Marty Pitts wrote: > However, when I add user input to let the range be dependant on this > input like this: > > multiplier = input("Which mulitplier value do you want to use? ") > for i in range(2, multiplier + 1): > for j in range(1, multiplier + 1): > if i == 2 and j == 1: > print "---------------------------------- " > print "This table is the",i,"multiple table" > print "---------------------------------- " > print "%d x %d = %d" % (j, i, j * i) > if i == multiplier: > break > print "---------------------------------- " > print "This table is the",i + 1 ,"multiple table" > print "---------------------------------- " > > Using any input just returns to a prompt in 'idle'. Hmmm... actually, this looks ok! It might just be that the number that you inputted is too low. range() is a little weird because its asymmetric: given something like: range(a, b) it'll construct the list: [a, a+1, a+2, ... b-1] For example: ### >>> range(2, 2) [] >>> range(2, 3) [2] >>> range(2, 4) [2, 3] ### This is sometimes counter to what people expect; they might expect the right endpoint to also be a part of the list. Try it again; it seems to work for me. Good luck to you! From wheelege@tsn.cc Fri Mar 2 21:32:39 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 3 Mar 2001 08:32:39 +1100 Subject: [Tutor] Loops and User Input References: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> Message-ID: <00b401c0a360$4f2cd520$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_00B1_01C0A3BC.81E4AB80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Your script works fine on my system. I suggest trying it out through = the command prompt, or using the Activestate version of the python = interpreter. I used to use IDLE but it seems to have alot of issues (at = least the version for MS Windows does). The easiest way to run a script through the command prompt (if you = haven't set the path to point at your python20 directory) is to first = copy that script to the python20 directory. Then open up a DOS prompt, = and change directories to the c:\python20 directory. It is probably = different if youa re using a different version of python...but since I = started when python 2 was realeased I have no idea what the directory = name would be for previous versions :) You change directories by typing "dir <dirname>" without the quotes, = where <dirname> is python20 in this case. Then just type "python <scriptname>" to run the script. Don't forget = the .py at the end of the filename :) Cya, Glen. ----- Original Message -----=20 From: Marty Pitts=20 To: tutor@python.org=20 Sent: Saturday, March 03, 2001 6:52 AM Subject: [Tutor] Loops and User Input I'm a python newbie and I have been going through Mr. Gauld's book and = have a question. =20 Following an exercise to understand loops, the following came about: =20 for i in range(2, 13): for j in range(1, 13): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D 12: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " =20 Which works fine. =20 However, when I add user input to let the range be dependant on this = input like this: =20 multiplier =3D input("Which mulitplier value do you want to use? ") for i in range(2, multiplier + 1): for j in range(1, multiplier + 1): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D multiplier: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " =20 Using any input just returns to a prompt in 'idle'. =20 Any help will be appreciated. =20 Thanks, ------=_NextPart_000_00B1_01C0A3BC.81E4AB80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV> </DIV> <DIV> Your script works fine on my system. I suggest trying = it out=20 through the command prompt, or using the Activestate version of the = python=20 interpreter. I used to use IDLE but it seems to have alot of = issues (at=20 least the version for MS Windows does).</DIV> <DIV> The easiest way to run a script through the command prompt = (if you=20 haven't set the path to point at your python20 directory) is to first = copy that=20 script to the python20 directory. Then open up a DOS prompt, and = change=20 directories to the c:\python20 directory. It is probably different = if youa=20 re using a different version of python...but since I started when python = 2 was=20 realeased I have no idea what the directory name would be for previous = versions=20 :)</DIV> <DIV> You change directories by typing "dir <dirname>" = without the=20 quotes, where <dirname> is python20 in this case.</DIV> <DIV> Then just type "python <scriptname>" to run the = script. =20 Don't forget the .py at the end of the filename :)</DIV> <DIV> </DIV> <DIV> Cya,</DIV> <DIV> Glen.</DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:marty55@home.com" title=3Dmarty55@home.com>Marty = Pitts</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = href=3D"mailto:tutor@python.org"=20 title=3Dtutor@python.org>tutor@python.org</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Saturday, March 03, 2001 = 6:52=20 AM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Loops and User = Input</DIV> <DIV><BR></DIV> <DIV><FONT face=3DArial size=3D2>I'm a python newbie and I = have been=20 going through Mr. Gauld's book and have a question.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Following an exercise to understand = loops, the=20 following came about:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>for i in range(2, = 13):<BR> for=20 j in range(1, 13):<BR> if i = =3D=3D 2 and j =3D=3D=20 1:<BR> print=20 "---------------------------------- "<BR> = =20 print "This table is the",i,"multiple=20 table"<BR> = print=20 "---------------------------------- "<BR> = =20 print "%d x %d =3D %d" % (j, i, j * i)<BR> if i = =3D=3D=20 12:<BR> = break<BR> print=20 "---------------------------------- "<BR> print = "This table=20 is the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Which works fine.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>However, when I add user input to let = the range=20 be dependant on this input like this:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>multiplier =3D input("Which = mulitplier value do you=20 want to use? ")<BR>for i in range(2, multiplier + = 1):<BR> =20 for j in range(1, multiplier + 1):<BR> = if=20 i =3D=3D 2 and j =3D=3D 1:<BR> = =20 print "---------------------------------- "<BR> =20 print "This table is = the",i,"multiple=20 table"<BR> = print=20 "---------------------------------- "<BR> = =20 print "%d x %d =3D %d" % (j, i, j * i)<BR> if i = =3D=3D=20 multiplier:<BR> =20 break<BR> print "----------------------------------=20 "<BR> print "This table is the",i + 1 ,"multiple=20 table"<BR> print "---------------------------------- = "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Using any input just returns to a = prompt in=20 'idle'.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Any help will be = appreciated.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial = size=3D2>Thanks,</FONT></DIV></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_00B1_01C0A3BC.81E4AB80-- From kalle@gnupung.net Fri Mar 2 21:47:58 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 2 Mar 2001 22:47:58 +0100 Subject: [Tutor] Updating an FTP file In-Reply-To: <0103021205060C.01210@shecom>; from tim@johnsons-web.com on Fri, Mar 02, 2001 at 11:58:13AM -0900 References: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> <0103021205060C.01210@shecom> Message-ID: <20010302224758.A846@apone.network.loc> --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Tim Johnson: > Hello:=20 > I'd like to be able to append a line to a file at an FTP site. [snip] I don't think this is possible. You'll have to write a temporary file, and upload it with FTP. > BTW: have been looking at documentation for ftplib, but can't > seem to get focus on the appropriate method. Do *not* worry about that. IMHO, ftplib is one of the few *evil* modules in the standard library, and the documentation is not very nice either. I'm glad I don't have to deal with it much. Peace, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --y0ulUmNC+osPPQO6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6oBUOdNeA1787sd0RAuyMAKCrNEi8di3VMNhCAmA6LYV62wiwjwCbBCiR kQcRM074o606/3ltZ6OcX54= =J1Pa -----END PGP SIGNATURE----- --y0ulUmNC+osPPQO6-- From dyoo@hkn.eecs.berkeley.edu Fri Mar 2 21:48:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 2 Mar 2001 13:48:26 -0800 (PST) Subject: [Tutor] Updating an FTP file In-Reply-To: <0103021205060C.01210@shecom> Message-ID: <Pine.LNX.4.21.0103021336350.1046-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Tim Johnson wrote: > # I can then add the new line: > lines.append("this is the new line") > #here's where I 'hit the wall': > # How do I 'write' the update list of line back to the > # remote file. Hello! It looks like we need to give a file-like object to either storbinary() or storlines(). Since we're working with text, let's use storlines. >From the documentation, storlines takes in a command, like "STOR filename", and a file-like object. The tricky thing we need is a file-like object that has those changes that you've made before. One easy thing to do is to write a temporary file that reflects those changes, upload that, and then erase the temporary file. However, it sounds like you don't want to write an intermediate temporary file, so let's try a different approach. There's a module called StringIO, which allows one to simulate a string as a file! We could write all our lines into a StringIO, and pass that along to storlines(); I think that storlines() should be happy with that. Let's see how StringIO works: ### >>> from StringIO import StringIO >>> myfile = StringIO() >>> myfile.writelines(['this is a test', 'hello world', ... 'does this work?']) >>> myfile.seek(0) ## Let's rewind the file back >>> print myfile.read() this is a testhello worlddoes this work? >>> myfile.seek(0) ### I have no idea if this will work with storlines() though, so try it out, and tell us if you have any success with this. For more details, take a look at: http://python.org/doc/current/lib/ftp-objects.html http://python.org/doc/current/lib/module-StringIO.html Good luck! From tim@johnsons-web.com Fri Mar 2 22:25:38 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Fri, 2 Mar 2001 13:25:38 -0900 Subject: [Tutor] Updating an FTP file References: <Pine.LNX.4.21.0103021336350.1046-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <0103021330240D.01210@shecom> Hello Danny: > From the documentation, storlines takes in a command, like "STOR > filename", and a file-like object. The tricky thing we need is a > file-like object that has those changes that you've made before. One easy > thing to do is to write a temporary file that reflects those changes, > upload that, and then erase the temporary file. > > However, it sounds like you don't want to write an intermediate temporary > file, so let's try a different approach. There's a module called > StringIO, which allows one to simulate a string as a file! We could write > all our lines into a StringIO, and pass that along to storlines(); I think > that storlines() should be happy with that. I am such a chicken, I've just used Kalle's method and it works for me................. Actually, as it turns it out, I do want to keep the "temporary" file in the same dir as the program. Safety in redundancy and all that. > > I have no idea if this will work with storlines() though, so try it out, > and tell us if you have any success with this. But am going to play with your method, and will let you know. Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From Christopher Peet" <cpeet@point4.com Fri Mar 2 22:54:16 2001 From: Christopher Peet" <cpeet@point4.com (Christopher Peet) Date: Fri, 2 Mar 2001 14:54:16 -0800 Subject: [Tutor] 'number' strings error Message-ID: <003701c0a36c$12bc0000$0200a8c0@horus> When I run this I get a 'cannot assign to literal' on the number strings. But if I take that part out I get a 'cannot add type "int' to string' error on the password = part. What am I missing? I realize I can print after each random.choice but I'd still like to know how to work it this way. Thanks, Christopher Peet _______________ # random 'password' generator import random a = 'a' b = 'b' c = 'c' 1 = '1' # 2 = '2' # errors on these 3 = '3' # l = [a, b, c] n = [1, 2, 3] if l: l1 = random.choice(l) if l: l2 = random.choice(l) if n: n1 = random.choice(n) if l: l3 = random.choice(l) if l: l4 = random.choice(l) password = l1 + l2 + n1 + l3 + l4 print password From Christopher Peet" <cpeet@point4.com Fri Mar 2 23:54:45 2001 From: Christopher Peet" <cpeet@point4.com (Christopher Peet) Date: Fri, 2 Mar 2001 15:54:45 -0800 Subject: [Tutor] Re: 'number' strings error Message-ID: <005201c0a374$3aabdf10$0200a8c0@horus> Sorry the waste bandwidth..... I just figured out I needed the string module and string.atoi. I got it sorted now. Christopher Peet ----- Original Message ----- From: "Christopher Peet" <cpeet@point4.com> To: <tutor@python.org> Sent: Friday, March 02, 2001 2:54 PM Subject: 'number' strings error > When I run this I get a 'cannot assign to literal' on the number strings. > But if I take that part out I get a 'cannot add type "int' to string' error > on the password = part. What am I missing? > > I realize I can print after each random.choice but I'd still like to know > how to work it this way. > > Thanks, > > Christopher Peet From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 02:57:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 2 Mar 2001 18:57:43 -0800 (PST) Subject: [Tutor] 'number' strings error In-Reply-To: <003701c0a36c$12bc0000$0200a8c0@horus> Message-ID: <Pine.LNX.4.21.0103021846320.3210-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Christopher Peet wrote: > When I run this I get a 'cannot assign to literal' on the number > strings. But if I take that part out I get a 'cannot add type "int' to > string' error on the password = part. What am I missing? Python can be a little strict on is the naming of variables. Variable names like: 'x' and 'Foobar' are not quite good because they're not descriptive, but they're "legal" because they begin with a letter. However, '1', '2', and '3' don't work as variable names because they begin with number digits, and for technical reasons, this confuses the heck out of Python. To avoid this variable naming problem, try using the variable names: one, two, three and see if these works better for you. These are different because they begin with letters, which Python should accept. This is not to say that a variable name can't have numbers in it: it just means that a variable name can't start with a number. For example: var1, var2, var3 are perfectly good variable names, although I'd worry about trying to understand what those variables stand for, later on. Choose variable names that hint at what they're used for, and your program will be easier to read. By the way, you don't always need to store values in variables before using them. For example, > a = 'a' > b = 'b' > c = 'c' > l = [a, b, c] could be written more directly like this: l = ['a', 'b', 'c'] which tells Python to make a list of three elements of 'a', 'b', and 'c' strings. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 03:02:00 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 2 Mar 2001 19:02:00 -0800 (PST) Subject: [Tutor] Re: 'number' strings error In-Reply-To: <005201c0a374$3aabdf10$0200a8c0@horus> Message-ID: <Pine.LNX.4.21.0103021859130.3210-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Christopher Peet wrote: > Sorry the waste bandwidth..... I just figured out I needed the string > module and string.atoi. I got it sorted now. No problem, don't worry about it. By the way, instead of using string.atoi(), you can use the int() function, which will convert anything to an integer. For example: ### >>> age = int('42') >>> print type(age) <type 'int'> ### It's easier to type than string.atoi('42'), and more versatile. It can work with floating point numbers too: ### >>> average_children = int(3.5) >>> average_children 3 ### Hope this helps! From britt_green@hotmail.com Sat Mar 3 03:08:55 2001 From: britt_green@hotmail.com (Britt Green) Date: Fri, 02 Mar 2001 19:08:55 -0800 Subject: [Tutor] Getting a List of FTP Dirs? Message-ID: <F260q3k0rp95OTV1lsP0001db73@hotmail.com> Hello all, Part of my job duties is to check an FTP backup site and insure that a bunch of files have backed up for that day. I have to check 300 folders. Ugh. So in a meeting today with a new boss, I said that this was a waste of time, and that someone should code up a program to automatically check it. Unwisely, I said, "Its easy! I could write something like that." Now I have to do it. :) So, I've been playing with ftplib a bit and its very useful. However, this is what I'm stuck on. Say I have this listing of directories: drwxrwx--- 2 restback privftp 512 Mar 2 20:17 spice drwxrwx--- 2 restback privftp 512 Mar 2 20:03 terradisiena drwxrwx--- 2 restback privftp 512 Mar 2 20:22 tiburongrille drwxrwx--- 2 restback privftp 512 Mar 2 20:35 toulouse drwxrwx--- 2 restback privftp 512 Mar 2 20:50 vangoghs How do I tell my program that spice, terradisiene, etc are directories it needs to go into? Since we regularly add and delete directories, I can't create a static file of them. My program needs to take a line like this: drwxrwx--- 2 restback privftp 512 Mar 2 20:17 spice and understand that the last word in it will be a directory it needs to enter. And, I also need to let my program know when its done reading the listing of directories. I could probably write something that creates a tuple, and to take the last element in that tuple as the directory, but beyond that I"m a bit lost. Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From lumbricus@gmx.net Sat Mar 3 03:44:24 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sat, 3 Mar 2001 04:44:24 +0100 (MET) Subject: [Tutor] Getting a List of FTP Dirs? References: <F260q3k0rp95OTV1lsP0001db73@hotmail.com> Message-ID: <29214.983591064@www9.gmx.net> > Hello all, > > Part of my job duties is to check an FTP backup site and insure that a > bunch > of files have backed up for that day. I have to check 300 folders. Ugh. So > > in a meeting today with a new boss, I said that this was a waste of time, > and that someone should code up a program to automatically check it. > > Unwisely, I said, "Its easy! I could write something like that." > > Now I have to do it. :) > > So, I've been playing with ftplib a bit and its very useful. However, this > > is what I'm stuck on. Say I have this listing of directories: > > drwxrwx--- 2 restback privftp 512 Mar 2 20:17 spice > drwxrwx--- 2 restback privftp 512 Mar 2 20:03 terradisiena > drwxrwx--- 2 restback privftp 512 Mar 2 20:22 tiburongrille > drwxrwx--- 2 restback privftp 512 Mar 2 20:35 toulouse > drwxrwx--- 2 restback privftp 512 Mar 2 20:50 vangoghs > > How do I tell my program that spice, terradisiene, etc are directories it > needs to go into? Since we regularly add and delete directories, I can't > create a static file of them. My program needs to take a line like this: > > drwxrwx--- 2 restback privftp 512 Mar 2 20:17 spice > > and understand that the last word in it will be a directory it needs to > enter. And, I also need to let my program know when its done reading the > listing of directories. > > I could probably write something that creates a tuple, and to take the > last > element in that tuple as the directory, but beyond that I"m a bit lost. > > Britt > > > -- > It is pitch black. You are likely to be eaten by a grue. > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor from the stat module doc: import os,sys from stat import * def walktree(dir,callback): for f in os.listdir(dir): pathname='%s%s'%(dir,f) mode=os.stat(pathname)[ST_MODE] if S_ISDIR(mode): # recurse into dirs walktree(pathname,callback) elif S_ISREG(mode): # regular file callback(pathname) else: # anything else print "Error: Unknown file type - skipping..." is that what you're looking for? grrrretz JÖ! -- Sent through GMX FreeMail - http://www.gmx.net From britt_green@hotmail.com Sat Mar 3 04:27:19 2001 From: britt_green@hotmail.com (Britt Green) Date: Fri, 02 Mar 2001 20:27:19 -0800 Subject: [Tutor] Getting a List of FTP Dirs? Message-ID: <F242brQff9AccWl411E00016c51@hotmail.com> >From: Jörg Wölke <lumbricus@gmx.net> >To: "Britt Green" <britt_green@hotmail.com> >CC: tutor@python.org, tutor@python.org >Subject: Re: [Tutor] Getting a List of FTP Dirs? >Date: Sat, 3 Mar 2001 04:44:24 +0100 (MET) <snip> >from the stat module doc: >import os,sys >from stat import * > >def walktree(dir,callback): > for f in os.listdir(dir): > pathname='%s%s'%(dir,f) > mode=os.stat(pathname)[ST_MODE] > if S_ISDIR(mode): > # recurse into dirs > walktree(pathname,callback) > elif S_ISREG(mode): > # regular file > callback(pathname) > else: > # anything else > print "Error: Unknown file type - skipping..." > >is that what you're looking for? Yeah, thats exactly what I'm looking for. Let me ask you this. In the line "for f in os.listdir(dir):" how do I tell Python it needs to be checking the remote directory, not the one on my computer? Thanks! Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From marty55@home.com Sat Mar 3 04:47:47 2001 From: marty55@home.com (Marty Pitts) Date: Fri, 2 Mar 2001 20:47:47 -0800 Subject: [Tutor] Loops and User Input References: <002001c0a352$4f677580$369e0618@tcma1.wa.home.com> <00b401c0a360$4f2cd520$0200a8c0@ACE> Message-ID: <000e01c0a39d$18a47d40$369e0618@tcma1.wa.home.com> This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C0A35A.09BF73E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Much to my embarrassment, this script works for me if I run it at the = command prompt and not in idle. Though my primary platform is linux and not windows. =20 I don't know why I did not try it as a script. I assumed that if it = didn't work in idle, it wouldn't work any other way. Thanks for the comments. ----- Original Message -----=20 From: Glen Wheeler=20 To: Marty Pitts=20 Cc: tutor@python.org=20 Sent: Friday, March 02, 2001 1:32 PM Subject: Re: [Tutor] Loops and User Input Your script works fine on my system. I suggest trying it out = through the command prompt, or using the Activestate version of the = python interpreter. I used to use IDLE but it seems to have alot of = issues (at least the version for MS Windows does). The easiest way to run a script through the command prompt (if you = haven't set the path to point at your python20 directory) is to first = copy that script to the python20 directory. Then open up a DOS prompt, = and change directories to the c:\python20 directory. It is probably = different if youa re using a different version of python...but since I = started when python 2 was realeased I have no idea what the directory = name would be for previous versions :) You change directories by typing "dir <dirname>" without the quotes, = where <dirname> is python20 in this case. Then just type "python <scriptname>" to run the script. Don't = forget the .py at the end of the filename :) Cya, Glen. ----- Original Message -----=20 From: Marty Pitts=20 To: tutor@python.org=20 Sent: Saturday, March 03, 2001 6:52 AM Subject: [Tutor] Loops and User Input I'm a python newbie and I have been going through Mr. Gauld's book = and have a question. Following an exercise to understand loops, the following came about: for i in range(2, 13): for j in range(1, 13): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D 12: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " Which works fine. However, when I add user input to let the range be dependant on this = input like this: multiplier =3D input("Which mulitplier value do you want to use? ") for i in range(2, multiplier + 1): for j in range(1, multiplier + 1): if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- " print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D multiplier: break print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " Using any input just returns to a prompt in 'idle'. Any help will be appreciated. Thanks, ------=_NextPart_000_000B_01C0A35A.09BF73E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Much to my embarrassment, this script = works for me=20 if I run it at the command prompt and not in idle.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Though my primary platform is linux and = not=20 windows. </FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>I don't know why I did not try it as a=20 script. I assumed that if it didn't work in idle, it wouldn't work = any=20 other way.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks for the comments.</FONT></DIV> <BLOCKQUOTE dir=3Dltr=20 style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A title=3Dwheelege@tsn.cc href=3D"mailto:wheelege@tsn.cc">Glen = Wheeler</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dmarty55@home.com = href=3D"mailto:marty55@home.com">Marty Pitts</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A title=3Dtutor@python.org = href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, March 02, 2001 = 1:32=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Tutor] Loops and = User=20 Input</DIV> <DIV><BR></DIV> <DIV> </DIV> <DIV> Your script works fine on my system. I suggest = trying it out=20 through the command prompt, or using the Activestate version of the = python=20 interpreter. I used to use IDLE but it seems to have alot of = issues (at=20 least the version for MS Windows does).</DIV> <DIV> The easiest way to run a script through the command prompt = (if you=20 haven't set the path to point at your python20 directory) is to first = copy=20 that script to the python20 directory. Then open up a DOS = prompt, and=20 change directories to the c:\python20 directory. It is probably=20 different if youa re using a different version of python...but since I = started=20 when python 2 was realeased I have no idea what the directory name = would be=20 for previous versions :)</DIV> <DIV> You change directories by typing "dir <dirname>" = without the=20 quotes, where <dirname> is python20 in this case.</DIV> <DIV> Then just type "python <scriptname>" to run the=20 script. Don't forget the .py at the end of the filename :)</DIV> <DIV> </DIV> <DIV> Cya,</DIV> <DIV> Glen.</DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <BLOCKQUOTE=20 style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A title=3Dmarty55@home.com href=3D"mailto:marty55@home.com">Marty = Pitts</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = title=3Dtutor@python.org=20 href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Saturday, March 03, = 2001 6:52=20 AM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Loops and = User=20 Input</DIV> <DIV><BR></DIV> <DIV><FONT face=3DArial size=3D2>I'm a python newbie and I = have been=20 going through Mr. Gauld's book and have a question.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Following an exercise to understand = loops, the=20 following came about:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>for i in range(2, = 13):<BR> =20 for j in range(1, 13):<BR> if i = =3D=3D 2=20 and j =3D=3D 1:<BR> = =20 print "---------------------------------- "<BR> =20 print "This table is = the",i,"multiple=20 table"<BR> = print=20 "---------------------------------- "<BR> =20 print "%d x %d =3D %d" % (j, i, j *=20 i)<BR> if i =3D=3D 12:<BR> =20 break<BR> print=20 "---------------------------------- "<BR> print = "This=20 table is the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Which works fine.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>However, when I add user input to = let the range=20 be dependant on this input like this:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>multiplier =3D input("Which = mulitplier value do=20 you want to use? ")<BR>for i in range(2, multiplier +=20 1):<BR> for j in range(1, multiplier +=20 1):<BR> if i =3D=3D 2 and j = =3D=3D=20 1:<BR> print = "---------------------------------- "<BR> =20 print "This table is = the",i,"multiple=20 table"<BR> = print=20 "---------------------------------- "<BR> =20 print "%d x %d =3D %d" % (j, i, j *=20 i)<BR> if i =3D=3D = multiplier:<BR> =20 break<BR> print=20 "---------------------------------- "<BR> print = "This=20 table is the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Using any input just returns to a = prompt in=20 'idle'.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Any help will be = appreciated.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial=20 size=3D2>Thanks,</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_000B_01C0A35A.09BF73E0-- From sburr@home.com Sat Mar 3 06:20:28 2001 From: sburr@home.com (Steven Burr) Date: Fri, 2 Mar 2001 23:20:28 -0700 Subject: [Tutor] Two More Questions Message-ID: <20010303062029.JSRG22496.mail1.rdc1.az.home.com@localhost> On Wednesday, February 28, 2001, at 10:35 PM, Danny Yoo wrote: > On Wed, 28 Feb 2001 alan.gauld@bt.com wrote:=20 > =20 > > > >>> string.center('''hello world.=20 > > > ... this is a test.''', 45)=20 > > > ' hello world.\012this is a test. '=20 > > > ###=20 > > > =20 > > > Hmmm... but it depends on the function if it handles a =20 > > > multi-line string properly or not. string.center() =20 > > > certainly didn't handle that nicely. =20 > =20 > > Now whether thats what you expected centre to do so is another =20 > > matter, it certainly won't centre each line, but it doesn't =20 > > claim to do so.=20 > =20 > =20 > Very true! But I still would like it to do something different. = *grin*=20 > =20 > Let me see if I can "fix" it:=20 > =20 > ###=20 > >>> def mycenter(multiline, colwidth):=20 > ... lines =3D string.split(multiline, '\n')=20 > ... newlines =3D [string.center(l, colwidth) for l in lines]=20 > ... return string.join(newlines, '\n')=20 > ...=20 You could also use string methods instead of string module functions to = make a one-line version that is concise but still readable: >>> def mycenter(multiline, colwidth): ... return '\n'.join([line.center(colwidth) for line in = multiline.split('\n')])= From uygar_t@yahoo.com Sat Mar 3 09:11:16 2001 From: uygar_t@yahoo.com (uygar teomete) Date: Sat, 3 Mar 2001 01:11:16 -0800 (PST) Subject: [Tutor] (no subject) Message-ID: <20010303091116.4430.qmail@web4705.mail.yahoo.com> --0-882857320-983610676=:29055 Content-Type: text/plain; charset=us-ascii I would like to unsubscribe. My new mail adress is pitontr@yahoo.com could you please send tutor mailing list messages to my new adress? --------------------------------- Do You Yahoo!? Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail. --0-882857320-983610676=:29055 Content-Type: text/html; charset=us-ascii I would like to unsubscribe. My new mail adress is <A href="mailto:pitontr@yahoo.com">pitontr@yahoo.com</A> could you please send tutor mailing list messages to my new adress? <p><br><hr size=1><b>Do You Yahoo!?</b><br> <a href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</a> - Get email at your own domain with Yahoo! Mail. --0-882857320-983610676=:29055-- From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 12:25:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 04:25:42 -0800 (PST) Subject: [Tutor] 'number' strings error In-Reply-To: <004801c0a398$34eae660$0200a8c0@horus> Message-ID: <Pine.LNX.4.21.0103030417500.877-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Christopher Peet wrote: > Thanks very much for the pointers. I've never programmed before and > this was my first script. I'm surprised how much it changed and how > much I learned in just a single day... Very cool! That's good to hear. > The code I posted was just a quick sample. Below is the actual script > I was working on. As you can see it looks quite a bit nicer now and I > ended up not needing the string module... > import random > > ll = ['q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'] > rl = ['y','u','i','o','p','h','j','k','l','b','n','m'] > ln = ['1','2','3','4','5'] > rn = ['6','7','8','9','0'] > > ll1 = random.choice(ll) > rl1 = random.choice(rl) > ll2 = random.choice(ll) > rn1 = random.choice(rn) > ln1 = random.choice(ln) > rn2 = random.choice(rn) > ll3 = random.choice(ll) > rl2 = random.choice(rl) > ll4 = random.choice(ll) > > password = ll1 + rl1 + ll2 + rn1 + ln1 + rn2 + ll3 + rl2 + ll4 > > print password There's another place where we can make things look neater: > ll = ['q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'] random.choice() works equally well with strings as well as lists. If we tweak the definition of ll to: ll = 'qwertyasdfgzxcvb' your code should still have the same effect. This will make your definitions of your code characters a little easier to read and write. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 12:52:40 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 04:52:40 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <20010303091116.4430.qmail@web4705.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103030451350.1223-100000@c82114-a.pinol1.sfba.home.com> On Sat, 3 Mar 2001, uygar teomete wrote: > I would like to unsubscribe. My new mail adress is pitontr@yahoo.com > could you please send tutor mailing list messages to my new adress? What you can do is visit the administration site here: http://mail.python.org/mailman/listinfo/tutor Go down to the bottom; you'll be able to change your settings, including where tutor@python.org postings email themselves to. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 13:00:18 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 05:00:18 -0800 (PST) Subject: [Tutor] Getting a List of FTP Dirs? In-Reply-To: <F260q3k0rp95OTV1lsP0001db73@hotmail.com> Message-ID: <Pine.LNX.4.21.0103030447030.1223-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Britt Green wrote: > How do I tell my program that spice, terradisiene, etc are directories it > needs to go into? Since we regularly add and delete directories, I can't > create a static file of them. My program needs to take a line like this: > > drwxrwx--- 2 restback privftp 512 Mar 2 20:17 spice > > and understand that the last word in it will be a directory it needs to > enter. In cases like this, string.split() is your friend. *grin* If you give string.split() a line with the fields separated by a delimiter, it'll return us a list of those fields. Here's an example, edited to fit on a line: ### >>> string.split('drwxrwx--- 2 restback privftp spice') ['drwxrwx---', '2', 'restback', 'privftp', 'spice'] ### string.split() by default will skip multiple spaces if it needs to, which is usually what we want. Also, we can tell if a line given by ftplib's listing is a directory: there's always a 'd' at the very beginning of the line. Writing a function that takes in a line that comes out of the ftplib listing and extracts out directory names doesn't sound too bad. Try it, and if you get stuck, we can help make things less unstuck. (I think that writing this program might involve a little recursion; can anyone confirm this?) Good luck to you. From dyoo@hkn.eecs.berkeley.edu Sat Mar 3 13:10:55 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 05:10:55 -0800 (PST) Subject: [Tutor] Getting a List of FTP Dirs? In-Reply-To: <F260q3k0rp95OTV1lsP0001db73@hotmail.com> Message-ID: <Pine.LNX.4.21.0103030501000.1223-100000@c82114-a.pinol1.sfba.home.com> On Fri, 2 Mar 2001, Britt Green wrote: > Part of my job duties is to check an FTP backup site and insure that a > bunch of files have backed up for that day. I have to check 300 > folders. Ugh. So in a meeting today with a new boss, I said that this > was a waste of time, and that someone should code up a program to > automatically check it. After looking at the original problem, I'm a little curious: does the FTP backup site have an ssh server installed? If so, it might be easier to avoid dealing with FTP altogether: We can write a script that will do the os.path.walk() thing on the server, and send its results back to the client. That might be easier to do, and I think it might involve less coding. By the way, you might find the following module useful when verifying a file, md5 (Message Digest): http://python.org/doc/current/lib/module-md5.html md5 can be used to take a "fingerprint" of a file that can be easily checked on both your client and backup server. Could be useful if you really want to make sure that the files are identical on both backup and the real server. Good luck! From pdiaz88@terra.es Sat Mar 3 13:03:45 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 3 Mar 2001 14:03:45 +0100 Subject: [Tutor] Re: [SLL] CGI with python question In-Reply-To: <418F865215F3D4119F110006293883DB019209@idcmercury.idcertify.com> References: <418F865215F3D4119F110006293883DB019209@idcmercury.idcertify.com> Message-ID: <01030314034500.00365@tajo> Hi, Well, I got some awnsers but not from this list but from my Linux List. Here is the most interesting: On Thursday 01 March 2001 19:20, Ben Johnson wrote: > I don't know python, but I'm interested in your security problem. I > don't like cgi programs running as root at all so in my opinion your > scheme sounds ok except that httpd is creating root owned processes. > > here is an idea. > > have one program that executes as root, reads the login info, and then > forks into the background and becomes owned by nobody. it then could > act as a server for the needed info. it should probably open a unix > domain socket so that tcp connections can't get to it (directly anyway). > > now you have the problem of authenticating connecting processes so that > no just anyone can connect and read the info. one lame way to do this > would be to check the owner of whatever process is connecting to see > it's nobody. that could be ok unless you have other people on your > machine who are allowed to run cgi scripts. another way would be with a > shared secret... one that the daemon and the cgi scripts know. if you > did that though you might was well just put real needed info into your > cgi scripts directly (which is typical actually... this is the way I do > it). another method would be one that uses public key cryptography. > There seems like there are all sorts of reasonably secure ways to do it > this way but none of them, that I can think of, are perfect. > > the easiest way to do this is to put your connect info in one file that > is readable only by nobody and then make sure that there is no one on > your machine that can run a program/script as nobody and get to it. > > sorry I'm not more helpful. I guess I just had to listen to myself > type. > > - Ben Its a somewhat strange that no one on the python list awnsered my question, since python is used heavily in web sites as a cgi script language. Cheers Pedro On Saturday 03 March 2001 02:13, amoe@IDCertify.com wrote: > Hi Pedro, > > Did you ever get an answer on this? I would be interested to hear it. > > Alan > > -----Original Message----- > > Hi folks, > > I'm doing some CGI python scripts. One of them needs to access a MySQL > database on the localhost. i have experience dealing with MySQLdb so this > is not a problem. Actually the problem is that I need to fetch the > username-password-host-db tuple from a file in /etc. Of course, this > file must be root-only readable, so nobody except the root can read > this sensitive information. On the other hand, I don't want to have > cgi's in my system with root priviledges (I dont know if this is even > posible > with apache). > > Considering this, I planned my cgi to do the following: > - The script is initially suid root > - Once is called, reads the /etc files > - Inmediatly after this, changes is euid to Nobody via os.setuid > - Do the rest of the job, including interacting with the MySQL server > > Does this schema looks ok in security terms?. If not, what other schema > should I follow? > > I've also been playing with suid python scripts, but I wasn't able to make > the perform root privileged actions. Example: > > test.py: > ------- > #!/usr/bin/python > > import os > print os.geteuid() > os.setuid(0) > print os.geteuid() > f = open("/etc/shadow" ) > print "ALL OK" > -------- > > # chmod +x test.py > # ls -la test.py > -rwxr-xr-x 1 root root 120 Mar 1 18:07 test.py > # ./test.py > 0 > 0 > ALL OK > # chmod u+s test.py > # ls -la test.py > -rwsr-xr-x 1 root root 120 Mar 1 18:07 test.py > # su pdiaz > $ ./test.py > 1000 > Traceback (innermost last): > File "./test.py", line 5, in ? > os.setuid(0) > OSError: [Errno 1] Operation not permitted > $ > > What I'm doing wrong? > > Thanks > > Pedro > > ======================================================================== > Contributions/Posts To: linux-list@ssc.com > To Unsubscribe: linux-list-request@ssc.com, "unsubscribe" in message body > Report Problems to: owner-linux-list@ssc.com > List archive at: http://www.ssc.com/mailing-lists/ From kalle@gnupung.net Sat Mar 3 14:58:03 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sat, 3 Mar 2001 15:58:03 +0100 Subject: [Tutor] CGI with python question In-Reply-To: <01030118121500.00644@tajo>; from pdiaz88@terra.es on Thu, Mar 01, 2001 at 06:12:15PM +0100 References: <01030118121500.00644@tajo> Message-ID: <20010303155803.A796@apone.network.loc> --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Pedro Diaz Jimenez: [snip] > Considering this, I planned my cgi to do the following: > - The script is initially suid root [snip] I don't think this is possible with apache. Others may be able to correct = me. > I've also been playing with suid python scripts, but I wasn't able to mak= e=20 > the perform root privileged actions. Example: [snip] > What I'm doing wrong? Python scripts can't be setuid on linux. To get a setuid script, you'll have to make a C wrapper. A simple example: #include <unistd.h> int main(int argc, char *argv[], char *envp[]) { execve("your_python_script.py", argv, envp); } Peace, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --tKW2IUtsqtDRztdT Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6oQZ7dNeA1787sd0RAgjoAJwOrt46iyZgM6Ew375NJFA9Gj71lACgqRNN +Ijezfm332mE0KZ2ePC6960= =FtWi -----END PGP SIGNATURE----- --tKW2IUtsqtDRztdT-- From pdiaz88@terra.es Sat Mar 3 14:12:29 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 3 Mar 2001 15:12:29 +0100 Subject: [Tutor] Re: [SLL] CGI with python question In-Reply-To: <01030314034500.00365@tajo> References: <418F865215F3D4119F110006293883DB019209@idcmercury.idcertify.com> <01030314034500.00365@tajo> Message-ID: <01030315122902.00365@tajo> Oops, I apologize Kalle Svensson replied to my question (thanks). duh! Pedro On Saturday 03 March 2001 14:03, Pedro Diaz Jimenez wrote: > Hi, > > Well, I got some awnsers but not from this list but from my Linux List. > Here is the most interesting: > > On Thursday 01 March 2001 19:20, Ben Johnson wrote: > > I don't know python, but I'm interested in your security problem. I > > don't like cgi programs running as root at all so in my opinion your > > scheme sounds ok except that httpd is creating root owned processes. > > > > here is an idea. > > > > have one program that executes as root, reads the login info, and then > > forks into the background and becomes owned by nobody. it then could > > act as a server for the needed info. it should probably open a unix > > domain socket so that tcp connections can't get to it (directly anyway). > > > > now you have the problem of authenticating connecting processes so that > > no just anyone can connect and read the info. one lame way to do this > > would be to check the owner of whatever process is connecting to see > > it's nobody. that could be ok unless you have other people on your > > machine who are allowed to run cgi scripts. another way would be with a > > shared secret... one that the daemon and the cgi scripts know. if you > > did that though you might was well just put real needed info into your > > cgi scripts directly (which is typical actually... this is the way I do > > it). another method would be one that uses public key cryptography. > > There seems like there are all sorts of reasonably secure ways to do it > > this way but none of them, that I can think of, are perfect. > > > > the easiest way to do this is to put your connect info in one file that > > is readable only by nobody and then make sure that there is no one on > > your machine that can run a program/script as nobody and get to it. > > > > sorry I'm not more helpful. I guess I just had to listen to myself > > type. > > > > - Ben > > Its a somewhat strange that no one on the python list awnsered my question, > since python is used heavily in web sites as a cgi script language. > > Cheers > > Pedro > > On Saturday 03 March 2001 02:13, amoe@IDCertify.com wrote: > > Hi Pedro, > > > > Did you ever get an answer on this? I would be interested to hear it. > > > > Alan > > > > -----Original Message----- > > > > Hi folks, > > > > I'm doing some CGI python scripts. One of them needs to access a MySQL > > database on the localhost. i have experience dealing with MySQLdb so this > > is not a problem. Actually the problem is that I need to fetch the > > username-password-host-db tuple from a file in /etc. Of course, this > > file must be root-only readable, so nobody except the root can read > > this sensitive information. On the other hand, I don't want to have > > cgi's in my system with root priviledges (I dont know if this is even > > posible > > with apache). > > > > Considering this, I planned my cgi to do the following: > > - The script is initially suid root > > - Once is called, reads the /etc files > > - Inmediatly after this, changes is euid to Nobody via os.setuid > > - Do the rest of the job, including interacting with the MySQL server > > > > Does this schema looks ok in security terms?. If not, what other schema > > should I follow? > > > > I've also been playing with suid python scripts, but I wasn't able to > > make the perform root privileged actions. Example: > > > > test.py: > > ------- > > #!/usr/bin/python > > > > import os > > print os.geteuid() > > os.setuid(0) > > print os.geteuid() > > f = open("/etc/shadow" ) > > print "ALL OK" > > -------- > > > > # chmod +x test.py > > # ls -la test.py > > -rwxr-xr-x 1 root root 120 Mar 1 18:07 test.py > > # ./test.py > > 0 > > 0 > > ALL OK > > # chmod u+s test.py > > # ls -la test.py > > -rwsr-xr-x 1 root root 120 Mar 1 18:07 test.py > > # su pdiaz > > $ ./test.py > > 1000 > > Traceback (innermost last): > > File "./test.py", line 5, in ? > > os.setuid(0) > > OSError: [Errno 1] Operation not permitted > > $ > > > > What I'm doing wrong? > > > > Thanks > > > > Pedro > > > > ======================================================================== > > Contributions/Posts To: linux-list@ssc.com > > To Unsubscribe: linux-list-request@ssc.com, "unsubscribe" in message body > > Report Problems to: owner-linux-list@ssc.com > > List archive at: http://www.ssc.com/mailing-lists/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From sthickey@juno.com Sat Mar 3 16:10:11 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Sat, 3 Mar 2001 08:10:11 -0800 Subject: [Tutor] ActivePython Message-ID: <20010303.081014.-218543.0.sthickey@juno.com> HI! I noticed a reference to ActiveState yesterday on a posting on this listserver and went to look for it. I wound up downloading ActivePython and found that the interface is much better for my purposes than IDLE was. For one thing, it does away with PYTHONPATH and other Autoexec.bat entries and puts them into the Registry. One can then edit them directly in the Registry, which is nice. However, ActivePython is based upon version 2.0 and I had just downloaded the version 2.1 Beta. Am I going to lose something important for a newbie here? I welcome any comments about ActivePython from those who have used it. Thanks for any help, Stevenson Hickey sthickey@juno.com From tim@johnsons-web.com Sat Mar 3 17:10:48 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sat, 3 Mar 2001 08:10:48 -0900 Subject: [Tutor] Type Checking: References: <20010303.081014.-218543.0.sthickey@juno.com> Message-ID: <0103030814560F.01210@shecom> Hello: I need to be able to test the type of a variable: Consider the following code: # code begins >>> str = 'hello' >>> type(str) <type 'string'> >>> if type(str) == 'string': ... print "it's a string" ... else: ... print "I don't know how to type" ... I don't know how to type # code ends How do I get this code to return "it's a string" Thanks Much!! Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From sheila@thinkspot.net Sat Mar 3 17:34:53 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 03 Mar 2001 09:34:53 -0800 Subject: [Tutor] Type Checking: In-Reply-To: <0103030814560F.01210@shecom> References: <20010303.081014.-218543.0.sthickey@juno.com> <0103030814560F.01210@shecom> Message-ID: <5AEF8F83B66@kserver.org> On Sat, 3 Mar 2001 08:10:48 -0900, Tim Johnson <tim@johnsons-web.com> wrote about [Tutor] Type Checking:: :Hello: : I need to be able to test the type of a variable: :Consider the following code: :# code begins :>>> str = 'hello' :>>> type(str) :<type 'string'> :>>> if type(str) == 'string': :... print "it's a string" :... else: :... print "I don't know how to type" :... :I don't know how to type :# code ends : :How do I get this code to return :"it's a string" This problem is interesting to me. I've been playing with it for a few minutes, now. I'm not clear on exactly how one can work with the objects that the type() function returns. However, I did manage to do, at least this: >>> str = 'hello' >>> type(str) <type 'string'> >>> str2 = 'bye!' >>> if type(str) == type(str2): print "type match" else: print "no type match" type match >>> -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From kalle@gnupung.net Sat Mar 3 17:49:36 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sat, 3 Mar 2001 18:49:36 +0100 Subject: [Tutor] Type Checking: In-Reply-To: <0103030814560F.01210@shecom>; from tim@johnsons-web.com on Sat, Mar 03, 2001 at 08:10:48AM -0900 References: <20010303.081014.-218543.0.sthickey@juno.com> <0103030814560F.01210@shecom> Message-ID: <20010303184936.A372@apone.network.loc> --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Tim Johnson: > Hello: > I need to be able to test the type of a variable: > Consider the following code: [snip] > How do I get this code to return=20 > "it's a string" Howzabout >>> if type(str) =3D=3D type(""): or >>> import types >>> if type(str) =3D=3D types.StringType: Peace, Kalle --=20 Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD --Kj7319i9nmIyA2yE Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6oS6wdNeA1787sd0RAitMAJ9azImMrIHUWFN981zuxfAnQStZygCgo+8+ DzADG7b7B95KHh9MT+OseeE= =0XPy -----END PGP SIGNATURE----- --Kj7319i9nmIyA2yE-- From sheila@thinkspot.net Sat Mar 3 17:48:21 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 03 Mar 2001 09:48:21 -0800 Subject: [Tutor] Type Checking: In-Reply-To: <0103030814560F.01210@shecom> References: <20010303.081014.-218543.0.sthickey@juno.com> <0103030814560F.01210@shecom> Message-ID: <5BB66A22C14@kserver.org> There is a module called types and there is a name in that module called StringType. This code works: >>> from types import * >>> str = 'hello' >>> if type(str) is StringType: print "It's a string!" else: print "Not a string" It's a string! >>> -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sat, 3 Mar 2001 08:10:48 -0900, Tim Johnson <tim@johnsons-web.com> wrote about [Tutor] Type Checking:: :Hello: : I need to be able to test the type of a variable: :Consider the following code: :# code begins :>>> str = 'hello' :>>> type(str) :<type 'string'> :>>> if type(str) == 'string': :... print "it's a string" :... else: :... print "I don't know how to type" :... :I don't know how to type :# code ends : :How do I get this code to return :"it's a string" From tim@johnsons-web.com Sat Mar 3 18:06:50 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sat, 3 Mar 2001 09:06:50 -0900 Subject: [Tutor] Type Checking: References: <20010303184936.A372@apone.network.loc> Message-ID: <0103030907590G.01210@shecom> Hey Kalle: On Sat, 03 Mar 2001, Kalle Svensson wrote: > >%_Sez Tim Johnson: > > Hello: > > I need to be able to test the type of a variable: > > Consider the following code: > [snip] > > How do I get this code to return > > "it's a string" > > Howzabout > >>> if type(str) == type(""): > or > >>> import types > >>> if type(str) == types.StringType: That duz it: and I must add: dir(types) Displays all types: Cool.... thnx -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From arcege@shore.net Sat Mar 3 18:38:04 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sat, 3 Mar 2001 13:38:04 -0500 (EST) Subject: [Tutor] Type Checking: In-Reply-To: <0103030814560F.01210@shecom> from Tim Johnson at "Mar 3, 2001 8:10:48 am" Message-ID: <E14ZGuq-00076J-00@nautilus.shore.net> > Hello: > I need to be able to test the type of a variable: > Consider the following code: > # code begins > >>> str = 'hello' > >>> type(str) > <type 'string'> > >>> if type(str) == 'string': > ... print "it's a string" > ... else: > ... print "I don't know how to type" > ... > I don't know how to type > # code ends > > How do I get this code to return > "it's a string" > Each object in Python has a type, which is a unique object, like None is unique. All of Python's built-in types can be accessed through the types module. In addition, there is a nice little built-in function called isinstance() that can check types of objects for you. >>> import types >>> str = 'Spam' >>> isinstance(str, types.StringType) 1 >>> type(str) is types.StringType 1 There is another thing to consider, classes and instances. An instance of a class is just that - an instance. >>> class SillyWalk: ... pass ... >>> mysillywalk = SillyWalk() >>> type(SillyWalk) <type 'class'> >>> type(mysillywalk) <type 'instance'> >>> import types >>> isinstance(SillyWalk, types.ClassType) 1 >>> isinstance(mysillywalk, types.InstanceType) 1 But another nice feature of isinstance() is: >>> isinstance(mysillywalk, SillyWalk) 1 One last comment, is about numbers. Integers, longs and floating points are all different types. There is no one nice function to check for any type of number, usually just something like: type(num) in (IntType, LongType, FloatType) References: Library Reference Manual, 2.3 Built-in Functions http://www.python.org/doc/current/lib/built-in-funcs.html Library Reference Manual, 3.4 types -- Names for all built-in types http://www.python.org/doc/current/lib/module-types.html -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From lumbricus@gmx.net Sat Mar 3 23:30:41 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sun, 4 Mar 2001 00:30:41 +0100 (MET) Subject: [Tutor] Getting a List of FTP Dirs? References: <F242brQff9AccWl411E00016c51@hotmail.com> Message-ID: <22443.983662241@www22.gmx.net> > > >is that what you're looking for? > > Yeah, thats exactly what I'm looking for. Let me ask you this. In the line > > "for f in os.listdir(dir):" how do I tell Python it needs to be checking > the > remote directory, not the one on my computer? > REMOTE ??? Oh damn!!! this depends on what remote.maschine allows you to do. Best would be you could mount (site has mountd running or via nfs or smb) the remote ftp-directory and then just run your script. (ask the admin, beg, buy him/her beer) else: find a way to run the script on remote.maschine (telnet, ssh) just via ftp ??? well you can't run a program on your machine and expect a ftp-server to ... no way except by reconnecting in each recursion (via ftplib) ftp> mget * > Thanks! > > Britt > > > -- > It is pitch black. You are likely to be eaten by a grue. > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > -- Sent through GMX FreeMail - http://www.gmx.net From lumbricus@gmx.net Sun Mar 4 00:20:08 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sun, 4 Mar 2001 01:20:08 +0100 (MET) Subject: [Tutor] Getting a List of FTP Dirs? References: <F173AX3cf3ednHM3SOl000048c0@hotmail.com> Message-ID: <31939.983665208@www1.gmx.net> > > How about this instead. If I use the dir() method from ftplib, I'll get > something like this returned: > > drwxrwx--- 55 restback privftp 1536 Feb 26 19:19 seattle > drwxrwx--- 222 restback privftp 4608 Feb 23 15:14 sf > drwxrwx--- 3 restback privftp 512 Nov 24 10:33 slc > drwxrwx--- 2 restback privftp 512 Jan 11 08:08 tallships > > If I can convert this into a string, I can then work with it and write > code > to tell my program that the last word on each line is a directory. > Unfortunately, I can't seem to get Python to convert this into a string! > Trying something like: > > directories = ftp.dir() > > just causes the ftp.dir() code to be executed. Even if I try to explicitly > > cast it as a string by doing: > > directories = str(ftp.dir()) > > doesn't seem to work. Any idea on how to get this to work? > > Thanks for the help, btw! I'm sure I'm going to be using the os.* modules > soon enough. > > Britt > Yo --- the dox of ftplib (RTFM) sez that the dir() method returns NONE so you can't cast None to string. but if the last argument to dir() is a function this function is used as a callback (f.e. retrlines() *wink*). this is taken with a grain of salt cuz i didn't check out ftplib myself. hope this helps grrrrretz Jö! -- Sent through GMX FreeMail - http://www.gmx.net From tim@johnsons-web.com Sun Mar 4 03:58:18 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sat, 3 Mar 2001 18:58:18 -0900 Subject: [Tutor] Text Widget Readonly References: <22443.983662241@www22.gmx.net> Message-ID: <0103031905060J.01210@shecom> Hello All: I am browsing TKinter.py as we speak, and am looking for a way to set Text as readonly...... Also, I also see a good informational layout at http://www.pythonware.com/library/tkinter/introduction/x8518-options.htm But can't find anything on read/write toggles. NOTE: User wants to read some text, wants to be able to copy and paste, but not to change. Any ideas? Should I be using a different widget? Thanks in advance to all.... -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From dyoo@hkn.eecs.berkeley.edu Sun Mar 4 04:24:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 20:24:28 -0800 (PST) Subject: [Tutor] Type Checking: In-Reply-To: <0103030814560F.01210@shecom> Message-ID: <Pine.LNX.4.21.0103032006190.850-100000@c82114-a.pinol1.sfba.home.com> On Sat, 3 Mar 2001, Tim Johnson wrote: > Consider the following code: > # code begins > >>> str = 'hello' > >>> type(str) > <type 'string'> > >>> if type(str) == 'string': > ... print "it's a string" > ... else: > ... print "I don't know how to type" (Side note: try to avoid using 'str' as a variable name: it's already the name of the built-in str() function that converts anything to a string. This warning is meant to avoid potential weirdness later on; you'll probably want to keep that str() function for a rainy day. *grin*) Other people have already pointed out that type(mystr) == types.StringType is the traditional way of doing the type comparison. The reason that type(mystr) == 'string': doesn't quite work is because types are things --- objects --- that need to be compared with either other. This might not make much sense yet; let's make an analogy with what we already know. In Python: 1 == '1' is false, even though they 'look' the same, and the reason is because numbers are different from strings. Likewise: type(mystr) == "<type 'string'>" doesn't work either; types are things that are different from both strings and numbers. That's why Python has a premade collection of these type objects in the 'types' module, to make the comparison easier and to avoid this issue. However, in a pinch, this will work: type(mystr) == type('this is a string') because we grab the type of mystr, and grab the type of a string, and compare the two. This works because we're comparing between alike things. It's the apples and oranges argument, taken in a very literal setting. (Does anyone find it humorous that there's even a types.TypeType object in there?) Good luck to you. From dyoo@hkn.eecs.berkeley.edu Sun Mar 4 05:52:29 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 3 Mar 2001 21:52:29 -0800 (PST) Subject: [Tutor] PySol (fwd) Message-ID: <Pine.LNX.4.21.0103032145430.2329-100000@c82114-a.pinol1.sfba.home.com> Let me forward this to the other tutors; I'm still a little stupid when it comes to Tkinter stuff, so perhaps others can point you toward Tkinter resources and demos. About not being able to get PySol... weird! That server's a little slow, but it seems to be working. Try to download it again. Here's the link to the source code: http://wildsau.idv.uni-linz.ac.at/mfx/download/pysol/pysol-4.60-src.tar.gz (If you still can't get it, I can forward it to you as an attachment. Email me privately if this happens.) Also, there's a lot of example code you can find at the Vaults of Parnassus: http://www.vex.net/parnassus and I think I did see a few Tkinter projects somewhere in there. Also, try emailing the people who package the Python 2.0 binary; perhaps they can amend the missing Tk demo files. Quite a few people on tutor have Tkinter experience, so I hope that we can help you find good resources. ---------- Forwarded message ---------- Date: Sun, 04 Mar 2001 00:09:59 -0500 From: Timothy M. Brauch <tbrauch@mindless.com> To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu> Subject: Re: [Tutor] PySol Danny Yoo wrote: > > I took a quick look at a Tkinter-based game called PySol: > > http://wildsau.idv.uni-linz.ac.at/mfx/pysol/ > > They have source code available, which is great, because it's one of the > most impressive demonstrations of Tkinter use that I've seen. (Plus a > great time waster. *grin*) Okay, this is something that has just been annoying to me. I've heard people talk about PySol, and even given the link to the game. But, no matter how many times I try, no matter what hour of the day I try, I cannot connect to get the game. Also, people have talk about Demo Tkinter programs somewhere in the Python directories, and again, I have nothing anywhere as demos for Tkinter in Python. I would really like to start using some Tkinter. I've gotten decent (okay, maybe just acceptable) with my Python coding so far. That is, if there is something that I want to do, I can hack together something that might not be pretty but will work. But, since I have no experience with Tkinter, or anything like it, I have no real idea where to start. However, with some demos, I might have an idea of what can be done. Oh, this is also for Python 1.5.2 for Windows and just recently upgraded to Python 2.0 for Windows. No demos for Tkinter. However, I am in the process of creating a Linux box and might eventually leave the evil that is Windows. Maybe the Tkinter demos are not part of the Windows install. Tim Brauch P.S. Yeah, I realize this seems somewhat like a rant, but I really didn't intend it to be. I just would like some Tkinter demos like it seems everyone else has. From Sascharrer@aol.com Sun Mar 4 06:38:25 2001 From: Sascharrer@aol.com (Sascharrer@aol.com) Date: Sun, 4 Mar 2001 01:38:25 EST Subject: [Tutor] GUI Apps Message-ID: <e5.3198f44.27d33ce1@aol.com> Hi, there! Is it better to use Tkinter or wxPython for creating GUI-Applications with Python? Which of them is quicker? Why is Tkinter the standard graphics library for Python? Thanks, Sascharrer From Sascharrer@aol.com Sun Mar 4 06:38:27 2001 From: Sascharrer@aol.com (Sascharrer@aol.com) Date: Sun, 4 Mar 2001 01:38:27 EST Subject: [Tutor] Windows-EXE-Files Message-ID: <f6.7d29b1d.27d33ce3@aol.com> Hi, there! When I have a finished python program (some *.py files), can I create a Win95-EXE - file out of it? (I'm using the BeOpen-Python-2.0.exe pack for Windows 95/98/NT) Thanks Sascharrer From tbrauch@mindless.com Sun Mar 4 06:48:26 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Sun, 04 Mar 2001 01:48:26 -0500 Subject: [Tutor] Windows-EXE-Files References: <f6.7d29b1d.27d33ce3@aol.com> Message-ID: <3AA1E53A.8E084F73@mindless.com> Ha, here is one I can (try to) answer. Essentially, if someone doesn't have Python installed, they can't run *.py or *.pyw files. Now, this reason alone should be enough to convince anyone to download and install Python, along with the sheer fun of programming in such an easy-to-learn language. But, alas, it is hard to actually convince most Windows users of this (trust me, I am slowly weening myself from Windows so I know how Windows users think). But, as luck would have it, you are definitely not the only person to ask this question and somebody decided to give us some help. Something that I use, Freeze, can be found at <http://www.mcmillan-inc.com/install1.html>. It is not that difficult to use and, best of all, it actually works. I've created Python programs using VPython and sent them through Freeze. After emailing them to friends who use Windows, they can run the program, with VPython support. Even though it supports it, I haven't tried using it with Tk yet, but that is a whole different problem that I am having on my own ;o). Sascharrer@aol.com wrote: > > Hi, there! > > When I have a finished python program (some *.py files), can I create a > Win95-EXE - file out of it? > > (I'm using the BeOpen-Python-2.0.exe pack for Windows 95/98/NT) > > Thanks > > Sascharrer > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From aleaxit@yahoo.com Sun Mar 4 08:16:03 2001 From: aleaxit@yahoo.com (Alex Martelli) Date: Sun, 4 Mar 2001 09:16:03 +0100 Subject: [Tutor] Re: [Python-Help] Windows-EXE-Files References: <f6.7d29b1d.27d33ce3@aol.com> Message-ID: <03a501c0a483$ea891fa0$0300a8c0@arthur> <Sascharrer@aol.com> writes: > When I have a finished python program (some *.py files), can I create a > Win95-EXE - file out of it? > > (I'm using the BeOpen-Python-2.0.exe pack for Windows 95/98/NT) Simplest, if it works for you, may be py2exe, http://www.sourceforge.net/projects/py2exe/. Not quite as easy to use, very powerful, is Installer, http://www.mcmillan-inc.com/builder.html Alex _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From tescoil@irtc.net Sun Mar 4 12:18:46 2001 From: tescoil@irtc.net (Tesla Coil) Date: Sun, 04 Mar 2001 07:18:46 -0500 Subject: [Tutor] Mappage. Message-ID: <3AA232A6.3811A64@irtc.net> In the spirit of "Useless Python", just thought I'd share an interpreter session with a couple moments of what don't work and what does... >>> percentages = range(1.05, 1.5, .05) Traceback (innermost last): File "<stdin>", line 1, in ? ValueError: zero step for range() # What am I thinking? Can't do that. >>> percentages = range(105, 155, 5) >>> def percentify(x):return x*.01 ... >>> percentages = map(percentify, percentages) >>> percentages [1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5] # That's what I want. Next phase of the formula: >>> dimensions = [33.46, 11, 5.5, 2.75] >>> def scaleup(dims, prcnt):return dims*prnct ... >>> for prcnt in percentages: ... map(scaleup, dimensions, prcnt) ... Traceback (innermost last): File "<stdin>", line 2, in ? TypeError: argument 3 to map() must be a sequence object # Err, gotta pass prcnt to the scaleup function. # Wait, if I can "def percentify(x):return x*.01" ... >>> for prcnt in percentages: ... def scaleup(dims):return dims*prcnt ... map(scaleup, dimensions) ... [35.133, 11.55, 5.775, 2.8875] [36.806, 12.1, 6.05, 3.025] [38.479, 12.65, 6.325, 3.1625] [40.152, 13.2, 6.6, 3.3] [41.825, 13.75, 6.875, 3.4375] [43.498, 14.3, 7.15, 3.575] [45.171, 14.85, 7.425, 3.7125] [46.844, 15.4, 7.7, 3.85] [48.517, 15.95, 7.975, 3.9875] [50.19, 16.5, 8.25, 4.125] From lha2@columbia.edu Sun Mar 4 12:41:02 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Sun, 04 Mar 2001 07:41:02 -0500 Subject: [Tutor] Re: Type Checking References: <E14ZXUX-0005TK-00@mail.python.org> Message-ID: <3AA237DE.941C53DD@mail.verizon.net> >From message> 10. Re: Type Checking: (Danny Yoo) ... > (Does anyone find it humorous that there's even a types.TypeType object Have you ever repeated a word until it doesn't feel like a word anymore, or at least must be spelled wrong? >>> type(types.TypeType) <type 'type'> From arcege@shore.net Sun Mar 4 12:57:15 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 4 Mar 2001 07:57:15 -0500 (EST) Subject: [Tutor] Re: Type Checking In-Reply-To: <3AA237DE.941C53DD@mail.verizon.net> from Lloyd Hugh Allen at "Mar 4, 2001 7:41: 2 am" Message-ID: <E14ZY4Z-0000K4-00@nautilus.shore.net> > >From message> 10. Re: Type Checking: (Danny Yoo) > ... > > (Does anyone find it humorous that there's even a types.TypeType object > > Have you ever repeated a word until it doesn't feel like a word anymore, > or at least must be spelled wrong? > > >>> type(types.TypeType) > <type 'type'> Similarly, >>> types.TypeType <type 'type'> >>> x = None >>> for i in range(5): ... x = type(x) ... print x ... <type 'None'> <type 'type'> <type 'type'> <type 'type'> <type 'type'> >>> x is types.TypeType 1 >>> I don't find it humorous at all that there should be a name binding in the types module for the "type" data type; I find it complete. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From hbcc100@york.ac.uk Sun Mar 4 13:07:10 2001 From: hbcc100@york.ac.uk (hbcc100) Date: Sun, 04 Mar 2001 13:07:10 +0000 Subject: [Tutor] font Message-ID: <3AA23DFE.BB1D11A5@york.ac.uk> Hello, I am writing a program containing both Japanese and German on my Mac. To display both languages correctly, I need to change the font. How can I do this? I have been told that there might be a way of changing fonts using Fm (Font Manager). But I can't find any documentation on this. Can anyone help me? Thank you Heike From kstoner@netins.net Sun Mar 4 16:42:20 2001 From: kstoner@netins.net (Katharine Stoner) Date: Sun, 4 Mar 2001 10:42:20 -0600 Subject: [Tutor] software design Message-ID: <000801c0a4ca$158bb3c0$bf52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0A497.CA510C20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Does anyone know of a good scource on how to design programs before you = start programming? -Cameron Stoner ------=_NextPart_000_0005_01C0A497.CA510C20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Does anyone know of a good scource on = how to design=20 programs before you start programming?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Cameron = Stoner</FONT></DIV></BODY></HTML> ------=_NextPart_000_0005_01C0A497.CA510C20-- From tim@johnsons-web.com Sun Mar 4 17:16:06 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 4 Mar 2001 08:16:06 -0900 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words References: <Pine.LNX.4.21.0103032006190.850-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <01030408264800.04879@shecom> Hey Danny: Thought I'd post my reply back to the list because other newbies might want to see your cautionary about what is essentialy "high-jacking" python reserved words. I would welcome some comments from anyone as to the comparative advantages of the following > type(mystr) == types.StringType as opposed to > type(mystr) == 'string': because the first method necessitates importing another module: re: more "overhead". Thanks for the heads up Danny! On Sat, 03 Mar 2001, Danny Yoo wrote: <snip> > (Side note: try to avoid using 'str' as a variable name: it's already the > name of the built-in str() function that converts anything to a string. > This warning is meant to avoid potential weirdness later on; you'll > probably want to keep that str() function for a rainy day. *grin*) > > > Other people have already pointed out that > > type(mystr) == types.StringType > > is the traditional way of doing the type comparison. The reason that > > type(mystr) == 'string': > > doesn't quite work is because types are things --- objects --- that need > to be compared with either other. This might not make much sense yet; > let's make an analogy with what we already know. In Python: > > 1 == '1' > > is false, even though they 'look' the same, and the reason is because > numbers are different from strings. Likewise: > > type(mystr) == "<type 'string'>" > > doesn't work either; types are things that are different from both strings > and numbers. That's why Python has a premade collection of these type > objects in the 'types' module, to make the comparison easier and to avoid > this issue. However, in a pinch, this will work: > > type(mystr) == type('this is a string') > > because we grab the type of mystr, and grab the type of a string, and > compare the two. This works because we're comparing between alike things. > It's the apples and oranges argument, taken in a very literal setting. > > (Does anyone find it humorous that there's even a types.TypeType object in > there?) > > Good luck to you. -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From alan.gauld@bt.com Sun Mar 4 17:25:06 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 4 Mar 2001 17:25:06 -0000 Subject: [Tutor] 'number' strings error Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5EB@mbtlipnt02.btlabs.bt.co.uk> > When I run this I get a 'cannot assign to literal' on the > number strings. Thats because you are using numbers as variables which is not allowed. Try using one, two, three etc instead > 1 = '1' # > 2 = '2' # errors on these - try one = '1' instead > 3 = '3' # > > l = [a, b, c] > n = [1, 2, 3] # and this becomes [one,two,three] # or just use ['1','2','3']... > > if l: > l1 = random.choice(l) > if l: Since this is already tested above why not combine all the l conditions like: if l: l1 = random.choice(l) l2 = random.choice(l) l3 = ... l4 = .... > if n: > n1 = random.choice(n) Or does random.choice change l during its action - eek! bad! Alan G From sheila@thinkspot.net Sun Mar 4 17:37:18 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 04 Mar 2001 09:37:18 -0800 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <01030408264800.04879@shecom> References: <Pine.LNX.4.21.0103032006190.850-100000@c82114-a.pinol1.sfba.home.com> <01030408264800.04879@shecom> Message-ID: <2CB1ABC17C6@kserver.org> It is not necessary to import the types module. Just try this: teststr = "" if type(mystr) == type(teststr): pass People pointed this out yesterday, but perhaps you overlooked it? I reckon, that this is what the types module does, anyhow. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sun, 4 Mar 2001 08:16:06 -0900, Tim Johnson <tim@johnsons-web.com> wrote about Re: [Tutor] Type Checking:/High-Jacking Reserved Words: :Hey Danny: : Thought I'd post my reply back to the list because other :newbies might want to see your cautionary about :what is essentialy "high-jacking" python reserved words. : :I would welcome some comments from anyone as to the :comparative advantages of the following :> type(mystr) == types.StringType :as opposed to :> type(mystr) == 'string': :because the first method necessitates importing another :module: re: more "overhead". : :Thanks for the heads up Danny! From alan.gauld@bt.com Sun Mar 4 17:36:49 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 4 Mar 2001 17:36:49 -0000 Subject: [Tutor] Re: 'number' strings error Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5ED@mbtlipnt02.btlabs.bt.co.uk> > >>> age = int('42') > >>> print type(age) > <type 'int'> > ### > > It's easier to type than string.atoi('42'), and more > versatile. It can work with floating point numbers too: But unlike atoi can't do different number bases like hex or binary. Thats where atoi really is necessary. Just a nit pick. Alan G. From alan.gauld@bt.com Sun Mar 4 17:47:00 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 4 Mar 2001 17:47:00 -0000 Subject: [Tutor] GUI Apps Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5EE@mbtlipnt02.btlabs.bt.co.uk> > Is it better to use Tkinter or wxPython for creating > GUI-Applications with Python? As ever it depends. Tk seems to be better supported on multiple platforms wxPython is only on PC, Mac and Unix - but thats probably enough for most purposes! Personally I find Tk easier to program but thats probably because I'm used to it on Tcl and Tk... There is certainly much more documentation for Tk than wx. > Which of them is quicker? Id guess wx would be marginally faster since Tk has to go through a layer of Tcl code. But most operations won't be in the GUI stuff they'll be waiting on the underlying event handlers which will be pretty similar since they are in Python! > Why is Tkinter the standard graphics library for Python? It was first? And its easy to use and widely available, like python. My personal opinion, others may differ. Alan G. From tim@johnsons-web.com Sun Mar 4 18:05:01 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 4 Mar 2001 09:05:01 -0900 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words References: <Pine.LNX.4.21.0103032006190.850-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <01030408264800.04879@shecom> Hello: There was an errory in my previous post, so am reposting. Sorry! ======================================================= I would welcome some comments from anyone as to the comparative advantages of the following > type(mystr) == types.StringType as opposed to > type(mystr) == type("") because the first method necessitates importing another module: re: more "overhead". -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From alan.gauld@bt.com Sun Mar 4 17:59:12 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 4 Mar 2001 17:59:12 -0000 Subject: [Tutor] PySol (fwd) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5EF@mbtlipnt02.btlabs.bt.co.uk> > Oh, this is also for Python 1.5.2 for Windows and just > recently upgraded > to Python 2.0 for Windows. No demos for Tkinter. The only "demos" that I have are in the Tools directory structure of the standard windows install. In my case thats at: D:\Python\Tools But these are a bit more than a simple demo! If you install the TCL installer from scriptics site then there is a demo application there that shows off all the Tk widgets but uses Tcl code. That might be what is being spoken of. HTH, Alan G. From alan.gauld@bt.com Sun Mar 4 18:12:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 4 Mar 2001 18:12:29 -0000 Subject: [Tutor] software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F1@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0A4D6.ACB67850 Content-type: text/plain; charset="iso-8859-1" Does anyone know of a good scource on how to design programs before you start programming? Short answer is no. I have a chapter in my book called "Designing a solution" but even it is really just some things to think about. Its really hard to describe the creative processes involved in converting an idea to an algorithm and hence to a program. There are a few books on Problem Solving that try to do thast but none do it well IMHO. Going down a level there are a few that describe ways of documenting solutions using various notations. But that doesn't help you actually come up with a design, just how ton write your thoughts down... Alan G. ------_=_NextPart_001_01C0A4D6.ACB67850 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT size=2><FONT face=Arial>Does anyone know of a good scource on how to design programs before you start programming?<FONT color=#0000ff><SPAN class=930590218-04032001> </SPAN></FONT></FONT><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001> </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001></SPAN></FONT></FONT></FONT> </DIV></BLOCKQUOTE> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>Short answer is no. I have a chapter in my book called "Designing a solution" </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>but even it is really just some things to think about. Its really hard to describe </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>the creative processes involved in converting an idea to an algorithm and hence </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>to a program. There are a few books on Problem Solving that try to do thast </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>but none do it well IMHO.</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>Going down a level there are a few that describe ways of documenting </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>solutions using various notations. But that doesn't help you actually come </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>up with a design, just how ton write your thoughts down...</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=930590218-04032001>Alan G.</SPAN></FONT></FONT></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0A4D6.ACB67850-- From tim@johnsons-web.com Sun Mar 4 18:29:35 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 4 Mar 2001 09:29:35 -0900 Subject: [Tutor] Read - Only Text? References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F1@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01030409325106.04879@shecom> Hi: I need to set up a widget that : 1)Displays text 2)Allows copy and paste 3)But does "not" allow editing Question: I can't find a way to set the TKinter Text widget to read - only. That is, not editable. Is there a way? If not, can someone recommend an alternative? TIA -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From DOUGS@oceanic.com Sun Mar 4 19:06:35 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sun, 4 Mar 2001 09:06:35 -1000 Subject: [Tutor] software design Message-ID: <8457258D741DD411BD3D0050DA62365907A697@huina.oceanic.com> [Katharine Stoner asked:] >> Does anyone know of a good source on how to design programs >> before you start programming? [and Alan G. answered:] > Short answer is no. I have a chapter in my book called "Designing > a solution" but even it is really just some things to think about. > Its really hard to describe the creative processes involved in > converting an idea to an algorithm and hence to a program. There > are a few books on Problem Solving that try to do that but none > do it well IMHO. > Going down a level there are a few that describe ways of documenting > solutions using various notations. But that doesn't help you actually > come up with a design, just how to write your thoughts down... Mostly I'm in agreement with Alan. But I'd like to turn your question around slightly. With Python you have a language that gets out of your way enough that you may be able to start programming before you "do" design. I don't mean that in the way of taking it to an extreme of randomly entering code in an editor. You wouldn't have come to programming and Python without some idea of something you wanted to make a computer do. That in itself is a design. With many languages you definately need to plan to the extreme to make headway against the blank slate syndrome. With Python you have many tools to get started before your design is fully formed. That half formed idea you have can be enough. My process is very often this: Start an interpretor session while a text editor is open in another window. Think about what the output of the program needs to be. Type into the interpreter commands that will produce that output. When I've gotten what I want, copy the commands that work into the editor and create a function structure around it. Save the file and try to run it and correct any errors until it does. This process is as much a design process as sitting down with diagramming tools and the like. Its also one that seems best suited to a programmer, and that Python facilitates instead of impeding like other languages might. The other more long term process has to do with the evolution of the program in terms of 'paradigm'. Mine usually start as simple scripts that sequentially process something. I then start pulling functions out to simplify, adding a if __name__ == '__Main__' to create an importable module. Finally I'll often pull out code that should go together and start creating objects. Python supports this migration from script to functional to object oriented system in a unique way. Just to be clear, I think this process eventually requires a bunch more than the simple version above. It helps a lot to read a lot of code. I try to read everything that comes on c.l.py, especially from the gurus. This gives you a basis to start when you are in the interpreter. You should be aware of the developments in design patterns, unit testing, and refactoring. With this method of coding you are building one or two to throw away. With refactoring you don't exactly throw it away, and unit testing, often the tests come from the original interpreter sessions, makes sure its always doing what you want. I guess my main point, start programming and the design will fall into place. -Doug- From bobhicks@adelphia.net Sun Mar 4 19:09:43 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Sun, 4 Mar 2001 14:09:43 -0500 Subject: [Tutor] GUI Apps Message-ID: <E14Zdtb-0006Ez-00@mail.python.org> wxPython is on the Mac? On Sunday, March 4, 2001, at 12:47 PM, alan.gauld@bt.com wrote: > > Is it better to use Tkinter or wxPython for creating > > GUI-Applications with Python? > > > As ever it depends. > Tk seems to be better supported on multiple platforms > wxPython is only on PC, Mac and Unix - but thats probably > enough for most purposes! > > Personally I find Tk easier to program but thats probably > because I'm used to it on Tcl and Tk... > > There is certainly much more documentation for Tk than wx. > > > Which of them is quicker? > > Id guess wx would be marginally faster since Tk has to go > through a layer of Tcl code. But most operations won't be > in the GUI stuff they'll be waiting on the underlying > event handlers which will be pretty similar since they > are in Python! > > > Why is Tkinter the standard graphics library for Python? > > It was first? And its easy to use and widely available, > like python. > > My personal opinion, others may differ. > > Alan G. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From bsass@freenet.edmonton.ab.ca Sun Mar 4 22:23:54 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Sun, 4 Mar 2001 15:23:54 -0700 (MST) Subject: [Tutor] software design In-Reply-To: <000801c0a4ca$158bb3c0$bf52b1cf@oemcomputer> Message-ID: <Pine.LNX.4.33.0103041357500.15206-100000@bms> On Sun, 4 Mar 2001, Katharine Stoner wrote: > Hi all, > > Does anyone know of a good scource on how to design programs before you start programming? > > -Cameron Stoner Coming at it from a mostly hacker^H^H^H^H^Hobbiest background, professionals and academics may have different opinions, it appears that it is the kinda thing you just get a feel for. In general... The better an understanding you have of the system the problem arises in, the easier it is to design a program that does what you want and is usable (flexible). This is true at both the user level (running the program) and with the individual coding tasks. If your program is a `control center' kinda thing (most apps), you probably want to start with the user interface; `have A, need to get to B' types of programs (utilities and tools) can be approached in a more linear manner. For example: If you are writing a editor you could start with a GUI designer and do the main window, then some dialogs - don't worry about the details, just define the functionality. A program to translate something would start at the beginning and take it step by step, you can always go back and rewrite the steps as functions or methods of objects later on. The data structures you use to represent things are probably the most important bits of the program. Often you have data coming in a particular format which makes such'n'such structure a natural choice, but if you are going to be presenting the data as information most of the time... the natural structure may result in your code having to work harder than if you had used a structure closer to what the output of the program requires. I usually go through this design loop: - work on the UI - work on the low-level stuff - work on the data structure - connect the UI and low-level to the data structure to provide a particular function - test at some point the "work on..." stuff is skipped (but never forgotten) because I have settled on a design, all that is left is to write the code for specific functions, and test. The program often ends up looking quite different from how it started; however, if I find I want to fiddle with the data structure(s) everytime new functionality is connected up, I know I don't really understand what I am trying to do. HTH - Bruce From Sammy69Ch@si.rr.com Sun Mar 4 22:28:20 2001 From: Sammy69Ch@si.rr.com (Juan Samalot) Date: Sun, 4 Mar 2001 17:28:20 -0500 Subject: [Tutor] hi Message-ID: <000a01c0a4fa$6b4f1ce0$0300a8c0@si.rr.com> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0A4D0.821C00C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi my name is Sammy i have just bought a Python book "Sam teach yourself = Python" and i have just started to read it.=20 ------=_NextPart_000_0007_01C0A4D0.821C00C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi my name is Sammy i have just bought = a Python=20 book "Sam teach yourself Python" and i have just started to read = it.=20 </FONT></DIV></BODY></HTML> ------=_NextPart_000_0007_01C0A4D0.821C00C0-- From kojo@tamu.edu Sun Mar 4 22:46:18 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Sun, 04 Mar 2001 16:46:18 -0600 Subject: [Tutor] hi In-Reply-To: <000a01c0a4fa$6b4f1ce0$0300a8c0@si.rr.com> Message-ID: <5.0.2.1.0.20010304164556.0220d070@pop3.norton.antivirus> --=====================_58389609==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed Hello and Welcome Sammy!! At 05:28 PM 3/4/01 -0500, Juan Samalot wrote: >Hi my name is Sammy i have just bought a Python book "Sam teach yourself >Python" and i have just started to read it. **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** --=====================_58389609==_.ALT Content-Type: text/html; charset="us-ascii" <html> Hello and Welcome Sammy!!<br> <br> <br> At 05:28 PM 3/4/01 -0500, Juan Samalot wrote:<br> <blockquote type=cite class=cite cite><font face="arial" size=2>Hi my name is Sammy i have just bought a Python book "Sam teach yourself Python" and i have just started to read it. </font></blockquote> <x-sigsep><p></x-sigsep> **************************** <br> Kojo Idrissa <br> KPMG Scholar <br> Accounting Doctoral Student <br> Texas A&M University <br> <br> Kojo@tamu.edu <br> 401M Wehner Bldg. <br> 979-862-2726 <br> ****************************</html> --=====================_58389609==_.ALT-- From jdrake@jam.rr.com Sun Mar 4 23:08:41 2001 From: jdrake@jam.rr.com (Jason Drake) Date: Sun, 4 Mar 2001 17:08:41 -0600 Subject: Fw: [Tutor] software design Message-ID: <038f01c0a500$0e1f76e0$80c8a418@jam.rr.com> This is a multi-part message in MIME format. ------=_NextPart_000_038C_01C0A4CD.C3311A80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable First off, sorry to Alan Gauld! Dang, but I can't seem to get used to = this particular listserv which doesn't seem to want to handle replies to = the list as replies to the list in the manner I am most familiar with... = That complaint and apology out of the way, the following was meant for = the list, not just Mr. Gauld... --------------------------------------------------------------- Sent: Sunday, March 04, 2001 3:21 PM Subject: Re: [Tutor] software design Sadly I don't have a good answer for this either, and actually would = like to know, related to this, if anyone knows of any good resources for = designing flow charts? I remember once upon a time completely ignoring = that part of my comp-sci class in junior high because I was in no need = of them (Ha!) but wish now that I had paid better attention or could = find a good resource... Jay D. --------------------------------------------------------------- ----- Original Message -----=20 From: alan.gauld@bt.com=20 To: kstoner@netins.net ; tutor@python.org=20 Sent: Sunday, March 04, 2001 12:12 PM Subject: RE: [Tutor] software design Does anyone know of a good scource on how to design programs before = you start programming? =20 Short answer is no. I have a chapter in my book called "Designing a = solution"=20 but even it is really just some things to think about. Its really hard = to describe=20 the creative processes involved in converting an idea to an algorithm = and hence=20 to a program. There are a few books on Problem Solving that try to do = thast=20 but none do it well IMHO. Going down a level there are a few that describe ways of documenting=20 solutions using various notations. But that doesn't help you actually = come=20 up with a design, just how ton write your thoughts down... Alan G. ------=_NextPart_000_038C_01C0A4CD.C3311A80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>First off, sorry to Alan Gauld! Dang, = but I=20 can't seem to get used to this particular listserv which doesn't seem to = want to=20 handle replies to the list as replies to the list in the manner I am = most=20 familiar with... That complaint and apology out of the way, the = following was=20 meant for the list, not just Mr. Gauld...</FONT></DIV> <DIV><B></B> </DIV> <DIV><STRONG>------------------------------------------------------------= ---</STRONG></DIV> <DIV><B>Sent:</B> Sunday, March 04, 2001 3:21 PM</DIV> <DIV style=3D"FONT: 10pt arial"> <DIV><B>Subject:</B> Re: [Tutor] software design</DIV></DIV> <DIV><FONT face=3DArial size=3D2></FONT><BR></DIV> <DIV><FONT face=3DArial size=3D2>Sadly I don't have a good answer for = this either,=20 and actually would like to know, related to this, if anyone knows of any = good=20 resources for designing flow charts? I remember once upon a time = completely=20 ignoring that part of my comp-sci class in junior high because I was in = no need=20 of them (Ha!) but wish now that I had paid better attention or could = find a good=20 resource...</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Jay D.</FONT></DIV> <DIV><STRONG>------------------------------------------------------------= ---</STRONG></DIV> <BLOCKQUOTE dir=3Dltr=20 style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A title=3Dalan.gauld@bt.com=20 href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = title=3Dkstoner@netins.net=20 href=3D"mailto:kstoner@netins.net">kstoner@netins.net</A> ; <A=20 title=3Dtutor@python.org = href=3D"mailto:tutor@python.org">tutor@python.org</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, March 04, 2001 = 12:12=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] software=20 design</DIV> <DIV><BR></DIV> <BLOCKQUOTE=20 style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px = solid; MARGIN-RIGHT: 0px"> <DIV><FONT size=3D2><FONT face=3DArial>Does anyone know of a good = scource on how=20 to design programs before you start programming?<FONT = color=3D#0000ff><SPAN=20 class=3D930590218-04032001> </SPAN></FONT></FONT><FONT = face=3DArial><FONT=20 color=3D#0000ff><SPAN=20 class=3D930590218-04032001> </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 = class=3D930590218-04032001></SPAN></FONT></FONT></FONT> </DIV></BLOC= KQUOTE> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>Short answer is no. I have a chapter in my = book=20 called "Designing a solution" </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>but even it is really just some things to = think=20 about. Its really hard to describe </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>the creative processes involved in = converting an idea=20 to an algorithm and hence </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>to a program. There are a few books on = Problem=20 Solving that try to do thast </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>but none do it well=20 IMHO.</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>Going down a level there are a few that = describe ways=20 of documenting </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>solutions using various notations. But that = doesn't=20 help you actually come </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>up with a design, just how ton write your = thoughts=20 down...</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=3D2><FONT face=3DArial><FONT color=3D#0000ff><SPAN=20 class=3D930590218-04032001>Alan=20 G.</SPAN></FONT></FONT></FONT></DIV></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_038C_01C0A4CD.C3311A80-- From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 03:08:58 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 4 Mar 2001 19:08:58 -0800 (PST) Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <2CB1ABC17C6@kserver.org> Message-ID: <Pine.LNX.4.21.0103041906380.944-100000@c82114-a.pinol1.sfba.home.com> On Sun, 4 Mar 2001, Sheila King wrote: > It is not necessary to import the types module. > > Just try this: > > teststr = "" > > if type(mystr) == type(teststr): > pass > > People pointed this out yesterday, but perhaps you overlooked it? > I reckon, that this is what the types module does, anyhow. Let's take a look: [excerpt from types.py] ### IntType = type(0) LongType = type(0L) FloatType = type(0.0) try: ComplexType = type(complex(0,1)) except NameError: pass StringType = type('') ### Yes, that's how they're doing it. Personally, I like using the StringType approach, but both will work ok. From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 02:41:49 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 4 Mar 2001 18:41:49 -0800 (PST) Subject: [Tutor] hi In-Reply-To: <000a01c0a4fa$6b4f1ce0$0300a8c0@si.rr.com> Message-ID: <Pine.LNX.4.21.0103041841180.944-100000@c82114-a.pinol1.sfba.home.com> On Sun, 4 Mar 2001, Juan Samalot wrote: > Hi my name is Sammy i have just bought a Python book "Sam teach > yourself Python" and i have just started to read it. Hello Sammy! Nice to meet you. How's the book so far? From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 02:58:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 4 Mar 2001 18:58:26 -0800 (PST) Subject: [Tutor] Read - Only Text? In-Reply-To: <01030409325106.04879@shecom> Message-ID: <Pine.LNX.4.21.0103041853090.944-100000@c82114-a.pinol1.sfba.home.com> On Sun, 4 Mar 2001, Tim Johnson wrote: > I need to set up a widget that : > > 1)Displays text > 2)Allows copy and paste > 3)But does "not" allow editing > > Question: I can't find a way to set the TKinter Text widget to > read - only. That is, not editable. Has anyone answered your question yet? I haven't found a boolean that makes it uneditable yet. I've been looking at the Message widget, which I thought would be perfect. However, I can't seem to do copy and paste against it. *sigh* Close, but not close enough. I'll read and experiment some more, and if I find anything, I'll email again about this. From sthickey@juno.com Mon Mar 5 07:35:39 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Sun, 4 Mar 2001 23:35:39 -0800 Subject: [Tutor] Re: Software Design Message-ID: <20010304.233541.-275951.0.sthickey@juno.com> I don't think that you are in the right forum for Software Design. In the Master's Program at Ball State University, there are approximately 10 semester long courses that seek to prepare one for Software Design and IMHO, fail. I have not been current on design for some time, but common sense helps. First there has to be a really good Needs Analysis so that you know what the program is to produce. Then you need some Functional Analysis, so that you know what modules you will need and what functions have to be written, not to mention what functions that do not need to be written. If you get past this point, then there is the Algorithm Design to think of for anything more than a simple 25 line Function. OOPS, I almost forgot: DOCUMENTATION and ERROR CONTROL DESIGN. Then there is the CODING! Then the Testing. ETC ETC Stevenson Hickey PS, then, when you think that you are done, the CLIENT SAYS: Why doesn't it do "X"?? AND you REALIZE THAT YOU DON'T KNOW HOW TO DO X!! From marty55@home.com Mon Mar 5 08:28:13 2001 From: marty55@home.com (Marty Pitts) Date: Mon, 5 Mar 2001 00:28:13 -0800 Subject: [Tutor] Loops and User Input References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5EA@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <002001c0a54e$389e3b60$369e0618@tcma1.wa.home.com> This is a multi-part message in MIME format. ------=_NextPart_000_001D_01C0A50B.2A3F7900 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable From: alan.gauld@bt.com=20 To: marty55@home.com=20 Sent: Sunday, March 04, 2001 9:16 AM Subject: RE: [Tutor] Loops and User Input HI, Glad to see you are working thru' the book. Your example looks = fine=20 to me and the fact that you have elaborated on the version on the book = is excellent. That's by far the best way to learn. Just in case you haven't seen it there is an errata page at: http://www.crosswinds.net/~agauld/book/errata.htm And there are direct mail links to me there too. Thanks, I appreciate the pointer. But I can't see any immediate problems in your code other than the = ones=20 Danny Yoo pointed out with strangeness using low multipliers. However I couldn't help adding a few "thought provoking" comments :-) multiplier =3D input("Which mulitplier value do you want to use? ") for i in range(2, multiplier + 1): for j in range(1, multiplier + 1): =20 Are you sure you want this? If you use a multiplier of say 20 you = will get all of the tables from 2 to 20 times. BUT they will also have all the elements from 1 to 20! I suspect you want to make the second range be (1,13) to get the 1 = to 12 values? I noticed this. I am thinking about modifying the input for the = user to be able to have choice for both variables. Just a thought. if i =3D=3D 2 and j =3D=3D 1: print "---------------------------------- " print "This table is the",i,"multiple table" print "---------------------------------- "=20 So this only prints for the first time round since i is only 2 once. Assuming you want the caption for every table I think you only=20 need to check for j=3D=3D1?=20 It is necessary to check for both values if the caption is to work = correctly. If I check, as you suggest, only for equality on the variable = j, double captions result for every table after the first one. In order = for the heading to show up on only the first time around, a check is = needed on both variables. I discovered this by trial and error. =20 print "%d x %d =3D %d" % (j, i, j * i) if i =3D=3D multiplier: break =20 Oooh! Now I never wrote about break :-) Where did you find that trick? Yours is not the only book on Python that I own. :-) However, I = find it a good one for my pace. But it will throw you out of the loop one iteration before I think = you want to? After all, you used multiplier+1 in the initial range. This will = somewhat deeat the=20 purpose of that won't it? Actually, it breaks at just the right spot. When the code runs, = if I don't put a break here, it prints a caption at the end of the = output that is useless, since the captions are for information at the = start of each table. print "---------------------------------- " print "This table is the",i + 1 ,"multiple table" print "---------------------------------- " Using any input just returns to a prompt in 'idle'. Don't understand why that is tho'... Alan G. Thanks for your critique. If you spot any errors in my reasonings = above, please feel free to point them out. Regards, Marty. ------=_NextPart_000_001D_01C0A50B.2A3F7900 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <BLOCKQUOTE dir=3Dltr=20 style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A title=3Dalan.gauld@bt.com=20 href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dmarty55@home.com = href=3D"mailto:marty55@home.com">marty55@home.com</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, March 04, 2001 = 9:16=20 AM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] Loops and = User=20 Input</DIV> <DIV><FONT face=3DArial size=3D2></FONT><BR></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>HI,=20 Glad to see you are working thru' the book. Your example looks fine=20 </SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>to=20 me and the fact that you have elaborated on the version on the book=20 </SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>is=20 excellent. That's by far the best way to learn.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT><FONT face=3DArial = color=3D#0000ff=20 size=3D2><SPAN class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>Just=20 in case you haven't seen it there is an errata page = at:</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001><A=20 = href=3D"http://www.crosswinds.net/~agauld/book/errata.htm">http://www.cro= sswinds.net/~agauld/book/errata.htm</A></SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>And=20 there are direct mail links to me there too.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001> Thanks, I appreciate the = pointer.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT><FONT face=3DArial = color=3D#0000ff=20 size=3D2><SPAN class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>But=20 I can't see any immediate problems in your code other than the ones=20 </SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>Danny Yoo pointed out with strangeness = using low=20 multipliers.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>However I couldn't help adding a few = "thought=20 provoking" comments :-)</SPAN></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <BLOCKQUOTE=20 style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px = solid; MARGIN-RIGHT: 0px"> <DIV><FONT face=3DArial size=3D2>multiplier =3D input("Which = mulitplier value do=20 you want to use? ")<BR>for i in range(2, multiplier +=20 1):<BR> for j in range(1, multiplier + = 1):<BR><SPAN=20 class=3D590055616-04032001><FONT=20 color=3D#0000ff> </FONT></SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>Are you sure you want this? If you use a = multiplier=20 of say 20 you will get</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>all of the tables from 2 to 20=20 times.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>BUT they will also have all the elements = from 1 to=20 20!</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D590055616-04032001>I=20 suspect you want to make the second range be (1,13) to get the 1 to = 12=20 values?</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001> I noticed this. = I am=20 thinking about modifying the input for the user to be able to have = choice=20 for both variables.</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>Just a thought.</SPAN></FONT></DIV> <DIV><FONT face=3DArial size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT><FONT face=3DArial = size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN=20 = class=3D590055616-04032001> </SPAN> &nb= sp; =20 if i =3D=3D 2 and j =3D=3D 1:<BR> = =20 print "----------------------------------=20 "<BR> print = "This=20 table is the",i,"multiple table"<BR> = =20 print "---------------------------------- "<SPAN=20 class=3D590055616-04032001><FONT=20 color=3D#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN=20 class=3D590055616-04032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN = class=3D590055616-04032001><FONT=20 color=3D#0000ff>So this only prints for the first time round = since i is=20 only 2 once.</FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN = class=3D590055616-04032001><FONT=20 color=3D#0000ff>Assuming you want the caption for every table I = think you only=20 </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN = class=3D590055616-04032001><FONT=20 color=3D#0000ff>need to check for=20 j=3D=3D1?</FONT> </SPAN></FONT></FONT></DIV> <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px"> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001>It is necessary to check for both = values if the=20 caption is to work correctly. If I check, as you suggest,=20 only for equality on the variable j, double captions = result for=20 every table after the first one. In order for the heading to show = up on=20 only the first time around, a check is needed on both variables. I = discovered this by trial and = error.</SPAN></FONT></DIV></BLOCKQUOTE> <DIV><FONT face=3DArial size=3D2><SPAN=20 class=3D590055616-04032001> </SPAN></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial><SPAN=20 = class=3D590055616-04032001> </SPAN> &nb= sp; =20 print "%d x %d =3D %d" % (j, i, j * i)<BR> if i = =3D=3D=20 multiplier:<BR> break<BR><SPAN=20 class=3D590055616-04032001><FONT=20 color=3D#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial color=3D#0000ff><SPAN=20 class=3D590055616-04032001>Oooh! Now I never wrote about break=20 :-)</SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial color=3D#0000ff><SPAN=20 class=3D590055616-04032001>Where did you find that=20 trick?</SPAN></FONT></FONT></DIV> <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px"> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001>Yours is not the only book on Python = that I own.=20 :-) However, I find it a good one for my=20 pace.</SPAN></FONT></DIV></BLOCKQUOTE> <DIV><FONT size=3D2><FONT face=3DArial color=3D#0000ff><SPAN=20 class=3D590055616-04032001>But it will throw you out of the loop one = iteration=20 before I think you want to?</SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial color=3D#0000ff><SPAN=20 class=3D590055616-04032001>After all, you used multiplier+1 in the = initial=20 range. This will somewhat deeat the </SPAN></FONT></FONT></DIV> <DIV><FONT size=3D2><FONT face=3DArial color=3D#0000ff><SPAN=20 class=3D590055616-04032001>purpose of that won't=20 it?</SPAN></FONT></FONT></DIV> <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px"> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001>Actually, it breaks at just the right = spot. =20 When the code runs, if I don't put a break here, it prints a = caption at=20 the end of the output that is useless, since the captions are for=20 information at the start of each = table.</SPAN></FONT></DIV></BLOCKQUOTE> <DIV><FONT size=3D2><FONT face=3DArial><SPAN=20 class=3D590055616-04032001> </SPAN> print=20 "---------------------------------- "<BR> print = "This=20 table is the",i + 1 ,"multiple table"<BR> print=20 "---------------------------------- "</FONT></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Using any input just returns to a = prompt in=20 'idle'.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><SPAN class=3D590055616-04032001><FONT face=3DArial = color=3D#0000ff=20 size=3D2>Don't understand why that is tho'...</FONT></SPAN></DIV> <DIV><SPAN class=3D590055616-04032001></SPAN><FONT face=3DArial = color=3D#0000ff=20 size=3D2><SPAN class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001>Alan G.</SPAN></FONT></DIV> <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px"> <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20 class=3D590055616-04032001><FONT color=3D#800000>Thanks for your=20 critique.</FONT> <FONT color=3D#800000>If you spot any errors in = my=20 reasonings above, please feel free to point them=20 out.</FONT></SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001>Regards,</SPAN></FONT></DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 class=3D590055616-04032001></SPAN></FONT> </DIV> <DIV><FONT face=3DArial color=3D#800000 size=3D2><SPAN=20 = class=3D590055616-04032001>Marty.</SPAN></FONT></DIV></BLOCKQUOTE></BLOCK= QUOTE></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_001D_01C0A50B.2A3F7900-- From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 10:28:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 5 Mar 2001 02:28:43 -0800 (PST) Subject: [Tutor] font In-Reply-To: <3AA23DFE.BB1D11A5@york.ac.uk> Message-ID: <Pine.LNX.4.21.0103041912000.944-100000@c82114-a.pinol1.sfba.home.com> On Sun, 4 Mar 2001, hbcc100 wrote: > I am writing a program containing both Japanese and German on my Mac. > To display both languages correctly, I need to change the font. How > can I do this? I have been told that there might be a way of changing > fonts using Fm (Font Manager). But I can't find any documentation on > this. Can anyone help me? Have you gotten an answer yet on this one? If not, you might want to talk to the python-mac people on this; I'm not sure if there are any mac experts on this mailing list, but there should be tons on the other mailing list. Try here: http://python.org/sigs/pythonmac-sig/ I hope you get help on this; it sounds like an interesting problem. Good luck to you. From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 10:37:57 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 5 Mar 2001 02:37:57 -0800 (PST) Subject: [Tutor] GUI Apps In-Reply-To: <e5.3198f44.27d33ce1@aol.com> Message-ID: <Pine.LNX.4.21.0103050230330.4259-100000@c82114-a.pinol1.sfba.home.com> On Sun, 4 Mar 2001 Sascharrer@aol.com wrote: > Is it better to use Tkinter or wxPython for creating GUI-Applications > with Python? Which of them is quicker? Why is Tkinter the standard > graphics library for Python? Tkinter is generally considered the standard GUI interface for Python. That being said, lots of people use wxPython; even Eric S. Raymond has been quoted: "Why the hell hasn't wxPython become the standard GUI for Python yet?" A lot of it has to do with the fact that Tkinter already works pretty well; Tkinter's easy to use, and it works like a charm. I believe that Tkinter is also ported to more platforms than wxPython, but then, I could be completely wrong about this one. If anyone can talk about the nice things in wxPython, we can get a balanced discussion about it. Personally, I've never used wxPython, so I can't say much more about it. Try it out, and see which one you like. Good luck! From britt_green@hotmail.com Mon Mar 5 11:43:00 2001 From: britt_green@hotmail.com (Britt Green) Date: Mon, 05 Mar 2001 03:43:00 -0800 Subject: [Tutor] Can't Launch IDLE from Linux System Message-ID: <F246CjSSOV5NMboP9ux00018139@hotmail.com> Howdy, I just got Mandrake 7.2 up and running. When I try to start IDLE, I get the following error message: [cheshire@C718841-B cheshire]$ idle Traceback (most recent call last): File "/usr/lib/python1.5/site-packages/idle/idle.py", line 2, in ? import PyShell File "/usr/lib/python1.5/site-packages/idle/PyShell.py", line 12, in ? from Tkinter import * File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter [cheshire@C718841-B cheshire]$ How can I fix this? Thanks! Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From jdrake@jam.rr.com Mon Mar 5 12:15:16 2001 From: jdrake@jam.rr.com (Jason Drake) Date: Mon, 5 Mar 2001 06:15:16 -0600 Subject: [Tutor] re: software design Message-ID: <002801c0a56d$f0708c60$80c8a418@jam.rr.com> This is a multi-part message in MIME format. ------=_NextPart_000_0025_01C0A53B.A5A3C1C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hey... related to the software design resources question, does anyone = know of any resources that could point someone in the right direction = for writing flow charts that others would be able to understand? I seem = to remember flow chart symbols having specific meanings, but for the = life of me, I can't remember more than maybe one or two from learning = them in junior high. TIA, Jay D ------=_NextPart_000_0025_01C0A53B.A5A3C1C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hey... related to the software design = resources=20 question, does anyone know of any resources that could point someone in = the=20 right direction for writing flow charts that others would be able to = understand?=20 I seem to remember flow chart symbols having specific meanings, but for = the life=20 of me, I can't remember more than maybe one or two from learning them in = junior=20 high.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV> <DIV><FONT face=3DArial size=3D2><BR>Jay D</FONT></DIV></BODY></HTML> ------=_NextPart_000_0025_01C0A53B.A5A3C1C0-- From alan.gauld@bt.com Mon Mar 5 11:26:19 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 11:26:19 -0000 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F4@mbtlipnt02.btlabs.bt.co.uk> > I would welcome some comments from anyone as to the > comparative advantages of the following > > type(mystr) == types.StringType This works best if you are checkjing for type several times since the import overhead only gets called once. > > type(mystr) == type("") This is better if you only do it once since the extra function call is probably faster than importing the type module. > because the first method necessitates importing another > module: re: more "overhead". And the second has the overhead of the second type() function call. Alan g From alan.gauld@bt.com Mon Mar 5 11:42:23 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 11:42:23 -0000 Subject: [Tutor] software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F7@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0A569.585EC990 Content-type: text/plain; charset="iso-8859-1" am most familiar with... That complaint and apology out of the way, the following was meant for the list, not just Mr. Gauld... Since you replied to me I replied to you... Here it is for the group's benefit ! Alan G ----------------------------- > if anyone knows of any good resources for designing flow charts? To be honest I wouldn't use flow charts but rather opt for the Activity Charts in the UML notation. They are like a superset of flowcharts but allow multiple parallel streams of activity (eg threads) plus can show responsibilities for actions too (eg objects, processes) , via something called swimlanes. They are very powerful and documentation on UML and how to use it is plentiful both on the web and in book stores > I remember once upon a time completely ignoring that part of my comp-sci > class in junior high because I was in no need of them (Ha!) but wish now > that I had paid better attention or could find a good resource... Completely as an aside. When I wrote my book I mentioned flow charts and several reviewers took me to task because newbies to programming wouldn't know what they are. This amazed me because in the UK flow charts are taught to everyone in junior school. They are not associated with comp science at all. In fact nearly every instruction manual be it for a HiFi or washing machine will have a flowchart of how to find faults etc. Just a small transatlantic cultural observation. :-) Alan g. ------_=_NextPart_001_01C0A569.585EC990 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE dir=ltr style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>am most familiar with... That complaint and apology out of the way, the following was meant for the list, not just Mr. Gauld...</FONT></DIV></BLOCKQUOTE> <DIV><SPAN class=550073311-05032001><FONT color=#0000ff face=Arial size=2>Since you replied to me I replied to you...</FONT></SPAN></DIV> <DIV><SPAN class=550073311-05032001></SPAN> </DIV> <DIV><SPAN class=550073311-05032001></SPAN><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>Here it is for the group's benefit</SPAN><SPAN class=550073311-05032001> !</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>Alan G</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>-----------------------------</SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001> > </SPAN>if anyone knows of any good resources for designing flow charts? <BR> </FONT></FONT></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2>To be honest I wouldn't use flow charts but rather opt for the Activity Charts <BR>in the UML notation. They are like a superset of flowcharts but allow multiple <BR>parallel streams of activity <SPAN class=550073311-05032001> (eg threads) </SPAN>plus can show responsibilities for <SPAN class=550073311-05032001> </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2>actions too<SPAN class=550073311-05032001> (eg objects, processes) </SPAN>, <SPAN class=550073311-05032001> </SPAN>via something called swimlanes.<BR> <BR>They are very powerful and documentation on UML and how to use it is <BR>plentiful both on the web and in book stores</FONT></DIV> <DIV> </DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>> </SPAN>I remember once upon a time completely ignoring that part of my comp-sci <SPAN class=550073311-05032001> </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>> </SPAN>class in junior high because I was in no need of them (Ha!) but wish now <SPAN class=550073311-05032001> </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=550073311-05032001>> </SPAN>that I had paid better attention or could find a good resource...</FONT></FONT></FONT></DIV> <DIV> </DIV> <DIV><FONT color=#0000ff face=Arial size=2>Completely as an aside. When I wrote my book <SPAN class=550073311-05032001> I </SPAN> mentioned flow charts and <BR>several reviewers took me to task because newbies to programming wouldn't <BR>know what they are. This amazed me because in the UK flow charts are <BR>taught to everyone in junior school. They are not associated with comp <BR>science at all. In fact nearly every instruction manual be it for a <SPAN class=550073311-05032001> H</SPAN>i<SPAN class=550073311-05032001>F</SPAN>i or <BR>washing mac<SPAN class=550073311-05032001>h</SPAN>ine will have a flowchart of how to find faults etc.<BR> <BR>Just a small transatlantic cultural observation. :-)<BR> <BR>Alan g.<BR></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0A569.585EC990-- From alan.gauld@bt.com Mon Mar 5 11:29:59 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 11:29:59 -0000 Subject: [Tutor] GUI Apps Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F5@mbtlipnt02.btlabs.bt.co.uk> > wxPython is on the Mac? Well wxWindows claims to be. I'm assuming the Python port is too. But I'm a Tk user. Alan g. PS. In my previous post I said I was familiar with Tk on Tcl and Tk, I meant of course on Tcl and Perl... From dyoo@hkn.eecs.berkeley.edu Mon Mar 5 12:03:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 5 Mar 2001 04:03:42 -0800 (PST) Subject: [Tutor] Can't Launch IDLE from Linux System In-Reply-To: <F246CjSSOV5NMboP9ux00018139@hotmail.com> Message-ID: <Pine.LNX.4.21.0103050356130.5082-100000@c82114-a.pinol1.sfba.home.com> On Mon, 5 Mar 2001, Britt Green wrote: > I just got Mandrake 7.2 up and running. When I try to start IDLE, I > get the following error message: [lots of stuff cut out] > File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? > import _tkinter # If this fails your Python may not be configured for Tk > ImportError: No module named _tkinter [Ignore this message if you haven't compiled Python by hand.] It sounds like you'll need to enable the Tkinter module. By default, Tkinter is turned off because the Makefile doesn't know if you have Tk installed. You'll probably need to check the file "Modules/Setup" in Python's source directory, and uncomment a few lines that talk about Tk. Here's a what the Tk section of "Setup" might look like: ### # *** Always uncomment this (leave the leading underscore in!): _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ # *** Uncomment and edit to reflect where your Tcl/Tk headers are: -I/usr/include \ # *** Uncomment and edit to reflect where your X11 header files are: -I/usr/X11R6/include \ # *** Or uncomment this for Solaris: # -I/usr/openwin/include \ # *** Uncomment and edit for Tix extension only: # -DWITH_TIX -ltix4.1.8.0 \ # *** Uncomment and edit for BLT extension only: # -DWITH_BLT -I/usr/local/blt/blt8.0-unoff/include -lBLT8.0 \ # *** Uncomment and edit for PIL (TkImaging) extension only: # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ # *** Uncomment and edit for TOGL extension only: # -DWITH_TOGL togl.c \ # *** Uncomment and edit to reflect where your Tcl/Tk libraries are: -L/usr/lib \ # *** Uncomment and edit to reflect your Tcl/Tk versions: -ltk8.0 -ltcl8.0 \ # *** Uncomment and edit to reflect where your X11 libraries are: -L/usr/X11R6/lib \ # *** Or uncomment this for Solaris: # -L/usr/openwin/lib \ # *** Uncomment these for TOGL extension only: # -lGL -lGLU -lXext -lXmu \ # *** Uncomment for AIX: # -lld \ # *** Always uncomment this; X11 libraries to link with: -lX11 ### Afterwards, recompile and install, and you should be all set. This is ugly, but it's necessary for now. (Thankfully, Python 2.1 should get rid of these manual configuration issues: it will autodetect and enable most of the optional Python modules.) Hope this helps! From arcege@shore.net Mon Mar 5 12:06:31 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Mar 2001 07:06:31 -0500 (EST) Subject: [Tutor] Read - Only Text? In-Reply-To: <01030409325106.04879@shecom> from Tim Johnson at "Mar 4, 2001 9:29:35 am" Message-ID: <E14Ztl1-0002Go-00@nautilus.shore.net> > Hi: > I need to set up a widget that : > > 1)Displays text > 2)Allows copy and paste > 3)But does "not" allow editing > > Question: I can't find a way to set the TKinter Text widget to > read - only. That is, not editable. > > Is there a way? > If not, can someone recommend an alternative? About the "best" way (which I've still found some problems with) is to use a Text widget and to unbind the key events in the Text "class". This is fairly drastic, because it will apply the change to all Text widgets ("class" here is a GUI term, not Python's classes). The reason this has to be done is because Tk has a multilevel event binding: first the widget's specific binding, then the class's binding. You could remove or override the key bindings (<KeyPress>, <KeyRelease>) on the widget, but the classes bindings would still be there. How I've removed them is: master.unbind_class("Text", "<Return>") master.unbind_class("Text", "<Any-KeyPress>") master.unbind_class("Text", "<Any-KeyRelease>") textwid = Text(master, ...) Notice that I don't use the widget itself to unbind the Text class. It is a global change, so it can work on just about any widget. After this you may bind more events to the widget itself. But, the issue is that this will make the change to ALL Text widgets in your application, not just the one you create. You might want to look at my Xmore application where I do this (with one bug on the ^o key that I never figured out, which does modify the text). Good luck, -Arcege <URL: http://www.shore.net/~arcege/python/Xmore.py> -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From scarblac@pino.selwerd.nl Mon Mar 5 12:17:09 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 5 Mar 2001 13:17:09 +0100 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F4@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Mon, Mar 05, 2001 at 11:26:19AM -0000 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F4@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010305131709.A7316@pino.selwerd.nl> On Mon, Mar 05, 2001 at 11:26:19AM -0000, alan.gauld@bt.com wrote: > > I would welcome some comments from anyone as to the > > comparative advantages of the following > > > type(mystr) == types.StringType > > This works best if you are checkjing for type several > times since the import overhead only gets called once. > > > > type(mystr) == type("") > > This is better if you only do it once since the extra > function call is probably faster than importing the > type module. Since type has to return a Type itself, I bet it also imports the type module itself (or the equivalent in C). It's not just a function call, it has to decide what type 'mystr' is, and then it has to decide what type "" is. *fiddle with profiler* Hmm, oddly enough, the second is a lot faster, even if the import only happens once for 500,000 iterations. So much for reasoning about efficiency :). I still don't like the way 'type(mystr) == type("")' looks, and I don't think decisions like this should be made based on speed (after all, why not use C if you want to do premature optimization...), but whatever. -- Remco Gerlich From alan.gauld@bt.com Mon Mar 5 11:37:33 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 11:37:33 -0000 Subject: [Tutor] software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F6@mbtlipnt02.btlabs.bt.co.uk> > > Does anyone know of a good scource on how to design > programs before you start programming? Hmm, I'm about to hijack a thread that was already only marginally Python related... maybe replies to me privately would be in order? > professionals and academics may have different opinions, it > appears that it is the kinda thing you just get a feel for. I agree about the process. But a good notation can help capture the design concisely and identify flaws. Now there are many notations available for software engineers but mainly they come with an accompanying methodology(*) which is usually overkill for small/medium sized projects. I have long had the notion to write a book capturing just the notations and describing what each is good for (things like flow charts, data flows, entity diagrams, state charts, herring bones, and the whole UML set of diagrams etc). A small case study for each one too. But definitely no methodologies, just a description of the tool and how to use it. What do people think? Is there a need/market for such a book amongst practicing programmers? Alan g. From arcege@shore.net Mon Mar 5 12:59:41 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Mar 2001 07:59:41 -0500 (EST) Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <20010305131709.A7316@pino.selwerd.nl> from Remco Gerlich at "Mar 5, 2001 1:17: 9 pm" Message-ID: <E14ZuaT-0003Qw-00@nautilus.shore.net> > On Mon, Mar 05, 2001 at 11:26:19AM -0000, alan.gauld@bt.com wrote: > > > I would welcome some comments from anyone as to the > > > comparative advantages of the following > > > > type(mystr) == types.StringType > > > > This works best if you are checkjing for type several > > times since the import overhead only gets called once. > > > > > > type(mystr) == type("") > > > > This is better if you only do it once since the extra > > function call is probably faster than importing the > > type module. > > Since type has to return a Type itself, I bet it also imports the type > module itself (or the equivalent in C). It's not just a function call, it > has to decide what type 'mystr' is, and then it has to decide what type "" is. Actually, no. There is an ob_type field in the PyObject structure (the C data structure for all Python objects). This is what is returned by the type() function. The types module will basically retrieve these values for each built-in data type. The built-in type() function would likely be much faster than a reference into a module. > *fiddle with profiler* > > Hmm, oddly enough, the second is a lot faster, even if the import only > happens once for 500,000 iterations. So much for reasoning about efficiency > :). > > I still don't like the way 'type(mystr) == type("")' looks, and I don't > think decisions like this should be made based on speed (after all, why not > use C if you want to do premature optimization...), but whatever. I agree. Myself, I find 'type(mystr) is types.StringType' and 'isinstance(mystr, types.StringType)' far more clear than 'type(mystr) is type("")' -Arcege PS: The type objects are unique so using the identity (is, is not) operators will be faster than the equivalence (==,!=,<>) operators. And in terms of style, "is" is more clear than "==", for me anyway. -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From livelikemad@yahoo.com Mon Mar 5 14:55:08 2001 From: livelikemad@yahoo.com (Chris McCormick) Date: Mon, 5 Mar 2001 06:55:08 -0800 (PST) Subject: [Tutor] Re; Making a text box read-only. Message-ID: <20010305145508.73949.qmail@web10509.mail.yahoo.com> Tim, I haven't treid this yet, but there is a pretty good explanation of text box attributes at the following address: http://www.pythonware.com/library/tkinter/introduction/x7931-patterns.htm Looks like you might need to set state attribute: text.config(state=NORMAL) Normal is default, and will allow entry. text.config(state=DISABLED) Disabled will not allow typing in the box. As for copying and pasting? I don't know. But look at the page, play around with it, and let us know. :-) While we're at it, I'm stuck with my own text box problem. I know this has ot be simple, but I can't find it in any of the Tkinter docs I have. **How do I grab the contents of the box?** I'm writing a notes program. I want to have a button that will set off a function to grab the text in the box and input it into a text file. What is the name of the data structure that contains the information typed into the box? It's probably a list full of individual lines.... Hope that helps, and maybe someone will answer my piggyback question. :-) - Chris __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From sthickey@juno.com Mon Mar 5 16:20:15 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Mon, 5 Mar 2001 08:20:15 -0800 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs Message-ID: <20010305.082016.-431197.1.sthickey@juno.com> 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. ----__JNP_000_52c0.07ef.324a Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Alan Gauld wrote: This works best if you are checkjing for type several times since the import overhead only gets called once. > > type(mystr) == type("") This is better if you only do it once since the extra function call is probably faster than importing the type module. ______ Am I misunderstanding something? If you enter: "import type" and hit return, are you not adding only a pointer to the file 'type.py'? I ask this, because, after having written 'import type', you have to instantiate a function in type.py by using the referrent preface -- 'type.' in front of the function name, before you can use the function. Secondly, when using IDLE, I noticed that I can use the function 'type' without an 'import type' command. Is this something in IDLE, or is 'type' a preferred function that is contained inside the Python executable? Of course, I am working on Windows (yech) and so do not know what the 'REAL WORLD' viewpoint is! So what's the Overhead for this? If you enter 'from type import *' then, I think, you would have the overhead of each function in type.py being taken into Ram. Stevenson Hickey ----__JNP_000_52c0.07ef.324a Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR></HEAD> <BODY bottomMargin=3D0 leftMargin=3D3 rightMargin=3D3 topMargin=3D0> <DIV></DIV> <DIV>Alan Gauld wrote:</DIV> <DIV> </DIV> <DIV> <DIV>This works best if you are checkjing for type several <BR>times since = the=20 import overhead only gets called once.</DIV> <DIV> </DIV> <DIV>> > type(mystr) =3D=3D type("") </DIV> <DIV> </DIV> <DIV>This is better if you only do it once since the extra <BR>function = call is=20 probably faster than importing the <BR>type module.</DIV> <DIV> </DIV> <DIV>______</DIV> <DIV> </DIV> <DIV>Am I misunderstanding something?</DIV> <DIV> </DIV> <DIV>If you enter: "import type" and hit return, are you not = adding=20 only a pointer to the file 'type.py'?</DIV> <DIV> </DIV> <DIV>I ask this, because, after having written 'import type', you = have to=20 instantiate a function in type.py by using the referrent preface --=20 'type.' in front of the function name, before you can use the=20 function.</DIV> <DIV> </DIV> <DIV>Secondly, when using IDLE, I noticed that I can use the function 'type= '=20 without an 'import type' command. Is this something in IDLE, or is '= type'=20 a preferred function that is contained inside the Python executable? = Of=20 course, I am working on Windows (yech) and so do not know what the 'REAL = WORLD'=20 viewpoint is!</DIV> <DIV> </DIV> <DIV>So what's the Overhead for this?</DIV> <DIV> </DIV> <DIV>If you enter 'from type import *' then, I think, you would have = the=20 overhead of each function in type.py being taken into Ram. </DIV> <DIV> </DIV> <DIV>Stevenson Hickey</DIV> <DIV> </DIV> <DIV> </DIV></DIV></BODY></HTML> ----__JNP_000_52c0.07ef.324a-- From tim@johnsons-web.com Mon Mar 5 16:56:00 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 5 Mar 2001 07:56:00 -0900 Subject: [Tutor] Read - Only Text? References: <E14Ztl1-0002Go-00@nautilus.shore.net> Message-ID: <01030508034900.01151@shecom> Hi Michael: On Mon, 05 Mar 2001, Michael P. Reilly wrote: <snip> > > About the "best" way (which I've still found some problems with) is to > use a Text widget and to unbind the key events in the Text "class". > This is fairly drastic, because it will apply the change to all Text > widgets ("class" here is a GUI term, not Python's classes). The reason > this has to be done is because Tk has a multilevel event binding: first > the widget's specific binding, then the class's binding. You could > remove or override the key bindings (<KeyPress>, <KeyRelease>) on the > widget, but the classes bindings would still be there. > > How I've removed them is: > master.unbind_class("Text", "<Return>") > master.unbind_class("Text", "<Any-KeyPress>") > master.unbind_class("Text", "<Any-KeyRelease>") > textwid = Text(master, ...) =========================================================== I am unclear from the code above what class "master" is instantiated from. Is it the main Tk() object? =========================================================== [In time crunch today, so don't have time to experiment 'til evening :>) ] > Notice that I don't use the widget itself to unbind the Text class. It > is a global change, so it can work on just about any widget. After > this you may bind more events to the widget itself. > > But, the issue is that this will make the change to ALL Text widgets in > your application, not just the one you create. > > You might want to look at my Xmore application where I do this (with > one bug on the ^o key that I never figured out, which does modify the > text). I have downloaded Xmore and will look at it more today. Nice stuff, it's going to be good code to review!! =============== Thanks Michael! =============== -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Mon Mar 5 17:05:27 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 5 Mar 2001 08:05:27 -0900 Subject: [Tutor] Read - Only Text? References: <Pine.LNX.4.21.0103041853090.944-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <01030508082901.01151@shecom> Hi Danny: On Sun, 04 Mar 2001, Danny Yoo wrote: > Has anyone answered your question yet? I haven't found a boolean that > makes it uneditable yet. I got some good stuff back from Michael Reilly. I'll review later today when I have time > I've been looking at the Message widget, which I thought would be perfect. Hey, I'm glad you brought that up. I will check that out as well.... > However, I can't seem to do copy and paste against it. *sigh* Close, but > not close enough. I'll read and experiment some more, and if I find > anything, I'll email again about this. Thank you !! -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From arcege@shore.net Mon Mar 5 17:14:07 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Mar 2001 12:14:07 -0500 (EST) Subject: [Tutor] Read - Only Text? In-Reply-To: <01030508034900.01151@shecom> from Tim Johnson at "Mar 5, 2001 7:56: 0 am" Message-ID: <E14ZyYh-0003ba-00@nautilus.shore.net> > Hi Michael: > On Mon, 05 Mar 2001, Michael P. Reilly wrote: > <snip> > > > > About the "best" way (which I've still found some problems with) is to > > use a Text widget and to unbind the key events in the Text "class". > > This is fairly drastic, because it will apply the change to all Text > > widgets ("class" here is a GUI term, not Python's classes). The reason > > this has to be done is because Tk has a multilevel event binding: first > > the widget's specific binding, then the class's binding. You could > > remove or override the key bindings (<KeyPress>, <KeyRelease>) on the > > widget, but the classes bindings would still be there. > > > > How I've removed them is: > > master.unbind_class("Text", "<Return>") > > master.unbind_class("Text", "<Any-KeyPress>") > > master.unbind_class("Text", "<Any-KeyRelease>") > > textwid = Text(master, ...) > =========================================================== > I am unclear from the code above what class "master" is instantiated from. > Is it the main Tk() object? > =========================================================== It won't matter what class, it is part of the general "Misc" add-on class in Tkinter. It could be Tk, Toplevel, Frame, Button, etc. Someone else mentioned the "state=DISABLED" attribute. This will make a widget fully read-only.. but also unresponsive to cut-and-paste keystrokes (Ctrl-X, Ctrl-C, Ctrl-V) because it prevents handling of key and mouse button events. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From pdiaz88@terra.es Mon Mar 5 15:51:00 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 5 Mar 2001 16:51:00 +0100 Subject: [Tutor] re: software design In-Reply-To: <002801c0a56d$f0708c60$80c8a418@jam.rr.com> References: <002801c0a56d$f0708c60$80c8a418@jam.rr.com> Message-ID: <01030516510001.00337@tajo> Hi, As computer engineer student I am, I have to told you what my teachers have told me thousand of times: flow charts are not enougth. They are obsolete. They are not suitable for large projects. They don't represent well data hidding. My advice is to forget them Instead, take a good book of software design (I don't have here my class notes, but If you want I can send you some recomended bibliography from my Data Estructures class). Maybe learning UML could help. Granted that you plan to design & implement a mid-large software piece. If not, maybe you could do with flow diagrams :) Cheers Pedro On Monday 05 March 2001 13:15, Jason Drake wrote: > > Hey... related to the software design resources question, does anyone know > of any resources that could point someone in the right direction for > writing flow charts that others would be able to understand? I seem to > remember flow chart symbols having specific meanings, but for the life of > me, I can't remember more than maybe one or two from learning them in > junior high. > > TIA, > > Jay D ---------------------------------------- Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1" Content-Transfer-Encoding: quoted-printable Content-Description: ---------------------------------------- From amoreira@mercury.ubi.pt Mon Mar 5 16:35:45 2001 From: amoreira@mercury.ubi.pt (Jose Amoreira) Date: Mon, 05 Mar 2001 16:35:45 +0000 Subject: [Tutor] Re; Making a text box read-only. References: <20010305145508.73949.qmail@web10509.mail.yahoo.com> Message-ID: <3AA3C061.EAF20DAC@mercury.ubi.pt> Hi. You can get the contents of a text widget using the Text.get(start_index,end_index) method. The first char in the text widget has an index line.col='1.0'; the last one's index is END. Here follows a sample interpreter session: pandora:exam$ python Python 2.0 (#5, Jan 22 2001, 11:06:56) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> from Tkinter import * >>> r=Tk() >>> t=Text(r) >>> t.pack() >>> #type some garbage in the text widget... ... >>> t.get('1.0',END) "hello, how are you?\012I'm fine thank you.\012\012" >>> print t.get('1.0',END) hello, how are you? I'm fine thank you. >>> ^D I think that it is also possible to use Tkinter's StringVar class to get the contents of a text (or entry) widget (and to update it automatically), but I really don't know exactly how it's done. Cheers, Ze Amoreira amoreira@mercury.ubi.pt Chris McCormick wrote: > [...] > While we're at it, I'm stuck with my own text box > problem. I know this has ot be simple, but I can't > find it in any of the Tkinter docs I have. **How do I > grab the contents of the box?** > > I'm writing a notes program. I want to have a button > that will set off a function to grab the text in the > box and input it into a text file. What is the name > of the data structure that contains the information > typed into the box? It's probably a list full of > individual lines.... > > Hope that helps, and maybe someone will answer my > piggyback question. :-) > > - Chris From DOUGS@oceanic.com Mon Mar 5 18:00:30 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Mon, 5 Mar 2001 08:00:30 -1000 Subject: [Tutor] Re: importing type Message-ID: <8457258D741DD411BD3D0050DA62365907A699@huina.oceanic.com> [Alan Gauld wrote:] >> This works best if you are checkjing for type several >> times since the import overhead only gets called once. >>> type(mystr) == type("") >> This is better if you only do it once since the extra >> function call is probably faster than importing the >> type module. [Stevenson M Hickey asked:] > Am I misunderstanding something? > If you enter: "import type" and hit return, are you not > adding only a pointer to the file 'type.py'? No, as I understand it, the import function reads the file and does a byte-compile to turn it in to Python's op-code representation. It then stores it in the same way it does the program it was called from, except... > I ask this, because, after having written 'import type', > you have to instantiate a function in type.py by using the > referrent preface -- 'type.' in front of the function name, > before you can use the function. .. it needs to be able to distinguish it from other imported or main module functions. The 'type.' in this case is just a reference like almost everything else in Python. > Secondly, when using IDLE, I noticed that I can use the > function 'type' without an 'import type' command. Is this > something in IDLE, or is 'type' a preferred function that > is contained inside the Python executable? Of course, I am > working on Windows (yech) and so do not know what the 'REAL > WORLD' viewpoint is! I don't happen to have IDLE set up right now so I can't directly answer this question. Notwithstanding that Windows is as real world as it gets, you can explore. Use the 'dir()' function in each environment and compare the results. When I do it from a direct interpreter session on Windows it looks like this: D:\PYTHON>python ActivePython 2.0, build 202 (ActiveState Tool Corp.) based on Python 2.0 (#8, Oct 19 2000, 11:30:05) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> dir() ['__builtins__', '__doc__', '__name__'] >>> dir("__builtins_") ['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'i ndex', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isuppe r', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', ' rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'tra nslate', 'upper'] >>> It doesn't looke like 'type' is there. Maybe in the IDLE environment it is already imported to make IDLE work. Since there seems to be a difference, I'd suggest getting in the habit of importing what you need just for portability sake. > So what's the Overhead for this? Ultimately the question comes down to, does my program run fast enough. In all that I've ever done with Python it has never been slow enough for me to be concerned about optimizing out such things as imports. > If you enter 'from type import *' then, I think, you would > have the overhead of each function in type.py being taken into Ram. I think it is more or less the same with the exception that now you lose the name referenceing ability. The above is generally considered _BAD_ in a Python module. The exception is libraries like Tkinter that are designed for it. About the only time you should be using the import star form is in an interpretive session where you are exploring a libraries functions. -Doug- From alan.gauld@bt.com Mon Mar 5 16:31:09 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 16:31:09 -0000 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F9@mbtlipnt02.btlabs.bt.co.uk> > Since type has to return a Type itself, I bet it also > imports the type module itself Not necessarily, the function returns a type object but the type module defines *names* for the different kinds of type objects. Since the type function doesn't care about the names it doesn't need to import it. And because importing it runs lots of calls to the type function it follows that importing it is slower than calling type() > *fiddle with profiler* > > the second is a lot faster, even if the import only > happens once for 500,000 iterations. Wow! but I didn't expect it to be *that* much slower... > I still don't like the way 'type(mystr) == type("")' looks, Looks a lot like C++ RTTI to me :-) Alan G. From alan.gauld@bt.com Mon Mar 5 17:52:38 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 5 Mar 2001 17:52:38 -0000 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FA@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0A59D.113023F0 Content-type: text/plain; charset="iso-8859-1" Am I misunderstanding something? If you enter: "import type" and hit return, are you not adding only a pointer to the file 'type.py'? Try this simple test: Create a module foo.py containing: # foo.py print "Hello from foo" Now create a script bar.py containing: #bar.py import foo print "hello from bar" And run bar.py.... C:\Temp>python bar.py Hello from foo hello from bar I ask this, because, after having written 'import type', you have to instantiate a function in type.py by using the referrent preface -- 'type.' in front of the function name, before you can use the function. Nope thats simply controlling the namespace not instantiating the function. Secondly, when using IDLE, I noticed that I can use the function 'type' without an 'import type' command. Is this something in IDLE, or is 'type' a preferred function that is contained inside the Python executable? type() is a function within builtins. The types(plural) module does not contain the type() function merely the type references - which are built by executing the type() function!!! [ this quickly gets confusing...] At least thats how I undertand it. Alan g. ------_=_NextPart_001_01C0A59D.113023F0 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD> <BODY bottomMargin=0 leftMargin=3 rightMargin=3 topMargin=0> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV> <DIV>Am I misunderstanding something?</DIV> <DIV> </DIV> <DIV>If you enter: "import type" and hit return, are you not adding only a pointer to the file 'type.py'?</DIV> <DIV> </DIV></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Try this simple test:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Create a module foo.py containing:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001># foo.py</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>print "Hello from foo"</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Now create a script bar.py containing:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001><FONT size=1><FONT size=1> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>#bar.py</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>import foo</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>print "hello from bar"</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001> <DIV> </DIV></SPAN></FONT></DIV></FONT></FONT></SPAN></FONT><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>And run bar.py....</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001><BR>C:\Temp>python bar.py<BR>Hello from foo<BR>hello from bar<BR></SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>I ask this, because, after having written 'import type', you have to instantiate a function in type.py by using the referrent preface -- 'type.' in front of the function name, before you can use the function.<FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001> </SPAN></FONT></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Nope thats simply controlling the namespace not instantiating the function.</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>Secondly, when using IDLE, I noticed that I can use the function 'type' without an 'import type' command. Is this something in IDLE, or is 'type' a preferred function that is contained inside the Python executable? <SPAN class=310173617-05032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV> <DIV><SPAN class=310173617-05032001></SPAN> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>type() is a function within builtins.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>The types(plural) module does not contain the type() function </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>merely the type references - which are built by executing the type() function!!!</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>[ this quickly gets confusing...]</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>At least thats how I undertand it.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Alan g.</SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0A59D.113023F0-- From bobhicks@adelphia.net Mon Mar 5 14:49:47 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Mon, 5 Mar 2001 09:49:47 -0500 Subject: [Tutor] GUI Apps Message-ID: <E14a02n-0005lF-00@mail.python.org> It may be somewhere out there but the wxPython site only has Windows and = Linux versions. - Bob On Monday, March 5, 2001, at 06:29 AM, alan.gauld@bt.com wrote: > > wxPython is on the Mac?=20 > =20 > Well wxWindows claims to be. I'm assuming the Python =20 > port is too. But I'm a Tk user.=20 > =20 > Alan g.=20 > =20 > PS. In my previous post I said I was familiar with =20 > Tk on Tcl and Tk, I meant of course on Tcl and Perl...=20 > =20 > =20 From deirdre@deirdre.net Mon Mar 5 19:56:45 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 5 Mar 2001 11:56:45 -0800 (PST) Subject: [Tutor] re: software design In-Reply-To: <01030516510001.00337@tajo> Message-ID: <Pine.LNX.4.31.0103051154060.651-100000@emperor.deirdre.org> On Mon, 5 Mar 2001, Pedro Diaz Jimenez wrote: > As computer engineer student I am, I have to told you what my teachers > have told me thousand of times: flow charts are not enougth. They are > obsolete. They are not suitable for large projects. They don't > represent well data hidding. My advice is to forget them Flow charts are bottom up design. Bottom up design is considered passe. Data flow diagrams are inherently top down. Think about it for a while and it becomes obvious why this is. What's important is how the data needs to move and transmute. The single best book on software design I've seen is "Structured Analysis and System Specification" by Tom Demarco. That's why I've gone through three copies in 20 years where all the other books sit unused on my shelf. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From bsass@freenet.edmonton.ab.ca Mon Mar 5 21:25:42 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Mon, 5 Mar 2001 14:25:42 -0700 (MST) Subject: [Tutor] Can't Launch IDLE from Linux System In-Reply-To: <F246CjSSOV5NMboP9ux00018139@hotmail.com> Message-ID: <Pine.LNX.4.33.0103051414580.15571-100000@bms> On Mon, 5 Mar 2001, Britt Green wrote: > Howdy, > > I just got Mandrake 7.2 up and running. When I try to start IDLE, I get the > following error message: > > [cheshire@C718841-B cheshire]$ idle > Traceback (most recent call last): > File "/usr/lib/python1.5/site-packages/idle/idle.py", line 2, in ? ^^^^^^^^^^^ > import PyShell > File "/usr/lib/python1.5/site-packages/idle/PyShell.py", line 12, in ? ^^^^^^^^^^^ > from Tkinter import * > File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? ^^^^^^^^^^^ ! > import _tkinter # If this fails your Python may not be configured for Tk > ImportError: No module named _tkinter > [cheshire@C718841-B cheshire]$ Python 1.5.2 comes with Mandrake, and you installed Python 2.0 yourself, right. > How can I fix this? My solution was to build and install tcl/tk8.3, then tell the py-2.0 executables to use python2.0 instead of python (the .../Tools/fixps.py script will help, but you will need to tweak it yourself). re: tcl/tk You may want to rebuild py-2.0 to use whatever 8.x of tcl/tk you have, I've heard of it being done (but don't know what to do, ottomh)... but you should still tell the py-2.0 stuff to use the python2.0 interpreter if you want 1.5.2 and 2.0 to coexist. - Bruce From pdiaz88@terra.es Mon Mar 5 19:49:23 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 5 Mar 2001 20:49:23 +0100 Subject: [Tutor] re: software design In-Reply-To: <Pine.LNX.4.31.0103051154060.651-100000@emperor.deirdre.org> References: <Pine.LNX.4.31.0103051154060.651-100000@emperor.deirdre.org> Message-ID: <01030520492300.00609@tajo> Hi, Bottom-up design is very concrete. Too much in my opinion. Think about a large project and a very common data structure used in that project. If you use bottom-up design, you let all the parts of the application know about the internals of this data struct. Thats ok until, for some reason you realize that changing that data struct from, for example to, say, a linked list improves performance in your app. Now, problem begin since you have to change code in *all* the parts of your project. And thats inadecuate (and boring :). Using top-down desing lets you specify data structs as black boxes that each one has its own, inmutable interface. Need to change the implementation of the interface?. Ok, just don't change the interface and all will be ok. Just my two cents, Cheers, Pedro P.D: Not a flame, but aren't 20 years two much for a software design book?. Methodologies have change a lot within this 20 years (Structured - OOP) On Monday 05 March 2001 20:56, Deirdre Saoirse wrote: > On Mon, 5 Mar 2001, Pedro Diaz Jimenez wrote: > > As computer engineer student I am, I have to told you what my teachers > > have told me thousand of times: flow charts are not enougth. They are > > obsolete. They are not suitable for large projects. They don't > > represent well data hidding. My advice is to forget them > > Flow charts are bottom up design. Bottom up design is considered passe. > > Data flow diagrams are inherently top down. > > Think about it for a while and it becomes obvious why this is. What's > important is how the data needs to move and transmute. > > The single best book on software design I've seen is "Structured Analysis > and System Specification" by Tom Demarco. That's why I've gone through > three copies in 20 years where all the other books sit unused on my shelf. > > -- > _Deirdre deirdre@deirdre.net http://www.deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams From deirdre@deirdre.net Mon Mar 5 21:51:40 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 5 Mar 2001 13:51:40 -0800 (PST) Subject: [Tutor] re: software design In-Reply-To: <01030520492300.00609@tajo> Message-ID: <Pine.LNX.4.31.0103051338160.651-100000@emperor.deirdre.org> On Mon, 5 Mar 2001, Pedro Diaz Jimenez wrote: > Bottom-up design is very concrete. This is why flowcharts are a bad idea. > Using top-down desing lets you specify data structs as black boxes > that each one has its own, inmutable interface. Need to change the > implementation of the interface?. Ok, just don't change the interface > and all will be ok. You still need to figure out where the data goes. That the definition changes isn't relevant. The implementation isn't the issue. How it's processed isn't the issue. Whether or not the implementation is object-oriented isn't the issue. Ultimately, what you'll have is: raw-data -> processing -> processed-data -> more processing -> final data Everything is about data transformation ultimately. Every menu changes state or performs an action -- which is a data transformation. Every command, same thing. It doesn't matter if the program is command-line or GUI, functional, imperative, threaded, object-oriented or not. For example, let me talk about a company that did a good OOD design. No data flow, but lots of flowcharts. They're a big-name consulting firm that you see billboards for and they did the project for $AUTO_MANUFACTURER, where I was a sysadmin and analyst. But they didn't do a data flow diagram. So, they put together pieces that were themeslves well-designed. But they didn't solve the problems. Why? No data flow diagram for the system. The data didn't flow THROUGH the system correctly and there were problems. $AUTO_MANUFACTURER needed the system to work. As a result, $AUTO_MANUFACTURER was about to sue; they'd paid several million dollars for the system. They were even intending on rewriting from scratch. I got everyone to agree to do a data flow diagram, where the flaws in the design and implementation were seen -- 3 years after the fact. So now they all have copies of the book that saved both of them from a multi-million dollar suit. And, in three months, they had a working system where they hadn't for three years. > P.D: Not a flame, but aren't 20 years two much for a software design book?. > Methodologies have change a lot within this 20 years (Structured - OOP) Maybe you should read the book. (There were good OOD books in 1975 fwiw) OOD does not change the fact that data still flows through the system. :) The fact is that if you look at where the data needs to go and what transformations are needed to the data, you have a top-down design. It doesn't matter if you use OOD or any other kind of programming language. It's a meta-design. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From dsh8290@rit.edu Mon Mar 5 21:53:40 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 16:53:40 -0500 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <E14ZuaT-0003Qw-00@nautilus.shore.net>; from arcege@shore.net on Mon, Mar 05, 2001 at 07:59:41AM -0500 References: <20010305131709.A7316@pino.selwerd.nl> <E14ZuaT-0003Qw-00@nautilus.shore.net> Message-ID: <20010305165340.A121@harmony.cs.rit.edu> On Mon, Mar 05, 2001 at 07:59:41AM -0500, Michael P. Reilly wrote: [snip] | | PS: The type objects are unique so using the identity (is, is not) | operators will be faster than the equivalence (==,!=,<>) operators. | And in terms of style, "is" is more clear than "==", for me anyway. I have heard that == checks identity before checking equality since an object must be equal to itself. (unless you contrive a not very useful comparison function ;-)) -D From dsh8290@rit.edu Mon Mar 5 21:53:56 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 16:53:56 -0500 Subject: [Tutor] Type Checking:/High-Jacking Reserved Words In-Reply-To: <01030408264800.04879@shecom>; from tim@johnsons-web.com on Sun, Mar 04, 2001 at 08:16:06AM -0900 References: <Pine.LNX.4.21.0103032006190.850-100000@c82114-a.pinol1.sfba.home.com> <01030408264800.04879@shecom> Message-ID: <20010305165356.B121@harmony.cs.rit.edu> On Sun, Mar 04, 2001 at 08:16:06AM -0900, Tim Johnson wrote: | I would welcome some comments from anyone as to the | comparative advantages of the following | > type(mystr) == types.StringType | as opposed to | > type(mystr) == type('string'): | because the first method necessitates importing another | module: re: more "overhead". I also prefer the first form, even though I didn't know about the types module until now (I haven't needed it yet). I was idly wondering about checking the type of instance objects and the overhead of creating a new instance. Take for example, class Foo : def __init__( self ) : sleep( 50000 ) # take some time initing the object ;-) obj = Foo() if type( obj ) is type( Foo() ) : print "matches" This would take execessive time (and maybe resources) to create an instance of Foo solely to check its type. I like the isinstance( obj , Foo ) method since it avoids this unnecessary overhead. I suppose one could also do if obj.__class__ is Foo : print "matches" but I don't think access __class__ is very clean. -D From bsass@freenet.edmonton.ab.ca Mon Mar 5 22:19:59 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Mon, 5 Mar 2001 15:19:59 -0700 (MST) Subject: [Tutor] Re: importing type In-Reply-To: <8457258D741DD411BD3D0050DA62365907A699@huina.oceanic.com> Message-ID: <Pine.LNX.4.33.0103051515070.15571-100000@bms> On Mon, 5 Mar 2001, Doug Stanfield wrote: <...> > results. When I do it from a direct interpreter session on Windows it looks > like this: > > D:\PYTHON>python > ActivePython 2.0, build 202 (ActiveState Tool Corp.) > based on Python 2.0 (#8, Oct 19 2000, 11:30:05) [MSC 32 bit (Intel)] on > win32 > Type "copyright", "credits" or "license" for more information. > >>> dir() > ['__builtins__', '__doc__', '__name__'] > >>> dir("__builtins_") > ['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs', > 'find', 'i > ndex', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', > 'isuppe > r', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', > 'rjust', ' > rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', > 'tra > nslate', 'upper'] > >>> > > It doesn't looke like 'type' is there. Maybe in the IDLE environment it is > already imported to make IDLE work. Since there seems to be a difference, > I'd suggest getting in the habit of importing what you need just for > portability sake. Very odd... ActivePython 2.0, build 202 (ActiveState Tool Corp.) based on Python 2.0 (#1, Oct 19 2000, 12:45:38) [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 Type "copyright", "credits" or "license" for more information. >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'EOFError', <...> 'slice', 'str', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] >>> ...and... Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'EOFError', <...> 'str', 'tuple', 'type', 'vars', 'xrange'] >>> - Bruce From dsh8290@rit.edu Mon Mar 5 22:33:43 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 17:33:43 -0500 Subject: [Tutor] GUI Apps In-Reply-To: <e5.3198f44.27d33ce1@aol.com>; from Sascharrer@aol.com on Sun, Mar 04, 2001 at 01:38:25AM -0500 References: <e5.3198f44.27d33ce1@aol.com> Message-ID: <20010305173343.C121@harmony.cs.rit.edu> On Sun, Mar 04, 2001 at 01:38:25AM -0500, Sascharrer@aol.com wrote: | Hi, there! | | Is it better to use Tkinter or wxPython for creating GUI-Applications with | Python? Whichever one suits you better. I know, not a very good answer, but it's the most accurate one. | Which of them is quicker? Don't know. Doesn't really matter much overall. | Why is Tkinter the standard graphics library for Python? Tkinter has been around and is on a lot of platforms. Personally, I hate the way the widgets look. I think Tk is ugly. I think wxPython looks a lot better, (sometimes, I don't like the Motif look either). wxPython has the advantage for users of appearing just like native applications since it is a Python wrapper for a C++ wrapper for the native toolkit. Coding style is also significant when choosing a toolkit. I like the GTK style of coding (widget hierarchy, the functions to manipulate the widgets) quite a bit. I also like the way GTK handles layout of widgets, and libglade is very cool for fast development and easy changes. I haven't gotten very involved with wxPython yet so I don't know if I can work well with it's layout scheme. (I have used Swing and am constantly fighting to get the windows to look halfway decent) Other than describing some of the differences between the toolkits and various things that I like/dislike I can't do much for helping you decide on a toolkit. If you can provide some more requirements or preferences for your own development, maybe we can provide more details regarding the various toolkits available to python programmers. -D From deirdre@deirdre.net Mon Mar 5 22:40:01 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 5 Mar 2001 14:40:01 -0800 (PST) Subject: [Tutor] GUI Apps In-Reply-To: <20010305173343.C121@harmony.cs.rit.edu> Message-ID: <Pine.LNX.4.31.0103051439330.2043-100000@emperor.deirdre.org> On Mon, 5 Mar 2001, D-Man wrote: > | Why is Tkinter the standard graphics library for Python? > > Tkinter has been around and is on a lot of platforms. More specifically, it's available on more platforms than any other toolkit. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From dsh8290@rit.edu Mon Mar 5 22:44:09 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 17:44:09 -0500 Subject: [Tutor] Can't Launch IDLE from Linux System In-Reply-To: <F246CjSSOV5NMboP9ux00018139@hotmail.com>; from britt_green@hotmail.com on Mon, Mar 05, 2001 at 03:43:00AM -0800 References: <F246CjSSOV5NMboP9ux00018139@hotmail.com> Message-ID: <20010305174409.D121@harmony.cs.rit.edu> On Mon, Mar 05, 2001 at 03:43:00AM -0800, Britt Green wrote: | Howdy, | | I just got Mandrake 7.2 up and running. When I try to start IDLE, I get the | following error message: Mandrake is rpm-based right? Try and find a mandrake rpm for Tkinter. If you go to the BeOpen site, I believe they have source rpms for Python 2.0. Get it and run rpm --rebuild NameOfSourceRpm.srpm to build rpms of python and tkinter specifically for your system. Then install them. I always liked to build the srpms when I was running a RedHat system. Now I use Debain ;-). ( $ apt-get install python2-tk apt will resolve all dependencies such as the interpreter itself ) -D From todd@slideburn.com Mon Mar 5 22:50:45 2001 From: todd@slideburn.com (Todd Chapman) Date: Mon, 5 Mar 2001 15:50:45 -0700 Subject: [Tutor] Can't Launch IDLE from Linux System References: <F246CjSSOV5NMboP9ux00018139@hotmail.com> <20010305174409.D121@harmony.cs.rit.edu> Message-ID: <00c101c0a5c6$be03c680$e801a8c0@tchapman> Hi all, I'm new to this list and have been working with python for a short time now. Still pretty much a novice but about to embark on a mission of sorts with a python application project. Anyhow... I lost the original message, but I had the same errors come up and I HAD tkinter on my machine. I had to edit the setup file to uncomment and edit the proper lines for tkinter support to be built. The installation readme that comes with python is more concise that I am, but it should be in there. You may want to make sure that you have TCL/TK first as D-Man suggests by looking into your (/usr/lib or /usr/local/lib) directories. The setup file will want those paths anyway. Todd ----- Original Message ----- From: "D-Man" <dsh8290@rit.edu> To: <tutor@python.org> Sent: Monday, March 05, 2001 3:44 PM Subject: Re: [Tutor] Can't Launch IDLE from Linux System > On Mon, Mar 05, 2001 at 03:43:00AM -0800, Britt Green wrote: > | Howdy, > | > | I just got Mandrake 7.2 up and running. When I try to start IDLE, I get the > | following error message: > > Mandrake is rpm-based right? Try and find a mandrake rpm for Tkinter. > If you go to the BeOpen site, I believe they have source rpms for > Python 2.0. Get it and run > > rpm --rebuild NameOfSourceRpm.srpm > > to build rpms of python and tkinter specifically for your system. > Then install them. > > I always liked to build the srpms when I was running a RedHat system. > Now I use Debain ;-). > > ( > $ apt-get install python2-tk > > apt will resolve all dependencies such as the interpreter itself > ) > > -D > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dsh8290@rit.edu Mon Mar 5 22:59:35 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 17:59:35 -0500 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs In-Reply-To: <20010305.082016.-431197.1.sthickey@juno.com>; from sthickey@juno.com on Mon, Mar 05, 2001 at 08:20:15AM -0800 References: <20010305.082016.-431197.1.sthickey@juno.com> Message-ID: <20010305175934.E121@harmony.cs.rit.edu> FYI, [ when replying to the digest, it is good to change the subject to something meaningful, otherwise some people (like me) have a tendency to kill-thread it without reading it ] [ also, plain-text is better than HTML mail, this was wrapped horridly and I had to sort through this to find what you wrote as opposed to what you replied to ] On Mon, Mar 05, 2001 at 08:20:15AM -0800, Stevenson M Hickey wrote: | Am I misunderstanding something? If you enter: | "import type" and hit return, are you not adding only a pointer to the | file 'type.py'? The import statement locates the file. It then parses and byte-compiles the file (unless it has already been byte-compiled). It then executes any file-level statements in the file. The module is loaded into memory at this time. Also, imports only actually happen once. If a module is already loaded, the import simply creates a name in the current namespace that refers to the already loaded module. | I ask this, because, after having written 'import | type', you have to instantiate a function in type.py by using the | referrent preface -- 'type.' in front of the function name, before you | can use the function. You didn't instantiate the function then, it was instantiated when the import reached the "def" statement. Prefixing module members with the module name simply tells the interpreter which module the name you want should be found in. Take the following two files/modules for example : # foo.py def func() : print "This is foo" # bar.py def func() : print "This is bar" Now try to use these modules : import foo import bar func() # which func?? # actually, there is no func in the current namespace so this # is a NameError foo.func() # prints "This is foo" bar.func() # prints "This is bar" If you were to use the evil from import * syntax, you would have problems : from foo import * from bar import * func() # prints "This is bar" # now I can't get "This is foo" since I overwrote the reference | Secondly, when using IDLE, I noticed that I can | use the function 'type' without an 'import type' command. Is this | something in IDLE, or is 'type' a preferred function that is contained | inside the Python executable? Of course, I am working on Windows | (yech) and so do not know what the 'REAL WORLD' viewpoint is! So The function type() is in a builtin function. It is in the module __builtins__. You don't do anything to import this module. The types module is different. It is separate, and must be imported in order to use it. Also, the 'types' module doesn't define any functions, just constants that can be useful. | what's the Overhead for this? If you enter 'from type import *' then, | I think, you would have the overhead of each function in type.py being | taken into Ram. Overhead isn't something to worry about unless your program is too slow. from types import * is considered bad (actually, any from import *) because of the namespace clashing issue as I demonstrated above. Each function is loaded into RAM when the module is imported regardless of whether a "normal" or a from-* import is performed. The from-* form is slower only because the interpreter must iterate over each name in the module and insert it into the current module. The extra memory usage is only slightly higher than 4 bytes for each name (not very significant) (a pointer, plus the other fields in a PyObject). -D From dsh8290@rit.edu Mon Mar 5 23:13:32 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 5 Mar 2001 18:13:32 -0500 Subject: [Tutor] Read - Only Text? In-Reply-To: <E14Ztl1-0002Go-00@nautilus.shore.net>; from arcege@shore.net on Mon, Mar 05, 2001 at 07:06:31AM -0500 References: <01030409325106.04879@shecom> <E14Ztl1-0002Go-00@nautilus.shore.net> Message-ID: <20010305181332.F121@harmony.cs.rit.edu> On Mon, Mar 05, 2001 at 07:06:31AM -0500, Michael P. Reilly wrote: | > Hi: | > I need to set up a widget that : | > | > 1)Displays text | > 2)Allows copy and paste | > 3)But does "not" allow editing | > | > Question: I can't find a way to set the TKinter Text widget to | > read - only. That is, not editable. | > | > Is there a way? | > If not, can someone recommend an alternative? | | About the "best" way (which I've still found some problems with) is to | use a Text widget and to unbind the key events in the Text "class". Ugh. Swing and GTK have methods/functions like field = javax.swing.JTextField( ) file.setEditable( 0 ) (you can use Swing if you use the Jython interpreter) I don't recall off-hand the exact name of the GTK function. Just some info ... -D From jdrake@jam.rr.com Tue Mar 6 02:41:10 2001 From: jdrake@jam.rr.com (Jason Drake) Date: Mon, 5 Mar 2001 20:41:10 -0600 Subject: [Tutor] software design References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F6@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <002901c0a5e7$039b1f20$80c8a418@jam.rr.com> Where do I send the check? Jay ---------- one too. But definitely no methodologies, > just a description of the tool and how to use it. > > What do people think? Is there a need/market for such a book > amongst practicing programmers? > > Alan g. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Tue Mar 6 10:06:02 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 6 Mar 2001 10:06:02 -0000 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FB@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0A625.0CBB34D0 Content-type: text/plain; charset="iso-8859-1" I am unsure, as to whether your answer really answers my question. It depends upon how Python was designed. Yes and I admit I'm only passing on my understanding which is not intimate with the internals but based on reading books and news articles... The fact that running bar.py produces 'hello from foo' in it does not make it certain that a pointer is not used and that Python simply follows the pointer to foo.py and puts it in. True, but it does show that foo gets executed not just set up a pointer. In fact if you think about how Python uses names/variabnles/references it might make more sense. Python creates a new variable name when an assignment occurs, thus: baz = [] creates a new name baz pointing at an empty list. For modules assignment is not appropriate so wwe use import as a mechanism for creating names thus: import foo creates a new name foo But it also gives indirect access to all the names in foo. But those names won't exist in Python until their definitions(class, def or assignment statements) have been executed thus for the foo namespace to made available in Python the module *must* be executed on import (it could be executed on the first reference to a foo name but that's a minor nitpick, either way the entire module must be executed to create the names within it.) Is there any way that one can access the amount of RAM being used? In this way one could do the import foo and the from foo import * and see the relative amounts of Ram used. Since in both cases the module must be run I suspect there'd be no difference. The only difference is in which names Python stores in its top level dictionary (python names are all in dictionaries which is why the dir() function works as it does...) Because from foo import xxx only puts xxx into the dictionary anything else in foo's naming dictionary is not seen since foo itself is not seen. I would take your word for it, but I would like to know how Python works. As I say I'm not the expert there, wait for Tim Peters or Remco or maybe Guido himself to answer that one :-) You wrote: Nope thats simply controlling the namespace not instantiating the function. I do not understand this, can you expand on it a bit? See above... T hen, are you saying that writing 'import foo' is not creating a pointer to the file? Not as such, its creating a name entry in a dictionary, slightly different. That name entry in turn is, I believe a pointer to another dictionary of names for the foo module, not the file foo.py. Maybe a real guru could chip in here and tell us how it really works? cue Alex, Tim P, Remco et al? Alan G ------_=_NextPart_001_01C0A625.0CBB34D0 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD> <BODY bottomMargin=0 leftMargin=3 rightMargin=3 topMargin=0> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>I am unsure, as to whether your answer really answers my question. It depends upon how Python was designed.<SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Yes and I admit I'm only passing on my understanding which is not intimate with </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>the internals but based on reading books and news articles...</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><SPAN class=700034509-06032001> </SPAN> The fact that running bar.py produces 'hello from foo' in it does not make it certain that a pointer is not used and that Python simply follows the pointer to foo.py and puts it in.<SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>True, but it does show that foo gets executed not just set up a pointer.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>In fact if you think about how Python uses names/variabnles/references it might make more sense. </SPAN></FONT><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Python creates a new variable name when an assignment occurs, thus:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>baz = []</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>creates a new name baz pointing at an empty list.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>For modules assignment is not appropriate so wwe use import as a mechanism for </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>creating names thus:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>import foo</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>creates a new name foo</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>But it also gives indirect access to all the names in foo. But those names won't </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>exist in Python until their definitions(class, def or assignment statements) have </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>been executed thus for the foo namespace to made available in Python the module </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>*must* be executed on import (it could be executed on the first reference to a foo </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>name but that's a minor nitpick, either way the entire module must be executed </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>to create the names within it.)</SPAN></FONT></DIV> <DIV> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>Is there any way that one can access the amount of RAM being used? In this way one could do the import foo and the from foo import * and see the relative amounts of Ram used. <SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Since in both cases the module must be run I suspect there'd be no difference. </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>The only difference is in which names Python stores in its top level dictionary</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>(python names are all in dictionaries which is why the dir() function works as </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>it does...) Because from foo import xxx only puts xxx into the dictionary anything </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>else in foo's naming dictionary is not seen since foo itself is not seen.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>I would take your word for it, but I would like to know how Python works. <SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>As I say I'm not the expert there, wait for Tim Peters or Remco or maybe Guido himself </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>to answer that one :-)</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV>You wrote: <FONT color=#0000ff face=Arial size=2><SPAN class=310173617-05032001>Nope thats simply controlling the namespace not instantiating the function. </SPAN></FONT></DIV> <DIV> </DIV> <DIV>I do not understand this, can you expand on it a bit? <SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>See above...</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> T </FONT></SPAN>hen, are you saying that writing 'import foo' is not creating a pointer to the file? <SPAN class=700034509-06032001><FONT color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Not as such, its creating a name entry in a dictionary, slightly different.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>That name entry in turn is, I believe a pointer to another dictionary of </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>names for the foo module, not the file foo.py.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Maybe a real guru could chip in here and tell us how it really works?</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>cue Alex, Tim P, Remco et al?</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Alan G</SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0A625.0CBB34D0-- From scarblac@pino.selwerd.nl Tue Mar 6 11:02:38 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 6 Mar 2001 12:02:38 +0100 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FB@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Tue, Mar 06, 2001 at 10:06:02AM -0000 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FB@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010306120238.A9112@pino.selwerd.nl> On Tue, Mar 06, 2001 at 10:06:02AM -0000, alan.gauld@bt.com wrote: > I am unsure, as to whether your answer really answers my question. It > depends upon how Python was designed. > > Yes and I admit I'm only passing on my understanding which is not intimate > with > the internals but based on reading books and news articles... > > The fact that running bar.py produces 'hello from foo' in it does not make > it certain that a pointer is not used and that Python simply follows the > pointer to foo.py and puts it in. It's a bit hard to read your mail since I think you're replying to a personal mail, and I can't tell what was written by whom. However, your explanation is similar to the way I believe importing works; "import bar" does two things - 1) *if* module 'bar' is not loaded yet (is not present in sys.modules) then it is loaded, and executed. So it's executed, but only once. 2) A reference 'bar' to the module is put into the current namespace. In case of 'from bar import *', the contents of bar are put into the namespace instead. But why are we putting this in our own words, when you really want to know how it works exactly you have to look at the Language Reference: http://www.python.org/doc/current/ref/import.html > Maybe a real guru could chip in here and tell us how it really works? > cue Alex, Tim P, Remco et al? I'm not a 'real guru' at all, just a CS student who likes Python a lot, but I haven't even looked at internals... *You* wrote a book on it :-). -- Remco Gerlich From alan.gauld@bt.com Tue Mar 6 11:19:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 6 Mar 2001 11:19:45 -0000 Subject: [Tutor] re: software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FC@mbtlipnt02.btlabs.bt.co.uk> > On Mon, 5 Mar 2001, Pedro Diaz Jimenez wrote: > > As computer engineer student I am, I have to told you > > what my teachers have told me thousand of times: flow > > charts are not enough. This is true. > > They are obsolete. They are not suitable for large projects. This is not. The largest program I ever worked on - a mainframe billing system, written in COBOL with over 10,000,000 lines of code was all documented in flow charts at the module level. As a maintainer of a large component(about 350,000 lines) I can say it was very effective. And this was not a loing time ago it was 1998... So not obsolete, not useless either! But not sufficient. > Flow charts are bottom up design. Bottom up design is > considered passe. In some circles. OTOH many pundits have stated that the best way to do OO design is bottom up. And in an environment like Smalltalk and python with the interactive prompt to play with, bottom up makes a lot of sense. Personally I tend to draft out a top level architecture then drop straight down to the bottom level and work up from there towards my architecture. I use the prompt to experiment with algorithms, data structures etc then reflect changes as needed in the architecture layer. > Data flow diagrams are inherently top down. > > Think about it for a while and it becomes obvious > why this is. What's important is how the data needs > to move and transmute. Depends on the application environment. For business type apps its usually true but in a real time embedded system the data is usually trivial and the data flows consist of a few primitive data parameters in method calls. The work is all in the algorithms and state macjhines. Thats why SDL(a state based designmethod/notation) is so popular in the real-time/telecomms industry. Similatly when designing intensively GUI oriented apps - even something like a word processor.... > The single best book on software design I've seen is > "Structured Analysis and System Specification" by > Tom Demarco. That's why I've gone through > three copies in 20 years where all the other books sit unused > on my shelf. "Software Engineering - a Practitioners Approach" by Pressman is my bible - I buy each new edition as it comes out. Alan g. From alan.gauld@bt.com Tue Mar 6 11:29:23 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 6 Mar 2001 11:29:23 -0000 Subject: [Tutor] re: software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FD@mbtlipnt02.btlabs.bt.co.uk> > P.D: Not a flame, but aren't 20 years two much for a software > design book?. Methodologies have change a lot within this 20 years > (Structured - OOP) Methodologies haven't changed that much. New ones have appeared but the older ones are still around and valid for some areas. OO is a great advance in software engineering but it's not universally "a good thing". Indeed the functional programming school would suggest that they already have the natural successor to OO but even FP is not a universal panacea. Choosing the correct tool for the job is, and always will be, the most important skill in an engineer's armoury (to mix metaphors!). One of the greatest benefits of Python is that it doesn't dictate any particular mode of working. It offers imperative, object and functional styles to be used as the programmer deems appropriate depending on the problem at hand and his/her experience. Alan g. From ibraheem@micromuse.com Tue Mar 6 12:05:01 2001 From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed) Date: Tue, 6 Mar 2001 12:05:01 +0000 Subject: [Tutor] FAQ a day? Message-ID: <20010306120501.A18920@micromuse.com> Is there anything like the "faq-a-day" service available for Python? Kindest regards, --ibs. --------------------------------------------------------------------------- -- Ibraheem Umaru-Mohammed -- -- Email:ium@micromuse.com -- -- Micromuse Ltd, Disraeli House, 90 Putney Bridge Road, London SW18 1DA -- -- http://www.micromuse.com -- --------------------------------------------------------------------------- From scarblac@pino.selwerd.nl Tue Mar 6 13:17:04 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 6 Mar 2001 14:17:04 +0100 Subject: [Tutor] FAQ a day? In-Reply-To: <20010306120501.A18920@micromuse.com>; from ibraheem@micromuse.com on Tue, Mar 06, 2001 at 12:05:01PM +0000 References: <20010306120501.A18920@micromuse.com> Message-ID: <20010306141704.A9304@pino.selwerd.nl> On Tue, Mar 06, 2001 at 12:05:01PM +0000, Ibraheem Umaru-Mohammed wrote: > Is there anything like the "faq-a-day" service available for Python? No. I took a look with Google to see what a "faq-a-day" was, and I found http://perl.faq-by-day.org/ Looks like a nice idea, and not that hard to implement. On the other hand, it makes a lot more sense for Perl than for Python, since Perl's FAQ is a lot larger (I think). -- Remco Gerlich From ibraheem@micromuse.com Tue Mar 6 13:39:42 2001 From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed) Date: Tue, 6 Mar 2001 13:39:42 +0000 Subject: [Tutor] FAQ a day? Message-ID: <20010306133942.B19160@micromuse.com> --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline --IJpNTDwzlM2Ie8A6 Content-Type: message/rfc822 Content-Disposition: inline Date: Tue, 6 Mar 2001 13:38:27 +0000 From: Ibraheem Umaru-Mohammed <ibraheem> To: Remco Gerlich <scarblac@pino.selwerd.nl> Subject: Re: [Tutor] FAQ a day? Message-ID: <20010306133827.A19160@micromuse.com> References: <20010306120501.A18920@micromuse.com> <20010306141704.A9304@pino.selwerd.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010306141704.A9304@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Tue, Mar 06, 2001 at 02:17:04PM +0100 On Tue, Mar 06, 2001 at 02:17:04PM +0100, Remco Gerlich wrote: > On Tue, Mar 06, 2001 at 12:05:01PM +0000, Ibraheem Umaru-Mohammed wrote: > > Is there anything like the "faq-a-day" service available for Python? > > No. I took a look with Google to see what a "faq-a-day" was, and I found > http://perl.faq-by-day.org/ Exactly what I meant. Not that I used perl much, but I started looking at Perl/Python at around the same time - I read a couple of books on Python (Learning Python, Python Quick Reference etc), and skimmed very briefly through "Learning Perl", but I have to say that I have learnt a *lot* from reading FAQs, and perls way of doing it seemed attractive to me from a Python perspective. > > Looks like a nice idea, and not that hard to implement. On the other hand, > it makes a lot more sense for Perl than for Python, since Perl's FAQ is a > lot larger (I think). > I would probably say so too, I was thinking of going through some of them and coding the equivalents in Python just to firm up my experience of Python. (Don't use either at work, just studied them in my spare time) But then it occurred to me that it might already exist somewhere out there. Kindest regards, --ibs. --------------------------------------------------------------------------- -- Ibraheem Umaru-Mohammed -- -- Email:ium@micromuse.com -- -- Micromuse Ltd, Disraeli House, 90 Putney Bridge Road, London SW18 1DA -- -- http://www.micromuse.com -- --------------------------------------------------------------------------- --IJpNTDwzlM2Ie8A6-- From dsh8290@rit.edu Tue Mar 6 14:23:27 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 6 Mar 2001 09:23:27 -0500 Subject: [Tutor] new subject, but not very interesting In-Reply-To: <20010305175934.E121@harmony.cs.rit.edu>; from dsh8290@rit.edu on Mon, Mar 05, 2001 at 05:59:35PM -0500 References: <20010305.082016.-431197.1.sthickey@juno.com> <"from sthickey"@juno.com> <20010305175934.E121@harmony.cs.rit.edu> Message-ID: <20010306092326.A2343@harmony.cs.rit.edu> On Mon, Mar 05, 2001 at 05:59:35PM -0500, D-Man wrote: | | [ when replying to the digest, it is good to change the subject to | something meaningful, otherwise some people (like me) have a tendency | to kill-thread it without reading it ] | Oops, I apologize for not even following my own suggestion. I replied but forgot to change the subject before I sent it. At least I wasn't getting burned with a flame ;-). -D From dsh8290@rit.edu Tue Mar 6 14:43:09 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 6 Mar 2001 09:43:09 -0500 Subject: [Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FB@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Tue, Mar 06, 2001 at 10:06:02AM +0000 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FB@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010306094309.B2343@harmony.cs.rit.edu> If I was able to follow the discussion properly, it seems as if Alan gave rather good explanations of the issues at hand. I adjusted the indentation to show where Alan was responding to the original questions. On Tue, Mar 06, 2001 at 10:06:02AM +0000, alan.gauld@bt.com wrote: | | I am unsure, as to whether your answer really answers my question. It | depends upon how Python was designed. | | Yes and I admit I'm only passing on my understanding which is not | intimate with the internals but based on reading books and news articles... Same here. | Is there any way that one can access the amount of RAM being used? In | this way one could do the import foo and the from foo import * and see | the relative amounts of Ram used. Sure, use a profiler and get into the internals of the interpreter. This will probably (almost certainly) require a knowledge of C and a desire to see how it works ;-). Someone asked this on c.l.py a little while back. I don't remember the outcome, but it should be in the archives. | Since in both cases the module must be run I suspect there'd be no | difference. I think there is a difference, but that difference is insignificant. | The only difference is in which names Python stores in its top level | dictionary This is why I think there is a difference. Instead of having a single reference in foo.__dict__ to the function/class/whatever there is a reference in foo.__dict__ and this.__dict__ (if I may borrow the name "this" from C++/Java). There will be double the number of references, but a reference is little more that 4 bytes (as I said before, whatever space 'struct PyObject' requires) so the memory usage is insignificant. Though I suppose it may only be a PyObject* in which case it is just a duplicate pointer without the other overhead of a PyObject. To be certain about this, one would most likely need to peruse the C implementation a bit. | (python names are all in dictionaries which is why the dir() | function works as it does...) Because from foo import xxx only puts | xxx into the dictionary anything else in foo's naming dictionary is | not seen since foo itself is not seen. | | | I would take your word for it, but I would like to know how Python | works. | | As I say I'm not the expert there, wait for Tim Peters or Remco or | maybe Guido himself to answer that one :-) Same here. I also haven't looked at the C (or Java) implementation at all and have only briefly seen snippets of the C API for extending the interpreter. | Maybe a real guru could chip in here and tell us how it really | works? cue Alex, Tim P, Remco et al? As Remco said, the Reference Manual is the real authority on the subject (aside from Guido or the Timbot of course). -D From livelikemad@yahoo.com Tue Mar 6 14:50:04 2001 From: livelikemad@yahoo.com (Chris McCormick) Date: Tue, 6 Mar 2001 06:50:04 -0800 (PST) Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? Message-ID: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Hey folx, Got a weird one here. I have a little program to grow some bananas. I have a banana class. It has methods for maturing at specified intervals, displaying different bitmaps at different life stages, and spawning new plants at maturity. The program works by creating a list of the class instances: bananacount = input('How many bananas do you wanna see? ') for x in range(0, bananacount): banananame = "banana" + str(x) new_banana = flora.Banana(banananame, 0, 0) bananas.append(new_banana) The code above creates the original list. Then when bananas get propagated, we append to the list: def bananaMaker(baby_x, baby_y, banana_name, bananas): new_banana = Banana(banana_name, baby_x, baby_y) bananas.append(new_banana) So far, so good, right? It's easy to append to the list. The problem comes when I try to remove items from the list. I'm supposed to use the value of the item I want to remove. But what is the value of a class instance? If I create two bananas and then print my list, I get something like this: [<flora.banana instance at 0081168C>, <flora.banana instance at 0081144C>] How do I feed that into banana.remove(listitemvalue)? Thanks in advance for your help. We're being overrun here. - Chris PS - On the other hand, it's pretty cool to be able to say that I've crashed my computer with bananas. :-) __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From gibbs05@flash.net Tue Mar 6 15:28:44 2001 From: gibbs05@flash.net (Harry Kattz) Date: Tue, 6 Mar 2001 09:28:44 -0600 Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? References: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Message-ID: <012d01c0a652$288afba0$1cdf3040@gibbs05> Greetings Chris, I'm afraid you'll have to do this the old fashioned way. :-) Loop through looking for the object and then remove it. Since you're storing the banana name that would be a good key. For example. def RemoveBanana(Bananas, BananaName): for CurrentBanana in Bananas: if CurrentBanana.banana_name == BananaName: Bananas.remove(CurrentBanana) Return That should work. Good luck, Sam > Hey folx, > Got a weird one here. I have a little program to > grow some bananas. I have a banana class. It has > methods for maturing at specified intervals, > displaying different bitmaps at different life stages, > and spawning new plants at maturity. > The program works by creating a list of the class > instances: > > bananacount = input('How many bananas do you wanna > see? ') > for x in range(0, bananacount): > banananame = "banana" + str(x) > new_banana = flora.Banana(banananame, 0, 0) > bananas.append(new_banana) > > The code above creates the original list. Then when > bananas get propagated, we append to the list: > > def bananaMaker(baby_x, baby_y, banana_name, bananas): > new_banana = Banana(banana_name, baby_x, baby_y) > bananas.append(new_banana) > > So far, so good, right? It's easy to append to the > list. The problem comes when I try to remove items > from the list. I'm supposed to use the value of the > item I want to remove. But what is the value of a > class instance? If I create two bananas and then > print my list, I get something like this: > > [<flora.banana instance at 0081168C>, <flora.banana > instance at 0081144C>] > > How do I feed that into banana.remove(listitemvalue)? > > Thanks in advance for your help. We're being overrun > here. > > - Chris > > PS - On the other hand, it's pretty cool to be able to > say that I've crashed my computer with bananas. :-) > > __________________________________________________ > Do You Yahoo!? > Get email at your own domain with Yahoo! Mail. > http://personal.mail.yahoo.com/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From amoreira@mercury.ubi.pt Tue Mar 6 15:28:17 2001 From: amoreira@mercury.ubi.pt (Jose Amoreira) Date: Tue, 06 Mar 2001 15:28:17 +0000 Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? References: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Message-ID: <3AA50211.C30936C6@mercury.ubi.pt> Hello! You can also remove list elements by position in the list, using del: >>> lst = ['a','b','c'] >>> lst ['a', 'b', 'c'] >>> del lst[1] >>> lst ['a', 'c'] Yet another possibility is to use the list.pop(i), wich returns and deletes list[i]. Hope it helps! So long Ze amoreira@mercury.ubi.pt Chris McCormick wrote: > [...] > So far, so good, right? It's easy to append to the > list. The problem comes when I try to remove items > from the list. I'm supposed to use the value of the > item I want to remove. But what is the value of a > class instance? If I create two bananas and then > print my list, I get something like this: > > [<flora.banana instance at 0081168C>, <flora.banana > instance at 0081144C>] > > How do I feed that into banana.remove(listitemvalue)? > > Thanks in advance for your help. We're being overrun > here. > > - Chris > > PS - On the other hand, it's pretty cool to be able to > say that I've crashed my computer with bananas. :-) From sthickey@juno.com Tue Mar 6 16:27:01 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Tue, 6 Mar 2001 08:27:01 -0800 Subject: [Tutor] Re:Importing Type Message-ID: <20010306.082702.-379881.0.sthickey@juno.com> I'm a real newbie to Python, so the question of a Tkinter Text Widget is not clear to me. However, there is a rule of thumb that says: 'When you can't make your language work for you, use another language.' C++ could be used to construct a read-only text widget fairly simply. Another approach is to realize that a text widget of any type is actually something that is handled by your OS. All OS' have methods to make text read-only. Can you create a new Text Widget structure from Tkinter and add code to tell the OS that the file is read-only? I am kind of scrabbling around in the dark here, but there is definitely a faint tickle in my upper right brain quadrant that says that this is a possible direction to take. Stevenson Hickey From dyoo@hkn.eecs.berkeley.edu Tue Mar 6 16:39:47 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 08:39:47 -0800 (PST) Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? In-Reply-To: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103060826410.13334-100000@hkn.eecs.berkeley.edu> On Tue, 6 Mar 2001, Chris McCormick wrote: > So far, so good, right? It's easy to append to the list. The problem > comes when I try to remove items from the list. I'm supposed to use > the value of the item I want to remove. But what is the value of a > class instance? If I create two bananas and then print my list, I get > something like this: > > [<flora.banana instance at 0081168C>, <flora.banana > instance at 0081144C>] > > How do I feed that into banana.remove(listitemvalue)? It depends on the situation. Which kind of banana do you want to remove? If it depends on the position (for example, the last banana), we don't need to use remove(): we can use del instead: del(bananas[-1]) will remove the last banana from our bananas. Yum. remove()'s useful when we do have a value to remove. For example: ### for b in bananas: if overripe(b): badbanana = b bananas.remove(badbanana) ### should get rid of the very last banana we see in the for loop. If you can tell us the criteria of a banana you want to remove, we can point you toward the appropriate removing function. If we want to look at the other list functions, we can do this: ### >>> print dir(bananas) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] ### Not only can we remove bananas, but we can pop() them too! (This is beginning to sound weird. *grin*) pop() takes in the position of a banana in a list, and returns that particular value: ### >>> numbers = range(5) >>> numbers [0, 1, 2, 3, 4] >>> numbers.pop(0) 0 >>> numbers [1, 2, 3, 4] >>> numbers.pop(-1) 4 >>> numbers [1, 2, 3] ### and this might be useful for you. By the way, what you're looking at, > [<flora.banana instance at 0081168C>, <flora.banana instance at > 0081144C>] is the string representation of the list elements, and it doesn't look too pretty yet. An object might not have an immediately meaningful representation as a string, but Python tries hard to make one up. When Python tries to print out a list of elements, it calls the repr() "representation" function on each element of the list. If we want our representation to look nicer, we can write our own __repr__() function for bananas. The reference manual talks about these sort of special functions here: http://python.org/doc/current/ref/specialnames.html > Thanks in advance for your help. We're being overrun here. Don't go bananas. From kalle@gnupung.net Tue Mar 6 17:09:43 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 6 Mar 2001 18:09:43 +0100 Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? In-Reply-To: <20010306145004.35071.qmail@web10507.mail.yahoo.com>; from livelikemad@yahoo.com on Tue, Mar 06, 2001 at 06:50:04AM -0800 References: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Message-ID: <20010306180943.B345@apone.network.loc> [not signed due to technical difficulties] Sez Chris McCormick: > So far, so good, right? It's easy to append to the > list. The problem comes when I try to remove items > from the list. I'm supposed to use the value of the > item I want to remove. But what is the value of a > class instance? If I create two bananas and then > print my list, I get something like this: > > [<flora.banana instance at 0081168C>, <flora.banana > instance at 0081144C>] > > How do I feed that into banana.remove(listitemvalue)? >>> class Banana: ... def __init__(self, n): ... self.name = n ... >>> a = Banana("adam") >>> b = Banana("bill") >>> c = Banana("cliff") >>> bananas = [a, b, c] >>> bananas [<__main__.Banana instance at 8057008>, <__main__.Banana instance at 804b4e0>, <__main__.Banana instance at 8056e58>] >>> bananas.remove(b) >>> bananas [<__main__.Banana instance at 8057008>, <__main__.Banana instance at 8056e58>] All right. But you want to ask the user what bananas to remove? Either ask for a number: >>> i = input("Which banana shall I remove? (1-%d) " % len(bananas)) Which banana shall I remove? (1-2) 2 >>> del bananas[i-1] # -1 for offset >>> bananas [<__main__.Banana instance at 8057008>] Or a name (or something else that can be used to separate bananas): >>> s = raw_input("What banana do you want to delete? ") What banana do you want to delete? adam >>> for banana in bananas: ... if banana.name == s: ... bananas.remove(banana) ... >>> bananas [] HTH, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD From dyoo@hkn.eecs.berkeley.edu Tue Mar 6 17:09:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 09:09:28 -0800 (PST) Subject: [Tutor] read-only Tkinter Entry Widget In-Reply-To: <20010306.082702.-379881.0.sthickey@juno.com> Message-ID: <Pine.LNX.4.21.0103060845040.13334-100000@hkn.eecs.berkeley.edu> On Tue, 6 Mar 2001, Stevenson M Hickey wrote: > I'm a real newbie to Python, so the question of a Tkinter Text Widget > is not clear to me. However, there is a rule of thumb that says: > 'When you can't make your language work for you, use another > language.' C++ could be used to construct a read-only text widget > fairly simply. The only problem is that this isn't really a Python issue; it seems that expressing "read-onlyness" to a widget shouldn't be too difficult, in any language. A program in C++ would face the same issues, since we'd still be working, in one form or another, with the same interface --- Tk. When we're working with Tkinter, we're actually working with a library that's a layer on top of the Tk graphics library. > Another approach is to realize that a text widget of any type is > actually something that is handled by your OS. All OS' have methods > to make text read-only. Can you create a new Text Widget structure > from Tkinter and add code to tell the OS that the file is read-only? The OS has no jurisdiction on this; it's very much a user level problem. Hmmm... according to: http://www.hobbs.wservice.com/tcl/faqs/tk/tkfaq.html#text/readonly apparently there is a mechanism for doing this nicely. The following code appears to be another way to do it: ### from Tkinter import * root = Tk() mystr = StringVar() entry = Entry(textvariable=mystr, state=DISABLED).pack(side=LEFT) mystr.set('hello world') mainloop() ### Because the widget's disabled, it won't listen to any keys. However, it still allows copy and paste. Tim, is this what you want? Hope this helps! From deirdre@deirdre.net Tue Mar 6 17:09:39 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 6 Mar 2001 09:09:39 -0800 (PST) Subject: [Tutor] re: software design In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5FC@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <Pine.LNX.4.31.0103060905250.9639-100000@emperor.deirdre.org> On Tue, 6 Mar 2001 alan.gauld@bt.com wrote: > > Think about it for a while and it becomes obvious > > why this is. What's important is how the data needs > > to move and transmute. > > Depends on the application environment. For business type > apps its usually true but in a real time embedded system > the data is usually trivial and the data flows consist > of a few primitive data parameters in method calls. Probably true. While I work on embedded systems, the work I do isn't especially > The work is all in the algorithms and state macjhines. Thats why SDL(a > state based designmethod/notation) is so popular in the > real-time/telecomms industry. Similatly when designing intensively GUI > oriented apps - even something like a word processor.... It's probably one reason why my firm *doesn't* use data flow diagrams as a rule, even when it should. :) > > The single best book on software design I've seen is > > "Structured Analysis and System Specification" by > > Tom Demarco. That's why I've gone through > > three copies in 20 years where all the other books sit unused > > on my shelf. > > "Software Engineering - a Practitioners Approach" by Pressman > is my bible - I buy each new edition as it comes out. I like the book as an overview, but frankly I get more use out of Brooks and DeMarco. That said, I've used it as a school text and find it moderately useful. -- _Deirdre deirdre@deirdre.net http://www.deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From dsh8290@rit.edu Tue Mar 6 17:17:35 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 6 Mar 2001 12:17:35 -0500 Subject: [Tutor] >> BANANAS! << Removing a class instance from a list? In-Reply-To: <20010306145004.35071.qmail@web10507.mail.yahoo.com>; from livelikemad@yahoo.com on Tue, Mar 06, 2001 at 06:50:04AM -0800 References: <20010306145004.35071.qmail@web10507.mail.yahoo.com> Message-ID: <20010306121735.B3203@harmony.cs.rit.edu> On Tue, Mar 06, 2001 at 06:50:04AM -0800, Chris McCormick wrote: | Hey folx, | Got a weird one here. I have a little program to | grow some bananas. I have a banana class. It has | methods for maturing at specified intervals, | displaying different bitmaps at different life stages, | and spawning new plants at maturity. | The program works by creating a list of the class | instances: | | bananacount = input('How many bananas do you wanna | see? ') | for x in range(0, bananacount): | banananame = "banana" + str(x) | new_banana = flora.Banana(banananame, 0, 0) | bananas.append(new_banana) Since you have unique names here I would suggest using a dictionary if the order of bananas in the list doesn't matter. Use the name as the key and the banana object as the value. When you want to remove a particular banana you can use : bananas = { } ... del banans[ name_of_banana_to_remove ] As Danny said, the criteria for removing the banana will determine how you should remove it, and also how to store it. -D From alan.gauld@bt.com Tue Mar 6 17:11:16 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 6 Mar 2001 17:11:16 -0000 Subject: [Tutor] re: software design Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D607@mbtlipnt02.btlabs.bt.co.uk> > > "Software Engineering - a Practitioners Approach" by Pressman > > is my bible - I buy each new edition as it comes out. > > I like the book as an overview, Yes it's as an overview I need it because he updates it with latest trends. In my work (Systems Architect), almost every project I work on, they use a different notation/methodology(*), so a book that offers a useable lead in to all of them is invaluable! Alan g. (*)I currently have one client using Jackson Structured Design - I've *never* seen that used in anger before! :-) From joejava@dragoncat.net Wed Mar 7 00:15:00 2001 From: joejava@dragoncat.net (JRicker) Date: Tue, 6 Mar 2001 19:15:00 -0500 Subject: [Tutor] OOP Advice Message-ID: <003201c0a69b$a7818980$54804cd8@ceo> I'm writing my first python object oriented program. I'm hoping to get some advice as to if I'm going in the right direction The actual program I'm donig is a space combat simulator of some sort to be either web based or client/server of some sort of another. Right now I'm working on the basic units of each ship and moving them around whatnot. I've got this basic classes: class Unit: """ Base class of units. Should not be used only inherited from """ XPos = -1 #x location of unit, -1 not on game board YPos = -1 #y loaction of unit, -1 not on game board def Location(self): return (self.XPos, self.YPos) def RangeToTarget(self,other): return Range(self.XPos, self.YPos, \ other.XPos, other.YPos) def ChangeFacing(self, d): if d == -1: if self.Facing == 1: self.Facing = 6 else: self.Facing = self.Facing - 1 if d == 1: if self.Facing == 6: self.Facing = 1 else: self.Facing = self.Facing + 1 def ReportFacing(self): if hasattr(self, "Facing"): return self.Facing else: return 0 def Move(self): if self.Facing == 1: self.YPos = self.YPos - 1 if self.Facing == 2: self.XPos = self.XPos + 1 if self.Facing == 3: self.XPos = self.XPos + 1 self.YPos = self.YPos + 1 if self.Facing == 4: self.YPos = self.YPos + 1 if self.Facing == 5: self.XPos = self.XPos - 1 self.YPos = self.YPos + 1 if self.Facing == 6: self.XPos = self.XPos - 1 class Ship(Unit): """ Ship class. Derives from Unit class. """ shipdata = {} def __init__(self, x, y, f): self.Report = Logger(sys.stdout) self.Facing = f self.XPos = x self.YPos = y class Shuttle(Unit): def __init__(self,x,y,f): pass Now my question primarily is around how the init can be handled. Ships and Shuttles would be very similar. Each has a speed, a heading (which is what the f is in the init), a hex position, plus lots of other things like weapons, size, turn mode (how many hexes a unit has to move before it can turn), etc. The main difference between a ship and a shuttle is when it comes to protection. A ship will have large shields, which a shield on each side of a ship while the shuttle may not have any at all, maybe a certain number of armor points that would be depleted before the shuttle was destroyed. Also a shuttle wouldn't have a shuttle bay that can launch shuttles like a ship would. My question is this, Is there a way to set up the init function in unit to handle most of the initialization of the object and the rest done by the object? How do I structure things so that Unit is doing most of the work? Probably not the most exact question in the world but I'm still having some hangups about object orientedness programs. Thanks for any help Joel From ewe2@can.org.au Wed Mar 7 00:57:04 2001 From: ewe2@can.org.au (ewe2@can.org.au) Date: Wed, 7 Mar 2001 11:57:04 +1100 Subject: [Tutor] more dictionary fun Message-ID: <20010307115703.A3005@can.org.au> hi, I have a dictionary in the form of {('A':(1,0)),('B':(2,1))} where the values are guaranteed to be unique. Given a specific value (e.g. (3,0)), how do i lookup the key? -- Sean Dwyer <ewe2@cvis.com.au> CAN Admin <ewe2@can.org.au> Web: http://ewe2.cvis.com.au/ From dsh8290@rit.edu Wed Mar 7 02:23:40 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 6 Mar 2001 21:23:40 -0500 Subject: [Tutor] more dictionary fun In-Reply-To: <20010307115703.A3005@can.org.au>; from ewe2@can.org.au on Wed, Mar 07, 2001 at 11:57:04AM +1100 References: <20010307115703.A3005@can.org.au> Message-ID: <20010306212339.A29195@harmony.cs.rit.edu> On Wed, Mar 07, 2001 at 11:57:04AM +1100, ewe2@can.org.au wrote: | hi, | | I have a dictionary in the form of {('A':(1,0)),('B':(2,1))} where the values | are guaranteed to be unique. Given a specific value (e.g. (3,0)), how do i | lookup the key? # 'd' is a dictionary # 'value_i_want' is the value you have and you want the key for it for key , value in d.items() : if value == value_i_want : break print "The key is" , key -D From shaleh@valinux.com Wed Mar 7 03:35:16 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 6 Mar 2001 19:35:16 -0800 Subject: [Tutor] OOP Advice In-Reply-To: <003201c0a69b$a7818980$54804cd8@ceo>; from joejava@dragoncat.net on Tue, Mar 06, 2001 at 07:15:00PM -0500 References: <003201c0a69b$a7818980$54804cd8@ceo> Message-ID: <20010306193516.B18198@valinux.com> Teaching by example........ class Polyhedron: def __init__(self, sides): self.sides = sides def num_sides(self): return self.sides class Rectangle(Polyhedron): def __init__(self, length, width): Polyhedron.__init__(self, 4) self.length = length self.width = width def area(self): return self.length * self.width class Square(Rectangle): def __init__(self, length): Rectangle.__init__(self, length, length) # override the Parent's method def area(self): """ area of a Square is length of side * length of side """ return self.length * self.length if __name__ == '__main__': p = Polydron(5) print p.num_sides() r = Rectangle(4, 6) print r.num_sides() print r.area() s = Square(4) print s.num_sides() print s.area() so, there is some inheritance, some poor planning (rectangle and square are rather similar, no good reason to make a new class unless other methods would care), and I hope a useful example. python /tmp/geo.py 5 4 24 4 16 From tbrauch@mindless.com Wed Mar 7 03:54:54 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Tue, 06 Mar 2001 22:54:54 -0500 Subject: [Tutor] File Copying on Win98 Message-ID: <3AA5B10E.79A7D5BD@mindless.com> Is there a way to copy a file from one place to another in Win 98 with Python 2.0. The following does *not* work. import os contents_0=os.listdir('../CIM2kCD/') try: os.mkdir('C:/Program Files/CIM2k/') except: pass for item in contents_0: file=open('../CIM2kCD/'+item,'rb').read() new=open('C:/Program Files/CIM2kCD/'+item,'w') new.write('C:/Program Files/CIM2k/'+item) This produces the following error: Traceback (innermost last) File "d:\cim2kcd\list.py", line 11, in ? new=open('C:/Program Files/CIM2kCD/'+item,'w') IOError: [Errno 2] No such file or directory: 'C:/Program Files/CIM2kCD/CIM2k.htm' I understand why it gives me that error, I am trying to open a file that doesn't exist. But, how else can I copy a file. All I am trying to do is copy the files in one directory into another directory. I know there has to be a way to do this, but I cannot for the life of me figure out how. Also, the files have all kinds of extensions, like .jpg, .html, .gif, .exe, and others. - Tim From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 05:19:31 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 21:19:31 -0800 (PST) Subject: [Tutor] Stuck on Something (fwd) Message-ID: <Pine.LNX.4.21.0103062118120.3848-100000@hkn.eecs.berkeley.edu> Dear Britt, Let me forward this to the other tutors at tutor@python.org; I'll take a look at your question later tonight, but perhaps someone else can answer quickly in the meantime. Talk to you later! ---------- Forwarded message ---------- Date: Tue, 06 Mar 2001 19:30:33 -0800 From: Britt Green <britt_green@hotmail.com> To: dyoo@hkn.eecs.berkeley.edu Subject: Stuck on Something Howdy, I'm kinda stuck on my program, and I think its because I'm just not sure how to write it in Python. Let me show you the bit of code i have so far: dirlist = ['/atl', '/boston', '/chicago'] ftp = FTP('ftp.opentable.com', 'account', 'password') for folders in dirlist: ftp.cwd(folders) folderContents = getftplist(ftp) Basically, this code goes into each of the three directories and returns, as a string, the list of directories in each folder. It kind of looks like this: drwxrwx--- 2 restback privftp 512 Feb 9 21:20 vivo drwxrwx--- 2 restback privftp 512 Mar 6 21:09 voltaire drwxrwx--- 2 restback privftp 512 Mar 6 21:10 vong drwxrwx--- 2 restback privftp 512 Mar 6 21:07 watusi drwxrwx--- 2 restback privftp 512 Mar 6 21:57 wildfire drwxrwx--- 2 restback privftp 512 Mar 6 21:35 zinfandel So what I need to do with this chunk is to tell my program that vivo, voltaire, vong, etc are all directories it needs to enter. The way I thought I'd do this is to use the string.splitlines() command to split up folderContents into a list. Then I run into the problem of trying to split up each of the elements in the list. Its proving to be more difficult than I thought. I'm hoping I can pick your brain once more. I know how I'd write this in C++, but not in Python. Any suggestions are appreciated! Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 05:33:08 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 21:33:08 -0800 (PST) Subject: [Tutor] more dictionary fun In-Reply-To: <20010307115703.A3005@can.org.au> Message-ID: <Pine.LNX.4.21.0103062126250.3848-100000@hkn.eecs.berkeley.edu> On Wed, 7 Mar 2001 ewe2@can.org.au wrote: > I have a dictionary in the form of {('A':(1,0)),('B':(2,1))} where the > values are guaranteed to be unique. Given a specific value (e.g. > (3,0)), how do i lookup the key? Hmmm... usually, it goes the other way around: dictionaries can, given a key, lookup a value really fast. If we have the value, and we're looking for keys, it's a lot slower, but it can be done. Dictionaries have a method called items() which give a list of key/value tuples. For example: ### >>> dict = {'a': (1,0), 'b': (2,1)} >>> dict.items() [('b', (2, 1)), ('a', (1, 0))] ### So we can write a for loop that says: for key, value in dict.items(): if value == (3,0): print "We've found it with key", key Another way to do it is to "invert" a dictionary. If we're positively sure that the values are unique, we can write a dictionary_invert() function that returns a new dictionary, where the keys are now the values and vice versa: ### def invert_dict(dict): new_dict = {} for key, value in dict.items(): new_dict[value] = key return new_dict ### Personally, I like the invert_dict() method, because it's reusable in many other problems. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 05:45:18 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 21:45:18 -0800 (PST) Subject: [Tutor] Stuck on Something (fwd) In-Reply-To: <Pine.LNX.4.21.0103062118120.3848-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.21.0103062138210.3848-100000@hkn.eecs.berkeley.edu> On Tue, 6 Mar 2001, Daniel Yoo wrote: > Basically, this code goes into each of the three directories and > returns, as a string, the list of directories in each folder. It kind > of looks like this: > > drwxrwx--- 2 restback privftp 512 Feb 9 21:20 vivo > drwxrwx--- 2 restback privftp 512 Mar 6 21:09 voltaire > drwxrwx--- 2 restback privftp 512 Mar 6 21:10 vong > drwxrwx--- 2 restback privftp 512 Mar 6 21:07 watusi > drwxrwx--- 2 restback privftp 512 Mar 6 21:57 wildfire > drwxrwx--- 2 restback privftp 512 Mar 6 21:35 zinfandel > So what I need to do with this chunk is to tell my program that vivo, > voltaire, vong, etc are all directories it needs to enter. The way I > thought I'd do this is to use the string.splitlines() command to split > up folderContents into a list. Then I run into the problem of trying > to split up each of the elements in the list. Its proving to be more > difficult than I thought. This looks reasonable. However, I did a quick check on my system, but I couldn't find string.splitlines(). Do you mean: string.split(some_large_string, '\n') instead? This should break your string into lists of lines. Also, if you have a sequence, it's fairly easy to get the last element in that sequence, by using negative indexing: ### l = [0, 1, 2, 3, 4, 5] print l[-1] ### so it shouldn't be too hard to grab the directory names out of the list of lines. Can you show us where you're getting stuck? We can help with that. (Getting unstuck, that is. *grin*) Double check the documentation for string, just to see what sort of stuff you can use for your problem: http://python.org/doc/current/lib/module-string.html Good luck! From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 05:49:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 6 Mar 2001 21:49:28 -0800 (PST) Subject: [Tutor] File Copying on Win98 In-Reply-To: <3AA5B10E.79A7D5BD@mindless.com> Message-ID: <Pine.LNX.4.21.0103062145240.3848-100000@hkn.eecs.berkeley.edu> On Tue, 6 Mar 2001, Timothy M. Brauch wrote: > Is there a way to copy a file from one place to another in Win 98 with > Python 2.0. The following does *not* work. > > import os > > contents_0=os.listdir('../CIM2kCD/') > > try: > os.mkdir('C:/Program Files/CIM2k/') > except: pass > > for item in contents_0: > file=open('../CIM2kCD/'+item,'rb').read() > new=open('C:/Program Files/CIM2kCD/'+item,'w') > new.write('C:/Program Files/CIM2k/'+item) > > This produces the following error: > > Traceback (innermost last) > File "d:\cim2kcd\list.py", line 11, in ? > new=open('C:/Program Files/CIM2kCD/'+item,'w') > IOError: [Errno 2] No such file or directory: > 'C:/Program Files/CIM2kCD/CIM2k.htm' > > I understand why it gives me that error, I am trying to open a file that > doesn't exist. But, how else can I copy a file. The only thing I can think of that would cause this is that the directory "C:/Program Files/CIM2kCD" doesn't exist. Can you double check that this is the case? From lumbricus@gmx.net Wed Mar 7 06:00:11 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Wed, 7 Mar 2001 07:00:11 +0100 (MET) Subject: [Tutor] Stuck on Something (fwd) References: <Pine.LNX.4.21.0103062118120.3848-100000@hkn.eecs.berkeley.edu> Message-ID: <28649.983944811@www17.gmx.net> This is a MIME encapsulated multipart message - please use a MIME-compliant e-mail program to open it. Dies ist eine mehrteilige Nachricht im MIME-Format - bitte verwenden Sie zum Lesen ein MIME-konformes Mailprogramm. --========GMXBoundary28649983944811 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit -- Sent through GMX FreeMail - http://www.gmx.net --========GMXBoundary28649983944811 Content-Type: text/plain; name="mailansw.txt" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="mailansw.txt" CiAgIGRpcmxpc3QgPSBbJy9hdGwnLCAnL2Jvc3RvbicsICcvY2hpY2FnbyddCiAgIGZ0cCA9IEZU UCgnZnRwLm9wZW50YWJsZS5jb20nLCAnYWNjb3VudCcsICdwYXNzd29yZCcpCiAgIGZvciBmb2xk ZXJzIGluIGRpcmxpc3Q6CiAgICAgICBmdHAuY3dkKGZvbGRlcnMpCiAgICAgICBmb2xkZXJDb250 ZW50cyA9IGdldGZ0cGxpc3QoZnRwKQogICBCYXNpY2FsbHksIHRoaXMgY29kZSBnb2VzIGludG8g ZWFjaCBvZiB0aGUgdGhyZWUgZGlyZWN0b3JpZXMgYW5kIHJldHVybnMsIGFzCiAgIGEgc3RyaW5n LCB0aGUgbGlzdCBvZiBkaXJlY3RvcmllcyBpbiBlYWNoIGZvbGRlci4gSXQga2luZCBvZiBsb29r cyBsaWtlCiAgIHRoaXM6CiAgIGRyd3hyd3gtLS0gICAyIHJlc3RiYWNrIHByaXZmdHAgICAgICAg NTEyIEZlYiAgOSAyMToyMCB2aXZvCiAgIGRyd3hyd3gtLS0gICAyIHJlc3RiYWNrIHByaXZmdHAg ICAgICAgNTEyIE1hciAgNiAyMTowOSB2b2x0YWlyZQogICBkcnd4cnd4LS0tICAgMiByZXN0YmFj ayBwcml2ZnRwICAgICAgIDUxMiBNYXIgIDYgMjE6MTAgdm9uZwogICBkcnd4cnd4LS0tICAgMiBy ZXN0YmFjayBwcml2ZnRwICAgICAgIDUxMiBNYXIgIDYgMjE6MDcgd2F0dXNpCiAgIGRyd3hyd3gt LS0gICAyIHJlc3RiYWNrIHByaXZmdHAgICAgICAgNTEyIE1hciAgNiAyMTo1NyB3aWxkZmlyZQog ICBkcnd4cnd4LS0tICAgMiByZXN0YmFjayBwcml2ZnRwICAgICAgIDUxMiBNYXIgIDYgMjE6MzUg emluZmFuZGVsCiAgIFNvIHdoYXQgSSBuZWVkIHRvIGRvIHdpdGggdGhpcyBjaHVuayBpcyB0byB0 ZWxsIG15IHByb2dyYW0gdGhhdCB2aXZvLAogICB2b2x0YWlyZSwgdm9uZywgZXRjIGFyZSBhbGwg ZGlyZWN0b3JpZXMgaXQgbmVlZHMgdG8gZW50ZXIuIFRoZSB3YXkgSSB0aG91Z2h0CiAgIEknZCBk byB0aGlzIGlzIHRvIHVzZSB0aGUgc3RyaW5nLnNwbGl0bGluZXMoKSBjb21tYW5kIHRvIHNwbGl0 IHVwCiAgIGZvbGRlckNvbnRlbnRzIGludG8gYSBsaXN0LiBUaGVuIEkgcnVuIGludG8gdGhlIHBy b2JsZW0gb2YgdHJ5aW5nIHRvIHNwbGl0CiAgIHVwIGVhY2ggb2YgdGhlIGVsZW1lbnRzIGluIHRo ZSBsaXN0LiBJdHMgcHJvdmluZyB0byBiZSBtb3JlIGRpZmZpY3VsdCB0aGFuIEkKICAgdGhvdWdo dC4KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIwpIZWxsbyAhISEKSSBkaWRuJ3QgdGVzdCB0aGlzLiBQ cm9wYWJseSBpdCB3b250IHdvcmsuCmRpcmxpc3Q9c3RyaW5nLnNwbGl0KGZvbGRlckNvbnRlbnRz LCdcbicpCmZvciBlbnRyeSBpbiBkaXJsaXN0OgoJcGVybT1zdHJpbmcuc3BsaXQoZW50cnkpWzBd CglmaWxlPXN0cmluZy5zcGxpdChlbnRyeSlbLTE6XQoJaWYgJ2QnIGluIHBlcm06CgkJIyB3ZSBr bm93IGZpbGUgaXMgYSBkaXJlY3RvcnkKCQlmdHAuY3dkKGZpbGUpICMgPz8/CgkJIyBUT0RPOgoJ CSMgZGVmaW5lIHRoZSBlbnRlcmluZyBvZiBkaXJlY3RvcmllcyArIHRoZSBhY3Rpb24KCQkjIHlv dSB3YW50IHRvIHBlcmZvcm0gYXMgYSBmdW5jdGlvbiB3aGljaAoJCSMgZ2V0cyBjYWxsZWQgcmVj dXJzaXZlbHkKCWVsc2U6CgkJIyBmaWxlIGlzIGEgcmVndWxhciBmaWxlCgkJIyBkbyBzb21ldGhp bmcgd2l0aCBpdAoJCQoJCQojIyMjIyMjIyMjIyMjIyMKZ3JyZXR6IEr2IQo= --========GMXBoundary28649983944811-- From lumbricus@gmx.net Wed Mar 7 06:05:03 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Wed, 7 Mar 2001 07:05:03 +0100 (MET) Subject: [Tutor] File Copying on Win98 References: <Pine.LNX.4.21.0103062145240.3848-100000@hkn.eecs.berkeley.edu> Message-ID: <31825.983945103@www17.gmx.net> > On Tue, 6 Mar 2001, Timothy M. Brauch wrote: > > > Is there a way to copy a file from one place to another in Win 98 with > > Python 2.0. The following does *not* work. > > > > import os > > > > contents_0=os.listdir('../CIM2kCD/') > > > > try: > > os.mkdir('C:/Program Files/CIM2k/') ^^^^ !!! > > except: pass > > > > for item in contents_0: > > file=open('../CIM2kCD/'+item,'rb').read() > > new=open('C:/Program Files/CIM2kCD/'+item,'w') ^^ you created a dir called c:/Pr[...]/CIM2k/ > > new.write('C:/Program Files/CIM2k/'+item) > > > > This produces the following error: > > > > Traceback (innermost last) > > File "d:\cim2kcd\list.py", line 11, in ? > > new=open('C:/Program Files/CIM2kCD/'+item,'w') > > IOError: [Errno 2] No such file or directory: > > 'C:/Program Files/CIM2kCD/CIM2k.htm' > > > > I understand why it gives me that error, I am trying to open a file that > > doesn't exist. But, how else can I copy a file. > > The only thing I can think of that would cause this is that the directory > "C:/Program Files/CIM2kCD" doesn't exist. Can you double check that this > is the case? > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From tmbrau00@centre.edu Wed Mar 7 06:14:48 2001 From: tmbrau00@centre.edu (Timothy Brauch) Date: Wed, 07 Mar 2001 01:14:48 -0500 Subject: [Tutor] File Copying on Win98 References: <Pine.LNX.4.21.0103062145240.3848-100000@hkn.eecs.berkeley.edu> Message-ID: <3AA5D1D8.12C5F26D@centre.edu> > > import os > > > > contents_0=os.listdir('../CIM2kCD/') > > > > try: > > os.mkdir('C:/Program Files/CIM2k/') > > except: pass > > > > for item in contents_0: > > file=open('../CIM2kCD/'+item,'rb').read() > >## new=open('C:/Program Files/CIM2kCD/'+item,'w') new=open('C:/Program Files/CIM2k/'+item,'wb') This is my first change > >## new.write('C:/Program Files/CIM2k/'+item) new.write(file) And here is another change I needed to make. I also need to change from 'w' to 'wb.' The picture files looked very odd using just 'w'. Thanks for all your help - Tim From gruschow2@hotmail.com Wed Mar 7 06:33:02 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Wed, 07 Mar 2001 00:33:02 -0600 Subject: [Tutor] urgent!!!! I need help in Python 1.5.2 and Windows 98---->labels and clocks Message-ID: <F27667MnH6yidNriojw00000eb5@hotmail.com> I need help with widgets, labels, and clocks. I have Idle 0.5, Python 1.5.2, Windows 98. I need to know how to create a digital clock with hours and minutes and seconds. Please help me gruschow2@hotmail.com _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From gruschow2@hotmail.com Wed Mar 7 06:46:23 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 7 Mar 2001 00:46:23 -0600 Subject: [Tutor] please respond to my last ?, I have desperately been trying to figure this out, I want to make a digital clock Message-ID: <OE67YyjlMFAVNL9pdRp00002ca8@hotmail.com> please respond to my last ?, I have desperately been trying to figure this out, I want to make a digital clock I would like to use labels amd widgets and Tkinter. I have Windows 98, Python 1.5.2, Idle 0.5. gruschow2@hotmail.com From britt_green@hotmail.com Wed Mar 7 06:56:50 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 06 Mar 2001 22:56:50 -0800 Subject: [Tutor] Stuck on Something Message-ID: <F315lGqAu5EKzAG72uq0001023c@hotmail.com> >Message: 11 >Date: Tue, 6 Mar 2001 21:19:31 -0800 (PST) >From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu> >To: tutor@python.org >Subject: [Tutor] Stuck on Something (fwd) > > >Dear Britt, > >Let me forward this to the other tutors at tutor@python.org; I'll take a >look at your question later tonight, but perhaps someone else can answer >quickly in the meantime. > >Talk to you later! Wierd. I would've swore I CCed the mailing list on this as well. Thanks for forwarding it on for me! Britt _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From britt_green@hotmail.com Wed Mar 7 07:13:10 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 06 Mar 2001 23:13:10 -0800 Subject: [Tutor] Stuck on Something Message-ID: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com> >This looks reasonable. However, I did a quick check on my system, but I >couldn't find string.splitlines(). Do you mean: > > string.split(some_large_string, '\n') > >instead? This should break your string into lists of lines. Hmm, interesting. I have a copy of Core Python Programming by Wesley Chun right here, and it lists string.splitlines() as a string function. But when I check on the Python website, all I see is string.split(). Odd. >Also, if you have a sequence, it's fairly easy to get the last element in >that sequence, by using negative indexing: > >### > l = [0, 1, 2, 3, 4, 5] > print l[-1] >### > >so it shouldn't be too hard to grab the directory names out of the list of >lines. Can you show us where you're getting stuck? We can help with >that. (Getting unstuck, that is. *grin*) Ok. The line x = string.split(dlist, '\n') will split a listing of the FTP directory into individual lines, instead of just one giant string. So instead of having: drwxrwx--- 2 restback privftp 512 Mar 6 21:23 technicolorkitchen drwxrwx--- 2 restback privftp 512 Mar 6 21:58 theclubhouse drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme it looks more like ['drwxrwx--- 2 restback...', 'drwxrwx--- 2 restback...', 'etc', 'etc]. I guess I should ask if I'm making the correct assumption here. Thats what the output seems to suggest. Assuming that I'm not mistaken here, the next step is to have Python remove from each line the name of the directory. So in the above examples it needs to have 'theclubhouse', 'thirdstreet' and 'thyme' removed from the line. This is where I'm getting a bit stuck. I can't seem to get this to be removed. I've tried a couple of different things but the most i can get it to return is a single letter. Hopefully that wasn't too vague. Any suggestions? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From jcm@bigskytel.com Wed Mar 7 08:07:11 2001 From: jcm@bigskytel.com (David Porter) Date: Wed, 7 Mar 2001 01:07:11 -0700 Subject: [Tutor] Stuck on Something In-Reply-To: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com>; from britt_green@hotmail.com on Tue, Mar 06, 2001 at 11:13:10PM -0800 References: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com> Message-ID: <20010307010710.A392@bigskytel.com> * Britt Green <britt_green@hotmail.com>: > Hopefully that wasn't too vague. Any suggestions? #--- import string raw_dirs = """\ drwxrwx--- 2 restback privftp 512 Mar 6 21:23 technicolorkitchen drwxrwx--- 2 restback privftp 512 Mar 6 21:58 theclubhouse drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme""" dirs = [] raw_dirs = string.split(raw_dirs, '\n') for x in raw_dirs: dirs.append(string.split(x)[-1]) print dirs #--- HTH, David From scarblac@pino.selwerd.nl Wed Mar 7 09:33:02 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 7 Mar 2001 10:33:02 +0100 Subject: [Tutor] Stuck on Something In-Reply-To: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com>; from britt_green@hotmail.com on Tue, Mar 06, 2001 at 11:13:10PM -0800 References: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com> Message-ID: <20010307103302.B10672@pino.selwerd.nl> On Tue, Mar 06, 2001 at 11:13:10PM -0800, Britt Green wrote: > drwxrwx--- 2 restback privftp 512 Mar 6 21:23 technicolorkitchen > drwxrwx--- 2 restback privftp 512 Mar 6 21:58 theclubhouse > drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet > drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme > > it looks more like ['drwxrwx--- 2 restback...', 'drwxrwx--- 2 restback...', > 'etc', 'etc]. I guess I should ask if I'm making the correct assumption > here. Thats what the output seems to suggest. > > Assuming that I'm not mistaken here, the next step is to have Python remove > from each line the name of the directory. So in the above examples it needs > to have 'theclubhouse', 'thirdstreet' and 'thyme' removed from the line. > > This is where I'm getting a bit stuck. I can't seem to get this to be > removed. I've tried a couple of different things but the most i can get it > to return is a single letter. Ok, so the first string is like 'drwxrwx--- 2 restback privftp 512 Mar 6 21:23 technicolorkitchen' We can split that up between the spaces, and take the last one: ('lines' is the list of strings here) for line in lines: directory = line.split()[-1] print directory line.split() splits the line up, using " " as a separator, and [-1] takes the last element. Now in theory, the filename could also have a space in it, and then it won't work. If the output always looks exactly like this, we can also notice that the word 'technicolorkitchen' starts at index 54, and use that: for line in lines: directory = line[54:] print directory But this won't work if you use different FTP servers, I think. I don't know how standard this output format is. I feel there should be an easier way to figure out the directory contents, but I don't know it right now. -- Remco Gerlich From scarblac@pino.selwerd.nl Wed Mar 7 09:46:21 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 7 Mar 2001 10:46:21 +0100 Subject: [Tutor] please respond to my last ?, I have desperately been trying to figure this out, I want to make a digital clock In-Reply-To: <OE67YyjlMFAVNL9pdRp00002ca8@hotmail.com>; from gruschow2@hotmail.com on Wed, Mar 07, 2001 at 12:46:23AM -0600 References: <OE67YyjlMFAVNL9pdRp00002ca8@hotmail.com> Message-ID: <20010307104621.C10672@pino.selwerd.nl> On Wed, Mar 07, 2001 at 12:46:23AM -0600, Charles Gruschow, Jr. wrote: > please respond to my last ?, I have desperately been trying to figure this > out, I want to make a digital clock > > I would like to use labels amd widgets and Tkinter. A digital clock? So you only show the hours, minutes etc in text, you don't have to draw a clock? You're going to need a simple Tkinter frame and maybe one label in it (saying: 'time: 10:40:27') or maybe a few for seperate hours, minutes, seconds. The introduction to Tkinter is at http://www.secretlabs.com/library/tkinter/introduction/hello-again.htm Look at the second Hello World example and at the docs for Labels, and try to put them together into something that displays some text. Next, you can get the time with something like this: import time year, month, day, hour, minutes, seconds = time.localtime(time.time())[:6] And put together something to display from that. Then, all you need to do is call that again after a second or so. See the 'Alarm' documentation in the Tkinter docs or time.sleep(). This should get you underway... -- Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 10:36:57 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 7 Mar 2001 02:36:57 -0800 (PST) Subject: [Tutor] urgent!!!! I need help in Python 1.5.2 and Windows 98---->labels and clocks In-Reply-To: <F27667MnH6yidNriojw00000eb5@hotmail.com> Message-ID: <Pine.LNX.4.21.0103070230150.14533-100000@hkn.eecs.berkeley.edu> On Wed, 7 Mar 2001, Charles Gruschow wrote: > I need help with widgets, labels, and clocks. > > I have Idle 0.5, Python 1.5.2, Windows 98. > > I need to know how to create a digital clock with hours and minutes and > seconds. Hello! Have you taken a look at: http://python.org/topics/tkinter/doc.html yet? There are a few tutorials to Tkinter there. The question that you're asking sounds way too large for us to handle; we can't teach all of Tkinter in one message. Ask smaller, more specific questions, and we can be more effective in helping out. What do you know about Tkinter already? From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 10:54:53 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 7 Mar 2001 02:54:53 -0800 (PST) Subject: [Tutor] OOP Advice In-Reply-To: <003201c0a69b$a7818980$54804cd8@ceo> Message-ID: <Pine.LNX.4.21.0103070240160.14729-100000@hkn.eecs.berkeley.edu> Hello! Ok, let's do a quick scan through your program. (Some of my code assumes Python 1.52, so there are probably better ways of writing the code if you're using a more recent version of Python.) On Tue, 6 Mar 2001, JRicker wrote: > class Unit: > """ > Base class of units. Should not be used only inherited from > """ > > XPos = -1 #x location of unit, -1 not on game board > YPos = -1 #y loaction of unit, -1 not on game board In Python, you don't need to predeclare member variables. I'm guessing that every Unit should their own separate XPos and YPos. What you have right now defines a class variable XPos, YPos for all Units. Most likely, you don't need those two lines. > def ChangeFacing(self, d): > if d == -1: > if self.Facing == 1: > self.Facing = 6 > else: self.Facing = self.Facing - 1 There's a slightly nicer way of defining direction, but it involves using angles and trigonometry. *shudder* Seriously though, it will help if you use angles to define your facing direction. If we do so, then our move function becomes a lot more direct and clean: ### def Move(self): self.XPos = self.XPos + cos(self.Facing) self.YPos = self.YPos + sin(self.Facing) ### This assumes that self.Facing now represents the angle (in radians) where the ship's directed at. Turning left or right, then, represents adding and subtracting the quantity pi/2.0 (90 degrees) from the Facing. Math: it's actually useful! *grin* > My question is this, Is there a way to set up the init function in unit > to handle most of the initialization of the object and the rest done by > the object? How do I structure things so that Unit is doing most of the > work? Yes, Unit can itself have a constructor that does most of the work. This way, when we make extensions to Unit, we can still initialize the Unitness of an object. All units, at the moment, appear to have inital XPos and YPos, so we can put that there: # within Unit definition: ### def __init__(self, XPos, YPos): self.XPos, Self.Ypos = XPos, YPos ## and do other common initialization of Units here ### If we have something like this, we can take advantage of it in our inherited classes: # within Ship definition def __init__(self, x, y, f): Unit.__init__(self, x, y) ## Let's call the parent's initializer ## and now we can do specific stuff for ships here. So we can call our parent's initializer directly, passing it the appropriate arguments. Hope this helps! From arcege@shore.net Wed Mar 7 12:27:20 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 7 Mar 2001 07:27:20 -0500 (EST) Subject: [Tutor] Stuck on Something In-Reply-To: <F34MXehYSoOZzHZlJ2H00001cc5@hotmail.com> from Britt Green at "Mar 6, 2001 11:13:10 pm" Message-ID: <E14ad2G-0004LE-00@nautilus.shore.net> > > >This looks reasonable. However, I did a quick check on my system, but I > >couldn't find string.splitlines(). Do you mean: > > > > string.split(some_large_string, '\n') > > > >instead? This should break your string into lists of lines. > > Hmm, interesting. I have a copy of Core Python Programming by Wesley Chun > right here, and it lists string.splitlines() as a string function. But when > I check on the Python website, all I see is string.split(). Odd. There is a function called "splitfields". In Python 1.5.2, the string.split was changed to have the same (extended) functionality as string.splitfields. Splitfields() may possibly be deprecated in the future, and it is better to use split(). What you might be thinking of is the new Python 2.0 string methods where there is a `"".splitlines()', instead of the functions in the "string" module. It is basically the equivalent of `string.splitfields("", os.linesep)'. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From kstoner@netins.net Wed Mar 7 13:11:50 2001 From: kstoner@netins.net (Katharine Stoner) Date: Wed, 7 Mar 2001 07:11:50 -0600 Subject: [Tutor] data flow Message-ID: <000c01c0a708$2c6271c0$9152b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0A6D5.E130F1E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable What is a data flow model? -Cameron Stoner ------=_NextPart_000_0009_01C0A6D5.E130F1E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>What is a data flow model?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Cameron = Stoner</FONT></DIV></BODY></HTML> ------=_NextPart_000_0009_01C0A6D5.E130F1E0-- From jsp@opencom.de Wed Mar 7 14:44:17 2001 From: jsp@opencom.de (=?iso-8859-1?Q?J=F6rg_Sporer?=) Date: Wed, 7 Mar 2001 15:44:17 +0100 Subject: [Tutor] Icons for frames Message-ID: <000c01c0a715$16682650$2501000a@opencom> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0A71D.781583E0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Hi there! How can I change the small Tk icon in the upper left corner of a frame = (made by tkinter)? Thanks for your help ------=_NextPart_000_0009_01C0A71D.781583E0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi there!</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>How can I change the small Tk icon in = the upper=20 left corner of a frame (made by tkinter)?</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks for your help</FONT></DIV> <DIV> </DIV></BODY></HTML> ------=_NextPart_000_0009_01C0A71D.781583E0-- From gibbs05@flash.net Wed Mar 7 16:01:39 2001 From: gibbs05@flash.net (Harry Kattz) Date: Wed, 7 Mar 2001 10:01:39 -0600 Subject: [Tutor] Icons for frames References: <000c01c0a715$16682650$2501000a@opencom> Message-ID: <000f01c0a71f$ef7dd5c0$11de3040@gibbs05> This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C0A6ED.9A6A6DA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Greetings J=F6rg & All, Currently this is possible for some people but not for most. Soon it'll = be possible for everyone... Ok, I'll explain. Standard Tk 8.3 or below doesn't come with the ability to change what = they call the 'winicon', but there was an extension written back during = v 8.0 called winico that will attempt to. You can get it at = http://ftp.bj-ig.de/pub/tcltk/ I think the latest version is = winico31.zip Once you've unzipped this lemon, don't try to run the install program, = teki. It was written for Tcl v 8.0 and will exception out for any later = version. I've looked at the source for teki, and it's a beast. You can use the standard Tcl load command to get around this like so: % load <path to where you put it>//winico03.dll This works for some people, but every machine I've tried it on page = faults! I'll repeat, it works for some people even if they have later = versions of Tcl. It just doesn't crash for them, so they don't have a = solution to the page fault. >From there you'd use notation something like this, though I've not been = able to try it: % winico setwindow $w $Icon where you've loaded Icon with a bitmap earlier. >From Tkinter you'd use something like this to load it: Tk.call('load', '<path to where you put it>/winico03.dll') I've tried this and it gives me the same page fault. Others have = claimed to get it to work though. If you're able to successfully load it, something like this could set = the icon: <Your main window name>.call('winico', 'setwindow', <Your main = window name>._w, Icon) where you've already loaded an image into Icon. Well, good luck if you try this anyone. If someone finds a way to fix = the page faults, please let me know. The crew working on Tk have promised to add winicon support directly to = their wm module in version 8.4. They haven't done it yet, but with = ActiveState having taken over Tcl dev I expect it may move up the = priority ladder a bit. :-) Once they do that, this'll be easy. I'm going to be patient and wait... Good luck, Sam Hi there! =20 How can I change the small Tk icon in the upper left corner of a frame = (made by tkinter)? =20 Thanks for your help ------=_NextPart_000_000C_01C0A6ED.9A6A6DA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Greetings J=F6rg & All,</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Currently this is possible for some people but not = for=20 most. Soon it'll be possible for everyone...</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Ok, I'll explain.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Standard Tk 8.3 or below doesn't come with the = ability to=20 change what they call the 'winicon', but there was an extension written = back=20 during v 8.0 called winico that will attempt to. You can get it at = <A=20 href=3D"http://ftp.bj-ig.de/pub/tcltk/">http://ftp.bj-ig.de/pub/tcltk/</A= > I=20 think the latest version is winico31.zip</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Once you've unzipped this lemon, don't try to run = the install=20 program, teki. It was written for Tcl v 8.0 and will exception out = for any=20 later version. I've looked at the source for teki, and it's=20 a beast.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>You can use the standard Tcl load command to = get around=20 this like so:</FONT></DIV> <DIV><FONT size=3D2> % load <path to where you put=20 it>//winico03.dll</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>This works for some people, but every machine I've = tried it on=20 page faults! I'll repeat, it works for some people even if they = have later=20 versions of Tcl. It just doesn't crash for them, so they don't = have a=20 solution to the page fault.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>From there you'd use notation something like this, = though I've=20 not been able to try it:</FONT></DIV> <DIV><FONT size=3D2> % winico setwindow $w = $Icon</FONT></DIV> <DIV><FONT size=3D2>where you've loaded Icon with a bitmap = earlier.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>From Tkinter you'd use something like this to load=20 it:</FONT></DIV> <DIV><FONT size=3D2> Tk.call('load', '<path to = where you put=20 it>/winico03.dll')</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>I've tried this and it gives me the same page = fault. =20 Others have claimed to get it to work though.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>If you're able to successfully load it, something = like this=20 could set the icon:</FONT></DIV> <DIV><FONT size=3D2> <Your main window=20 name>.call('winico', 'setwindow', <Your main window name>._w,=20 Icon)</FONT></DIV> <DIV><FONT size=3D2>where you've already loaded an image into = Icon.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Well, good luck if you try this anyone. If = someone finds=20 a way to fix the page faults, please let me know.</FONT></DIV> <DIV> </DIV> <DIV> </DIV> <DIV><FONT size=3D2>The crew working on Tk have promised to add winicon = support=20 directly to their wm module in version 8.4. They haven't done it = yet, but=20 with ActiveState having taken over Tcl dev I expect it may move up the = priority=20 ladder a bit. :-) Once they do that, this'll be easy.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>I'm going to be patient and wait...</FONT></DIV> <DIV> </DIV> <DIV> </DIV> <DIV><FONT size=3D2>Good luck,</FONT></DIV> <DIV><FONT size=3D2>Sam</FONT></DIV> <DIV> </DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV><FONT face=3DArial size=3D2>Hi there!</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>How can I change the small Tk icon in = the upper=20 left corner of a frame (made by tkinter)?</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks for your help</FONT></DIV> <DIV> </DIV></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_000C_01C0A6ED.9A6A6DA0-- From gruschow2@hotmail.com Wed Mar 7 16:39:49 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Wed, 07 Mar 2001 10:39:49 -0600 Subject: [Tutor] RE: Remco Gerlich's response to my plea for help with widgets and a clock Message-ID: <F220LHVbxZXAoirK6Ut00001b8c@hotmail.com> Remco's response was of some help. I will try what he says. My biggest problem is that I want to play with widgets and I cant find any good example programs to show me the proper format to use and etc. If any one knows of a site with good small programming examples using Tkinter and Widgets please let me know. Thank you Remco for responding to the message that I had posted. gruschow2@hotmail.com _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From tim@johnsons-web.com Wed Mar 7 17:22:07 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Wed, 7 Mar 2001 08:22:07 -0900 Subject: [Tutor] RE: Remco Gerlich's response to my plea for help with widgets and a clock References: <F220LHVbxZXAoirK6Ut00001b8c@hotmail.com> Message-ID: <0103070828510F.01754@shecom> Hello Charles: I'd like to put in a plug for some books: I'm a newbie and am really "biting the bullet" by both learning python and simultaneously designing a class in python: Also am totally new to tkinter .... 1)Alan Gauld's book: Learning Python etc.... Has an introduction to GUI programming with a case study using it. 2) Van Laningham : "Teach yourself Python in 24 Hours" goes into it in more depth. - the last third of the book is focused on tkinter 3)Grayson: Python and Tkinter programming is fully dedicated to the subject and is quite advanced. On Wed, 07 Mar 2001, Charles Gruschow wrote: > Remco's response was of some help. I will try what he says. My biggest > problem is that I want to play with widgets and I cant find any good example > programs to show me the proper format to use and etc. > > If any one knows of a site with good small programming examples using > Tkinter and Widgets please let me know. > > Thank you Remco for responding to the message that I had posted. > > gruschow2@hotmail.com > > > > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Wed Mar 7 17:29:12 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Wed, 7 Mar 2001 08:29:12 -0900 Subject: [Tutor] Read - Only Text? References: <E14acrz-0002sO-00@nautilus.shore.net> Message-ID: <0103070839230G.01754@shecom> Hi Michael: Thanks for the response and the mini tutorial. It's been a great help! I am now able automatically insert text and disable the entry of printable keystrokes. ====================================================== As it is now, non-printing keystrokes like backspace, delete and tab are still allowed, and I need to "stomp them out" also. ====================================================== I've included the code that I've written following my signature. I'm looking for documentation and code on this subject as well. Some questions are in the comments - Tim Johnson ----------- "My shroe, my shroe, my dingkom for a shroe" - Anonymous ####################################################### #!/usr/local/bin/python from Tkinter import * from ScrolledText import * import sys def quit(event): print "exit by button" sys.exit(0) def test(event): add_text("hello") def add_text(text): st.insert(END,text) # this _should_ bypass the event system and not add "a" to the text widget # added by Michael def add_a(event): # where is docs on this event object? There is much for me to # learn about the attributes, I think.... if event.keysym == 'a': #pass print "You typed 'a' but I won't add it." else: pass #event.widget.insert(END, event.keysym) main_window = Tk() text_frame = Canvas(main_window) text_frame.pack(expand=1,fill=BOTH,side=BOTTOM) q_button = Button(main_window,width=15) q_button["text"] = "Quit" q_button.bind("<Button>",quit) q_button.pack(side=LEFT) # as per Michael: # It appears that 'Text' references the unbinding of # of printable text # Next, I would like to be able to 'unbind' # Non-printing keystrokes, like delete, backspace # and TAB q_button.unbind_class('Text', '<Any-KeyPress>') q_button.unbind_class('Text', '<Any-KeyRelease>') ################################################## i_button = Button(main_window,width=15) i_button["text"] = "Test" i_button.bind("<Button>",test) i_button.pack(side=LEFT) ################################################## st = ScrolledText(text_frame ,background="white") st.bind('<KeyPress>', add_a) # per Michael st.pack() main_window.mainloop() From rickp@telocity.com Wed Mar 7 19:45:27 2001 From: rickp@telocity.com (rickp@telocity.com) Date: Wed, 7 Mar 2001 14:45:27 -0500 Subject: [Tutor] read-only Tkinter Entry Widget In-Reply-To: <Pine.LNX.4.21.0103060845040.13334-100000@hkn.eecs.berkeley.edu>; from dyoo@hkn.eecs.berkeley.edu on Tue, Mar 06, 2001 at 09:09:28AM -0800 References: <20010306.082702.-379881.0.sthickey@juno.com> <Pine.LNX.4.21.0103060845040.13334-100000@hkn.eecs.berkeley.edu> Message-ID: <20010307144527.F29306@tc.niof.net> On Tue, Mar 06, 2001 at 09:09:28AM -0800, Daniel Yoo wrote: > > The following code appears to be another way to do it: > > ### > from Tkinter import * > root = Tk() > mystr = StringVar() > entry = Entry(textvariable=mystr, state=DISABLED).pack(side=LEFT) > mystr.set('hello world') > mainloop() > ### > > Because the widget's disabled, it won't listen to any keys. However, it > still allows copy and paste. Tim, is this what you want? My email got disrupted so I'm coming in a little late. Several points. 1) The original question was about a *text* widget which does not support a textvariable. 2) Since DISABLE causes the widget not to listen to any keys, how is ctl-c supposed to work? I can still highlight with the mouse and then paste the highlighted section into another field using the mouse but I can't paste using ctl-v into another field. -- "Every person who puts money into the hands of a 'government' (so called), puts into its hands a sword which will be used against him, to extort more money from him, and also to keep him in subjection to its arbitrary will." -- Lysander Spooner Rick Pasotto email: rickp@telocity.com From gruschow2@hotmail.com Wed Mar 7 20:24:19 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Wed, 07 Mar 2001 14:24:19 -0600 Subject: [Tutor] Now where do I go from here in this program?????? Message-ID: <F25t2ireTUgAHbx4Rrn00001f42@hotmail.com> I want to repeat/refresh App so I get a continually running clock. Instead of one instance. This program so far works good but it only gives one instance in time. Charles Gruschow gruschow2@hotmail.com #!/usr/local/bin/python from Tkinter import * from time import * class App: def __init__(self, master): frame=Frame(master) frame.pack() self.button = Button(frame,text="Die Button",fg="red",command=frame.quit) self.button.pack() w=StringVar() self.label=Label(frame,textvariable=w) self.label.pack() def givetime(): a=localtime(time())[3:6] b=a[0],chr(58),a[1],chr(58),a[2] c=str(b[0])+str(b[1])+str(b[2])+str(b[3])+str(b[4]) d='Time is ' e=d+c return e w.set(givetime()) root=Tk() app=App(root) root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From arcege@shore.net Wed Mar 7 20:41:07 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 7 Mar 2001 15:41:07 -0500 (EST) Subject: [Tutor] Now where do I go from here in this program?????? In-Reply-To: <F25t2ireTUgAHbx4Rrn00001f42@hotmail.com> from Charles Gruschow at "Mar 7, 2001 2:24:19 pm" Message-ID: <E14akk7-0000Sq-00@nautilus.shore.net> > I want to repeat/refresh App so I get a continually running clock. Instead > of one instance. This program so far works good but it only gives one > instance in time. First, put the time setting functionality into a method, then using the widget's after() method, have that method called every second. class Spam(Label): images = ['bite00.xpm', 'bite01.xpm', 'bite02.xpm', 'bite00.xpm'] def __init__(self, master): self.imageno = 0 Label.__init__(self, master) self.take_a_bite() self.start_biting() def take_a_bite(self, event=None): self.config(bitmap=self.images[self.imageno]) # go the next image next time self.imageno = (self.imageno + 1) % len(self.images) def start_biting(self): self.after_id = self.after(1000, self.take_a_bite) def stop_biting_me(self): self.after_cancel(self.after_id) Spam(None).pack() You'd need images to for this example, but the principle should work the same for changing another label' text. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dyoo@hkn.eecs.berkeley.edu Wed Mar 7 22:58:15 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 7 Mar 2001 14:58:15 -0800 (PST) Subject: [Tutor] read-only Tkinter Entry Widget In-Reply-To: <20010307144527.F29306@tc.niof.net> Message-ID: <Pine.LNX.4.21.0103071454540.32330-100000@hkn.eecs.berkeley.edu> On Wed, 7 Mar 2001 rickp@telocity.com wrote: > > Because the widget's disabled, it won't listen to any keys. > However, it > still allows copy and paste. Tim, is this what you > want? > > My email got disrupted so I'm coming in a little late. > > Several points. > > 1) The original question was about a *text* widget which does not > support a textvariable. Whoops. I must remember the original problem. > 2) Since DISABLE causes the widget not to listen to any keys, how is > ctl-c supposed to work? I can still highlight with the mouse and then > paste the highlighted section into another field using the mouse but I > can't paste using ctl-v into another field. And I need to remember the platform too. On Unix, simply highlighting the text is enough to do the "copy" operation; I completely forgot about how copy/paste is done on Windows. My apologies. From alan.gauld@bt.com Wed Mar 7 23:23:17 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 7 Mar 2001 23:23:17 -0000 Subject: [Tutor] urgent!!!! I need help in Python 1.5.2 and Windows 98 ---->labels and clocks Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D60A@mbtlipnt02.btlabs.bt.co.uk> > I need help with widgets, labels, and clocks. You need to be more specific. What GUI toolkit do you want to use. Labels are usually considered to be a widget... If this is a homework assignment (or even if it isn't!) I suggest you try to solve it yourself and then ask specific questions about the specific problems you encounter. Assuming you want to use Tkinter as your toolkit visit the Tkinter focus area of the Python web site and read the tutorials referenced there. Alan G. From deirdre@deirdre.net Wed Mar 7 23:34:46 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Mar 2001 15:34:46 -0800 (PST) Subject: [Tutor] urgent!!!! I need help in Python 1.5.2 and Windows 98 ---->labels and clocks In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D60A@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <Pine.LNX.4.31.0103071531220.23066-100000@emperor.deirdre.org> On Wed, 7 Mar 2001 alan.gauld@bt.com wrote: > > I need help with widgets, labels, and clocks. > > You need to be more specific. > What GUI toolkit do you want to use. Labels are > usually considered to be a widget... Actually, he did say in the other email -- Tkinter. Even though I work a lot in tcl (ugh), I don't use Tk a lot so I can't help. However, the subject line *didn't* help because the question was neither Python 1.5.2 nor Windows 98 specific. For those of us who don't use Windows, we might ignore the question because of the subject when we might, if we read the whole message, know the answer. A "Help us Help you" hint: Use a relevant subject. :) > If this is a homework assignment (or even if it isn't!) I suggest you > try to solve it yourself and then ask specific questions about the > specific problems you encounter. Another "Help us Help you" hint: We have no idea, unless we know someone, what your coding skill is or what specifically you're having problems with. If you show us what you've tried, it's a lot easier for us. That way, we can try it ourselves. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From alan.gauld@bt.com Wed Mar 7 23:32:09 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 7 Mar 2001 23:32:09 -0000 Subject: [Tutor] data flow Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D60B@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0A75E.D45B1FC0 Content-type: text/plain; charset="iso-8859-1" What is a data flow model? A model of how data flows thru a system. In an order entry system order details will be captured from the customer and stored in a data form. Later those details will be passed to various order handling systems, stock control modules, billing and receipting systems etc. Drawing the various processes and systems as bubbles and the flow of data between them with arrows yieds a data flow model. (Actually theres a bit more to it than that but thats the idea.) You can then break down each top level process bubble and analyse how it manipulates its top level data inputs to generate its top level data outputs etc. Data stores represent files and databases etc and provide a link to the actual mdata definitions for a database etc. (Entity Relationships in technical terms) Check out any reasonable software engineering textbook for a more precise description. Data flows are very good at modelling typical business processes in a form suitable for turning into software systems. They are less good for designing the details of those systems. They are very poor at producing object oriented designs, although various people have produced heuristics for so doing... HTH Alan G. ------_=_NextPart_001_01C0A75E.D45B1FC0 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>What is a data flow model?</FONT></DIV> <DIV> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>A model of how data flows thru a system.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>In an order entry system order details will be captured from the customer and stored in a data form. Later those details will be passed to various order handling systems, stock control modules, billing and receipting systems etc. Drawing the various processes and systems as bubbles and the flow of data between them with arrows yieds a data flow model. (Actually theres a bit more to it than that but thats the idea.)</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>You can then break down each top level process bubble and analyse how it manipulates its top level data inputs to generate its top level data outputs etc.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>Data stores represent files and databases etc and provide a link to the actual mdata definitions for a database etc. (Entity Relationships in technical terms)</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>Check out any reasonable software engineering textbook for a more precise description.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>Data flows are very good at modelling typical business processes in a form suitable for turning into software systems. They are less good for designing the details of those systems. They are very poor at producing object oriented designs, although various people have produced heuristics for so doing...</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>HTH</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970541923-07032001>Alan G.</SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0A75E.D45B1FC0-- From joejava@dragoncat.net Thu Mar 8 00:53:46 2001 From: joejava@dragoncat.net (JRicker) Date: Wed, 7 Mar 2001 19:53:46 -0500 Subject: [Tutor] OOP Advice References: <Pine.LNX.4.21.0103070240160.14729-100000@hkn.eecs.berkeley.edu> Message-ID: <00eb01c0a76a$40805ca0$b3804cd8@ceo> From: "Daniel Yoo" <dyoo@hkn.eecs.berkeley.edu> : Hello! Ok, let's do a quick scan through your program. (Some of my code : assumes Python 1.52, so there are probably better ways of writing the code : if you're using a more recent version of Python.) I am using 2.0 but if I was to put it online at all my ISP is using Python 1.5(1 or 2) so I try and code for that when I can. : On Tue, 6 Mar 2001, JRicker wrote: : > XPos = -1 #x location of unit, -1 not on game board : > YPos = -1 #y loaction of unit, -1 not on game board : : In Python, you don't need to predeclare member variables. I'm guessing : that every Unit should their own separate XPos and YPos. What you have : right now defines a class variable XPos, YPos for all Units. : : Most likely, you don't need those two lines. Ok I think I can understand that. What I was thinking is that an unit that isn't on the board is stored on a ship (ie, A shuttle docked in a shuttle bay) hence the (-1,-1). I thinking I could do this: aship.bay[0] = Shuttle(shuttleatrributes). and later aship.launchshuttle(shuttlenumber) which does something like self.bay[0].pop() The code may not be completely correct, I don't have my python reference in front of me and I can't yet code without glancing it at it every few seconds to make sure I'm right but I think you can get the gist of what I'm saying. : > def ChangeFacing(self, d): : > if d == -1: : > if self.Facing == 1: : > self.Facing = 6 : > else: self.Facing = self.Facing - 1 : : There's a slightly nicer way of defining direction, but it involves using : angles and trigonometry. *shudder* Seriously though, it will help if you : use angles to define your facing direction. If we do so, then our move : function becomes a lot more direct and clean: Shudder is right. My advanced math is kind of weak and so I wouldn't come up with that on my own. I appreciate the tip. At the risk of keeping this a little offtopic, I have to ask, does anyone know how do a range function for a hex based map? : This assumes that self.Facing now represents the angle (in radians) where : the ship's directed at. Turning left or right, then, represents adding : and subtracting the quantity pi/2.0 (90 degrees) from the Facing. Math: : it's actually useful! *grin* I'm actually using a hex based map which means each direction is left to right 60 degrees. Will this still work? : > My question is this, Is there a way to set up the init function in unit : > to handle most of the initialization of the object and the rest done by : > the object? How do I structure things so that Unit is doing most of the : > work? : : Yes, Unit can itself have a constructor that does most of the work. This : way, when we make extensions to Unit, we can still initialize the Unitness : of an object. : : : If we have something like this, we can take advantage of it in our : inherited classes: : : So we can call our parent's initializer directly, passing it the : appropriate arguments. Nice. So basically the easiest way to plan this would be to work out the possible different kinds of varied types of units and decide what kinds share all the same thing, which share a few, etc and working it down to the smallest type of object. : Hope this helps! It does. Thanks! Joel From britt_green@hotmail.com Thu Mar 8 01:48:32 2001 From: britt_green@hotmail.com (Britt Green) Date: Wed, 07 Mar 2001 17:48:32 -0800 Subject: [Tutor] Stuck on Something Message-ID: <F449ByoykQMQ5MwIab7000238af@hotmail.com> >Message: 8 Date: Wed, 7 Mar 2001 01:07:11 -0700 From: David Porter To: >Python Tutor Subject: Re: [Tutor] Stuck on Something Organization: (a >Conspiracy) > >* Britt Green : > > > Hopefully that wasn't too vague. Any suggestions? > >#--- > >import string > >raw_dirs = """\ drwxrwx--- 2 restback privftp 512 Mar 6 21:23 >technicolorkitchen drwxrwx--- 2 restback privftp 512 Mar 6 21:58 >theclubhouse drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet >drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme""" > >dirs = [] raw_dirs = string.split(raw_dirs, '\n') for x in raw_dirs: >dirs.append(string.split(x)[-1]) > >print dirs Okay. I see what you're doing with this. Unfortunately, when I run this I get this error: >>> Traceback (innermost last): File "C:\Program Files\Python20\Code\anotherftpthing.py", line 22, in ? dirs.append(string.split(x)[-1]) IndexError: list index out of range I've been playing with this for the past couple hours, but haven't quite figured out how to get around this. Britt _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From gruschow2@hotmail.com Thu Mar 8 03:14:34 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Wed, 07 Mar 2001 21:14:34 -0600 Subject: [Tutor] still working on program. Also I don't understand Michael P. Reilly's response Message-ID: <F218F8HGmCvoXM7e0C900007bb2@hotmail.com> still working on program. Also I don't understand Michael P. Reilly's response I get the part of having to use after command or time.sleep, but I am not sure how to put it in. And how this will get the time instance to keep refreshing. I finally figured out how to do one instance thanks to Remco Gerlich's assistance. But how to keep instances going is the problem. The program so far follows: (Thank You, Charles Gruschow gruschow2@hotmail.com) #!/usr/local/bin/python from Tkinter import * from time import * class App: def __init__(self, master): frame=Frame(master) frame.pack() self.button = Button(frame,text="Die Button",fg="red",command=frame.quit) self.button.pack() w=StringVar() self.label=Label(frame,textvariable=w) self.label.pack() def givetime(): a=localtime(time())[3:6] b=a[0],chr(58),a[1],chr(58),a[2] c=str(b[0])+str(b[1])+str(b[2])+str(b[3])+str(b[4]) d='Time is ' e=d+c return e w.set(givetime()) root=Tk() app=App(root) root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From jcm@bigskytel.com Thu Mar 8 03:15:38 2001 From: jcm@bigskytel.com (David Porter) Date: Wed, 7 Mar 2001 20:15:38 -0700 Subject: [Tutor] Stuck on Something In-Reply-To: <F449ByoykQMQ5MwIab7000238af@hotmail.com>; from britt_green@hotmail.com on Wed, Mar 07, 2001 at 05:48:32PM -0800 References: <F449ByoykQMQ5MwIab7000238af@hotmail.com> Message-ID: <20010307201538.A5299@bigskytel.com> * Britt Green <britt_green@hotmail.com>: > >#--- > > > >import string > > > >raw_dirs = """\ drwxrwx--- 2 restback privftp 512 Mar 6 21:23 > >technicolorkitchen drwxrwx--- 2 restback privftp 512 Mar 6 21:58 > >theclubhouse drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet > >drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme""" > > > >dirs = [] raw_dirs = string.split(raw_dirs, '\n') for x in raw_dirs: > >dirs.append(string.split(x)[-1]) > > > >print dirs > > Okay. I see what you're doing with this. Unfortunately, when I run this I > get this error: > > >>> > Traceback (innermost last): > File "C:\Program Files\Python20\Code\anotherftpthing.py", line 22, in ? > dirs.append(string.split(x)[-1]) > IndexError: list index out of range Ah. This could be due to empty lines in raw_dirs. How about changing for x in raw_dirs: dirs.append(string.split(x)[-1]) TO for x in raw_dirs: try: dirs.append(string.split(x)[-1]) except IndexError: pass This *should* ignore any line without a directory. Another method will trim trailing and leading whitespace which might address the problem more directly. just add the line: raw_dirs = string.strip(raw_dirs) right before raw_dirs = string.split(raw_dirs, '\n') HTH, David From lumbricus@gmx.net Thu Mar 8 03:44:59 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Thu, 8 Mar 2001 04:44:59 +0100 (MET) Subject: [Tutor] Stuck on Something References: <F449ByoykQMQ5MwIab7000238af@hotmail.com> Message-ID: <15526.984023099@www24.gmx.net> > >Message: 8 Date: Wed, 7 Mar 2001 01:07:11 -0700 From: David Porter To: > >Python Tutor Subject: Re: [Tutor] Stuck on Something Organization: (a > >Conspiracy) > > > >* Britt Green : > > > > > Hopefully that wasn't too vague. Any suggestions? > > > >#--- > > > >import string > > > >raw_dirs = """\ drwxrwx--- 2 restback privftp 512 Mar 6 21:23 > >technicolorkitchen drwxrwx--- 2 restback privftp 512 Mar 6 21:58 > >theclubhouse drwxrwx--- 2 restback privftp 512 Mar 6 21:07 thirdstreet > >drwxrwx--- 2 restback privftp 512 Feb 27 11:18 thyme""" > > > >dirs = [] raw_dirs = string.split(raw_dirs, '\n') for x in raw_dirs: > >dirs.append(string.split(x)[-1]) > > > >print dirs > > Okay. I see what you're doing with this. Unfortunately, when I run this I > get this error: > > >>> > Traceback (innermost last): > File "C:\Program Files\Python20\Code\anotherftpthing.py", line 22, in ? > dirs.append(string.split(x)[-1]) > IndexError: list index out of range Hello !!! have you tried to slice this thing i.e. string.split(x)[-1:] ^^ grreetz Jö! > > I've been playing with this for the past couple hours, but haven't quite > figured out how to get around this. > > Britt > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From lumbricus@gmx.net Thu Mar 8 03:53:12 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Thu, 8 Mar 2001 04:53:12 +0100 (MET) Subject: [Tutor] conditional import Message-ID: <18292.984023592@www24.gmx.net> Hello!!! is there a way to import a module conditionally. I have (roughly) something like this: def print_dict(modul): import modul # here comes the error: no module print modul.__dict__ # named modul def main(): mod=raw_input("Enter module name\n> ") print_dict(mod) ########################### of course theres no module named modul but shouldn't it replace modul with the result from raw_input() ???? what am i missing? TIA n' Grrreetz Jö! -- Sent through GMX FreeMail - http://www.gmx.net From dyoo@hkn.eecs.berkeley.edu Thu Mar 8 03:56:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 7 Mar 2001 19:56:37 -0800 (PST) Subject: [Tutor] Stuck on Something [Truth, falsehood, tuples!] In-Reply-To: <20010307201538.A5299@bigskytel.com> Message-ID: <Pine.LNX.4.21.0103071943580.10074-100000@hkn.eecs.berkeley.edu> On Wed, 7 Mar 2001, David Porter wrote: > > File "C:\Program Files\Python20\Code\anotherftpthing.py", line 22, in ? > > dirs.append(string.split(x)[-1]) > > IndexError: list index out of range > > Ah. This could be due to empty lines in raw_dirs. How about changing > > for x in raw_dirs: > dirs.append(string.split(x)[-1]) > > TO > > for x in raw_dirs: > try: > dirs.append(string.split(x)[-1]) > except IndexError: > pass Let's drive home the point: ### >>> mystr = '' >>> l = string.split(mystr) >>> l [] >>> l[-1] Traceback (most recent call last): File "<stdin>", line 1, in ? IndexError: list index out of range ### I agree with David; this is probably the culprit. An alternative way to fix the problem could be: ### for x in raw_dirs: if string.strip(x): dirs.append(string.split(x)[-1]) ### which says to append x to our list of directories only if, when we lay that string bare, that there's still substance to it. In Python, the empty string, 0, the empty tuple, and the empty list are considered "false" values: ### >>> def isTrue(x): ... if x: return 1 ... else: return 0 ... >>> isTrue("") 0 >>> isTrue([]) 0 >>> isTrue([[]]) 1 ### But the big surprise I'm running into is this one: ### >>> isTrue(()) 0 >>> isTrue((())) 0 ### !! I can understand the empty tuple being false, but I can't rationalize why the tuple containing an empty tuple would be also false! Oh. Whoops. That's because (()) is not a tuple that contains the empty tuple. ### >>> isTrue(((),)) 1 ### False alarm, sorry. Gosh, I keep forgetting that tuples of one element need to be disambiguated with the comma --- otherwise, Python thinks that we're just trying to make a parenthesized expression. Went way off course on that one this time. *grin* From dyoo@hkn.eecs.berkeley.edu Thu Mar 8 04:00:38 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 7 Mar 2001 20:00:38 -0800 (PST) Subject: [Tutor] OOP Advice In-Reply-To: <00eb01c0a76a$40805ca0$b3804cd8@ceo> Message-ID: <Pine.LNX.4.21.0103071957190.10074-100000@hkn.eecs.berkeley.edu> On Wed, 7 Mar 2001, JRicker wrote: > Shudder is right. My advanced math is kind of weak and so I wouldn't > come up with that on my own. I appreciate the tip. At the risk of > keeping this a little offtopic, I have to ask, does anyone know how do a > range function for a hex based map? Clarification needed: do you mean "range" as in distance between points on a hex grid, or "range" as in a Python range object? ### >>> range(5) [0, 1, 2, 3, 4] ### Words, words, words. > I'm actually using a hex based map which means each direction is left > to right 60 degrees. Will this still work? We might need to be more careful; I didn't consider a hex map. Your other scheme, then, might be better. I was thinking of something free-floating. From aichele@mindspring.com Wed Mar 7 04:49:36 2001 From: aichele@mindspring.com (Steve A.) Date: Tue, 6 Mar 2001 20:49:36 -0800 Subject: [Tutor] networking basics Message-ID: <000a01c0a6c2$03b47c00$7001a8c0@sagga> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0A67E.F4BEA9C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello. I'm writing an applicaton that will be similar to ICQ in that it = will support P2P instant messages and fullduplex split-screen chats. =20 Problem: a month ago, I managed to get two machines talking to one = another simultaneously (fullduplex chat), but now I can't seem to figure out how I did it. argh! I 'get' the = basics of sockets and am familiar with the tutorials in most of the python books, but I can't find out how to do this simple = thing. Help! :-) Also, any suggestions about what to use and what to avoid as far as = setting up a network server with Python=20 would be *GREATLY* appreciated. thanks! stephen ------=_NextPart_000_0007_01C0A67E.F4BEA9C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hello. I'm writing an applicaton = that will be=20 similar to ICQ in that it will support P2P instant messages = and</FONT></DIV> <DIV><FONT face=3DArial size=3D2>fullduplex split-screen chats. = </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Problem: a month ago, I managed to get = two machines=20 talking to one another simultaneously (fullduplex chat),</FONT></DIV> <DIV><FONT face=3DArial size=3D2>but now I can't seem to figure out how = I did=20 it. argh! I 'get' the basics of sockets and am familiar with = the=20 tutorials</FONT></DIV> <DIV><FONT face=3DArial size=3D2>in most of the python books, but I = can't find out=20 how to do this simple thing. Help! :-)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Also, any suggestions about what to use = and what to=20 avoid as far as setting up a network server with Python </FONT></DIV> <DIV><FONT face=3DArial size=3D2>would be *GREATLY* = appreciated.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>thanks!</FONT></DIV> <DIV><FONT face=3DArial size=3D2>stephen</FONT></DIV></BODY></HTML> ------=_NextPart_000_0007_01C0A67E.F4BEA9C0-- From jcm@bigskytel.com Thu Mar 8 04:53:50 2001 From: jcm@bigskytel.com (David Porter) Date: Wed, 7 Mar 2001 21:53:50 -0700 Subject: [Tutor] conditional import In-Reply-To: <18292.984023592@www24.gmx.net>; from lumbricus@gmx.net on Thu, Mar 08, 2001 at 04:53:12AM +0100 References: <18292.984023592@www24.gmx.net> Message-ID: <20010307215350.A5667@bigskytel.com> * Jörg Wölke <lumbricus@gmx.net>: > is there a way to import a module conditionally. Yes. Use exception handling with a try statement: try: import modul except ImportError: pass This way, if the module cannot be found (i.e., an ImportError), no exception is raised. > I have (roughly) something like this: > > def print_dict(modul): > import modul # here comes the error: no module > print modul.__dict__ # named modul > > def main(): > mod=raw_input("Enter module name\n> ") > print_dict(mod) > > ########################### > of course theres no module named modul but > shouldn't it replace modul with the result from > raw_input() ???? No. import is literally searching for a module named modul in the search paths. It is not looking for a variable in Python. E.G., >>> sys = 'donuts' >>> print sys donuts >>> import sys >>> print sys <module 'sys' (built-in)> You would have to use something like exec to accomplish what you want: modul = 'rfc822' exec 'import '+modul HTH, David From toxx@post.com Thu Mar 8 06:10:00 2001 From: toxx@post.com (t.d) Date: Thu, 8 Mar 2001 01:10:00 -0500 (EST) Subject: [Tutor] baics of networking programming Message-ID: <391239414.984031800649.JavaMail.root@web394-mc> Hello people, Could you tell me where I can find good source on python programming for networking /basics/ sincerely, tur ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From scarblac@pino.selwerd.nl Thu Mar 8 06:32:06 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 8 Mar 2001 07:32:06 +0100 Subject: [Tutor] conditional import In-Reply-To: <18292.984023592@www24.gmx.net>; from lumbricus@gmx.net on Thu, Mar 08, 2001 at 04:53:12AM +0100 References: <18292.984023592@www24.gmx.net> Message-ID: <20010308073206.A12782@pino.selwerd.nl> On Thu, Mar 08, 2001 at 04:53:12AM +0100, Jörg Wölke wrote: > Hello!!! > > is there a way to import a module conditionally. > I have (roughly) something like this: > > def print_dict(modul): > import modul # here comes the error: no module > print modul.__dict__ # named modul > > def main(): > mod=raw_input("Enter module name\n> ") > print_dict(mod) > > ########################### > of course theres no module named modul but > shouldn't it replace modul with the result from > raw_input() ???? > what am i missing? Import doesn't take variables, only the real name of a module. For instance, it's import string instead of import "string" You can use the __import__ function which imports and returns a module: def print_dict(modulename): module = __import__(modulename) print module.__dict__ This loads any module by its name and calls it module locally. -- Remco Gerlich From lumbricus@gmx.net Thu Mar 8 06:37:04 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Thu, 8 Mar 2001 07:37:04 +0100 (MET) Subject: [Tutor] baics of networking programming References: <391239414.984031800649.JavaMail.root@web394-mc> Message-ID: <32057.984033424@www24.gmx.net> > Hello people, > > Could you tell me where I can find good source on python programming for > networking /basics/ > The Socket-Programming-HOWTO at python.org > sincerely, > tur > Tschö Jö! -- Sent through GMX FreeMail - http://www.gmx.net From deirdre@deirdre.net Thu Mar 8 07:24:30 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Mar 2001 23:24:30 -0800 (PST) Subject: [Tutor] baics of networking programming In-Reply-To: <391239414.984031800649.JavaMail.root@web394-mc> Message-ID: <Pine.LNX.4.31.0103072323540.25218-100000@emperor.deirdre.org> On Thu, 8 Mar 2001, t.d wrote: > Could you tell me where I can find good source on python programming > for networking /basics/ Basically, the python interfaces are very similar to the C interfaces. If you want to do something specific, ask about what you want to do and we'll try and help. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From toxx@post.com Thu Mar 8 07:35:32 2001 From: toxx@post.com (t.d) Date: Thu, 8 Mar 2001 02:35:32 -0500 (EST) Subject: [Tutor] baics of networking programming Message-ID: <384237387.984036932422.JavaMail.root@web577-mc> Dear lumbricus, I know where is this how-to, but it seems to me that it is a direction for people who already know how to programm in networking already. sincerely, ------Original Message------ From: =3D?ISO-8859-1?Q?J=3DF6rg_W=3DF6lke?=3D <lumbricus@gmx.net> To: tutor@python.org Sent: March 8, 2001 6:37:04 AM GMT Subject: Re: [Tutor] baics of networking programming > Hello people, > > Could you tell me where I can find good source on python programming for > networking /basics/ > The Socket-Programming-HOWTO at python.org > sincerely, > tur > Tsch=81EJ=81E -- Sent through GMX FreeMail - http://www.gmx.net _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=3Dsignup From scarblac@pino.selwerd.nl Thu Mar 8 07:36:12 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 8 Mar 2001 08:36:12 +0100 Subject: [Tutor] networking basics In-Reply-To: <000a01c0a6c2$03b47c00$7001a8c0@sagga>; from aichele@mindspring.com on Tue, Mar 06, 2001 at 08:49:36PM -0800 References: <000a01c0a6c2$03b47c00$7001a8c0@sagga> Message-ID: <20010308083612.A12907@pino.selwerd.nl> On Tue, Mar 06, 2001 at 08:49:36PM -0800, Steve A. wrote: > Problem: a month ago, I managed to get two machines talking to one another > simultaneously (fullduplex chat), but now I can't seem to figure out how I > did it. Look at Demo/sockets/unixserver.py and unixclient.py for the 'Hello World' of sending something from a client to a server over sockets. To do this both ways I think you need to set up threads too, and I don't know them well enough to explain here, and I have to start working anyway... -- Remco Gerlich From deirdre@deirdre.net Thu Mar 8 07:41:12 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Mar 2001 23:41:12 -0800 (PST) Subject: [Tutor] baics of networking programming In-Reply-To: <384237387.984036932422.JavaMail.root@web577-mc> Message-ID: <Pine.LNX.4.31.0103072339530.25218-100000@emperor.deirdre.org> On Thu, 8 Mar 2001, t.d wrote: > I know where is this how-to, but it seems to me that it is a direction for > people who already know how to programm in networking already. OK. Can you tell us what specifically you'd like to do? Networking is a vast topic. I presume you mean TCP/IP related stuff and not some other type of protocol. But what you want to do really is the fundamental question. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From toxx@post.com Thu Mar 8 07:41:32 2001 From: toxx@post.com (t.d) Date: Thu, 8 Mar 2001 02:41:32 -0500 (EST) Subject: [Tutor] baics of networking programming Message-ID: <388891910.984037292045.JavaMail.root@web577-mc> Dear Deirdre Saoirse, Thank you for your reply. But before something to do I would like to understand basic of structure, since i sayd about basics on networking programming in general sincerely, tur ------Original Message------ From: Deirdre Saoirse <deirdre@deirdre.net> To: "t.d" <toxx@post.com> Sent: March 8, 2001 7:24:30 AM GMT Subject: Re: [Tutor] baics of networking programming On Thu, 8 Mar 2001, t.d wrote: > Could you tell me where I can find good source on python programming > for networking /basics/ Basically, the python interfaces are very similar to the C interfaces. If you want to do something specific, ask about what you want to do and we'll try and help. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From deirdre@deirdre.net Thu Mar 8 07:48:05 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Mar 2001 23:48:05 -0800 (PST) Subject: [Tutor] networking basics In-Reply-To: <000a01c0a6c2$03b47c00$7001a8c0@sagga> Message-ID: <Pine.LNX.4.31.0103072341340.25218-100000@emperor.deirdre.org> On Tue, 6 Mar 2001, Steve A. wrote: > Hello. I'm writing an applicaton that will be similar to ICQ in that > it will support P2P instant messages and fullduplex split-screen > chats. OK. > Problem: a month ago, I managed to get two machines talking to one > another simultaneously (fullduplex chat), but now I can't seem to > figure out how I did it. argh! I 'get' the basics of sockets and am > familiar with the tutorials in most of the python books, but I can't > find out how to do this simple thing. Help! :-) Well, a server waits for a connection on a port and a client connects to that port. That's the basics. > Also, any suggestions about what to use and what to avoid as far as > setting up a network server with Python would be *GREATLY* > appreciated. I've only done little networking projects, but I think my very stupid server and client are on the Useless Python pages. :) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From toxx@post.com Thu Mar 8 07:48:21 2001 From: toxx@post.com (t.d) Date: Thu, 8 Mar 2001 02:48:21 -0500 (EST) Subject: [Tutor] baics of networking programming Message-ID: <387188197.984037701164.JavaMail.root@web597-mc> Dear Deirdre Saoirse , Yes, it is TCP/IP related thing, thank you for your advice. ------Original Message------ From: Deirdre Saoirse <deirdre@deirdre.net> To: "t.d" <toxx@post.com> Sent: March 8, 2001 7:41:12 AM GMT Subject: Re: [Tutor] baics of networking programming On Thu, 8 Mar 2001, t.d wrote: > I know where is this how-to, but it seems to me that it is a direction for > people who already know how to programm in networking already. OK. Can you tell us what specifically you'd like to do? Networking is a vast topic. I presume you mean TCP/IP related stuff and not some other type of protocol. But what you want to do really is the fundamental question. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From deirdre@deirdre.net Thu Mar 8 07:51:48 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Mar 2001 23:51:48 -0800 (PST) Subject: [Tutor] baics of networking programming In-Reply-To: <388891910.984037292045.JavaMail.root@web577-mc> Message-ID: <Pine.LNX.4.31.0103072348250.25218-100000@emperor.deirdre.org> On Thu, 8 Mar 2001, t.d wrote: > Thank you for your reply. But before something to do I would like to > understand basic of structure, since i sayd about basics on networking > programming in general Then there's only one book I can recommend. OK, it's a pair of books: Richard Stevens, Network Programming Volume 1 (ISBN 013490012X) and Volume 2 (ISBN 0130810819). The two cost almost $150 between them, but if that's the subject you want to learn, that's where to learn it. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kojo@tamu.edu Thu Mar 8 08:12:56 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Thu, 08 Mar 2001 02:12:56 -0600 Subject: [Tutor] basics of networking programming In-Reply-To: <Pine.LNX.4.31.0103072323540.25218-100000@emperor.deirdre.o rg> References: <391239414.984031800649.JavaMail.root@web394-mc> Message-ID: <5.0.2.1.0.20010308020915.021a7950@pop3.norton.antivirus> Hey, while we're on the subject, I got an idea from what Deirdre said below. I'm taking a Networking class now (and it's killing me!) where we're doing socket programming in C (which I'm not very familiar with). Would it be helpful to me to learn how to do similar stuff in Python (which I'm more familiar with and I find easier to learn/get help with)? I've got Vol. 1 of the Stevens book already, but I think it's my weak C skills that are holding me back. Any input is appreciated. Thanks, At 11:24 PM 3/7/01 -0800, Deirdre Saoirse wrote: >Basically, the python interfaces are very similar to the C interfaces. If >you want to do something specific, ask about what you want to do and we'll >try and help. > >-- >_Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net >"I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** From deirdre@deirdre.net Thu Mar 8 08:21:54 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 8 Mar 2001 00:21:54 -0800 (PST) Subject: [Tutor] basics of networking programming In-Reply-To: <5.0.2.1.0.20010308020915.021a7950@pop3.norton.antivirus> Message-ID: <Pine.LNX.4.31.0103080019230.25218-100000@emperor.deirdre.org> On Thu, 8 Mar 2001, Kojo Idrissa wrote: > Hey, while we're on the subject, I got an idea from what Deirdre said > below. I'm taking a Networking class now (and it's killing me!) where > we're doing socket programming in C (which I'm not very familiar > with). Would it be helpful to me to learn how to do similar stuff in > Python (which I'm more familiar with and I find easier to learn/get > help with)? > > I've got Vol. 1 of the Stevens book already, but I think it's my weak > C skills that are holding me back. > > Any input is appreciated. Thanks, Actually, it might be helpful to have a sort of a project-based "class" on the list -- sort of a "work along with Stevens" for those who are interested. It might warrant an additional list if there's so much interest that it overwhelms this list. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kojo@tamu.edu Thu Mar 8 08:26:53 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Thu, 08 Mar 2001 02:26:53 -0600 Subject: [Tutor] basics of networking programming In-Reply-To: <Pine.LNX.4.31.0103080019230.25218-100000@emperor.deirdre.o rg> References: <5.0.2.1.0.20010308020915.021a7950@pop3.norton.antivirus> Message-ID: <5.0.2.1.0.20010308022236.02209b80@pop3.norton.antivirus> --=====================_13641731==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed That's sort of my problem...I've got a projects based class now, and I don't know what the hell I'm doing!! :-) Seriously, I understand most of it conceptually, it's the "how to do this in C" part that's giving me problems. Your comment that the Python network interfaces are similar to the ones in C lit a spark of hope in my otherwise frazzled mind. I can talk to my prof. and see if he'd mind us using the stuff we do in class for the list. So far, it's been * Modify this TCP Server and Client code and add some timestamping so you can measure performance at different packet sizes * Similar to above, but with UDP Server and Client (that's due Saturday...Ugh) At 12:21 AM 3/8/01 -0800, Deirdre Saoirse wrote: >On Thu, 8 Mar 2001, Kojo Idrissa wrote: > > > Hey, while we're on the subject, I got an idea from what Deirdre said > > below. I'm taking a Networking class now (and it's killing me!) where > > we're doing socket programming in C (which I'm not very familiar > > with). Would it be helpful to me to learn how to do similar stuff in > > Python (which I'm more familiar with and I find easier to learn/get > > help with)? > > > > I've got Vol. 1 of the Stevens book already, but I think it's my weak > > C skills that are holding me back. > > > > Any input is appreciated. Thanks, > >Actually, it might be helpful to have a sort of a project-based "class" on >the list -- sort of a "work along with Stevens" for those who are >interested. It might warrant an additional list if there's so much >interest that it overwhelms this list. > >-- >_Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net >"I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** --=====================_13641731==_.ALT Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html> That's sort of my problem...I've got a projects based class now, and I don't know what the hell I'm doing!!<br> :-)<br> <br> Seriously, I understand most of it conceptually, it's the "how to do this in C" part that's giving me problems. Your comment that the Python network interfaces are similar to the ones in C lit a spark of hope in my otherwise frazzled mind.<br> <br> I can talk to my prof. and see if he'd mind us using the stuff we do in class for the list. So far, it's been <ul> <li>Modify this TCP Server and Client code and add some timestamping so you can measure performance at different packet sizes <li>Similar to above, but with UDP Server and Client (that's due Saturday...Ugh) </ul><br> <br> At 12:21 AM 3/8/01 -0800, Deirdre Saoirse wrote:<br> <blockquote type=3Dcite class=3Dcite cite>On Thu, 8 Mar 2001, Kojo Idrissa wrote:<br> <br> > Hey, while we're on the subject, I got an idea from what Deirdre said<br> > below. I'm taking a Networking class now (and it's killing me!) where<br> > we're doing socket programming in C (which I'm not very familiar<br> > with). Would it be helpful to me to learn how to do similar stuff in<br> > Python (which I'm more familiar with and I find easier to learn/get<br> > help with)?<br> ><br> > I've got Vol. 1 of the Stevens book already, but I think it's my weak<br> > C skills that are holding me back.<br> ><br> > Any input is appreciated. Thanks,<br> <br> Actually, it might be helpful to have a sort of a project-based "class" on<br> the list -- sort of a "work along with Stevens" for those who are<br> interested. It might warrant an additional list if there's so much<br> interest that it overwhelms this list.<br> <br> --<br> _Deirdre NEW Stash-o-Matic: <a href=3D"http://fuzzyorange.com=A0/" eudora=3D"autourl">http://fuzzyorange= .com </a> <a href=3D"http://deirdre.net/" eudora=3D"autourl">http://deirdre.net</a><br= > "I love deadlines. I like the whooshing sound they make as they fly by."<br> &nbs= p; &n= bsp; = &nbs= p; - Douglas Adams</blockquote> <x-sigsep><p></x-sigsep> **************************** <br> Kojo Idrissa <br> KPMG Scholar <br> Accounting Doctoral Student <br> Texas A&M University <br> <br> Kojo@tamu.edu <br> 401M Wehner Bldg. <br> 979-862-2726 <br> ****************************</html> --=====================_13641731==_.ALT-- From Sascharrer@aol.com Thu Mar 8 13:42:05 2001 From: Sascharrer@aol.com (Sascharrer@aol.com) Date: Thu, 8 Mar 2001 08:42:05 EST Subject: [Tutor] GUI Apps Message-ID: <fd.3532169.27d8e62d@aol.com> Thanks a lot for answering my question! From rickp@telocity.com Thu Mar 8 14:54:29 2001 From: rickp@telocity.com (rickp@telocity.com) Date: Thu, 8 Mar 2001 09:54:29 -0500 Subject: [Tutor] insert problem using gadfly Message-ID: <20010308095429.G29306@tc.niof.net> How can I insert a string that contains newlines into a gadfly database? The docs say that most anything (ie, string, tuple, list, etc) can be put in a varchar field so why does gadfly look at the contents of a string? I could understand having to escape embedded quotes but not embedded newlines. Here is some example code: import gadfly try: conn = gadfly.gadfly('test_db','gadfly') curs = conn.cursor() except: conn = gadfly.gadfly() conn.startup('test_db','gadfly') curs = conn.cursor() curs.execute('create table tstab (id integer, txt varchar)') id = 1 txt = 'this is a single line of text' sql = "insert into tstab (id,txt) values ('%s','%s')" % (id,txt) curs.execute(sql) print "successfully inserted a single line of text" # the program works this far id = 2 txt = """this is multiple lines of text""" sql = "insert into tstab (id,txt) values ('%s','%s')" % (id,txt) curs.execute(sql) # at this point I get the following traceback: Traceback (innermost last): File "./tstdb.py", line 25, in ? curs.execute(sql) File "/usr/lib/python1.5/site-packages/gadfly.py", line 322, in execute cs = self.commands = sql.DoParse1(statement, context) File "/usr/lib/python1.5/site-packages/kjParser.py", line 1175, in DoParse1 return self.DoParse(String, Context, DoReductions)[0] File "/usr/lib/python1.5/site-packages/kjParser.py", line 1167, in DoParse ParseResult = ParseOb.GO() File "/usr/lib/python1.5/site-packages/kjParser.py", line 832, in GO self.DoOneReduction() File "/usr/lib/python1.5/site-packages/kjParser.py", line 725, in DoOneReduction tokenVal = Stream.getmember() File "/usr/lib/python1.5/site-packages/kjParser.py", line 562, in getmember (Token,skip) = self.LexDict.Token(self.String, self.Position) File "/usr/lib/python1.5/site-packages/kjParser.py", line 427, in Token raise LexTokenError, "Lexical token not found "+info LexTokenError: Lexical token not found near :: "t) values ('2',"*"'this is\012multip" -- "So long as the power-seekers clung to the basic premises of the welfare state, holding need as the criterion of rewards, logic forced them, step by step, to champion the interests of the less & less productive... until they reached the ultimate dead end of turning from the role of champions of 'honest toil' to the role of champions of open parasitism, parasitism on principle, parasitism as a 'right'." -- Ayn Rand "A PreView" _The Ayn Rand Letter_ Rick Pasotto email: rickp@telocity.com From jsp@opencom.de Thu Mar 8 15:40:02 2001 From: jsp@opencom.de (=?iso-8859-1?Q?J=F6rg_Sporer?=) Date: Thu, 8 Mar 2001 16:40:02 +0100 Subject: [Tutor] Coordinates of a frame Message-ID: <000001c0a7e6$0b43c000$3701000a@arthur> SG93IGNhbiBpIGRlZmluZSB3aGVyZSBhIGZyYW1lIGlzIGNyZWF0ZWQgKFgsWSBDb29yZGluYXRl cyBpcyBpbnRlZ2Vycyk/DQoNClRoYW5rcyBmb3IgeW91ciBoZWxwIQ0KSvZyZw0KDQo= From Greg.Furmanek@hit.cendant.com Thu Mar 8 16:30:37 2001 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Thu, 8 Mar 2001 11:30:37 -0500 Subject: [Tutor] xml stuff Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9D35@hit-phx-mail-3.hfscorp.com> I seem to have problem with xml. When I tried to run some examples the interpreter is giving me a message Traceback (most recent call last): File "try1.py", line 28, in ? import pyexpat ImportError: No module named pyexpat I am using py 2.0 On Sun. is there a problem with xml libs in this version??? some code. *************************************** START ************************** from xml.sax import saxutils from xml.sax import make_parser from xml.sax.handler import feature_namespaces import pyexpat string = """ <collection> <comic title="Sandman" number='62'> <writer>Neil Gaiman</writer> <penciller pages='1-9,18-24'>Glyn Dillon</penciller> <penciller pages="10-17">Charles Vess</penciller> </comic> </collection> """ # ............................... FUNCTIONS ............................... def main(): # Create a parser parser = make_parser() # Tell the parser we are not interested in XML namespaces parser.setFeature(feature_namespaces, 0) # Create the handler dh = FindIssue('Sandman', '62') # Tell the parser to use our handler parser.setContentHandler(dh) # Parse the input parser.parse(file) # ................................ CLASSES ................................ # ............................ EXECUTION START ............................ if __name__ == "__main__": main() *************************************** START ************************** Grzegorz Furmanek Furmanek.Greg@hit.cendant.com ---------------------------------------------------------- Three Mile Island '79 Chernobyl '86 Windows '00 (1900) "The sender believes that this E-mail and any attachments were free of any virus, worm, Trojan horse, and/or malicious code when sent. This message and its attachments could have been infected during transmission. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective and remedial action about viruses and other defects. The sender's employer is not liable for any loss or damage arising in any way from this message or its attachments." From arcege@shore.net Thu Mar 8 16:49:32 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 8 Mar 2001 11:49:32 -0500 (EST) Subject: [Tutor] Coordinates of a frame In-Reply-To: <000001c0a7e6$0b43c000$3701000a@arthur> from "[J_rg Sporer]" at "Mar 8, 2001 4:40: 2 pm" Message-ID: <E14b3bY-00026Z-00@nautilus.shore.net> [Charset iso-8859-1 unsupported, filtering to ASCII...] > How can i define where a frame is created (X,Y Coordinates is integers)? > > Thanks for your help! > J_rg Do you mean with Tkinter? I'll assume so. You would use the place() methods (instead of pack()). With this geometry manager, you can position widgets absolutely, or relative to another widget (for example, centered in another widget). >>> from Tkinter import * >>> root =Tk() >>> pane = Frame(root) >>> Label(pane, text="Pane Title", bg="red").pack() >>> b = Button(pane, width=12, height=12, text="Go!") >>> # place the top-right corner (NE) at (-2,2) within the frame >>> b.place(relx=1,x=-2,y=2, anchor=NE) >>> pane.pack() You'll see the red in the background from the Label widget. The Button is placed over it. >>> b.lower() # you'll see the "Pane Title" appear >>> b.lift() # you'll see the Button come back to the foreground You might want to look at Fredrik Lundh's "An Introduction to Tkinter" <URL: http://www.pythonware.com/library/tkinter/introduction/> and Grayson's "Python and Tkinter Programming" book. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From gruschow2@hotmail.com Thu Mar 8 18:07:38 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Thu, 08 Mar 2001 12:07:38 -0600 Subject: [Tutor] thanks Remco Gerlich & Michael P. Reilly,have program but still have problems Message-ID: <F233gIu3q1vblaLJPv000002ccc@hotmail.com> thanks Remco Gerlich & Michael P. Reilly,have program but still have problems I do apologize for miswording my posts to this forum. I did go through help files and attempt to do what I wanted to do before asking. I was just confused, that's all. (btw, I have been playing with Python for a long time now, off and on, there are just a lot of things I am confused by, but I do try to figure things out all by myself all the time, I don't like to bother people.) My program so far can do one instance in time so far. I am still having trouble with getting a steady flow of instances in time. (I mean so clock repeats itself instead of only giving time out once.) My program follows (and after that ?'s about Michael P. Reilly's response): Thank you, Charles Gruschow (gruschow2@hotmail.com) #!/usr/local/bin/python from Tkinter import * from time import * class App: def __init__(self, master): frame=Frame(master) frame.pack() self.button = Button(frame,text="Die Button",fg="red",command=frame.quit) self.button.pack() w=StringVar() self.label=Label(frame,textvariable=w) self.label.pack() def givetime(): a=localtime(time())[3:6] b=a[0],chr(58),a[1],chr(58),a[2] c=str(b[0])+str(b[1])+str(b[2])+str(b[3])+str(b[4]) d='Time is ' e=d+c return e w.set(givetime()) root=Tk() app=App(root) root.mainloop() *************THE FOllowing is what Michael P. Reilly responded and I am not quite sure how to apply this to my program, but I see what he is doing (I think). ************************************** [ >I want to repeat/refresh App so I get a continually running clock. Instead >of one instance. This program so far works good but it only gives one >instance in time. First, put the time setting functionality into a method, then using the widget's after() method, have that method called every second. class Spam(Label): images = ['bite00.xpm', 'bite01.xpm', 'bite02.xpm', 'bite00.xpm'] def __init__(self, master): self.imageno = 0 Label.__init__(self, master) self.take_a_bite() self.start_biting() def take_a_bite(self, event=None): self.config(bitmap=self.images[self.imageno]) # go the next image next time self.imageno = (self.imageno + 1) % len(self.images) def start_biting(self): self.after_id = self.after(1000, self.take_a_bite) def stop_biting_me(self): self.after_cancel(self.after_id) Spam(None).pack() You'd need images to for this example, but the principle should work the same for changing another label' text. -Arcege ] I am not quite sure how to apply what Michael is saying so I can refresh my label(s) after a certain period of time. Thank you, Charles Gruschow gruschow2@hotmail.com _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From alan.gauld@bt.com Thu Mar 8 18:02:18 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 8 Mar 2001 18:02:18 -0000 Subject: [Tutor] baics of networking programming Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D60F@mbtlipnt02.btlabs.bt.co.uk> > understand basic of structure, since i sayd about basics > on networking programming in general OK, I'll make a start, tell us whether you want more or less detail(probably more!) Network programming is about getting two processes to communicate over a network. The normal way to do that is to use a socket(its possible to use more advanced mechanisms like CORBA, DCOM and RPCs but I'll ignore them for now, they usually use sockets underneath anyway). A socket can be thought of like a physical socket where the wire plugs in. Thus imagine a bit of wire between the two boxes each end connected to a socket. One process writes data to its socket and the receiving process monitors the socket for incoming data. The format of the data sent is dependant on the protocol used, the most common protocols for our purposes being UDP and TCP/IP. Usually it won't make much difference to you - provided you use the same protocol at both ends! To make a connection you open a socket and either read from it(listen()) or write to it. The simplest possible Python code for doing this is contained in the Python documentation as already indicated. Anything more specific? Alan G From alan.gauld@bt.com Thu Mar 8 18:10:22 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 8 Mar 2001 18:10:22 -0000 Subject: [Tutor] Coordinates of a frame Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D610@mbtlipnt02.btlabs.bt.co.uk> > How can i define where a frame is created (X,Y Coordinates is > integers)? Assuming you are using Tkinter the general answer is you don't, you leave it all to Tkinter. I'm guessing you come from a Windoze background where everything gets specified in coordinates? In Tk its best to let the geometry manager look after everything. Once you get over the culture shock its a much better way to program GUIs If my assumption is wrong try asking again with a bit of background about what exactly you want to do... Alan G From alan.gauld@bt.com Thu Mar 8 18:16:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 8 Mar 2001 18:16:45 -0000 Subject: [Tutor] xml stuff Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D611@mbtlipnt02.btlabs.bt.co.uk> > Traceback (most recent call last): > File "try1.py", line 28, in ? > import pyexpat > ImportError: No module named pyexpat Can't help with this except that I thought you didn't need to import explicitly, it was handled by make_parser() > string = """ > <collection> > <comic title="Sandman" number='62'> > <writer>Neil Gaiman</writer> > <penciller pages='1-9,18-24'>Glyn Dillon</penciller> > <penciller pages="10-17">Charles Vess</penciller> > </comic> > </collection> > """ > # Parse the input > parser.parse(file) Shouldn't this be the string vewrsion of parse not the file version? Just a thought... Alan G From Glen@ihello-inc.com Thu Mar 8 20:32:04 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Thu, 8 Mar 2001 12:32:04 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A45F@go.ihello.com> Hi all, I have what I hope is a very easy question. I need to save the results of a command to a variable but I am not sure how to go about doing it. This is what I have done so far: >>>import os >>>test = os.system('cut --character=5- ActsAutomation,ihello,com') When I do this, it runs the command properly and prints the output to the screen. However when I: >>>print test >>>0 It does not save the output of the command to test. It only saves 0. What am I doing wrong? This is the default install of python on Mandrake 7.2. Thanks Glen Bunting From kwindus@hotmail.com Thu Mar 8 20:36:16 2001 From: kwindus@hotmail.com (Karen Windus) Date: Thu, 08 Mar 2001 20:36:16 Subject: [Tutor] Changing lines in a set of files Message-ID: <F206t3HvoFOAmEaJswF00003e70@hotmail.com> Hi - I've been wrestling with this problem for about a week now (I'm a newbie). I want to open a series of files from a directory, matchand replace a substring in the files and then (here's the tricky part for me) save and close the files. This script works, until I introduced the input and output file objects. I'm not so sure how the input and output files work. Here's what I have so far: #! /usr/bin/env python import string, sys, fileinput # take the first argument out of sys.argv and assign it to searchterm searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:] inputfiles, outputfiles = fileinput.input() for inputfilename in inputfilenames: for line in fileinput.input(): num_matches = string.count(line, searchterm) new_string = string.replace(line,searchterm,"Feedback") if num_matches: inputfile = open(fileinput.filename(), 'r') new_string = string.replace(line,searchterm,"Feedback") print new_string # a nonzero count means there was a match print "found '%s' %d times in %s on line %d." % (searchterm, num_matches, fileinput.filename(), fileinput.filelineno()) outputfiles=open(fileinput.filename(),'w') write_results(outputfiles) fileinput.nextfile() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Thu Mar 8 20:41:18 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 8 Mar 2001 12:41:18 -0800 (PST) Subject: [Tutor] xml stuff In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D611@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <Pine.LNX.4.21.0103081238580.3499-100000@hkn.eecs.berkeley.edu> On Thu, 8 Mar 2001 alan.gauld@bt.com wrote: > > > Traceback (most recent call last): > > File "try1.py", line 28, in ? > > import pyexpat > > ImportError: No module named pyexpat As of Python 2.0, the pyexpat module has been renamed to xml.parsers.expat: http://python.org/doc/current/lib/module-xml.parsers.expat.html So you'll need to write the slightly longer: import xml.parsers.expat instead. There's an example of using it here: http://python.org/doc/current/lib/expat-example.html Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu Mar 8 20:48:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 8 Mar 2001 12:48:26 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A45F@go.ihello.com> Message-ID: <Pine.LNX.4.21.0103081243130.3499-100000@hkn.eecs.berkeley.edu> On Thu, 8 Mar 2001, Glen Bunting wrote: > I have what I hope is a very easy question. I need to save the > results of a command to a variable but I am not sure how to go about > doing it. This is what I have done so far: > > >>>import os > >>>test = os.system('cut --character=5- ActsAutomation,ihello,com') The os.system() function returns the "errorlevel" of its command, which is often different from its printed output. (This errorlevel value is useful when you're writing shell scripts that check for the success or failure of a command.) That's where the zero is coming from. What you'll want to use instead is os.popen(), which gives us a "file"-like object. From this, we can read off the program's output. For example: ### >>> import os >>> output = os.popen('ls *.txt').read() >>> print output indrel.txt list.txt rules.txt sentenceword.txt ### will call the ls command, get the file, read() off all of its string contents, and store that into our output. If you have more questions, please feel free to ask us. From Greg.Furmanek@hit.cendant.com Thu Mar 8 21:03:30 2001 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Thu, 8 Mar 2001 16:03:30 -0500 Subject: [Tutor] xml stuff Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9D3B@hit-phx-mail-3.hfscorp.com> Ok I have used the expat stuff and I get some strange results: Character data: [u' '] Start element: [PRICE] [{}] Character data: [u'$7.06'] End element: [PRICE] Character data: [u'\012'] Character data: [u' '] Start element: [AVAILABILITY] [{}] Character data: [u'052599'] End element: [AVAILABILITY] Character data: [u'\012'] Character data: [u' '] End element: [PLANT] Character data: [u'\012'] Character data: [u' '] Character data: [u'\012'] End element: [CATALOG] when parsing some stuff I get these u characters. Is this normal. code follows: from xml.parsers import expat def start_element(name, attrs): print 'Start element: [%s] [%s]' % ( name, attrs) def end_element(name): print 'End element: [%s]' % ( name ) def char_data(data): print 'Character data: [%s]' % ( repr(data) ) # ............................... FUNCTIONS ............................... def main(): p = expat.ParserCreate() p.StartElementHandler = start_element p.EndElementHandler = end_element p.CharacterDataHandler = char_data p.Parse( """<?xml version="1.0"?> <CATALOG> <PLANT> <COMMON>Butterfly Weed</COMMON> <BOTANICAL>Asclepias tuberosa</BOTANICAL> <ZONE>Annual</ZONE> <LIGHT>Sunny</LIGHT> <PRICE>$2.78</PRICE> <AVAILABILITY>063099</AVAILABILITY> </PLANT> <PLANT> <COMMON>Cinquefoil</COMMON> <BOTANICAL>Potentilla</BOTANICAL> <ZONE>Annual</ZONE> <LIGHT>Shade</LIGHT> <PRICE>$7.06</PRICE> <AVAILABILITY>052599</AVAILABILITY> </PLANT> </CATALOG>""") # ................................ CLASSES ................................ # ............................ EXECUTION START ............................ if __name__ == "__main__": main() "The sender believes that this E-mail and any attachments were free of any virus, worm, Trojan horse, and/or malicious code when sent. This message and its attachments could have been infected during transmission. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective and remedial action about viruses and other defects. The sender's employer is not liable for any loss or damage arising in any way from this message or its attachments." From tim@johnsons-web.com Thu Mar 8 21:20:13 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Thu, 8 Mar 2001 12:20:13 -0900 Subject: [Tutor] basics of networking programming/Class Project References: <Pine.LNX.4.31.0103080019230.25218-100000@emperor.deirdre.org> Message-ID: <01030811270601.04114@shecom> Hello: On Wed, 07 Mar 2001, you wrote: > On Thu, 8 Mar 2001, Kojo Idrissa wrote: > > > Hey, while we're on the subject, I got an idea from what Deirdre said > > below. I'm taking a Networking class now (and it's killing me!) where > > we're doing socket programming in C (which I'm not very familiar > > with). Would it be helpful to me to learn how to do similar stuff in > > Python (which I'm more familiar with and I find easier to learn/get > > help with)? <snip--> > > Actually, it might be helpful to have a sort of a project-based "class" on > the list -- sort of a "work along with Stevens" for those who are > interested. It might warrant an additional list if there's so much > interest that it overwhelms this list. ================================================================== I'm in the midst of setting up a series of 4 semesters of on-line high-school course on programming. Python is second semester. The fourth, I intend to get into some network programming like simple client-server communications. It will be project based. I intend to do my own r&d for this with "Linux Socket Programming" by Warren Gay as the example book. The Project Case will be a server written in C processing requests from any of the "scripting languages" that were covered in the 3 previous semesters. Rebol, python, and perl. I've only committed to the socket part being linux compatible, but I am going to check out whether cygwin would enable such a server to run from a windows machine. ===================================================================== It is likely that this topic is off of the subject of the python Tutor mailing list, but anyone who wants to correspond with me on this issue is welcome to. I plan to start in by next tuesday. (March 13). Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From dsh8290@rit.edu Thu Mar 8 21:42:18 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 8 Mar 2001 16:42:18 -0500 Subject: [Tutor] xml stuff In-Reply-To: <E5468D0C0B2DD411AE52009027B0FA3F8D9D3B@hit-phx-mail-3.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Thu, Mar 08, 2001 at 04:03:30PM -0500 References: <E5468D0C0B2DD411AE52009027B0FA3F8D9D3B@hit-phx-mail-3.hfscorp.com> Message-ID: <20010308164217.A3723@harmony.cs.rit.edu> On Thu, Mar 08, 2001 at 04:03:30PM -0500, Furmanek, Greg wrote: | Ok I have used the expat stuff and I get some strange results: | | Character data: [u' '] | Start element: [PRICE] [{}] | Character data: [u'$7.06'] | End element: [PRICE] | Character data: [u'\012'] | Character data: [u' '] | Start element: [AVAILABILITY] [{}] | Character data: [u'052599'] | End element: [AVAILABILITY] | Character data: [u'\012'] | Character data: [u' '] | End element: [PLANT] | Character data: [u'\012'] | Character data: [u' '] | Character data: [u'\012'] | End element: [CATALOG] | | when parsing some stuff I get these u characters. | Is this normal. code follows: The u character means that the string is in Unicode. r would mean that it is raw (no escape codes or other special characters). Suppose that you wanted to print out some Unicode strings : print 'Hello World.' print u'Hello World.' The first one gives ASCII since it is the default (AFIAK). The second one explicitly requests Unicode. -D From kalle@gnupung.net Thu Mar 8 21:59:55 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 8 Mar 2001 22:59:55 +0100 Subject: [Tutor] xml stuff In-Reply-To: <E5468D0C0B2DD411AE52009027B0FA3F8D9D3B@hit-phx-mail-3.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Thu, Mar 08, 2001 at 04:03:30PM -0500 References: <E5468D0C0B2DD411AE52009027B0FA3F8D9D3B@hit-phx-mail-3.hfscorp.com> Message-ID: <20010308225955.A348@apone.network.loc> Sez Furmanek, Greg: > Ok I have used the expat stuff and I get some strange results: > > Character data: [u' '] [snip] > > when parsing some stuff I get these u characters. > Is this normal. code follows: Yes, I think so. It means that the returned string is a unicode object. That's got to do with character sets and stuff that I don't even want to know about. ISO-8859-1 was good enough for granddad! <wink> Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD From dsh8290@rit.edu Thu Mar 8 22:00:12 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 8 Mar 2001 17:00:12 -0500 Subject: [Tutor] thanks Remco Gerlich & Michael P. Reilly,have program but still have problems In-Reply-To: <F233gIu3q1vblaLJPv000002ccc@hotmail.com>; from gruschow2@hotmail.com on Thu, Mar 08, 2001 at 12:07:38PM -0600 References: <F233gIu3q1vblaLJPv000002ccc@hotmail.com> Message-ID: <20010308170011.B3723@harmony.cs.rit.edu> On Thu, Mar 08, 2001 at 12:07:38PM -0600, Charles Gruschow wrote: | My program so far can do one instance in time so far. I am still | having trouble with getting a steady flow of instances in time. (I | mean so clock repeats itself instead of only giving time out once.) I am not familiar with Tkinter, and I don't particularly like the look of the widgets so I'm not likely to learn. Anyways, the following might help. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/usr/bin/env python from Tkinter import * from time import * class App : def __init__( self , master ) : frame = Frame( master ) frame.pack() self.button = Button(frame,text="Die Button", fg="red",command=frame.quit) self.button.pack() self.time_text = StringVar() self.label = Label( frame , textvariable=self.time_text ) self.label.pack() self.after_id = self.after( 1000, self.display_time ) def display_time( self ) : a = localtime( time() )[3:6] text = ( 'Time is ' + str( a[0] ) + ":" + str( a[1] ) + ":" + str( a[2] ) ) ### Maybe take a look at the strtime() function? self.time_text.set( text ) root = Tk() app = App(root) root.mainloop() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You will notice that I modified some stuff. Some of it is just personal preference (like the spaces around operators and inside parenthesis). Others are a bit more significant. FYI, It is not very clear code to do things like : c = str( b[0] ) + str( b[1] ) + ... because instead you can use import string c = string.join( b , '' ) ## check the order of the arguments Similarly, don't use chr( 58 ) when you really mean ':' ;-) For implementing the refreshing, I would have made an infinite loop that would call a function to update the display in the label, then sleep for a while. I don't know how well Tk would play with this sort of design, but I would use it for Swing or GTK. That timer thing Arcege mentioned sounds like a pretty cool built-in feature. HTH, -D From Glen@ihello-inc.com Thu Mar 8 22:15:42 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Thu, 8 Mar 2001 14:15:42 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A460@go.ihello.com> Thanks Danny, I have another question in the same area. Here is the code that I have so far: >>>SERVER = popen('cut --character=5- eachName') >>>LOOK_FOR = popen('cut --character=9- eachName') RESULTS = os.system(curl --include --max-time 30 SERVER | grep LOOK_FOR') I just need to verify that what is specified in LOOK_FOR is there or not. What is wrong with the last line? Glen Bunting -----Original Message----- From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Thursday, March 08, 2001 12:48 PM To: Glen Bunting Cc: tutor@python.org Subject: Re: [Tutor] (no subject) On Thu, 8 Mar 2001, Glen Bunting wrote: > I have what I hope is a very easy question. I need to save the > results of a command to a variable but I am not sure how to go about > doing it. This is what I have done so far: > > >>>import os > >>>test = os.system('cut --character=5- ActsAutomation,ihello,com') The os.system() function returns the "errorlevel" of its command, which is often different from its printed output. (This errorlevel value is useful when you're writing shell scripts that check for the success or failure of a command.) That's where the zero is coming from. What you'll want to use instead is os.popen(), which gives us a "file"-like object. From this, we can read off the program's output. For example: ### >>> import os >>> output = os.popen('ls *.txt').read() >>> print output indrel.txt list.txt rules.txt sentenceword.txt ### will call the ls command, get the file, read() off all of its string contents, and store that into our output. If you have more questions, please feel free to ask us. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From Glen@ihello-inc.com Thu Mar 8 23:29:16 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Thu, 8 Mar 2001 15:29:16 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A461@go.ihello.com> Forgot to say what the problem was. When I try to run it, I get an error that curl couldn't resolve host SERVER. It seems to me that instead of using the url that is in the variable, it tries to use the variable itself. SERVER is contains two lines. One line is a url the second line is what I need to find on the page. What I'm trying to do is rewrite a sh script in python. Please let me know if I should post the original script and what I've done so far. Glen Bunting -----Original Message----- From: Glen Bunting [mailto:Glen@ihello-inc.com] Sent: Thursday, March 08, 2001 2:16 PM To: 'Daniel Yoo' Cc: tutor@python.org Subject: RE: [Tutor] (no subject) Thanks Danny, I have another question in the same area. Here is the code that I have so far: >>>SERVER = popen('cut --character=5- eachName') >>>LOOK_FOR = popen('cut --character=9- eachName') RESULTS = os.system(curl --include --max-time 30 SERVER | grep LOOK_FOR') I just need to verify that what is specified in LOOK_FOR is there or not. What is wrong with the last line? Glen Bunting -----Original Message----- From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Thursday, March 08, 2001 12:48 PM To: Glen Bunting Cc: tutor@python.org Subject: Re: [Tutor] (no subject) On Thu, 8 Mar 2001, Glen Bunting wrote: > I have what I hope is a very easy question. I need to save the > results of a command to a variable but I am not sure how to go about > doing it. This is what I have done so far: > > >>>import os > >>>test = os.system('cut --character=5- ActsAutomation,ihello,com') The os.system() function returns the "errorlevel" of its command, which is often different from its printed output. (This errorlevel value is useful when you're writing shell scripts that check for the success or failure of a command.) That's where the zero is coming from. What you'll want to use instead is os.popen(), which gives us a "file"-like object. From this, we can read off the program's output. For example: ### >>> import os >>> output = os.popen('ls *.txt').read() >>> print output indrel.txt list.txt rules.txt sentenceword.txt ### will call the ls command, get the file, read() off all of its string contents, and store that into our output. If you have more questions, please feel free to ask us. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From britt_green@hotmail.com Thu Mar 8 23:57:38 2001 From: britt_green@hotmail.com (Britt Green) Date: Thu, 08 Mar 2001 15:57:38 -0800 Subject: [Tutor] Thanks! Message-ID: <F440k51iQRenMgs1Cjj00024be9@hotmail.com> >Ah. This could be due to empty lines in raw_dirs. How about changing > >for x in raw_dirs: dirs.append(string.split(x)[-1]) > >TO > >for x in raw_dirs: try: dirs.append(string.split(x)[-1]) except IndexError: >pass Yeah that worked great. Thanks for the help!! Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From britt_green@hotmail.com Fri Mar 9 03:03:09 2001 From: britt_green@hotmail.com (Britt Green) Date: Thu, 08 Mar 2001 19:03:09 -0800 Subject: [Tutor] Hmmm... Message-ID: <F88Wyu9kstC7tXjs5FG0000430c@hotmail.com> If I have a list, is there a way to extract from it the element that contains a string? For example, if I have: someVeggies = ['carrot', 'lettuce', 'rhubarb', 'peas'] how would i extract the element that matches the string 'carrot' or 'peas' and put that into another string? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From toxx@post.com Fri Mar 9 03:42:30 2001 From: toxx@post.com (t.d) Date: Thu, 8 Mar 2001 22:42:30 -0500 (EST) Subject: [Tutor] basics of networking programming/Class Project Message-ID: <382931976.984109350696.JavaMail.root@web129-mc> Dear Tim, you wrote >>It is likely that this topic is off of the subject of the python Tutor mailing list, but anyone who wants to correspond with me on this issue is welcome to. yes I would like to ....correspond :since it is internet, here is people not only from us, but from other country, where python not yet concidered on class level of learning process at colleges and institiutes and lack of handy books published, so people from those country only use source from python site which nice one, but .., >>I plan to start in by next tuesday. (March 13). very good Regards tur ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From lumbricus@gmx.net Fri Mar 9 03:56:48 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Fri, 9 Mar 2001 04:56:48 +0100 (MET) Subject: [Tutor] Hmmm... References: <F88Wyu9kstC7tXjs5FG0000430c@hotmail.com> Message-ID: <605.984110208@www18.gmx.net> --========GMXBoundary605984110208 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit > If I have a list, is there a way to extract from it the element that > contains a string? > > For example, if I have: > > someVeggies = ['carrot', 'lettuce', 'rhubarb', 'peas'] > > how would i extract the element that matches the string 'carrot' or 'peas' > > and put that into another string? > > Britt > > -- > It is pitch black. You are likely to be eaten by a grue. > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Something like that? ########################## -- Sent through GMX FreeMail - http://www.gmx.net --========GMXBoundary605984110208 Content-Type: application/octet-stream; name=""fil.py""; name="fil.py" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="fil.py" IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCnNvbWVWZWdnaWVzPVsna2Fyb3R0ZScsJ3J1ZWJlbicsJ25h c2UnXQpkZWYgZihpdGVtKToKICAgIGlmIGl0ZW0gPT0gJ25hc2UnOgoJcmV0dXJuIHNvbWVWZWdn aWVzLnBvcChzb21lVmVnZ2llcy5pbmRleChpdGVtKSkKCmRlZiBtYWluKCk6CiAgICBwcmludCBm aWx0ZXIoZixzb21lVmVnZ2llcykKICAgIHByaW50IHNvbWVWZWdnaWVzCgppZiBfX25hbWVfXyA9 PSAnX19tYWluX18nOgogICAgbWFpbigpCg== --========GMXBoundary605984110208-- From lumbricus@gmx.net Fri Mar 9 04:27:01 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Fri, 9 Mar 2001 05:27:01 +0100 (MET) Subject: [Tutor] Changing lines in a set of files References: <F206t3HvoFOAmEaJswF00003e70@hotmail.com> Message-ID: <11005.984112021@www18.gmx.net> > Hi - > > I've been wrestling with this problem for about a week now (I'm a newbie). > > I want to open a series of files from a directory, matchand replace a > substring in the files and then (here's the tricky part for me) save and > close the files. > > This script works, until I introduced the input and output file objects. > > I'm not so sure how the input and output files work. Here's what I have > so > far: > > #! /usr/bin/env python > > import string, sys, fileinput > # take the first argument out of sys.argv and assign it to searchterm I hope I don't miss the point here but I don't think this one does what you want: > searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:] ^^^^^^^^^^^^^^^^^^^^^^^^^ this packs a tuple of ( <first arg>, <second arg> and... ^^^^^^^^^^^^^^^^^^^^^^^^^^ unpacks it to searchterm and <first arg> == searchterm=sys.argv[2:] sys.argv[1:]=sys.argv[1] you want: searchterm=sys.argv[1] # cause sys.argv[0] is the commandname # itself Or am I completely missing the point?? didn't look at fileinput module yet: > inputfiles, outputfiles = fileinput.input() > for inputfilename in inputfilenames: > for line in fileinput.input(): > num_matches = string.count(line, searchterm) > new_string = string.replace(line,searchterm,"Feedback") > if num_matches: > inputfile = open(fileinput.filename(), 'r') > new_string = string.replace(line,searchterm,"Feedback") > print new_string > # a nonzero count means there was a match > print "found '%s' %d times in %s on line %d." % (searchterm, > num_matches, > fileinput.filename(), fileinput.filelineno()) > outputfiles=open(fileinput.filename(),'w') > write_results(outputfiles) > fileinput.nextfile() > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From lumbricus@gmx.net Fri Mar 9 04:27:31 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Fri, 9 Mar 2001 05:27:31 +0100 (MET) Subject: [Tutor] Changing lines in a set of files References: <F206t3HvoFOAmEaJswF00003e70@hotmail.com> Message-ID: <11055.984112051@www18.gmx.net> > Hi - > > I've been wrestling with this problem for about a week now (I'm a newbie). > > I want to open a series of files from a directory, matchand replace a > substring in the files and then (here's the tricky part for me) save and > close the files. > > This script works, until I introduced the input and output file objects. > > I'm not so sure how the input and output files work. Here's what I have > so > far: > > #! /usr/bin/env python > > import string, sys, fileinput > # take the first argument out of sys.argv and assign it to searchterm I hope I don't miss the point here but I don't think this one does what you want: > searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:] ^^^^^^^^^^^^^^^^^^^^^^^^^ this packs a tuple of ( <first arg>, <second arg> and... ^^^^^^^^^^^^^^^^^^^^^^^^^^ unpacks it to searchterm and <first arg> == searchterm=sys.argv[2:] sys.argv[1:]=sys.argv[1] you want: searchterm=sys.argv[1] # cause sys.argv[0] is the commandname # itself Or am I completely missing the point?? didn't look at fileinput module yet: > inputfiles, outputfiles = fileinput.input() > for inputfilename in inputfilenames: > for line in fileinput.input(): > num_matches = string.count(line, searchterm) > new_string = string.replace(line,searchterm,"Feedback") > if num_matches: > inputfile = open(fileinput.filename(), 'r') > new_string = string.replace(line,searchterm,"Feedback") > print new_string > # a nonzero count means there was a match > print "found '%s' %d times in %s on line %d." % (searchterm, > num_matches, > fileinput.filename(), fileinput.filelineno()) > outputfiles=open(fileinput.filename(),'w') > write_results(outputfiles) > fileinput.nextfile() > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From shaleh@valinux.com Fri Mar 9 07:53:40 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 8 Mar 2001 23:53:40 -0800 Subject: [Tutor] Hmmm... In-Reply-To: <F88Wyu9kstC7tXjs5FG0000430c@hotmail.com>; from britt_green@hotmail.com on Thu, Mar 08, 2001 at 07:03:09PM -0800 References: <F88Wyu9kstC7tXjs5FG0000430c@hotmail.com> Message-ID: <20010308235340.A25344@valinux.com> On Thu, Mar 08, 2001 at 07:03:09PM -0800, Britt Green wrote: > If I have a list, is there a way to extract from it the element that > contains a string? > > For example, if I have: > > someVeggies = ['carrot', 'lettuce', 'rhubarb', 'peas'] > > how would i extract the element that matches the string 'carrot' or 'peas' > and put that into another string? > if 'carrot' in someVeggies: print 'Veggies has a carrot' is that useful? From britt_green@hotmail.com Fri Mar 9 08:01:54 2001 From: britt_green@hotmail.com (Britt Green) Date: Fri, 09 Mar 2001 00:01:54 -0800 Subject: [Tutor] Hmmm... Message-ID: <F260T2NqFJ3sl3xbYiM00024746@hotmail.com> >On Thu, Mar 08, 2001 at 07:03:09PM -0800, Britt Green wrote: > > If I have a list, is there a way to extract from it the element that > > contains a string? > > > > For example, if I have: > > > > someVeggies = ['carrot', 'lettuce', 'rhubarb', 'peas'] > > > > how would i extract the element that matches the string 'carrot' or >'peas' > > and put that into another string? > > > >if 'carrot' in someVeggies: > print 'Veggies has a carrot' > >is that useful? Actually, I figured out what I needed to do on my own! import string theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] chosen = [] for stuff in theFruits: if stuff.endswith('e'): chosen.append(stuff) print chosen When run, only the elements of theFruits that end with an 'e' will get added to the list of chosen. Is there a better way to do this? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From arcege@shore.net Fri Mar 9 12:20:44 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 9 Mar 2001 07:20:44 -0500 (EST) Subject: [Tutor] Changing lines in a set of files In-Reply-To: <F206t3HvoFOAmEaJswF00003e70@hotmail.com> from Karen Windus at "Mar 8, 2001 8:36:16 pm" Message-ID: <E14bLsy-0007hE-00@nautilus.shore.net> > Hi - > > I've been wrestling with this problem for about a week now (I'm a newbie). > I want to open a series of files from a directory, matchand replace a > substring in the files and then (here's the tricky part for me) save and > close the files. > > This script works, until I introduced the input and output file objects. It is sometimes better to let fileinput handle the file processing for you, but there is nothing wrong with you doing it yourself. > I'm not so sure how the input and output files work. Here's what I have so > far: > > #! /usr/bin/env python > > import string, sys, fileinput > # take the first argument out of sys.argv and assign it to searchterm > searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:] > inputfiles, outputfiles = fileinput.input() # fileinput.input returns in instance of FileInput, not a tuple; how # it works is that you repeatedly get a line from one of the files # given (or taken from sys.argv) > for inputfilename in inputfilenames: > for line in fileinput.input(): > num_matches = string.count(line, searchterm) > new_string = string.replace(line,searchterm,"Feedback") > if num_matches: > inputfile = open(fileinput.filename(), 'r') > new_string = string.replace(line,searchterm,"Feedback") > print new_string > # a nonzero count means there was a match > print "found '%s' %d times in %s on line %d." % (searchterm, > num_matches, > fileinput.filename(), fileinput.filelineno()) > outputfiles=open(fileinput.filename(),'w') > write_results(outputfiles) > fileinput.nextfile() How about: import fileinput, string, sys # myself, I would handle the sys.argv processing differently, but there # is nothing wrong with what you have here searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:] # the inplace=1 argument tells fileinput to rename each file with a ".bak" # extension, a new file is created with the new name and sys.stdout points # to that new file for line in fileinput.input(inplace=1, backup='.bak'): line = string.replace(line, searchterm, "Feedback") sys.stdout.write(line) fileinput.close() This should do all you need to. But if you wanted to handle this explicitly... import os, string, sys for filename in sys.argv[2:]: if os.path.exists(filename): os.rename(filename, filename + '.bak') infile = open(filename + '.bak', 'r') # text mode outfile = open(filename, 'w') line = infile.readline() while line: line = string.replace(line, sys.argv[1], "Feedback") outfile.write(line) line = infile.readline() infile.close() outfile.close() else: sys.stderr.write('%s: No such file or directory\n' % filename) This isn't doing all the fileinput does, but performs the same way. Enjoy. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From livelikemad@yahoo.com Fri Mar 9 15:19:58 2001 From: livelikemad@yahoo.com (Chris McCormick) Date: Fri, 9 Mar 2001 07:19:58 -0800 (PST) Subject: [Tutor] >> BANANAS! << The answer. :-) Message-ID: <20010309151958.5549.qmail@web10513.mail.yahoo.com> --0-1728907065-984151198=:3915 Content-Type: text/plain; charset=us-ascii So, can you have a "significant rewrite" of a program that's fewer than 1000 lines? I got the chance yesterday to play with my virtual world program again, and tried some of the things suggested a couple of days ago. For those of you late to the conversation, I was trying to do the following: - Create a list. - Append instances of a class to the list. - Remove those instances without regard to their place in the list. The list happened to contain bananas, which I wanted to remove when they died of old age or got eaten. The obvious solution, now that I think about it (and mentioned by more than one person) was to grab the bananas by name, which implies the use of a dictionary. Once I got the hang of how to refer to values inside items inside a dictionary, it was all smooth sailing: >From the game.py module: bananas = {} # Dictionary to contain bananasglobals = {} # Dictionary to contain any needed info.bananacount = input('How many bananas do you wanna see? ') ## Get number of bananasglobals['banana_count'] = bananacountfor x in range(0, bananacount): ## Create bananas dictionary banana_name = "banana" + str(x) xPos = whrandom.randint(100,500) ## Random x position yPos = whrandom.randint(100,500) ## Random y position maturity = whrandom.randint(1,4) ## Random maturity new_banana = flora2.Banana(banana_name, xPos, yPos, maturity) ## Class instance bananas[banana_name] = new_banana ## Add instance to dictionary And from my flora.py module: def die(self, bananas, banana_name, canvas): del bananas[banana_name] ## remove banana instance canvas.delete(banana_name) ## remove picture from canvas print banana_name, "has died." Thanks a lot, guys. I'm starting to learn (a little) what the natural data structures are for some of these things. As usual, I have a piggyback question: I'm always trying to pass information from my main module, game.py, to functions contained in other modules. Those functions need to update the information so that it can be passed again on the next loop. The problem I have is making the information available to everyone. The best solution I have come up with so far is to have a "globals" dictionary, and pass it as an argument to the functions, like so: Pieces of my main module, game.py: globals = {} # Dictionary to contain any needed info.bananacount = input('How many bananas do you wanna see? ') ## Get number of bananasglobals['banana_count'] = bananacount####################### START THE GAME #########################window.GameWindow(heroes, bananas, globals) >From the window.py module: gameframe = myFrame(gamewindow, heroes, bananas, globals) ## Create the main frame... def __init__(self, gamewindow, heroes, bananas, globals): Tkinter.Frame.__init__(self, gamewindow) Tkinter.Pack.config(self) self.createMenus(gamewindow,heroes) self.createCanvas(gamewindow, heroes, bananas, globals)... def createCanvas(gameframe, gamewindow, heroes, bananas, globals): gameframe.moveImages(canvas, gameframe, gamewindow, heroes, bananas, globals)... def moveImages(self, canvas, gameframe, gamewindow, heroes, bananas, globals): while 1: #### Update AI/ new objects for banana_name in bananas.keys(): bananas[banana_name].mature(canvas, bananas, globals) And that's how I get the information to my bananas in flora.py. Sorry for all of the code, here, but do you see how I have to include the globals dictionary all over the place, in a lot of places it's not needed, just to get it to the bananas functions? I know that I could eliminate some of it by making the globals dictionary global within each module (and I should rename it "myGlobals" while I'm at it), but that's still a lot of passing around. Is there *any* way to make a dictionary or a list global to *all* modules, or to make it importable? On a general level, what's the best treatment of scope you've read? 90% of my problems arise from confusion about scope. Thanks for listening to me ramble,Chris --------------------------------- Do You Yahoo!? Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail. --0-1728907065-984151198=:3915 Content-Type: text/html; charset=us-ascii So, can you have a "significant rewrite" of a program that's fewer than 1000 lines? I got the chance yesterday to play with my virtual world program again, and tried some of the things suggested a couple of days ago. For those of you late to the conversation, I was trying to do the following: <p> - Create a list.<br> - Append instances of a class to the list.<br> - Remove those instances without regard to their place in the list. <p> The list happened to contain bananas, which I wanted to remove when they died of old age or got eaten. <p> The obvious solution, now that I think about it (and mentioned by more than one person) was to grab the bananas by name, which implies the use of a dictionary. Once I got the hang of how to refer to values inside items inside a dictionary, it was all smooth sailing: <p><b> >From the game.py module:</b> <pre> bananas = {} # Dictionary to contain bananas globals = {} # Dictionary to contain any needed info. bananacount = input('How many bananas do you wanna see? ') ## Get number of bananas globals['banana_count'] = bananacount for x in range(0, bananacount): ## Create bananas dictionary banana_name = "banana" + str(x) xPos = whrandom.randint(100,500) ## Random x position yPos = whrandom.randint(100,500) ## Random y position maturity = whrandom.randint(1,4) ## Random maturity new_banana = flora2.Banana(banana_name, xPos, yPos, maturity) ## Class instance bananas[banana_name] = new_banana ## Add instance to dictionary </pre><b> And from my flora.py module:</b> <pre> def die(self, bananas, banana_name, canvas): del bananas[banana_name] ## remove banana instance canvas.delete(banana_name) ## remove picture from canvas print banana_name, "has died." </pre> Thanks a lot, guys. I'm starting to learn (a little) what the natural data structures are for some of these things. <p> As usual, I have a piggyback question: <p> I'm always trying to pass information from my main module, game.py, to functions contained in other modules. Those functions need to update the information so that it can be passed again on the next loop. The problem I have is making the information available to everyone. The best solution I have come up with so far is to have a "globals" dictionary, and pass it as an argument to the functions, like so: <p> <b>Pieces of my main module, game.py:</b> <pre> globals = {} # Dictionary to contain any needed info. bananacount = input('How many bananas do you wanna see? ') ## Get number of bananas globals['banana_count'] = bananacount ####################### START THE GAME ######################### window.GameWindow(heroes, bananas, globals) </pre> <b>From the window.py module:</b> <pre> gameframe = myFrame(gamewindow, heroes, bananas, globals) ## Create the main frame ... def __init__(self, gamewindow, heroes, bananas, globals): Tkinter.Frame.__init__(self, gamewindow) Tkinter.Pack.config(self) self.createMenus(gamewindow,heroes) self.createCanvas(gamewindow, heroes, bananas, globals) ... def createCanvas(gameframe, gamewindow, heroes, bananas, globals): gameframe.moveImages(canvas, gameframe, gamewindow, heroes, bananas, globals) ... def moveImages(self, canvas, gameframe, gamewindow, heroes, bananas, globals): while 1: #### Update AI/ new objects for banana_name in bananas.keys(): bananas[banana_name].mature(canvas, bananas, globals) </pre> And that's how I get the information to my bananas in flora.py. Sorry for all of the code, here, but do you see how I have to include the globals dictionary all over the place, in a lot of places it's not needed, just to get it to the bananas functions? I know that I could eliminate some of it by making the globals dictionary global within each module (and I should rename it "myGlobals" while I'm at it), but that's still a lot of passing around. <p> Is there *any* way to make a dictionary or a list global to *all* modules, or to make it importable? On a general level, what's the best treatment of scope you've read? 90% of my problems arise from confusion about scope. <p> Thanks for listening to me ramble, Chris <p><br><hr size=1><b>Do You Yahoo!?</b><br> <a href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</a> - Get email at your own domain with Yahoo! Mail. --0-1728907065-984151198=:3915-- From dsh8290@rit.edu Fri Mar 9 15:49:22 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 9 Mar 2001 10:49:22 -0500 Subject: [Tutor] >> BANANAS! << The answer. :-) In-Reply-To: <20010309151958.5549.qmail@web10513.mail.yahoo.com>; from livelikemad@yahoo.com on Fri, Mar 09, 2001 at 07:19:58AM -0800 References: <20010309151958.5549.qmail@web10513.mail.yahoo.com> Message-ID: <20010309104922.C4546@harmony.cs.rit.edu> On Fri, Mar 09, 2001 at 07:19:58AM -0800, Chris McCormick wrote: | | So, can you have a "significant rewrite" of a program that's fewer | than 1000 lines? I got the chance yesterday to play with my virtual Yes. | As usual, I have a piggyback question: | | I'm always trying to pass information from my main module, game.py, to | functions contained in other modules. Those functions need to update | the information so that it can be passed again on the next loop. The | problem I have is making the information available to everyone. The | best solution I have come up with so far is to have a "globals" | dictionary, and pass it as an argument to the functions, like so: I would recommend using a class. A class is essentially some functions bundled together with some data they operate on. For example: ######## module Banana.py class Banana : def __init__( self ) : self.current_age = 0 # it start out new right? self.ripeness = 0 self.is_bad = 0 # I miss the keyword 'false' self.is_eaten = 0 def mature( self ) : self.ripeness += 1 # the += operator only works in >= 2.0 # otherwise use ## self.ripeness = self.ripeness + 1 You should be able to get rid of that 'globals' dictionary. You commented it as "contain needed info". That's exactly what classes are for. If you want the count of bananas, use len( bananas_dict.keys() ). | Is there *any* way to make a dictionary or a list global to *all* | modules, or to make it importable? On a general level, what's the best It is importable. In window.py put import game then use game.globals to access it. | treatment of scope you've read? 90% of my problems arise from | confusion about scope. Read the part of the tutorial/reference about classes. I think they will help you a lot. Do you have experience programming in other languages? Data encapsulation is what you need. You have a good idea of what you want to do, and python likes encapsulation much more than C does. In C, for example, everything exists in 1 namespace (except for locals in a function). Thus you get a higher tendency to use globals in C. Python makes it much harder to use globals and helps you to explore ways to encapsulate your data more. | Thanks for listening to me ramble, Chris No problem. If you don't know or understand classes/OOP feel free to ask and someone (maybe even me ;-)) will come up with a good introduction with examples, etc. -D From tescoil@irtc.net Fri Mar 9 15:55:35 2001 From: tescoil@irtc.net (Tesla Coil) Date: Fri, 09 Mar 2001 10:55:35 -0500 Subject: [Tutor] Hmmm... References: <F260T2NqFJ3sl3xbYiM00024746@hotmail.com> Message-ID: <3AA8FCF7.C333131F@irtc.net> On 8 Mar 2001, Britt Green wrote: > Actually, I figured out what I needed to > do on my own! > > import string > > theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] > > chosen = [] > > for stuff in theFruits: > if stuff.endswith('e'): > chosen.append(stuff) > > print chosen > > When run, only the elements of theFruits that end with > an 'e' will get added to the list of chosen. Is there > a better way to do this? No need to import string for the above. An old-fashioned (<2.0) method that still works: for stuff in theFruits: if stuff[-1] == 'e': chosen.append(stuff) You might be interested in this: >>> import re >>> basket = ['apple', 'banana', 'pineapple', 'pear', 'orange'] >>> chosen = [] >>> pick = re.compile('an') >>> for fruits in basket: ... if pick.search(fruits): ... chosen.append(fruits) >>> chosen ['banana', 'orange'] See: http://www.python.org/doc/howto/regex/regex.html From Greg.Furmanek@hit.cendant.com Fri Mar 9 16:16:07 2001 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Fri, 9 Mar 2001 11:16:07 -0500 Subject: FW: [Tutor] xml stuff Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9D41@hit-phx-mail-3.hfscorp.com> How do I change unicode to askii? -> -----Original Message----- -> From: Kalle Svensson [mailto:kalle@gnupung.net] -> Sent: Thursday, March 08, 2001 3:00 PM -> To: tutor@python.org -> Subject: Re: [Tutor] xml stuff -> -> -> Sez Furmanek, Greg: -> > Ok I have used the expat stuff and I get some strange results: -> > -> > Character data: [u' '] -> [snip] -> > -> > when parsing some stuff I get these u characters. -> > Is this normal. code follows: -> -> Yes, I think so. It means that the returned string is a -> unicode object. -> That's got to do with character sets and stuff that I don't -> even want to -> know about. ISO-8859-1 was good enough for granddad! <wink> -> -> Peace, -> Kalle -> -- -> Email: kalle@gnupung.net | You can tune a filesystem, but you -> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) -> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD -> -> _______________________________________________ -> Tutor maillist - Tutor@python.org -> http://mail.python.org/mailman/listinfo/tutor -> "The sender believes that this E-mail and any attachments were free of any virus, worm, Trojan horse, and/or malicious code when sent. This message and its attachments could have been infected during transmission. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective and remedial action about viruses and other defects. The sender's employer is not liable for any loss or damage arising in any way from this message or its attachments." From cmccormick@thestate.com Fri Mar 9 16:37:24 2001 From: cmccormick@thestate.com (Chris McCormick) Date: Fri, 09 Mar 2001 11:37:24 -0500 Subject: [Tutor] >> Bananas << A -bunch- of replying. Message-ID: <3AA906C4.195B87B3@thestate.com> D-Man, Thanks for your reply. <snipped> | As usual, I have a piggyback question: | | I'm always trying to pass information from my main module, game.py, to | functions contained in other modules. Those functions need to update | the information so that it can be passed again on the next loop. The | problem I have is making the information available to everyone. The | best solution I have come up with so far is to have a "globals" | dictionary, and pass it as an argument to the functions, like so: I would recommend using a class. A class is essentially some functions bundled together with some data they operate on. For example: ######## module Banana.py class Banana : def __init__( self ) : self.current_age = 0 # it start out new right? self.ripeness = 0 self.is_bad = 0 # I miss the keyword 'false' self.is_eaten = 0 def mature( self ) : self.ripeness += 1 # the += operator only works in >= 2.0 # otherwise use ## self.ripeness = self.ripeness + 1 *** I am using a banana class, from my flora.py module. A dictionary all the instances of the Banana class. I have a Banana.mature function, too. :-) *** You should be able to get rid of that 'globals' dictionary. You commented it as "contain needed info". That's exactly what classes are for. If you want the count of bananas, use len( bananas_dict.keys() ). *** I automatically name each instance of my banana class, so that I can retrieve it from the dictionary. I name them banana0, banana1, banana2, and so on. My dictionary looks something like this: {'banana1':<class instance...>, 'banana2':<class instance...>} The problem lies in the function to generate unique names. It has to get the initial slate of names as it generates each instance and puts it in the dictionary: bananacount = input('How many bananas do you wanna see? ') ## Get number of bananas gameGlobals['banana_count'] = bananacount for x in range(0, bananacount): ## Create bananas dictionary banana_name = "banana" + str(x) <snip> bananas[banana_name] = new_banana So far, so good, right? But when new bananas are propagated later, I can't just use len( bananas_dict.keys() ), because some of the bananas have gone away. If I have bananas 1-20, the last one is named banana19. Let's say banana2 dies or gets eaten. Now, my dictionary has 19 items. If I take the length and generate a name, I get banana19 again. So, what I've done is to create a dictionary that can hold a banana_count item. Then I update it when a banana goes through its die() function. The problem is making that data available all around the program, in different modules. | Is there *any* way to make a dictionary or a list global to *all* | modules, or to make it importable? On a general level, what's the best It is importable. In window.py put import game then use game.globals to access it. *** Now, this makes things much easier. I can put all global data, along with functions to change them, in a globals module. *** <snip> No problem. If you don't know or understand classes/OOP feel free to ask and someone (maybe even me ;-)) will come up with a good introduction with examples, etc. -D *** thanks. I'll keep working on it. *** - Chris From alan.gauld@bt.com Fri Mar 9 20:11:42 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 9 Mar 2001 20:11:42 -0000 Subject: [Tutor] >> Bananas << A -bunch- of replying. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D618@mbtlipnt02.btlabs.bt.co.uk> > *** I am using a banana class, from my flora.py module. ... > The problem lies in the function to generate unique names. It has to > get the initial slate of names as it generates each instance > ... So, what I've done is to create a dictionary that can hold a > banana_count item. Take a look at class variables. class Banana: count = 0 def __init__(.... Now you can globally access Banana.count anywhere you can access Banana Classes are just fancy dictionaries under the hood ;-) On the subject of scope you might try my tutorial page on namespaces... Alan G. http://www.crosswinds.net/~agauld/ From alan.gauld@bt.com Fri Mar 9 20:14:15 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 9 Mar 2001 20:14:15 -0000 Subject: [Tutor] xml stuff Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D619@mbtlipnt02.btlabs.bt.co.uk> > How do I change unicode to askii? Why would you want to? Unicode strings should work just as well as ASCII ones in any of the string functions in Python. And your program will be that much more widely useful since it can handle any alphabet. Alan G. From dsh8290@rit.edu Fri Mar 9 20:27:33 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 9 Mar 2001 15:27:33 -0500 Subject: [Tutor] >> Bananas << A -bunch- of replying. In-Reply-To: <3AA906C4.195B87B3@thestate.com>; from cmccormick@thestate.com on Fri, Mar 09, 2001 at 11:37:24AM -0500 References: <3AA906C4.195B87B3@thestate.com> Message-ID: <20010309152733.B4987@harmony.cs.rit.edu> On Fri, Mar 09, 2001 at 11:37:24AM -0500, Chris McCormick wrote: | D-Man, | Thanks for your reply. | | <snipped> | | I would recommend using a class. A class is essentially some | functions bundled together with some data they operate on. For | example: | | | *** I am using a banana class, from my flora.py module. A dictionary | all the instances of the Banana class. I have a Banana.mature function, | too. :-) *** Good. | | You should be able to get rid of that 'globals' dictionary. You | commented it as "contain needed info". That's exactly what classes are | for. | | If you want the count of bananas, use len( bananas_dict.keys() ). | | *** I automatically name each instance of my banana class, so that I | can retrieve it from the dictionary. I name them banana0, banana1, | banana2, and so on. My dictionary looks something like this: | | {'banana1':<class instance...>, 'banana2':<class instance...>} | | The problem lies in the function to generate unique names. It has to | get the initial slate of names as it generates each instance and puts it | in the dictionary: | There are a couple of ways around this. I would recommend storing the banana's name in the Banana instance. You can have a class (aka static) member that keeps track of how many bananas have been created. class Banana : instance_count = 0 # this is in the class object def __init__( self ) : Banana.instance_count += 1 self.name = "banana" + str( Banana.instance_count ) This sort of implementation will allow your function to not know and not care what the current number is. I don't know if it would be very helpful, but you could make the bananas hashable. This means defining a __hash__ function (or some similar name, check the docs). In this case it would suffice for it to simply return hash( self.name ) and let the string object's authors do the hard work of devising a good hashing function. | So far, so good, right? But when new bananas are propagated later, I | can't just use len( bananas_dict.keys() ), because some of the bananas | have gone away. If I have bananas 1-20, the last one is named | banana19. Let's say banana2 dies or gets eaten. Now, my dictionary has | 19 items. If I take the length and generate a name, I get banana19 Ok. First how about adding a space between "banana" and "19" (to make extraction easier)? def get_highest_count( banana_dict ) : names = banana_dict.keys() names.sort() highest = 0 for name in names : # the next line will throw ValueError if I messed up the # split, or if the name doesn't follow the pattern index = int( string.split( name , " " )[1] ) if index > highest : highest = index return highest but obviously the class technique above is simpler. | | Is there *any* way to make a dictionary or a list global to *all* | | modules, or to make it importable? On a general level, what's the | best | | It is importable. In window.py put | | import game | | | then use | | game.globals | | to access it. | | *** Now, this makes things much easier. I can put all global data, | along with functions to change them, in a globals module. *** Yes, if global data is absolutely necessary (in some cases it is) a module specifically for it is a good idea. | *** thanks. I'll keep working on it. *** No problem. That's the way to learn it and improve your techniques. -D From lumbricus@gmx.net Sat Mar 10 00:17:14 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sat, 10 Mar 2001 01:17:14 +0100 (MET) Subject: [Tutor] xml stuff References: <5104D4DBC598D211B5FE0000F8FE7EB20751D619@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <12618.984183434@www24.gmx.net> > > How do I change unicode to askii? > > Why would you want to? Unicode strings should work just as > well as ASCII ones in any of the string functions in Python. > And your program will be that much more widely useful since it > can handle any alphabet. > > Alan G. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > is unicodedata.decomposition() doing what you want? the module unicodedata is available version >= 2.0 so i cant test it. greetings Jö! -- Sent through GMX FreeMail - http://www.gmx.net From ewe2@can.org.au Sat Mar 10 01:38:14 2001 From: ewe2@can.org.au (ewe2@can.org.au) Date: Sat, 10 Mar 2001 12:38:14 +1100 Subject: [Tutor] string iteration Message-ID: <20010310123814.A608@can.org.au> ok, i'm feeling particularly stupid today: given a string a = 'abcdefghijklmnop' and a string b = 'abc', how do i iterate b against a, so i get a string c = 'abcabcabcabcabca' the length of a? my brain is hurting from all the failed for loops :) -- Sean Dwyer <ewe2@cvis.com.au> CAN Admin <ewe2@can.org.au> Web: http://ewe2.cvis.com.au/ From DOUGS@oceanic.com Sat Mar 10 01:51:05 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Fri, 9 Mar 2001 15:51:05 -1000 Subject: [Tutor] string iteration Message-ID: <8457258D741DD411BD3D0050DA62365907A6B7@huina.oceanic.com> [Sean Dwyer asked:] > given a string a = 'abcdefghijklmnop' and a string b = 'abc', how do i > iterate b against a, so i get a string c = 'abcabcabcabcabca' > the length of a? > my brain is hurting from all the failed for loops :) One way: Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> a = 'abcdefghijklmnop' >>> b = 'abc' >>> spam = b * int(len(a)/len(b)) >>> spam 'abcabcabcabcabc' >>> spam = b * (int(len(a)/len(b))+1) >>> spam 'abcabcabcabcabcabc' >>> eggs = spam[:len(a)] >>> eggs 'abcabcabcabcabca' >>> Does that help? -Doug- From dyoo@hkn.eecs.berkeley.edu Sat Mar 10 02:38:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Mar 2001 18:38:43 -0800 (PST) Subject: [Tutor] Hmmm... In-Reply-To: <F260T2NqFJ3sl3xbYiM00024746@hotmail.com> Message-ID: <Pine.LNX.4.21.0103091834310.952-100000@c82114-a.pinol1.sfba.home.com> On Fri, 9 Mar 2001, Britt Green wrote: > import string > > theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] > > chosen = [] > > for stuff in theFruits: > if stuff.endswith('e'): > chosen.append(stuff) > > print chosen > > When run, only the elements of theFruits that end with an 'e' will get > added to the list of chosen. Is there a better way to do this? Here's another wacky way to do that: ### def endsWithE(word): return word.endswith('e') theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] chosen = filter(endsWithE, theFruits) print chosen ### which tells Python: "Ok, let's filter out only theFruits that endsWithE()." This is called the "functional" approach, because all we're doing is function calls and passing functions around. It's a lot of fun. From dyoo@hkn.eecs.berkeley.edu Sat Mar 10 02:54:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Mar 2001 18:54:05 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A460@go.ihello.com> Message-ID: <Pine.LNX.4.21.0103091349330.952-100000@c82114-a.pinol1.sfba.home.com> On Thu, 8 Mar 2001, Glen Bunting wrote: > I have another question in the same area. > > Here is the code that I have so far: > >>>SERVER = popen('cut --character=5- eachName') > >>>LOOK_FOR = popen('cut --character=9- eachName') > RESULTS = os.system(curl --include --max-time 30 SERVER | grep LOOK_FOR') > > I just need to verify that what is specified in LOOK_FOR is there or not. > What is wrong with the last line? I'll assume that you meant to write: > RESULTS = os.system('curl --include --max-time 30 SERVER|grep LOOK_FOR') (with the leading quote; be careful!) Python doesn't automatically interpolate variables into strings --- for all it knows, you really meant to literally say the word "SERVER" or "LOOK_FOR". In order to get Python to "fill in the blanks", we can do "string interpolation": ### mycmd_template = 'curl --include --max-time 30 %s | grep %s' mycmd = mycmd_template % (SERVER, LOOK_FOR) # <-- This is interpolation results = os.system(mycmd) ### The important part to look at is the '%' operator: this is string interpolation. What it does is akin to the game "Mad Libs": it fills in wherever there's a '%s' in our string. It takes in a template to its self, and a tuple of the stuff it fills in to its right. You might think that '%s' isn't quite nice: it's very position dependent. We can make this behave more nicely if we use string interpolation with dictionaries: ### mycmd_template = 'curl --include --max-time 30 %(server)s | grep \ %(look_for)s' mycmd = mycmd_template % {'server' : SERVER, 'look_for' : LOOK_FOR } ### Now, when it interpolates, it looks inside our dictionary to see what we mean by '%(server)s' and '%(look_for)s', and fills in the blanks appropriately. Hope this helps! From wheelege@tsn.cc Sat Mar 10 04:00:52 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 10 Mar 2001 15:00:52 +1100 Subject: [Tutor] string iteration References: <20010310123814.A608@can.org.au> Message-ID: <00f201c0a916$b3978440$0200a8c0@ACE> Well, here is my typically newbie attempt... length = 'abcdefghijklmnop' data = 'abc' resultant = '' position = -1 ## because first spot is 0 for x in length: if position < (len(data) - 1): ## len('abc') is 3, not 2. so if the -1 was not there, it would try to iterate 4 times (0,1,2,3) position += 1 else: position -= (len(data) - 1) resultant = resultant + data[position] print resultant As you can see it's alot bigger and clunkier than Doug's attempt, but I thought it best to give another solutional - the bigger and clunkier something is the easier it is to understand (most of the time :). Glen. ----- Original Message ----- From: <ewe2@can.org.au> To: <tutor@python.org> Sent: Saturday, March 10, 2001 12:38 PM Subject: [Tutor] string iteration > ok, i'm feeling particularly stupid today: > > given a string a = 'abcdefghijklmnop' and a string b = 'abc', how do i > iterate b against a, so i get a string c = 'abcabcabcabcabca' the length of a? > my brain is hurting from all the failed for loops :) > > > -- > Sean Dwyer <ewe2@cvis.com.au> > CAN Admin <ewe2@can.org.au> > Web: http://ewe2.cvis.com.au/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From biotechinfo2003@yahoo.com Fri Mar 9 21:27:00 2001 From: biotechinfo2003@yahoo.com (biotechinfo2003@yahoo.com) Date: Fri, 9 Mar 2001 21:27:00 Subject: [Tutor] FREE Biotech Stock Info! 954 Message-ID: <737.733799.517437@earthlink.net> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>Do you want to capitalize on the Biotech Revolution</title> </head> <body> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto" align="center"><img border="0" src="http://www.geocities.com/mailtestbox2000/Kiloh_logo.gif" width="204" height="170"></p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:Arial">Do you want to capitalize on the Biotech Revolution? Would you like to add groundbreaking biotech, pharmaceutical and medical device companies to your portfolio mix? Does hearing about exciting IPO and private placement offerings from life sciences companies interest you?</span></p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:Arial">The exclusive <b>Ruddy-Carlisle Biotech Infoline</b> service keeps you abreast of investment opportunities in the life sciences space. Just sign up for it once and get important information instantly delivered to study at your leisure. Our service is <b><u>100% FREE</u></b>! <b><span style="color:blue"><a href="mailto:biotechsubscribe@yahoo.com">Sign up!</a></span></b></span></p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><i><span style="font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:#003366">Ruddy-Carlisle Biotech Infoline:</span></i></b></p> <ul type="disc"> <li class="MsoNormal" style="color:#003366;mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l0 level1 lfo1;tab-stops:list .5in"><b><i><span style="font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Arial">Instantly delivers key life sciences investment information directly to you! </span></i></b><o:p> </o:p> </li> <li class="MsoNormal" style="color:#003366;mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l0 level1 lfo1;tab-stops:list .5in"><b><i><span style="font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Arial">Learn about biotech, pharmaceutical & medical device investment opportunities before others! </span></i></b><o:p> </o:p> </li> <li class="MsoNormal" style="color:#003366;mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l0 level1 lfo1;tab-stops:list .5in"><b><i><span style="font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Arial">Includes IPO & private placement information! </span></i></b><o:p> </o:p> </li> <li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l0 level1 lfo1;tab-stops:list .5in"><b><i><span style="font-size: 11.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;color:#003366">100% FREE!</span></i></b></li> </ul> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:Arial">For the entire last decade there were only three profitable biotech companies. At the end of this year, ten are projected. At the end of 2003, <u>over forty</u> are projected! The genomic promise is about to be delivered and investors know it. The <b>Ruddy-Carlisle Biotech Infoline </b>provides you with critical, decision-making, information that aids the chance of investment success in this lucrative space. <b><span style="color:blue"><a href="mailto:biotechsubscribe@yahoo.com">Sign up!</a></span></b></span></p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:Arial">Please Note-</span></b><span style="font-family:Arial"> Your information will only be shared with companies that are in the life sciences space <u>and</u> pass our rigorous inspection. Only the best opportunities will come to you. Ruddy-Carlisle respects your privacy. <b><span style="color:blue"><a href="mailto:biotechsubscribe@yahoo.com">Sign up!</a></span></b></span></p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> </p> <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> </p> <b><span style="font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial; mso-fareast-font-family:"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language: EN-US;mso-bidi-language:AR-SA"> </p> </p>List Removal Instructions</span></b><span style="font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Arial;mso-fareast-font-family: "Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:EN-US; mso-bidi-language:AR-SA">- Simply click here: <b><span style="color:blue"><a href="mailto:remobiotech@yahoo.com">remove</a></span></b> to be instantly and permanently removed from our list. Send the blank email to the address specified. Please do not try to reply to this message.</span> </body> </html> From gruschow2@hotmail.com Sat Mar 10 06:37:25 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Sat, 10 Mar 2001 00:37:25 -0600 Subject: [Tutor] I will keep you guys posted, but I am making some progress thanks to your help. Message-ID: <F125LTC5w4q1aikm8rv0000464b@hotmail.com> I will keep you guys posted, but I am making some progress thanks to your help. I don't have time right more to write anymore. I will later. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sburr@home.com Sat Mar 10 06:52:40 2001 From: sburr@home.com (Steven Burr) Date: Fri, 9 Mar 2001 23:52:40 -0700 Subject: [Tutor] string iteration Message-ID: <20010310065241.WCYH796.mail2.rdc1.az.home.com@localhost> On Friday, March 9, 2001, at 06:38 PM, <ewe2@can.org.au> wrote: > ok, i'm feeling particularly stupid today:=20 > =20 > given a string a =3D 'abcdefghijklmnop' and a string b =3D 'abc', how = do i=20 > iterate b against a, so i get a string c =3D 'abcabcabcabcabca' the = length of a?=20 > my brain is hurting from all the failed for loops :)=20 > =20 How about: def iterate(s, p): full, part =3D divmod(len(s), len(p)) return p * full + p[0: part] a =3D 'abcdefghijklmnop' b =3D 'abc' print iterate(a, b)= From britt_green@hotmail.com Sat Mar 10 06:57:38 2001 From: britt_green@hotmail.com (Britt Green) Date: Fri, 09 Mar 2001 22:57:38 -0800 Subject: [Tutor] Removing Null Elements from a List Message-ID: <F262de13YDLVBXbpEki000054e8@hotmail.com> If I have a list that looks like: [None, None, None, None, None, None, None, None, None, None, ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, None, None, None, None, None, None, None, None, None, ['/boston/rplace'], ['/boston/salamander'], None, ['/boston/test'], ['/boston/the_federalist'], None, ['/boston/yanks']] How can I remove those None elements in it? The code that I'm getting that from is, in part, this: chosen = [] badFiles = [] pick = re.compile(theDate) for elements in files: if pick.search(elements): chosen.append(elements) #print chosen if chosen == []: #print ftp.pwd() badFiles.append(ftp.pwd() ) return badFiles Basically, if a directory listing from an FTP site does *not* have a file with today's date on it, it should be added to the list badFiles. Since some directories are fine, they're being added as None. How can I either stop this, or just remove them from the final list. Either solution would work just as well for me. Thanks for the continued help. I appreciate it. Britt _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From lumbricus@gmx.net Sat Mar 10 08:19:22 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sat, 10 Mar 2001 09:19:22 +0100 (MET) Subject: [Tutor] Removing Null Elements from a List References: <F262de13YDLVBXbpEki000054e8@hotmail.com> Message-ID: <13978.984212362@www10.gmx.net> > If I have a list that looks like: > > [None, None, None, None, None, None, None, None, None, None, > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, > None, > None, None, None, None, None, None, None, None, None, None, > ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, > None, > None, None, None, None, None, None, None, None, ['/boston/rplace'], > ['/boston/salamander'], None, ['/boston/test'], > ['/boston/the_federalist'], > None, ['/boston/yanks']] > > How can I remove those None elements in it? The code that I'm getting that > > >from is, in part, this: > > chosen = [] > badFiles = [] > > > pick = re.compile(theDate) > for elements in files: > if pick.search(elements): > chosen.append(elements) > #print chosen > > if chosen == []: > #print ftp.pwd() > badFiles.append(ftp.pwd() ) > return badFiles > if <your function> is not None: list.append(<your function>) > Basically, if a directory listing from an FTP site does *not* have a file > with today's date on it, it should be added to the list badFiles. Since > some > directories are fine, they're being added as None. How can I either stop > this, or just remove them from the final list. Either solution would work > just as well for me. > result=[] for item in list: if item is not None: result.append item > Thanks for the continued help. I appreciate it. > > Britt > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Grreetings Jö! -- Sent through GMX FreeMail - http://www.gmx.net From lha2@columbia.edu Sat Mar 10 11:24:13 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Sat, 10 Mar 2001 06:24:13 -0500 Subject: [Tutor] re: [Totor] string iteration References: <E14becY-0001Jc-00@mail.python.org> Message-ID: <3AAA0EDD.9FEEE257@mail.verizon.net> ewe2 wrote: > given a string a = 'abcdefghijklmnop' and a string b = 'abc', how do i > iterate b against a, so i get a string c = 'abcabcabcabcabca' the length of a? > my brain is hurting from all the failed for loops :) Here's my go, along with the thinking that went into it >>> a = 'abcdefghijklmnopq' >>> len(a) 17 #wanted to make sure that len(a) is not divisible by 3--if it were, it would be easy to get a function that works today but fails to work tomorrow >>> b='abc' >>> len(b) 3 #I'm relatively new to Python, and wanted to make sure that len(foo) doesn't have off-by-one from the behavior that I would expect. It acts as I expect. >>> c='' #initialize the target string--probably could have used a more descriptive name >>> for foo in range(len(a)): c=c+b[foo%len(b)] #you weren't clear about how the for loops were failing. The thing that kept throwing me off at first is that for has to iterate over a list, not just up to a ceiling--range(x) returns a list that goes from 0 to x-1, which is x units long. '%' is the (integer) modular division operation (return the remainder of the division operation, which in this case will be a number between 0 and 2). >>> c 'abcabcabcabcabcab' # it worked. Because you didn't give your math and python background, and because I'm good in math but new to Python, I overcommented (in large part for my own benefit)--hope it only annoyed a few folks on the list. -LHA From amoreira@mercury.ubi.pt Sat Mar 10 13:53:46 2001 From: amoreira@mercury.ubi.pt (Jose Amoreira) Date: Sat, 10 Mar 2001 13:53:46 +0000 Subject: [Tutor] Removing Null Elements from a List References: <F262de13YDLVBXbpEki000054e8@hotmail.com> Message-ID: <3AAA31EA.A4A1B81A@mercury.ubi.pt> Hello! I remove a given value from a list like this: while undesired_value in mylist: mylist.remove(undesired_value) In this case, mylist is your list (this sounds weird...) and undesired_value is None (wich in any other context would mean that all values are desired [even None?]). I think that it would be better to avoid appending None to the list, instead of removing None from the list in the end, but I didn't fully understand what the code is supposed to do, so... Hope it helps! Ze amoreira@mercury.ubi.pt Britt Green wrote: > If I have a list that looks like: > > [None, None, None, None, None, None, None, None, None, None, > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, None, > None, None, None, None, None, None, None, None, None, None, > ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, None, > None, None, None, None, None, None, None, None, ['/boston/rplace'], > ['/boston/salamander'], None, ['/boston/test'], ['/boston/the_federalist'], > None, ['/boston/yanks']] > > How can I remove those None elements in it? The code that I'm getting that > from is, in part, this: > > chosen = [] > badFiles = [] > > pick = re.compile(theDate) > for elements in files: > if pick.search(elements): > chosen.append(elements) > #print chosen > > if chosen == []: > #print ftp.pwd() > badFiles.append(ftp.pwd() ) > return badFiles > > Basically, if a directory listing from an FTP site does *not* have a file > with today's date on it, it should be added to the list badFiles. Since some > directories are fine, they're being added as None. How can I either stop > this, or just remove them from the final list. Either solution would work > just as well for me. > > Thanks for the continued help. I appreciate it. > > Britt > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From Lindsay.Davies@moonshine.co.uk Sat Mar 10 14:06:54 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Sat, 10 Mar 2001 14:06:54 +0000 Subject: [Tutor] string iteration In-Reply-To: <20010310123814.A608@can.org.au> References: <20010310123814.A608@can.org.au> Message-ID: <p05010417b6cfe52ecbb3@[195.102.186.233]> On 10/3/01, <ewe2@can.org.au> wrote about '[Tutor] string iteration': >ok, i'm feeling particularly stupid today: > >given a string a = 'abcdefghijklmnop' and a string b = 'abc', how do i >iterate b against a, so i get a string c = 'abcabcabcabcabca' the length of a? >my brain is hurting from all the failed for loops :) Here's my bash at it... c = (b * (len(a) / len(b))) + b[:len(a) % len(b)] Best wishes, Lindsay From dyoo@hkn.eecs.berkeley.edu Sat Mar 10 14:29:19 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 10 Mar 2001 06:29:19 -0800 (PST) Subject: [Tutor] Removing Null Elements from a List In-Reply-To: <F262de13YDLVBXbpEki000054e8@hotmail.com> Message-ID: <Pine.LNX.4.21.0103100620330.13096-100000@hkn.eecs.berkeley.edu> On Fri, 9 Mar 2001, Britt Green wrote: > If I have a list that looks like: > > [None, None, None, None, None, None, None, None, None, None, > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, None, > None, None, None, None, None, None, None, None, None, None, > ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, None, > None, None, None, None, None, None, None, None, ['/boston/rplace'], > ['/boston/salamander'], None, ['/boston/test'], ['/boston/the_federalist'], > None, ['/boston/yanks']] > > How can I remove those None elements in it? The code that I'm getting that > from is, in part, this: One way to do this is to use the functional tool filter(): ### def isTrue(x): if x: return 1 else: return 0 cleanFiles = filter(isTrue, files) ### That's one way of removing all the None's out of there: isTrue() is a function that says 1 only when the filename is either nonempty or not None. Hmmm... In more Python 2.0 terms, it's doing something like this: cleanfiles = [f for f in files if f != None] Sorry, I'm a stickler for functional stuff sometimes... The list comprehension way is probably a lot easier to read: it creates for us a list of all files that aren't None. We can extend this method to take care of both the None's and the badfiles in one swoop: chosen = [f for f in files if pick.search(f) and f != None] should do it. (I renamed 'elements' to 'f' to save some space.) Hope this helps! From tim.one@home.com Sat Mar 10 20:11:15 2001 From: tim.one@home.com (Tim Peters) Date: Sat, 10 Mar 2001 15:11:15 -0500 Subject: [Tutor] Removing Null Elements from a List In-Reply-To: <Pine.LNX.4.21.0103100620330.13096-100000@hkn.eecs.berkeley.edu> Message-ID: <LNBBLJKPBEHFEDALKOLCAELNJEAA.tim.one@home.com> [Britt Green] > If I have a list that looks like: > > [None, None, None, None, None, None, None, None, None, None, > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, > None, None, None, None, None, None, None, None, None, None, None, > None, ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], > None, None, None, None, None, None, None, None, None, None, > ['/boston/rplace'], ['/boston/salamander'], None, ['/boston/test'], > ['/boston/the_federalist'], None, ['/boston/yanks']] > > How can I remove those None elements in it? > ... [Daniel Yoo] > One way to do this is to use the functional tool filter(): > > ### > def isTrue(x): > if x: return 1 > else: return 0 > > cleanFiles = filter(isTrue, files) > ### > > That's one way of removing all the None's out of there: isTrue() is a > function that says 1 only when the filename is either nonempty or not > None. First note that isTrue is the same as operator.truth: >>> import operator >>> print operator.truth.__doc__ truth(a) -- Return 1 if a is true, and 0 otherwise. >>> filter(operator.truth, ["", "a", None, ["b"], 0.0]) ['a', ['b']] >>> Then note that filter supports a little-known special case: >>> print filter.__doc__ filter(function, sequence) -> list Return a list containing those items of sequence for which function(item) is true. If function is None, return a list of items that are true. >>> filter(None, ["", "a", None, ["b"], 0.0]) ['a', ['b']] >>> So filter(None, list) works for this without further ado, and happens to be very fast. From britt_green@hotmail.com Sat Mar 10 20:18:38 2001 From: britt_green@hotmail.com (Britt Green) Date: Sat, 10 Mar 2001 12:18:38 -0800 Subject: [Tutor] Removing Null Elements from a List Message-ID: <F251yeKzGZuNY1SWoBD00005902@hotmail.com> Again, I thank you for the code. I was wondering if there was anyplace on the web that I could've found an answer to this on my own. I've checked the documentation at python.org, but sometimes its a bit lacking. Also, might anyone out there have a recommendation for a good Python book? I've heard the O'Reilly ones are great. I have an intro to Python by Alan Gauld which was excellent, but I now need something a bit more in-depth to accompany it. Thanks! Britt >From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu> >To: Britt Green <britt_green@hotmail.com> >CC: tutor@python.org >Subject: Re: [Tutor] Removing Null Elements from a List >Date: Sat, 10 Mar 2001 06:29:19 -0800 (PST) > >On Fri, 9 Mar 2001, Britt Green wrote: > > > If I have a list that looks like: > > > > [None, None, None, None, None, None, None, None, None, None, > > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, >None, > > None, None, None, None, None, None, None, None, None, None, > > ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, >None, > > None, None, None, None, None, None, None, None, ['/boston/rplace'], > > ['/boston/salamander'], None, ['/boston/test'], >['/boston/the_federalist'], > > None, ['/boston/yanks']] > > > > How can I remove those None elements in it? The code that I'm getting >that > > from is, in part, this: > >One way to do this is to use the functional tool filter(): > >### >def isTrue(x): > if x: return 1 > else: return 0 > >cleanFiles = filter(isTrue, files) >### > >That's one way of removing all the None's out of there: isTrue() is a >function that says 1 only when the filename is either nonempty or not >None. > > >Hmmm... In more Python 2.0 terms, it's doing something like this: > > cleanfiles = [f for f in files if f != None] > >Sorry, I'm a stickler for functional stuff sometimes... The list >comprehension way is probably a lot easier to read: it creates for us a >list of all files that aren't None. > > >We can extend this method to take care of both the None's and the badfiles >in one swoop: > > chosen = [f for f in files if pick.search(f) and f != None] > >should do it. (I renamed 'elements' to 'f' to save some space.) > >Hope this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Sun Mar 11 00:11:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 10 Mar 2001 16:11:33 -0800 (PST) Subject: [Tutor] Removing Null Elements from a List In-Reply-To: <F251yeKzGZuNY1SWoBD00005902@hotmail.com> Message-ID: <Pine.LNX.4.21.0103101544540.863-100000@c82114-a.pinol1.sfba.home.com> On Sat, 10 Mar 2001, Britt Green wrote: > Again, I thank you for the code. > I was wondering if there was anyplace on the web that I could've found an > answer to this on my own. I've checked the documentation at python.org, but > sometimes its a bit lacking. The way I learned list comprehensions was by watching other people use it. There's a really brief overview of list comprehensions in the official tutorial: http://python.org/doc/current/tut/node7.html#SECTION007140000000000000000 However, it seems that the tutorial only touches glancingly on this subject; it doesn't give much explanation about list comprehensions. The other place that I've seen it mentioned is in the "What's New with Python 2.0" document: http://python.org/2.0/new-python.html#SECTION000600000000000000000 which gives a more in-depth explanation of list comprehensions. However, that's all I've found as far as documentation. > Also, might anyone out there have a recommendation for a good Python > book? I've heard the O'Reilly ones are great. I have an intro to > Python by Alan Gauld which was excellent, but I now need something a > bit more in-depth to accompany it. I've only taken a brief look at "Core Python Programming", by Wesley Chun, but it looks like a good book. Good luck to you. From pdiaz88@terra.es Sat Mar 10 18:37:38 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 10 Mar 2001 19:37:38 +0100 Subject: [Tutor] Removing Null Elements from a List In-Reply-To: <F262de13YDLVBXbpEki000054e8@hotmail.com> References: <F262de13YDLVBXbpEki000054e8@hotmail.com> Message-ID: <01031019373801.02944@tajo> Lambda attack to the problem ;D >>> a=[2,3,45,76,None,None,None,54] >>> filter( lambda x:x!=None, a ) [2, 3, 45, 76, 54] >>> Cheers Pedro On Saturday 10 March 2001 07:57, Britt Green wrote: > If I have a list that looks like: > > [None, None, None, None, None, None, None, None, None, None, > ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None, > None, None, None, None, None, None, None, None, None, None, None, > ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None, None, > None, None, None, None, None, None, None, None, ['/boston/rplace'], > ['/boston/salamander'], None, ['/boston/test'], ['/boston/the_federalist'], > None, ['/boston/yanks']] > > How can I remove those None elements in it? The code that I'm getting that > from is, in part, this: > > chosen = [] > badFiles = [] > > > pick = re.compile(theDate) > for elements in files: > if pick.search(elements): > chosen.append(elements) > #print chosen > > if chosen == []: > #print ftp.pwd() > badFiles.append(ftp.pwd() ) > return badFiles > > Basically, if a directory listing from an FTP site does *not* have a file > with today's date on it, it should be added to the list badFiles. Since > some directories are fine, they're being added as None. How can I either > stop this, or just remove them from the final list. Either solution would > work just as well for me. > > Thanks for the continued help. I appreciate it. > > Britt > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From pdiaz88@terra.es Sat Mar 10 18:49:32 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 10 Mar 2001 19:49:32 +0100 Subject: [Tutor] Hmmm... In-Reply-To: <Pine.LNX.4.21.0103091834310.952-100000@c82114-a.pinol1.sfba.home.com> References: <Pine.LNX.4.21.0103091834310.952-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <01031019493202.02944@tajo> Didn't read all the replies, so sorry if this response is a repetition lambda attack to the problem: >>> a=['pera','manzana','limon','naranja'] >>> filter( lambda x:x[len(x)-1]=='a', a ) ['pera', 'manzana', 'naranja'] >>> Cheers Pedro On Saturday 10 March 2001 03:38, Danny Yoo wrote: > On Fri, 9 Mar 2001, Britt Green wrote: > > import string > > > > theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] > > > > chosen = [] > > > > for stuff in theFruits: > > if stuff.endswith('e'): > > chosen.append(stuff) > > > > print chosen > > > > When run, only the elements of theFruits that end with an 'e' will get > > added to the list of chosen. Is there a better way to do this? > > Here's another wacky way to do that: > > ### > def endsWithE(word): > return word.endswith('e') > > theFruits = ['apple', 'banana', 'pineapple', 'pear', 'orange'] > chosen = filter(endsWithE, theFruits) > print chosen > ### > > which tells Python: "Ok, let's filter out only theFruits that > endsWithE()." This is called the "functional" approach, because all we're > doing is function calls and passing functions around. It's a lot of fun. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From sheila@thinkspot.net Sun Mar 11 02:22:07 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 10 Mar 2001 18:22:07 -0800 Subject: [Tutor] Object comparison vs. Identity Message-ID: <9D08484FE7@kserver.org> I recently received one of the Python books I ordered: Core Python Programming by Wesley Chun Seems OK. Since I've already programmed in a few different languages, and worked through the Python tutorial, I'm doing fine with it. It is definitely not a book for someone who has never programmed before. Anyhow, to my question... On pp. 84 - 85 he is discussing object identity, and presents the following example: foo1 = 4 foo2 = 3 + 1 He says that the first statement creates a numeric object and assigns it to foo1. The second statement creates a numeric object, and assigns it to foo2. Although the value of the two objects are the same, he claims that they are two distinct objects. (I read this as implying, that while foo1==foo2 would return 1, he is saying that id(foo1) == id(foo2), or alternatively foo1 is foo2 would both return 0.) Now, on my Win98 machine, in an interactive IDLE session, I got the following: >>> x = 4 >>> y = 3+1 >>> id(x) 8400780 >>> id(y) 8400780 >>> y is x 1 >>> I also typed up a similar example, saved it in a file, and ran it from a DOS prompt, and got the same results. 3+1 did not create a different object for me than 4. Is this something I should write to the author about, and let him know there is an error? Or is there something I'm not picking up on going on here? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Sun Mar 11 02:37:23 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 10 Mar 2001 18:37:23 -0800 Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <9D08484FE7@kserver.org> References: <9D08484FE7@kserver.org> Message-ID: <AB092723A3@kserver.org> On Sat, 10 Mar 2001 18:22:07 -0800, Sheila King <sheila@thinkspot.net> wrote about [Tutor] Object comparison vs. Identity: : :Is this something I should write to the author about, and let him know there :is an error? Or is there something I'm not picking up on going on here? By the way, I found the author's website for the book, here: http://starship.python.net/crew/wesc/cpp/ and in the "Guestbook", which is here: http://starship.python.net/crew/wesc/cgi-bin/readfeed.cgi someone else (named Guido Truetwein) mentions this very example from Chapter 3, and says that it is an error (due to instances of small integers?). -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From pdiaz88@terra.es Sat Mar 10 19:43:12 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 10 Mar 2001 20:43:12 +0100 Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <9D08484FE7@kserver.org> References: <9D08484FE7@kserver.org> Message-ID: <01031020431204.02944@tajo> Maybe the author wants to explain that foo1 and foo2 are two diferent instances of the numeric (or whatever) class but they hold the same numeric value Cheers Pedro On Sunday 11 March 2001 03:22, Sheila King wrote: > I recently received one of the Python books I ordered: > Core Python Programming by Wesley Chun > > Seems OK. Since I've already programmed in a few different languages, and > worked through the Python tutorial, I'm doing fine with it. It is > definitely not a book for someone who has never programmed before. > > Anyhow, to my question... > > On pp. 84 - 85 he is discussing object identity, and presents the following > example: > foo1 = 4 > foo2 = 3 + 1 > > He says that the first statement creates a numeric object and assigns it to > foo1. The second statement creates a numeric object, and assigns it to > foo2. Although the value of the two objects are the same, he claims that > they are two distinct objects. > (I read this as implying, that while > foo1==foo2 would return 1, > he is saying that id(foo1) == id(foo2), > or alternatively foo1 is foo2 > would both return 0.) > > Now, on my Win98 machine, in an interactive IDLE session, I got the following: > >>> x = 4 > >>> y = 3+1 > >>> id(x) > > 8400780 > > >>> id(y) > > 8400780 > > >>> y is x > > 1 > > > I also typed up a similar example, saved it in a file, and ran it from a > DOS prompt, and got the same results. 3+1 did not create a different object > for me than 4. > > Is this something I should write to the author about, and let him know > there is an error? Or is there something I'm not picking up on going on > here? > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From sheila@thinkspot.net Sun Mar 11 02:41:26 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 10 Mar 2001 18:41:26 -0800 Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <01031020431204.02944@tajo> References: <9D08484FE7@kserver.org> <01031020431204.02944@tajo> Message-ID: <AEBB3208A2@kserver.org> On Sat, 10 Mar 2001 20:43:12 +0100, Pedro Diaz Jimenez <pdiaz88@terra.es> wrote about Re: [Tutor] Object comparison vs. Identity: :Maybe the author wants to explain that foo1 and foo2 are two diferent :instances of the numeric (or whatever) class but they hold the same numeric :value : :Cheers :Pedro I'm sure that that is what he WANTS to explain, but I think he has (possibly) made an error in this instance? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From pdiaz88@terra.es Sat Mar 10 19:52:35 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 10 Mar 2001 20:52:35 +0100 Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <AB092723A3@kserver.org> References: <9D08484FE7@kserver.org> <AB092723A3@kserver.org> Message-ID: <01031020523505.02944@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 >>> class d: ... g = 2 ... >>> q1 = d() >>> q2 = d() >>> id(q1) 134682456 >>> id(q2) 134682640 >>> Maybe a bad choosen example (instances of builtin types maybe)? Cheers Pedro On Sunday 11 March 2001 03:37, Sheila King wrote: > On Sat, 10 Mar 2001 18:22:07 -0800, Sheila King <sheila@thinkspot.net> > wrote > > about [Tutor] Object comparison vs. Identity: > :Is this something I should write to the author about, and let him know > : there is an error? Or is there something I'm not picking up on going on > : here? > > By the way, I found the author's website for the book, here: > http://starship.python.net/crew/wesc/cpp/ > > and in the "Guestbook", which is here: > http://starship.python.net/crew/wesc/cgi-bin/readfeed.cgi > > someone else (named Guido Truetwein) mentions this very example from > Chapter 3, and says that it is an error (due to instances of small > integers?). > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6qoYDnu53feEYxlERAltVAKCtOQGoP2Mps8dZszPldLpZxyRoGgCgsfTm dYJGc9bXn2tKWUnmw7E5WKw= =S54r -----END PGP SIGNATURE----- From senum@singnet.com.sg Sun Mar 11 03:02:49 2001 From: senum@singnet.com.sg (senum@singnet.com.sg) Date: Sun, 11 Mar 2001 11:02:49 +0800 Subject: [Tutor] how do i join this discussion?the links on python.org doesnt work. Message-ID: <3AAB5B59.3687.637D03@localhost> From kojo@tamu.edu Sun Mar 11 03:17:49 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Sat, 10 Mar 2001 21:17:49 -0600 Subject: [Tutor] how do i join this discussion?the links on python.org doesnt work. In-Reply-To: <3AAB5B59.3687.637D03@localhost> Message-ID: <5.0.2.1.0.20010310211719.02219d20@pop3.norton.antivirus> Try the link at the bottom of your message, quoted below. At 11:02 AM 3/11/01 +0800, senum@singnet.com.sg wrote: >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** From deirdre@deirdre.net Sun Mar 11 03:24:50 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 10 Mar 2001 19:24:50 -0800 (PST) Subject: [Tutor] how do i join this discussion?the links on python.org doesnt work. In-Reply-To: <3AAB5B59.3687.637D03@localhost> Message-ID: <Pine.LNX.4.31.0103101924300.21304-100000@emperor.deirdre.org> On Sun, 11 Mar 2001 senum@singnet.com.sg wrote: You're here. Welcome. Just email any questions to tutor@python.org. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From senum@singnet.com.sg Sun Mar 11 05:57:52 2001 From: senum@singnet.com.sg (senum@singnet.com.sg) Date: Sun, 11 Mar 2001 13:57:52 +0800 Subject: [Tutor] Hi all. Message-ID: <3AAB8460.4849.1035D18@localhost> Hi..thanks for the replies.First of all i tried the list but it didnt work. Anyway i have a few questions..any replies would be greatly appreciated :) I'm keen on taking up Python..the only language I had experience is C.I tried reading the official docs and tutorial at python.org but found them to be a bit dry.And the other tutorials around the web seems a bit too well,for the really new non programmer. Is there a online tutorial somewhere i might have missed? And is the official docs enough to grasp the whole language syntax and working or do i need to buy a book?Coz i've been looking around my local stores and none of them as any python books[neither did they know what it is]..seems that python's not popular[close to unknown perhaps] here.Is it possible to get a copy elsewhere for a low price[say someone who doesnt want his/her copy anymore].I would really like to get in on Python..but i'm kinda lost. Thanks. From dyoo@hkn.eecs.berkeley.edu Sun Mar 11 06:36:52 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 10 Mar 2001 22:36:52 -0800 (PST) Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <9D08484FE7@kserver.org> Message-ID: <Pine.LNX.4.21.0103102223370.2210-100000@c82114-a.pinol1.sfba.home.com> On Sat, 10 Mar 2001, Sheila King wrote: > On pp. 84 - 85 he is discussing object identity, and presents the following > example: > foo1 = 4 > foo2 = 3 + 1 > He says that the first statement creates a numeric object and assigns it to > foo1. The second statement creates a numeric object, and assigns it to foo2. > Although the value of the two objects are the same, he claims that they are > two distinct objects. > (I read this as implying, that while > foo1==foo2 would return 1, > he is saying that id(foo1) == id(foo2), > or alternatively foo1 is foo2 > would both return 0.) True; however, the reason that this doesn't work for small numbers is because the integers are precached --- Python keeps instances of the integers from -1 to 100 to reduce the cost of using these popular numbers. We can empirically see this with a small experiment: ### >>> for i in range(-1, 105): ... x = int(i * 1.0) ## Doing a little bit of trickery here ... y = int(i * 1.0) ## to guarantee the construction ... if x is not y: print x ... 100 101 102 103 104 ### Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sun Mar 11 06:45:30 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 10 Mar 2001 22:45:30 -0800 (PST) Subject: [Tutor] Hi all. In-Reply-To: <3AAB8460.4849.1035D18@localhost> Message-ID: <Pine.LNX.4.21.0103102237060.2210-100000@c82114-a.pinol1.sfba.home.com> On Sun, 11 Mar 2001 senum@singnet.com.sg wrote: > Hi..thanks for the replies.First of all i tried the list but it didnt > work. Anyway i have a few questions..any replies would be greatly > appreciated :) (Try to sign up again later; it appears that the web interface isn't working at the moment. You'll receive replies to your own messages, but you're missing out on the other messages addressed to the general tutor list.) > I'm keen on taking up Python..the only language I had experience is > C.I tried reading the official docs and tutorial at python.org but > found them to be a bit dry.And the other tutorials around the web > seems a bit too well,for the really new non programmer. Is there a > online tutorial somewhere i might have missed? Which ones have you tried? I like Alan Gauld's tutorial a lot: http://www.crosswinds.net/~agauld/ and the ones linked up here: http://python.org/doc/Intros.html are all very good. Go for the "Non Programmers" section, and see if they're slightly more moist and chewy. If you have questions about Python, feel free to ask us. It's a quiet weekend. From kauphlyn@speakeasy.org Sun Mar 11 08:34:58 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Sun, 11 Mar 2001 00:34:58 -0800 (PST) Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <Pine.LNX.4.21.0103102223370.2210-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <Pine.LNX.4.21.0103110016510.20865-100000@grace.speakeasy.org> On Sat, 10 Mar 2001, Danny Yoo wrote: > True; however, the reason that this doesn't work for small numbers is > because the integers are precached --- Python keeps instances of the > integers from -1 to 100 to reduce the cost of using these popular numbers. > We can empirically see this with a small experiment: Does 'precached' mean that for those values python will always refer to the same instance? I am very new at this programming business, but i am presuming that if the id is the same, then the instance is the same. And if that is so, then the book that Sheila mentioned is a little misleading on this point, since it doesnt point out this exception - yet uses as an example one of these exceptional integers. From cpsoct@lycos.com Sun Mar 11 10:50:41 2001 From: cpsoct@lycos.com (kevin parks) Date: Sun, 11 Mar 2001 19:50:41 +0900 Subject: [Tutor] [ot] comp.lang.python Message-ID: <PAGGBDEDJBPBDAAA@mailcity.com> Anyone here know how i can read USENET newsgroups over the web. For the last year or so i was an avid www.deja.com user, but Google has decide to buy and destroy deja.com microsoft-style -- gobbling up Deja, killing it's user's accounts (save e-mail) -- www bookmarks, saved threads, etc. are all gone now), and replacing it with a service which is really only a search and not a full blown news reader, poster, archiver, etc. This has left me high and dry as i love to read comp.lang.python and now am really not able to (unless you want to read the same messages over and over, not be able to mark them read, reply, start a post, etc. google sucks for snuffing out deja and not replacing it with anything remotely like it. What they have up there now is simply searching. Ughh. i want my comp.lang.python. R.I.P. Deja-news. kevin cpsoct@lycos.com Get 250 color business cards for FREE! at Lycos Mail http://mail.lycos.com/freemail/vistaprint_index.html From arcege@shore.net Sun Mar 11 13:22:28 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 11 Mar 2001 08:22:28 -0500 (EST) Subject: [Tutor] [ot] comp.lang.python In-Reply-To: <PAGGBDEDJBPBDAAA@mailcity.com> from kevin parks at "Mar 11, 2001 7:50:41 pm" Message-ID: <E14c5no-00016R-00@nautilus.shore.net> > Anyone here know how i can read USENET newsgroups over the web. For the last > full blown news reader, poster, archiver, etc. This has left me high and dry > > google sucks for snuffing out deja and not replacing it with anything remotel > > i want my comp.lang.python. There are a few mirrors for the newsgroup, cumulatively called the "python-list". One at Deja/Google, another at Yahoo and at Python.org. <URL: http://www.python.org/search/search_news.html> -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From rob@jam.rr.com Sun Mar 11 13:27:55 2001 From: rob@jam.rr.com (Rob) Date: Sun, 11 Mar 2001 07:27:55 -0600 Subject: [Tutor] [ot] comp.lang.python References: <PAGGBDEDJBPBDAAA@mailcity.com> Message-ID: <3AAB7D5B.6070100@jam.rr.com> I, too, grieve over what's happened with deja.com, but I suspect that google will do right by us as soon as they can. I've searched around, but there just doesn't appear to be anything else quite like deja.com out there. Rob kevin parks wrote: > Anyone here know how i can read USENET newsgroups over the web. For the last year or so i was an avid www.deja.com user, but Google has decide to buy and destroy deja.com microsoft-style -- gobbling up Deja, killing it's user's accounts (save e-mail) -- www bookmarks, saved threads, etc. are all gone now), and replacing it with a service which is really only a search and not a > full blown news reader, poster, archiver, etc. This has left me high and dry as i love to read comp.lang.python and now am really not able to (unless you want to read the same messages over and over, not be able to mark them read, reply, start a post, etc. > > google sucks for snuffing out deja and not replacing it with anything remotely like it. What they have up there now is simply searching. Ughh. > > i want my comp.lang.python. > > R.I.P. Deja-news. > > kevin -- The Useless Python Repository has received an XHTML face-lift! http://www.lowerstandard.com/python/pythonsource.html From scarblac@pino.selwerd.nl Sun Mar 11 14:15:55 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 11 Mar 2001 15:15:55 +0100 Subject: [Tutor] [ot] comp.lang.python In-Reply-To: <PAGGBDEDJBPBDAAA@mailcity.com>; from cpsoct@lycos.com on Sun, Mar 11, 2001 at 07:50:41PM +0900 References: <PAGGBDEDJBPBDAAA@mailcity.com> Message-ID: <20010311151555.A18663@pino.selwerd.nl> On Sun, Mar 11, 2001 at 07:50:41PM +0900, kevin parks wrote: > Anyone here know how i can read USENET newsgroups over the web. For the > last year or so i was an avid www.deja.com user, but Google has decide to > buy and destroy deja.com microsoft-style -- gobbling up Deja, killing it's This is not right. Deja is broke. Google bought a copy of the database *just* in time, according to the people there who did the copying, they managed to copy things off the drives about 10 minutes before the machines were hauled away. Google saved the archive. They've just had a few weeks time now to set up a whole web infrastructure for it. Be patient, furrfu. Google are the good guys. They have the best and best looking web search engine, they use Python all over the place, I already like their Usenet interface better than Deja's ever was, *they have a clue*, and I'm sure posting from them will be great soon as well. > user's accounts (save e-mail) -- www bookmarks, saved threads, etc. are all > gone now), and replacing it with a service which is really only a search and > not a full blown news reader, poster, archiver, etc. They are working on it, as their page says. I'd like to see you setup such a site in a month... > This has left me high and > dry as i love to read comp.lang.python and now am really not able to (unless > you want to read the same messages over and over, not be able to mark them > read, reply, start a post, etc. Try some of the ones that Google suggests, ie http://directory.google.com/Top/Computers/Usenet/Web_Based/ Of course, reading Usenet on the Web sucks. Doesn't your ISP have a news server? If not, searching for "free news server" on Google gives quite a few sites that list open news servers (but this is not ideal since those servers are often open by accident, so you have to find a new one now and then). Good newsreaders for Windows are for instance XNews and Free Agent. There are some commercial news servers as well, but I don't know the names. And in the end, all that comp.lang.python is, is a mirror of the Python mailing list. You can always use that interface, same way you read the Tutor list now. Unfortunately, it has far more posts... > google sucks for snuffing out deja and not replacing it with anything > remotely like it. What they have up there now is simply searching. Ughh. Deja snuffed out itself. Google only bought a copy, Deja could have continued if it wanted to, but it's hard when all your computers are being sold by people you owe money to... And of course, if you really hate the way Google does it, you can always ask your money back ;) -- Remco Gerlich From sheila@thinkspot.net Sun Mar 11 17:15:56 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 11 Mar 2001 09:15:56 -0800 Subject: [Tutor] [ot] comp.lang.python In-Reply-To: <PAGGBDEDJBPBDAAA@mailcity.com> References: <PAGGBDEDJBPBDAAA@mailcity.com> Message-ID: <3CE84D05D81@kserver.org> On Sun, 11 Mar 2001 19:50:41 +0900, "kevin parks" <cpsoct@lycos.com> wrote about [Tutor] [ot] comp.lang.python: :i want my comp.lang.python. : :R.I.P. Deja-news. Two that you might want to try: www.mailgate.com Mailgate does allow you to read and post. It doesn't have a lot of customization/preference settings. You are not required to register with the service in order to post. www.newsranger.com Newsranger has quite a few preference settings. I am really impressed with that aspect of it. However, navigation on the site (in its current incarnation) is not so hot. But, I did post a message to their newsranger.support newsgroup, suggesting ways to improve the site, and the response I received from the admin seemed like they were receptive to the ideas and would try to implement them. When...I have no idea. It's been nearly two weeks, and I see no change, yet. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From tim@johnsons-web.com Sun Mar 11 17:40:56 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Mar 2001 08:40:56 -0900 Subject: [Tutor] Python Daemon References: <20010311151555.A18663@pino.selwerd.nl> Message-ID: <01031108460408.11686@shecom> Hello: I'd like to write a test python script as a daemon. (Red Hat 6.0) If the topic is a little involved, (and I'm sure it is), I'd be perfectly happy if someone could just point me to some documentation to get me started. TIA Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From sheila@thinkspot.net Sun Mar 11 17:41:59 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 11 Mar 2001 09:41:59 -0800 Subject: [Tutor] Object comparison vs. Identity In-Reply-To: <Pine.LNX.4.21.0103102223370.2210-100000@c82114-a.pinol1.sfba.home.com> References: <9D08484FE7@kserver.org> <Pine.LNX.4.21.0103102223370.2210-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <3E65F587456@kserver.org> Thanks, Danny, for the explanation about the list of cached ints. I think I will e-mail this thread to the author, so that he is aware that this example from his book needs to be changed. Or at least, he should modify SOMETHING with respect to using certain integers to show the difference in object identity. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sat, 10 Mar 2001 22:36:52 -0800 (PST), Danny Yoo <dyoo@hkn.eecs.berkeley.edu> wrote about Re: [Tutor] Object comparison vs. Identity: :On Sat, 10 Mar 2001, Sheila King wrote: : :> On pp. 84 - 85 he is discussing object identity, and presents the following :> example: :> foo1 = 4 :> foo2 = 3 + 1 :> He says that the first statement creates a numeric object and assigns it to :> foo1. The second statement creates a numeric object, and assigns it to foo2. :> Although the value of the two objects are the same, he claims that they are :> two distinct objects. :> (I read this as implying, that while :> foo1==foo2 would return 1, :> he is saying that id(foo1) == id(foo2), :> or alternatively foo1 is foo2 :> would both return 0.) : : :True; however, the reason that this doesn't work for small numbers is :because the integers are precached --- Python keeps instances of the :integers from -1 to 100 to reduce the cost of using these popular numbers. :We can empirically see this with a small experiment: : :### :>>> for i in range(-1, 105): :... x = int(i * 1.0) ## Doing a little bit of trickery here :... y = int(i * 1.0) ## to guarantee the construction :... if x is not y: print x :... :100 :101 :102 :103 :104 :### : From deirdre@deirdre.net Sun Mar 11 19:31:07 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 11 Mar 2001 11:31:07 -0800 (PST) Subject: [Tutor] [ot] comp.lang.python In-Reply-To: <20010311151555.A18663@pino.selwerd.nl> Message-ID: <Pine.LNX.4.31.0103111127310.319-100000@emperor.deirdre.org> On Sun, 11 Mar 2001, Remco Gerlich wrote: > Of course, reading Usenet on the Web sucks. Doesn't your ISP have a > news server? If not, searching for "free news server" on Google gives > quite a few sites that list open news servers (but this is not ideal > since those servers are often open by accident, so you have to find a > new one now and then). Good newsreaders for Windows are for instance > XNews and Free Agent. There are some commercial news servers as well, > but I don't know the names. In the "excellent but not free" category, I subscribe to newsguy.com which does really major news serving. It doesn't archive, but they do have a long expire time. You can read either via the web or via a news server; I personally run a leafnode server that fetches groups I read from it (it only gets groups read in the last week). > > google sucks for snuffing out deja and not replacing it with anything > > remotely like it. What they have up there now is simply searching. Ughh. > > Deja snuffed out itself. Google only bought a copy, Deja could have > continued if it wanted to, but it's hard when all your computers are > being sold by people you owe money to... If deja had stuck to news services and just used banner ads on each page, they probably would have survived. As it was, they had grandiose plans that migrated further and further from their original business model and cost a lot of money. Heck, they probably could have instituted a subscription service for posts > 60 days old and some of us would have paid a reasonable quarterly fee for it. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Sun Mar 11 10:20:36 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sun, 11 Mar 2001 11:20:36 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <01031108460408.11686@shecom> References: <20010311151555.A18663@pino.selwerd.nl> <01031108460408.11686@shecom> Message-ID: <01031111203600.00530@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 hi, In order to make a daemon, you've got to fork() and kill the father. Then you have a child in the background Example: #!/usr/bin/python import os import sys import time if os.fork(): sys.exit() print "Child still here" time.sleep(10) print "Child exiting" Look at the library reference for more information Cheers Pedro On Sunday 11 March 2001 18:40, Tim Johnson wrote: > Hello: > I'd like to write a test python script as a daemon. > (Red Hat 6.0) > If the topic is a little involved, (and I'm sure it is), > I'd be perfectly happy if someone could just point > me to some documentation to get me started. > TIA > Regards > -- > Tim Johnson > ----------- > "Of all manifestations of power, > restraint impresses the most." > -Thucydides > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6q1F7nu53feEYxlERAi92AJ91XvronniACBLun3RV6qk1o8ZWRwCeIYLh HBeJK+Dij7o2EgebFzmTLLQ= =RwCY -----END PGP SIGNATURE----- From sheila@thinkspot.net Sun Mar 11 22:02:11 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 11 Mar 2001 14:02:11 -0800 Subject: [Tutor] Python Daemon In-Reply-To: <01031111203600.00530@tajo> References: <20010311151555.A18663@pino.selwerd.nl> <01031108460408.11686@shecom> <01031111203600.00530@tajo> Message-ID: <4D298960E1C@kserver.org> os.fork() is not available on Windows machines. Is there an alternate way to handle this for Windows machines? Or, is it impossible to write daemons for Windows machines? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sun, 11 Mar 2001 11:20:36 +0100, Pedro Diaz Jimenez <pdiaz88@terra.es> wrote about Re: [Tutor] Python Daemon: :-----BEGIN PGP SIGNED MESSAGE----- :Hash: SHA1 : :hi, : :In order to make a daemon, you've got to fork() and kill the father. Then :you have a child in the background : :Example: : :#!/usr/bin/python :import os :import sys :import time :if os.fork(): : sys.exit() :print "Child still here" :time.sleep(10) :print "Child exiting" : :Look at the library reference for more information : :Cheers :Pedro : :On Sunday 11 March 2001 18:40, Tim Johnson wrote: :> Hello: :> I'd like to write a test python script as a daemon. :> (Red Hat 6.0) :> If the topic is a little involved, (and I'm sure it is), :> I'd be perfectly happy if someone could just point :> me to some documentation to get me started. :> TIA :> Regards :> -- :> Tim Johnson :> ----------- :> "Of all manifestations of power, :> restraint impresses the most." :> -Thucydides :> :> _______________________________________________ :> Tutor maillist - Tutor@python.org :> http://mail.python.org/mailman/listinfo/tutor :-----BEGIN PGP SIGNATURE----- :Version: GnuPG v1.0.1 (GNU/Linux) :Comment: For info see http://www.gnupg.org : :iD8DBQE6q1F7nu53feEYxlERAi92AJ91XvronniACBLun3RV6qk1o8ZWRwCeIYLh :HBeJK+Dij7o2EgebFzmTLLQ= :=RwCY :-----END PGP SIGNATURE----- : :_______________________________________________ :Tutor maillist - Tutor@python.org :http://mail.python.org/mailman/listinfo/tutor From deirdre@deirdre.net Sun Mar 11 22:19:32 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 11 Mar 2001 14:19:32 -0800 (PST) Subject: [Tutor] Python Daemon In-Reply-To: <4D298960E1C@kserver.org> Message-ID: <Pine.LNX.4.31.0103111414230.961-100000@emperor.deirdre.org> On Sun, 11 Mar 2001, Sheila King wrote: > os.fork() is not available on Windows machines. That's because they don't fork. > Is there an alternate way to handle this for Windows machines? Or, is > it impossible to write daemons for Windows machines? I'm sure there's some analogous process on Windows; I'm not a Windows programmer. I know there are functions like os.fork() for MacOS, but don't know if it's implemented on the MacOS version of Python. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From tescoil@irtc.net Sun Mar 11 21:57:51 2001 From: tescoil@irtc.net (Tesla Coil) Date: Sun, 11 Mar 2001 16:57:51 -0500 Subject: [Tutor] Python Daemon References: <Pine.LNX.4.31.0103111414230.961-100000@emperor.deirdre.org> Message-ID: <3AABF4DF.68655023@irtc.net> On 11 Mar 2001, Deirdre Saoirse replied to Sheila King >> os.fork() is not available on Windows machines. > > That's because they don't fork. > >> Is there an alternate way to handle this for Windows >> machines? Or, is it impossible to write daemons for >> Windows machines? > > I'm sure there's some analogous process on Windows; > I'm not a Windows programmer. os.spawnv? Not a Windows programmer either... From kalle@gnupung.net Sun Mar 11 23:13:27 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 00:13:27 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <01031111203600.00530@tajo>; from pdiaz88@terra.es on Sun, Mar 11, 2001 at 11:20:36AM +0100 References: <20010311151555.A18663@pino.selwerd.nl> <01031108460408.11686@shecom> <01031111203600.00530@tajo> Message-ID: <20010312001327.A617@apone.network.loc> Sez Pedro Diaz Jimenez: > In order to make a daemon, you've got to fork() and kill the father. Then > you have a child in the background That's not true, at least not with my definition of daemon, basically a process that is left running. Just start the process in the background (with an &, like "python script.py &") and exit the shell. Perhaps with older shells you'll have to run it through nohup or something, but I don't know. <offtopic> Or put it in you system startup scripts, for example /etc/rc.d/rc.local on Red Hat 6.2 and the like. On debian, you'd make a script in /etc/init.d/ and link it in /etc/rcN.d/ where N is between 2 and 5. This will work nicely on Red Hat too, except it's /etc/rc.d/{init.d,rcN.d} on older versions than 7.0. If you have more questions about GNU/Linux startup scripts, you can of course send them to me privately or to your local LUG mailing list, but I guess it's a bit offtopic for tutor... </offtopic> Anyway, my point is that fork()ing should not be necessary. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From deirdre@deirdre.net Sun Mar 11 23:16:35 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 11 Mar 2001 15:16:35 -0800 (PST) Subject: [Tutor] Python Daemon In-Reply-To: <20010312001327.A617@apone.network.loc> Message-ID: <Pine.LNX.4.31.0103111514150.961-100000@emperor.deirdre.org> On Mon, 12 Mar 2001, Kalle Svensson wrote: > Sez Pedro Diaz Jimenez: > > In order to make a daemon, you've got to fork() and kill the father. Then > > you have a child in the background > > That's not true, at least not with my definition of daemon, basically > a process that is left running. Just start the process in the > background (with an &, like "python script.py &") and exit the shell. > Perhaps with older shells you'll have to run it through nohup or > something, but I don't know. That doesn't *necessarily* work -- try logging out from that shell afterwards. In many cases, it'll be gone. Screen is a workaround, but not suitable for a daemon. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Sun Mar 11 11:50:10 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sun, 11 Mar 2001 12:50:10 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <20010312001327.A617@apone.network.loc> References: <20010311151555.A18663@pino.selwerd.nl> <01031111203600.00530@tajo> <20010312001327.A617@apone.network.loc> Message-ID: <01031112501002.00530@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Kalle, Well, actually is true ;D. Ok, you can make a proccess go to background with the & operator of the shell. But that is considered crappy. If you want your program go to background without any external intervention, you have to fork and kill the father. When you kill the father, the orphan child is adopted by init and thus, run into background (thats because that child proccess is not grandchild of the shell anymore). This is how the almost all unix daemon work. I'm sure. Confirm this running, for example, lpd as root. You don't have to put & or do something special. lpd just go to background by itself Cheers, Pedro On Monday 12 March 2001 00:13, Kalle Svensson wrote: > Sez Pedro Diaz Jimenez: > > In order to make a daemon, you've got to fork() and kill the father. Then > > you have a child in the background > > That's not true, at least not with my definition of daemon, basically a > process that is left running. Just start the process in the background > (with an &, like "python script.py &") and exit the shell. > Perhaps with older shells you'll have to run it through nohup or something, > but I don't know. > > <offtopic> > Or put it in you system startup scripts, for example /etc/rc.d/rc.local on > Red Hat 6.2 and the like. On debian, you'd make a script in /etc/init.d/ > and link it in /etc/rcN.d/ where N is between 2 and 5. This will work > nicely on Red Hat too, except it's /etc/rc.d/{init.d,rcN.d} on older > versions than 7.0. If you have more questions about GNU/Linux startup > scripts, you can of course send them to me privately or to your local LUG > mailing list, but I guess it's a bit offtopic for tutor... > </offtopic> > > Anyway, my point is that fork()ing should not be necessary. > > Peace, > Kalle -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6q2Zynu53feEYxlERAjgMAJ4i0WkRZwb0pzgsxv8WVU1I/c91iQCfYfkD JEb46aUr/BUKq8JGbwF2V5o= =VJI4 -----END PGP SIGNATURE----- From scarblac@pino.selwerd.nl Sun Mar 11 23:26:30 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 12 Mar 2001 00:26:30 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <01031111203600.00530@tajo>; from pdiaz88@terra.es on Sun, Mar 11, 2001 at 11:20:36AM +0100 References: <20010311151555.A18663@pino.selwerd.nl> <01031108460408.11686@shecom> <01031111203600.00530@tajo> Message-ID: <20010312002630.A19628@pino.selwerd.nl> On Sun, Mar 11, 2001 at 11:20:36AM +0100, Pedro Diaz Jimenez wrote: > In order to make a daemon, you've got to fork() and kill the father. Then > you have a child in the background Then, to make it a well-behaved daemon, you make it chdir() to /, and set its stdin, stdout and stderr to /dev/null. Without that, I wouldn't call it a daemon. What is the daemon supposed to do, btw? :) -- Remco Gerlich From kalle@gnupung.net Sun Mar 11 23:51:12 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 00:51:12 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <01031112501002.00530@tajo>; from pdiaz88@terra.es on Sun, Mar 11, 2001 at 12:50:10PM +0100 References: <20010311151555.A18663@pino.selwerd.nl> <01031111203600.00530@tajo> <20010312001327.A617@apone.network.loc> <01031112501002.00530@tajo> Message-ID: <20010312005112.B617@apone.network.loc> Sez Pedro Diaz Jimenez: > Ok, you can make a proccess go to background with the & operator of the > shell. But that is considered crappy. So sue me for being crappy! <wink> My point is that it isn't necessary to start fork()ing and kill()ing just because you want a daemon. Surely, that's the way to go when your application is becoming more mature, but I feel that it's an unnecessary burden in early development phases... That's my opinion, you may have yours. > If you want your program go to background without any external > intervention, you have to fork and kill the father. I believe this is true, and I don't dispute it. My beef basically is that you're making daemon writing more difficult than it can be. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From kalle@gnupung.net Sun Mar 11 23:53:37 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 00:53:37 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <Pine.LNX.4.31.0103111514150.961-100000@emperor.deirdre.org>; from deirdre@deirdre.net on Sun, Mar 11, 2001 at 03:16:35PM -0800 References: <20010312001327.A617@apone.network.loc> <Pine.LNX.4.31.0103111514150.961-100000@emperor.deirdre.org> Message-ID: <20010312005337.C617@apone.network.loc> Sez Deirdre Saoirse: > On Mon, 12 Mar 2001, Kalle Svensson wrote: > > > Sez Pedro Diaz Jimenez: > > > In order to make a daemon, you've got to fork() and kill the father. Then > > > you have a child in the background > > > > That's not true, at least not with my definition of daemon, basically > > a process that is left running. Just start the process in the > > background (with an &, like "python script.py &") and exit the shell. > > Perhaps with older shells you'll have to run it through nohup or > > something, but I don't know. > > That doesn't *necessarily* work -- try logging out from that shell > afterwards. In many cases, it'll be gone. Screen is a workaround, but not > suitable for a daemon. Perhaps. I thought nohup would work when the shell doesn't help you, but I've never been unfortunate enough to have to try it. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From bobhicks@adelphia.net Sun Mar 11 23:55:02 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Sun, 11 Mar 2001 18:55:02 -0500 Subject: [Tutor] GUI Apps In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5F5@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <B6D17A86.22A4%bobhicks@adelphia.net> I just checked the wxPython side of the house and nada. wxWindows IS on the Mac though. I have not heard of wxPython going that way yet. > From: alan.gauld@bt.com > Date: Mon, 5 Mar 2001 11:29:59 -0000 > To: bobhicks@adelphia.net, tutor@python.org > Subject: RE: [Tutor] GUI Apps > >> wxPython is on the Mac? > > Well wxWindows claims to be. I'm assuming the Python > port is too. But I'm a Tk user. > > Alan g. > > PS. In my previous post I said I was familiar with > Tk on Tcl and Tk, I meant of course on Tcl and Perl... > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From tim@johnsons-web.com Mon Mar 12 00:12:48 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Mar 2001 15:12:48 -0900 Subject: [Tutor] Python Daemon References: <Pine.LNX.4.31.0103111514150.961-100000@emperor.deirdre.org> Message-ID: <0103111518090F.11686@shecom> I'll add to what Dierdre said: The ampersand (I believe) will only run the process in the background of the terminal that is open. However, if I run fetchmail with a -d switch, then it will still run regardless if I have any console windows open from X. So indeed, the second example is what I'm looking for....... On Sun, 11 Mar 2001, Deirdre Saoirse wrote: > On Mon, 12 Mar 2001, Kalle Svensson wrote: > > > Sez Pedro Diaz Jimenez: > > > In order to make a daemon, you've got to fork() and kill the father. Then > > > you have a child in the background > > > > That's not true, at least not with my definition of daemon, basically > > a process that is left running. Just start the process in the > > background (with an &, like "python script.py &") and exit the shell. > > Perhaps with older shells you'll have to run it through nohup or > > something, but I don't know. > > That doesn't *necessarily* work -- try logging out from that shell > afterwards. In many cases, it'll be gone. Screen is a workaround, but not > suitable for a daemon. > > -- > _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Mon Mar 12 00:19:07 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Mar 2001 15:19:07 -0900 Subject: [Tutor] Python Daemon(Service) References: <4D298960E1C@kserver.org> Message-ID: <0103111526150G.11686@shecom> Hi Sheila: On Sun, 11 Mar 2001, Sheila King wrote: > os.fork() is not available on Windows machines. > > Is there an alternate way to handle this for Windows machines? Or, is it > impossible to write daemons for Windows machines? I've been moving away from windows programming, but I think the key word is Service: For this to happen on windows, the application (or python script) would be installed as a Service. I've got Mark Hammond's Book here. (Python on Win32s). I will look through that later on today and let you know what I find. Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From sheila@thinkspot.net Mon Mar 12 00:27:30 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 11 Mar 2001 16:27:30 -0800 Subject: [Tutor] Python Daemon(Service) In-Reply-To: <0103111526150G.11686@shecom> References: <4D298960E1C@kserver.org> <0103111526150G.11686@shecom> Message-ID: <55667143B7B@kserver.org> On Sun, 11 Mar 2001 15:19:07 -0900, Tim Johnson <tim@johnsons-web.com> wrote about Re: [Tutor] Python Daemon(Service): :I've been moving away from windows programming, but I think the key word :is :Service: :For this to happen on windows, the application (or python script) would :be installed as a Service. When you say "service", you're talking about WinNT or Win2000. I don't think that would apply to Win98 (like I run). :I've got Mark Hammond's Book here. :(Python on Win32s). :I will look through that later on today and let you know what I find. Please don't go to too much trouble on my account. I am mildly curious, but it isn't anything I will be doing in the near future (read: before June at the earliest). I am mildly surprised at the very Unix-centric trend that recent responses have taken. Eventually I think I will get a new computer (within the next year or so), and when I do, I think I will put a dual boot option on it, and have a Linux drive. But for now, I am without. (I am only mildly acquainted with Unix: took one university programming course in C++ on Unix systems...and host my website off of a Linux server.) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From arcege@shore.net Mon Mar 12 00:39:55 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 11 Mar 2001 19:39:55 -0500 (EST) Subject: [Tutor] Python Daemon In-Reply-To: <01031108460408.11686@shecom> from Tim Johnson at "Mar 11, 2001 8:40:56 am" Message-ID: <E14cGNP-0005MQ-00@nautilus.shore.net> > Hello: > I'd like to write a test python script as a daemon. > (Red Hat 6.0) > If the topic is a little involved, (and I'm sure it is), > I'd be perfectly happy if someone could just point > me to some documentation to get me started. > TIA > Regards > -- > Tim Johnson You'll have to say which platform you are working with. On WinNT, they are called "services" (as in IIS, Internet Information Service). The "Python Programming on Win32" book covers this pretty well, but I'm no windoze programmer. Since you're calling this a "daemon", I asusme you are asking for UNIX. On UNIX, a daemon is a process without an associated terminal or login shell. Backgrounding a process from a shell is not enough, it must disassociate itself from the controlling terminal as well (and not be affected by the user shell). Run the os.setpgrp() function, and close stdin, stdout and stderr. Some example code is (based on Steven's "daemon_start()" function): import os, signal, sys def make_daemon(): if os.getppid() != 1: # we're already a daemon (started from init) if hasattr(signal, 'SIGTTOU'): signal.signal(signal.SIGTTOU, signal.SIG_IGN) if hasattr(signal, 'SIGTTIN'): signal.signal(signal.SIGTTIN, signal.SIG_IGN) if hasattr(signal, 'SIGTSTP'): signal.signal(signal.SIGTSTP, signal.SIG_IGN) pid = os.fork() if pid: sys.exit(0) os.setpgrp() signal.signal(signal.SIGHUP, signal.SIG_IGN) sys.stdin.close() sys.stdout.close() sys.stderr.close() os.chdir(os.sep) os.umask(0) signal.signal(signal.SIGCLD, signal.SIG_IGN) if __name__ == '__main__': make_daemon() Good luck, -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From tim@johnsons-web.com Mon Mar 12 00:50:00 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Mar 2001 15:50:00 -0900 Subject: [Tutor] Python Daemon References: <20010312005337.C617@apone.network.loc> Message-ID: <0103111600250H.11686@shecom> Hi Thanks to Pedro..... I used his coding suggestion as per below: #!/usr/bin/python import os import sys import time PID = os.fork() if PID != 0: print "shutting down parent process:",PID sys.exit() else: #print "Child still here" time.sleep(20) #print "Child exiting" sys.exit() ##################################### Now when I run this from a gnome-terminal window, it operates *as -advertised* if I type ps from that window, during the time that it remains installed, I see something like this: [tim@shecom sem2]$ python daemontest.py shutting down parent process: 12234 [tim@shecom sem2]$ ps PID TTY TIME CMD 11995 pts/2 00:00:00 bash 12234 pts/2 00:00:00 python # yo!! There it is 12235 pts/2 00:00:00 ps # if at the same time, I go to another terminal and query processes # this is what I see: [tim@shecom tim]$ ps PID TTY TIME CMD 12228 pts/1 00:00:00 bash 12236 pts/1 00:00:00 ps # Now, my questions are : Did I really create a daemon or did I just create a background process? If I did create the daemon, how do I verify that? Thanks Not only am I just getting the hang of Python, I new to Linux as well. :>) Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From kalle@gnupung.net Mon Mar 12 01:19:10 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 02:19:10 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <0103111518090F.11686@shecom>; from tim@johnsons-web.com on Sun, Mar 11, 2001 at 03:12:48PM -0900 References: <Pine.LNX.4.31.0103111514150.961-100000@emperor.deirdre.org> <0103111518090F.11686@shecom> Message-ID: <20010312021909.D617@apone.network.loc> Sez Tim Johnson: > I'll add to what Dierdre said: > The ampersand (I believe) will > only run the process in the background of the > terminal that is open. Trust me, for I have tested: It may Depend, but in my environment I have no problem keeping it alive. On another system, with another shell, you may well be right. YMMV. Using bash 2.04.0(1)-release on Debian GNU/Linux unstable: Run your script in one shell (an xterm, for example), put it in the background. Start another shell, run "ps ax" to find the process. Log out of the first shell. Run "ps ax" again. All your daemons are belong to us, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From kalle@gnupung.net Mon Mar 12 01:26:30 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 02:26:30 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <0103111600250H.11686@shecom>; from tim@johnsons-web.com on Sun, Mar 11, 2001 at 03:50:00PM -0900 References: <20010312005337.C617@apone.network.loc> <0103111600250H.11686@shecom> Message-ID: <20010312022629.E617@apone.network.loc> Sez Tim Johnson: [snip] > [tim@shecom sem2]$ python daemontest.py > shutting down parent process: 12234 > [tim@shecom sem2]$ ps > PID TTY TIME CMD > 11995 pts/2 00:00:00 bash > 12234 pts/2 00:00:00 python # yo!! There it is > 12235 pts/2 00:00:00 ps > # if at the same time, I go to another terminal and query processes > # this is what I see: > [tim@shecom tim]$ ps > PID TTY TIME CMD > 12228 pts/1 00:00:00 bash > 12236 pts/1 00:00:00 ps > # Now, my questions are : > Did I really create a daemon or did I just create a background process? > If I did create the daemon, how do I verify that? You'll have to use "ps ax" to see all processes. "man ps" is your friend. Use grep to filter them: "ps ax | grep python | grep -v grep". Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From wesc@deirdre.org Mon Mar 12 01:57:53 2001 From: wesc@deirdre.org (Wesley J. Chun) Date: Sun, 11 Mar 2001 17:57:53 -0800 Subject: [Tutor] Object comparison vs. Identity Message-ID: <200103120157.RAA03152@emperor.deirdre.org> > From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu> > Date: Sat, 10 Mar 2001 22:36:52 -0800 (PST) > > On Sat, 10 Mar 2001, Sheila King wrote: > > > On pp. 84 - 85 he is discussing object identity, and > > presents the following example: > > foo1 = 4 > > foo2 = 3 + 1 > > He says that the first statement creates a numeric object and assigns it to > > foo1. The second statement creates a numeric object, and assigns it to foo2. > > Although the value of the two objects are the same, he claims that they are > > two distinct objects. > > True; however, the reason that this doesn't work for small numbers is > because the integers are precached --- Python keeps instances of the > integers from -1 to 100 to reduce the cost of using these popular numbers. > We can empirically see this with a small experiment: > : first, i'd like to thank Danny publically for covering for me in this particular example. Python does cache what it perceives as "high-use" integers (as well as some strings). my example can also be reworked by using floating point values: >>> foo1 = 4.0 >>> foo2 = 3.0 + 1.0 >>> foo1 4.0 >>> foo2 4.0 >>> id(foo1) 906864 >>> id(foo2) 906816 i will make sure this boo-boo is annoted in the errata as well as evicted in the next edition. thanks, and sorry sheila for the confusion! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Silicon Valley-SF Bay Area Python users group: http://www.baypiggies.org "Core Python Programming", Prentice Hall PTR, TBP Fall 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html wesley.j.chun :: wesc@baypiggies.org or cyberweb_consulting@yahoo.com cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From senum@singnet.com.sg Mon Mar 12 02:32:11 2001 From: senum@singnet.com.sg (senum@singnet.com.sg) Date: Mon, 12 Mar 2001 10:32:11 +0800 Subject: [Tutor] Thanks ppl...i appreciated it ;) Message-ID: <3AACA5AB.7190.40485DD@localhost> Thanks to all who replied.I'm checking out the links and hope to be writing useful Python code soon ;) Be prepared to see my barrage of questions rolling in soon lol Thanks once again. Sincerely, Kenny. p.s.Dan: thanks for the link..i'll keep u inform if i find any good ones. From deirdre@deirdre.net Mon Mar 12 03:34:13 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 11 Mar 2001 19:34:13 -0800 (PST) Subject: [Tutor] Python Daemon(Service) In-Reply-To: <55667143B7B@kserver.org> Message-ID: <Pine.LNX.4.31.0103111927490.961-100000@emperor.deirdre.org> On Sun, 11 Mar 2001, Sheila King wrote: > I am mildly surprised at the very Unix-centric trend that recent > responses have taken. Eventually I think I will get a new computer > (within the next year or so), and when I do, I think I will put a dual > boot option on it, and have a Linux drive. But for now, I am without. > (I am only mildly acquainted with Unix: took one university > programming course in C++ on Unix systems...and host my website off of > a Linux server.) For a lot of us, we're hard-core Unix people. The reason I never answer Windows questions is pretty simple: I've never been a Windows user. Never owned a Windows machine. Right now, I run Python on Linux, Solaris and MacOS. I would welcome someone who was very familiar about Python on Windows and wanted the commitment to become one of the official "Tutors" (Wesley Chun and I are the list owners). The number of Windows users asking Windows-specific questions on the list has been rising. While I'm not a fan of Windows, I consider this a Good Thing and just part of the wider adoption of Python. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From sarnold@earthling.net Mon Mar 12 04:14:12 2001 From: sarnold@earthling.net (Stephen L Arnold) Date: Sun, 11 Mar 2001 20:14:12 -0800 Subject: [Tutor] Python Daemon(Service) In-Reply-To: <Pine.LNX.4.31.0103111927490.961-100000@emperor.deirdre.org> References: <55667143B7B@kserver.org> Message-ID: <20010312041413.413651F661@shiva.arnolds.bogus> On 11 Mar 01, at 19:34, Deirdre Saoirse wrote: > On Sun, 11 Mar 2001, Sheila King wrote: > > > I am mildly surprised at the very Unix-centric trend that recent > > responses have taken. Eventually I think I will get a new computer > > (within the next year or so), and when I do, I think I will put a dual > > boot option on it, and have a Linux drive. But for now, I am without. (I > > am only mildly acquainted with Unix: took one university programming > > course in C++ on Unix systems...and host my website off of a Linux > > server.) Until you get the dual-boot setup, you can always try Cygwin. It gives you many Linux/unix type tools (bash, make, gcc, perl, python, etc) on win32 and a way to build apps for various platforms. You could also run Linux on surplus hardware; I have two servers here that are old pentiums built from surplus parts (and they perform surprisingly well). > For a lot of us, we're hard-core Unix people. The reason I never answer > Windows questions is pretty simple: I've never been a Windows user. Never > owned a Windows machine. Right now, I run Python on Linux, Solaris and > MacOS. I guess I'm trying to use less windoze and more Linux. Right now I kind of straddle the fence (but I have very little NT or 2K experience yet). I'll try to help with windows stuff where I can, as I learn python. Steve ************************************************************* Steve Arnold sarnold@arnolds.dhs.org Assoc. Faculty, Dept of Geography, Allan Hancock College http://arnolds.dhs.org/geography.html Linux: It's not just for nerds anymore... From tim@johnsons-web.com Mon Mar 12 05:08:46 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Mar 2001 20:08:46 -0900 Subject: [Tutor] Python Daemon(Service) References: <Pine.LNX.4.31.0103111927490.961-100000@emperor.deirdre.org> Message-ID: <0103112020030K.11686@shecom> Hi: On Sun, 11 Mar 2001, Deirdre Saoirse wrote: <snip> > I would welcome someone who was very familiar about Python on Windows and > wanted the commitment to become one of the official "Tutors" (Wesley Chun > and I are the list owners). Aha!! Now I know who to personally thank ..... This is a great list. Thank You!! Dierdre > The number of Windows users asking Windows-specific questions on the list > has been rising. While I'm not a fan of Windows, I consider this a Good > Thing and just part of the wider adoption of Python. And hopefully they will continue to rise..... python offers options to the more expensive (and sometimes very manipulative) vendors.... I don't have any windows-specific projects coming up, but when I do see them, I know Python is going to play a big role. From what I have seen of Mark Hammond's work (Python on Win32s), he has gotten a lot of exposure to the windows api there for the taking. Dieirdre, perhaps there is someone with the ActivePython group or the Starship group that could get involved? Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From deirdre@deirdre.net Mon Mar 12 05:22:04 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 11 Mar 2001 21:22:04 -0800 (PST) Subject: [Tutor] Python Daemon(Service) In-Reply-To: <0103112020030K.11686@shecom> Message-ID: <Pine.LNX.4.31.0103112117440.961-100000@emperor.deirdre.org> On Sun, 11 Mar 2001, Tim Johnson wrote: > Aha!! Now I know who to personally thank ..... This is a great list. > Thank You!! Dierdre In fairness, I didn't start the list, Wes and I took it over when David Ascher (of "Learning Python" fame) wanted to retire. :) > > The number of Windows users asking Windows-specific questions on the list > > has been rising. While I'm not a fan of Windows, I consider this a Good > > Thing and just part of the wider adoption of Python. > And hopefully they will continue to rise..... python offers options to > the more expensive (and sometimes very manipulative) vendors.... It wasn't until I became a sysadmin that I respected the power that programmers have and often aren't aware of. Knowing that you can write something that can control a computer's actions is very powerful and I wholly support Guido's "Computer Programming For Everyone" concept. > I don't have any windows-specific projects coming up, but when I do > see them, I know Python is going to play a big role. From what I have > seen of Mark Hammond's work (Python on Win32s), he has gotten a lot of > exposure to the windows api there for the taking. It does seem like a really good book, but I don't have the basis to judge it. > perhaps there is someone with the ActivePython group or the Starship > group that could get involved? Tutor admins tend to come from long-standing posters to the tutor list as they're self-selected. I'll ask though. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From scarblac@pino.selwerd.nl Mon Mar 12 08:32:08 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 12 Mar 2001 09:32:08 +0100 Subject: [Tutor] Python Daemon(Service) In-Reply-To: <55667143B7B@kserver.org>; from sheila@thinkspot.net on Sun, Mar 11, 2001 at 04:27:30PM -0800 References: <4D298960E1C@kserver.org> <0103111526150G.11686@shecom> <55667143B7B@kserver.org> Message-ID: <20010312093208.A20308@pino.selwerd.nl> On Sun, Mar 11, 2001 at 04:27:30PM -0800, Sheila King wrote: > I am mildly surprised at the very Unix-centric trend that recent responses > have taken. I think that's because "daemon" is a Unix term. It has a pretty precise meaning there (see man daemon on a linux system, for instance), but I've never heard the term used for a Windows program... -- Remco Gerlich From wheelege@tsn.cc Mon Mar 12 08:52:18 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 12 Mar 2001 19:52:18 +1100 Subject: [Tutor] Python Daemon(Service) References: <4D298960E1C@kserver.org> <0103111526150G.11686@shecom> <55667143B7B@kserver.org> <20010312093208.A20308@pino.selwerd.nl> Message-ID: <016601c0aad1$bef83c00$0200a8c0@ACE> ----- Original Message ----- From: Remco Gerlich <scarblac@pino.selwerd.nl> To: <tutor@python.org> Sent: Monday, March 12, 2001 7:32 PM Subject: Re: [Tutor] Python Daemon(Service) > On Sun, Mar 11, 2001 at 04:27:30PM -0800, Sheila King wrote: > > I am mildly surprised at the very Unix-centric trend that recent responses > > have taken. > > I think that's because "daemon" is a Unix term. It has a pretty precise > meaning there (see man daemon on a linux system, for instance), but I've > never heard the term used for a Windows program... > Whenever I hear daemon I always think of the Doom and DoomII startup screens... hey they are sorta windows applications :) Damn I'm off-topic today... > -- > Remco Gerlich > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Mon Mar 12 10:24:00 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Mar 2001 10:24:00 -0000 Subject: [Tutor] Hi all. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D61D@mbtlipnt02.btlabs.bt.co.uk> > I'm keen on taking up Python..the only language I had experience > is C.I tried reading the official docs and tutorial at python.org but > found them to be a bit dry. They are a bit dry but do get thru all the important stuff pretty quickly. You can literally sit down at the start of the day and be finished by the end of the day knowing all you need to write pretty advanced Python programs. If you have specific interests try the various howto docs too, they tend be lighter reading. > seems a bit too well,for the really new non programmer. Yes, most of us feel the official tutor covers the programming community pretty well. Other useful sources invclude the various publishers home pages for sample chapters: www.manning.com have chapters from Quick Python www.ora.com have some bits from Learning Python and Programming Python There are a few articles around on DDJ and inforIT too. Alan G From britt_green@hotmail.com Mon Mar 12 11:23:44 2001 From: britt_green@hotmail.com (Britt Green) Date: Mon, 12 Mar 2001 03:23:44 -0800 Subject: [Tutor] Re: Tutor digest, Vol 1 #652 - 15 msgs Message-ID: <F119tgXajWka1cK4hys00017ff9@hotmail.com> > > On Sun, Mar 11, 2001 at 04:27:30PM -0800, Sheila King wrote: > > > I am mildly surprised at the very Unix-centric trend that recent >responses > > > have taken. > > > > I think that's because "daemon" is a Unix term. It has a pretty precise > > meaning there (see man daemon on a linux system, for instance), but I've > > never heard the term used for a Windows program... > > I think under Windows (at least NT anyways) they're called "services". But they seem to be the same thing. Just my two cents, but I use both Windows and the Macintosh, but for coding, I've recently come to enjoy Linux. To me I feel much closer to the OS than I do with a GUI-based OS. Not to mention free coding utilities! :) As a horrible off-topic aside, someoen mentioned that when they hear of daemons, they think of Doom. I would invite that person to look at this link: http://www.cs.unm.edu/~dlchao/flake/doom/ and see how someone combined both Doom and daemons! :) Now back to your regularly scheduled Python messages. Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From pdiaz88@terra.es Mon Mar 12 00:23:17 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 12 Mar 2001 01:23:17 +0100 Subject: [Tutor] Python Daemon(Service) In-Reply-To: <55667143B7B@kserver.org> References: <4D298960E1C@kserver.org> <0103111526150G.11686@shecom> <55667143B7B@kserver.org> Message-ID: <01031201231700.02065@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 12 March 2001 01:27, Sheila King wrote: > On Sun, 11 Mar 2001 15:19:07 -0900, Tim Johnson <tim@johnsons-web.com> > wrote > > about Re: [Tutor] Python Daemon(Service): > :I've been moving away from windows programming, but I think the key word > :is > :Service: > :For this to happen on windows, the application (or python script) would > :be installed as a Service. > > When you say "service", you're talking about WinNT or Win2000. I don't > think that would apply to Win98 (like I run). > > :I've got Mark Hammond's Book here. > :(Python on Win32s). > :I will look through that later on today and let you know what I find. > > Please don't go to too much trouble on my account. I am mildly curious, but > it isn't anything I will be doing in the near future (read: before June at > the earliest). > > I am mildly surprised at the very Unix-centric trend that recent responses > have taken. Eventually I think I will get a new computer (within the next > year or so), and when I do, I think I will put a dual boot option on it, > and have a Linux drive. But for now, I am without. (I am only mildly > acquainted with Unix: took one university programming course in C++ on Unix > systems...and host my website off of a Linux server.) > Hi, Well, I as an scripting language, python is used a lot in servers (that's why I learned python). And the vast majority of the inet servers run unix. Anyway, I recomend you to explore a little bit the unix world. Although it may seem a little cryptic when you start, in a couple of months you will love it or hate it ;D I personaly love unix Pedro > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6rBcJnu53feEYxlERAmsPAKCl6KJIMb090yiaHn+f8Y0urwXFHwCg7Oj1 1fkK4qdwskJAUZR4jSAevqI= =gXdb -----END PGP SIGNATURE----- From pdiaz88@terra.es Mon Mar 12 00:34:32 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 12 Mar 2001 01:34:32 +0100 Subject: [Tutor] Python Daemon In-Reply-To: <0103111600250H.11686@shecom> References: <20010312005337.C617@apone.network.loc> <0103111600250H.11686@shecom> Message-ID: <01031201343201.02065@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Well, the distinction between daemon and background proccess is conceptual. A daemon, per definition, is a background proccess. But a background proccess doesn't have to be a daemon. Tipically a daemon will provide some service, eg: telnet daemon (remote logins), ftp daemon (file transfer service), etc.. On the other hand, Remco Gerlich proposed some steps that a well designed daemon will do. I agree with Remco, and I would also propose to setuid () the daemon to nobody/nogroup for security reasons if you can Cheers Pedro On Monday 12 March 2001 01:50, Tim Johnson wrote: > Hi Thanks to Pedro..... > I used his coding suggestion as per below: > #!/usr/bin/python > import os > import sys > import time > PID = os.fork() > if PID != 0: > print "shutting down parent process:",PID > sys.exit() > else: > #print "Child still here" > time.sleep(20) > #print "Child exiting" > sys.exit() > ##################################### > Now when I run this from a gnome-terminal window, > it operates *as -advertised* > if I type ps from that window, during the time that it remains installed, > I see something like this: > [tim@shecom sem2]$ python daemontest.py > shutting down parent process: 12234 > [tim@shecom sem2]$ ps > PID TTY TIME CMD > 11995 pts/2 00:00:00 bash > 12234 pts/2 00:00:00 python # yo!! There it is > 12235 pts/2 00:00:00 ps > # if at the same time, I go to another terminal and query processes > # this is what I see: > [tim@shecom tim]$ ps > PID TTY TIME CMD > 12228 pts/1 00:00:00 bash > 12236 pts/1 00:00:00 ps > # Now, my questions are : > Did I really create a daemon or did I just create a background process? > If I did create the daemon, how do I verify that? > Thanks > Not only am I just getting the hang of Python, I new to Linux as well. > > :>) > > Regards > -- > Tim Johnson > ----------- > "Of all manifestations of power, > restraint impresses the most." > -Thucydides > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6rBmYnu53feEYxlERAhjPAJ93Ssk2KmE3hqxU9Hc926bseanAYACfcNeC m/6u9VofcPPyUPgBMMRzzbY= =WB/f -----END PGP SIGNATURE----- From senum@singnet.com.sg Mon Mar 12 13:53:12 2001 From: senum@singnet.com.sg (senum@singnet.com.sg) Date: Mon, 12 Mar 2001 21:53:12 +0800 Subject: [Tutor] Hm..i found a better alternative ;P Message-ID: <3AAD4548.16326.11C4690@localhost> Well all these URLs are really useful[valuable resources in fact] ;) I'm sure they'll come of use soon.But then i found a better alternative to this: i went out to the store and got oreilly's learning python yayy!well..now reading my first chapter and it's great..once again thanks to all for your help..will be needing more in future tho' cheers, kenny. From dyoo@hkn.eecs.berkeley.edu Mon Mar 12 14:03:03 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 12 Mar 2001 06:03:03 -0800 (PST) Subject: [Tutor] Hm..i found a better alternative ;P In-Reply-To: <3AAD4548.16326.11C4690@localhost> Message-ID: <Pine.LNX.4.21.0103120601560.16386-100000@hkn.eecs.berkeley.edu> On Mon, 12 Mar 2001 senum@singnet.com.sg wrote: > Well all these URLs are really useful[valuable resources in fact] ;) > I'm sure they'll come of use soon.But then i found a better > alternative to this: > > i went out to the store and got oreilly's learning python > > yayy!well..now reading my first chapter and it's great..once again > thanks to all for your help..will be needing more in future tho' Learning Python is a great book; I liked it as well. Hope to hear from you soon! From paulnsharon@dingoblue.net.au Mon Mar 12 14:41:32 2001 From: paulnsharon@dingoblue.net.au (Paul Jones) Date: Tue, 13 Mar 2001 00:41:32 +1000 Subject: [Tutor] Working with strings Message-ID: <000c01c0ab02$89027da0$a6c11dcb@barney> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0AB56.59CB3280 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi- I'm going through the OBP tutorial on how to think like a scientist = by Allen B. Downey and Jeffrey Elkner (Ch7). There is a problem on doing = a program to write a function to accept a string -and output it = reversed. ie Bruce --->ecurB I'm using the IDLE interface on Win98 (I have Linux but my modem is not = working so well on it at the moment). Can you correct my program below = and give me some sample program as to how to do it simply. I'm not = having trouble with the logic of the string manipulation(I think) - just = getting the program to accept input and print output. Regards.. Paul Jones >>> def backword(bruce): bruce=3Draw_input('input a word to reverse ') index=3Dlen(bruce)-1 while index<0: letter=3Dbruce[index] print letter, index =3D index+1 =20 >>> backword <function backword at 00BC015C> >>> backword(flowerpot) Traceback (innermost last): File "<pyshell#36>", line 1, in ? backword(flowerpot) NameError: There is no variable named 'flowerpot' >>> backword('flowerpot') input a word to reverse flowerpot >>> print bruce harold # a value I entered earlier that it hasn't cleared. >>> def backword('bruce'): =20 SyntaxError: invalid syntax >>> backword(flowerpot) Traceback (innermost last): File "<pyshell#40>", line 1, in ? backword(flowerpot) NameError: There is no variable named 'flowerpot' >>>=20 email: paulnsharon@dingoblue.net.au ------=_NextPart_000_0009_01C0AB56.59CB3280 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi- I'm going through the OBP tutorial = on how to=20 think like a scientist by Allen B. Downey and Jeffrey Elkner (Ch7). = There is a=20 problem on doing a program to write a function to accept a string -and = output it=20 reversed. ie Bruce --->ecurB</FONT></DIV> <DIV><FONT face=3DArial size=3D2>I'm using the IDLE interface on Win98 = (I have Linux=20 but my modem is not working so well on it at the moment). Can you = correct my=20 program below and give me some sample program as to how to do it simply. = I'm not=20 having trouble with the logic of the string manipulation(I think) - = just=20 getting the program to accept input and print output.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Regards..</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Paul Jones</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV><FONT face=3DArial = size=3D2> <DIV><BR>>>> def = backword(bruce):<BR> bruce=3Draw_input('input a=20 word to reverse ')<BR> index=3Dlen(bruce)-1<BR> while=20 index<0:<BR> letter=3Dbruce[index]<BR> print=20 letter,<BR> index =3D index+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> <BR>>>>=20 backword<BR><function backword at 00BC015C><BR>>>>=20 backword(flowerpot)<BR>Traceback (innermost last):<BR> File=20 "<pyshell#36>", line 1, in ?<BR> =20 backword(flowerpot)<BR>NameError: There is no variable named=20 'flowerpot'<BR>>>> backword('flowerpot')<BR>input a word to=20 reverse flowerpot<BR>>>> print bruce<BR>harold # a value = I=20 entered earlier that it hasn't cleared.<BR>>>> def=20 backword('bruce'):<BR> <BR>SyntaxError: invalid = syntax<BR>>>>=20 backword(flowerpot)<BR>Traceback (innermost last):<BR> File=20 "<pyshell#40>", line 1, in ?<BR> =20 backword(flowerpot)<BR>NameError: There is no variable named=20 'flowerpot'<BR>>>> <BR>email: <A=20 href=3D"mailto:paulnsharon@dingoblue.net.au">paulnsharon@dingoblue.net.au= </A></FONT></DIV></BODY></HTML> ------=_NextPart_000_0009_01C0AB56.59CB3280-- From pdiaz88@terra.es Mon Mar 12 03:21:39 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 12 Mar 2001 04:21:39 +0100 Subject: [Tutor] Working with strings In-Reply-To: <000c01c0ab02$89027da0$a6c11dcb@barney> References: <000c01c0ab02$89027da0$a6c11dcb@barney> Message-ID: <01031204213905.02065@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 what about this? >>> def backword(s): ... index = len(s)-1 ... while index >= 0: ... print s[index], ... index = index-1 ... >>> backword("hola") a l o h >>> Does anyone know how to take portions of a list. I would like to resolve this problem this in a recursive manner, but given a="potato" I don't know how to take "potat" without writting another function (which would destroy the beauty of a well designed recursive function ). Using python 1.5.2 (yeah, its old but works great :) Cheers Pedro On Monday 12 March 2001 15:41, Paul Jones wrote: > Hi- I'm going through the OBP tutorial on how to think like a scientist by > Allen B. Downey and Jeffrey Elkner (Ch7). There is a problem on doing a > program to write a function to accept a string -and output it reversed. ie > Bruce --->ecurB I'm using the IDLE interface on Win98 (I have Linux but my > modem is not working so well on it at the moment). Can you correct my > program below and give me some sample program as to how to do it simply. > I'm not having trouble with the logic of the string manipulation(I think) - > just getting the program to accept input and print output. Regards.. > Paul Jones > Watch your indentation > >>> def backword(bruce): Whats the role of the bruce param??. I'll use either params or local vars with raw_input > > bruce=raw_input('input a word to reverse ') > index=len(bruce)-1 > while index<0: wrong^ > letter=bruce[index] > print letter, > index = index+1 wrong ^ > > >>> backword > > <function backword at 00BC015C> > > >>> backword(flowerpot) > > Traceback (innermost last): > File "<pyshell#36>", line 1, in ? > backword(flowerpot) > NameError: There is no variable named 'flowerpot' > > >>> backword('flowerpot') > > input a word to reverse flowerpot > > >>> print bruce > > harold # a value I entered earlier that it hasn't cleared. > > >>> def backword('bruce'): > > SyntaxError: invalid syntax > > >>> backword(flowerpot) > > Traceback (innermost last): > File "<pyshell#40>", line 1, in ? > backword(flowerpot) > NameError: There is no variable named 'flowerpot' > > email: paulnsharon@dingoblue.net.au - ---------------------------------------- Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1" Content-Transfer-Encoding: quoted-printable Content-Description: - ---------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.1 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6rEDDnu53feEYxlERAi64AJ4xxBoUAITH4ztgRYt8uqRrz6iV8gCgvqoq iHYK8WW12sOD01V62OzHMn0= =Umi7 -----END PGP SIGNATURE----- From kalle@gnupung.net Mon Mar 12 16:29:05 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 17:29:05 +0100 Subject: [Tutor] Working with strings In-Reply-To: <01031204213905.02065@tajo>; from pdiaz88@terra.es on Mon, Mar 12, 2001 at 04:21:39AM +0100 References: <000c01c0ab02$89027da0$a6c11dcb@barney> <01031204213905.02065@tajo> Message-ID: <20010312172905.A21488@father> Sez Pedro Diaz Jimenez: > >>> def backword(s): > ... index = len(s)-1 > ... while index >= 0: > ... print s[index], > ... index = index-1 > ... > >>> backword("hola") > a l o h > >>> > [would like a recursive version] def backword(s): if s: print s[-1], backword(s[:-1]) I might have written the iterative version like this: def backword(s): while s: print s[-1], s = s[:-1] Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From Lindsay.Davies@moonshine.co.uk Mon Mar 12 16:21:35 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Mon, 12 Mar 2001 16:21:35 +0000 Subject: [Tutor] Working with strings In-Reply-To: <000c01c0ab02$89027da0$a6c11dcb@barney> References: <000c01c0ab02$89027da0$a6c11dcb@barney> Message-ID: <p05010408b6d2a5eda3d3@[195.102.186.233]> --============_-1227708348==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Paul - Here's a working version. You'll easily be able to work out the changes... def backword(bruce): bruce=raw_input('input a word to reverse ') print bruce for index in range(0, len(bruce)): letter=bruce[index:][0] print letter, ...and here's another way to do it... ;-) bruce = raw_input('input a word to reverse ') ecurb = string.join([bruce[-x:][0] for x in range(1,len(bruce) + 1)], "") Best wishes, Lindsay On 13/3/01, Paul Jones wrote about '[Tutor] Working with strings': >Hi- I'm going through the OBP tutorial on how to think like a >scientist by Allen B. Downey and Jeffrey Elkner (Ch7). There is a >problem on doing a program to write a function to accept a string >-and output it reversed. ie Bruce --->ecurB >I'm using the IDLE interface on Win98 (I have Linux but my modem is >not working so well on it at the moment). Can you correct my program >below and give me some sample program as to how to do it simply. I'm >not having trouble with the logic of the string manipulation(I >think) - just getting the program to accept input and print output. >Regards.. >Paul Jones > > >>>> def backword(bruce): > bruce=raw_input('input a word to reverse ') > index=len(bruce)-1 > while index<0: > letter=bruce[index] > print letter, > index = index+1 > > >>>> backword ><function backword at 00BC015C> >>>> backword(flowerpot) >Traceback (innermost last): > File "<pyshell#36>", line 1, in ? > backword(flowerpot) >NameError: There is no variable named 'flowerpot' >>>> backword('flowerpot') >input a word to reverse flowerpot >>>> print bruce >harold # a value I entered earlier that it hasn't cleared. >>>> def backword('bruce'): > >SyntaxError: invalid syntax >>>> backword(flowerpot) >Traceback (innermost last): > File "<pyshell#40>", line 1, in ? > backword(flowerpot) >NameError: There is no variable named 'flowerpot' > >>> >email: <mailto:paulnsharon@dingoblue.net.au>paulnsharon@dingoblue.net.au --============_-1227708348==_ma============ Content-Type: text/html; charset="us-ascii" <!doctype html public "-//W3C//DTD W3 HTML//EN"> <html><head><style type="text/css"><!-- blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 } --></style><title>Re: [Tutor] Working with strings</title></head><body> <div>Paul -</div> <div><br></div> <div>Here's a working version. You'll easily be able to work out the changes...</div> <div><br></div> <div>def backword(bruce):</div> <div><x-tab> </x-tab><font color="#000000">bruce=raw_input(</font><font color="#007F00">'input a word to reverse '</font><font color="#000000">)</font></div> <div><font color="#000000"><b><x-tab> </x-tab>print</b> bruce<br> <b><x-tab> </x-tab>for</b> index<b> in</b> range(0, len(bruce)):<br> <x-tab> </x-tab><x-tab> </x-tab>letter=bruce[index:][0]</font></div> <div><font color="#000000"><b><x-tab> </x-tab><x-tab> </x-tab>print</b> letter,</font></div> <div><br></div> <div><br></div> <div>...and here's another way to do it... ;-)</div> <div><br></div> <div><font color="#000000">bruce =</font> raw_input('input a word to reverse ')</div> <div><font color="#000000">ecurb = string.join([bruce[-x:][0]<b> for</b> x<b> in</b> range(1,len(bruce) + 1)],</font><font color="#007F00"> ""</font><font color="#000000">)</font></div> <div><br></div> <div><br></div> <div>Best wishes,</div> <div><br></div> <div>Lindsay</div> <div><br></div> <div><br></div> <div>On 13/3/01, Paul Jones wrote about '[Tutor] Working with strings':</div> <blockquote type="cite" cite>Hi- I'm going through the OBP tutorial on how to think like a scientist by Allen B. Downey and Jeffrey Elkner (Ch7). There is a problem on doing a program to write a function to accept a string -and output it reversed. ie Bruce --->ecurB</blockquote> <blockquote type="cite" cite>I'm using the IDLE interface on Win98 (I have Linux but my modem is not working so well on it at the moment). Can you correct my program below and give me some sample program as to how to do it simply. I'm not having trouble with the logic of the string manipulation(I think) - just getting the program to accept input and print output.</blockquote> <blockquote type="cite" cite>Regards..</blockquote> <blockquote type="cite" cite>Paul Jones</blockquote> <blockquote type="cite" cite> </blockquote> <blockquote type="cite" cite><br> >>> def backword(bruce):</blockquote> <blockquote type="cite" cite> bruce=raw_input('input a word to reverse ')<br> index=len(bruce)-1<br> while index<0:<br> letter=bruce[index]<br> print letter,</blockquote> <blockquote type="cite" cite> index = index+1</blockquote> <blockquote type="cite" cite> </blockquote> <blockquote type="cite" cite> <br> >>> backword<br> <function backword at 00BC015C><br> >>> backword(flowerpot)<br> Traceback (innermost last):<br> File "<pyshell#36>", line 1, in ?<br> backword(flowerpot)<br> NameError: There is no variable named 'flowerpot'<br> >>> backword('flowerpot')<br> input a word to reverse flowerpot<br> >>> print bruce<br> harold # a value I entered earlier that it hasn't cleared.<br> >>> def backword('bruce'):<br> <br> SyntaxError: invalid syntax<br> >>> backword(flowerpot)<br> Traceback (innermost last):<br> File "<pyshell#40>", line 1, in ?<br> backword(flowerpot)<br> NameError: There is no variable named 'flowerpot'</blockquote> <blockquote type="cite" cite>>>></blockquote> <blockquote type="cite" cite>email: <a href="mailto:paulnsharon@dingoblue.net.au" >paulnsharon@dingoblue.net.au</a></blockquote> <div><br></div> </body> </html> --============_-1227708348==_ma============-- From tescoil@irtc.net Mon Mar 12 15:32:47 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 10:32:47 -0500 Subject: [Tutor] Working with strings References: <000c01c0ab02$89027da0$a6c11dcb@barney> <01031204213905.02065@tajo> Message-ID: <3AACEC1F.EFAB1DC8@irtc.net> 12 Mar 2001 Pedro Diaz Jimenez replied to Paul Jones: > what about this? > >>>> def backword(s): >... index = len(s)-1 >... while index >= 0: >... print s[index], >... index = index-1 >... >>>> backword("hola") >a l o h or this? >>> def backword(gnirts): ... hctac = '' ... for xedni in range(len(gnirts)-1, -1, -1): ... hctac = hctac+gnirts[xedni] ... print hctac >>> want = 'proper spaces' >>> backwords(want) secaps reporp From arcege@shore.net Mon Mar 12 16:42:40 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 12 Mar 2001 11:42:40 -0500 (EST) Subject: [Tutor] Working with strings In-Reply-To: <000c01c0ab02$89027da0$a6c11dcb@barney> from Paul Jones at "Mar 13, 2001 0:41:32 am" Message-ID: <E14cVP6-0006Pp-00@nautilus.shore.net> [Charset iso-8859-1 unsupported, filtering to ASCII...] > Hi- I'm going through the OBP tutorial on how to think like a scientist by Allen B. Downey and Jeffrey Elkner (Ch7). There is a problem on doing a program to write a function to accept a string -and output it reversed. ie Bruce --->ecurB > I'm using the IDLE interface on Win98 (I have Linux but my modem is not working so well on it at the moment). Can you correct my program below and give me some sample program as to how to do it simply. I'm not having trouble with the logic of the string manipulation(I think) - just getting the program to accept input and print output. > Regards.. > Paul Jones If you don't care about the algorihm, then you can utilize Python apropriately. >>> import string >>> a = 'spam, spam, eggs and spam' >>> l = list(a) >>> l ['s', 'p', 'a', 'm', ',', ' ', 's', 'p', 'a', 'm', ',', ' ', 'e', 'g', 'g', 's', ' ', 'a', 'n', 'd', ' ', 's', 'p', 'a', 'm'] >>> l.reverse() >>> l ['m', 'a', 'p', 's', ' ', 'd', 'n', 'a', ' ', 's', 'g', 'g', 'e', ' ', ',', 'm', 'a', 'p', 's', ' ', ',', 'm', 'a', 'p', 's'] >>> b = string.join(l, '') >>> b 'maps dna sgge ,maps ,maps' >>> And if you do care about the algorithm, the book will likely have you looking into recursion. >>> def string_reverse(s): ... if s: ... # prepend last character to result of string_reverse ... return s[-1:] + string_reverse(s[:-1]) ... else: ... return '' ... >>> string_reverse(a) 'maps dna sgge ,maps ,maps' >>> -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From alan.gauld@bt.com Mon Mar 12 16:52:07 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Mar 2001 16:52:07 -0000 Subject: [Tutor] Working with strings Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D623@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0AB14.C600A300 Content-type: text/plain; charset="iso-8859-1" it at the moment). Can you correct my program below and give me some sample program as to how to do it simply. I'm not having trouble with the logic of the string manipulation(I think) - just getting the program to accept input and print output. Most replies have tried to give you a different function, I'll try to work with this one... First I'll indent it they way I think you meant it to be and use a non proportional font for clarity: def backword(bruce): bruce=raw_input('input a word to reverse ') index=len(bruce)-1 while index<0: letter=bruce[index] print letter, index = index+1 >>> backword <function backword at 00BC015C> So we've defined a function which takes an argument, now to see if it works... >>> backword(flowerpot) Traceback (innermost last): File "<pyshell#36>", line 1, in ? backword(flowerpot) NameError: There is no variable named 'flowerpot' We passed a variable parameter(not a string because there were no quote signs around it) and Python objected because the variable doesn't exist yet.. Fix it by declaring the variable before calling the function: >>> flowerpot = "Flowerpot" >>> backward(flowerpot) Or by calling the function with a string: >>> backward("flowerpot") # note the quotes... >>> backword('flowerpot') input a word to reverse flowerpot OK, we entered the function. Now its asking us to replace the argument we passed('flowerpot') with a new value we type at the prompt. We now try to execute: index=len(bruce)-1 find index of last letter while index<0: never do the loop stuff because the index of the last letter is greater than 0 exit the function. >>> print bruce harold # a value I entered earlier that it hasn't cleared. correct! >>> def backword('bruce'): SyntaxError: invalid syntax Try to define a new function but specify an argumemnt name of "bruce" which is a string literal - Python doesn't allow string literals as argument/variable names so its a syntax error. >>> backword(flowerpot) Traceback (innermost last): File "<pyshell#40>", line 1, in ? backword(flowerpot) NameError: There is no variable named 'flowerpot' Back to the start of the message :-) HTH, Alan G. ------_=_NextPart_001_01C0AB14.C600A300 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>it at the moment). Can you correct my program below and give me some sample program as to how to do it simply. I'm not having trouble with the logic of the string manipulation(I think) - just getting the program to accept input and print output.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV></BLOCKQUOTE> <DIV><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial size=2>Most replies have tried to give you a different function, I'll try to </FONT></SPAN></DIV> <DIV><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial size=2>work with this one...</FONT></SPAN> <FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>First I'll indent it they way I think you meant it to be and use a non </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>proportional font for clarity:</FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001> </SPAN><BR></FONT><FONT face=Arial></FONT></FONT><FONT face="Courier New" size=2>def backword(bruce):<BR><SPAN class=360213516-12032001><FONT color=#0000ff><FONT color=#000000> </FONT> </FONT></SPAN> bruce=raw_input('input a word to reverse ')<BR><SPAN class=360213516-12032001><FONT color=#0000ff> <FONT color=#000000> </FONT> </FONT></SPAN> index=len(bruce)-1<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>while index<0:<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>letter=bruce[index]<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>print letter,<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>index = index+1</FONT><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001> </SPAN> <BR></FONT><FONT face="Courier New">>>> backword<BR><function backword at 00BC015C><BR><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>So we've defined a function which takes an argument, now to see if it works...</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face="Courier New"><FONT size=2><SPAN class=360213516-12032001> </SPAN>>>> backword(flowerpot)<BR>Traceback (innermost last):<BR> File "<pyshell#36>", line 1, in ?<BR> backword(flowerpot)<BR>NameError: There is no variable named 'flowerpot'<SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>We passed a variable parameter(not a string because there were no quote signs </SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>around it) and Python objected because the variable doesn't exist yet.. </SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>Fix it by declaring the variable before calling the function:</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face="Courier New"><SPAN class=360213516-12032001>>>> flowerpot = "Flowerpot"</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face="Courier New"><SPAN class=360213516-12032001>>>> backward(flowerpot)</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>Or by calling the function with a string:</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face="Courier New"><SPAN class=360213516-12032001>>>> backward("flowerpot") # note the quotes...</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001> </SPAN><BR></FONT><FONT face="Courier New">>>> backword('flowerpot')<BR>input a word to reverse flowerpot<SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>OK, we entered the function. Now its asking us to replace the argument we </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>passed('flowerpot') with a new value we type at the prompt.</FONT></SPAN></FONT></FONT></DIV> <DIV><SPAN class=360213516-12032001></SPAN><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff> We now try to execute:</FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face="Courier New"><FONT size=2><SPAN class=360213516-12032001><FONT color=#0000ff><SPAN class=360213516-12032001><FONT color=#0000ff> <FONT color=#000000> </FONT> </FONT></SPAN> index=len(bruce)-1</FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial>find index of last letter</FONT></SPAN></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff><BR><FONT face="Courier New"> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>while index<0:<BR></FONT><FONT face=Arial>never do the loop stuff because the index of the last letter is greater than 0</FONT></FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>exit the function.</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face=Arial size=2><FONT face="Courier New">>>> print bruce<BR></FONT>harold # a value I entered earlier that it hasn't cleared.<SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001>correct!</SPAN></FONT></DIV> <DIV><FONT face=Arial><FONT size=2><SPAN class=360213516-12032001> </SPAN><BR><FONT face="Courier New"></FONT><FONT size=2>>>> def backword('bruce'):<BR></FONT></FONT><FONT size=2> SyntaxError: invalid syntax<SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT size=2><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN class=360213516-12032001>Try to define a new function but specify an argumemnt name of "bruce" </SPAN></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN class=360213516-12032001>which is a string literal - Python doesn't allow string literals as argument/variable </SPAN></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN class=360213516-12032001>names so its a syntax error.</SPAN></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face=Arial size=2>>>> backword(flowerpot)<BR>Traceback (innermost last):<BR> File "<pyshell#40>", line 1, in ?<BR> backword(flowerpot)<BR>NameError: There is no variable named 'flowerpot'<BR><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001>Back to the start of the message :-)</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001>HTH,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=360213516-12032001>Alan G.</SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0AB14.C600A300-- From douglas.shawhan@ae.ge.com Mon Mar 12 17:29:35 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Mon, 12 Mar 2001 12:29:35 -0500 Subject: [Tutor] Breaking string at commas Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> I am trying to write a script that will take comma seperated text from a file, break the strings into seperate units at the linefeeds then seperate the comma seperated text into strings, insert html formatting then output the whole shebang into an html file. I have figured out how to read the info from the flat files and squirt them to html with formatting (do what you can, if it's all that you can! :-). ---------begin ugly script--------------- f=open('/windows/desktop/shuffles/hippie.db','r') grunty=f.read() f=open('/windows/desktop/shuffles/whofrom.db','r') whofrom=f.read() f=open('/windows/desktop/shuffles/whofrom.db','r') whoto=f.read() f=open('punker.html','w') f.write('<html><h1><b>MOVES/INSTALLS</b></h1><body bgcolor=white><font face=\"arial,helvetica\" size=\"2\"><table width=580><tr><td bgcolor=black> </td><tr><td>'+`grunty`+'</td><tr><td bgcolor=black> </td><tr><td>'+`whofrom`+'</td><tr><td bgcolor=black> </td><tr><td>'+`whoto`+'</td></table></font></html >') f.close() ----------end ugly script-------------- Now the tricky part for me is: How can I first bust the files apart at the line breaks, then search for the unique id in the resulting output? Tuples? The other trick is: How am I going to bust apart those strings within the chosen output to insert the formatting? Feel free to poke me in the eye or point me to an example in a manual (I have the tutorial from the website and a copy of Lutz and Ascher's so-far excellent "Learning Python") Thanks! d From kalle@gnupung.net Mon Mar 12 17:56:43 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 12 Mar 2001 18:56:43 +0100 Subject: [Tutor] Breaking string at commas In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Mon, Mar 12, 2001 at 12:29:35PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> Message-ID: <20010312185643.A21772@father> Sez Shawhan, Douglas (GEAE, GECC): [snip] > f=open('/windows/desktop/shuffles/whofrom.db','r') > whofrom=f.read() > f=open('/windows/desktop/shuffles/whofrom.db','r') > whoto=f.read() Is this a typo, or could it be written whoto = whofrom? [snip] > Now the tricky part for me is: How can I first bust the files apart at the > line breaks, then search for the unique id in the resulting output? Tuples? Use f.readlines(). This gives you a list of lines in the file. http://www.python.org/doc/current/lib/bltin-file-objects.html Searching could be done with some kind of loop over this list. > The other trick is: How am I going to bust apart those strings within the > chosen output to insert the formatting? Use the string method split, or if you're stuck with Python 1.5.2 or older, use string.split(): Python 2.0 (#2, Oct 17 2000, 11:33:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> s = "a,b,c" >>> s.split(",") ['a', 'b', 'c'] >>> Python 1.5.2 (#1, Dec 21 2000, 15:29:08) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import string >>> s = "a,b,c" >>> string.split(s, ",") ['a', 'b', 'c'] >>> http://www.python.org/doc/current/lib/string-methods.html http://www.python.org/doc/current/lib/module-string.html The string module works in 1.6 and later too, but I prefer using string methods if possible. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From tmbrau00@centre.edu Mon Mar 12 17:49:18 2001 From: tmbrau00@centre.edu (Timothy Brauch) Date: Mon, 12 Mar 2001 12:49:18 -0500 Subject: [Tutor] Breaking string at commas References: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> Message-ID: <3AAD0C1E.89CAF40A@centre.edu> The string.split from the string module will break up a string into a list of parts of the string. You can choose what to use for a break point. THe following example uses <> as a break point. >>> import string >>> raw_string='I hope this will be split after this <> but before this.' >>> new_strings=string.split(raw_string,'<>') >>> print new_strings ['I hope this will be split after this ', ' but before this.'] By default, if you don't specify a pattern to break by, it will break by white space. Like this, >>> raw_string='This is a string of words' >>> new_string=string.split(raw_string) >>> print new_string ['This', 'is', 'a', 'string', 'of', 'words'] Now, try this, >>> db_entry='item_1, item_2, item_3' >>> format_db=string.split(db_entry,',') >>> print format_db ['item_1', ' item_2', ' item_3'] Hmm, if you look closely at the items in format_db, it is ' item_2', there is some whitespace at the beginning. Instead, let's try this: >>> db_entry='item_1, item_2, item_3' >>> format_db=string.split(db_entry,' ,') >>> print format_db ['item_1, item_2, item_3'] There, that works better. Hopefully that will help you to break up the strings where you want them. - Tim ********************************************************************** "Shawhan, Douglas (GEAE, GECC)" wrote: I am trying to write a script that will take comma seperated text from a file, break the strings into seperate units at the linefeeds then seperate the comma seperated text into strings, insert html formatting then output the whole shebang into an html file. I have figured out how to read the info from the flat files and squirt them to html with formatting (do what you can, if it's all that you can! :-). ---------begin ugly script--------------- f=open('/windows/desktop/shuffles/hippie.db','r') grunty=f.read() f=open('/windows/desktop/shuffles/whofrom.db','r') whofrom=f.read() f=open('/windows/desktop/shuffles/whofrom.db','r') whoto=f.read() f=open('punker.html','w') f.write('<html><h1><b>MOVES/INSTALLS</b></h1><body bgcolor=white><font face=\"arial,helvetica\" size=\"2\"><table width=580><tr><td bgcolor=black> </td><tr><td>'+`grunty`+'</td><tr><td bgcolor=black> </td><tr><td>'+`whofrom`+'</td><tr><td bgcolor=black> </td><tr><td>'+`whoto`+'</td></table></font></html >') f.close() ----------end ugly script-------------- Now the tricky part for me is: How can I first bust the files apart at the line breaks, then search for the unique id in the resulting output? Tuples? The other trick is: How am I going to bust apart those strings within the chosen output to insert the formatting? Feel free to poke me in the eye or point me to an example in a manual (I have the tutorial from the website and a copy of Lutz and Ascher's so-far excellent "Learning Python") Thanks! d From Lindsay.Davies@moonshine.co.uk Mon Mar 12 17:55:24 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Mon, 12 Mar 2001 17:55:24 +0000 Subject: [Tutor] Breaking string at commas In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> References: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> Message-ID: <p0501040fb6d2bbfcd3eb@[195.102.186.233]> The first thing you can take a look at is... http://www.pydoc.org/2.1b1/string.html#-split which documents string.split(), which splits a string! However, splitting true CSV text is more complicated than that, so the actual solution depends on whether you have a simple data set or not. The simple approach is to split the text on linefeeds into a list of lines. Then for each line, split on commas into a list your required fields. To place the fields into HTML, I'd suggest using python's triple quoting mechanism, then you can correctly quote your tag attributes without any problems... f.write(""" <html> <body bgcolor=white> ...etc """) BTW, the HTML in your example is actually incorrect (You have no HEAD tag, and the H1 tag should be moved into the BODY tag). Best wishes, Lindsay On 12/3/01, Shawhan, Douglas (GEAE, GECC) wrote about '[Tutor] Breaking string at commas': >I am trying to write a script that will take comma seperated text from a >file, break the strings into seperate units at the linefeeds then seperate >the comma seperated text into strings, insert html formatting then output >the whole shebang into an html file. I have figured out how to read the info >from the flat files and squirt them to html with formatting (do what you >can, if it's all that you can! :-). > >---------begin ugly script--------------- >f=open('/windows/desktop/shuffles/hippie.db','r') >grunty=f.read() >f=open('/windows/desktop/shuffles/whofrom.db','r') >whofrom=f.read() >f=open('/windows/desktop/shuffles/whofrom.db','r') >whoto=f.read() >f=open('punker.html','w') >f.write('<html><h1><b>MOVES/INSTALLS</b></h1><body bgcolor=white><font >face=\"arial,helvetica\" size=\"2\"><table width=580><tr><td >bgcolor=black> </td><tr><td>'+`grunty`+'</td><tr><td >bgcolor=black> </td><tr><td>'+`whofrom`+'</td><tr><td >bgcolor=black> </td><tr><td>'+`whoto`+'</td></table></font></html > >') >f.close() >----------end ugly script-------------- > >Now the tricky part for me is: How can I first bust the files apart at the >line breaks, then search for the unique id in the resulting output? Tuples? > > >The other trick is: How am I going to bust apart those strings within the >chosen output to insert the formatting? > >Feel free to poke me in the eye or point me to an example in a manual (I >have the tutorial from the website and a copy of Lutz and Ascher's so-far >excellent "Learning Python") > >Thanks! > >d > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From scarblac@pino.selwerd.nl Mon Mar 12 18:01:15 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 12 Mar 2001 19:01:15 +0100 Subject: [Tutor] Breaking string at commas In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Mon, Mar 12, 2001 at 12:29:35PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> Message-ID: <20010312190115.A10539@pino.selwerd.nl> On Mon, Mar 12, 2001 at 12:29:35PM -0500, Shawhan, Douglas (GEAE, GECC) wrote: > I am trying to write a script that will take comma seperated text from a > file, break the strings into seperate units at the linefeeds then seperate > the comma seperated text into strings, insert html formatting then output > the whole shebang into an html file. I have figured out how to read the info > from the flat files and squirt them to html with formatting (do what you > can, if it's all that you can! :-). > > ---------begin ugly script--------------- > f=open('/windows/desktop/shuffles/hippie.db','r') > grunty=f.read() > f=open('/windows/desktop/shuffles/whofrom.db','r') > whofrom=f.read() > f=open('/windows/desktop/shuffles/whofrom.db','r') > whoto=f.read() > f.write('<html><h1><b>MOVES/INSTALLS</b></h1><body bgcolor=white><font > face=\"arial,helvetica\" size=\"2\"><table width=580><tr><td > bgcolor=black> </td><tr><td>'+`grunty`+'</td><tr><td > bgcolor=black> </td><tr><td>'+`whofrom`+'</td><tr><td > bgcolor=black> </td><tr><td>'+`whoto`+'</td></table></font></html > >') > f.close() > ----------end ugly script-------------- I suppose that the whole 'f.write(' thing was on a single line, that's ugly indeed :). With """triple quoted strings""" you can span multiple lines. > Now the tricky part for me is: How can I first bust the files apart at the > line breaks, You can split it on "\n", or read them in as a list of lines in the first place using f.readlines(). However, readlines() leaves the \n in the strings, and since you don't want that here, it's easiest to split it yourself, using string.split (it's also a string method in newer versions, but this probably has to run on some web server, they often have 1.5.2, so I'm assuming that). > then search for the unique id in the resulting output? Tuples? I don't know what this id is, but you can split the comma seperated line with a further string.split on ",", as long as it's not too complicated (if the data itself can have a comma inside it you'll have some escaping thing, simply splitting will be wrong then). > The other trick is: How am I going to bust apart those strings within the > chosen output to insert the formatting? For the formatting, you want to make a template of the html, with things like '%(howto)s' inside it, then you can fill in the template with the % operator. I'd write it like this: ---------------------------------------------------------------- html_template = """ <html> <h1> <b>MOVES/INSTALLS</b> </h1> <body bgcolor=white> <font face="arial,helvetica" size="2"> <table width=580> <tr> <td bgcolor=black> </td> <tr> <td>%(grunty)s</td> <tr> <td bgcolor=black> </td> <tr> <td>%(whofrom)s</td> <tr> <td bgcolor=black> </td> <tr> <td>%(whoto)s</td> </table> </font> </html> """ # (You can't have a <h1> before <body>, but it's the example you use...) # You also didn't close your <tr> tags! # Note I didn't have to escape " in a """ string # Instead of writing a template you may want to use HTMLGen. # Now the files stuff: import string # For the split function information = {} # Dict in which we store things for the template # You also should have some error detection here... grunty = open('/windows/desktop/shuffles/hippie.db','r').read() grunty = string.split(grunty, "\n") # Divide into lines # As an example, we'll print the split version of the first line of the file, # I don't know what you need information['grunty'] = repr(string.split(grunty[0], ",")) whofrom = open('/windows/desktop/shuffles/whofrom.db','r').read() whofrom = string.split(whofrom, "\n") information['whofrom'] = repr(string.split(whofrom[0], ",")) whoto = open('/windows/desktop/shuffles/whofrom.db','r').read() whoto = string.split(whoto, "\n") information['whofrom'] = repr(string.split(whofrom[0], ",")) # Now we fill in the template using the dictionary HTML = html_template % information # And write it f=open('punker.html','w') f.write(HTML) f.close() ---------------------------------------------------------------- -- Remco Gerlich From tescoil@irtc.net Mon Mar 12 17:10:32 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 12:10:32 -0500 Subject: [Tutor] filtering within a function. Message-ID: <3AAD0308.C9C1EE61@irtc.net> Revising cipher.py... http://www.lowerstandard.com/python/cipher.py to eliminate import of string, and discovered that the unstray function is bugged something awful (guess it usually gets the right input; this has gone unnoticed for a couple months). Given: >>> foo = list('UPPERlowerUPPER12345') This appears to work: >>> uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> def f(x): return x in uppercase ... >>> filter(f, foo) ['U', 'P', 'P', 'E', 'R', 'U', 'P', 'P', 'E', 'R'] Can't seem to make it work inside the function. From sthickey@juno.com Mon Mar 12 18:20:40 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Mon, 12 Mar 2001 10:20:40 -0800 Subject: [Tutor] Re: Tutor Daemon [Service] Message-ID: <20010312.102041.-521359.0.sthickey@juno.com> Some of us Windows users are not there by choice. When I left school in 1993, I had 4 years of Unix under by belt, but the jobs I wound up getting were working with Windows stuff. I have not had access to a Unix machine for 6 years! Thanks for the tip about Cygwin. I also am going to try to load Linux on an older machine I have put in the Garage! Stevenson Hickey From alan.gauld@bt.com Mon Mar 12 18:16:34 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Mar 2001 18:16:34 -0000 Subject: [Tutor] Working with strings Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D625@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0AB20.921AD8B0 Content-type: text/plain; charset="iso-8859-1" Most replies have tried to give you a different function, I'll try to work with this one... First I'll indent it they way I think you meant it to be and use a non proportional font for clarity: def backword(bruce): bruce=raw_input('input a word to reverse ') index=len(bruce)-1 while index<0: letter=bruce[index] print letter, index = index+1 I also meant to say that the algorithm above is broken... index=len(bruce)-1 find index of last letter while index<0: never do the loop stuff because the index of the last letter is greater than 0 exit the function. The algorithm should I think be: index = len(bruce)-1 while index >= 0: print bruce[index] index = index -1 Thus for 'flowerpot' we get an index of 8 which now enters the while loop Now we can print bruce[-n](ie 't') then decrement index to 7 and print 'o' etc.. till index = 0 which prints 'f'But several of the other suggested algorithms are better, I just assume this is the one in the book... Alan G ------_=_NextPart_001_01C0AB20.921AD8B0 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial size=2>Most replies have tried to give you a different function, I'll try to </FONT></SPAN></DIV> <DIV><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial size=2>work with this one...</FONT></SPAN> <FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>First I'll indent it they way I think you meant it to be and use a non </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff>proportional font for clarity:</FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001> </SPAN><BR></FONT><FONT face=Arial></FONT></FONT><FONT face="Courier New" size=2>def backword(bruce):<BR><SPAN class=360213516-12032001><FONT color=#0000ff><FONT color=#000000> </FONT> </FONT></SPAN> bruce=raw_input('input a word to reverse ')<BR><SPAN class=360213516-12032001><FONT color=#0000ff> <FONT color=#000000> </FONT> </FONT></SPAN> index=len(bruce)-1<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>while index<0:<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>letter=bruce[index]<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>print letter,<BR> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>index = index+1</FONT><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><SPAN class=780560318-12032001><FONT color=#0000ff> I also meant to say that the algorithm above is broken...</FONT></SPAN></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><SPAN class=780560318-12032001> </SPAN> </SPAN> <BR></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN class=360213516-12032001><FONT color=#0000ff><SPAN class=360213516-12032001><FONT color=#0000ff> <FONT color=#000000> </FONT> </FONT></SPAN> index=len(bruce)-1</FONT></SPAN></FONT></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT size=2><SPAN class=360213516-12032001><FONT color=#0000ff face=Arial>find index of last letter</FONT></SPAN></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001><FONT color=#0000ff><BR><FONT face="Courier New"> <SPAN class=360213516-12032001><FONT color=#0000ff> </FONT></SPAN>while index<0:<BR></FONT><FONT face=Arial>never do the loop stuff because the index of the last letter is greater than 0</FONT></FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=360213516-12032001>exit the function.</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT face=Arial><SPAN class=360213516-12032001></SPAN></FONT></FONT> </DIV></BLOCKQUOTE> <DIV><SPAN class=780560318-12032001><FONT color=#0000ff face=Arial size=2>The algorithm should I think be:</FONT></SPAN></DIV> <DIV><SPAN class=780560318-12032001></SPAN> </DIV> <DIV><SPAN class=780560318-12032001></SPAN><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001>index = len(bruce)-1</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001>while index >= 0:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001> print bruce[index]</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001> index = index -1</SPAN></FONT></DIV> <DIV><FONT color=#0000ff size=2><SPAN class=780560318-12032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Thus for 'flowerpot' we get an index of 8</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>which now enters the while loop</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Now we can print bruce[-n](ie 't') </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>then decrement index to 7 and print 'o' etc..</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>till index = 0 which prints 'f'But several of the other </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>suggested algorithms are better, I just assume this is </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>the one in the book...</SPAN></FONT></DIV> <DIV><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN class=780560318-12032001></SPAN></FONT></FONT> </DIV> <DIV><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN class=780560318-12032001>Alan G</SPAN></FONT></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0AB20.921AD8B0-- From alan.gauld@bt.com Mon Mar 12 18:21:05 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Mar 2001 18:21:05 -0000 Subject: [Tutor] Working with strings Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D626@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0AB21.33B2CC00 Content-type: text/plain; charset="iso-8859-1" Doh!!! The algorithm should I think be: index = len(bruce)-1 while index >= 0: print bruce[index] index = index -1 Thus for 'flowerpot' we get an index of 8 which now enters the while loop Now we can print bruce[-n](ie 't') bruce[index] not [-n]... where'd that come from?!!! Alan G. ------_=_NextPart_001_01C0AB21.33B2CC00 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=330101518-12032001>Doh!!!</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><SPAN class=780560318-12032001><FONT color=#0000ff face=Arial size=2>The algorithm should I think be:</FONT></SPAN></DIV> <DIV><SPAN class=780560318-12032001></SPAN> </DIV> <DIV><SPAN class=780560318-12032001></SPAN><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001>index = len(bruce)-1</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001>while index >= 0:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001> print bruce[index]</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN class=780560318-12032001> index = index -1</SPAN></FONT></DIV> <DIV><FONT color=#0000ff size=2><SPAN class=780560318-12032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Thus for 'flowerpot' we get an index of 8</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>which now enters the while loop</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Now we can print bruce[-n](ie 't') </SPAN></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=780560318-12032001><SPAN class=330101518-12032001> </SPAN></SPAN></FONT></FONT></FONT></DIV></BLOCKQUOTE> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=780560318-12032001><SPAN class=330101518-12032001>bruce[index] not [-n]... where'd that come from?!!!</SPAN></SPAN></FONT></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=780560318-12032001><SPAN class=330101518-12032001></SPAN></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN class=780560318-12032001><SPAN class=330101518-12032001>Alan G.</SPAN></SPAN></FONT></FONT></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0AB21.33B2CC00-- From arcege@shore.net Mon Mar 12 18:36:35 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 12 Mar 2001 13:36:35 -0500 (EST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD0308.C9C1EE61@irtc.net> from Tesla Coil at "Mar 12, 2001 12:10:32 pm" Message-ID: <E14cXBL-00054D-00@nautilus.shore.net> > Revising cipher.py... > http://www.lowerstandard.com/python/cipher.py > to eliminate import of string, and discovered > that the unstray function is bugged something > awful (guess it usually gets the right input; > this has gone unnoticed for a couple months). > > Given: > >>> foo = list('UPPERlowerUPPER12345') > > This appears to work: > > >>> uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > >>> def f(x): return x in uppercase > ... > >>> filter(f, foo) > ['U', 'P', 'P', 'E', 'R', 'U', 'P', 'P', 'E', 'R'] > > Can't seem to make it work inside the function. That is probably because unstray relies on side-effects of the function parameter, which is usually a bad design choice (but not always). Here the problem is that unstray returns nothing and modifies listinput. What you can do is overwrite the list's elements. How about: uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def unstray(listinput, f=lambda x: x in uppercase): l = filter(f, listinput) # replace the contents of listinput with the result of the filtering listinput[:] = l But then, maybe I'm missing the point. :) -Michael -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From glingl@mail.rg16.asn-wien.ac.at Mon Mar 12 18:40:10 2001 From: glingl@mail.rg16.asn-wien.ac.at (Gregor Lingl) Date: Mon, 12 Mar 2001 19:40:10 +0100 Subject: [Tutor] Working with strings References: <E14cVCu-0006SB-00@mail.python.org> Message-ID: <3AAD180A.E1F691C3@rg16.asn-wien.ac.at> Concerning the problem: reversing a string I think, since print x, inserts a space after printing x, it is better first to construct the backword and then return it to a print-statement: For instance: >>> def backword(s): s = list(s) s.reverse() return ''.join(s) >>> print backword("abraham") maharba >>> Have fun! Gregor From dsh8290@rit.edu Mon Mar 12 19:12:51 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 12 Mar 2001 14:12:51 -0500 Subject: [Tutor] Hi all. In-Reply-To: <Pine.LNX.4.21.0103102237060.2210-100000@c82114-a.pinol1.sfba.home.com>; from dyoo@hkn.eecs.berkeley.edu on Sat, Mar 10, 2001 at 10:45:30PM -0800 References: <3AAB8460.4849.1035D18@localhost> <Pine.LNX.4.21.0103102237060.2210-100000@c82114-a.pinol1.sfba.home.com> Message-ID: <20010312141250.A7761@harmony.cs.rit.edu> On Sat, Mar 10, 2001 at 10:45:30PM -0800, Danny Yoo wrote: | On Sun, 11 Mar 2001 senum@singnet.com.sg wrote: | | > Hi..thanks for the replies.First of all i tried the list but it didnt | > work. Anyway i have a few questions..any replies would be greatly | > appreciated :) | | (Try to sign up again later; it appears that the web interface isn't | working at the moment. You'll receive replies to your own messages, but | you're missing out on the other messages addressed to the general tutor | list.) FYI, this isn't always true. If the person replying selectes "group" reply, a copy will be sent to the list and to the sender (and anyone else in the To and CC lists as well). If the person replying selects "list" reply, a copy will be sent only to the list, and to anyone listed in the Mail-Followup-To header. AFAIK not many mailers have list support so it shouldn't be much of an issue. I use mutt and, unless explicitly requested in the mesage (and in this case since you may not be on the list yet ;-)), use "list" reply instead of "group" reply. If you are signed up on the list, you will get a copy of the message, as sent to the list when I use this feature. When people use "group" reply you get a copy addressed to you AND a copy addressed to the list. -D PS. Just in case it isn't clear, I'm not complaining about broken mailers ;-), just informing readers of the whole story (as I know it) From senum@singnet.com.sg Mon Mar 12 19:30:00 2001 From: senum@singnet.com.sg (senum@singnet.com.sg) Date: Tue, 13 Mar 2001 03:30:00 +0800 Subject: [Tutor] how do i link up the file and the interpreter? Message-ID: <3AAD9438.13650.1080340@localhost> Hi all, well..i'm back with a first question.I need to run some examples at the interactive prompt..current i have two OS installed[Linux and windows] but since i'm on the net most of the time i use windows.so right now i'm using active python to run the code samples.In this example i'm supposed to use the 'print' command and at the same time include a module file 'test.py'.can i set a path env in active python to link to my testfiles dir?i tried but the edit path doesnt seem to work. Also i tried to run the python cmd from the dos prompt but bad cmd or filename.i recall i should be adding a path env statement in autoexec.bat to make it globally avail?is it valid coz that's wat i did the other time with my C compiler? Any advice is appreciated. Thanks. Kenny, From dsh8290@rit.edu Mon Mar 12 19:53:00 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 12 Mar 2001 14:53:00 -0500 Subject: [Tutor] Python Daemon(Service) In-Reply-To: <55667143B7B@kserver.org>; from sheila@thinkspot.net on Sun, Mar 11, 2001 at 04:27:30PM -0800 References: <4D298960E1C@kserver.org> <0103111526150G.11686@shecom> <55667143B7B@kserver.org> Message-ID: <20010312145300.B7761@harmony.cs.rit.edu> On Sun, Mar 11, 2001 at 04:27:30PM -0800, Sheila King wrote: | On Sun, 11 Mar 2001 15:19:07 -0900, Tim Johnson <tim@johnsons-web.com> wrote | about Re: [Tutor] Python Daemon(Service): | | :I've been moving away from windows programming, but I think the key word | :is Service: | :For this to happen on windows, the application (or python script) would | :be installed as a Service. | | When you say "service", you're talking about WinNT or Win2000. I don't think | that would apply to Win98 (like I run). I have heard the term "service" associated only with NT and 2K. I think that on those systems there is some work that must be done to tell the OS that your process is a service. AFAIK there is no such thing in Win9x. After all, daemons and services really only make sense on a server system. Win9x isn't intended, not is it suitable IMO, for a server set up. Inetd and Apache do run on Win9x though, so maybe a peek at it may help. I think that they are simply processes that don't terminate. I also think that apache is kind of stuck with a DOS window, unless it is registered as a service on NT/2000. Also, as has already been mentioned, a deamon on Unix isn't really anything special except in what it does for the user. As far as programming goes it is mostly an event/interrupt based program that runs infinitely. Certains actions should be taken for security/safety reasons, but aren't absolutely necessary. | I am mildly surprised at the very Unix-centric trend that recent responses | have taken. The term 'daemon' implies Unix, and the original poster asked about (RedHat) Linux specifically. Also, some of the suggestions ( chdir to "/", setuid/setgrp to nobody) don't have any windows equivalents AFAIK. If they do, then it would almost certainly require different function calls. | Eventually I think I will get a new computer (within the next year | or so), and when I do, I think I will put a dual boot option on it, | and have a Linux drive. But for now, I am without. (I am only mildly | acquainted with Unix: took one university programming course in C++ | on Unix systems...and host my website off of a Linux server.) Dual booting isn't actually necessary. On a prebuilt machine it is actually harder since the disk will only have 1 partition devoted wholly to Windows (at least my 8GB drive was ~3 years ago). I bought a second hard drive to try out Linux on. Now I rarely boot the windows disk. Also, Linux will run perfectly happy on older 486/Pentium machines. Ok, so X won't be so smooth on a 486, but a Pentium should be ok. Since you are running Win98 now you probably have a newer machine than that. (My dad is still running Win95 on a 486DX2, 66MHz system; my grandfather has a 386SX with Win95 that I got for free a couple years ago) When you get the new one simply convert this one to Linux. You could even use it to firewall for your windows box. I strongly prefer Linux and find cygwin invaluable on the Win2k box I must use at work. I try and make it look as much like a *nix system as I can. (I primarily use gvim and bash for development, and I found a nice (free!) virtual desktop utility) -D From tescoil@irtc.net Mon Mar 12 19:39:43 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 14:39:43 -0500 Subject: [Tutor] filtering within a function. References: <E14cXBL-00054D-00@nautilus.shore.net> Message-ID: <3AAD25FF.B5FD481@irtc.net> On 12 Mar 2001, Michael P. Reilly replied: > That is probably because unstray relies on > side-effects of the function parameter, which > is usually a bad design choice (but not always). > Here the problem is that unstray returns nothing > and modifies listinput. In this case, returning nothing and modifying the list was a conscious choice, not just how I got it to work--no need to retain the original list. unstray is a crock for the same reason as: foo = [1, 2, 1, 3, 1, 4] for x in foo: if x >= 2: foo.remove(x) That looks like it works, but foo[1] is removed, foo[2] falls into foo[1], placing it behind the iteration, as foo = [1, 2, 3, 4] would reveal. > What you can do is overwrite the list's elements. > > How about: > uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > def unstray(listinput, f=lambda x: x in uppercase): > l = filter(f, listinput) > # replace the contents of listinput with the result of the filtering > listinput[:] = l > > But then, maybe I'm missing the point. :) Not that I can see. Is this bad form?: def unstray(listinput): f=lambda x: x in uppercase l = filter(f, listinput) listinput[:] = l From wesc@deirdre.org Mon Mar 12 20:52:51 2001 From: wesc@deirdre.org (Wesley J. Chun) Date: Mon, 12 Mar 2001 12:52:51 -0800 Subject: [Tutor] Breaking string at commas Message-ID: <200103122052.MAA11788@emperor.deirdre.org> > From: "Shawhan, Douglas (GEAE, GECC)" <douglas.shawhan@ae.ge.com> > Date: Mon, 12 Mar 2001 12:29:35 -0500 > > I am trying to write a script that will take comma seperated text from a > file, break the strings into seperate units at the linefeeds then seperate > the comma seperated text into strings, insert html formatting then output > the whole shebang into an html file. douglas, the basic recipe i would use is: 1. use file.readlines() to get list of input lines (broken @ linefeeds) (the new file.xreadlines() can be used for large input files) 2. use string.split() to get comma-separated text string list (split() [and join()] are string module functions or string methods) 3. use string.join() to merge the strings together with the HTML formatting and calling file.write() to output to a HTML file hope this helps! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Silicon Valley-SF Bay Area Python users group: http://www.baypiggies.org "Core Python Programming", Prentice Hall PTR, December 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html wesley.j.chun :: wesc@baypiggies.org cyberweb.consulting :: silicon.valley, ca cyberweb_consulting@yahoo.com http://www.roadkill.com/~wesc/cyberweb/ From arcege@shore.net Mon Mar 12 20:51:22 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 12 Mar 2001 15:51:22 -0500 (EST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD25FF.B5FD481@irtc.net> from Tesla Coil at "Mar 12, 2001 2:39:43 pm" Message-ID: <E14cZHm-0001SY-00@nautilus.shore.net> > On 12 Mar 2001, Michael P. Reilly replied: > > That is probably because unstray relies on > > side-effects of the function parameter, which > > is usually a bad design choice (but not always). > > Here the problem is that unstray returns nothing > > and modifies listinput. > > In this case, returning nothing and modifying the > list was a conscious choice, not just how I got > it to work--no need to retain the original list. > > unstray is a crock for the same reason as: > > foo = [1, 2, 1, 3, 1, 4] > for x in foo: > if x >= 2: > foo.remove(x) > > That looks like it works, but foo[1] is removed, > foo[2] falls into foo[1], placing it behind the > iteration, as foo = [1, 2, 3, 4] would reveal. Yup, if you're going to do this, then it is generally better to use indices, which just makes life more interesting. ;) The remove() method removes the first element that matches. >>> i = 0 >>> while i < len(foo): ... if foo[i] >= 2: ... del foo[i] # do NOT increment i ... else: ... i = i + 1 >>> > > What you can do is overwrite the list's elements. > > > > How about: > > uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > > def unstray(listinput, f=lambda x: x in uppercase): > > l = filter(f, listinput) > > # replace the contents of listinput with the result of the filtering > > listinput[:] = l > > > > But then, maybe I'm missing the point. :) > > Not that I can see. Is this bad form?: > > def unstray(listinput): > f=lambda x: x in uppercase > l = filter(f, listinput) > listinput[:] = l About the only thing is that putting the lambda in the function declaration does not recreate the lambda function every time and also keeps it out of the global namespace. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Mon Mar 12 21:07:39 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 12 Mar 2001 16:07:39 -0500 (EST) Subject: [Tutor] Breaking string at commas In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F252E@ma001dataaege.ae.ge.com> from "Shawhan, Douglas (GEAE, GECC)" at "Mar 12, 2001 12:29:35 pm" Message-ID: <E14cZXX-00063n-00@nautilus.shore.net> > I am trying to write a script that will take comma seperated text from a > file, break the strings into seperate units at the linefeeds then seperate > the comma seperated text into strings, insert html formatting then output > the whole shebang into an html file. I have figured out how to read the info > from the flat files and squirt them to html with formatting (do what you > can, if it's all that you can! :-). > > ---------begin ugly script--------------- > f=open('/windows/desktop/shuffles/hippie.db','r') > grunty=f.read() > f=open('/windows/desktop/shuffles/whofrom.db','r') > whofrom=f.read() > f=open('/windows/desktop/shuffles/whofrom.db','r') > whoto=f.read() > f=open('punker.html','w') > f.write('<html><h1><b>MOVES/INSTALLS</b></h1><body bgcolor=white><font > face=\"arial,helvetica\" size=\"2\"><table width=580><tr><td > bgcolor=black> </td><tr><td>'+`grunty`+'</td><tr><td > bgcolor=black> </td><tr><td>'+`whofrom`+'</td><tr><td > bgcolor=black> </td><tr><td>'+`whoto`+'</td></table></font></html > >') > f.close() > ----------end ugly script-------------- CSV (Comma Separated Values) can be a little complicated (embedded commas are quoted with double quotes around the whole field, but what about embedded double quotes, etc.). There are some packages that have already been written for CSV that you can find at the Vaults of Parnassus <URL: http://www.vex.net/parnassus/apyllo.py?so=d&find=CSV>. -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From tescoil@irtc.net Mon Mar 12 20:37:17 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 15:37:17 -0500 Subject: [Tutor] filtering within a function. References: <E14cZHm-0001SY-00@nautilus.shore.net> Message-ID: <3AAD337D.30B844D5@irtc.net> On 12 Mar 2001, Michael P. Reilly replied: >>> How about: >>> uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> def unstray(listinput, f=lambda x: x in uppercase): >>> l = filter(f, listinput) >>> # replace the contents of listinput with the result of the filtering >>> listinput[:] = l >>> >>> But then, maybe I'm missing the point. :) >> >> Not that I can see. Is this bad form?: >> >> def unstray(listinput): >> f=lambda x: x in uppercase >> l = filter(f, listinput) >> listinput[:] = l > > About the only thing is that putting the lambda in the > function declaration does not recreate the lambda function > every time and also keeps it out of the global namespace. "Keeps it out of the global namespace," I got. "Does not recreate the lambda function every time," I need explained --not yet a black belt in the lambda attack like Pedro. ;) From deirdre@deirdre.net Mon Mar 12 21:45:51 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 12 Mar 2001 13:45:51 -0800 (PST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD337D.30B844D5@irtc.net> Message-ID: <Pine.LNX.4.31.0103121341120.11087-100000@emperor.deirdre.org> On Mon, 12 Mar 2001, Tesla Coil wrote: > "Keeps it out of the global namespace," I got. "Does not > recreate the lambda function every time," I need explained > --not yet a black belt in the lambda attack like Pedro. ;) Or, as we would say around my house: "Your lambda-fu is not so good." This comes from a group of us going to see Star Wars Episode 1 in the scene where Anakin's fate is decided by Yoda -- and it was mentioned that Qui-Gon Jinn hadn't been successful. One of my friends quipped at the time "His kung fu was not so good." -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From arcege@shore.net Mon Mar 12 22:01:59 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 12 Mar 2001 17:01:59 -0500 (EST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD337D.30B844D5@irtc.net> from Tesla Coil at "Mar 12, 2001 3:37:17 pm" Message-ID: <E14caO7-0004Mp-00@nautilus.shore.net> > On 12 Mar 2001, Michael P. Reilly replied: > > About the only thing is that putting the lambda in the > > function declaration does not recreate the lambda function > > every time and also keeps it out of the global namespace. > > "Keeps it out of the global namespace," I got. "Does not > recreate the lambda function every time," I need explained > --not yet a black belt in the lambda attack like Pedro. ;) A function's arguments are evaluated when the function is created, not when it is called. >>> def f(a, l=[]): ... l.append(a) ... print id(l), l ... >>> f(0) 135094144 [0] >>> f(1) 135094144 [0, 1] >>> f('a') 135094144 [0, 1, 'a'] >>> So you can put the lambda function in the function definition and not have to recreate a new one each time. It doesn't really matter and pretty much is just a matter of style. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From scarblac@pino.selwerd.nl Mon Mar 12 22:37:50 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 12 Mar 2001 23:37:50 +0100 Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD0308.C9C1EE61@irtc.net>; from tescoil@irtc.net on Mon, Mar 12, 2001 at 12:10:32PM -0500 References: <3AAD0308.C9C1EE61@irtc.net> Message-ID: <20010312233750.A10865@pino.selwerd.nl> On Mon, Mar 12, 2001 at 12:10:32PM -0500, Tesla Coil wrote: > Revising cipher.py... > http://www.lowerstandard.com/python/cipher.py > to eliminate import of string, and discovered > that the unstray function is bugged something > awful (guess it usually gets the right input; > this has gone unnoticed for a couple months). > > Given: > >>> foo = list('UPPERlowerUPPER12345') > > This appears to work: > > >>> uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > >>> def f(x): return x in uppercase > ... > >>> filter(f, foo) > ['U', 'P', 'P', 'E', 'R', 'U', 'P', 'P', 'E', 'R'] > > Can't seem to make it work inside the function. What do you mean? What did you do exactly, and how does it fail? And why would you eliminate importing string when it has a perfectly fine definition of uppercase?! Hmmmm... Did you do 'listinput = filter(f, listinput)' ? In that case you only changed the local variable listinput, not the list it referred to. Try listinput[:] = filter(f, listinput) (slice assignment does change the list) -- Remco Gerlich From tescoil@irtc.net Mon Mar 12 23:02:56 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 18:02:56 -0500 Subject: [Tutor] filtering within a function. References: <3AAD0308.C9C1EE61@irtc.net> <20010312233750.A10865@pino.selwerd.nl> Message-ID: <3AAD55A0.8C52C5FC@irtc.net> On 12 Mar 2001, Remco Gerlich replied: >> This appears to work: >> >> >>> uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >> >>> def f(x): return x in uppercase >> ... >> >>> filter(f, foo) >> ['U', 'P', 'P', 'E', 'R', 'U', 'P', 'P', 'E', 'R'] >> >> Can't seem to make it work inside the >> function. > > What do you mean? What did you do exactly, > and how does it fail? Only neglected to go into detail as I wasn't sure which of a variety of attempts to provide as an example. > Did you do 'listinput = filter(f, listinput)' ? > In that case you only changed the local variable > listinput, not the list it referred to. Try > > listinput[:] = filter(f, listinput) > > (slice assignment does change the list) I think that was the main problem. > And why would you eliminate importing string > when it has a perfectly fine definition of > uppercase?! Currently have "import string" in the cipher module, and "import cipher, string" will load cipher, string and cipher.string--and all that cipher has ended up using is string.uppercase. I could simply 'from string import uppercase' but uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' doesn't amount to that much more typing, and >>> from string import uppercase >>> len(uppercase) == 26 0 >>> len(uppercase) 56 ...could prove The Wrong Thing. From jmshkim@yahoo.com Tue Mar 13 01:41:17 2001 From: jmshkim@yahoo.com (J. Kim) Date: Mon, 12 Mar 2001 17:41:17 -0800 (PST) Subject: [Tutor] (no subject) Message-ID: <20010313014117.87096.qmail@web13109.mail.yahoo.com> __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ From dsh8290@rit.edu Tue Mar 13 02:54:35 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 12 Mar 2001 21:54:35 -0500 Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD55A0.8C52C5FC@irtc.net>; from tescoil@irtc.net on Mon, Mar 12, 2001 at 06:02:56PM -0500 References: <3AAD0308.C9C1EE61@irtc.net> <20010312233750.A10865@pino.selwerd.nl> <3AAD55A0.8C52C5FC@irtc.net> Message-ID: <20010312215435.A8276@harmony.cs.rit.edu> On Mon, Mar 12, 2001 at 06:02:56PM -0500, Tesla Coil wrote: | On 12 Mar 2001, Remco Gerlich replied: | > And why would you eliminate importing string | > when it has a perfectly fine definition of | > uppercase?! | | Currently have "import string" in the cipher | module, and "import cipher, string" will load | cipher, string and cipher.string--and all that | cipher has ended up using is string.uppercase. How is this a problem? If I understand correctly you have: ### cipher.py import string ### here.py (I don't know what you named this module ;-) import cipher , string # now there exists 2 paths to string print string print cipher.string ## but I don't see a problem with it, just use 'string' instead of 'cipher.string' | I could simply 'from string import uppercase' | but uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | doesn't amount to that much more typing, and | | >>> from string import uppercase | >>> len(uppercase) == 26 | 0 | >>> len(uppercase) | 56 | | ...could prove The Wrong Thing. Maybe. Are you using some interesting locales or something? Here: Python 2.0 (#18, Oct 31 2000, 13:55:49) [C] on sunos5 Type "copyright", "credits" or "license" for more information. >>> import string >>> len( string.uppercase ) 26 >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ >>> -D From tescoil@irtc.net Tue Mar 13 03:26:06 2001 From: tescoil@irtc.net (Tesla Coil) Date: Mon, 12 Mar 2001 22:26:06 -0500 Subject: [Tutor] filtering within a function. References: <3AAD0308.C9C1EE61@irtc.net> <20010312233750.A10865@pino.selwerd.nl> <3AAD55A0.8C52C5FC@irtc.net> <20010312215435.A8276@harmony.cs.rit.edu> Message-ID: <3AAD934E.EC0D2F3B@irtc.net> On 12 Mar 2001, D-Man replied: > Maybe. Are you using some interesting locales or something? > > Here: > > Python 2.0 (#18, Oct 31 2000, 13:55:49) [C] on sunos5 > Type "copyright", "credits" or "license" for more information. > >>> import string > >>> len( string.uppercase ) > 26 > >>> print string.uppercase > ABCDEFGHIJKLMNOPQRSTUVWXYZ > >>> Hmmm... Python 2.0 (#1, Oct 16 2000, 18:10:03)=20 [GCC 2.95.2 19991024 (release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import string, sys >>> len(string.uppercase) 56 >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ=C0=C1=C2=C3=C4=C5=C6=C7=C8=C9=CA=CB=CC=CD=CE=CF= =D0=D1=D2=D3=D4=D5=D6=D8=D9=DA=DB=DC=DD=DE >>> sys.path ['', '/mnt/usr/local/lib/python2.0', '/mnt/usr/local/lib/python2.0/plat-linux2', '/mnt/usr/local/lib/python2.0/lib-tk', '/mnt/usr/local/lib/python2.0/lib-dynload', '/mnt/usr/local/lib/python2.0/site-packages', '/mnt/usr/local/lib/python2.0/site-packages/PIL'] >>>=20 Python 1.5.2 (#1, Aug 25 2000, 09:33:37) =20 [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import string, sys >>> len(string.uppercase ... ) 56 >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ=C0=C1=C2=C3=C4=C5=C6=C7=C8=C9=CA=CB=CC=CD=CE=CF= =D0=D1=D2=D3=D4=D5=D6=D8=D9=DA=DB=DC=DD=DE >>> sys.path ['', '/usr/lib/python1.5/', '/usr/lib/python1.5/plat-linux-i386',=20 '/usr/lib/python1.5/lib-tk', '/usr/lib/python1.5/lib-dynload', '/usr/lib/python1.5/site-packages'] From van@lindbergs.org Tue Mar 13 07:18:07 2001 From: van@lindbergs.org (VanL) Date: Tue, 13 Mar 2001 00:18:07 -0700 Subject: [Tutor] Help with lists Message-ID: <3AADC9AF.BA9B3924@lindbergs.org> Hello, I'm stuck on what is probably a simple problem, but I can't figure out how to solve it. I am reading through some log files, and testing for some error conditions. The log files are formatted this way: (begin) Here is some header text, explaining the warning. This is several lines long. Each header has something that is unique. Here is an error message. Here is error message number 2. Here is error message number 3. Here is error message n. Here is the beginning of the next header.... (end) Notice the blank lines before and after the error block. Now I am opening these files up and feeding them to this function: def filter(logfile): thisfile = logfile.readlines() # Test for trigger strings -- these indicate the presence of a specific # warning block. The number after the string is the number of lines # from the trigger line to the first blank line (before the block of error # messages) test1 = 'Here is some header text, explaining the warning', 2 test2 = 'some other trigger text in header two', 3 for line in thisfile: # Get the results.... result1 = string.find(line, test1[0]) result2 = string.find(line, test2[0]) # For each positive result, parse the error block to see what # really went wrong. if (result1 != -1): blockindex1 = (thisfile.index(line) + test1[1]) if (find_bad_errors(logfile, blockindex1)): return (0) if (result2 != -1): blockindex2 = (thisfile.index(line) + test2[1]) if (find_bad_errors(logfile, blockindex1)): return (0) else: return (1) Now, find_bad_errors goes like this: def find_bad_errors(logfile, start): print "In function find_bad_errors" # start denotes the index of the blank line at the top of the error block. # I want to search through each line, beginning at the index of the top of the # error block. If I find another blank line without encountering a really bad # error, I'm done. block = logfile.readlines() blockstart = start for line in (block[(blockstart + 1):]): print "In for loop" if ((line == thisblock[startblock]) or (re.match('^\s+$', line))): print "All done, no errors." return (0) if re.search('(notbad1|notbad2|notbad3|notbad4)', line): print line , 'Matched an error, but nothing to worry about' continue else: print "I encountered a really bad error. Fail" return (1) Now, here are my problems: 1. I never seem to be going into the for loop. The top print statement ("In function find_bad_errors") always prints but the second ("In for loop") never does. 2. If I rewrite the code so that it is forced to go through the tests, I always fail because each line is getting split up into 1-character strings. For example, you see that I test for "notbad1". I never find it, though, because all I see when I print is " n o t b a d 1 " Could anybody help me? Thanks, Van From alan.gauld@bt.com Tue Mar 13 10:26:48 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 13 Mar 2001 10:26:48 -0000 Subject: [Tutor] how do i link up the file and the interpreter? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D629@mbtlipnt02.btlabs.bt.co.uk> > windows] but since i'm on the net most of the time i use > windows.so right now i'm using active python to run the code OK, Thats probably a wise choice for Windows. > and at the same time include a module file 'test.py'.can i set a path > env in active python to link to my testfiles dir? Yes, use the PYTHONPATH env var with the same syntax as the DOS PATH variable. (The same applies in Unix BTW just use the shell PATH variable syntax...) > i tried but the edit path doesnt seem to work. Within Pythonwin IDE changes to the path should be reflected in the registry and be persistent... > Also i tried to run the python cmd from the dos prompt but bad > cmd or filename.i recall i should be adding a path env statement in > autoexec.bat Correct, although the CNRI installer seems to do that by default the new BeOpen one doesn't - for shame!. Presumably Active Python follows the BeOpen route - for greater shame, since its supposed to be Windoze friendly! Alan g From arcege@shore.net Tue Mar 13 12:08:59 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 13 Mar 2001 07:08:59 -0500 (EST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD934E.EC0D2F3B@irtc.net> from Tesla Coil at "Mar 12, 2001 10:26: 6 pm" Message-ID: <E14cnbn-00067T-00@nautilus.shore.net> [Charset iso-8859-1 unsupported, filtering to ASCII...] > On 12 Mar 2001, D-Man replied: > > Maybe. Are you using some interesting locales or something? > > > > Here: > > > > Python 2.0 (#18, Oct 31 2000, 13:55:49) [C] on sunos5 > > Type "copyright", "credits" or "license" for more information. > > >>> import string > > >>> len( string.uppercase ) > > 26 > > >>> print string.uppercase > > ABCDEFGHIJKLMNOPQRSTUVWXYZ > > >>> > > Hmmm... > > Python 2.0 (#1, Oct 16 2000, 18:10:03) > [GCC 2.95.2 19991024 (release)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import string, sys > >>> len(string.uppercase) > 56 > >>> print string.uppercase > ABCDEFGHIJKLMNOPQRSTUVWXYZ______________________________ > >>> sys.path > ['', '/mnt/usr/local/lib/python2.0', > '/mnt/usr/local/lib/python2.0/plat-linux2', > '/mnt/usr/local/lib/python2.0/lib-tk', > '/mnt/usr/local/lib/python2.0/lib-dynload', > '/mnt/usr/local/lib/python2.0/site-packages', > '/mnt/usr/local/lib/python2.0/site-packages/PIL'] > >>> > > > Python 1.5.2 (#1, Aug 25 2000, 09:33:37) > [GCC 2.96 20000731 (experimental)] on linux-i386 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> import string, sys > >>> len(string.uppercase > ... ) > 56 > >>> print string.uppercase > ABCDEFGHIJKLMNOPQRSTUVWXYZ______________________________ > >>> sys.path > ['', '/usr/lib/python1.5/', > '/usr/lib/python1.5/plat-linux-i386', > '/usr/lib/python1.5/lib-tk', > '/usr/lib/python1.5/lib-dynload', > '/usr/lib/python1.5/site-packages'] The first element in the path is important.. what is the file being imported? >>> print string.__file__ ?? It could be from a more local file. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Tue Mar 13 12:34:22 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 13 Mar 2001 07:34:22 -0500 (EST) Subject: [Tutor] filtering within a function. In-Reply-To: <3AAD934E.EC0D2F3B@irtc.net> from Tesla Coil at "Mar 12, 2001 10:26: 6 pm" Message-ID: <E14co0M-0001it-00@nautilus.shore.net> [Charset iso-8859-1 unsupported, filtering to ASCII...] > On 12 Mar 2001, D-Man replied: > > Maybe. Are you using some interesting locales or something? > > > > Here: > > > > Python 2.0 (#18, Oct 31 2000, 13:55:49) [C] on sunos5 > > Type "copyright", "credits" or "license" for more information. > > >>> import string > > >>> len( string.uppercase ) > > 26 > > >>> print string.uppercase > > ABCDEFGHIJKLMNOPQRSTUVWXYZ > > >>> Actually, looking deeper, yes, it is a locale issue. strop.uppercase, which replaces string.uppercase, is built using isupper(3) which does use locale(7) settings on most systems. This is looking at Python 2.0; I'm fairly sure that Modules/stropmodule.c didn't change much from 1.5.2. It looks like the best bet is to build your own value if you want just the ASCII characters. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From douglas.shawhan@ae.ge.com Tue Mar 13 18:38:49 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Tue, 13 Mar 2001 13:38:49 -0500 Subject: [Tutor] Signals Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F2540@ma001dataaege.ae.ge.com> Where is a good tutorial for signals? I have a need to parse data from an ISA bus board to a database. (gaze in wide-eyed wonder as he once agains bites off more than he can chew....) d From gwperry@tva.gov Tue Mar 13 19:09:18 2001 From: gwperry@tva.gov (Perry, George W.) Date: Tue, 13 Mar 2001 14:09:18 -0500 Subject: [Tutor] Reading Entire File Message-ID: <DF936EB98CCBD4118EC500508BCFE69A0C0998@tvachaxch1.cha.tva.gov> I want to read the entire contents of a file into a string and then compute the CRC using crc32() in module zlib. I am using the file method read() to read the file. It works as expected for text files, but for Microsoft Excel and Word files, it only reads a few characters. How can I read the entire file? I have Windogs 95 and Python 2.0. George Perry From scarblac@pino.selwerd.nl Tue Mar 13 19:18:48 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 13 Mar 2001 20:18:48 +0100 Subject: [Tutor] Reading Entire File In-Reply-To: <DF936EB98CCBD4118EC500508BCFE69A0C0998@tvachaxch1.cha.tva.gov>; from gwperry@tva.gov on Tue, Mar 13, 2001 at 02:09:18PM -0500 References: <DF936EB98CCBD4118EC500508BCFE69A0C0998@tvachaxch1.cha.tva.gov> Message-ID: <20010313201848.A146@pino.selwerd.nl> On Tue, Mar 13, 2001 at 02:09:18PM -0500, Perry, George W. wrote: > I want to read the entire contents of a file into a string and then compute > the CRC using crc32() in module zlib. I am using the file method read() to > read the file. It works as expected for text files, but for Microsoft Excel > and Word files, it only reads a few characters. > How can I read the entire file? > > I have Windogs 95 and Python 2.0. Open the file as binary, ie using open("filename","rb") The default is to open in ASCII mode, and then a certain code counts as end of file, so that reading the file stops the first time that code occurs. -- Remco Gerlich From dsh8290@rit.edu Tue Mar 13 19:46:51 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 13 Mar 2001 14:46:51 -0500 Subject: [Tutor] Signals In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F2540@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Tue, Mar 13, 2001 at 01:38:49PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F2540@ma001dataaege.ae.ge.com> Message-ID: <20010313144651.A10619@harmony.cs.rit.edu> On Tue, Mar 13, 2001 at 01:38:49PM -0500, Shawhan, Douglas (GEAE, GECC) wrote: | Where is a good tutorial for signals? I have a need to parse data from an | ISA bus board to a database. (gaze in wide-eyed wonder as he once agains | bites off more than he can chew....) Not a tutorial, but 'man signal' may give you a starting point. I imagine that Python's signal module closely matches the C library. Also try loading the signal library and browsing it (in an interactive session). The Ref Man should also give a brief description of the API. HTH, -D From dsh8290@rit.edu Tue Mar 13 20:16:17 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 13 Mar 2001 15:16:17 -0500 Subject: [Tutor] Help with lists In-Reply-To: <3AADC9AF.BA9B3924@lindbergs.org>; from van@lindbergs.org on Tue, Mar 13, 2001 at 12:18:07AM -0700 References: <3AADC9AF.BA9B3924@lindbergs.org> Message-ID: <20010313151617.B10619@harmony.cs.rit.edu> On Tue, Mar 13, 2001 at 12:18:07AM -0700, VanL wrote: | Hello, | | I'm stuck on what is probably a simple problem, but I can't figure | out how to solve it. | | I am reading through some log files, and testing for some error | conditions. The log files are formatted this way: | (begin) | | Here is some header text, explaining the warning. This is several | lines long. Each header has something that is unique. | | Here is an error message. | Here is error message number 2. | Here is error message number 3. | Here is error message n. | | Here is the beginning of the next header.... | (end) | | Notice the blank lines before and after the error block. | | Now I am opening these files up and feeding them to this function: | | def filter(logfile): | thisfile = logfile.readlines() I assume that 'logfile' is a file object. After the above line, the current location in the file is the end. Any more reads will fail, unless seek() is used to reposition the cursor. | | # Test for trigger strings -- these indicate the presence of | # a specific warning block. The number after the string | # is the number of lines from the trigger line to the | # first blank line (before the block of error messages) | | test1 = ( 'Here is some header text, explaining the warning', 2 ) | test2 = ( 'some other trigger text in header two', 3 ) What are the integer constants in the tuple representing? Are they correct? | | for line in thisfile: | | # Get the results.... | result1 = string.find(line, test1[0]) | result2 = string.find(line, test2[0]) | | # For each positive result, parse the error block to | # see what really went wrong. | | if (result1 != -1): | blockindex1 = (thisfile.index(line) + test1[1]) | if (find_bad_errors(logfile, blockindex1)): Now you are giving the file object 'logfile' to find_bad_errors(), but the cursor is at the end. | return (0) | | if (result2 != -1): | blockindex2 = (thisfile.index(line) + test2[1]) | if (find_bad_errors(logfile, blockindex1)): ^ This should probably be a 2. Same as above also. | return 0 | else: | return 1 | | | def find_bad_errors(logfile, start): | | print "In function find_bad_errors" | | # start denotes the index of the blank line at the top of | # the error block. I want to search through each line, | # beginning at the index of the top of the error block. | # If I find another blank line without encountering a really | # bad error, I'm done. | | block = logfile.readlines() This will return [], the empty list since 'logfile' is at the end. | blockstart = start | for line in (block[(blockstart + 1):]): The outer parens are unneccessary for delimiting the expression. Without them the expression is block[(blockstart + 1):] You are slicing an empty list from (blockstart + 1) to the end. This gives the empty list back. So the loop is (psuedo code) for line in nothing : do something or in other words never : do something | Now, here are my problems: | | 1. I never seem to be going into the for loop. The top print | statement ("In function find_bad_errors") always prints but the | second ("In for loop") never does. As explained above, you are iterating over an empty list, which means the loop body never executes. I would suggest handing only the list of strings that is necessary to the find_bad_errors function. Do the slicing in the caller, who already has the list. It would be much slower to have it read through the file again. It would also duplicate the memory used since there would be two copies of the file in memory. Most importantly, though, it makes the code harder to understand since the function doesn't really need to read the file, it only needs the list of strings from it. | 2. If I rewrite the code so that it is forced to go through the | tests, I always fail because each line is getting split up into | 1-character strings. For example, you see that I test for | "notbad1". I never find it, though, because all I see when I print | is | " | n | o | t | b | a | d | 1 | | " print "f" print "o" print "o" will give f o o for output. If instead I write print "f", print "o", print "o", I will get f o o for output print will put a newline after whatever it prints by default. If you put a comma after it, it doesn't print the newline, but it stil puts a space in trying to be extra helpful. If you don't want either situation, build up a string in a local variable and print it when the string is complete. I don't know how you got the second situation since you haven't shared your rewrite that gets into the loop. Try fixing the first problem, and the second may go away. HTH, -D From W.W.vandenBroek Tue Mar 13 20:30:40 2001 From: W.W.vandenBroek (W.W.vandenBroek) Date: Tue, 13 Mar 2001 21:30:40 +0100 Subject: [Tutor] boolean or input trouble Message-ID: <01031321304000.05228@vdbroekw> Sorry newbie here, i am trying to make a program usefull for diagnostic clinical purposes. The quetinair has several questions, the naswer to two questions are obligatiry for a dianosis, need input the two scores of the quetions, wrote the next program (it is dutch) cannot get the answer to the second question. Wath am i missing, should i make a list, seems strange for such a simple program #! /usr/bin/python #We gaan is de twee hoofdkenmerken van een dsm depressie diagnose vaststellen x = input ("Welk getal is het antwoord op vraag 234 van de SADS?") y = input ("Welk getal is het antwoord op vraag 326 van de SADS?") if (x > 4) or (y > 4): print " Er kan sprake zijn van een depressieve stoornis" else: print " Er kan geen sprake zijn van een depressie" Thanks walter -- W.W. van den Broek e-mail: vandenbroek@psyd.azr.nl AZR-Dijkzigt fax: 010-4633217 afdeling psychiatrie tel: 010-4639222 Postbus 2040 e-mail vdbroekw@wxs.nl (thuis) 3000 CA Rotterdam homepage: http://home.planet.nl/~vdbroekw From shaleh@valinux.com Tue Mar 13 21:09:18 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 13 Mar 2001 13:09:18 -0800 Subject: [Tutor] boolean or input trouble In-Reply-To: <01031321304000.05228@vdbroekw>; from vdbroekw@wxs.nl on Tue, Mar 13, 2001 at 09:30:40PM +0100 References: <01031321304000.05228@vdbroekw> Message-ID: <20010313130918.C8009@valinux.com> On Tue, Mar 13, 2001 at 09:30:40PM +0100, W.W. van den Broek wrote: > Sorry newbie here, i am trying to make a program usefull for diagnostic > clinical purposes. The quetinair has several questions, the naswer to two > questions are obligatiry for a dianosis, need input the two scores of the > quetions, wrote the next program (it is dutch) cannot get the answer to the > second question. Wath am i missing, should i make a list, seems strange for > such a simple program > #! /usr/bin/python > #We gaan is de twee hoofdkenmerken van een dsm depressie diagnose vaststellen > x = input ("Welk getal is het antwoord op vraag 234 van de SADS?") > y = input ("Welk getal is het antwoord op vraag 326 van de SADS?") > if (x > 4) or (y > 4): > print " Er kan sprake zijn van een depressieve stoornis" > else: > print " Er kan geen sprake zijn van een depressie" > the example as you typed it works here: $ python ./foo.py Welk getal is het antwoord op vraag 234 van de SADS?10 Welk getal is het antwoord op vraag 326 van de SADS?2 Er kan sprake zijn van een depressieve stoornis $ python ./foo.py Welk getal is het antwoord op vraag 234 van de SADS?3 Welk getal is het antwoord op vraag 326 van de SADS?3 Er kan geen sprake zijn van een depressie From shaleh@valinux.com Tue Mar 13 21:17:18 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 13 Mar 2001 13:17:18 -0800 Subject: [Tutor] pipes, lots of 'em Message-ID: <20010313131718.D8009@valinux.com> So I am writing this program and I need to run several programs from within it and read their output something like: foo | bar | baz # I want the output of baz. I do not necessarily know how many programs will be run at once in this way. I know about os.popen(), but is the best approach really: command = '%s | %s' % (one, two) # assuming only two commands (common case) os.popen(command) if I could somehow manipulate tar and ar files directly in python, I would not really need this. From arcege@shore.net Tue Mar 13 22:01:30 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 13 Mar 2001 17:01:30 -0500 (EST) Subject: [Tutor] Reading Entire File In-Reply-To: <DF936EB98CCBD4118EC500508BCFE69A0C0998@tvachaxch1.cha.tva.gov> from "Perry, George W." at "Mar 13, 2001 2: 9:18 pm" Message-ID: <E14cwrD-00058O-00@nautilus.shore.net> > I want to read the entire contents of a file into a string and then compute > the CRC using crc32() in module zlib. I am using the file method read() to > read the file. It works as expected for text files, but for Microsoft Excel > and Word files, it only reads a few characters. > How can I read the entire file? > > I have Windogs 95 and Python 2.0. You should be able to read blocks at a time instead of the whole file. If, for example, the file was 10 meg, then you'd have to have that much memory to hold the file; it would be more efficient to read in bits and perform the crc checks on that. >>> import zlib >>> f = open('foo.dat', 'rb') >>> whole_contents = f.read() >>> crc_on_whole = zlib.crc32(whole_contents) >>> f.seek(0) # rewind to the beginning of the file >>> block = f.read(8192) >>> crc_by_block = 0 >>> while block: ... crc_by_block = zlib.crc32(block, crc_by_block) ... block = f.read(8192) ... >>> crc_on_whole == crc_by_block 1 >>> crc_on_whole, crc_by_block (395051047, 395051047) For CRC checks, you should always be working with the binary formats to get all characters (that would be transmitted, if for that purpose). Good luck, -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From blitz@escaped.net Tue Mar 13 19:52:51 2001 From: blitz@escaped.net (Blitz) Date: Tue, 13 Mar 2001 16:52:51 -0300 Subject: [Tutor] Possible error on 2.1b1 Message-ID: <3AAE7A93.E32C729A@mindspring.com> Hi, I have tried this example from the Tutorial and I get different results. This is from the tutorial: >>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... print n, 'is a prime number' ... 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3 This is my code, the same statements from the tutorial, but different results: Python 2.1b1 (#11, Mar 2 2001, 11:23:29) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.6 -- press F1 for help >>> for n in range(2, 10): for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: print n, 'is a prime number' 3 is a prime number 4 equals 2 * 2 5 is a prime number 5 is a prime number 5 is a prime number 6 equals 2 * 3 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 8 equals 2 * 4 9 is a prime number 9 equals 3 * 3 Do you know why this happens? Note that I used Python 2.1b1 for Windows. Thank you! A. Demetrio Jr. From dsh8290@rit.edu Tue Mar 13 23:34:34 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 13 Mar 2001 18:34:34 -0500 Subject: [Tutor] Possible error on 2.1b1 In-Reply-To: <3AAE7A93.E32C729A@mindspring.com>; from blitz@escaped.net on Tue, Mar 13, 2001 at 04:52:51PM -0300 References: <3AAE7A93.E32C729A@mindspring.com> Message-ID: <20010313183433.B10847@harmony.cs.rit.edu> On Tue, Mar 13, 2001 at 04:52:51PM -0300, Blitz wrote: | Hi, I have tried this example from the Tutorial and I get different | results. This is from the tutorial: | | >>> for n in range(2, 10): | ... for x in range(2, n): | ... if n % x == 0: | ... print n, 'equals', x, '*', n/x | ... break | ... else: ^^^^^ Note the indentation level. | This is my code, the same statements from the tutorial, but different | results: | | Python 2.1b1 (#11, Mar 2 2001, 11:23:29) [MSC 32 bit (Intel)] on win32 | Type "copyright", "credits" or "license" for more information. | IDLE 0.6 -- press F1 for help | >>> for n in range(2, 10): | for x in range(2, n): | if n % x == 0: | print n, 'equals', x, '*', n/x | break | else: ^^^^^^^^ Note this indentation level. | print n, 'is a prime number' | | | 3 is a prime number | 4 equals 2 * 2 | 5 is a prime number | 5 is a prime number | 5 is a prime number | 6 equals 2 * 3 | 7 is a prime number | 7 is a prime number | 7 is a prime number | 7 is a prime number | 7 is a prime number | 8 equals 2 * 4 | 9 is a prime number | 9 equals 3 * 3 | | Do you know why this happens? Note that I used Python 2.1b1 for Windows. Your "print n is a prime number" statement is inside the loop that checks for a divisor. Thus, every time a particular divisor fails, you print "n is a prime number" rather than waiting until after all potential divisors have been tried. The "else" on a "for" statement is a bit weird, but read the docs closely as to its semantics and try to see why it is useful here. I must admit that I am not very familiar/comfortable with "else" clauses on loops, but that is largely because no other language that I know supports such a construct. -D From dsh8290@rit.edu Wed Mar 14 00:10:02 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 13 Mar 2001 19:10:02 -0500 Subject: [Tutor] boolean or input trouble In-Reply-To: <01031321304000.05228@vdbroekw>; from vdbroekw@wxs.nl on Tue, Mar 13, 2001 at 09:30:40PM +0100 References: <01031321304000.05228@vdbroekw> Message-ID: <20010313191002.A10975@harmony.cs.rit.edu> On Tue, Mar 13, 2001 at 09:30:40PM +0100, W.W. van den Broek wrote: | #! /usr/bin/python | #We gaan is de twee hoofdkenmerken van een dsm depressie diagnose vaststellen | x = input ("Welk getal is het antwoord op vraag 234 van de SADS?") | y = input ("Welk getal is het antwoord op vraag 326 van de SADS?") | if (x > 4) or (y > 4): | print " Er kan sprake zijn van een depressieve stoornis" | else: | print " Er kan geen sprake zijn van een depressie" | The only obvious problem I notice is that you use 'input'. Also there is no try-except block wrapping the input. Suppose I were to type in 'a'? Or 'open( "some_file_to_trash" , "w" )" ? Both would cause the input function to either fail, or do some unexpected bad things. Try this instead: #!/usr/bin/env python good_input = 0 while not good_input : try : x = int( raw_input( "Welk ..." ) ) good_input = 1 except ValueError , error : print "You didn't enter a valid number, please enter a valid number" good_input = 0 while not good_input : try : y = int( raw_input( "Welk ..." ) ) good_input = 1 except ValueError , error : print "You didn't enter a valid number, please enter a valid number" if (x > 4) or (y > 4): print " Er kan sprake zijn van een depressieve stoornis" else: print " Er kan geen sprake zijn van een depressie" Using raw_input will prevent the interpreter from executing arbitrary (and possibly harmful!) expressions. Using int() to convert the string to an integer inside the try-except blocks will allow you to robustly handle any weird data the users may throw at your program. HTH, -D From paulnsharon@dingoblue.net.au Wed Mar 14 03:11:11 2001 From: paulnsharon@dingoblue.net.au (Paul Jones) Date: Wed, 14 Mar 2001 13:11:11 +1000 Subject: [Tutor] backwords program Message-ID: <002c01c0ac34$6efb1740$e1c21dcb@barney> This is a multi-part message in MIME format. ------=_NextPart_000_0029_01C0AC88.3DDE9160 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks for the replies- I've just had a chance to look at them. Paul Jones email: paulnsharon@dingoblue.net.au ------=_NextPart_000_0029_01C0AC88.3DDE9160 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Thanks for the replies- I've just had a = chance to=20 look at them.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Paul Jones<BR>email: <A=20 href=3D"mailto:paulnsharon@dingoblue.net.au">paulnsharon@dingoblue.net.au= </A></FONT></DIV></BODY></HTML> ------=_NextPart_000_0029_01C0AC88.3DDE9160-- From tbrauch@mindless.com Wed Mar 14 04:21:47 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Tue, 13 Mar 2001 23:21:47 -0500 Subject: [Tutor] File Attributes Message-ID: <3AAEF1DB.25764EFE@mindless.com> I know that os.stat(fd) will return a tuple of integers about a file. Two of the numbers are the date it was accessed last and last modification. Is there a way to find out when a file was created? - Tim From margaret@retriever.com.au Wed Mar 14 04:22:09 2001 From: margaret@retriever.com.au (Margaret Brierton) Date: Wed, 14 Mar 2001 15:22:09 +1100 Subject: [Tutor] constructors Message-ID: <3AAEF1F0.2D44F633@retriever.com.au> Hi I'm another new one to python. I seem to be having a problem with class constructors. My program is tiny and consists of the following code: #! /usr/bin/env python class ConnectInfo: def _init_(self, accname): self.accname=accname def main(): connect = ConnectInfo("me") print connect.accname main() when i run the above program i get the following error message: Traceback (innermost last): File "test.sh", line 15, in ? main() File "test.sh", line 11, in main connect = ConnectInfo("me") Can someone please enlightened me! Cheers From kauphlyn@speakeasy.org Wed Mar 14 04:46:42 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Tue, 13 Mar 2001 20:46:42 -0800 (PST) Subject: [Tutor] constructors In-Reply-To: <3AAEF1F0.2D44F633@retriever.com.au> Message-ID: <Pine.LNX.4.21.0103132039430.22335-100000@grace.speakeasy.org> On Wed, 14 Mar 2001, Margaret Brierton wrote: > Hi I'm another new one to python. > > I seem to be having a problem with class constructors. My program is > tiny and consists of the following code: > > #! /usr/bin/env python > > class ConnectInfo: > def _init_(self, accname): ^^ ^^ the __init__ method takes two underscores in front and in back. it should work then. From lumbricus@gmx.net Wed Mar 14 05:09:45 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Wed, 14 Mar 2001 06:09:45 +0100 (MET) Subject: [Tutor] File Attributes References: <3AAEF1DB.25764EFE@mindless.com> Message-ID: <32365.984546585@www29.gmx.net> > I know that os.stat(fd) will return a tuple of integers about a file. > Two of the numbers are the date it was accessed last and last > modification. Is there a way to find out when a file was created? > > - Tim > Files don't celebrate Birthdays (never ever) -- it isn't stored anywhere It wouldn't make sense anyway. What birthday has the source of your kernel? Is a copy a new file ... > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From jcm@bigskytel.com Wed Mar 14 06:16:37 2001 From: jcm@bigskytel.com (David Porter) Date: Tue, 13 Mar 2001 23:16:37 -0700 Subject: [Tutor] File Attributes In-Reply-To: <3AAEF1DB.25764EFE@mindless.com>; from tbrauch@mindless.com on Tue, Mar 13, 2001 at 11:21:47PM -0500 References: <3AAEF1DB.25764EFE@mindless.com> Message-ID: <20010313231637.A26670@bigskytel.com> * Timothy M. Brauch <tbrauch@mindless.com>: > I know that os.stat(fd) will return a tuple of integers about a file. > Two of the numbers are the date it was accessed last and last > modification. Is there a way to find out when a file was created? Look closer. Items 7, 8, and 9 in the tuple are atime, mtime, and ctime respectively: os.stat(filename)[9] David From dyoo@hkn.eecs.berkeley.edu Wed Mar 14 06:31:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 13 Mar 2001 22:31:33 -0800 (PST) Subject: [Tutor] constructors In-Reply-To: <3AAEF1F0.2D44F633@retriever.com.au> Message-ID: <Pine.LNX.4.21.0103132230060.20579-100000@hkn.eecs.berkeley.edu> On Wed, 14 Mar 2001, Margaret Brierton wrote: > Hi I'm another new one to python. > > I seem to be having a problem with class constructors. My program is > tiny and consists of the following code: > > #! /usr/bin/env python > > class ConnectInfo: > def _init_(self, accname): > self.accname=accname More underscores. *grin* ### class ConnectInfo: def __init__(self, accname): self.accname = accname ### This goes for all of the special methods that classes can override: http://python.org/doc/current/ref/specialnames.html Good luck to you. From dyoo@hkn.eecs.berkeley.edu Wed Mar 14 06:39:44 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 13 Mar 2001 22:39:44 -0800 (PST) Subject: [Tutor] pipes, lots of 'em In-Reply-To: <20010313131718.D8009@valinux.com> Message-ID: <Pine.LNX.4.21.0103132236430.20579-100000@hkn.eecs.berkeley.edu> On Tue, 13 Mar 2001, Sean 'Shaleh' Perry wrote: > So I am writing this program and I need to run several programs from within it > and read their output something like: > > foo | bar | baz # I want the output of baz. > > I do not necessarily know how many programs will be run at once in this way. > > I know about os.popen(), but is the best approach really: > > command = '%s | %s' % (one, two) # assuming only two commands (common case) > os.popen(command) > > if I could somehow manipulate tar and ar files directly in python, I would not > really need this. Hmmm... don't know about the pipes thing, but I did find a module that will let you read tar archives: http://www.faqts.com/knowledge_base/view.phtml/aid/4395 Haven't played around with it yet though. I'm very surprised not to easily find a full tar program for Python though; perhaps someone else can verify this? From britt_green@hotmail.com Wed Mar 14 07:13:06 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 13 Mar 2001 23:13:06 -0800 Subject: [Tutor] Re: Tutor digest, Vol 1 #659 - 15 msgs Message-ID: <F78ZgzDgtZKpjE5aHaZ00001c7d@hotmail.com> <html><DIV></DIV>>Message: 15 <DIV></DIV>>Date: Wed, 14 Mar 2001 15:22:09 +1100 <DIV></DIV>>From: Margaret Brierton <MARGARET@RETRIEVER.COM.AU> <DIV></DIV>>Organization: Retriever Communications <DIV></DIV>>To: tutor@python.org <DIV></DIV>>Subject: [Tutor] constructors <DIV></DIV>> <DIV></DIV>>Hi I'm another new one to python. <DIV></DIV>> <DIV></DIV>>I seem to be having a problem with class constructors. My program is <DIV></DIV>>tiny and consists of the following code: <DIV></DIV>> <DIV></DIV>>#! /usr/bin/env python <DIV></DIV>> <DIV></DIV>>class ConnectInfo: <DIV></DIV>> def _init_(self, accname): <DIV></DIV>> self.accname=accname <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>def main(): <DIV></DIV>> connect = ConnectInfo("me") <DIV></DIV>> print connect.accname <DIV></DIV>> <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>main() <DIV></DIV>> <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>when i run the above program i get the following error message: <DIV></DIV>> <DIV></DIV>>Traceback (innermost last): <DIV></DIV>> File "test.sh", line 15, in ? <DIV></DIV>> main() <DIV></DIV>> File "test.sh", line 11, in main <DIV></DIV>> connect = ConnectInfo("me") <DIV></DIV> <DIV> </DIV> <DIV>Althought its hard to tell, I think you're not putting *two* underscore characters around the constructor. Try changing it to:</DIV> <DIV> </DIV> <DIV>class ConnectInfo: <DIV></DIV> def __init__(self, accname): <DIV></DIV> self.accname=accname </DIV> <DIV> </DIV> <DIV>See if that works!</DIV> <DIV> </DIV> <DIV>Britt</DIV><br clear=all><hr>Get your FREE download of MSN Explorer at <a href="http://explorer.msn.com">http://explorer.msn.com</a><br></p></html> From shaleh@valinux.com Wed Mar 14 07:35:24 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 13 Mar 2001 23:35:24 -0800 Subject: [Tutor] pipes, lots of 'em In-Reply-To: <Pine.LNX.4.21.0103132236430.20579-100000@hkn.eecs.berkeley.edu>; from dyoo@hkn.eecs.berkeley.edu on Tue, Mar 13, 2001 at 10:39:44PM -0800 References: <20010313131718.D8009@valinux.com> <Pine.LNX.4.21.0103132236430.20579-100000@hkn.eecs.berkeley.edu> Message-ID: <20010313233524.A8131@valinux.com> On Tue, Mar 13, 2001 at 10:39:44PM -0800, Daniel Yoo wrote: > > Hmmm... don't know about the pipes thing, but I did find a module that > will let you read tar archives: > > http://www.faqts.com/knowledge_base/view.phtml/aid/4395 > > Haven't played around with it yet though. > > I'm very surprised not to easily find a full tar program for Python > though; perhaps someone else can verify this? I am not surprised, there are no C libs either. tar seems to only be spoken by tar. But even if I had a tar module, I also need ar support. So, I am still dealing with pipes. ar p foo.ar bar|tar xfO - baz is the basic command line I need. This get bar out of the ar formatted foo.ar and sends it to tar which extracts baz. I want to be able to parse baz without it getting written to disk. My attempts at this have failed for the most part. From lumbricus@gmx.net Wed Mar 14 10:28:39 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Wed, 14 Mar 2001 11:28:39 +0100 (MET) Subject: [Tutor] File Attributes References: <20010313231637.A26670@bigskytel.com> Message-ID: <14966.984565719@www23.gmx.net> > * Timothy M. Brauch <tbrauch@mindless.com>: > > I know that os.stat(fd) will return a tuple of integers about a file. > > Two of the numbers are the date it was accessed last and last > > modification. Is there a way to find out when a file was created? > > Look closer. Items 7, 8, and 9 in the tuple are atime, mtime, and ctime > respectively: > > os.stat(filename)[9] > Hello!!! (don't have python here so looking into my c-tutorial) time_t st_atime when the file was last accessed time_t st_mtime when the file was last modified (created or written to) time_t st_ctime when the file was last changed (permissions or book-keeping, NOT contents change) Again: (Unix) FILES HAVE NO BIRTHDAY Greetings!!! > > David > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From alan.gauld@bt.com Wed Mar 14 10:26:16 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 14 Mar 2001 10:26:16 -0000 Subject: [Tutor] Signals Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D635@mbtlipnt02.btlabs.bt.co.uk> > Where is a good tutorial for signals? Let's first confirm what you mean by 'signals'. Which OS? - I normally associate signals with *nix and its signal() system call, but you might be meaning the more general meaning of catching interrupts or some other kind of 'signal' from hardware... > I have a need to parse data from an ISA bus > board to a database. So the hardware raises an interrupt which is translated into a *nix signal? You then want to read from the hardware (via an IO port?) and store the parsed data in a database? If so, then the best place to start is at the low level C signal call and the hardware vendors specs for reading the IO port... Alternatively if you have the excellent O'Reilly book "Unix Systems Programming" look it up in there. If that's a wrong interpretation of your request please clarify and ask about the specific thing you need help with. Alan G. From alan.gauld@bt.com Wed Mar 14 10:38:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 14 Mar 2001 10:38:29 -0000 Subject: [Tutor] constructors Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D636@mbtlipnt02.btlabs.bt.co.uk> > class ConnectInfo: > def _init_(self, accname): > self.accname=accname init() should have two underscores each side. That's a common Python convention for special methods like init ie def __init__(self, accname):... > Traceback (innermost last): > File "test.sh", line 15, in ? > main() > File "test.sh", line 11, in main > connect = ConnectInfo("me") Hmm, there should have been another line giving the actual error message - usually the most important bit! Are you sure thats all it said? Alan g. From dyoo@hkn.eecs.berkeley.edu Wed Mar 14 13:59:23 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 14 Mar 2001 05:59:23 -0800 (PST) Subject: [Tutor] Help with lists In-Reply-To: <3AADC9AF.BA9B3924@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103140547010.31530-100000@hkn.eecs.berkeley.edu> Dear VanL, Apologies for not responding more quickly to your message. Let's take a look at your program! On Tue, 13 Mar 2001, VanL wrote: > def filter(logfile): > thisfile = logfile.readlines() [lots of code cut] > > Now, find_bad_errors goes like this: > > def find_bad_errors(logfile, start): > block = logfile.readlines() [lots of code cut] > 1. I never seem to be going into the for loop. The top print > statement ("In function find_bad_errors") always prints but the > second ("In for loop") never does. Which for loop do you mean, the one in filter() or find_bad_errors()? Since you're reporting that you never get into the "in for loop" function, we're probably not able to read those lines in. My best guess is that if you're calling filter() on your logfile, and then find_bad_errors(), you may be calling readlines() twice on that file. If so, you may need to "rewind" your file before reading its lines again. Using logfile.seek(0) should do the trick. The following interpreter session will show what we mean by rewinding: ### >>> f = open('foo.txt', 'w') >>> f.write("hello world\nthis is a file with multiple\nlines of text") >>> f.close() >>> f = open('foo.txt') >>> f.readlines() ['hello world\012', 'this is a file with multiple\012', 'lines of text'] >>> f.readlines() [] >>> f.seek(0) >>> f.readlines() ['hello world\012', 'this is a file with multiple\012', 'lines of text'] ### Tricky bug. Don't do that! *grin* > 2. If I rewrite the code so that it is forced to go through the > tests, I always fail because each line is getting split up into > 1-character strings. For example, you see that I test for > "notbad1". I never find it, though, because all I see when I print Could you show us how you rewrote the code? We're fairly good at guessing, but not THAT good. *grin* Can you show us what you mean by "forcing" the tests? Anyway, I hope you're not discouraged at the late response; we'll try to do better next time. Try making your report a little shorter though; it makes debugging easier. From dyoo@hkn.eecs.berkeley.edu Wed Mar 14 14:18:21 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 14 Mar 2001 06:18:21 -0800 (PST) Subject: [Tutor] pipes, lots of 'em In-Reply-To: <20010313233524.A8131@valinux.com> Message-ID: <Pine.LNX.4.21.0103140613460.31900-100000@hkn.eecs.berkeley.edu> On Tue, 13 Mar 2001, Sean 'Shaleh' Perry wrote: > On Tue, Mar 13, 2001 at 10:39:44PM -0800, Daniel Yoo wrote: > > > > Hmmm... don't know about the pipes thing, but I did find a module that > > will let you read tar archives: > > > > http://www.faqts.com/knowledge_base/view.phtml/aid/4395 > > > > Haven't played around with it yet though. > > > > I'm very surprised not to easily find a full tar program for Python > > though; perhaps someone else can verify this? > > I am not surprised, there are no C libs either. tar seems to only be spoken > by tar. But even if I had a tar module, I also need ar support. So, I am > still dealing with pipes. > > ar p foo.ar bar|tar xfO - baz Hello Sean! I tried some limited experiments with pipes and popen, which appear to work: ### >>> output = os.popen('cat foo.txt.tar | tar xO').read() >>> output 'hello world\012this is a file with multiple\012lines of text' ### I'm not quite sure how this will react to binary files, but at least this works on text files. Wait... according to the documentation on popen2: http://python.org/doc/current/lib/os-newstreams.html http://python.org/doc/current/lib/module-popen2.html we should be able to handle the standard output from the pipe as binary too, so we shouldn't run into many problems. Can you show us what you've tried so far? From dsh8290@rit.edu Wed Mar 14 15:03:09 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 14 Mar 2001 10:03:09 -0500 Subject: [Tutor] pipes, lots of 'em In-Reply-To: <20010313233524.A8131@valinux.com>; from shaleh@valinux.com on Tue, Mar 13, 2001 at 11:35:24PM -0800 References: <20010313131718.D8009@valinux.com> <Pine.LNX.4.21.0103132236430.20579-100000@hkn.eecs.berkeley.edu> <"from dyoo"@hkn.eecs.berkeley.edu> <20010313233524.A8131@valinux.com> Message-ID: <20010314100308.A11169@harmony.cs.rit.edu> On Tue, Mar 13, 2001 at 11:35:24PM -0800, Sean 'Shaleh' Perry wrote: | On Tue, Mar 13, 2001 at 10:39:44PM -0800, Daniel Yoo wrote: | | ar p foo.ar bar|tar xfO - baz | | is the basic command line I need. This get bar out of the ar formatted foo.ar | and sends it to tar which extracts baz. I want to be able to parse baz | without it getting written to disk. I think the problem here is the command line. Can you request tar to output on stdout, rather than writing to disk? I know that you can for the tarfile itself with the "f -" options. I just briefly looked at the tar manpage but didn't find any obvious examples. Perhaps a closer look at the manpage would help. Alternatively, maybe you can dig into tar's sources a little and find the functions that do the actual work. Maybe you can turn it into a library without too much trouble? -D From DavidCraig@PIA.CA.GOV Wed Mar 14 17:01:11 2001 From: DavidCraig@PIA.CA.GOV (DavidCraig@PIA.CA.GOV) Date: Wed, 14 Mar 2001 09:01:11 -0800 Subject: [Tutor] Typing Equations-A Newbie Message-ID: <OF6834D74F.90AC7CD3-ON88256A0F.005D37C7@PIA.CA.GOV> How do I type formulas using superscripts/subscripts into Idle? I have tried importing them from MS Word to no avail. Current Platform is WIN 98. Thanks, D. H. Craig, CSM From arcege@shore.net Wed Mar 14 17:25:07 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 14 Mar 2001 12:25:07 -0500 (EST) Subject: [Tutor] pipes, lots of 'em In-Reply-To: <20010314100308.A11169@harmony.cs.rit.edu> from D-Man at "Mar 14, 2001 10: 3: 9 am" Message-ID: <E14dF1H-0001U6-00@nautilus.shore.net> > On Tue, Mar 13, 2001 at 11:35:24PM -0800, Sean 'Shaleh' Perry wrote: > | On Tue, Mar 13, 2001 at 10:39:44PM -0800, Daniel Yoo wrote: > | > | ar p foo.ar bar|tar xfO - baz > | > | is the basic command line I need. This get bar out of the ar formatted foo.ar > | and sends it to tar which extracts baz. I want to be able to parse baz > | without it getting written to disk. > > I think the problem here is the command line. Can you request tar to > output on stdout, rather than writing to disk? I know that you can > for the tarfile itself with the "f -" options. I just briefly looked > at the tar manpage but didn't find any obvious examples. Perhaps a > closer look at the manpage would help. > > Alternatively, maybe you can dig into tar's sources a little and find > the functions that do the actual work. Maybe you can turn it into a > library without too much trouble? I have a form of tar (<URL: http://www.shore.net/~arcege/python/tar.py>) available. It only handles reading tarfiles. The "O" option is not standard, and probably only exists for GNU tar. I have to read tarfiles a lot in my code at times, I usually create a temporary directory, change into that directory, extract the files there, then remove the directory tree when I'm done. >>> import os, shutil, tempfile >>> tempdir = tempfile.mktemp() >>> os.mkdir(tempdir) >>> os.chdir(tempdir) >>> if os.path.splitext(tarfile)[1] == '.gz': ... preop = 'gzip -cd' ... else: ... preop = 'cat' ... >>> f = os.popen('%(preop)s %(tarfile) | tar xvf -' % locals(), 'r') >>> files_extracted = f.readlines() >>> tar_status = f.close() >>> for extracted_file in files_extracted: ... # use extracted_file in current directory to operate of files ... pass ... >>> os.chdir('/') >>> shutil.rmtree(tempdir) Or something like that. :) -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dsh8290@rit.edu Wed Mar 14 18:39:47 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 14 Mar 2001 13:39:47 -0500 Subject: [Tutor] Typing Equations-A Newbie In-Reply-To: <OF6834D74F.90AC7CD3-ON88256A0F.005D37C7@PIA.CA.GOV>; from DavidCraig@pia.ca.gov on Wed, Mar 14, 2001 at 09:01:11AM -0800 References: <OF6834D74F.90AC7CD3-ON88256A0F.005D37C7@PIA.CA.GOV> Message-ID: <20010314133947.A11445@harmony.cs.rit.edu> On Wed, Mar 14, 2001 at 09:01:11AM -0800, DavidCraig@pia.ca.gov wrote: | How do I type formulas using superscripts/subscripts into Idle? superscripts refer to exponentiation (powers). That can be typed as, ex: x**y >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> x = 10 >>> y = 2 >>> x**y 100 (I think the ** operator was introduced in 2.0, if you only have 1.5.2 use the pow() function in math) >>> import math >>> x = 10 >>> y = 2 >>> pow( x , y ) 100 Subscripts are used only to give a different name to a variable of the same name. Just use a different name. For example: x1**y1 + x2**y2 >>> x1 = 10 >>> y1 = 2 >>> x2 = 20 >>> y2 = 4 >>> x1**y1 + x2**y2 160100 | I have tried importing them from MS Word to no avail. Current Platform is | WIN 98. MS Word formulas exist only to look pretty. They have no functionality at all. That's why "importing" them doesn't work. ;-) Basically you need to understand what the formula is trying to tell you. Then write that same mathematical operation using Python's grammar and math operations. If you are simply trying to use python as a calculator, then just write the numeric constants in instead of first assigning them to a variable name and then using that name. HTH, -D From ttorp@netpower.no Wed Mar 14 18:51:56 2001 From: ttorp@netpower.no (Thomas Ueland Torp) Date: Wed, 14 Mar 2001 19:51:56 +0100 Subject: [Tutor] "Goto"-function Message-ID: <000f01c0acb7$d850f1f0$0b44a8c0@thomas> This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C0ACC0.39C453C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am new to Python. In fact I am new to all of programming, having only = done a tiny bit on my calculator (a Texas Instruments). What I wanted to = know was that if I have a programming code, and want to go to a certain = point in the code, from another point, how do I do that (what is the = code for it)? Example: print 'Main Menu' print '1. something' print '2. something else' print '3...' a =3D int(raw_input("choose ")) if a =3D=3D 1: (some function, doesn't matter what in my question) print '1. back to main menu' print '2. Quit' b =3D int(raw_input("choose ")) if b =3D=3D 1: ??? Oh, and how do I clear the screen on the python interpreter (with a code = built-in in the program). Sincerly Thomas Torp ------=_NextPart_000_000C_01C0ACC0.39C453C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>I am new to Python. In fact I am new to = all of=20 programming, having only done a tiny bit on my calculator (a Texas = Instruments).=20 What I wanted to know was that if I have a programming code, and want to = go to a=20 certain point in the code, from another point, how do I do that (what is = the=20 code for it)?</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Example:</FONT></DIV> <DIV><FONT face=3DArial size=3D2>print 'Main Menu'</FONT></DIV> <DIV><FONT face=3DArial size=3D2>print '1. something'</FONT></DIV> <DIV><FONT face=3DArial size=3D2>print '2. something else'</FONT></DIV> <DIV><FONT face=3DArial size=3D2>print '3...'</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>a =3D int(raw_input("choose = "))</FONT></DIV> <DIV><FONT face=3DArial size=3D2>if a =3D=3D 1:</FONT></DIV> <DIV><FONT face=3DArial size=3D2> (some function, = doesn't matter=20 what in my question)</FONT></DIV> <DIV><FONT face=3DArial size=3D2> print '1. back to = main=20 menu'</FONT></DIV> <DIV><FONT face=3DArial size=3D2> print '2. = Quit'</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> b =3D = int(raw_input("choose=20 "))</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> if b =3D=3D = 1:</FONT></DIV> <DIV><FONT face=3DArial size=3D2> ???</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Oh, and how do I clear the screen on = the python=20 interpreter (with a code built-in in the program).</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Sincerly</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Thomas Torp</FONT></DIV></BODY></HTML> ------=_NextPart_000_000C_01C0ACC0.39C453C0-- From W.W.vandenBroek Wed Mar 14 19:55:09 2001 From: W.W.vandenBroek (W.W.vandenBroek) Date: Wed, 14 Mar 2001 20:55:09 +0100 Subject: [Tutor] boolean or input trouble Message-ID: <01031420550900.01092@vdbroekw> The mistake i made was trying it in idle (F5)instead of as a script, sorry again, but it works and i love it, beware though i am continuing building my "program" Thanks walter -- W.W. van den Broek e-mail: vandenbroek@psyd.azr.nl AZR-Dijkzigt fax: 010-4633217 afdeling psychiatrie tel: 010-4639222 Postbus 2040 e-mail vdbroekw@wxs.nl (thuis) 3000 CA Rotterdam homepage: http://home.planet.nl/~vdbroekw From deirdre@deirdre.net Wed Mar 14 20:10:20 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 14 Mar 2001 12:10:20 -0800 (PST) Subject: [Tutor] "Goto"-function In-Reply-To: <000f01c0acb7$d850f1f0$0b44a8c0@thomas> Message-ID: <Pine.LNX.4.31.0103141207420.6290-100000@emperor.deirdre.org> On Wed, 14 Mar 2001, Thomas Ueland Torp wrote: > I am new to Python. In fact I am new to all of programming, having > only done a tiny bit on my calculator (a Texas Instruments). What I > wanted to know was that if I have a programming code, and want to go > to a certain point in the code, from another point, how do I do that > (what is the code for it)? You make a function and call that. > Example: > print 'Main Menu' > print '1. something' > print '2. something else' > print '3...' > > a = int(raw_input("choose ")) > if a == 1: > (some function, doesn't matter what in my question) > print '1. back to main menu' > print '2. Quit' > > b = int(raw_input("choose ")) > > if b == 1: > ??? def printMainMenu(): print 'Main Menu' print '1. something' print '2. something else' print '3...' a = int(raw_input("choose ")) if a == 1: (some function, doesn't matter what in my question) print '1. back to main menu' print '2. Quit' b = int(raw_input("choose ")) if b == 1: printMainMenu() -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From hailan@givex.com Tue Mar 13 22:01:33 2001 From: hailan@givex.com (Hailan Yu) Date: Tue, 13 Mar 2001 17:01:33 -0500 Subject: [Tutor] Static variable in Python References: <E14dEeQ-00081q-00@mail.python.org> Message-ID: <007901c0ac09$2b0b0700$1507a8c0@radiantmedia.com> I know Python is a dynamic language. You don't have to define variable when you use it. Can you define a static field, which will be in stack all the time, so all forked child process can use it. Thanks Hailan Yu From tim@johnsons-web.com Thu Mar 15 01:55:37 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Wed, 14 Mar 2001 16:55:37 -0900 Subject: [Tutor] Tkinter/Identifying Text by position References: <01031420550900.01092@vdbroekw> Message-ID: <01031417094809.01346@shecom> Hello: Using tkinter on RH 6.0... ==>> I would like to get the index of a body of text in a Text widget via a mouse click and/or a keystroke on the focus. This much I know: vars(event) will return an instance with a large amount of information I also know that Text.get with a beggining and an ending row,col pair will return the text in that range. ==>> If I click with the mouse on a character, and then enter a keystroke, can I get the row,col pair at that location? TIA :>) BTW: I downloaded a large amount of Python Documentation from http://python.org/doc/current/download.html I don't see any tkinter documentation there. Is it at another location. Thanks -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From britt_green@hotmail.com Thu Mar 15 02:27:45 2001 From: britt_green@hotmail.com (Britt Green) Date: Wed, 14 Mar 2001 18:27:45 -0800 Subject: [Tutor] System Beep? Message-ID: <F258FR6sKBEr8pkpLkT000001fb@hotmail.com> I was wondering what the easiest way was to get my program to make a beep. I didn't see anything in the sys module. When I use the winsound.beep() function, no matter what number I enter for the frequency, my speakers stay silent. Any tips? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From ewe2@can.org.au Thu Mar 15 02:33:10 2001 From: ewe2@can.org.au (ewe2@can.org.au) Date: Thu, 15 Mar 2001 13:33:10 +1100 Subject: [Tutor] Porta cipher in python [ot?] Message-ID: <20010315133310.A1033@can.org.au> Sorry if this is getting off-topic, but I'm getting desperate (and sleepless): I posted a question about a Porta cipher algorithm to sci.crypt, but I thought I'd ask the cryptographically-minded Python gurus here: all I'm after is the basic algorithm, I can do the rest :) Believe me, I've searched the net, and I haven't found a single clue to it. BTW, this is part of an ongoing project to supply Tesla Coil's cipher.py with as many classical ciphers as I can muster :) waiting in prayerful mode, -- Sean Dwyer <ewe2@cvis.com.au> CAN Admin <ewe2@can.org.au> Web: http://ewe2.cvis.com.au/ From shaleh@valinux.com Thu Mar 15 03:16:20 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 14 Mar 2001 19:16:20 -0800 Subject: [Tutor] System Beep? In-Reply-To: <F258FR6sKBEr8pkpLkT000001fb@hotmail.com>; from britt_green@hotmail.com on Wed, Mar 14, 2001 at 06:27:45PM -0800 References: <F258FR6sKBEr8pkpLkT000001fb@hotmail.com> Message-ID: <20010314191620.A19156@valinux.com> On Wed, Mar 14, 2001 at 06:27:45PM -0800, Britt Green wrote: > I was wondering what the easiest way was to get my program to make a beep. I > didn't see anything in the sys module. When I use the winsound.beep() > function, no matter what number I enter for the frequency, my speakers stay > silent. Any tips? > >>> print '\a' # make the system beep From shaleh@valinux.com Thu Mar 15 03:18:32 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 14 Mar 2001 19:18:32 -0800 Subject: [Tutor] Porta cipher in python [ot?] In-Reply-To: <20010315133310.A1033@can.org.au>; from ewe2@can.org.au on Thu, Mar 15, 2001 at 01:33:10PM +1100 References: <20010315133310.A1033@can.org.au> Message-ID: <20010314191832.B19156@valinux.com> On Thu, Mar 15, 2001 at 01:33:10PM +1100, ewe2@can.org.au wrote: > Sorry if this is getting off-topic, but I'm getting desperate > (and sleepless): > > I posted a question about a Porta cipher algorithm to sci.crypt, but I thought > I'd ask the cryptographically-minded Python gurus here: all I'm after is the > basic algorithm, I can do the rest :) Believe me, I've searched the net, and I > haven't found a single clue to it. > go to www.google.com (currently the best search engine going) and type: 'porta cipher algorithm'. From paulnsharon@dingoblue.net.au Thu Mar 15 05:48:35 2001 From: paulnsharon@dingoblue.net.au (Paul Jones) Date: Thu, 15 Mar 2001 15:48:35 +1000 Subject: [Tutor] inputting strings into functions Message-ID: <001801c0ad13$95252fc0$1dc21dcb@barney> This is a multi-part message in MIME format. ------=_NextPart_000_0015_01C0AD67.651CD900 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi-back again- I'm trying with little success to figure out how to input = strings as parameters into a function definition. The problem is as = follows. I have been given the following algorithm {in brackets}=20 {The following program counts the number of times the letter 'a' appears = in a string: fruit =3D "banana"=20 count =3D 0=20 index =3D 0=20 for char in fruit:=20 if char =3D=3D 'a':=20 count =3D count + 1=20 print count } and asked to encapsulate this code in a function named countLetters, and = generalize it so that it accepts the string and the letter as arguments. = I have tried various incarnations of an algorithm as below: def countletters("string","letter"): fruit =3D 'string' count=3D0 index=3D0 for char in fruit: if char =3D=3D 'letter': count=3Dcount+1 print count =20 SyntaxError: invalid syntax (the closing quote(") on the first = parameter of the function definition is highlighted. I have tried it without the quotes but it still doesn't work as it gives = me the message underneath this code: def countletters(string,letter): fruit =3D 'string' count=3D0 index=3D0 for char in fruit: if char =3D=3D 'letter': count=3Dcount+1 print count =20 >>> countletters(kingmaker,k) Traceback (innermost last): File "<pyshell#16>", line 1, in ? countletters(kingmaker,k) NameError: There is no variable named 'kingmaker' How can I write this so it will work and the end user doesn't have to = input anything except the parameters of the function. The tutorial I'm doing(How to Think Like a Computer Scientist) has given = examples of integer parameters but not how to do this with strings. I'm = sure there is an easy way to do this but I'm obviously not finding it. Regards. Paul Jones email: paulnsharon@dingoblue.net.au ------=_NextPart_000_0015_01C0AD67.651CD900 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi-back again- I'm trying with little = success to=20 figure out how to input strings as parameters into a function = definition. The=20 problem is as follows.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>I have been given the following = algorithm {in=20 brackets} </FONT></DIV> <P>{The following program counts the number of times the letter <SPAN=20 class=3Dcode><SPAN class=3Dquote><FONT face=3DCourier=20 color=3D#ff0000>'a'</FONT></SPAN></SPAN> appears in a string:</P> <DIV><SPAN class=3Dcode><FONT face=3DCourier> fruit =3D <SPAN = class=3Dquote><FONT=20 color=3D#ff0000>"banana"</FONT></SPAN> <BR> count =3D 0 <BR> = index =3D 0=20 <BR> <SPAN class=3Dkeyword><FONT color=3D#0000ff>for</FONT></SPAN> = char <SPAN=20 class=3Dkeyword><FONT color=3D#0000ff>in</FONT></SPAN> fruit: <BR> = =20 <SPAN class=3Dkeyword><FONT color=3D#0000ff>if</FONT></SPAN> char =3D=3D = <SPAN=20 class=3Dquote><FONT color=3D#ff0000>'a'</FONT></SPAN>: <BR> = =20 count =3D count + 1 <BR> <SPAN class=3Dkeyword><FONT=20 color=3D#0000ff>print</FONT></SPAN>=20 count =20 }</FONT></SPAN></DIV><SPAN class=3Dcode><FONT face=3DCourier></FONT> <DIV><BR><FONT face=3DArial size=3D2>and asked to <FONT = size=3D3><EM><FONT=20 face=3D"Times New Roman">encapsulate this code in a function named = </FONT><SPAN=20 class=3Dcode><FONT face=3DCourier>countLetters</FONT></SPAN><FONT=20 face=3D"Times New Roman">, and generalize it so that it accepts the = string and the=20 letter as arguments.</FONT></EM><FONT face=3D"Times New Roman">=20 </FONT></FONT></FONT></DIV> <DIV> </DIV> <DIV>I have tried various incarnations of an algorithm as below:</DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>def = countletters("string","letter"):<BR> fruit=20 =3D 'string'<BR> count=3D0<BR> index=3D0<BR> for char in=20 fruit:<BR> if char =3D=3D=20 'letter':<BR> count=3Dcount+1<BR> print=20 count<BR> <BR>SyntaxError: invalid syntax<EM> (the = closing=20 quote(") on the first parameter of the function definition is=20 highlighted.</EM></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>I have tried it without the quotes but = it still=20 doesn't work as it gives me the message underneath this = code:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>def = countletters(string,letter):<BR> fruit =3D=20 'string'<BR> count=3D0<BR> index=3D0<BR> for char in=20 fruit:<BR> if char =3D=3D=20 'letter':<BR> count=3Dcount+1<BR> print = count</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> <BR>>>>=20 countletters(kingmaker,k)<BR>Traceback (innermost last):<BR> File=20 "<pyshell#16>", line 1, in ?<BR> =20 countletters(kingmaker,k)<BR>NameError: There is no variable named=20 'kingmaker'</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>How can I write this so it will work = and the end=20 user doesn't have to input anything except the parameters of the=20 function.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>The tutorial I'm doing(How to Think = Like a Computer=20 Scientist) has given examples of integer parameters but not how to do = this with=20 strings. I'm sure there is an easy way to do this but I'm obviously not = finding=20 it.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Regards.</FONT></SPAN></DIV> <DIV><FONT face=3DArial size=3D2>Paul Jones<BR>email: <A=20 href=3D"mailto:paulnsharon@dingoblue.net.au">paulnsharon@dingoblue.net.au= </A></FONT></DIV></BODY></HTML> ------=_NextPart_000_0015_01C0AD67.651CD900-- From jovoslav@dir.bg Thu Mar 15 05:55:41 2001 From: jovoslav@dir.bg (jovoslav@dir.bg) Date: Thu, 15 Mar 2001 07:55:41 +0200 Subject: [Tutor] Method overriding Message-ID: <web-19790448@dir.bg> Hello, Can someone please define what method overriding means. Thank you very much ! ----------------------------- Free mail from www.dir.bg! From paulnsharon@dingoblue.net.au Thu Mar 15 06:29:27 2001 From: paulnsharon@dingoblue.net.au (Paul Jones) Date: Thu, 15 Mar 2001 16:29:27 +1000 Subject: [Tutor] inputting strings into functions Message-ID: <003d01c0ad19$4a04f380$1dc21dcb@barney> This is a multi-part message in MIME format. ------=_NextPart_000_003A_01C0AD6D.1A508920 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I just figured out how to make it work- sorry if anyone has already = worked on it. the program below works when I input the parameters as strings.=20 def countletters(string,letter): fruit =3D string count=3D0 index=3D0 for char in fruit: if char =3D=3D letter: count=3Dcount+1 print count =20 >>> countletters("monsterio","o") 2 >>> countletters('monsterio','e') 1 I'm still not sure why I can't just declare the parameters as strings in = the function definition and then just input them without quotes into the = function parameters when I call the function. Regards.. Paul Jones email: paulnsharon@dingoblue.net.au ------=_NextPart_000_003A_01C0AD6D.1A508920 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>I just figured out how to make it work- = sorry if=20 anyone has already worked on it.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>the program below works when I input = the parameters=20 as strings. </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>def = countletters(string,letter):<BR> fruit =3D=20 string<BR> count=3D0<BR> index=3D0<BR> for char in=20 fruit:<BR> if char =3D=3D=20 letter:<BR> count=3Dcount+1<BR> print = count</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> <BR>>>>=20 countletters("monsterio","o")<BR>2<BR>>>>=20 countletters('monsterio','e')<BR>1</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>I'm still not sure why I can't just = declare the=20 parameters as strings in the function definition and then just input = them=20 without quotes into the function parameters when I call the=20 function.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Regards..</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Paul Jones<BR>email: <A=20 href=3D"mailto:paulnsharon@dingoblue.net.au">paulnsharon@dingoblue.net.au= </A></FONT></DIV></BODY></HTML> ------=_NextPart_000_003A_01C0AD6D.1A508920-- From shaleh@valinux.com Thu Mar 15 06:16:36 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 14 Mar 2001 22:16:36 -0800 Subject: [Tutor] inputting strings into functions In-Reply-To: <001801c0ad13$95252fc0$1dc21dcb@barney>; from paulnsharon@dingoblue.net.au on Thu, Mar 15, 2001 at 03:48:35PM +1000 References: <001801c0ad13$95252fc0$1dc21dcb@barney> Message-ID: <20010314221636.A19199@valinux.com> On Thu, Mar 15, 2001 at 03:48:35PM +1000, Paul Jones wrote: > Hi-back again- I'm trying with little success to figure out how to input strings as parameters into a function definition. The problem is as follows. > I have been given the following algorithm {in brackets} > {The following program counts the number of times the letter 'a' appears in a string: > > fruit = "banana" > count = 0 > index = 0 > for char in fruit: > if char == 'a': > count = count + 1 > print count } > fruit is a variable holding a string. When you access it, you do not need quotes. When you quote something you turn it into a string. So, foo is a variable, 'foo' is a string literal. > > def countletters(string,letter): > fruit = 'string' > count=0 > index=0 > for char in fruit: > if char == 'letter': > count=count+1 > print count > just remove the quotes when you use the variable. Note the example code you showed in the beginning did not quote fruit. For further help here, look at the string.py module shipped with python: # convert UPPER CASE letters to lower case def lower(s): """lower(s) -> string Return a copy of the string s converted to lowercase. """ res = '' for c in s: res = res + _lower[ord(c)] return res From britt_green@hotmail.com Thu Mar 15 06:42:02 2001 From: britt_green@hotmail.com (Britt Green) Date: Wed, 14 Mar 2001 22:42:02 -0800 Subject: [Tutor] inputting strings into functions Message-ID: <F39Tzvb5YI9IJsaJbqJ0000052b@hotmail.com> Hi Paul, So what you want is a function that will count the number of times the letter 'a' will occur in a word. Try this: #This is our function def countLetters(fruit, letter): count= 0 for x in fruit: if x == letter: count += 1 print count #This is the main routine of the program fruit = "banana" letter = "a" countLetters(fruit, letter) You could also skip the declaring of the variables in the main function and just call countLetters by doing it like so: countLetters("banana","a") If you have any questions about this, let me know and I'll try to help. Britt >Message: 13 >From: "Paul Jones" <paulnsharon@dingoblue.net.au> >To: <tutor@python.org> >Date: Thu, 15 Mar 2001 15:48:35 +1000 >Subject: [Tutor] inputting strings into functions > >This is a multi-part message in MIME format. > >------=_NextPart_000_0015_01C0AD67.651CD900 >Content-Type: text/plain; > charset="iso-8859-1" >Content-Transfer-Encoding: quoted-printable > >Hi-back again- I'm trying with little success to figure out how to input = >strings as parameters into a function definition. The problem is as = >follows. >I have been given the following algorithm {in brackets}=20 >{The following program counts the number of times the letter 'a' appears = >in a string: > > fruit =3D "banana"=20 > count =3D 0=20 > index =3D 0=20 > for char in fruit:=20 > if char =3D=3D 'a':=20 > count =3D count + 1=20 > print count } > >and asked to encapsulate this code in a function named countLetters, and = >generalize it so that it accepts the string and the letter as arguments. = > > >I have tried various incarnations of an algorithm as below: > >def countletters("string","letter"): > fruit =3D 'string' > count=3D0 > index=3D0 > for char in fruit: > if char =3D=3D 'letter': > count=3Dcount+1 > print count >=20 >SyntaxError: invalid syntax (the closing quote(") on the first = >parameter of the function definition is highlighted. > >I have tried it without the quotes but it still doesn't work as it gives = >me the message underneath this code: > >def countletters(string,letter): > fruit =3D 'string' > count=3D0 > index=3D0 > for char in fruit: > if char =3D=3D 'letter': > count=3Dcount+1 > print count > >=20 > >>> countletters(kingmaker,k) >Traceback (innermost last): > File "<pyshell#16>", line 1, in ? > countletters(kingmaker,k) >NameError: There is no variable named 'kingmaker' > >How can I write this so it will work and the end user doesn't have to = >input anything except the parameters of the function. >The tutorial I'm doing(How to Think Like a Computer Scientist) has given = >examples of integer parameters but not how to do this with strings. I'm = >sure there is an easy way to do this but I'm obviously not finding it. >Regards. >Paul Jones >email: paulnsharon@dingoblue.net.au _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Thu Mar 15 07:57:08 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 14 Mar 2001 23:57:08 -0800 (PST) Subject: [Tutor] inputting strings into functions In-Reply-To: <F39Tzvb5YI9IJsaJbqJ0000052b@hotmail.com> Message-ID: <Pine.LNX.4.31.0103142356160.12309-100000@emperor.deirdre.org> On Wed, 14 Mar 2001, Britt Green wrote: > count += 1 += is not python syntax. The line should be: count = count + 1 -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kauphlyn@speakeasy.org Thu Mar 15 08:16:08 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Thu, 15 Mar 2001 00:16:08 -0800 (PST) Subject: [Tutor] inputting strings into functions In-Reply-To: <Pine.LNX.4.31.0103142356160.12309-100000@emperor.deirdre.org> Message-ID: <Pine.LNX.4.21.0103150013260.6128-100000@grace.speakeasy.org> FYI, this assignment operator is supported in python 2.0 http://python.org/2.0/new-python.html On Wed, 14 Mar 2001, Deirdre Saoirse wrote: > > += is not python syntax. The line should be: > count = count + 1 > From scarblac@pino.selwerd.nl Thu Mar 15 09:38:42 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 15 Mar 2001 10:38:42 +0100 Subject: [Tutor] Porta cipher in python [ot?] In-Reply-To: <20010315133310.A1033@can.org.au>; from ewe2@can.org.au on Thu, Mar 15, 2001 at 01:33:10PM +1100 References: <20010315133310.A1033@can.org.au> Message-ID: <20010315103842.A2486@pino.selwerd.nl> On Thu, Mar 15, 2001 at 01:33:10PM +1100, ewe2@can.org.au wrote: > Sorry if this is getting off-topic, but I'm getting desperate > (and sleepless): > > I posted a question about a Porta cipher algorithm to sci.crypt, but I thought > I'd ask the cryptographically-minded Python gurus here: all I'm after is the > basic algorithm, I can do the rest :) Believe me, I've searched the net, and I > haven't found a single clue to it. A quick search on Google turned up http://www.achiever.com/freehmpg/cryptology/porta.html -- Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Thu Mar 15 11:41:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 15 Mar 2001 03:41:28 -0800 (PST) Subject: [Tutor] inputting strings into functions In-Reply-To: <003d01c0ad19$4a04f380$1dc21dcb@barney> Message-ID: <Pine.LNX.4.21.0103150334260.32763-100000@hkn.eecs.berkeley.edu> On Thu, 15 Mar 2001, Paul Jones wrote: > >>> countletters("monsterio","o") > 2 > >>> countletters('monsterio','e') > 1 > > I'm still not sure why I can't just declare the parameters as strings > in the function definition and then just input them without quotes > into the function parameters when I call the function. It's a slight "naming" problem. When we say countletters(cigar, i) do we really mean the string "cigar", or do we mean another variable _named_ cigar? It's perfectly legal, for example, to have this: cigar = 'not a cigar' i = ' ' countletters(cigar, i) which should return back to us '2', since there are two spaces in the phrase 'not a cigar'. Without quotes, Python will automatically plug in the variable values for us. What this means is that the names we give a variable and the values they contain are not necessarily the same. Sometimes, a cigar is not a 'cigar'. From dyoo@hkn.eecs.berkeley.edu Thu Mar 15 11:47:58 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 15 Mar 2001 03:47:58 -0800 (PST) Subject: [Tutor] Typing Equations-A Newbie In-Reply-To: <OF6834D74F.90AC7CD3-ON88256A0F.005D37C7@PIA.CA.GOV> Message-ID: <Pine.LNX.4.21.0103150342340.32763-100000@hkn.eecs.berkeley.edu> On Wed, 14 Mar 2001 DavidCraig@PIA.CA.GOV wrote: > How do I type formulas using superscripts/subscripts into Idle? > > I have tried importing them from MS Word to no avail. Current Platform is > WIN 98. Unfortunately, most programming languages don't directly support the use of subscripts and superscripts --- you'll need to translate them to a linear form. For example: 2 2 a + b will need to be written as: a**2 + b**2 in Python. Likewise, all the subscripted variables will need to be renamed. It depends on one relationship the subscripts are trying to say: if the subscripts mean some sort of sequence, like: 10 Sum a n=0 n ,the sum of a_0, a_2, ..., a_10, then it might be a good idea to give Python the information that our a's are all part of a sequence, by making it a list. Gosh, I feel handwavy today. If you show us what equation you're trying to encode, we can help find a way to translate it into Python. Good luck! From dsh8290@rit.edu Thu Mar 15 15:57:39 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 15 Mar 2001 10:57:39 -0500 Subject: [Tutor] System Beep? In-Reply-To: <20010314191620.A19156@valinux.com>; from shaleh@valinux.com on Wed, Mar 14, 2001 at 07:16:20PM -0800 References: <F258FR6sKBEr8pkpLkT000001fb@hotmail.com> <"from britt_green"@hotmail.com> <20010314191620.A19156@valinux.com> Message-ID: <20010315105739.A14599@harmony.cs.rit.edu> On Wed, Mar 14, 2001 at 07:16:20PM -0800, Sean 'Shaleh' Perry wrote: | On Wed, Mar 14, 2001 at 06:27:45PM -0800, Britt Green wrote: | > I was wondering what the easiest way was to get my program to make a beep. I | > didn't see anything in the sys module. When I use the winsound.beep() | > function, no matter what number I enter for the frequency, my speakers stay | > silent. Any tips? Not totally related, but on Win9x, windows ignores the arguments to Beep. On WinNT and 2K, however, windows actually adjusts the sound according to the arguments. It works on this Win2K system. | >>> print '\a' # make the system beep This also works. It only gives the default beep, with no customization (obviously). Are your speakers on? Are they plugged in? Do you have the proper driver for your sound card? Sure, they're stupid questions, but it is easy to overlook something :-). Make sure that other things (ie WinAmp) can play sound. -D From dsh8290@rit.edu Thu Mar 15 16:05:51 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 15 Mar 2001 11:05:51 -0500 Subject: [Tutor] Method overriding In-Reply-To: <web-19790448@dir.bg>; from jovoslav@dir.bg on Thu, Mar 15, 2001 at 07:55:41AM +0200 References: <web-19790448@dir.bg> Message-ID: <20010315110551.B14599@harmony.cs.rit.edu> On Thu, Mar 15, 2001 at 07:55:41AM +0200, jovoslav@dir.bg wrote: | Hello, | Can someone please define what method overriding means. Here is an example : class P : def foo( self ) : print "Hello" def bar( self ) : print "Bar" class C( P ) : def foo( self ) : print "GoodBye" obj1 = P() obj2 = C() # an instance of class 'C' is-a instance of class 'P' because of the # inheritance, # however it will be have differently. obj1.foo() # prints "Hello" obj2.foo() # prints "GoodBye" Class 'C' overrode the definition of method foo in class 'P' to make instances of class 'C' behave differently. It didn't override 'bar' so: obj1.bar() # prints "Bar" obj2.bar() # prints "Bar" -D From tescoil@irtc.net Thu Mar 15 15:29:51 2001 From: tescoil@irtc.net (Tesla Coil) Date: Thu, 15 Mar 2001 10:29:51 -0500 Subject: [Tutor] Porta cipher in python [ot?] References: <20010315133310.A1033@can.org.au> Message-ID: <3AB0DFEF.7CCC8B0C@irtc.net> > I posted a question about a Porta cipher > algorithm to sci.crypt, but I thought I'd > ask the cryptographically-minded Python > gurus here: all I'm after is the basic > algorithm, I can do the rest :) Believe > me, I've searched the net, and I haven't > found a single clue to it. You can think of a Porta Tableau as an extended case of ROT13--if keyletter in ['A', 'B']: it's ordinary ROT13--and it remains essentially ROT13 for any other keyletter, but ROT13 on a different construction of the alphabet. Those alphabets differ only in that (hold on...) >>> alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') >>> porta = [alphabet[0:13], alphabet[13:26]] porta[0] remains fixed, and porta[1] is rotated conditionally upon the key: >>> keypair = [] >>> for x in range(0,26,2): ... keypair.append([alphabet[x], alphabet[x+1]]) ... >>> for x in range(len(keypair)): ... if x == 0: ... pass ... else: ... rot = porta[1].pop(12) ... porta[1].insert(0, rot) ... print keypair[x], porta[1] Perhaps load a dictionary on a similar basis. Hopefully this assists you with your question, and other tutor participants with understanding whatever it was you were asking... ;) From ium@micromuse.com Thu Mar 15 16:48:14 2001 From: ium@micromuse.com (ium@micromuse.com) Date: Thu, 15 Mar 2001 16:48:14 +0000 Subject: [Tutor] "Goto"-function In-Reply-To: <000f01c0acb7$d850f1f0$0b44a8c0@thomas>; from ttorp@netpower.no on Wed, Mar 14, 2001 at 07:51:56PM +0100 References: <000f01c0acb7$d850f1f0$0b44a8c0@thomas> Message-ID: <20010315164814.A15035@ignoramus.ukdev.micromuse.com> On Wed, Mar 14, 2001 at 07:51:56PM +0100, Thomas Ueland Torp wrote: | Oh, and how do I clear the screen on the python interpreter (with a code built-in in the program). The best solution I have seen to this is the following.... >>>import os >>>os.system('clear') Kindest regards, --ibs. -------------------------- Ibraheem Umaru-Mohammed --------------------------- -- Email:ium@micromuse.com -- -- Micromuse Ltd, Disraeli House, 90 Putney Bridge Road, London SW18 1DA -- -- http://www.micromuse.com -- From cooler12001@yahoo.com Thu Mar 15 19:08:25 2001 From: cooler12001@yahoo.com (Matthews James) Date: Thu, 15 Mar 2001 11:08:25 -0800 (PST) Subject: [Tutor] (no subject) Message-ID: <20010315190825.1522.qmail@web11405.mail.yahoo.com> I was wondering ,if any of you have the time to help with my program i just started to learn python and I have made a program called "Autobook" and it saves my phone numbers and stuff like that but anyways i was wonder if any of you could write it so that it is excutable with out python right now it only can run through python and i was wanting to learn how to run it in a window with buttons and a display, stuff like that Its not a biggi, so if it is a bother don't bother __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Thu Mar 15 20:40:48 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 15 Mar 2001 12:40:48 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <20010315190825.1522.qmail@web11405.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103151229510.12218-100000@hkn.eecs.berkeley.edu> On Thu, 15 Mar 2001, Matthews James wrote: > but anyways i was wonder if any of you could write it so that it is > excutable with out python right now it only can run through python Yes, there's a way to make it executable. You'll want to look at: http://www.mcmillan-inc.com/install1.html and I think there's supposed be an easier-to-use program that lets you package Python programs too... but I can't remember the name off the top of my head. Can someone clarify? > and i was wanting to learn how to run it in a window > with buttons and a display, stuff like that Sure; this sounds like a job for the Tkinter library. You'll need to get the basics of Python down, but after that: there's a graphics library called Tkinter that makes it easy to make buttons, text fields, and other stuff. For example, this program: ### from Tkinter import * root = Tk() Label(root, text="Hello World").pack(side=LEFT) Button(root, text="Press me").pack(side=LEFT) ### will make a label and a button; in ascii, it'll sorta look like this: --------------------------- | Hello world | Press me | --------------------------- I think there's a few tutorials that introduce Tkinter; there's a whole section on it on the python.org web site: http://python.org/topics/tkinter/ You can feel free asking us Tkinter problems. I'm trying to learn Tkinter myself at the moment, so it'll be good to talk about it with a fellow learner. > Its not a biggi, so if it is a bother don't bother It's not a bother at all; don't worry about it. From ttorp@netpower.no Thu Mar 15 20:58:34 2001 From: ttorp@netpower.no (Thomas Ueland Torp) Date: Thu, 15 Mar 2001 21:58:34 +0100 Subject: [Tutor] Local variable --> global variable -- how to? Message-ID: <003b01c0ad92$b3287f20$0b44a8c0@thomas> This is a multi-part message in MIME format. ------=_NextPart_000_0038_01C0AD9B.149D6790 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Someone kght have noticed that I just asked for some help. Well, I seem = to need more. Look at this code (it is for an online game I am playing, = Planetarion (www.planetarion.com): print 'PA Build Manager v.b1.0 Python Version' # This is the shiplist def printShiplist(): print 'Shiplist' print '1. Interceptor' print '2. Torpedo' print '3. Warfrigate' a =3D int(raw_input ("Choose your ship ")) if a =3D=3D 1: Interceptor() elif a =3D=3D 2: Torpedo() elif a =3D=3D 3: Warfrigate() else: print 'under construction' def Shipcost(): print 'cost:', g, 'metal' print 'cost:', h, 'crystal' def Interceptor(): print 'Interceptors' b =3D int(raw_input ("How many? ")) g =3D 1000*b h =3D 0 Shipcost() =20 =20 When I run this I get this error: NameError: global name 'g' is not defined I do see the problem, of course. The g in Interceptor() is not global, = only local (as I understand it). Problem is, how do I get the variables = to become global. Hope someone can help Thomas U. Torp ------=_NextPart_000_0038_01C0AD9B.149D6790 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2>Someone kght have noticed that I just = asked for=20 some help. Well, I seem to need more. Look at this code (it is for an = online=20 game I am playing, Planetarion (<A=20 href=3D"http://www.planetarion.com">www.planetarion.com</A>):</FONT></DIV= > <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>print 'PA Build Manager v.b1.0 Python = Version'<BR>#=20 This is the shiplist<BR>def printShiplist():<BR> print = 'Shiplist'<BR> print '1. = Interceptor'<BR> =20 print '2. Torpedo'<BR> print '3.=20 Warfrigate'<BR> a =3D int(raw_input ("Choose your ship = "))<BR> if a =3D=3D=20 1:<BR> =20 Interceptor()<BR> elif a =3D=3D=20 2:<BR> = Torpedo()<BR> =20 elif a =3D=3D 3:<BR> =20 Warfrigate()<BR> =20 else:<BR> print 'under=20 construction'</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>def Shipcost():<BR> = print=20 'cost:', g, 'metal'<BR> print 'cost:', h,=20 'crystal'</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>def = Interceptor():<BR> print=20 'Interceptors'<BR> b =3D int(raw_input ("How many?=20 "))<BR> g =3D 1000*b<BR> h =3D=20 0<BR> Shipcost() </FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>When I run this I get this = error:</FONT></DIV> <DIV><FONT face=3DArial size=3D2>NameError: global name 'g' is not=20 defined</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>I do see the problem, of course. The g = in=20 Interceptor() is not global, only local (as I understand it). Problem = is, how do=20 I get the variables to become global.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Hope someone can help</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Thomas U.=20 Torp</FONT></DIV></FONT></DIV></BODY></HTML> ------=_NextPart_000_0038_01C0AD9B.149D6790-- From kojo@tamu.edu Thu Mar 15 20:59:51 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Thu, 15 Mar 2001 14:59:51 -0600 Subject: [Tutor] Real World Python Message-ID: <5.0.2.1.0.20010315144458.02222520@pop3.norton.antivirus> --=====================_139377589==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed Hello all (or, as we say here in AggieLand, "Howdy!"), This is sort of off-topic, but I thought it was interesting. I was reading the latest gaming column at ArsTechnica (<http://arstechnica.com/etc/games/>), and at the bottom of the column, they have their weekly cheat codes. This week, it's for a game called "Blade of Darkness". They tell you to enable the codes, you have to make changes to your menu.py file. ".py!?! Hey!". I thought, "They're using Python to configure this game!...and I recognized it!...and I know some (ok, very little) Python! Wow!" Ok, maybe I overreacted, but for a Python novice like myself, it was pretty cool. I even understood the seven lines of code they wanted you to add to the config file. Ok, the point? I thought it might be interesting if we posted some of the more down to earth Real World uses of Python when we came across them. The question seems to keep coming up (especially from newer people) about what can be done with Python or who's using Python. I mean, a lot of us have heard about how NASA and Disney and ILM are using it, but how many of us (especially people new to the language) are going to be working in or visiting any of those places any time soon? (I think Ron and I probably live closest to NASA's JSC...I'm not planning any trips in the near future, how about you Ron?) On the other hand, the Blade of Darkness demo is included on the Maximum PC CD that came in the mail earlier this week, and is on newstands now. I suddenly have more incentive to install the demo. It seems that if we had more of these examples, the answer to that oft-asked question could become, "You can use Python in about 10 minutes. Just go load up that game/app that uses it and get to typing!" That's my idea. What do the rest of you think? **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** --=====================_139377589==_.ALT Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html> Hello all (or, as we say here in AggieLand, "Howdy!"),<br> <br> This is sort of off-topic, but I thought it was interesting. I was reading the latest gaming column at ArsTechnica (<<a href=3D"http://arstechnica.com/etc/games/" eudora=3D"autourl">http:/= /arstechnica.com/etc/games/</a>>), and at the bottom of the column, they have their weekly cheat codes. This week, it's for a game called "Blade of Darkness". They tell you to enable the codes, you have to make changes to your <b>menu.py</b> file. ".py!?! Hey!". I thought, "They're using Python to configure this game!...and I recognized it!...and I know some (ok, very little) Python! Wow!"<br> <br> Ok, maybe I overreacted, but for a Python novice like myself, it was pretty cool. I even understood the seven lines of code they wanted you to add to the config file.<br> <br> Ok, the point? I thought it might be interesting if we posted some of the more down to earth Real World uses of Python when we came across them. The question seems to keep coming up (especially from newer people) about what can be done with Python or who's using Python. I mean, a lot of us have heard about how NASA and Disney and ILM are using it, but how many of us (especially people new to the language) are going to be working in or visiting any of those places any time soon? (I think Ron and I probably live closest to NASA's JSC...I'm not planning any trips in the near future, how about you Ron?) On the other hand, the Blade of Darkness demo is included on the Maximum PC CD that came in the mail earlier this week, and is on newstands now. I suddenly have more incentive to install the demo. It seems that if we had more of these examples, the answer to that oft-asked question could become, "You can use Python in about 10 minutes. Just go load up that game/app that uses it and get to typing!"<br> <br> That's my idea. What do the rest of you think?<br> <x-sigsep><p></x-sigsep> **************************** <br> Kojo Idrissa <br> KPMG Scholar <br> Accounting Doctoral Student <br> Texas A&M University <br> <br> Kojo@tamu.edu <br> 401M Wehner Bldg. <br> 979-862-2726 <br> ****************************</html> --=====================_139377589==_.ALT-- From deirdre@deirdre.net Thu Mar 15 21:35:15 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 15 Mar 2001 13:35:15 -0800 (PST) Subject: [Tutor] Local variable --> global variable -- how to? In-Reply-To: <003b01c0ad92$b3287f20$0b44a8c0@thomas> Message-ID: <Pine.LNX.4.31.0103151332170.18156-100000@emperor.deirdre.org> On Thu, 15 Mar 2001, Thomas Ueland Torp wrote: > def Shipcost(): > print 'cost:', g, 'metal' > print 'cost:', h, 'crystal' > > def Interceptor(): > print 'Interceptors' > b = int(raw_input ("How many? ")) > g = 1000*b > h = 0 > Shipcost() > > When I run this I get this error: > NameError: global name 'g' is not defined > > I do see the problem, of course. The g in Interceptor() is not global, > only local (as I understand it). Problem is, how do I get the > variables to become global. 1) bad idea to make variables global unless there is no other way. 2) there is nearly always another way. 3) Pass g and h to the Shipcost function: def Shipcost(gold, crystal): print 'cost:', gold, 'metal' print 'cost:', crystal, 'crystal' def Interceptor(): print 'Interceptors' b = int(raw_input ("How many? ")) g = 1000*b h = 0 Shipcost(g, h) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Thu Mar 15 22:34:38 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Thu, 15 Mar 2001 23:34:38 +0100 Subject: [Tutor] Real World Python In-Reply-To: <5.0.2.1.0.20010315144458.02222520@pop3.norton.antivirus> References: <5.0.2.1.0.20010315144458.02222520@pop3.norton.antivirus> Message-ID: <01031523343802.30326@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 15 March 2001 21:59, you wrote: > Hello all (or, as we say here in AggieLand, "Howdy!"), > > This is sort of off-topic, but I thought it was interesting. I was reading > the latest gaming column at ArsTechnica > (<http://arstechnica.com/etc/games/>), and at the bottom of the column, > they have their weekly cheat codes. This week, it's for a game called > "Blade of Darkness". They tell you to enable the codes, you have to make > changes to your menu.py file. ".py!?! Hey!". I thought, "They're using > Python to configure this game!...and I recognized it!...and I know some > (ok, very little) Python! Wow!" I knew that. They are spanish people and the talked in a conference at my university. Pretty interesting > > Ok, maybe I overreacted, but for a Python novice like myself, it was pretty > cool. I even understood the seven lines of code they wanted you to add to > the config file. I have a feeling that is more dificult to make a python code non-understandable than to make a perl code understandable ;D > > Ok, the point? I thought it might be interesting if we posted some of the > more down to earth Real World uses of Python when we came across them. The > question seems to keep coming up (especially from newer people) about what > can be done with Python or who's using Python. I mean, a lot of us have > heard about how NASA and Disney and ILM are using it, but how many of us > (especially people new to the language) are going to be working in or > visiting any of those places any time soon? (I think Ron and I probably > live closest to NASA's JSC...I'm not planning any trips in the near future, > how about you Ron?) On the other hand, the Blade of Darkness demo is > included on the Maximum PC CD that came in the mail earlier this week, and > is on newstands now. I suddenly have more incentive to install the > demo. It seems that if we had more of these examples, the answer to that > oft-asked question could become, "You can use Python in about 10 > minutes. Just go load up that game/app that uses it and get to typing!" > > That's my idea. What do the rest of you think? > More real-world examples: - -Mailman (excelent mailing list manager, used for example at python.org and freebsd.org) - -blender: 3d modeler that uses python as an extension languaje c-u Pedro > **************************** > Kojo Idrissa > KPMG Scholar > Accounting Doctoral Student > Texas A&M University > > Kojo@tamu.edu > 401M Wehner Bldg. > 979-862-2726 > **************************** - ---------------------------------------- Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1" Content-Transfer-Encoding: quoted-printable Content-Description: - ---------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6sUN+nu53feEYxlERAl7PAKDOytE73yiA7IlSgaEF10xyxT06qwCfTiym PoRpsirhP2iewnLVn0W7+Dw= =SZSN -----END PGP SIGNATURE----- From deirdre@deirdre.net Thu Mar 15 21:49:38 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 15 Mar 2001 13:49:38 -0800 (PST) Subject: [Tutor] Real World Python In-Reply-To: <01031523343802.30326@tajo> Message-ID: <Pine.LNX.4.31.0103151346030.18156-100000@emperor.deirdre.org> On Thu, 15 Mar 2001, Pedro Diaz Jimenez wrote: > More real-world examples: > - -Mailman (excelent mailing list manager, used for example at python.org and > freebsd.org) > - -blender: 3d modeler that uses python as an extension languaje One of my favorite "gee I wish I'd written that" examples: kivio, a visio clone: http://www.thekompany.com/projects/kivio/ or wget ftp://ftp.thekompany.com/pub/kivio/0.9.2/src/kivio-0.9.2.tar.gz -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From alan.gauld@bt.com Thu Mar 15 22:14:22 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:14:22 -0000 Subject: [Tutor] Tkinter/Identifying Text by position Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D63C@mbtlipnt02.btlabs.bt.co.uk> > I would like to get the index of a body of text in a Text widget via > a mouse click and/or a keystroke on the focus. I know you can do this but dont remember how... > BTW: I downloaded a large amount of Python Documentation from > http://python.org/doc/current/download.html > I don't see any tkinter documentation there. > Is it at another location. Go to the Tkinter topic at the python.org site. Under there you will find a docs and tutorials link specific to Tkinter. In particular you really should bookmark Frederik's Tkinter reference/tutorial. Also it looks like you are getting in deep enough to warrant buying Grayson's Tkinter book. Its more than you need for basic Tkinter but if you do anything complex at all its worth having. Alan g From alan.gauld@bt.com Thu Mar 15 22:29:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:29:45 -0000 Subject: [Tutor] inputting strings into functions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D63D@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0AD9F.6FD6D750 Content-type: text/plain; charset="iso-8859-1" I have tried various incarnations of an algorithm as below: def countletters("string","letter"): This tries to create a funtion with literal strings as parameters. Parameters are a special type of variable and obey the same naming rules thus you can't use quotes around them... SyntaxError: invalid syntax (the closing quote(") on the first parameter of the function definition is highlighted. So Python correctly complains that the variable is badly named. I have tried it without the quotes but it still doesn't work as it gives me the message underneath this code: def countletters(string,letter): fruit = 'string' Oh, so close! you want to make the variable fruit hold the same as the parameter/variable string so you don't want the quotes: fruit = string What you did was to make fruit hold the literal string 'string'. if char == 'letter': Same here, you want to compare char to the value of the parameter not to the literal string 'letter' : if char == letter >>> countletters(kingmaker,k) Traceback (innermost last): File "<pyshell#16>", line 1, in ? countletters(kingmaker,k) NameError: There is no variable named 'kingmaker' This is because you are now passing a name(no quotes) into the function. You need to pass a literal string: >>> countletters("kingmaker","k") You need to go back to your textbook and read up on the difference between variable names and values. In particular play with assigning strings to variables and printing the results. Comparing them to other strings etc. eg: >>> var = "variable" >>> var2 = "another" >>> print var >>> print "variable" >>> print variable >>> print var2 >>> if var2 == "another" : print "another" >>> if var2 == another : print "another" >>> if var2 == "another"v : print another etc... Try these and look carefully at what hapens and keep at it till you understand exactly whats happening. The tutorial I'm doing(How to Think Like a Computer Scientist) has given examples of integer parameters but not how to do this with strings. I'm sure there is an easy way to do this but I'm biased but you might find it helpful to compare HtTLaCS with my tutorial when you get stuck - its not necessarily better but gives a different perspective :-) http://www.crosswinds.net/~agauld/ <http://www.crosswinds.net/~agauld/> For this case look at the following sections: simple sequences, raw materials(first few sections only), more sequences, modules and functions HTH, Alan G ------_=_NextPart_001_01C0AD9F.6FD6D750 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"><SPAN class=code> <DIV>I have tried various incarnations of an algorithm as below:</DIV> <DIV> </DIV> <DIV><FONT size=2><FONT face=Arial>def countletters("string","letter"):<BR><SPAN class=050551122-15032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>This tries to create a funtion with literal strings as parameters. Parameters </SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>are a special type of variable and obey the same naming rules thus you can't use </SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>quotes around them...</SPAN></FONT></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT size=2><FONT face=Arial>SyntaxError: invalid syntax<EM> (the closing quote(") on the first parameter of the function definition is highlighted.</EM></FONT></FONT></DIV></BLOCKQUOTE> <DIV><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>So Python correctly complains that the variable is badly named.</FONT></SPAN> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>I have tried it without the quotes but it still doesn't work as it gives me the message underneath this code:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV></BLOCKQUOTE> <DIV><FONT size=2><FONT face=Arial>def countletters(string,letter):<BR> <SPAN class=050551122-15032001><FONT color=#0000ff> </FONT></SPAN>fruit = 'string'<BR><SPAN class=050551122-15032001><FONT color=#0000ff> </FONT></SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>Oh, so close! you want to make the variable fruit hold the same as the </SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>parameter/variable string so you don't want the quotes:</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>fruit = string</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001></SPAN></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001>What you did was to make fruit hold the literal string 'string'.</SPAN></FONT></FONT></DIV> <DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN class=050551122-15032001></SPAN></FONT></FONT> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial><FONT size=2> if char == 'letter':<FONT color=#0000ff></FONT><FONT size=2><SPAN class=050551122-15032001> </SPAN></FONT></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN class=050551122-15032001></SPAN></FONT></FONT></FONT> </DIV></BLOCKQUOTE> <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN class=050551122-15032001><FONT color=#000000>Same here, you want to compare char to the value of the parameter </FONT></SPAN></FONT></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN class=050551122-15032001><FONT color=#000000>not to the literal string 'letter'</FONT> <FONT color=#000000>:</FONT></SPAN></FONT></FONT></FONT></DIV> <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN class=050551122-15032001></SPAN></FONT></FONT></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN><FONT size=2><FONT color=#000000><FONT face=Arial><SPAN class=050551122-15032001>if char == letter</SPAN></FONT></FONT></FONT></FONT></DIV> <DIV><FONT color=#0000ff><FONT size=2><FONT color=#000000><FONT face=Arial><SPAN class=050551122-15032001></SPAN></FONT></FONT></FONT></FONT> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>>>> countletters(kingmaker,k)<BR>Traceback (innermost last):<BR> File "<pyshell#16>", line 1, in ?<BR> countletters(kingmaker,k)<BR>NameError: There is no variable named 'kingmaker'</FONT></DIV></BLOCKQUOTE> <DIV><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>This is because you are now passing a name(no quotes) into the function.</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>You need to pass a literal string:</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> countletters("kingmaker","k")</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN> </DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>You need to go back to your textbook and read up on the difference between </FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>variable names and values. In particular play with assigning strings to variables </FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>and printing the results. Comparing them to other strings etc. eg:</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN> </DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> var = "variable"</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> var2 = "another"</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> print var</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> print "variable"</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> print variable</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> print var2</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> if var2 == "another" : print "another"</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> if var2 == another : print "another"</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>>>> if var2 == "another"v : print another</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN> </DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>etc...</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN> </DIV> <DIV><SPAN class=050551122-15032001></SPAN><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>Try these and look carefully at what hapens and keep at it till you understand </FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001><FONT color=#0000ff face=Arial size=2>exactly whats happening.</FONT></SPAN></DIV> <DIV><SPAN class=050551122-15032001></SPAN> </DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"><FONT size=2><FONT face=Arial> <DIV>The tutorial I'm doing(How to Think Like a Computer Scientist) has given examples of integer parameters but not how to do this with strings. I'm sure there is an easy way to do this but <FONT color=#0000ff><SPAN class=050551122-15032001> </SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>I'm biased but you might find it helpful to compare HtTLaCS with my tutorial when </SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>you get stuck - its not necessarily better but gives a different perspective :-)</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001><A href="http://www.crosswinds.net/~agauld/">http://www.crosswinds.net/~agauld/</A></SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>For this case look at the following sections:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>simple sequences,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>raw materials(first few sections only),</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>more sequences,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>modules and functions</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>HTH,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff><SPAN class=050551122-15032001>Alan G</SPAN></FONT></SPAN></FONT></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0AD9F.6FD6D750-- From alan.gauld@bt.com Thu Mar 15 22:31:16 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:31:16 -0000 Subject: [Tutor] Method overriding Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D63E@mbtlipnt02.btlabs.bt.co.uk> > Can someone please define what method overriding means. > Thank you very much ! Try looking towards the end og the raw materials section of my online tutor then read the Object Oriented Programming chapter. Between them, they cover this. Alan G From Rob Andrews" <rob@jam.rr.com Thu Mar 15 22:30:55 2001 From: Rob Andrews" <rob@jam.rr.com (Rob Andrews) Date: Thu, 15 Mar 2001 16:30:55 -0600 Subject: [Tutor] Real World Python References: <5.0.2.1.0.20010315144458.02222520@pop3.norton.antivirus> Message-ID: <003701c0ad9f$9a621b60$9600a8c0@Planhouse5> Have you looked at Useless Python? It's a collection of Python code that people from the list and from elsewhere in the Matrix send in for other people to look at and play with. Some of it is actually *real world* by fair definitions, and if you're a newbie looking for scripts/modules you can wrap your head around, it makes for an interesting resource. (And you can send in some of your own stuff, too!) Rob Andrews Useless Python Maintainer Dude Useless Python Repository http://www.lowerstandard.com/python/pythonsource.html ----- Original Message ----- From: Kojo Idrissa To: tutor@python.org Sent: Thursday, March 15, 2001 2:59 PM Subject: [Tutor] Real World Python Hello all (or, as we say here in AggieLand, "Howdy!"), This is sort of off-topic, but I thought it was interesting. I was reading the latest gaming column at ArsTechnica (<http://arstechnica.com/etc/games/>), and at the bottom of the column, they have their weekly cheat codes. This week, it's for a game called "Blade of Darkness". They tell you to enable the codes, you have to make changes to your menu.py file. ".py!?! Hey!". I thought, "They're using Python to configure this game!...and I recognized it!...and I know some (ok, very little) Python! Wow!" Ok, maybe I overreacted, but for a Python novice like myself, it was pretty cool. I even understood the seven lines of code they wanted you to add to the config file. Ok, the point? I thought it might be interesting if we posted some of the more down to earth Real World uses of Python when we came across them. The question seems to keep coming up (especially from newer people) about what can be done with Python or who's using Python. I mean, a lot of us have heard about how NASA and Disney and ILM are using it, but how many of us (especially people new to the language) are going to be working in or visiting any of those places any time soon? (I think Ron and I probably live closest to NASA's JSC...I'm not planning any trips in the near future, how about you Ron?) On the other hand, the Blade of Darkness demo is included on the Maximum PC CD that came in the mail earlier this week, and is on newstands now. I suddenly have more incentive to install the demo. It seems that if we had more of these examples, the answer to that oft-asked question could become, "You can use Python in about 10 minutes. Just go load up that game/app that uses it and get to typing!" That's my idea. What do the rest of you think? **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** From alan.gauld@bt.com Thu Mar 15 22:37:12 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:37:12 -0000 Subject: [Tutor] Static variable in Python Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D63F@mbtlipnt02.btlabs.bt.co.uk> > Can you define a static field, which will be in stack all the > time, so all forked child process can use it. Depends on exactly what you want to do. I fddon't think there is an exact equivalent to C's static keyword but you can fake it in various ways depending on exactly what you need to do. For example default parameters are defined just once so setting a hidden parameter to some value can do it sometimes: foo = input("give me a value") myStaticThing = lambda x=foo : return x Now anytime you call myStaticThing() you will get back the value that foo had when you defined it... A bit convoluted but its the best I've found. Dunno how that works across threads tho, I've not used Python threads yet! Alan G. PS Note that I haven't tried that code in the interpreter so it might need a tweak. I have used te principle tho... From alan.gauld@bt.com Thu Mar 15 22:39:37 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:39:37 -0000 Subject: [Tutor] "Goto"-function Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D640@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0ADA0.D0CAAD10 Content-type: text/plain; charset="iso-8859-1" I am new to Python. In fact I am new to all of programming, At risk of boring everyone can I commend my online tutor to you? http://www.crosswinds.net/~agauld <http://www.crosswinds.net/~agauld> It discusses the use of GOTO and the fact it doesn't exist in Python. See the looping and branching chapters. HTH, Alan G. ------_=_NextPart_001_01C0ADA0.D0CAAD10 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>I am new to Python. In fact I am new to all of programming, <SPAN class=980193322-15032001><FONT color=#0000ff> </FONT></SPAN></FONT></DIV> <DIV><FONT face=Arial size=2><SPAN class=980193322-15032001></SPAN></FONT> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001>At risk of boring everyone can I commend my online tutor to you?</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001><A href="http://www.crosswinds.net/~agauld">http://www.crosswinds.net/~agauld</A></SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001>It discusses the use of GOTO and the fact it doesn't exist in Python.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001>See the looping and branching chapters.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001>HTH,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=980193322-15032001>Alan G.</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV> </DIV></BLOCKQUOTE></BODY></HTML> ------_=_NextPart_001_01C0ADA0.D0CAAD10-- From alan.gauld@bt.com Thu Mar 15 22:48:42 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 22:48:42 -0000 Subject: [Tutor] "Goto"-function Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D641@mbtlipnt02.btlabs.bt.co.uk> > The best solution I have seen to this is the following.... > > >>>import os > >>>os.system('clear') If you use curses you can also use a curses function - can't recall which tho! Or on DOS: os.system('CLS') I think F/'s terminal module provides a platform transparent function for doing this too. Alan G From arcege@shore.net Thu Mar 15 23:00:47 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 15 Mar 2001 18:00:47 -0500 (EST) Subject: [Tutor] Real World Python In-Reply-To: <5.0.2.1.0.20010315144458.02222520@pop3.norton.antivirus> from Kojo Idrissa at "Mar 15, 2001 2:59:51 pm" Message-ID: <E14dgjf-0005pD-00@nautilus.shore.net> > Ok, the point? I thought it might be interesting if we posted some of the > more down to earth Real World uses of Python when we came across them. The > question seems to keep coming up (especially from newer people) about what > can be done with Python or who's using Python. I mean, a lot of us have > heard about how NASA and Disney and ILM are using it, but how many of us > (especially people new to the language) are going to be working in or > visiting any of those places any time soon? (I think Ron and I probably > live closest to NASA's JSC...I'm not planning any trips in the near future, > how about you Ron?) On the other hand, the Blade of Darkness demo is > included on the Maximum PC CD that came in the mail earlier this week, and > is on newstands now. I suddenly have more incentive to install the > demo. It seems that if we had more of these examples, the answer to that > oft-asked question could become, "You can use Python in about 10 > minutes. Just go load up that game/app that uses it and get to typing!" I've been using Python heavily in the lab this week. I'm no winblows user, but we have NT in the lab. It's hard to get services (FTPD, Web server) running, especially if you don't have the service CD. A few months ago, I wrote a cross-platform FTPD in python. I haven't really tested it heavily, but it works for the most part. I did a complete copy of a directory tree from a Win98 box to a WinNT (running my ftpd.py). This is all to set up a demo for our CEO where two web clients (WinXX) talk to a web server (WinNT), which is really SimpleHTTPServer.py, communicating through our networking prototype. In other areas, I wrote a fair portion of some system level bits of our product in Python; things like booting, upgrade, system management. I'm not sure how much the company would like that being advertised tho - they don't care to even say what the platform is. *hehe* -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From tim@johnsons-web.com Thu Mar 15 23:08:44 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Thu, 15 Mar 2001 14:08:44 -0900 Subject: [Tutor] Tkinter/Identifying Text by position References: <5104D4DBC598D211B5FE0000F8FE7EB20751D63C@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01031514124204.03217@shecom> Hi Alan: On Thu, 15 Mar 2001, alan.gauld@bt.com wrote: > > I would like to get the index of a body of text in a Text widget via > > a mouse click and/or a keystroke on the focus. > > I know you can do this but dont remember how... > > > BTW: I downloaded a large amount of Python Documentation from > > http://python.org/doc/current/download.html > > I don't see any tkinter documentation there. > > Is it at another location. > > Go to the Tkinter topic at the python.org site. Under > there you will find a docs and tutorials link specific > to Tkinter. In particular you really should bookmark > Frederik's Tkinter reference/tutorial. > > Also it looks like you are getting in deep enough to > warrant buying Grayson's Tkinter book. Its more than > you need for basic Tkinter but if you do anything > complex at all its worth having. Speakin of the divil...:>) Just got done downloading Frederik's stuff. Not all of it is complete, but it appears to be fairly thorough. I also have the Grayson, but I appear to be missing something when it comes to the options, and how to pass them, for instance vscrollmode..... python doesn't like it, even though it is listed by Grayson as an option for scrolledtext. I believe that Grayson has a site and a list. I will read a little Grayson and Fredirik's .... Thanks -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From alan.gauld@bt.com Thu Mar 15 23:00:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 15 Mar 2001 23:00:45 -0000 Subject: [Tutor] Real World Python Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D643@mbtlipnt02.btlabs.bt.co.uk> > more incentive to install the demo. It seems that if we had more of > these examples, Most of the Linux GUI config tools are written in Python There is a drawing program (Sketch?) also in Python There is a version of the wonderful vim editor that uses python as its macro laguage Hope that helps... Alan G From dsh8290@rit.edu Fri Mar 16 00:15:48 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 15 Mar 2001 19:15:48 -0500 Subject: [Tutor] "Goto"-function In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D641@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Thu, Mar 15, 2001 at 10:48:42PM +0000 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D641@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010315191548.A14853@harmony.cs.rit.edu> | > >>>import os | > >>>os.system('clear') this is only for Unix systems. | Or on DOS: | | os.system('CLS') and this is only for dos. For everything, use : print "\n" * 24 ;-) -D From chaibenl@yahoo.com Fri Mar 16 04:12:01 2001 From: chaibenl@yahoo.com (Cruiser) Date: Thu, 15 Mar 2001 20:12:01 -0800 (PST) Subject: [Tutor] string matching Message-ID: <20010316041201.22379.qmail@web3501.mail.yahoo.com> Hi, there, I got a problem using Regex module, i.e. object.match (string) method, in which object is a compiled regular expression pattern, string is a string with multiple lines (up to 6 pages!). This method can not find any pattern except that on the first line, while object.search(string) is working just fine! The version of Python I use is 1.4 on Unix. I appreciate your advice! -B.C. __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From jcm@bigskytel.com Fri Mar 16 04:40:43 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 15 Mar 2001 21:40:43 -0700 Subject: [Tutor] (no subject) In-Reply-To: <Pine.LNX.4.21.0103151229510.12218-100000@hkn.eecs.berkeley.edu>; from dyoo@hkn.eecs.berkeley.edu on Thu, Mar 15, 2001 at 12:40:48PM -0800 References: <20010315190825.1522.qmail@web11405.mail.yahoo.com> <Pine.LNX.4.21.0103151229510.12218-100000@hkn.eecs.berkeley.edu> Message-ID: <20010315214043.A6790@bigskytel.com> * Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>: > On Thu, 15 Mar 2001, Matthews James wrote: > > > but anyways i was wonder if any of you could write it so that it is > > excutable with out python right now it only can run through python > > Yes, there's a way to make it executable. You'll want to look at: > > http://www.mcmillan-inc.com/install1.html > > and I think there's supposed be an easier-to-use program that lets you > package Python programs too... but I can't remember the name off the top > of my head. Can someone clarify? http://starship.python.net/crew/theller/py2exe/ > > and i was wanting to learn how to run it in a window > > with buttons and a display, stuff like that > > Sure; this sounds like a job for the Tkinter library. You'll need to get > the basics of Python down, but after that: there's a graphics library > called Tkinter that makes it easy to make buttons, text fields, and other > stuff. <...> Note that Tkinter scripts are not currently supported by py2exe, though they are by McMillan's installer. From tescoil@irtc.net Fri Mar 16 03:50:06 2001 From: tescoil@irtc.net (Tesla Coil) Date: Thu, 15 Mar 2001 22:50:06 -0500 Subject: [Tutor] string matching References: <20010316041201.22379.qmail@web3501.mail.yahoo.com> Message-ID: <3AB18D6E.77014870@irtc.net> On 15 Mar 2001, Cruiser wrote: > I got a problem using Regex module, i.e. object.match > (string) method, in which object is a compiled regular > expression pattern, string is a string with multiple > lines (up to 6 pages!). This method can not find > any pattern except that on the first line, while > object.search(string) is working just fine! Sounds like the difference between match and search. See: http://py-howto.sourceforge.net/regex/node22.html From s349929@student.uq.edu.au Fri Mar 16 05:03:30 2001 From: s349929@student.uq.edu.au (Suzanne Little) Date: Fri, 16 Mar 2001 15:03:30 +1000 (GMT+1000) Subject: [Tutor] returning from a function? Message-ID: <Pine.OSF.4.30.0103161444460.19104-100000@student.uq.edu.au> Hi, It was difficult to think of a subject line for this because I don't know what's going on. I have a function, listed below, but it returns None instead of what I think it should - which is a unicode string. The function is intended to be part of a class which will search an xml file for text from the location specified and I want it to return either a list of nodes or the value of the node. I've tried returning various things, strings, node objects, but everything is None. Some code and a sample run follows ------------------------ from string import * from xml.dom.minidom import parse import xml.dom def accessData(baseNode, accessList): #recursive function if len(accessList) == 0: print baseNode #for debug print baseNode.firstChild #for debug res = baseNode.firstChild.data print res, type(res) #for debug return res else: #Recursion code <snipped> if __name__ == '__main__': f = open('some xml file', 'r') dom = parse(f) path = 'Top.NextNode.SomeOtherNode.TheNodeIWant' al = split(path, '.') al = al[1:] print accessData(dom.documentElement, al) ------ When I run this I get the following: $python2.0 accessData.py <DOM Element: Text at 1890636> <DOM Text Node "Problem 1"> Problem 1 <type 'unicode'> #This is the value that I want returned None #This is what I'm getting returned I've also tried importing the code into an interpretter session and calling the function but I get the same results. I'm using python2.0 on solarius. Any suggestions? Thanks, Suzanne -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From jovoslav@dir.bg Fri Mar 16 06:49:25 2001 From: jovoslav@dir.bg (jovoslav@dir.bg) Date: Fri, 16 Mar 2001 08:49:25 +0200 Subject: [Tutor] asyncore and SocketServer Message-ID: <web-19853586@dir.bg> Hello, Now it's so. I'm new to python and as a small project I started writing a small chat server ( for LAN ). My first spurce code looked like this: >>> import socket >>> host = '' >>> port = 3000 >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.bind((host, port)) >>> s.listen(5) " so far so good " >>> conn, addr = s.accept() >>> while 1: >>> send_data = raw_input('kiligarikond > ') " a kind of nickname " >>> conn.send(send_data) >>> recv_data = conn.recv(1024) " for example " >>> print 'sunay > ', recv_data END OK, It run well but everything run synchronously. That was the problem. The user had to make a request and when it came on the other side, the other user was on turn. The second try was ( after examining the asyncore module documentation ): >>> import socket >>> import asyncore >>> class server(asyncore.dispatcher): >>> def __init__(self): ... host = '' ... port = 3000 ... asyncore.dispatcher.__init__(self) ... self.create_socket(socket.AF_INET, socket.SOCK_STREAM) ... self.bind((host, port)) ... self.listen(5) ... self.accept() ... >>> serv = server() >>> Now the problem. : I made my program recieving incoming connections asynchronously. But I made only this. I would be very greatfull if someone could tell me how to write the other sections of the program. Or if someone could tell me an online book about network programming in python. Or, just tell me the URL where I can find some usefull examples. Thanks very much :) J O V O !!! :^) ----------------------------- Free mail from www.dir.bg! From dyoo@hkn.eecs.berkeley.edu Fri Mar 16 08:01:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 16 Mar 2001 00:01:14 -0800 (PST) Subject: [Tutor] Method overriding In-Reply-To: <web-19790448@dir.bg> Message-ID: <Pine.LNX.4.21.0103152351520.30009-100000@hkn.eecs.berkeley.edu> On Thu, 15 Mar 2001 jovoslav@dir.bg wrote: > Hello, > Can someone please define what method overriding means. Sometimes I get the terminology all mixed up; I'll assume you want to use inheritence to override the definition of an older class. Let's take the venerable Account class as an example of using method overriding: ### >>> class Account: ... def __init__(self, balance): ... self.balance = balance ... def withdraw(self, amount): ... self.balance = self.balance - amount ... def __str__(self): ... return 'balance: %s' % self.balance ... >>> x = Account(42) >>> x.withdraw(-10) >>> print x balance: 52 ### Hmmm... that's quite interesting! We can withdraw negative amounts of money for profit! Let's say that we want to disallow negative withdrawals from an account. What we can do is take our preexisting Account class, and slightly tweak it: let's override the definition of withdraw() to be a little more stringent: ### >>> class RestrictedAccount(Account): ... def __init__(self, balance): ... Account.__init__(self, balance) ... def withdraw(self, amount): ... if amount < 0: ... print "Bad! Bad!" ... else: ... Account.withdraw(self, amount) ... >>> x = RestrictedAccount(42) >>> x.withdraw(5) >>> print x balance: 37 >>> x.withdraw(-1000) Bad! Bad! ### Hope this helps! From alan.gauld@bt.com Fri Mar 16 09:58:27 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 16 Mar 2001 09:58:27 -0000 Subject: [Tutor] "Goto"-function Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D645@mbtlipnt02.btlabs.bt.co.uk> > | > >>>os.system('clear') > this is only for Unix systems. > > | os.system('CLS') > and this is only for dos. > > For everything, use : > print "\n" * 24 Nah, that only works for 24 line terminals - xterms and VGA DIS screens(43 or 50 lines) won't work. Clearing the screen is very terminal specific - which is why there isn't a standard function for it in Python I guess. I think F/'s terminal(name?) module tries to take care of most of these differences. Alan G. who appreciates that D probably knows all that... :-) From alan.gauld@bt.com Fri Mar 16 10:57:02 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 16 Mar 2001 10:57:02 -0000 Subject: [Tutor] string matching Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D646@mbtlipnt02.btlabs.bt.co.uk> > I got a problem using Regex module, i.e. object.match Note that match only searches from the beginning of the line. Thus matching foo ewill only work in the first case balow: foobert bertfoo > object.search(string) is working just fine! The Wheras search searches for te patter anywhere within the line so both the above cases will work. Alan g From arcege@shore.net Fri Mar 16 12:49:00 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 16 Mar 2001 07:49:00 -0500 (EST) Subject: [Tutor] string matching In-Reply-To: <20010316041201.22379.qmail@web3501.mail.yahoo.com> from Cruiser at "Mar 15, 2001 8:12: 1 pm" Message-ID: <E14dtfA-0002da-00@nautilus.shore.net> > Hi, there, > I got a problem using Regex module, i.e. object.match > (string) method, in which object is a compiled regular > expression pattern, string is a string with multiple > lines (up to 6 pages!). This method can not find any > pattern except that on the first line, while > object.search(string) is working just fine! The > version of Python I use is 1.4 on Unix. I appreciate > your advice! Hi, this sounds like a problem with ".". In regular expressions, the dot expression means "match any character except newline". So if you use the simplest ".*", you will only match the first line. You can either split the string into multiple lines, or change the regular expression to match a newline as well, for example "\\(.|\\n\\)*" which match any number of "any character except newline" OR newline. I can't test this easily - my other machine with 1.4 is down - but something like: >>> import string >>> lines = string.split(multiline) >>> matches = [] >>> for line in lines: ... matches.append( (line, object.search(line)) ) ... >>> for (line, did_it_match) in matches: ... if did_it_match: ... print repr(line), 'matched' ... or (I did check this with 1.5.2's regex, regsub modules): >>> import regex, regsub >>> re_patt = '.*\\(ab.*cd\\)*' >>> multiline_re_patt = regsub.gsub('\.', '\\(.\\|\n\\)', re_patt) >>> object = regex.compile(multiline_re_patt) FYI, you can still get the official docs for Python 1.4 from the Python website. <URL: http://www.python.org/doc/1.4/> -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Fri Mar 16 12:53:37 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 16 Mar 2001 07:53:37 -0500 (EST) Subject: [Tutor] returning from a function? In-Reply-To: <Pine.OSF.4.30.0103161444460.19104-100000@student.uq.edu.au> from Suzanne Little at "Mar 16, 2001 3: 3:30 pm" Message-ID: <E14dtjd-0003BT-00@nautilus.shore.net> > Hi, > > It was difficult to think of a subject line for this because I don't know > what's going on. I have a function, listed below, but it returns None > instead of what I think it should - which is a unicode string. The > function is intended to be part of a class which will search an xml file > for text from the location specified and I want it to return either a list > of nodes or the value of the node. I've tried returning various things, > strings, node objects, but everything is None. > > Some code and a sample run follows > ------------------------ > from string import * > from xml.dom.minidom import parse > import xml.dom > > def accessData(baseNode, accessList): #recursive function > if len(accessList) == 0: > print baseNode #for debug > print baseNode.firstChild #for debug > res = baseNode.firstChild.data > print res, type(res) #for debug > return res > else: > #Recursion code <snipped> The key part may be what you snipped. Is this part returning the result of the deeper recursion of accesData? For example, are you doing something like "return accessData(baseNode, accessList[1:])"? -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From lumbricus@gmx.net Fri Mar 16 14:05:08 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Fri, 16 Mar 2001 15:05:08 +0100 (MET) Subject: [Tutor] "Goto"-function References: <5104D4DBC598D211B5FE0000F8FE7EB20751D645@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <14932.984751508@www10.gmx.net> > > | > >>>os.system('clear') > > this is only for Unix systems. > > > > | os.system('CLS') > > and this is only for dos. > > > > For everything, use : > > print "\n" * 24 > > Nah, that only works for 24 line terminals > - xterms and VGA DIS screens(43 or 50 lines) won't work. > > Clearing the screen is very terminal specific - which is > why there isn't a standard function for it in Python I guess. > Is nobody out there using curses (to get rid of terminal depenency) anymore? curses.clear() > I think F/'s terminal(name?) module tries to take care > of most of these differences. > > Alan G. > who appreciates that D probably knows all that... :-) > Grreetz all!! -- Sent through GMX FreeMail - http://www.gmx.net From kalle@gnupung.net Fri Mar 16 14:25:09 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 16 Mar 2001 15:25:09 +0100 Subject: [Tutor] asyncore and SocketServer In-Reply-To: <web-19853586@dir.bg>; from jovoslav@dir.bg on Fri, Mar 16, 2001 at 08:49:25AM +0200 References: <web-19853586@dir.bg> Message-ID: <20010316152509.A12633@father> Sez jovoslav@dir.bg: > I made my program recieving incoming connections asynchronously. > But I made only this. > I would be very greatfull if someone could tell me how to write > the other sections of the program. Or if someone could tell me an online > book about network programming in python. I'm afraid I can't help you much with asyncore, but I recently caught wind of a nice networking library that you might want to take a look at: Twisted Python at http://www.twistedmatrix.com/ I think it contains some helpful classes for writing a chat server. If you want to continue with asyncore, IIRC there is an example handler in the xmlrpclib distribution, http://www.pythonware.com/products/xmlrpc/ Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From dsh8290@rit.edu Fri Mar 16 15:44:56 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 16 Mar 2001 10:44:56 -0500 Subject: [Tutor] "Goto"-function In-Reply-To: <14932.984751508@www10.gmx.net>; from lumbricus@gmx.net on Fri, Mar 16, 2001 at 03:05:08PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D645@mbtlipnt02.btlabs.bt.co.uk> <14932.984751508@www10.gmx.net> Message-ID: <20010316104455.A15521@harmony.cs.rit.edu> On Fri, Mar 16, 2001 at 03:05:08PM +0100, J=F6rg W=F6lke wrote: | > > | > >>>os.system('clear') | > > this is only for Unix systems. | > >=20 | > > | os.system('CLS') | > > and this is only for dos. | > >=20 | > > For everything, use : | > > print "\n" * 24 | >=20 | > Nah, that only works for 24 line terminals=20 | > - xterms and VGA DIS screens(43 or 50 lines) won't work. print "\n" * sys.maxint <grin> That may take a while though. ;-) | > Clearing the screen is very terminal specific - which is=20 | > why there isn't a standard function for it in Python I guess. |=20 | Is nobody out there using curses (to get rid of terminal depenency) any= more? | curses.clear() I'm sure that unix people are using curses. The problem is that M$ doesn't think curses is important, so if you want your app to work on Windows systems it can't rely on curses. If the interpreter was built with cygwin (and it's curses port) then it would work much better. Of course the whole purpose of cygwin is to try and provide the good qualities of Unix on the other platform. Even Apple now provides Unix functionality built-in to their system (MacOS X has a *BSD kernel, also tcsh and utils like telnet). | > I think /F's terminal(name?) module tries to take care of most of | > these differences. I haven't tried his module, but I have heard that he implemented a subset of ncurses in python to provide such cross-os terminal independence. | > Alan G. | > who appreciates that D probably knows all that... :-) :-) Just for fun, I think I'll mention that my .bashrc contains "alias cls=3Dclear", so the os.system( "cls" ) technique would work for my login shells (only if it is lowercase though). -D From douglas.shawhan@ae.ge.com Fri Mar 16 17:33:02 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Fri, 16 Mar 2001 12:33:02 -0500 Subject: [Tutor] sio equivalent for unix? (was: Communicating with serial port) Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F255C@ma001dataaege.ae.ge.com> Is there a similar module for unix? I am a little confused as to how one can get data from the serial port! -----Original Message----- From: Mike Callahan [mailto:mcalla@home.com] Sent: Thursday, March 15, 2001 4:57 PM To: python-list@python.org Subject: Re: Communicating with serial port Peter, I recently finished a program using Roger's latest version of Sio and it worked well with Python 2.0. Mike Callahan "Peter Blom" <pet-blo@online.no> wrote in message news:ndNn6.5161$t21.152593@news3.oke.nextra.no... > I shall write a python program for downloading data from a memory card in a > measuring instrument, via a serial port. > For this purpose, I have downloaded SioModule.zip - a serial comm extension > for windows 95, upgraded to Python 1.5.1. > This does not seem to work - when importing the module 'serial.py', my > system hangs (Windows 98, Activestate Python 2.0). > Could anybody give a hint? > > Peter (a newbie) > > -- http://mail.python.org/mailman/listinfo/python-list From douglas.shawhan@ae.ge.com Fri Mar 16 17:34:51 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Fri, 16 Mar 2001 12:34:51 -0500 Subject: [Tutor] Signals Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F255D@ma001dataaege.ae.ge.com> I have since found a different device that uses the serial port. Is there a standard module that will grab from the serial port? -----Original Message----- From: alan.gauld@bt.com [mailto:alan.gauld@bt.com] Sent: Wednesday, March 14, 2001 5:26 AM To: douglas.shawhan@ae.ge.com; tutor@python.org Subject: RE: [Tutor] Signals > Where is a good tutorial for signals? Let's first confirm what you mean by 'signals'. Which OS? - I normally associate signals with *nix and its signal() system call, but you might be meaning the more general meaning of catching interrupts or some other kind of 'signal' from hardware... > I have a need to parse data from an ISA bus > board to a database. So the hardware raises an interrupt which is translated into a *nix signal? You then want to read from the hardware (via an IO port?) and store the parsed data in a database? If so, then the best place to start is at the low level C signal call and the hardware vendors specs for reading the IO port... Alternatively if you have the excellent O'Reilly book "Unix Systems Programming" look it up in there. If that's a wrong interpretation of your request please clarify and ask about the specific thing you need help with. Alan G. From bchai@informatics.jax.org Fri Mar 16 17:43:58 2001 From: bchai@informatics.jax.org (Benli Chai) Date: Fri, 16 Mar 2001 12:43:58 -0500 Subject: [Tutor] string matching In-Reply-To: <E14dtfA-0002da-00@nautilus.shore.net> References: <E14dtfA-0002da-00@nautilus.shore.net> Message-ID: <a05010401b6d800caeba4@[192.233.41.26]> >Thank you very much for your suggestions. I'm going to try it out. B.C. > Hi, there, >> I got a problem using Regex module, i.e. object.match >> (string) method, in which object is a compiled regular >> expression pattern, string is a string with multiple >> lines (up to 6 pages!). This method can not find any >> pattern except that on the first line, while >> object.search(string) is working just fine! The >> version of Python I use is 1.4 on Unix. I appreciate >> your advice! > >Hi, this sounds like a problem with ".". In regular expressions, the >dot expression means "match any character except newline". So if you >use the simplest ".*", you will only match the first line. You can >either split the string into multiple lines, or change the regular >expression to match a newline as well, for example "\\(.|\\n\\)*" which >match any number of "any character except newline" OR newline. > >I can't test this easily - my other machine with 1.4 is down - but >something like: >>>> import string >>>> lines = string.split(multiline) >>>> matches = [] >>>> for line in lines: >... matches.append( (line, object.search(line)) ) >... >>>> for (line, did_it_match) in matches: >... if did_it_match: >... print repr(line), 'matched' >... > >or (I did check this with 1.5.2's regex, regsub modules): >>>> import regex, regsub >>>> re_patt = '.*\\(ab.*cd\\)*' >>>> multiline_re_patt = regsub.gsub('\.', '\\(.\\|\n\\)', re_patt) >>>> object = regex.compile(multiline_re_patt) > >FYI, you can still get the official docs for Python 1.4 from the >Python website. <URL: http://www.python.org/doc/1.4/> > > -Arcege > >-- >------------------------------------------------------------------------ >| Michael P. Reilly, Release Manager | Email: arcege@shore.net | >| Salem, Mass. USA 01970 | | >------------------------------------------------------------------------ > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Fri Mar 16 17:23:35 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 16 Mar 2001 17:23:35 -0000 Subject: [Tutor] "Goto"-function Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D64E@mbtlipnt02.btlabs.bt.co.uk> > Is nobody out there using curses (to get rid of terminal > depenency) anymore? > curses.clear() Yes but Python curses is only available on *nix. There is allegedly a way to get the DOS curses working but I failed miserably to make it work :-( Alan g From alan.gauld@bt.com Fri Mar 16 17:44:33 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 16 Mar 2001 17:44:33 -0000 Subject: [Tutor] Signals Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D650@mbtlipnt02.btlabs.bt.co.uk> > I have since found a different device that uses the serial > port. Is there a standard module that will grab from the > serial port? Have a look at fcntl, termios and tty and see if they will help. Basically Python provides a very thin wrapper over the Unix C functions. Alan G. From lumbricus@gmx.net Fri Mar 16 20:05:41 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Fri, 16 Mar 2001 21:05:41 +0100 (MET) Subject: [Tutor] sio equivalent for unix? (was: Communicating with serial port) References: <326FFBE574BED411ACA100D0B79DC2B53F255C@ma001dataaege.ae.ge.com> Message-ID: <23473.984773141@www10.gmx.net> > > Is there a similar module for unix? > > I am a little confused as to how one can get data from the serial port! > On *nix the file-methods/functions should work on /dev/tty* Greetings !!! > Subject: Re: Communicating with serial port > > -- > http://mail.python.org/mailman/listinfo/python-list > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From gruschow2@hotmail.com Sat Mar 17 04:18:14 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Fri, 16 Mar 2001 22:18:14 -0600 Subject: [Tutor] how to retrieve values from scale widget(sample code is attached)???? Message-ID: <F85hvqgStMVhEUsebms0000239c@hotmail.com> how to retrieve values from scale widget(sample code is attached)???? I can figure out frames and the basic widget formats themselves, but I can't figure out how to retrieve data from this widget so I can use it as input data in some other part of a program. Can you help??? (BTW, I think I am getting my clock program figured out (I think), that I was asking about earlier) gruschow2@hotmail.com Charles Gruschow ********************SAMPLE CODE BELOW**************** #!/usr/local/bin/python from Tkinter import * import sys import string def die(event): sys.exit(0) def reader(s): global label f = string.atoi(s) f = f - 32 c = f/9. c = c * 5. flabel["text"] = "Degrees Fahrenheit: %s" % (s) label["text"] = "Degrees Celsius: %d" % (int(c)) root = Tk() button = Button(root,width=25) button["text"] = "Quit" button.bind("<Button>",die) button.pack() flabel = Label(root,text="Degrees Fahrenheit:") flabel.pack(anchor=W) frame=Frame(root) scale2 = Scale(frame, orient=VERTICAL,from_=-40,to=212,width=10, length=100,sliderlength=20,troughcolor="cyan",command=reader) scale2.pack(side=LEFT) frame.pack(anchor=W) label = Label(root,text="Degrees Celsius:") label.pack(anchor=W) root.title("Fahrenheit to Celsius") root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From gruschow2@hotmail.com Sat Mar 17 04:19:04 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Fri, 16 Mar 2001 22:19:04 -0600 Subject: [Tutor] how to retrieve values from scale widget(sample code is attached)???? Message-ID: <F57S1DknvCesa31Z9cP00002350@hotmail.com> how to retrieve values from scale widget(sample code is attached)???? I can figure out frames and the basic widget formats themselves, but I can't figure out how to retrieve data from this widget so I can use it as input data in some other part of a program. Can you help??? (BTW, I think I am getting my clock program figured out (I think), that I was asking about earlier) gruschow2@hotmail.com Charles Gruschow ********************SAMPLE CODE BELOW**************** #!/usr/local/bin/python from Tkinter import * import sys import string def die(event): sys.exit(0) def reader(s): global label f = string.atoi(s) f = f - 32 c = f/9. c = c * 5. flabel["text"] = "Degrees Fahrenheit: %s" % (s) label["text"] = "Degrees Celsius: %d" % (int(c)) root = Tk() button = Button(root,width=25) button["text"] = "Quit" button.bind("<Button>",die) button.pack() flabel = Label(root,text="Degrees Fahrenheit:") flabel.pack(anchor=W) frame=Frame(root) scale2 = Scale(frame, orient=VERTICAL,from_=-40,to=212,width=10, length=100,sliderlength=20,troughcolor="cyan",command=reader) scale2.pack(side=LEFT) frame.pack(anchor=W) label = Label(root,text="Degrees Celsius:") label.pack(anchor=W) root.title("Fahrenheit to Celsius") root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From s349929@student.uq.edu.au Sat Mar 17 08:45:24 2001 From: s349929@student.uq.edu.au (Suzanne Little) Date: Sat, 17 Mar 2001 18:45:24 +1000 (GMT+1000) Subject: [Tutor] returning from a function? In-Reply-To: <E14dtjd-0003BT-00@nautilus.shore.net> Message-ID: <Pine.OSF.4.30.0103171841200.18402-100000@student.uq.edu.au> Sorry but I don't have access to the snipped part at the moment. It doesn't contain any return statements or print statements. All output comes from the final case which is the code listed. In general terms the snipped section takes the first string from the list and finds it within the child nodes of the base node and then calls accessData again with the new base node and the string removed from the list. It's a little more complicated than that to cope with potential doubles and selecting between them based on a supplied attribute value (eg: 'id=3'). Hopefully that makes it clear enough. Thanks, Suzanne On Fri, 16 Mar 2001, Michael P. Reilly wrote: > > Hi, > > > > It was difficult to think of a subject line for this because I don't know > > what's going on. I have a function, listed below, but it returns None > > instead of what I think it should - which is a unicode string. The > > function is intended to be part of a class which will search an xml file > > for text from the location specified and I want it to return either a list > > of nodes or the value of the node. I've tried returning various things, > > strings, node objects, but everything is None. > > > > Some code and a sample run follows > > ------------------------ > > from string import * > > from xml.dom.minidom import parse > > import xml.dom > > > > def accessData(baseNode, accessList): #recursive function > > if len(accessList) == 0: > > print baseNode #for debug > > print baseNode.firstChild #for debug > > res = baseNode.firstChild.data > > print res, type(res) #for debug > > return res > > else: > > #Recursion code <snipped> > > The key part may be what you snipped. Is this part returning the > result of the deeper recursion of accesData? For example, are you > doing something like "return accessData(baseNode, accessList[1:])"? > > -Arcege > > -- > ------------------------------------------------------------------------ > | Michael P. Reilly, Release Manager | Email: arcege@shore.net | > | Salem, Mass. USA 01970 | | > ------------------------------------------------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From dsh8290@rit.edu Sat Mar 17 18:39:50 2001 From: dsh8290@rit.edu (D-Man) Date: Sat, 17 Mar 2001 13:39:50 -0500 Subject: [Tutor] returning from a function? In-Reply-To: <Pine.OSF.4.30.0103171841200.18402-100000@student.uq.edu.au>; from s349929@student.uq.edu.au on Sat, Mar 17, 2001 at 06:45:24PM +1000 References: <E14dtjd-0003BT-00@nautilus.shore.net> <Pine.OSF.4.30.0103171841200.18402-100000@student.uq.edu.au> Message-ID: <20010317133950.A20772@harmony.cs.rit.edu> On Sat, Mar 17, 2001 at 06:45:24PM +1000, Suzanne Little wrote: | Sorry but I don't have access to the snipped part at the moment. It | doesn't contain any return statements or print statements. <snip> | Hopefully that makes it clear enough. It does. What you have is essentially, def func( some , args ) : if terminating_condition : return "some value" else : # call a function (this one) but DON"T return its return value func( some , different_args ) The result is if the condition is not true the first time the function is called, it won't return anything because that is the only place it has a return statement. To correct it, add 'return' in the else clause to return the value that is returned by the last recursive call. def func( some , args ) : if terminating_condition : return "some value" else : # call a function (this one) and return its return value return func( different , args ) This should solve your problem. This is a bit different than Lisp or Scheme. Lisp and Scheme implicitly return the return value from the last expression in the function. So if you had (def func (some args) (if terminating_condition "some value" (func different args))) it would have worked as expected, returning "some value" from the last invocation and propagating it up the stack to the first caller. (Actually, Scheme is cool because it optimizes tail-recursive functions like this so that almost all of the stack operations are eliminated and the last invocation returns directly to the first caller) -D From britt_green@hotmail.com Sun Mar 18 00:10:12 2001 From: britt_green@hotmail.com (Britt Green) Date: Sat, 17 Mar 2001 16:10:12 -0800 Subject: [Tutor] FTP Bug? Message-ID: <F225j1HaKtKufVma0os00003213@hotmail.com> Well, my FTP program that I've been working on is almost done. It works...almost! Occasionally when I run it I get this error message: Traceback (innermost last): File "C:\Program Files\Python20\Code\dirs.py", line 143, in ? dirListing = getftplist(ftp) File "C:\Program Files\Python20\Code\dirs.py", line 36, in getftplist conn = ftp.transfercmd('LIST') File "c:\program files\python20\lib\ftplib.py", line 297, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "c:\program files\python20\lib\ftplib.py", line 283, in ntransfercmd sock = self.makeport() File "c:\program files\python20\lib\ftplib.py", line 254, in makeport resp = self.sendport(host, port) File "c:\program files\python20\lib\ftplib.py", line 244, in sendport return self.voidcmd(cmd) File "c:\program files\python20\lib\ftplib.py", line 234, in voidcmd return self.voidresp() File "c:\program files\python20\lib\ftplib.py", line 209, in voidresp resp = self.getresp() File "c:\program files\python20\lib\ftplib.py", line 195, in getresp resp = self.getmultiline() File "c:\program files\python20\lib\ftplib.py", line 181, in getmultiline line = self.getline() File "c:\program files\python20\lib\ftplib.py", line 168, in getline line = self.file.readline() File "c:\program files\python20\lib\socket.py", line 221, in readline new = self._sock.recv(self._rbufsize) error: (10054, 'Connection reset by peer') Might anyone know what causes this, and how to solve it? _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From britt_green@hotmail.com Sun Mar 18 03:16:19 2001 From: britt_green@hotmail.com (Britt Green) Date: Sat, 17 Mar 2001 19:16:19 -0800 Subject: [Tutor] Making Python Find Modules Message-ID: <F218881Np7vXee4fDGC00003245@hotmail.com> I know that the answer to this question must be painfully obvious, but I can't seem to find it anywhere. If I have a folder called Code in my Python directory, how can I make Python see the modules that are in there? This is on a WinNT box. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sheila@spamcop.net Sun Mar 18 09:33:57 2001 From: sheila@spamcop.net (Sheila King) Date: Sun, 18 Mar 2001 01:33:57 -0800 Subject: [Tutor] Help with 500 error on cgi script Message-ID: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> OK, I'm at my wits end. I have Apache running on my local Win98 machine, and I have one simple python cgi script, equivalent to "Hello, World!", that I have been able to run. Today I thought I would start to play with the cgi module and start doing some forms and so forth. Well, I was getting 500 internal server errors. I've checked everything. The path, etc... So, finally, I tried just running cgi.test(), as recommended in the Python tutorial. It worked splendidly. I also have the Python Core Programming book, from Wesley Chun, that comes with a CD-ROM and I put up his friends.htm and friends1.py files from the CD onto my local site, and it ran just fine, also. I've compared my file to the other two files and just can't see what I'm doing wrong. So, here is my script. I'm sure someone here will see it right off? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ #!/usr/bin/env python import cgi form = cgi.FieldStorage() form_ok = 0 if form.has_key("subscriberEmail") and form.has_key("command"): form_ok = 1 if not form_ok: output = '''Content-type: text/html\n\n <html> <Head> <Title>Error in Form</Title> </Head>\n <Body>\n <H1>Error</H1> You have not filled out all necessary information to complete this request You <b>MUST</b> fill in your subscriber e-mail in the From: box and you <b>MUST</b> select some action to modify your delivery options. Please use the back button on your browser to return to the form and fill in the required information </body>\n</html> ''' print output else: for k in form.keys(): print k, " : ", form[k] print "All done!" From pdiaz88@terra.es Sun Mar 18 10:51:13 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sun, 18 Mar 2001 11:51:13 +0100 Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> Message-ID: <01031811511300.12014@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Remember to put the "Content-type: text/html" line first? Every cgi has to inform about the content is going to show since that cannot be know by the webserver. In every CGI you make, the golden rule is: Start with: print "Content-type: text/html\n" Cheers Pedro On Sunday 18 March 2001 10:33, Sheila King wrote: > OK, I'm at my wits end. > > I have Apache running on my local Win98 machine, and I have one simple > python cgi script, equivalent to "Hello, World!", that I have been able to > run. > > Today I thought I would start to play with the cgi module and start doing > some forms and so forth. > > Well, I was getting 500 internal server errors. I've checked everything. > The path, etc... > > So, finally, I tried just running cgi.test(), as recommended in the Python > tutorial. It worked splendidly. > > I also have the Python Core Programming book, from Wesley Chun, that comes > with a CD-ROM and I put up his friends.htm and friends1.py files from the > CD onto my local site, and it ran just fine, also. > > I've compared my file to the other two files and just can't see what I'm > doing wrong. > > So, here is my script. I'm sure someone here will see it right off? > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > > #!/usr/bin/env python > > > import cgi > > form = cgi.FieldStorage() > form_ok = 0 > > if form.has_key("subscriberEmail") and form.has_key("command"): > form_ok = 1 > if not form_ok: > output = '''Content-type: text/html\n\n > <html> > <Head> > <Title>Error in Form</Title> > </Head>\n > <Body>\n > <H1>Error</H1> > You have not filled out all necessary information to complete this request > You <b>MUST</b> fill in your subscriber e-mail in the From: box > and you <b>MUST</b> select some action to modify your delivery options. > Please use the back button on your browser to return to the form and fill > in the required information > </body>\n</html> > ''' > print output > else: > for k in form.keys(): > print k, " : ", form[k] > print "All done!" > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6tJMqnu53feEYxlERAvNXAKDRCEhW5UCIt8xVtMaJYVb2wuUNcgCgzl// GMBCEP1FJEwLqrD15RblXYo= =Vcx+ -----END PGP SIGNATURE----- From sheila@thinkspot.net Sun Mar 18 09:54:30 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 18 Mar 2001 01:54:30 -0800 Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> Message-ID: <B4F4C075E@kserver.org> On Sun, 18 Mar 2001 09:33:57 GMT, Sheila King <sheila@spamcop.net> wrote in comp.lang.python in article <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com>: :So, here is my script. I'm sure someone here will see it right off? Additionally, here is the error log's last entry: [Sun Mar 18 01:35:53 2001] [error] [client x.x.xxx.xxx] Premature end of script headers: e:/apache/cgi-bin/testform.py [Sun Mar 18 01:35:53 2001] [error] [client x.x.xxx.xxx] File "e:/apache/cgi-bin/testform.py", line 30 [Sun Mar 18 01:35:53 2001] [error] [client x.x.xxx.xxx] print k, " : ", form[k] [Sun Mar 18 01:35:53 2001] [error] [client x.x.xxx.xxx] ^ [Sun Mar 18 01:35:53 2001] [error] [client x.x.xxx.xxx] IndentationError: expected an indented block -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Sun Mar 18 09:58:25 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 18 Mar 2001 01:58:25 -0800 Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <01031811511300.12014@tajo> References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <01031811511300.12014@tajo> Message-ID: <EDA3B791D@kserver.org> On Sun, 18 Mar 2001 11:51:13 +0100, Pedro Diaz Jimenez <pdiaz88@terra.es> wrote about Re: [Tutor] Help with 500 error on cgi script: :Remember to put the "Content-type: text/html" line first? : :Every cgi has to inform about the content is going to show since that cannot :be know by the webserver. In every CGI you make, the golden rule is: : :Start with: :print "Content-type: text/html\n" Yes, if you look at the script that I posted, you will see that that line is there. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From arcege@shore.net Sun Mar 18 11:49:41 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 18 Mar 2001 06:49:41 -0500 (EST) Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <EDA3B791D@kserver.org> from Sheila King at "Mar 18, 2001 1:58:25 am" Message-ID: <E14ebgr-0005jO-00@nautilus.shore.net> > On Sun, 18 Mar 2001 11:51:13 +0100, Pedro Diaz Jimenez <pdiaz88@terra.es> > wrote about Re: [Tutor] Help with 500 error on cgi script: > > :Remember to put the "Content-type: text/html" line first? > : > :Every cgi has to inform about the content is going to show since that cannot > :be know by the webserver. In every CGI you make, the golden rule is: > : > :Start with: > :print "Content-type: text/html\n" > > Yes, if you look at the script that I posted, you will see that that line is > there. > It it only output when form_ok == 1, not otherwise. You just output the data with not MIME header. But based on the log output, it looks like the real error is that after the for loop, the print is not indented (you are getting an IndentationError exception in the errorlog). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Sun Mar 18 11:58:43 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 18 Mar 2001 06:58:43 -0500 (EST) Subject: [Tutor] Making Python Find Modules In-Reply-To: <F218881Np7vXee4fDGC00003245@hotmail.com> from Britt Green at "Mar 17, 2001 7:16:19 pm" Message-ID: <E14ebpb-0006DF-00@nautilus.shore.net> > I know that the answer to this question must be painfully obvious, but I > can't seem to find it anywhere. If I have a folder called Code in my Python > directory, how can I make Python see the modules that are in there? This is > on a WinNT box. There are two ways, inside python or within the environment. 1. Add the directory to the path: >>> import sys >>> sys.path.insert(0, r'c:\python20\Code') 2. Create a new environment variable: open the system properties and add 'PYTHONPATH' with your directory to the user environment section. If a path already exists, append the directory with a semicolon (;). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dyoo@hkn.eecs.berkeley.edu Sun Mar 18 13:15:49 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 18 Mar 2001 05:15:49 -0800 (PST) Subject: [Tutor] Making Python Find Modules In-Reply-To: <F218881Np7vXee4fDGC00003245@hotmail.com> Message-ID: <Pine.LNX.4.21.0103180508160.4566-100000@hkn.eecs.berkeley.edu> On Sat, 17 Mar 2001, Britt Green wrote: > I know that the answer to this question must be painfully obvious, but I > can't seem to find it anywhere. If I have a folder called Code in my Python > directory, how can I make Python see the modules that are in there? This is > on a WinNT box. One other thing you might need besides PYTHONPATH, if you have subdirectories in your Code directory, is an '__init__.py' file. Let's say that we have the following directory structure: /Code/ Math/ SecretPlans/ Even if we add Code to your PYTHONPATH, Python will not automatically look at directories within Code; I'm not quite sure why, but that's the default behavior. To fix this, all we need is to put an __init__.py file within both the /Code/Math and /Code/SecretPlans directories. __init__.py can even be an empty file, but as long as it exists, it marks a subdirectory as prime material for module stuff. http://python.org/doc/current/tut/node8.html covers a lot of the details about modules, so you might want to read this when you get the chance. Good luck to you. From kalle@gnupung.net Sun Mar 18 13:24:49 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sun, 18 Mar 2001 14:24:49 +0100 Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com>; from sheila@spamcop.net on Sun, Mar 18, 2001 at 01:33:57AM -0800 References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> Message-ID: <20010318142449.A359@apone.network.loc> Sez Sheila King: > So, here is my script. I'm sure someone here will see it right off? > #!/usr/bin/env python > > > import cgi > > form = cgi.FieldStorage() > form_ok = 0 > > if form.has_key("subscriberEmail") and form.has_key("command"): > form_ok = 1 > if not form_ok: > output = '''Content-type: text/html\n\n > <html> > <Head> > <Title>Error in Form</Title> > </Head>\n > <Body>\n > <H1>Error</H1> > You have not filled out all necessary information to complete this request > You <b>MUST</b> fill in your subscriber e-mail in the From: box > and you <b>MUST</b> select some action to modify your delivery options. > Please use the back button on your browser to return to the form and fill > in the required information > </body>\n</html> > ''' > print output > else: Problem 1: No print "Content-type: text/html\n" here... > for k in form.keys(): > print k, " : ", form[k] Problem 2: The line above should be indented. > print "All done!" > Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From dyoo@hkn.eecs.berkeley.edu Sun Mar 18 13:25:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 18 Mar 2001 05:25:42 -0800 (PST) Subject: [Tutor] Help with 500 error on cgi script In-Reply-To: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> Message-ID: <Pine.LNX.4.21.0103180518040.4566-100000@hkn.eecs.berkeley.edu> On Sun, 18 Mar 2001, Sheila King wrote: > if form.has_key("subscriberEmail") and form.has_key("command"): > form_ok = 1 > if not form_ok: > output = '''Content-type: text/html\n\n I think it's an indentation error. For example, these two statements have slightly inconsistant indentation --- I don't think Python will dock you for it for this particular case, but you'll want to be careful. [some time later] Ah! Noooo! It IS indentation, but in a very very evil disguise! > print k, " : ", form[k] This particular line above, although it doesn't show it, has a mixture of tabs and spaces. When you're indenting, stick with either tabs, or spaces, but don't use both. That's why that line is complaining. I think Guido mentions his opinion on what to use for indentation: http://python.org/doc/essays/styleguide.html In short, use spaces. *grin* Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sun Mar 18 13:44:30 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 18 Mar 2001 05:44:30 -0800 (PST) Subject: [Tutor] FTP Bug? In-Reply-To: <F225j1HaKtKufVma0os00003213@hotmail.com> Message-ID: <Pine.LNX.4.21.0103180533580.4827-100000@hkn.eecs.berkeley.edu> On Sat, 17 Mar 2001, Britt Green wrote: > Well, my FTP program that I've been working on is almost done. It > works...almost! Occasionally when I run it I get this error message: > error: (10054, 'Connection reset by peer') If your FTP program is idle (the adjective, not the editor), I think ftp servers are free to reset the connection, since it looks like it's not being used. Not quite sure what do to about this, as even Internet Explorer shows this to me every once in a while. *grin* My suggestion is to use a try/except block to detect this situation, and if it occurs, to try to reestablish the connection and go for it again. So something like: ### try: ## Do stuff except socket.error: if not reestablishConnection(): print "Oh no!" ### (Although there's probably a little more code involved than this.) Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sun Mar 18 13:50:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 18 Mar 2001 05:50:07 -0800 (PST) Subject: [Tutor] how to retrieve values from scale widget(sample code is attached)???? In-Reply-To: <F57S1DknvCesa31Z9cP00002350@hotmail.com> Message-ID: <Pine.LNX.4.21.0103180545480.4827-100000@hkn.eecs.berkeley.edu> On Fri, 16 Mar 2001, Charles Gruschow wrote: > I can figure out frames and the basic widget formats themselves, but I can't > figure out how to retrieve data from this widget so I can use it as input > data in some other part of a program. Dear Charles, Sorry for the long delay! Try to use the get() method of your scale widget, and you should be able to read off its value. Here's a sample bit of code that shows how to do this. ### from Tkinter import * s = Scale() s.pack(side=TOP) def reportScaleValue(scale = s): print s.get() b = Button(text="Press me!", command=reportScaleValue) b.pack(side=TOP) mainloop() ### Good luck! From dsh8290@rit.edu Sun Mar 18 19:08:28 2001 From: dsh8290@rit.edu (D-Man) Date: Sun, 18 Mar 2001 14:08:28 -0500 Subject: [Tutor] Making Python Find Modules In-Reply-To: <Pine.LNX.4.21.0103180508160.4566-100000@hkn.eecs.berkeley.edu>; from dyoo@hkn.eecs.berkeley.edu on Sun, Mar 18, 2001 at 05:15:49AM -0800 References: <F218881Np7vXee4fDGC00003245@hotmail.com> <Pine.LNX.4.21.0103180508160.4566-100000@hkn.eecs.berkeley.edu> Message-ID: <20010318140828.A22766@harmony.cs.rit.edu> On Sun, Mar 18, 2001 at 05:15:49AM -0800, Daniel Yoo wrote: | On Sat, 17 Mar 2001, Britt Green wrote: | | One other thing you might need besides PYTHONPATH, if you have | subdirectories in your Code directory, is an '__init__.py' file. Let's | say that we have the following directory structure: | | | /Code/ | | Math/ | SecretPlans/ | | Even if we add Code to your PYTHONPATH, Python will not automatically look | at directories within Code; I'm not quite sure why, but that's the default I think it is related to packages vs. modules. A directory containing __init__.py is a package. I'm not to clear on the particulars and why one would want to use a package instead of a module though. -D From bwgolling@home.com Sun Mar 18 14:44:41 2001 From: bwgolling@home.com (bwgolling) Date: Sun, 18 Mar 2001 14:44:41 -0000 Subject: [Tutor] Which modules have been imported? Message-ID: <001001c0afb9$f7b022a0$bb510941@corlis1.pa.home.com> This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C0AFB9.F74B6D60 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello All, I am trying to learn Python but am having a problem keeping up with = which modules I have loaded. I discovered somewhat by accident that I = can unload a module with 'del', but is there a command that will print a = list of exactly what modules are still loaded? Tks Bruce ------=_NextPart_000_000D_01C0AFB9.F74B6D60 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Dwindows-1252"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Hello All,</FONT></DIV> <DIV><FONT size=3D2>I am trying to learn Python but am having a problem = keeping up=20 with which modules I have loaded. I discovered somewhat by = accident that I=20 can unload a module with 'del', but is there a command that will print a = list of=20 exactly what modules are still loaded?</FONT></DIV> <DIV><FONT size=3D2>Tks</FONT></DIV> <DIV><FONT size=3D2>Bruce</FONT></DIV></BODY></HTML> ------=_NextPart_000_000D_01C0AFB9.F74B6D60-- From scarblac@pino.selwerd.nl Sun Mar 18 20:07:49 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 18 Mar 2001 21:07:49 +0100 Subject: [Tutor] Which modules have been imported? In-Reply-To: <001001c0afb9$f7b022a0$bb510941@corlis1.pa.home.com>; from bwgolling@home.com on Sun, Mar 18, 2001 at 02:44:41PM -0000 References: <001001c0afb9$f7b022a0$bb510941@corlis1.pa.home.com> Message-ID: <20010318210749.A8120@pino.selwerd.nl> On Sun, Mar 18, 2001 at 02:44:41PM -0000, bwgolling wrote: > I am trying to learn Python but am having a problem keeping up with which > modules I have loaded. I discovered somewhat by accident that I can unload > a module with 'del', but is there a command that will print a list of > exactly what modules are still loaded? A module isn't actually unloaded when you del it, it's simply not accessible under that name anymore in the current namespace. If you want to know all the names in the current namespace, use dir(). All the modules currently loaded in the system are in sys.modules. So import sys and print sys.modules. (For a nicer way to view it, use prettyprint: import sys, pprint pprint.pprint(sys.modules) ) But usually there's no need to unload modules. -- Remco Gerlich From sheila@thinkspot.net Sun Mar 18 20:11:07 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 18 Mar 2001 12:11:07 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <m37l1m282u.fsf@master.athome> References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> Message-ID: <237AE660FEF@kserver.org> [reply e-mailed to Andrew and posted to the Python Tutor list] On 18 Mar 2001 20:25:13 +0100, Andrew Markebo <email-withheld> wrote about Re: Help with 500 error on cgi script: :Hi again.. Hope you got your code straightened out?? :[...] :| print output :| else: :| print "<H1>Good Result!</H1> :| print "</body>\n</html>" :| """ for k in form.keys(): :| print k, " : ", form[k] :| print "All done!""" : :The """ and """ at the end here looks weird.. : :You said it worked when you ran it alone?? : : /Andy : Thanks to everyone who has sent me suggestions. It has helped a great deal. I've made considerable progress. The """ were to comment out parts of the script to help me see what was going wrong. Anyhow, as near as I can tell, it ended up to be problems with whitespace/indentation/tab-vs-space or something like that. I have gotten it to run on my home machine, using my local install of Apache web server. Now I'm trying to get it to run on my web host. I don't know if anyone on the list can help with this or not, but hey...I guess I can post it and see if it does any good? (I've also got a request for assistance in at my web host...although technically they "don't support" custom installed software. Sometimes they're pretty nice and help anyways.) My script is running fine now on my home web server, but when I put it on my webhost, and after making sure that it was uploaded in ASCII, file permissions set correctly, and path to the interpreter is correct, I am getting this message in the error log: %% [Sun Mar 18 14:52:25 2001] POST /cgi-bin/listsettings.py HTTP/1.0 %% 500 /big/dom/xthinkspot/cgi-bin/listsettings.py %request Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* Accept-Charset: iso-8859-1,*,utf-8 Accept-Encoding: gzip Accept-Language: en,de-DE,fr,ru,ko,zh,zh-CN,zh-TW,cs Connection: Keep-Alive Content-length: 88 Content-type: application/x-www-form-urlencoded Host: www.thinkspot.net Referer: http://www.thinkspot.net/sheila/computers/listManagement.html User-Agent: Mozilla/4.61 [en] (Win98; U) require-subscriberEmail=bob%40kserver.org&require-command=NODIGEST&Submit=Submit+Changes %response %stderr Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 'import site' failed; use -v for traceback Traceback (most recent call last): File "listsettings.py", line 5, in ? import cgi ImportError: No module named cgi So, somehow it is not finding the installed libraries, which are there and do work. I went to the directory where I have Python-2.0 installed, and invoked the interpreter, and at the prompt typed: >>>import cgi >>>cgi.test() and it rattled off its test script. I tried going to my home directory, and editing my .bash-profile directory, so that the PATH file includes: /big/dom/xthinkspot/Python-2.0 which is the path to my private install of Python-2.0, but it doesn't seem to have helped. Anyhow, this problem is off-topic for this list, but if anyone has an idea what I'm doing wrong, I wouldn't mind a tip. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From deirdre@deirdre.net Sun Mar 18 21:08:42 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 18 Mar 2001 13:08:42 -0800 (PST) Subject: [Tutor] SpamCop detained your email (fwd) Message-ID: <Pine.LNX.4.31.0103181306440.15738-100000@emperor.deirdre.org> Just a note. To lower the burden on tutor admins, anyone who subscribes to the tutor list should add the list address and the list admin address. I'm *not* going to reply to these; I will simply delete the person from the list to avoid the burden of dealing with them. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams ---------- Forwarded message ---------- Date: Sun, 18 Mar 2001 04:35:12 -0500 From: SpamCop email filter <nobody@spamcop.net> To: tutor-admin@python.org Subject: SpamCop detained your email You have attempted to send a message to sheila@spamcop.net. The subject of your message was "Auto-response for your message to tutor@python.org". The recipient (or one of the recipients) of this message subscribes to SpamCop, a system that filters unwanted email, to cut down on electronic "junk mail." We apologize for the inconvenience, but SpamCop needs to see if you are sending from a valid address before it can allow your message to go through. This only happens the first time you try to send an email, so you won't see this message again. From sheila@thinkspot.net Sun Mar 18 22:21:05 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 18 Mar 2001 14:21:05 -0800 Subject: [Tutor] SpamCop detained your email (fwd) In-Reply-To: <Pine.LNX.4.31.0103181306440.15738-100000@emperor.deirdre.org> References: <Pine.LNX.4.31.0103181306440.15738-100000@emperor.deirdre.org> Message-ID: <2AB577A2EB9@kserver.org> On Sun, 18 Mar 2001 13:08:42 -0800 (PST), Deirdre Saoirse <deirdre@deirdre.net> wrote about [Tutor] SpamCop detained your email (fwd): :To: <tutor@python.org> :Subject: [Tutor] SpamCop detained your email (fwd) :From: Deirdre Saoirse <deirdre@deirdre.net> :Date: Sun, 18 Mar 2001 13:08:42 -0800 (PST) : :Just a note. To lower the burden on tutor admins, anyone who subscribes to :the tutor list should add the list address and the list admin address. :I'm *not* going to reply to these; I will simply delete the person from :the list to avoid the burden of dealing with them. : :-- :_Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net :"I love deadlines. I like the whooshing sound they make as they fly by." : - Douglas Adams I'm sorry about that. It was a mistake. I did not intend to post to this list from my spamcop address. I usually only use that in newsgroups. I use my *real* address on lists. The problem occurred because I cross-posted to this list and comp.lang.python. It shouldn't happen again. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From kstoner@netins.net Sun Mar 18 22:58:50 2001 From: kstoner@netins.net (Katharine Stoner) Date: Sun, 18 Mar 2001 16:58:50 -0600 Subject: [Tutor] making executables Message-ID: <001001c0afff$001a0380$3d52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C0AFCC.B4D7BAC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi python people, How do you make a python program executable so it will run independently = of the GUI? thanks Cameron ------=_NextPart_000_000D_01C0AFCC.B4D7BAC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi python people,</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>How do you make a python program = executable so it=20 will run independently of the GUI?</FONT></DIV> <DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV></BODY></HTML> ------=_NextPart_000_000D_01C0AFCC.B4D7BAC0-- From dsh8290@rit.edu Sun Mar 18 23:46:07 2001 From: dsh8290@rit.edu (D-Man) Date: Sun, 18 Mar 2001 18:46:07 -0500 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <237AE660FEF@kserver.org>; from sheila@thinkspot.net on Sun, Mar 18, 2001 at 12:11:07PM -0800 References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> Message-ID: <20010318184607.A22841@harmony.cs.rit.edu> On Sun, Mar 18, 2001 at 12:11:07PM -0800, Sheila King wrote: | | Could not find platform independent libraries <prefix> | Could not find platform dependent libraries <exec_prefix> | Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] | 'import site' failed; use -v for traceback | Traceback (most recent call last): | File "listsettings.py", line 5, in ? | import cgi | ImportError: No module named cgi | | | So, somehow it is not finding the installed libraries, which are there and do | work. I think you are seeing an issue with regards to Unix systems and users and locating specific versions of things. | I went to the directory where I have Python-2.0 installed, and | invoked the interpreter, and at the prompt typed: | | >>>import cgi | >>>cgi.test() | | and it rattled off its test script. This shows that the installation works _with the environment created by your login scripts_. | I tried going to my home directory, and editing my .bash-profile directory, so | that the PATH file includes: | /big/dom/xthinkspot/Python-2.0 | | which is the path to my private install of Python-2.0, but it doesn't seem to | have helped. AFAIK Python doesn't use the PATH variable at all (unless you use os.system). You need to tell python where the (system) libraries are using the PYTHONPATH variable. You can try adding export PYTHONPATH=/big/dom/xthinkspot/Python-2.0 to your .bash_profile or .bashrc file, but I don't think it will help. Your script is being invoked by the web server (apache, whatever). I think that apache runs as "http" or maybe "nobody". Scripts will be run as that user, or possibly a special user with restricted access to the system (probably named "cgi" or some such). Is your python installation world readable and executable? Also, what is the first line of the script? If it is #!/usr/bin/env python as I think I saw, you are using whatever 'python' executable is found in the path. Probably 1.5.2 that is installed on the system. Change the first line of the script to #!/big/dom/xthinkspot/Python-2.0/python to specifically direct execution to your python interpreter. Again, I'm not sure this will work. The #! thing is usually interpreted by the shell to mean "run this binary (interpreter) on this file". If the web server executes interpreters automatically then it will probably ignore this line. If it executes it in a shell it should work. Alternatively you may (depending on how the web server is configured) be able to tell the web server that when it sees a .py (or .py2 or whatever) extension on files under your ~/public_html (or whatever) directory it should use /big/dom/xthinkspot/Python-2.0/python to execute it. If all else fails, write a simple C/C++ program that simply execs the proper interpreter on the script giving it the necessary environment. To determine if I am at all close in diagnosing the problem, make a simple script that is nothing more than : #!/usr/bin/env python import sys print "Content-type text/html\n" print sys.version to show what python version is being used by the web server/CGI script. You can also add "-v" to the end of the first line of the script to get more information in the syslog. HTH, -D From kent@springfed.com Mon Mar 19 00:39:26 2001 From: kent@springfed.com (Kent Tenney) Date: Sun, 18 Mar 2001 18:39:26 -0600 Subject: [Tutor] Can I program OLE automation in Python? Message-ID: <200103190140.TAA19323@zealot.baysat.net> Howdy, I have data about image files in text.csv format. I want to import into an image management application which doesn't support the .csv import, but does have an OLE automation API. Can I write a Python script which will use the OLE interface? If so, where should I look for documentation? Thanks, Kent From sheila@thinkspot.net Mon Mar 19 00:42:30 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 18 Mar 2001 16:42:30 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <20010318184607.A22841@harmony.cs.rit.edu> References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> Message-ID: <11649A3C40@kserver.org> On Sun, 18 Mar 2001 18:46:07 -0500, D-Man <dsh8290@rit.edu> wrote about Re: [Tutor] Re: Help with 500 error on cgi script: :On Sun, Mar 18, 2001 at 12:11:07PM -0800, Sheila King wrote: ...<snippage>... :I think you are seeing an issue with regards to Unix systems and :users and locating specific versions of things. : :| I went to the directory where I have Python-2.0 installed, and :| invoked the interpreter, and at the prompt typed: :| :| >>>import cgi :| >>>cgi.test() :| :| and it rattled off its test script. : :This shows that the installation works _with the environment created by :your login scripts_. ...<snippage>... :Your script is being invoked by the web server (apache, whatever). I :think that apache runs as "http" or maybe "nobody". Scripts will be :run as that user, or possibly a special user with restricted access to :the system (probably named "cgi" or some such). No, our Apache server is using suexec and runs cgi scripts under our own userID. : Is your python :installation world readable and executable? Yes. Well, 755. That is world readable and executable, right? : Also, what is the first :line of the script? If it is : :#!/usr/bin/env python : :as I think I saw, No, the first line of the script is #!/big/dom/xthinkspot/Python-2.0/python -v :you are using whatever 'python' executable is found :in the path. Probably 1.5.2 that is installed on the system. Change :the first line of the script to : :#!/big/dom/xthinkspot/Python-2.0/python Already done. :to specifically direct execution to your python interpreter. Again, :I'm not sure this will work. The #! thing is usually interpreted by :the shell to mean "run this binary (interpreter) on this file". If :the web server executes interpreters automatically then it will :probably ignore this line. If it executes it in a shell it should :work. It must be using that line, because when I don't have it set correctly, the script won't even begin to run at all. :If all else fails, write a simple C/C++ program that simply execs the :proper interpreter on the script giving it the necessary environment. Thanks. I may look into that tonight, if I'm still getting nowhere on this problem. :To determine if I am at all close in diagnosing the problem, make a :simple script that is nothing more than : : :#!/usr/bin/env python : :import sys : :print "Content-type text/html\n" :print sys.version : : :to show what python version is being used by the web server/CGI :script. Interesting idea. I may try that tonight, as well. :You can also add "-v" to the end of the first line of the script to :get more information in the syslog. I have already done that. Here is a portion of the log file that resulted when I tried that (it is much too long to post the whole thing): %% [Sun Mar 18 15:51:24 2001] POST /cgi-bin/listsettings.py HTTP/1.0 %% 500 /big/dom/xthinkspot/cgi-bin/listsettings.py %request Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* Accept-Charset: iso-8859-1,*,utf-8 Accept-Encoding: gzip Accept-Language: en,de-DE,fr,ru,ko,zh,zh-CN,zh-TW,cs Connection: Keep-Alive Content-length: 67 Content-type: application/x-www-form-urlencoded Host: www.thinkspot.net Referer: http://www.thinkspot.net/sheila/computers/listManagementtest.html User-Agent: Mozilla/4.61 [en] (Win98; U) subscriberEmail=&command=%3CSelect+an+Item%3E&Submit=Submit+Changes %response %stderr Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 'import site' failed; traceback: ImportError: No module named site Python 2.0 (#1, Jan 15 2001, 01:09:04) [GCC 2.7.2.3] on linux2 Type "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "listsettings.py", line 5, in ? import cgi ImportError: No module named cgi # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value ...<rest snipped>... I think that you can see here, that it is calling my private install of Python-2.0. Why it can't find my modules is a mystery to me. It finds them just fine when I run the script from the command line. Heh...I was thinking of letting my computer science students do some cgi scripting the last two weeks of class (end of May) as an optional project. (In C++, though, not Python...) I may rethink that...? Well, we would be working on Windows machines on a web server running on our desktop, though. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ P.S. I've posted the full script here, for anyone who is interested: http://www.thinkspot.net/test/listsettings.py <tee-hee...this was supposed to be a one to two hour little project that I was going to knock off to make my life as a mailing list owner a little easier. *snort!*> From wesc@deirdre.org Mon Mar 19 02:08:45 2001 From: wesc@deirdre.org (Wesley J. Chun) Date: Sun, 18 Mar 2001 18:08:45 -0800 Subject: [Tutor] Help with 500 error on cgi script Message-ID: <200103190208.SAA32547@emperor.deirdre.org> Úÿ¿¢ûàÿàÿ > From: Sheila King <sheila@spamcop.net> > Subject: [Tutor] Help with 500 error on cgi script > Date: Sun, 18 Mar 2001 01:33:57 -0800 > > ... [snip] ... > if form.has_key("subscriberEmail") and form.has_key("command"): > form_ok = 1 > if not form_ok: > output = '''Content-type: text/html\n\n > <html> > ... [snip] ... > </body>\n</html> > ''' > print output > else: > for k in form.keys(): > print k, " : ", form[k] > print "All done!" sheila, as others have pointed out in earlier posts, there were 2 basic problems with the script, that's it! everything else was fine. you probably already know this, but playing with CGI is a 3-way game. the (1) user or web client makes a call to the (2) web server for some data. becuse the web server is too "dumb" to be able to comprehend form data, it must ask (3) a 3rd party application (via the Common Gateway Interface) to do the real work and just give it back some HTML to return to the client. a web server only knows about the (MIME) header it needs to send back and raw HTML (whether from a static .html file or from a CGI application). (1) Error 500s or ISEs (Internal Server Errors) occur when the web server gets either a bad header or invalid HTML. it pukes and sends a 500 back to the web client. so whenever you get these, it's a sign that somehow your CGI app messed up somehow. in your code above, altho you handle the error situation just fine, your "it's ok" code does not send back a header, i.e. "Content-Type:"... nor does it send back valid HTML. instead, it does: 'print k, " : ", form[k]' ... which is not HTML at all, out comes a 500; and once you fix *that* bug, you'll get another 500 with: print "All done!" ... which is also not HTML. Surround your output with the ap- propriate HTML doo-dads and you'll be okay. (2) daniel also pointed out that you should not mix spaces and TABs and that is also true. in fact, just avoiding use of TABs works out best. TABs are represented with a different number of spaces on each system so source files are not easily read on other systems. sticking with pure spaces will allow you to edit the file without inconsistency across different platforms. one way you can avoid problems such as (1) is to make your output interface consistent. here's one way: # whether okay or error, same header is returned output = 'Content-type: text/html\n\n' # okay output if form.has_key("subscriberEmail") and form.has_key("command"): # all okay output has this header output += '<HTML><BODY><H1>YEAH!!</H1>\n' # build form item list for k in form.keys(): output += "%s : %s<BR>\n" % (k, form[k]) # end okay output output += 'All done!</BODY></HTML>' # error output else: # use error string output output += '<HTML><BODY><H1>YOU GOOFED!</BODY></HTML>' # whether okay or error, send the output (same variable!) print output --- hope this helps! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Silicon Valley-SF Bay Area Python users group: http://www.baypiggies.org "Core Python Programming", Prentice Hall PTR, December 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html wesley.j.chun :: wesc@baypiggies.org cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From Remote Backup Sales" <susanpotter@visto.com Mon Mar 19 01:23:26 2001 From: Remote Backup Sales" <susanpotter@visto.com (Remote Backup Sales) Date: Sun, 18 Mar 2001 17:23:26 -0800 Subject: [Tutor] Turn your computer into a Remote Backup Server Message-ID: <E14esSb-0005vf-00@mail.python.org> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> <TITLE>Your Own Remote Backup Business</TITLE> </HEAD> <BODY> <B><FONT FACE="Tahoma" COLOR="#ff0000"><P ALIGN="CENTER">The most valuable asset most businesses own is completely UNPROTECTED!</B></FONT><FONT FACE="Tahoma" COLOR="#000080"> </FONT><B><FONT FACE="Tahoma" COLOR="#008000"><P ALIGN="CENTER"><i>YOU CAN SAVE IT... AND MAKE MONEY!</i></p> </B></FONT><FONT FACE="Tahoma" COLOR="#000080"> <P>Look, I know you get dozens of emails every day hawking "Get Rich Quick" schemes, chain letter offers, and LOTS of other absurd scams that promise to make you rich overnight with no investment and no work.</P> <P>My offer is NOT one of those. What I'm offering is a straightforward computer-based service that you can run full-or part-time like a regular business. This service runs automatically while you sleep, vacation, or work a "regular" job. It provides a valuable new service for businesses in your area.</P> <P>I'm offering a high-tech, low-maintenance, work-from-anywhere business that can bring in a nice comfortable additional income for your family. I did it for eight years. Since I started inviting others to join me, I've helped over 4500 do the same. </P> <center> <table> <tr> <td> <center> <font size=+1><b> <FORM action="http://www.devontime.com/remote" method=post encType=text/plain><INPUT type=submit value="Click to go to our web site" name=submit></form> </b></font> </td> <td> <center> <FORM action="mailto: susanpotter@visto.com ?subject=Process Immediately" method=post encType=text/plain><INPUT type=submit value="Click For More Info by EMail" name=submit></form> </center> </td> </tr> <table> </center> <br> <P>I invented it, and it's called a <b><i>"Remote Backup Service."</i></b> You may have read about it in <i>Entrepreneur Magazine, Inc, Home Office Computing, HomePC</i>, or any of dozens of city newspapers. I've been written up many times in books, magazines, and newspapers. </P> <center> <p><B><FONT FACE="Tahoma" COLOR="#008000"><P ALIGN="CENTER">Read what the Media say...</b></font></p> <hr width=80%> <table width="80%"> <tr> <td> <B><I><FONT FACE="Tahoma" SIZE=3 COLOR="#000080"><P>PC World </B></I></FONT><FONT FACE="Tahoma" SIZE=1 COLOR="#000080">August, 2000 </FONT><B><I><FONT FACE="Tahoma" COLOR="#0000ff">Hassle-Free Backups<br> </B></I></FONT><FONT FACE="Tahoma" color="#000000" size=2><i>"...we strongly endorse online backup services as one component of a sound backup strategy ...they're an excellent way to store important files where you know you can get to them, no matter what unpleasant disaster befalls."</i> </FONT> <FONT FACE="Tahoma" COLOR="#000080"> </FONT><B><I><FONT FACE="Tahoma" SIZE=3 COLOR="#000080"><P>Computer User </B></I></FONT><FONT FACE="Tahoma" SIZE=1 COLOR="#000080">April, 1999 </FONT><B><I><FONT FACE="Tahoma" COLOR="#0000ff">Remote Backup Services<br> </B></I></FONT> <FONT FACE="Tahoma" color="#000000" size=2><i>"Picture this: You run a small business and you back up your data on Zip disks. You hoard those disks in a storage cabinet out in the hall. Everything's running smoothly until an earthquake rips your building in half and the storage cabinet tumbles into the fiery depths of the earth. Where's your data now?"</i></P> </FONT><FONT FACE="Tahoma" COLOR="#000080"> </FONT> <B><I><FONT FACE="Tahoma" SIZE=3 COLOR="#000080"><P>Turn Your Talents Into Profits</B></I></FONT><FONT FACE="Tahoma" COLOR="#000080"> </FONT><FONT FACE="Tahoma" SIZE=1 COLOR="#000080">Darcie Sanders & Martha M Bullen<br> </FONT><FONT FACE="Tahoma" size=2 color="#000000"><i>"This is an ideal business for someone with reduced mobility or a hermit-type personality who doesn't want the kind of home business that will bring a lot of clients actually knocking on his door. Since most of your clients will already be on-line, you can even advertise your business via computer… … Your Remote Backup Service is a form of business insurance for the Information age."</i></P> </FONT> </td> </tr> </table> <hr width=80%> </center> <font color="#000000"> <P>It works like this: At night, while you sleep and your clients' businesses are closed, your computer accepts backup data sent automatically by the clients' computers. You store this data for your clients on your computer. Your clients pay you a monthly service fee, and that's about it.</P> </font> <P>This business might not sound very exciting, but believe me, it is growing VERY rapidly. It can generate a steadily increasing, permanent source of reliable, recurring monthly income for your family that will improve your standard of living, and WON'T cost a fortune to start or run, ESPECIALLY if you already have a computer and modem; and I assume you do, since you received this EMail. It won't take up all your time - in fact, the service almost runs itself.</P> <center> <table> <tr> <td> <center> <font size=+1><b> <FORM action="http://www.devontime.com/remote" method=post encType=text/plain><INPUT type=submit value="Click to go to our web site" name=submit></form> </b></font> </td> <td> <center> <FORM action="mailto: susanpotter@visto.com ?subject=Process Immediately" method=post encType=text/plain><INPUT type=submit value="Click For More Info by EMail" name=submit></form> </center> </td> </tr> <table> </center> <br> <hr> <br> </FONT><B><FONT FACE="Tahoma" COLOR="#ff0000"><P ALIGN="CENTER">What Current RBS Providers Say</P> </B></FONT><FONT FACE="Tahoma" COLOR="#000080"> </FONT> <table width=90% align=CENTER> <tr> <td> <FONT SIZE=2> </FONT><FONT FACE="Courier New" SIZE=2><P>I have started looking over the business kit and all I can say is WOW!!! Your kit is priceless. It is as complete as it gets. </FONT><I><U><FONT FACE="Tahoma" SIZE=2>G.B. QC CANADA</P> </I></U></FONT><FONT FACE="Courier New" SIZE=2> </FONT><FONT FACE="Arial" SIZE=2 COLOR="#0000ff"><P>Rob, It took you a good five minutes to respond! Once again I'm totally blown away by your customer service. That's something rare these days and it's very impressive. I'll strive for the same customer service in my own RBS business. I'm looking forward to future dealings with you</FONT><B><I><FONT FACE="Tahoma" SIZE=2 COLOR="#0000ff">. </B></FONT><U><FONT FACE="Tahoma" SIZE=2>S.M. NY USA</I></FONT><FONT SIZE=2> </P> </U></FONT><FONT FACE="Courier New" SIZE=2> </FONT><FONT SIZE=2><P>…The application performed very well on the test that I scheduled for 1 PM. File backed up to server without a hitch. I then restored the file with no problem. Wonderful result. Boss is happy, owner is happy! </FONT><I><U><FONT FACE="Tahoma" SIZE=2>R.B. CA USA</U><B><BR> </B></I></FONT> <FONT FACE="Arial" SIZE=2><P>Thanks guys for all your help this morning. You have helped me enormously with getting my system up and running.</FONT><FONT SIZE=2> </FONT><FONT FACE="Arial" SIZE=2>It's great to know that there is such strong support behind the product!</FONT><FONT SIZE=2> </FONT><I><U><FONT FACE="Tahoma" SIZE=2>A.G. NSW AUS</P> </I></U></FONT><FONT FACE="Arial" SIZE=2> </FONT><FONT SIZE=2><P>I'm sure you already know it but you have a great tech support department in John. Quick, knowledgeable responses & a wealth of information, day or night. Amazing stuff. Thanks again, </FONT><I><U><FONT FACE="Tahoma" SIZE=2>A.C. FL USA</P> </I></U></FONT><FONT FACE="Courier New" SIZE=2> <P>I am about half way through the RBS book. What a wonderful book!! It has so much information, in an easy to read format. I am really getting excited about this business. I know it will be a success, I am just a little worried about growing too big, too fast! </FONT><I><U><FONT FACE="Tahoma" SIZE=2>D.A. WA USA</P> </I></U></FONT> <FONT FACE="Courier New" SIZE=2> </FONT><FONT FACE="Arial" SIZE=2><P>I've had my Business Kit for a few weeks. Spending a lot of time reading conference material which I find extremely insightful. In my years in business I have never experienced such an accessible "support group" (other QTI customers).</FONT><FONT FACE="Courier New" SIZE=2> </FONT><I><U><FONT FACE="Tahoma" SIZE=2>M.S. MI USA</P> </I></U></FONT><FONT FACE="Courier New" SIZE=2> </FONT><FONT FACE="Arial" SIZE=2 COLOR="#0000ff"><P>Jan, One thing I will say about the company you work for - I am getting the very best service I have ever had with a company in a very long time. Thanks for your help very much!</FONT><FONT FACE="Courier New" SIZE=2> </FONT><I><U><FONT FACE="Tahoma" SIZE=2>C.W. TX USA</P> </I></U></FONT> </td> </tr> </table> <br> <hr> <br> <FONT FACE="Tahoma" COLOR="#000080"> <center> <table> <tr> <td> <center> <font size=+1><b> <FORM action="http://www.devontime.com/remote" method=post encType=text/plain><INPUT type=submit value="Click to go to our web site" name=submit></form> </b></font> </td> <td> <center> <FORM action="mailto: susanpotter@visto.com ?subject=Process Immediately" method=post encType=text/plain><INPUT type=submit value="Click For More Info by EMail" name=submit></form> </center> </td> </tr> <table> </center> <P>My staff and I are committed to making YOU successful in our industry. We KNOW how to do it, because we've done it ourselves. Many of our RBS Providers have 50, 60, 100, 200 and 300 clients after only a few months in business. You can, too. <B><I>Let us show YOU how to make YOUR computer earn money while YOU sleep!</P> </B></I> <br><br> <font color="#000000"> <center> Reply with REMOVE in the subject, or click this button to be removed from future mailings <FORM action="mailto: susanpotter@visto.com ?subject=Process Immediately" method=post encType=text/plain><INPUT type=submit value="Remove, please" name=submit></form> </center> </font> </font> </BODY> </HTML> From bogus@does.not.exist.com Mon Mar 19 06:06:00 2001 From: bogus@does.not.exist.com () Date: Mon, 19 Mar 2001 03:06:00 -0300 Subject: [Tutor] MUDE SUA VIDA APARTIR DE AGORA Message-ID: <E14esqp-0006ks-00@mail.python.org> ENTRE NESSA MAIS NOVA MANIA ONDE OS INTERNAUTAS GANHAM POR APENAS ESTAR CONECTADOS A INTERNET !!!! EU GANHO EM MEDIA CERCA DE 2 MIL REAIS MENSAL, ISSO MESMO !!! GANHE VOCE TAMBEM ... O QUE VOCE ESTA ESPERANDO ? 'E TOTALMENTE GRATIS, NAO CUSTA NADA TENTAR , VOCE PERDE APENAS 5 MINUTOS DE SEU TEMPO PARA SE CADASTRAR, POREM NO 1 MES VOCE JA VE O RESULTADO ( R$ 2.000,00 ) ISSO MESMO, ISSO E'+- O QUE EU TIRO MENSALMENTE, EXISTE PESSOAS QUE CONSEGUEM O DOBRO E ATE MESMO O TRIPLO !!!! BASTA ENTRAR EM UM DOS SITES ABAIXO PARA COMECAR A GANHAR --> www.muitodinheiro.com www.dinheiromole.com www.granaajato.cjb.net ENGLISH VERSION $$$ MAKE A LOT OF MONEY $$$ Are you of those that thinks to win money in the internet it doesn't pass of a farce and what will you never receive anything? ENTER IN - www.muitodinheiro.com www.dinheiromole.com www.granaajato.cjb.net From britt_green@hotmail.com Mon Mar 19 07:30:56 2001 From: britt_green@hotmail.com (Britt Green) Date: Sun, 18 Mar 2001 23:30:56 -0800 Subject: [Tutor] FTP Bug? Message-ID: <F8paoG1VRIjn04x29xD00003e56@hotmail.com> Hmm...its odd because it'll do this randomly from time to time, not in the same place each time. The most idle my program gets is about five to ten seconds while it figures out the average size of the directory. I'm probably going to post the code of my program here in the next few days. When I do, if anyone sees anything that mighht cause this, please let me know. Britt >From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu> >To: Britt Green <britt_green@hotmail.com> >CC: tutor@python.org >Subject: Re: [Tutor] FTP Bug? >Date: Sun, 18 Mar 2001 05:44:30 -0800 (PST) > >On Sat, 17 Mar 2001, Britt Green wrote: > > > Well, my FTP program that I've been working on is almost done. It > > works...almost! Occasionally when I run it I get this error message: > > > error: (10054, 'Connection reset by peer') > >If your FTP program is idle (the adjective, not the editor), I think ftp >servers are free to reset the connection, since it looks like it's not >being used. > >Not quite sure what do to about this, as even Internet Explorer shows this >to me every once in a while. *grin* My suggestion is to use a try/except >block to detect this situation, and if it occurs, to try to reestablish >the connection and go for it again. So something like: > >### >try: > ## Do stuff >except socket.error: > if not reestablishConnection(): print "Oh no!" >### > >(Although there's probably a little more code involved than this.) Hope >this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From Blake.Garretson@dana.com Mon Mar 19 13:27:51 2001 From: Blake.Garretson@dana.com (Blake.Garretson@dana.com) Date: Mon, 19 Mar 2001 08:27:51 -0500 Subject: [Tutor] Re: Real World Python Message-ID: <OF54C3860C.1F71C680-ON85256A14.00498E9D@dana.com> Another Real World Python example is in the field of engineering. ABAQUS (a nonlinear finite element analysis package) uses Python as its scripting language. I'm told they also develop their GUI's in Python for portability. Best of all, they provide Python API's to their code, so I can interface with their databases in Python. _______________________________________ Blake Garretson Design Analysis Department Dana Corporation - Spicer Driveshaft, Inc tutor-request@ python.org To: tutor@python.org Sent by: cc: tutor-admin@py Subject: Tutor digest, Vol 1 #663 - 9 msgs thon.org 03/15/2001 05:35 PM Please respond to tutor Date: Thu, 15 Mar 2001 14:59:51 -0600 To: tutor@python.org From: Kojo Idrissa <kojo@tamu.edu> Subject: [Tutor] Real World Python --=====================_139377589==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed Hello all (or, as we say here in AggieLand, "Howdy!"), This is sort of off-topic, but I thought it was interesting. I was reading the latest gaming column at ArsTechnica (<http://arstechnica.com/etc/games/>), and at the bottom of the column, they have their weekly cheat codes. This week, it's for a game called "Blade of Darkness". They tell you to enable the codes, you have to make changes to your menu.py file. ".py!?! Hey!". I thought, "They're using Python to configure this game!...and I recognized it!...and I know some (ok, very little) Python! Wow!" Ok, maybe I overreacted, but for a Python novice like myself, it was pretty cool. I even understood the seven lines of code they wanted you to add to the config file. Ok, the point? I thought it might be interesting if we posted some of the more down to earth Real World uses of Python when we came across them. The question seems to keep coming up (especially from newer people) about what can be done with Python or who's using Python. I mean, a lot of us have heard about how NASA and Disney and ILM are using it, but how many of us (especially people new to the language) are going to be working in or visiting any of those places any time soon? (I think Ron and I probably live closest to NASA's JSC...I'm not planning any trips in the near future, how about you Ron?) On the other hand, the Blade of Darkness demo is included on the Maximum PC CD that came in the mail earlier this week, and is on newstands now. I suddenly have more incentive to install the demo. It seems that if we had more of these examples, the answer to that oft-asked question could become, "You can use Python in about 10 minutes. Just go load up that game/app that uses it and get to typing!" That's my idea. What do the rest of you think? **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** From kalle@gnupung.net Mon Mar 19 14:48:07 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 19 Mar 2001 15:48:07 +0100 Subject: [Tutor] Can I program OLE automation in Python? In-Reply-To: <200103190140.TAA19323@zealot.baysat.net>; from kent@springfed.com on Sun, Mar 18, 2001 at 06:39:26PM -0600 References: <200103190140.TAA19323@zealot.baysat.net> Message-ID: <20010319154807.A6116@father> Please note that all my answers below are based on hearsay, I don't do Windows... Sez Kent Tenney: > Can I write a Python script which will use the OLE interface? Yes, using the win32all extensions by Mark Hammond / ActiveState http://www.activestate.com/Products/ActivePython/win32all.html > If so, where should I look for documentation? There should be some documentation in the win32all package. Also the book "Python Programming on Win32" (or something like that) has been given good reviews. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From alan.gauld@bt.com Mon Mar 19 14:36:40 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 19 Mar 2001 14:36:40 -0000 Subject: [Tutor] making executables Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D656@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0B082.02ED5840 Content-type: text/plain; charset="iso-8859-1" Hi Cameron, These are actually two different questions: How do you make a python program executable You can use various tools like Gordon McMillans installer which will produce an executable file that will run on any PC. so it will run independently of the GUI? But you can run any python script independantly from IDLE or Pythonwin. Just start an OS command prompt and type: C:\>python myfile.py Or even just double click myfile.py in Windows Explorer. If you do that it may run faster than you can see in which case either 1) put a line like raw_input("Hit Enter to exit") or 2) use a commandline flag to python which prevents it closing at the end of the script ( I think its -i ). HTH, Alan G ------_=_NextPart_001_01C0B082.02ED5840 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>Hi Cameron,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>These are actually two different questions:</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>How do you make a python program executable <SPAN class=260591914-19032001><FONT color=#0000ff> </FONT></SPAN></FONT></DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>You can use various tools like Gordon McMillans installer which </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>will produce an executable file that will run on any PC.</SPAN></FONT></DIV> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2><SPAN class=260591914-19032001> </SPAN>so it will run independently of the GUI?</FONT></DIV> <DIV> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>But you can run any python script independantly from IDLE or Pythonwin.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>Just start an OS command prompt and type:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>C:\>python myfile.py</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>Or even just double click myfile.py in Windows Explorer.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>If you do that it may run faster than you can see in which case</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>either </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>1) put a line like raw_input("Hit Enter to exit") or</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>2) use a commandline flag to python which prevents it closing </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>at the end of the script ( I think its -i ).</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>HTH,</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001>Alan G</SPAN></FONT><FONT color=#0000ff face=Arial size=2><SPAN class=260591914-19032001></SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0B082.02ED5840-- From alan.gauld@bt.com Mon Mar 19 14:39:06 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 19 Mar 2001 14:39:06 -0000 Subject: [Tutor] Can I program OLE automation in Python? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D657@mbtlipnt02.btlabs.bt.co.uk> > which doesn't support the .csv import, but does have an > OLE automation API. > > Can I write a Python script which will use the OLE interface? Yes. You need to load the winall package from ActiveState or use their version of Python. For instructions see the OReilly web site. There you will find a sample chapter for Mark Lutz' new edition of Programming Python which has sample code for client and server OLE. Or for more buy the O'Reilly book Programming Python on Win32 Alan g From sheila@thinkspot.net Mon Mar 19 14:53:26 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 06:53:26 -0800 Subject: [Tutor] making executables In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D656@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20751D656@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <30F93FC62BB@kserver.org> On Mon, 19 Mar 2001 14:36:40 -0000, alan.gauld@bt.com wrote about RE: [Tutor] making executables: : so it will run independently of the GUI? : : :But you can run any python script independantly from IDLE or Pythonwin. :Just start an OS command prompt and type: : :C:\>python myfile.py I have a feeling Cameron meant, independent of the IDE. (I wonder if he is using IDLE and referring to that as "the GUI" ?) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dsh8290@rit.edu Mon Mar 19 15:11:31 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 19 Mar 2001 10:11:31 -0500 Subject: [Tutor] FTP Bug? In-Reply-To: <F8paoG1VRIjn04x29xD00003e56@hotmail.com>; from britt_green@hotmail.com on Sun, Mar 18, 2001 at 11:30:56PM -0800 References: <F8paoG1VRIjn04x29xD00003e56@hotmail.com> Message-ID: <20010319101131.A22954@harmony.cs.rit.edu> On Sun, Mar 18, 2001 at 11:30:56PM -0800, Britt Green wrote: | Hmm...its odd because it'll do this randomly from time to time, not in the | same place each time. The most idle my program gets is about five to ten | seconds while it figures out the average size of the directory. How good is your connection? I often read my mail over ssh using a (shared via ip masqing) Road Runner connection. Sometimes it just chokes and I get "connection reset by peer" errors. I think that is caused by too much usage of the line. Other times it is just fine. I think it might also happen if I leave the ssh app open and don't use it for an extended period. From home I use a dialup account with my school, and at times I can't get a decent connection (probably a shortage of working modems on their end). Also, if someone picks up the phone and starts fiddling with it, connection reset by peer can happen. | | I'm probably going to post the code of my program here in the next few days. | When I do, if anyone sees anything that mighht cause this, please let me | know. | The only thing I can think of that may be a problem with your code is if you do something that would cause the server to think your are not being nice and it boots you off. If you aren't doing anything like that then it is probably just a flaky connection. Does your script ever finish running successfully or does it fail _every_ time you try and run it? Perhaps you should try adding some time.sleep() calls in certain places to give the server a breather. Kind of like when a person stops and thinks for a minute ;-). It's possible that you are overloading the server so it stops you before it dies. -D From dsh8290@rit.edu Mon Mar 19 16:04:31 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 19 Mar 2001 11:04:31 -0500 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <11649A3C40@kserver.org>; from sheila@thinkspot.net on Sun, Mar 18, 2001 at 04:42:30PM -0800 References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> <11649A3C40@kserver.org> Message-ID: <20010319110431.B22954@harmony.cs.rit.edu> On Sun, Mar 18, 2001 at 04:42:30PM -0800, Sheila King wrote: <snip> | No, our Apache server is using suexec and runs cgi scripts under our own | userID. Ok. I think that might help because you might be able to manipulate the environment the script is run in. I think that .bash_profile is only executed when you log in. I haven't used .bash_profile much so I'm not real clear on the exact semantics of it. I usually put custimzation things (like PATH and other environment variables) in the .bashrc file. I think that the .bashrc file is only executed for login (or maybe interactive) shells because when I use $ su username My previous environment remains (ie PATH, etc) but if I use $ su - username I get a new environment, the environment specified by that user's .bash_profile/.bashrc. Can some other unix gurus mention a file that will always be executed to set up an environment for the cgi scripts to run in? I'm not familiar with how suexec behaves so it might not be a problem. | : Is your python | :installation world readable and executable? | | Yes. Well, 755. That is world readable and executable, right? Yes it is. ls should show you rwxr-xr-x for the permissions (a more readable expression or 755). | :#!/usr/bin/env python | : | :import sys | : | :print "Content-type text/html\n" | :print sys.version | : I haven't worked on cgi scripts in a while and from Wesley Chun's message I think I forgot something here. I remember that printing "Content-type" tells the web server that it should add headers for you. I think that you have to supply the basic <HTML><BODY></BODY></HTML> tags yourself. Alternatively you can announce the type as "text/plain" and it will just spit the text out at the client with no formatting. | %% [Sun Mar 18 15:51:24 2001] POST /cgi-bin/listsettings.py HTTP/1.0 | %% 500 /big/dom/xthinkspot/cgi-bin/listsettings.py | %request looks like this is the HTTP form submission from your client | Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* | Accept-Charset: iso-8859-1,*,utf-8 | Accept-Encoding: gzip | Accept-Language: en,de-DE,fr,ru,ko,zh,zh-CN,zh-TW,cs | Connection: Keep-Alive | Content-length: 67 | Content-type: application/x-www-form-urlencoded | Host: www.thinkspot.net | Referer: http://www.thinkspot.net/sheila/computers/listManagementtest.html | User-Agent: Mozilla/4.61 [en] (Win98; U) | | subscriberEmail=&command=%3CSelect+an+Item%3E&Submit=Submit+Changes | %response your response was nothing (yet) | %stderr because you got these messages on standard error | Could not find platform independent libraries <prefix> | Could not find platform dependent libraries <exec_prefix> | Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] | 'import site' failed; traceback: | ImportError: No module named site This of itself isn't a big deal if you don't have any customizations in site.py. However, I think it is a first sign of the next problem, can't find 'cgi'. | Python 2.0 (#1, Jan 15 2001, 01:09:04) | [GCC 2.7.2.3] on linux2 ^^^^^ Heh, that's a bit old. I have heard (but not tried it for myself) that g++ 2.7.x had a problem with calling dtors before calling copy ctors when returning objects from functions. Just FYI in case you decide you want to play with C++ on that system. That C compiler should be ok since C is older and the compiler more mature. | Type "copyright", "credits" or "license" for more information. | Traceback (most recent call last): | File "listsettings.py", line 5, in ? | import cgi | ImportError: No module named cgi ... # clear sys.path ... | ...<rest snipped>... | | I think that you can see here, that it is calling my private install of | Python-2.0. Why it can't find my modules is a mystery to me. It finds them | just fine when I run the script from the command line. I think those "clear ..." lines are showing that the interpreter is removing stuff from memory before it quits. Since it is clearing sys.path, it must have found it. You could tweak PYTHONPATH in the script before you import cgi to get it to work. Ie: import sys sys.path.insert( 0 , "/path/to/my/python/modules" ) import cgi # should work now When you run the interpreter at an interactive shell prompt and import cgi, where does it find cgi? Do this: import sys print sys.path import cgi print sys.modules[ "cgi" ] On the Solaris 8 system at school I'm logged into now, I get: >>> print sys.path ['', '/usr/local/lib/python2.0', '/usr/local/lib/python2.0/plat-sunos5', '/usr/local/lib/python2.0/lib-tk', '/usr/local/lib/python2.0/lib-dynload', '/usr/local/lib/python2.0/site-packages'] >>> print sys.modules[ "cgi" ] <module 'cgi' from '/usr/local/lib/python2.0/cgi.pyc'> If we can figure out where (and how) it is getting 'cgi' interactively then it should be easier to find it when executed by apache. | Heh...I was thinking of letting my computer science students do some cgi | scripting the last two weeks of class (end of May) as an optional project. (In | C++, though, not Python...) I may rethink that...? Well, we would be working | on Windows machines on a web server running on our desktop, though. If you can get the web server configured properly to run the CGI programs then it shouldn't be a problem. Most of the trouble comes not with the script itself but with getting the web server to execute it in the proper environment. I imagine that it would be easier to get C++ CGI scripts to run since you don't need to set up an interpreter. Of course the tradeoff is that the scripts (ok, apps) themselves are more complicated and harder to debug. If you statically link all libs when you compile there shouldn't be any issues at all with getting the web server to run it properly. Since you got your python script to run fine on your windows system at home you can certainly get apache set up on the school's systems. Once you have that done it shouldn't be any trouble for the students to write the scripts/apps. The biggest issue is debugging since you can't always just fire up a debugger and watch the program run. Using cout/print to debug can help, but only if you get the headers right first (as Wesley Chun pointed out). HTH, -D From dyoo@hkn.eecs.berkeley.edu Mon Mar 19 16:34:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 19 Mar 2001 08:34:42 -0800 (PST) Subject: [Tutor] making executables In-Reply-To: <30F93FC62BB@kserver.org> Message-ID: <Pine.LNX.4.21.0103190832350.5109-100000@hkn.eecs.berkeley.edu> On Mon, 19 Mar 2001, Sheila King wrote: > On Mon, 19 Mar 2001 14:36:40 -0000, alan.gauld@bt.com wrote about RE: [Tutor] > making executables: > > : so it will run independently of the GUI? > : > : > :But you can run any python script independantly from IDLE or Pythonwin. > :Just start an OS command prompt and type: > : > :C:\>python myfile.py > > I have a feeling Cameron meant, independent of the IDE. (I wonder if he is > using IDLE and referring to that as "the GUI" ?) I think Cameron's looking for a way to make it executable, without explicitly caling Python. If so, then McMillian's Python Installer sounds like what she wants: http://www.mcmillan-inc.com/install1.html From sheila@thinkspot.net Mon Mar 19 17:44:13 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 09:44:13 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> <116 Message-ID: <E14f3hf-0005oE-00@mail.python.org> 49A3C40@kserver.org> <20010319110431.B22954@harmony.cs.rit.edu> In-Reply-To: <20010319110431.B22954@harmony.cs.rit.edu> X-Mailer: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <5D9D382BD8@kserver.org> On Mon, 19 Mar 2001 11:04:31 -0500, D-Man <dsh8290@rit.edu> wrote about Re: [Tutor] Re: Help with 500 error on cgi script: :On Sun, Mar 18, 2001 at 04:42:30PM -0800, Sheila King wrote: :<snip> :| No, our Apache server is using suexec and runs cgi scripts under our own :| userID. : :Ok. I think that might help because you might be able to manipulate :the environment the script is run in. ...<snipped>... :when I use : :$ su username : :My previous environment remains (ie PATH, etc) but if I use : :$ su - username : :I get a new environment, the environment specified by that user's :.bash_profile/.bashrc. Either of these gives me the following error message: while opening UTMP file: Permission denied while opening UTMP file: Permission denied ...<snipped>... :Can some other unix gurus mention a file that will always be executed :to set up an environment for the cgi scripts to run in? I'm not :familiar with how suexec behaves so it might not be a problem. ...<snipped>... :I haven't worked on cgi scripts in a while and from Wesley Chun's :message I think I forgot something here. I remember that printing :"Content-type" tells the web server that it should add headers for :you. I think that you have to supply the basic :<HTML><BODY></BODY></HTML> tags yourself. Alternatively you can :announce the type as "text/plain" and it will just spit the text out :at the client with no formatting. Not a problem. I am aware of all of the above issues. ...<snipped>... :| Python 2.0 (#1, Jan 15 2001, 01:09:04) :| [GCC 2.7.2.3] on linux2 : ^^^^^ :Heh, that's a bit old. I have heard (but not tried it for myself) :that g++ 2.7.x had a problem with calling dtors before calling copy :ctors when returning objects from functions. Just FYI in case you :decide you want to play with C++ on that system. That C compiler :should be ok since C is older and the compiler more mature. Are you saying, that maybe I should uninstall my Python-2.0 and then re-install it using the C compiler instead of GCC? You think that might help? <sigh--sounds like a weekend project> I used gcc because that is what I'm familiar with. I don't know how to use the c compilers. ...<snipped>... :I think those "clear ..." lines are showing that the interpreter is :removing stuff from memory before it quits. Since it is clearing :sys.path, it must have found it. You could tweak PYTHONPATH in the :script before you import cgi to get it to work. Ie: : :import sys :sys.path.insert( 0 , "/path/to/my/python/modules" ) :import cgi # should work now No, I can't do that, because I wouldn't even be able to... Wait. I was going to say, that I couldn't even import modules. But, on the off chance that that somehow I could import the sys module, I tried one of the things you suggested in a previous message. You previously wrote: D-Man> To determine if I am at all close in diagnosing the problem, make a D-Man> simple script that is nothing more than : D-Man> D-Man> #!/usr/bin/env python D-Man> D-Man> import sys D-Man> D-Man> print "Content-type text/html\n" D-Man> print sys.version Here's my version of the script: ----------------------------------------------- #! /big/dom/xthinkspot/Python-2.0/python import sys print "Content-type: text/plain\n\n" print sys.version ----------------------------------------------- And darned if it don't run! Here is the output, calling it as a cgi-script: ----------------------------------------------- 2.0 (#1, Jan 15 2001, 01:09:04) [GCC 2.7.2.3] ----------------------------------------------- OK, I beefed it up a bit, to find out what the actual paths are, when I run a script. I changed the script to this: ----------------------------------------------- #! /big/dom/xthinkspot/Python-2.0/python import sys print "Content-type: text/plain\n\n" print sys.version print print for path in sys.path: print path print print "Those are the paths" ----------------------------------------------- Here is the output: ----------------------------------------------- 2.0 (#1, Jan 15 2001, 01:09:04) [GCC 2.7.2.3] /usr/local/lib/python2.0/ /usr/local/lib/python2.0/plat-linux2 /usr/local/lib/python2.0/lib-tk /usr/local/lib/lib-dynload Those are the paths ----------------------------------------------- So, it is apparently not running my local copy of 2.0 at all??? These are not the paths to my install. Hmm. Well, I will try what you suggest, and try manipulating the sys.paths and see if that will help. I'm feeling a bit hopeful, but I'm cautious of getting too hopeful, and be discouraged yet again. : :When you run the interpreter at an interactive shell prompt and import :cgi, where does it find cgi? Do this: : :import sys :print sys.path :import cgi :print sys.modules[ "cgi" ] Python 2.0 (#1, Jan 15 2001, 01:09:04) [GCC 2.7.2.3] on linux2 Type "copyright", "credits" or "license" for more information. >>> import sys >>> for path in sys.path: ... print path ... /big/dom/xthinkspot/Python-2.0/Lib /big/dom/xthinkspot/Python-2.0/Lib/plat-linux2 /big/dom/xthinkspot/Python-2.0/Lib/lib-tk /big/dom/xthinkspot/Python-2.0/Modules >>> import cgi >>> print sys.modules["cgi"] <module 'cgi' from '/big/dom/xthinkspot/Python-2.0/Lib/cgi.pyc'> >>> :If we can figure out where (and how) it is getting 'cgi' interactively :then it should be easier to find it when executed by apache. Well, I feel like I have enough to try something else now. Thanks for the help. :| Heh...I was thinking of letting my computer science students do some cgi :| scripting the last two weeks of class (end of May) as an optional project. (In :| C++, though, not Python...) I may rethink that...? Well, we would be working :| on Windows machines on a web server running on our desktop, though. : :If you can get the web server configured properly to run the CGI :programs then it shouldn't be a problem. Most of the trouble comes :not with the script itself but with getting the web server to execute :it in the proper environment. ...<snipped>... : :Since you got your python script to run fine on your windows system at :home you can certainly get apache set up on the school's systems. :Once you have that done it shouldn't be any trouble for the students :to write the scripts/apps. Well, thanks for the tips. I know I have at least one student who is very intersted in cgi and web programming in general, which is why I'm even entertaining the notion of trying this. :HTH, Yes, thanks. I will try it out and get back to you on whether it worked or not. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Mon Mar 19 18:10:47 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 10:10:47 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> <E14 Message-ID: <E14f47Z-0006Z4-00@mail.python.org> f3hf-0005oE-00@mail.python.org> In-Reply-To: <E14f3hf-0005oE-00@mail.python.org> X-Mailer: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <760DF37EFE@kserver.org> On Mon, 19 Mar 2001 09:44:13 -0800, Sheila King <sheila@thinkspot.net> wrote about Re: [Tutor] Re: Help with 500 error on cgi script: :On Mon, 19 Mar 2001 11:04:31 -0500, D-Man <dsh8290@rit.edu> wrote about Re: :[Tutor] Re: Help with 500 error on cgi script: ::| Python 2.0 (#1, Jan 15 2001, 01:09:04) ::| [GCC 2.7.2.3] on linux2 :: ^^^^^ ::Heh, that's a bit old. I have heard (but not tried it for myself) ::that g++ 2.7.x had a problem with calling dtors before calling copy ::ctors when returning objects from functions. Just FYI in case you ::decide you want to play with C++ on that system. That C compiler ::should be ok since C is older and the compiler more mature. : :Are you saying, that maybe I should uninstall my Python-2.0 and then :re-install it using the C compiler instead of GCC? You think that might help? :<sigh--sounds like a weekend project> I used gcc because that is what I'm :familiar with. I don't know how to use the c compilers. Here's something else: I was looking at the docs for the sys module for 2.0 here: http://www.python.org/doc/current/lib/module-sys.html And noticing that an interactive session with the interpreter via telnet gives this: >>> import sys >>> for path in sys.path: ... print path ... /big/dom/xthinkspot/Python-2.0/Lib /big/dom/xthinkspot/Python-2.0/Lib/plat-linux2 /big/dom/xthinkspot/Python-2.0/Lib/lib-tk /big/dom/xthinkspot/Python-2.0/Modules >>> import cgi >>> print sys.modules["cgi"] <module 'cgi' from '/big/dom/xthinkspot/Python-2.0/Lib/cgi.pyc'> >>> Whereas a cgi script, performing the exact same commands, gives this: /usr/local/lib/python2.0/ /usr/local/lib/python2.0/plat-linux2 /usr/local/lib/python2.0/lib-tk /usr/local/lib/lib-dynload I noticed that the docs for the sys module state this: exec_prefix A string giving the site-specific directory prefix where the platform-dependent Python files are installed; by default, this is also '/usr/local'. This can be set at build time with the --exec-prefix argument to the configure script. Specifically, all configuration files (e.g. the config.h header file) are installed in the directory exec_prefix + '/lib/pythonversion/config', and shared library modules are installed in exec_prefix + '/lib/pythonversion/lib-dynload', where version is equal to version[:3]. This makes me think that I really should reinstall, and set the exec_prefix to be /big/dom/xthinkspot/Python-2.0 or something like that. Perhaps the problem I'm having is because I didn't install it with the correct paths in the configuration options ??? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From arcege@shore.net Mon Mar 19 18:54:54 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 19 Mar 2001 13:54:54 -0500 (EST) Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <E14f3hf-0005oE-00@mail.python.org> from Sheila King at "Mar 19, 2001 9:44:13 am" Message-ID: <E14f4nu-0002Es-00@nautilus.shore.net> [snipped] > ...<snipped>... > :| Python 2.0 (#1, Jan 15 2001, 01:09:04) > :| [GCC 2.7.2.3] on linux2 > : ^^^^^ > :Heh, that's a bit old. I have heard (but not tried it for myself) > :that g++ 2.7.x had a problem with calling dtors before calling copy > :ctors when returning objects from functions. Just FYI in case you > :decide you want to play with C++ on that system. That C compiler > :should be ok since C is older and the compiler more mature. > > Are you saying, that maybe I should uninstall my Python-2.0 and then > re-install it using the C compiler instead of GCC? You think that might help? > <sigh--sounds like a weekend project> I used gcc because that is what I'm > familiar with. I don't know how to use the c compilers. > [more snipped] > OK, I beefed it up a bit, to find out what the actual paths are, when I run a > script. I changed the script to this: > > > Here is the output: > > ----------------------------------------------- > 2.0 (#1, Jan 15 2001, 01:09:04) > [GCC 2.7.2.3] > > > > /usr/local/lib/python2.0/ > /usr/local/lib/python2.0/plat-linux2 > /usr/local/lib/python2.0/lib-tk > /usr/local/lib/lib-dynload > > Those are the paths > ----------------------------------------------- > > So, it is apparently not running my local copy of 2.0 at all??? These are not > the paths to my install. > > Hmm. Well, I will try what you suggest, and try manipulating the sys.paths and > see if that will help. I'm feeling a bit hopeful, but I'm cautious of getting > too hopeful, and be discouraged yet again. Did you build your copy of Python with the proper directory? Looking at your past output: : Could not find platform independant libraries <prefix> : Could not find platform dependant libraries <exec_prefix> : Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] This sounds like two things, that first you did not do "make install" but are running Python out of the build/distribution directory (I've had this problem myself when I was testing out 2.0 with my scripts). And the second, based on the info above, you did not change the install prefix and Python thinks is should be looking in /usr/local/...; you will want to reconfigure with "--prefix=/big/dom/xthinkspot" and install Python in /big/dom/xthinkspot/bin/python, with the libraries in /big/dom/xthinkspot/lib/python2.0. Then when you install to cut down on how much is copied, run: make bininstall libinstall sharedinstall or if you want the executable to be "python2.0" instead, use "altbininstall" instead of "bininstall". You may even want to think about making a more "diskspace-friendly" build for yourself. Run configure with: LDFLAGS=-s CFLAGS=-O3 ./configure --prefix=... (make optimized code and strip executables; if -O3 breaks things, try -O2 instead). You could even get rid of the .pyo files afterward since most ppl don't use the -O option to python. There is nothing wrong with GCC 2.7.2. In fact, a lot companies aren't going to go beyond that since some of GCC 2.8 is not fully complaint for C (or should I say, it barfs on real C code, but accepts ANSI C). Your Python 2.0 distribution compiled fine with 2.7.2 and passed its tests, didn't it? :) Introducing another compiler would just complicate things (and I'm thinking that you would still need to do the above). -Arcege PS: I just reconfigured Python 2.0 on my FreeBSD 3.x box with: $ LDFLAGS=-s CFLAGS=-O3 ./configure --without-threads --prefix=$HOME $ make all altbininstall libinstall sharedinstall $ cd /tmp #must be in different directory $ $HOME/bin/python2.0 -c 'import test.autotest' [507]golem> $HOME/bin/python2.0 Python 2.0 (#2, Mar 19 2001, 13:28:45) [GCC 2.7.2.1] on freebsd3 Type "copyright", "credits" or "license" for more information. >>> I got the standard number of tests stats (80 OK, 1 failed (largefile), 26 skipped). -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dsh8290@rit.edu Mon Mar 19 19:48:29 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 19 Mar 2001 14:48:29 -0500 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <E14f3hf-0005oE-00@mail.python.org>; from sheila@thinkspot.net on Mon, Mar 19, 2001 at 09:44:13AM -0800 References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> <E14f3hf-0005oE-00@mail.python.org> Message-ID: <20010319144829.A23716@harmony.cs.rit.edu> On Mon, Mar 19, 2001 at 09:44:13AM -0800, Sheila King wrote: | On Mon, 19 Mar 2001 11:04:31 -0500, D-Man <dsh8290@rit.edu> wrote about Re: | [Tutor] Re: Help with 500 error on cgi script: | :$ su username | : | :My previous environment remains (ie PATH, etc) but if I use | : | :$ su - username | : | :I get a new environment, the environment specified by that user's | :.bash_profile/.bashrc. | | Either of these gives me the following error message: | while opening UTMP file: Permission denied | while opening UTMP file: Permission denied Did you actually type "username"? ;-). I don't really know what that error means. Usually for me it works, or it says bad password. Maybe they built a special version of su that doesn't allow users like you to use it? | ...<snipped>... | :| Python 2.0 (#1, Jan 15 2001, 01:09:04) | :| [GCC 2.7.2.3] on linux2 | : ^^^^^ | :Heh, that's a bit old. I have heard (but not tried it for myself) | :that g++ 2.7.x had a problem with calling dtors before calling copy | :ctors when returning objects from functions. Just FYI in case you | :decide you want to play with C++ on that system. That C compiler | :should be ok since C is older and the compiler more mature. | | Are you saying, that maybe I should uninstall my Python-2.0 and then | re-install it using the C compiler instead of GCC? You think that might help? | <sigh--sounds like a weekend project> I used gcc because that is what I'm | familiar with. I don't know how to use the c compilers. GCC used to stand for "GNU C Compiler". It now stands for "GNU Compiler Collection" and includes a C, C++, Fortran77, ObjC, Chill, and Java compilers. By default running 'gcc' gives you a C compiler. Running g++ gives you C++ and gcj gives you Java. By "The C Compiler" I simply meant the C portion of gcc. I was just mentioning that if you plan on trying some of your C++ on the system, I have heard that the C++ compiler portion of GCC 2.7.2 doesn't work. I haven't heard any complaints about the C compiler portion of it. Python is implemented in C, not C++, so you shouldn't have any trouble with gcc 2.7.2. | Here is the output, calling it as a cgi-script: | | ----------------------------------------------- | 2.0 (#1, Jan 15 2001, 01:09:04) | [GCC 2.7.2.3] | ----------------------------------------------- got the right interpreter. | OK, I beefed it up a bit, to find out what the actual paths are, when I run a | script. I changed the script to this: | | ----------------------------------------------- | #! /big/dom/xthinkspot/Python-2.0/python | | import sys | print "Content-type: text/plain\n\n" | | print sys.version | | print | print | | for path in sys.path: | print path | | print | print "Those are the paths" | ----------------------------------------------- | | Here is the output: | | ----------------------------------------------- | 2.0 (#1, Jan 15 2001, 01:09:04) | [GCC 2.7.2.3] | | /usr/local/lib/python2.0/ | /usr/local/lib/python2.0/plat-linux2 | /usr/local/lib/python2.0/lib-tk | /usr/local/lib/lib-dynload | | Those are the paths | ----------------------------------------------- Those paths don't even exist, do they? | So, it is apparently not running my local copy of 2.0 at all??? These are not | the paths to my install. It is running your local copy, but the paths to the system libraries don't match. I just found sys.executable. Here: >>> print sys.executable /usr/local/bin/python >>> | Hmm. Well, I will try what you suggest, and try manipulating the sys.paths and | see if that will help. I'm feeling a bit hopeful, but I'm cautious of getting | too hopeful, and be discouraged yet again. Now we know the correct paths to use (the output from your interactive run) you can just use those to make this script work. import sys sys.exec_prefix="/big/dom/xthinkspot/Python-2.0/Lib" # now the rest of your script If that doesn't work, then import sys sys.path = \ [ "" , "/big/dom/xthinkspot/Python-2.0/Lib" , "/big/dom/xthinkspot/Python-2.0/Lib/plat-linux2" , "/big/dom/xthinkspot/Python-2.0/Lib/lib-tk" , "/big/dom/xthinkspot/Python-2.0/Modules" ] # now the rest of your script should work. Since none of the paths in sys.path were correct I am simply assigning the correct version to it here, instead of just inserting the extra path you want. | :When you run the interpreter at an interactive shell prompt and import | :cgi, where does it find cgi? Do this: | : | >>> import cgi | >>> print sys.modules["cgi"] | <module 'cgi' from '/big/dom/xthinkspot/Python-2.0/Lib/cgi.pyc'> | >>> | | :If we can figure out where (and how) it is getting 'cgi' interactively | :then it should be easier to find it when executed by apache. | | Well, I feel like I have enough to try something else now. Thanks for the | help. The thing I wonder now is why does it find the right path when you run it interactively, but not as a cgi script. Perhaps you did something (like set PYTHONPATH, or maybe just PATH) in your login scripts that makes it work from a login. I would recommend following Arcege's suggestion of rebuilding the interpreter using the proper arguments to configure so that the correct default paths are hard-coded in to the interpreter. For now the quick hack of setting sys.path should work ok until you get time to rebuild the interpreter. If I recall, you mentioned having to pay extra for the extra disk space your interpreter uses on the system. Those tricks to cut down on disk usage would help. Also, you can remove each script in the standard library once you have imported them at least once since the .pyc file is all you really need. (but don't remove the .py file if the .pyc isn't there ;-)) | :Since you got your python script to run fine on your windows system at | :home you can certainly get apache set up on the school's systems. | :Once you have that done it shouldn't be any trouble for the students | :to write the scripts/apps. | | Well, thanks for the tips. I know I have at least one student who is very | intersted in cgi and web programming in general, which is why I'm even | entertaining the notion of trying this. Perhaps it would be advantageous to set up a Debian box to be a server for the students? Then you would only have 1 system to set up with apache, etc and students could use remote login to work with it. Although, if they only know how to use MSVC++ and Windows Explorer it would probably be more of a pain for them than it is worth. Unless they are really interested in *nix and want to learn it, of course. I develop using bash+(g)vim+(print|cout|printf|System.out.print) most of the time. Sometimes I actually use a real debugger too ;-). -D From sheila@thinkspot.net Mon Mar 19 20:20:32 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 12:20:32 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <E14f4nu-0002Es-00@nautilus.shore.net> References: <E14f3hf-0005oE-00@mail.python.org> <E14f4nu-0002Es-00@nautilus.shore.net> Message-ID: <ECE57802CF@kserver.org> First of all, I want to thank everyone for all their help. It seems that this is heading toward a solution, and I couldn't have gotten there without you, especially D-Man and Michael Reilly. On Mon, 19 Mar 2001 13:54:54 -0500 (EST), "Michael P. Reilly" <arcege@shore.net> wrote about Re: [Tutor] Re: Help with 500 error on cgi script: :Did you build your copy of Python with the proper directory? Looking at :your past output: :: Could not find platform independant libraries <prefix> :: Could not find platform dependant libraries <exec_prefix> :: Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] : :This sounds like two things, that first you did not do "make install" :but are running Python out of the build/distribution directory (I've :had this problem myself when I was testing out 2.0 with my scripts). No, I believe I did do "make install". :And the second, based on the info above, you did not change the install :prefix and Python thinks is should be looking in /usr/local/...; Well, I plead guilty to that. I think I did the impatient install, where I did not try to configure anything, but just typed "make install", and was done with it. Still, at the point in time that I installed this, I don't think I would even have known how to configure the paths or what they should have been. (Is it obvious that I'm no Unix maven ?? Nah, of course not.) : you :will want to reconfigure with "--prefix=/big/dom/xthinkspot" and :install Python in /big/dom/xthinkspot/bin/python, with the libraries in :/big/dom/xthinkspot/lib/python2.0. Great. I will have to do that. Later. I guess I will have to temporarily disable or pause all the scripts that I have running on my site that are using Python. Then remove/uninstall my current copy. Then reinstall in the correct place. Any tips on uninstalling? I have all the files in the /big/dom/xthinkspot/Python-2.0 director and its subdirectories. Can I simply delete that? :Then when you install to cut down on how much is copied, run: : make bininstall libinstall sharedinstall :or if you want the executable to be "python2.0" instead, use :"altbininstall" instead of "bininstall". : :You may even want to think about making a more "diskspace-friendly" :build for yourself. Run configure with: : LDFLAGS=-s CFLAGS=-O3 ./configure --prefix=... :(make optimized code and strip executables; if -O3 breaks things, try :-O2 instead). You could even get rid of the .pyo files afterward since :most ppl don't use the -O option to python. Thanks for the tips. :There is nothing wrong with GCC 2.7.2. ...<snipped>... : :PS: I just reconfigured Python 2.0 on my FreeBSD 3.x box with: : $ LDFLAGS=-s CFLAGS=-O3 ./configure --without-threads --prefix=$HOME : $ make all altbininstall libinstall sharedinstall : $ cd /tmp #must be in different directory : $ $HOME/bin/python2.0 -c 'import test.autotest' : [507]golem> $HOME/bin/python2.0 : Python 2.0 (#2, Mar 19 2001, 13:28:45) : [GCC 2.7.2.1] on freebsd3 : Type "copyright", "credits" or "license" for more information. : >>> : :I got the standard number of tests stats (80 OK, 1 failed (largefile), :26 skipped). Question, about the above snippets: what does the --without-threads option do? Do I want that? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Mon Mar 19 20:37:31 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 12:37:31 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script References: <quv8bto7r8s6f1tckc7qpmuir0kvufp1nb@4ax.com> <mailman.984909623.8814.python-list@python.org> <5739bt04e50ku01rn3dptgqch3l07p2cnf@4ax.com> <m37l1m282u.fsf@master.athome> <237AE660FEF@kserver.org> <20010318184607.A22841@harmony.cs.rit.edu> <E14 Message-ID: <E14f6Pd-0004bo-00@mail.python.org> f3hf-0005oE-00@mail.python.org> <20010319144829.A23716@harmony.cs.rit.edu> In-Reply-To: <20010319144829.A23716@harmony.cs.rit.edu> X-Mailer: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <FC65773FF8@kserver.org> On Mon, 19 Mar 2001 14:48:29 -0500, D-Man <dsh8290@rit.edu> wrote about Re: [Tutor] Re: Help with 500 error on cgi script: :On Mon, Mar 19, 2001 at 09:44:13AM -0800, Sheila King wrote: :| On Mon, 19 Mar 2001 11:04:31 -0500, D-Man <dsh8290@rit.edu> wrote about Re: :| [Tutor] Re: Help with 500 error on cgi script: :| :$ su username :| : :| :My previous environment remains (ie PATH, etc) but if I use :| : :| :$ su - username :| : :| :I get a new environment, the environment specified by that user's :| :.bash_profile/.bashrc. :| :| Either of these gives me the following error message: :| while opening UTMP file: Permission denied :| while opening UTMP file: Permission denied : :Did you actually type "username"? ;-). Er, um, well, only the first time. But I did get the same error message, even when I typed my *real* username, and the error messages above were generated with the *real* username. ;-) : I don't really know what that :error means. Usually for me it works, or it says bad password. Maybe :they built a special version of su that doesn't allow users like you :to use it? Probably they won't allow users like me to use it. :| Here is the output: :| :| ----------------------------------------------- :| 2.0 (#1, Jan 15 2001, 01:09:04) :| [GCC 2.7.2.3] :| :| /usr/local/lib/python2.0/ :| /usr/local/lib/python2.0/plat-linux2 :| /usr/local/lib/python2.0/lib-tk :| /usr/local/lib/lib-dynload :| :| Those are the paths :| ----------------------------------------------- : :Those paths don't even exist, do they? Nope. I tried to go there, and just got error messages. :Now we know the correct paths to use (the output from your interactive :run) you can just use those to make this script work. : :import sys :sys.exec_prefix="/big/dom/xthinkspot/Python-2.0/Lib" : :# now the rest of your script : : : :If that doesn't work, then : :import sys :sys.path = \ : [ : "" , : "/big/dom/xthinkspot/Python-2.0/Lib" , : "/big/dom/xthinkspot/Python-2.0/Lib/plat-linux2" , : "/big/dom/xthinkspot/Python-2.0/Lib/lib-tk" , : "/big/dom/xthinkspot/Python-2.0/Modules" : ] :# now the rest of your script : : :should work. Since none of the paths in sys.path were correct I am :simply assigning the correct version to it here, instead of just :inserting the extra path you want. Thanks. That's what I'm doing for now, and it seems to work, until I get a chance to re-install. :| :When you run the interpreter at an interactive shell prompt and import :| :cgi, where does it find cgi? Do this: :| : :| >>> import cgi :| >>> print sys.modules["cgi"] :| <module 'cgi' from '/big/dom/xthinkspot/Python-2.0/Lib/cgi.pyc'> :| >>> :| :| :If we can figure out where (and how) it is getting 'cgi' interactively :| :then it should be easier to find it when executed by apache. :| :| Well, I feel like I have enough to try something else now. Thanks for the :| help. : :The thing I wonder now is why does it find the right path when you run :it interactively, but not as a cgi script. Perhaps you did something :(like set PYTHONPATH, or maybe just PATH) in your login scripts that :makes it work from a login. Yes, I did change my PATH variable in my .bash_profile file. :I would recommend following Arcege's suggestion of rebuilding the :interpreter using the proper arguments to configure so that the :correct default paths are hard-coded in to the interpreter. Will do. :| Well, thanks for the tips. I know I have at least one student who is very :| intersted in cgi and web programming in general, which is why I'm even :| entertaining the notion of trying this. : :Perhaps it would be advantageous to set up a Debian box to be a server :for the students? Then you would only have 1 system to set up with :apache, etc and students could use remote login to work with it. :Although, if they only know how to use MSVC++ and Windows Explorer it :would probably be more of a pain for them than it is worth. Unless :they are really interested in *nix and want to learn it, of course. : :I develop using bash+(g)vim+(print|cout|printf|System.out.print) most :of the time. Sometimes I actually use a real debugger too ;-). Nooo, I don't think I will do anything with Debian (or other *nix). First off, there is no machine available, nor is there space in the classroom for it. Secondly, can you say: "28-stand alone, non-networked computer lab". (It is no fun administrating such a lab, I can assure you.) Also, I only have about two weeks for these projects, no one has expressed interest in other OS's (they even seem surprised when I refer to MS as the "evil empire"--they do not "get it"). In two weeks, teaching cgi scripts on an OS they are familiar with, in a programming language they already know will be more than sufficient fun, I'm sure. We don't use MSVC++. We use MetroWerks CodeWarrior Pro 5. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From arcege@shore.net Mon Mar 19 20:41:38 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 19 Mar 2001 15:41:38 -0500 (EST) Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <ECE57802CF@kserver.org> from Sheila King at "Mar 19, 2001 12:20:32 pm" Message-ID: <E14f6TC-0006Lm-00@nautilus.shore.net> > :Did you build your copy of Python with the proper directory? Looking at > :your past output: > :: Could not find platform independant libraries <prefix> > :: Could not find platform dependant libraries <exec_prefix> > :: Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] > : > :This sounds like two things, that first you did not do "make install" > :but are running Python out of the build/distribution directory (I've > :had this problem myself when I was testing out 2.0 with my scripts). > > No, I believe I did do "make install". I said "sounds like." :) > : you > :will want to reconfigure with "--prefix=/big/dom/xthinkspot" and > :install Python in /big/dom/xthinkspot/bin/python, with the libraries in > :/big/dom/xthinkspot/lib/python2.0. > > Great. I will have to do that. Later. I guess I will have to temporarily > disable or pause all the scripts that I have running on my site that are using > Python. Then remove/uninstall my current copy. Then reinstall in the correct > place. Mostly you just have to change the shebang (#!) line to point to the new interpreter when it is installed. > Any tips on uninstalling? I have all the files in the > /big/dom/xthinkspot/Python-2.0 director and its subdirectories. Can I simply > delete that? If the only thing in there are the binaries (and Python's copied library files), then yes, you could just delete the whole directory. (When deleting a whole directory tree, always either a) put an explicit pathname to the directory, or b) check what directory you are in first.) If your Python source distribution is in there, then I would perform a "make distclean" and run configure again. > :PS: I just reconfigured Python 2.0 on my FreeBSD 3.x box with: > : $ LDFLAGS=-s CFLAGS=-O3 ./configure --without-threads --prefix=$HOME > : $ make all altbininstall libinstall sharedinstall > : $ cd /tmp #must be in different directory > : $ $HOME/bin/python2.0 -c 'import test.autotest' > : [507]golem> $HOME/bin/python2.0 > : Python 2.0 (#2, Mar 19 2001, 13:28:45) > : [GCC 2.7.2.1] on freebsd3 > : Type "copyright", "credits" or "license" for more information. > : >>> > : > :I got the standard number of tests stats (80 OK, 1 failed (largefile), > :26 skipped). > > Question, about the above snippets: > what does the --without-threads option do? Do I want that? FreeBSD does not have good threads support, and the Python executable will crash if no stdin is given (like when called from Apache). It is not a bug with Python, but with FreeBSD. Adding the --without-threads option compiles with the correct configuration. If you aren't one FreeBSD, don't worry about it. :) -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From douglas.shawhan@ae.ge.com Mon Mar 19 20:58:05 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Mon, 19 Mar 2001 15:58:05 -0500 Subject: [Tutor] readlinesX Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F256C@ma001dataaege.ae.ge.com> I have been scouting around on the python.org site looking for references to readlineX. Where can I find the whole poop on this function? From phil.bertram@clear.net.nz Mon Mar 19 21:23:44 2001 From: phil.bertram@clear.net.nz (Phil Bertram) Date: Tue, 20 Mar 2001 09:23:44 +1200 Subject: [Tutor] I can't work out how to sort lists of lists Message-ID: <000b01c0b0ba$fe741540$69f2a7cb@pf05nt.bayernz.co.nz> This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C0B11F.75CF0D20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I have a list thus, a=3D[ (8,9,10), (1,2,3), (5,6,7) ]=20 I wish to sort the list by the second element of each tuple. I can not seem to work out how to get the sort method's compare function = to work. Any ideas ? Thanks in advance Phil B ------=_NextPart_000_0008_01C0B11F.75CF0D20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Dwindows-1252"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR></HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Hi all,</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>I have a list thus,</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>a=3D[ (8,9,10), (1,2,3), (5,6,7) =20 ] </FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>I wish to sort the list by the second element of = each=20 tuple.</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>I can not seem to work out how to get the sort = method's=20 compare function to work.</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>Any ideas ?</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>Thanks in advance</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>Phil B</FONT></DIV></BODY></HTML> ------=_NextPart_000_0008_01C0B11F.75CF0D20-- From cwebster@nevada.edu Mon Mar 19 21:39:11 2001 From: cwebster@nevada.edu (Corran Webster) Date: Mon, 19 Mar 2001 13:39:11 -0800 Subject: [Tutor] I can't work out how to sort lists of lists In-Reply-To: <000b01c0b0ba$fe741540$69f2a7cb@pf05nt.bayernz.co.nz> References: <000b01c0b0ba$fe741540$69f2a7cb@pf05nt.bayernz.co.nz> Message-ID: <f05001903b6dc2bf7bc20@[131.216.77.14]> At 9:23 AM +1200 20/3/01, Phil Bertram wrote: >Hi all, > >I have a list thus, > >a=[ (8,9,10), (1,2,3), (5,6,7) ] > >I wish to sort the list by the second element of each tuple. > >I can not seem to work out how to get the sort method's compare >function to work. > >Any ideas ? Perhaps the simplest way is to define your own comparison function: def cmpsecond(x, y): return cmp(x[1], y[1]) a.sort(cmpsecond) should do the trick. You can write it more concisely with a lambda as: a.sort(lambda x, y: cmp(x[1], y[1])) For more info on tricks you can use with custom comparison functions, see the Sorting Mini-HOWTO. http://py-howto.sourceforge.net/sorting/sorting.html Regards, Corran From Glen@ihello-inc.com Mon Mar 19 21:42:42 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Mon, 19 Mar 2001 13:42:42 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A472@go.ihello.com> Hi, I am trying to re-write a shell script that i have that checks for and verifies specified content on an html page. The following is the area that I am having problems with: os.chdir('/sec/bb/ext/bb-hcheck/cfg') LIST = os.listdir(os.getcwd()) for item in LIST: #NAME = 'cut --character=5- ' + item SERVER = os.popen('cut --character=5- ' + item).read() LOOK_FOR = os.popen('cut -- character=9- ' + item).read() #RESULTS = os.system('LYNX SERVER | grep LOOK_FOR') RESULTS_TEMPLATE = 'curl --include --max-time 30 %(server)s | grep %(LOOK_FOR)s' RESULTS = RESULTS_TEMPLATE % {'server' : SERVER, 'look_for': LOOK_FOR } FINAL = os.system(RESULTS) if [ RESULTS != 0 ]: COLOR = 'red' STATUS = 'Specified content:' + LOOK_FOR + 'was not found' else: COLOR = 'green' STATUS = 'Successfully found ' + LOOK_FOR running the program I get the following errors: ./bb-hcheck1.py cut: you must specify a list of bytes, characters, or fields Try `cut --help' for more information. Traceback (innermost last): File "./bb-hcheck1.py", line 59, in ? File "./bb-hcheck1.py", line 34, in main KeyError: LOOK_FOR Does anyone have any idea what I'm doing wrong? Am I taking the right track by trying to call the same program(curl,cut) that the shell script uses, or should I be doing this completely differently? Thanks Glen From douglas.shawhan@ae.ge.com Mon Mar 19 21:52:26 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Mon, 19 Mar 2001 16:52:26 -0500 Subject: [Tutor] disregard(doofus) Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F256E@ma001dataaege.ae.ge.com> *blush* - no wonder I could find nothing on readlinex..... Lysdexics of the world untie! From jovoslav@dir.bg Mon Mar 19 21:54:02 2001 From: jovoslav@dir.bg (jovoslav@dir.bg) Date: Mon, 19 Mar 2001 23:54:02 +0200 Subject: [Tutor] Fwd: asyncore and SocketServer Message-ID: <web-20031056@dir.bg> This is a multi-part MIME message --_===20031056====dir.bg===_ Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: 8bit --- sledva prepratenoto s"obschenie --- ----------------------------- Free mail from www.dir.bg! --_===20031056====dir.bg===_ Content-Type: message/rfc822 From: <jovoslav@dir.bg> Subject: asyncore and SocketServer To: tutor@python.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Fri, 16 Mar 2001 08:49:25 +0200 Message-ID: <web-19853586@dir.bg> MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: 8bit Hello, Now it's so. I'm new to python and as a small project I started writing a small chat server ( for LAN ). My first spurce code looked like this: >>> import socket >>> host = '' >>> port = 3000 >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.bind((host, port)) >>> s.listen(5) " so far so good " >>> conn, addr = s.accept() >>> while 1: >>> send_data = raw_input('kiligarikond > ') " a kind of nickname " >>> conn.send(send_data) >>> recv_data = conn.recv(1024) " for example " >>> print 'sunay > ', recv_data END OK, It run well but everything run synchronously. That was the problem. The user had to make a request and when it came on the other side, the other user was on turn. The second try was ( after examining the asyncore module documentation ): >>> import socket >>> import asyncore >>> class server(asyncore.dispatcher): >>> def __init__(self): ... host = '' ... port = 3000 ... asyncore.dispatcher.__init__(self) ... self.create_socket(socket.AF_INET, socket.SOCK_STREAM) ... self.bind((host, port)) ... self.listen(5) ... self.accept() ... >>> serv = server() >>> Now the problem. : I made my program recieving incoming connections asynchronously. But I made only this. I would be very greatfull if someone could tell me how to write the other sections of the program. Or if someone could tell me an online book about network programming in python. Or, just tell me the URL where I can find some usefull examples. Thanks very much :) J O V O !!! :^) ----------------------------- Free mail from www.dir.bg! --_===20031056====dir.bg===_-- From dsh8290@rit.edu Mon Mar 19 22:08:09 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 19 Mar 2001 17:08:09 -0500 Subject: [Tutor] disregard(doofus) In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F256E@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Mon, Mar 19, 2001 at 04:52:26PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F256E@ma001dataaege.ae.ge.com> Message-ID: <20010319170809.C23858@harmony.cs.rit.edu> On Mon, Mar 19, 2001 at 04:52:26PM -0500, Shawhan, Douglas (GEAE, GECC) wrote: | *blush* - no wonder I could find nothing on readlinex..... Lysdexics of the | world untie! <grin> Dyslexia strikes 30 in 1 ya know ;-). (at least, that's what I've heard) -D From dsh8290@rit.edu Mon Mar 19 22:14:34 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 19 Mar 2001 17:14:34 -0500 Subject: [Tutor] automatic checking of web pages In-Reply-To: <A50594A71D5FD311A00200902745F06F18A472@go.ihello.com>; from Glen@ihello-inc.com on Mon, Mar 19, 2001 at 01:42:42PM -0800 References: <A50594A71D5FD311A00200902745F06F18A472@go.ihello.com> Message-ID: <20010319171434.D23858@harmony.cs.rit.edu> On Mon, Mar 19, 2001 at 01:42:42PM -0800, Glen Bunting wrote: | Hi, | | I am trying to re-write a shell script that i have that checks for and | verifies specified content on an html page. The following is the area that | I am having problems with: | | os.chdir('/sec/bb/ext/bb-hcheck/cfg') | LIST = os.listdir(os.getcwd()) | for item in LIST: | #NAME = 'cut --character=5- ' + item | SERVER = os.popen('cut --character=5- ' + item).read() ^ Is that space supposed to be there? The shell will separate --character=5- and the contents of the variable item into separate arguments. | LOOK_FOR = os.popen('cut -- character=9- ' + item).read() ^ | #RESULTS = os.system('LYNX SERVER | grep LOOK_FOR') | RESULTS_TEMPLATE = 'curl --include --max-time 30 %(server)s | grep | %(LOOK_FOR)s' | RESULTS = RESULTS_TEMPLATE % {'server' : SERVER, | 'look_for': LOOK_FOR } | FINAL = os.system(RESULTS) | if [ RESULTS != 0 ]: | COLOR = 'red' | STATUS = 'Specified content:' + LOOK_FOR + 'was not found' | else: | COLOR = 'green' | STATUS = 'Successfully found ' + LOOK_FOR | | | running the program I get the following errors: | ./bb-hcheck1.py | cut: you must specify a list of bytes, characters, or fields | Try `cut --help' for more information. | Traceback (innermost last): | File "./bb-hcheck1.py", line 59, in ? | File "./bb-hcheck1.py", line 34, in main | KeyError: LOOK_FOR | | Does anyone have any idea what I'm doing wrong? Am I taking the right | track by trying to call the same program(curl,cut) that the shell script | uses, or should I be doing this completely differently? If you get the arguments right, you can get away with using the same external programs. I would recommend, however, trying to use the python library to help with this (see htmllib). If you only want to run the script on unix systems that has these external programs in the path, and assume that they interpret the arguments as you expected them to (oftentimes GNU programs have different/more arguments than non-GNU programs, ex ls tar make) then it is ok to use os.system an use them. If you want your script to be as portable as python is, then you should only use standard python modules (or your own modules, of course) and not rely on external programs. -D From kalle@gnupung.net Mon Mar 19 23:09:24 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 20 Mar 2001 00:09:24 +0100 Subject: [Tutor] readlinesX In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F256C@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Mon, Mar 19, 2001 at 03:58:05PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F256C@ma001dataaege.ae.ge.com> Message-ID: <20010320000924.A359@apone.network.loc> Sez Shawhan, Douglas (GEAE, GECC): > I have been scouting around on the python.org site looking for references > to readlineX. Where can I find the whole poop on this function? That would be xreadlines? There is no good documentation at the moment, but here's what I know: The below applies to the function xreadlines in the module xreadlines, and the file object method xreadlines. It returns a sequence object, much like the list returned by readlines, only it doesn't read all the lines into memory but reads them "on demand" (reading ahead a bit for performance, I think). Thus, it's now possible to do for line in file.xreadlines(): # formerly file.readlines() # do stuff with line without reading the entire file into memory. This does away with while 1: line = file.readline() if not line: break # do stuff with line which is sort of ugly. The above is IIRC, AFAIK and IMHO. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From tcondit@gblx.net Tue Mar 20 00:52:26 2001 From: tcondit@gblx.net (Timothy Condit) Date: Mon, 19 Mar 2001 17:52:26 -0700 Subject: [Tutor] multi-user program question Message-ID: <20010319175225.A19225@gblx.net> Hi, This is not really a python question in the strict sense; if this is the wrong place to ask, just say so. I'm going to be writing a python script for use by several (~15) people here at work. It will allow users to request paid time off (vacations, personal days, etc.). Before getting too far into it, I'm trying to work out a couple questions. I'm working on UNIX, and want to use the filesystem to store info about the user's personal info (passwords, usernames, etc.), and their pto request info. What I'm thinking right now is that I want to make a /home/pto/ directory, then make a password file within there, or in /etc/pto, then add user directories inside /home/pto/ to hold pto request info. I've got root access to the UNIX box, but don't want to use that for anything. I've been thinking about just going in and creating the pto dir manually, then using it to store all that info, but there are a couple problems with that approach, too. These are the things I'm trying to figure out: * what is the best way to store the pto request info? Creating a home dir requires root access, so I want to find an alternative to that. * if using a pto home dir turns out to be the best way to go, how can I run a script as user pto? A friend of mine says he runs perl scripts this way, but I cannot figure out how (and he's not around). * if I use the /home/pto/<user>/ directory scheme, how can I arrange so that an admin (my boss) can still view all that info but users cannot view each other's info? There will only be one admin account, who will add and delete users, accept/decline pto requests, etc. So he needs to be able to view all user info. I am inclined to think that these sort of issues have come up and been resolved by others, and am curious about any good ideas anyone has. I've got my own ideas, but so far nothing that feels quite right. Thanks in advance, -- Tim Condit Det-NCC Global Crossing From deirdre@deirdre.net Tue Mar 20 01:01:44 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 19 Mar 2001 17:01:44 -0800 (PST) Subject: [Tutor] multi-user program question In-Reply-To: <20010319175225.A19225@gblx.net> Message-ID: <Pine.LNX.4.31.0103191657550.9324-100000@emperor.deirdre.org> On Mon, 19 Mar 2001, Timothy Condit wrote: > I'm going to be writing a python script for use by several (~15) > people here at work. It will allow users to request paid time off > (vacations, personal days, etc.). Before getting too far into it, I'm > trying to work out a couple questions. > * what is the best way to store the pto request info? Creating a home > dir requires root access, so I want to find an alternative to that. Why not use a database like mysql? Postgres? > * if using a pto home dir turns out to be the best way to go, how can > I run a script as user pto? A friend of mine says he runs perl scripts > this way, but I cannot figure out how (and he's not around). http://www.python.org/doc/current/lib/os-procinfo.html > * if I use the /home/pto/<user>/ directory scheme, how can I arrange so > that an admin (my boss) can still view all that info but users cannot > view each other's info? There will only be one admin account, who will > add and delete users, accept/decline pto requests, etc. So he needs to > be able to view all user info. > I am inclined to think that these sort of issues have come up and been > resolved by others, and am curious about any good ideas anyone has. I've > got my own ideas, but so far nothing that feels quite right. My inclination would be to slap a web interface on it; this hides the data quite neatly. Access can be handled with an htaccess file and people can see only what they have access to. You can still plop the info into a database or a text file. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From shaleh@valinux.com Tue Mar 20 02:05:29 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 19 Mar 2001 18:05:29 -0800 Subject: [Tutor] readlinesX In-Reply-To: <20010320000924.A359@apone.network.loc>; from kalle@gnupung.net on Tue, Mar 20, 2001 at 12:09:24AM +0100 References: <326FFBE574BED411ACA100D0B79DC2B53F256C@ma001dataaege.ae.ge.com> <20010320000924.A359@apone.network.loc> Message-ID: <20010319180529.A5179@valinux.com> On Tue, Mar 20, 2001 at 12:09:24AM +0100, Kalle Svensson wrote: > Sez Shawhan, Douglas (GEAE, GECC): > > I have been scouting around on the python.org site looking for references > > to readlineX. Where can I find the whole poop on this function? > > The below applies to the function xreadlines in the module xreadlines, and > the file object method xreadlines. > It returns a sequence object, much like the list returned by readlines, only > it doesn't read all the lines into memory but reads them "on demand" > (reading ahead a bit for performance, I think). > without reading the entire file into memory. This does away with Yep, that about sums it up. It is analogous to range v. xrange. The idea here is that if you are reading a HUGE file, using readlines() is bad. Since you almost never know ahead of time how big a file will be (and they usually grow), readlines() is a memory sink waiting to happen. As a casual user, all you need to know is that as long as you are using python 2.x, always use xreadlines() instead of readlines(). Works the same, looks the same, it is just kinder to the computer. From tutor@python.org" <tutor@python.org Tue Mar 20 05:35:42 2001 From: tutor@python.org" <tutor@python.org (VanL) Date: Mon, 19 Mar 2001 22:35:42 -0700 Subject: [Tutor] Defining a new class Message-ID: <3AB6EC2E.944DE5F4@lindbergs.org> Hello, I am just getting started with Python so I thought I would implement a lot of the classical data structures in Python so as to get a feel for it. I am running into a few difficulties, tho. Here is my first Python class: class LinkedList: def __init__(self, name, object=None): self.label = name if object: self.link = object else: self.link = None def next(self): if self.link: return link else: return None def label(self): return self.label def link(self, object): self.link = object def unlink(self): self.link = None def rename(self, name): self.label = name Some things work as expected; I can declare an object of type LinkedList. I get some strange results overall, tho. For example: >>> from LinkedList import * >>> dir(LinkedList) ['__doc__', '__init__', '__module__', 'label', 'link', 'next', 'rename', 'unlink'] So far so good. >>> Me = LinkedList('MyName') >>> MyFriend = LinkedList('HisName', Me) >>> print Me.label() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: call of non-function (type string) I'm a little confused about that. I'm calling a function, aren't I? Still, after a little checking, I found >>> print Me.label MyName Still, I am confused. Moreover, the next function isn't working as I expected. I thought that >>> print Me.next should return None Instead, it returns <method LinkedList.next of LinkedList instance at 0082A45C> Similarly, >>> print (MyFriend.next).label should return MyName Instead, it returns Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: label Also, >>> print MyFriend.next <method LinkedList.next of LinkedList instance at 0082D65C> seems to show that I am not even getting back to my original node "Me". Could anyone enlighten me? Thanks very much, Van From deirdre@deirdre.net Tue Mar 20 05:39:08 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 19 Mar 2001 21:39:08 -0800 (PST) Subject: [Tutor] Defining a new class In-Reply-To: <3AB6EC2E.944DE5F4@lindbergs.org> Message-ID: <Pine.LNX.4.31.0103192138020.14411-100000@emperor.deirdre.org> On Mon, 19 Mar 2001, VanL wrote: > def label(self): > return self.label > >>> Me = LinkedList('MyName') > >>> MyFriend = LinkedList('HisName', Me) > >>> print Me.label() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: call of non-function (type string) > > I'm a little confused about that. I'm calling a function, aren't I? Well, insofar as you've defined a method AND a variable with the same name, that would be interpreter dependent. Evidently it parses for the variable first. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From van@lindbergs.org Tue Mar 20 05:51:47 2001 From: van@lindbergs.org (VanL) Date: Mon, 19 Mar 2001 22:51:47 -0700 Subject: [Tutor] Help with lists References: <Pine.LNX.4.21.0103140547010.31530-100000@hkn.eecs.berkeley.edu> Message-ID: <3AB6EFF3.2BF44AB5@lindbergs.org> To everyone who helped me: Thank you for your kind response. You were right - I had not rewound the file, so I was matching an empty line at the end (i.e., signalling that I had successfully made it through the file) and never making any of the other tests. I was able to get the code working -- it has inspired me to become proficient in Python. This was my first script in Python and it was a joy to write. Thanks! -Van From sheila@thinkspot.net Tue Mar 20 05:51:36 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 19 Mar 2001 21:51:36 -0800 Subject: [Tutor] Re: Help with 500 error on cgi script In-Reply-To: <E14f4nu-0002Es-00@nautilus.shore.net> References: <E14f3hf-0005oE-00@mail.python.org> <E14f4nu-0002Es-00@nautilus.shore.net> Message-ID: <12A462E24C5@kserver.org> Final summary: Re-install with attention to the --prefix option solved my problems. I couldn't wait. I ill-advisedly spent the time on the re-install today. But, I'm much happier for it. Everything is working splendidly. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dyoo@hkn.eecs.berkeley.edu Tue Mar 20 06:53:06 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 19 Mar 2001 22:53:06 -0800 (PST) Subject: [Tutor] Help with lists In-Reply-To: <3AB6EFF3.2BF44AB5@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103192252180.29899-100000@hkn.eecs.berkeley.edu> On Mon, 19 Mar 2001, VanL wrote: > Thank you for your kind response. You were right - I had not rewound the > file, so I was matching an empty line at the end (i.e., signalling that I had > successfully made it through the file) and never making any of the other > tests. Very cool! I'm glad it's working for you now. > I was able to get the code working -- it has inspired me to become proficient > in Python. This was my first script in Python and it was a joy to write. > Thanks! Feel free to talk to us again; it's getting too quiet in here again. Talk to you later! From scarblac@pino.selwerd.nl Tue Mar 20 07:53:25 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 20 Mar 2001 08:53:25 +0100 Subject: [Tutor] Defining a new class In-Reply-To: <3AB6EC2E.944DE5F4@lindbergs.org>; from van@lindbergs.org on Mon, Mar 19, 2001 at 10:35:42PM -0700 References: <3AB6EC2E.944DE5F4@lindbergs.org> Message-ID: <20010320085325.A11017@pino.selwerd.nl> On Mon, Mar 19, 2001 at 10:35:42PM -0700, VanL wrote: > I am just getting started with Python so I thought I would implement > a lot of the classical data structures in Python so as to get a feel > for it. I am running into a few difficulties, tho. Here is my > first Python class: > > class LinkedList: > > def __init__(self, name, object=None): > self.label = name > if object: self.link = object > else: self.link = None > > def next(self): > if self.link: return link > else: return None > > def label(self): > return self.label > > def link(self, object): > self.link = object > > def unlink(self): > self.link = None > > def rename(self, name): > self.label = name > > > Some things work as expected; I can declare an object of type > LinkedList. I get some strange results overall, tho. For example: > > >>> from LinkedList import * > >>> dir(LinkedList) > ['__doc__', '__init__', '__module__', 'label', 'link', 'next', > 'rename', 'unlink'] > > So far so good. > > >>> Me = LinkedList('MyName') > >>> MyFriend = LinkedList('HisName', Me) > >>> print Me.label() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: call of non-function (type string) Your function is called label, then in your __init__ you make a variable of the same name... 'Me.label' looks for 'label' in the instance first (finds the variable) and only if it finds nothing will it go look in the class to see if it has a 'label'. So, indeed, Me.label is a string, not a function, and you can't call it. > Still, I am confused. Moreover, the next function isn't working as > I expected. I thought that > >>> print Me.next > > should return > > None > > Instead, it returns > > <method LinkedList.next of LinkedList instance at 0082A45C> Me.next is simply the method (you didn't overwrite that name). So you can call it, ie you're looking for 'Me.next()'. I find I never use linked lists in Python by the way, always just Python lists. And so many other standard hard algorithms and data structures become trivial when you have dictionaries available :). -- Remco Gerlich From alan.gauld@bt.com Tue Mar 20 11:30:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 20 Mar 2001 11:30:29 -0000 Subject: [Tutor] Defining a new class Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D65B@mbtlipnt02.btlabs.bt.co.uk> > class LinkedList: > def label(self): > return self.label self.label is a text field label is a method of self Hence when you create Me which item do you want to access the field or the method? Because the field may be a reference to a function simply putting () after the name doesn't help. Because Python doesn't have implicitly private object members you need to enforce it. Make your field names have underscores in front or use a naming convention like mLabel. Then: def label(self): return self.mLabel No ambiguity. > Still, after a little checking, I found > > >>> print Me.label > MyName Coz here you are printing the field. > >>> print Me.next There is no field 'next' it is a bound method > <method LinkedList.next of LinkedList instance at 0082A45C> which is ewhat Python tells you. > Similarly, > >>> print (MyFriend.next).label > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: label and the bound method object does not have an attribute called 'label. You need print MyFriend.next().label Simple answer is don't create metjods with the same name as attributes. Use a naming convention to avoid it. Personally I tend to use 'the' as in: def label(self): return self.theLabel and parameters of methods us 'a/an' as in: def link(self,anObject): self.theLink = anObject HTH, Alan G From arcege@shore.net Tue Mar 20 13:21:59 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 20 Mar 2001 08:21:59 -0500 (EST) Subject: [Tutor] multi-user program question In-Reply-To: <20010319175225.A19225@gblx.net> from Timothy Condit at "Mar 19, 2001 5:52:26 pm" Message-ID: <E14fM5H-0007hk-00@nautilus.shore.net> > This is not really a python question in the strict sense; if this is the > wrong place to ask, just say so. > > I'm going to be writing a python script for use by several (~15) people > here at work. It will allow users to request paid time off (vacations, > personal days, etc.). Before getting too far into it, I'm trying to work > out a couple questions. > > I'm working on UNIX, and want to use the filesystem to store info about > the user's personal info (passwords, usernames, etc.), and their pto > request info. > > What I'm thinking right now is that I want to make a /home/pto/ > directory, then make a password file within there, or in /etc/pto, then > add user directories inside /home/pto/ to hold pto request info. I've > got root access to the UNIX box, but don't want to use that for > anything. I've been thinking about just going in and creating the pto > dir manually, then using it to store all that info, but there are a > couple problems with that approach, too. > > These are the things I'm trying to figure out: > > * what is the best way to store the pto request info? Creating a home > dir requires root access, so I want to find an alternative to that. I suggest creating the "pto home" directory (it just needs to be one directory where the data will be stored) with group-writable permissions. Give all fifteen users access to the group, then allow files to be updated with those permissions. The users don't need to be root, and you can get some level of security by controlling the permissions (I do suggest creating a "pto" account to own things). > * if using a pto home dir turns out to be the best way to go, how can I > run a script as user pto? A friend of mine says he runs perl scripts > this way, but I cannot figure out how (and he's not around). You can't do that in perl, or in Python. You need a setuid program to change a user. This is something in the operating system, not a language (cf. chmod(2). But if you set up the permissions correctly, you shouldn't need setuid at all. > * if I use the /home/pto/<user>/ directory scheme, how can I arrange so > that an admin (my boss) can still view all that info but users cannot > view each other's info? There will only be one admin account, who will > add and delete users, accept/decline pto requests, etc. So he needs to > be able to view all user info. Deirdre gave the suggestion of using a database. You may not need to go to the level of mysql or postgres, but that gives you the security that you will want - users can insert rows in a table but not read them, and manager can access those rows (read, delete, change, etc.). If you are really concerned you could create your own data server, but if you were going to do that, then I'd suggest installing MySQL. SQL can be a little tricky if you aren't used to it (what should the table look like, how to get security correct, etc.); if you want to get this going faster than you can pick up SQL, think about your own server for added security. But if you have the data files set up correctly then this shouldn't be a big deal. It depends on how much you are concerned with different levels of security. > I am inclined to think that these sort of issues have come up and been > resolved by others, and am curious about any good ideas anyone has. I've > got my own ideas, but so far nothing that feels quite right. I have a product called crd-mail that does a lot of what you describe above. It is a multi-user, multi-host, call-tracking system, originally written in Bourne shell. It handles all the locking problems that you'll have when multiple users on different machines try to access a database. I ported it to Python sometime ago, but that version has never made it out of my hands. Let me know if you would like to see some of relevant. In short, anything that requires a level of security (e.g. anything dealing with payroll) need to be designed carefully. Make sure you have all your requirements layed out first. There are a lot of design choices you could use, which one depends more on the project's requirements. For example, do you want/need a web interface (a web interface doesn't necessarily mean IE/Netscape, you could use Python's httplib from a command-line interface)? Will there be a command-line interface? GUI (Tkinter, GTK, wxPython)? All these will affect how the data is handled, and can affect how the data is secured. Good luck, -Arcege PS: My crd-mail product does not have an open licensed because of past usage. So I cannot simply publish it on the net, unfortunately. -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From jthing@frisurf.no Tue Mar 20 13:42:14 2001 From: jthing@frisurf.no (John Thingstad) Date: Tue, 20 Mar 2001 14:42:14 +0100 Subject: [Tutor] re: VanL LinkedList Message-ID: <200103201343.OAA09177@mail49.fg.online.no> You wrote: >class LinkedList: > def __init__(self, name, object=None): > self.label = name > i f object: self.link = object > else: self.link = None > def next(self): > if self.link: return link > else: return None > def label(self): > return self.label > def link(self, object): > self.link = object > def unlink(self): > self.link = None > def rename(self, name): > self.label = name First the obvious. In function next you wrote: if self.link: return link link is the class method link. You meant self.link. Next is the scoping issue that is giving you trouble. You have both a class variable that is named label and a function that is named label. The label function is declared as local to the class. The variable self.label, however, belongs to the object instance and thus takes presedence You get the same problem with link. The nobrains solution is to rename the instance variables __label and __link. the __ extension up front means they are private (well, almost private) to the class. Not only does that better present the abstraction but it resolves the name conflict. The result is what you see below. It works fine. Given that lists are built into Python, and much more powerfull than this besides, it is of cource a pointless class. But then you probably know this. class LinkedList: def __init__(self, name, object=None): self.__label = name if object: self.__link = object else: self.__link = None def next(self): if self.__link: return self.__link else: return None def label(self): return self.__label def link(self, object): self.__link = object def unlink(self): self.__link = None def rename(self, name): self.__label = name From van@lindbergs.org Tue Mar 20 14:54:24 2001 From: van@lindbergs.org (VanL) Date: Tue, 20 Mar 2001 07:54:24 -0700 Subject: [Tutor] Self-referential objects and garbage collection Message-ID: <3AB76F20.53E82209@lindbergs.org> Hello, How does Python deal with self-referential objects? For example: class DLinkedList: def __init__(self, name, objprev=None, objnext=None): self.__label = name if objprev: self.__prevlink = objprev if objnext: self.__nextlink = objnext else: self.__prevlink = self self.__nextlink = self [methods snipped] I had understood that Python used a reference-counting scheme. Is this true, and is there a __destroy__ method to call for circular data structures? Thanks, Van From van@lindbergs.org Tue Mar 20 14:58:21 2001 From: van@lindbergs.org (VanL) Date: Tue, 20 Mar 2001 07:58:21 -0700 Subject: [Tutor] Sorry for the posting barrage Message-ID: <3AB7700D.869B9A11@lindbergs.org> Sorry for the posting barrage -- you all have been very helpful. I am just going through implementing a lot of the classic data structures and algorithms in an effort to learn Python. Please, ignore me (or tell me) if I become bothersome. VanL From van@lindbergs.org Tue Mar 20 15:02:51 2001 From: van@lindbergs.org (VanL) Date: Tue, 20 Mar 2001 08:02:51 -0700 Subject: [Tutor] Re: Linked Lists Message-ID: <3AB7711B.DC3B83A2@lindbergs.org> Thanks, the advice you all gave solved it. I had a question, tho: One person said: > Given that lists are built into Python, and much more powerfull than this besides, it is of cource a pointless class. Another said: > I find I never use linked lists in Python by the way, always just Python > lists. And so many other standard hard algorithms and data structures become > trivial when you have dictionaries available :). Yeah, the native Python lists support a log more operations. But I was under the impression that linked lists and lists were completely different data structures. Say, for instance, that you have a 10MB file. Is readlines() smart enough to not load the whole thing into memory at once? I know that readline() will only return one line, but it was my impression that it was a one-at a time dispatching from an in-memory list. In a similar vein, how would you use Python's native data types to represent a linked list? From scarblac@pino.selwerd.nl Tue Mar 20 14:52:30 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 20 Mar 2001 15:52:30 +0100 Subject: [Tutor] Self-referential objects and garbage collection In-Reply-To: <3AB76F20.53E82209@lindbergs.org>; from van@lindbergs.org on Tue, Mar 20, 2001 at 07:54:24AM -0700 References: <3AB76F20.53E82209@lindbergs.org> Message-ID: <20010320155230.A12066@pino.selwerd.nl> On Tue, Mar 20, 2001 at 07:54:24AM -0700, VanL wrote: > How does Python deal with self-referential objects? For example: > > class DLinkedList: > > def __init__(self, name, objprev=None, objnext=None): > self.__label = name > if objprev: self.__prevlink = objprev > if objnext: self.__nextlink = objnext > else: > self.__prevlink = self > self.__nextlink = self > > [methods snipped] > > I had understood that Python used a reference-counting scheme. Is > this true, and is there a __destroy__ method to call for circular > data structures? Yes, Python uses reference counting, and this is a problem. Instead of calling some sort of __destroy__ method, you must manually break the cycle, ie set self.__prevlink and the other to None before you let go of the last reference outside the object. Since 2.0 there is an optional garbage collector that will find these objects and clear them, but I don't have any experience with it yet, don't even know if it's on by default (I don't think so). On Linux/Unix you must give an option to ./configure when you compile Python to turn it on. -- Remco Gerlich From kalle@gnupung.net Tue Mar 20 15:13:21 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 20 Mar 2001 16:13:21 +0100 Subject: [Tutor] Self-referential objects and garbage collection In-Reply-To: <3AB76F20.53E82209@lindbergs.org>; from van@lindbergs.org on Tue, Mar 20, 2001 at 07:54:24AM -0700 References: <3AB76F20.53E82209@lindbergs.org> Message-ID: <20010320161321.A10786@father> Sez VanL: > Hello, > > How does Python deal with self-referential objects? For example: > > class DLinkedList: > > def __init__(self, name, objprev=None, objnext=None): > self.__label = name > if objprev: self.__prevlink = objprev > if objnext: self.__nextlink = objnext > else: > self.__prevlink = self > self.__nextlink = self > > [methods snipped] > > I had understood that Python used a reference-counting scheme. Is > this true, and is there a __destroy__ method to call for circular > data structures? Python versions 1.5.2 and earlier uses pure refcounting, and thus have problems with circular references. Version 2.0 (and future versions) has a hybrid scheme with mostly refcounting and a GC to break circular references. I'm not sure about version 1.6. More information is hard to come by, but check the python-dev archives if you're interested. IIRC, there has been some heavy discussion of the subject there. There is a __del__ method, see http://www.python.org/doc/current/ref/customization.html Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From scarblac@pino.selwerd.nl Tue Mar 20 15:05:26 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 20 Mar 2001 16:05:26 +0100 Subject: [Tutor] Self-referential objects and garbage collection In-Reply-To: <3AB7711B.DC3B83A2@lindbergs.org>; from van@lindbergs.org on Tue, Mar 20, 2001 at 08:02:51AM -0700 References: <3AB7711B.DC3B83A2@lindbergs.org> Message-ID: <20010320160526.B12066@pino.selwerd.nl> On Tue, Mar 20, 2001 at 08:02:51AM -0700, VanL wrote: > Thanks, the advice you all gave solved it. > > I had a question, tho: > > One person said: > > Given that lists are built into Python, and much more powerfull > than this besides, it is of cource a pointless class. > > Another said: > > I find I never use linked lists in Python by the way, always just > Python > > lists. And so many other standard hard algorithms and data > structures become > > trivial when you have dictionaries available :). > > Yeah, the native Python lists support a log more operations. But I > was under the impression that linked lists > and lists were completely different data structures. Yes. But you can often use lists where you would need a linked list in other languages. For instance, Python lists can grow, something that e.g. Pascal arrays can't. > Say, for instance, that you have a 10MB file. Is readlines() smart > enough to not load the whole thing into > memory at once? No, it will read it in all at once. You can give an optional second argument that is a sizehint, it won't read in much more than that. In a new version (2.1 I think), files have an xreadlines() attribute that is smart enough. What does this have to do with linked lists, by the way? In Python you make something like xreadlines() by means of a class that behaves like a list, but gets its values lazily, ie when it needs them. You can give it a __getitem__ method and you can run a for loop over it; see the UserList from the standard library. > I know that readline() will only return one line, > but it was my impression that it was a one-at a time dispatching > from an in-memory list. readline() doesn't read in the whole file at once. > In a similar vein, how would you use Python's native data types to > represent a linked list? What would you use the linked list for? Sometimes I'd use a normal list, sometimes a bunch of (value, next) tuples, sometimes a minimal class like: class LinkedList: def __init__(self, value, prev=None, next=None): self.value = value self.prev = prev self.next = next You don't need much more than that. But your mileage may vary, maybe your problem needs something completely different, or exactly your linked list implementation :) We have had some fun on this list solving problems from an ACM Programming Contest list of problems at http://acm.uva.es/problemset/ . Several people have sent solutions to some problems to the Useless Python pages at http://www.lowerstandard.com/python/pythonsource.html . [ Note: Why is there no link to the ACM problems page from there?! ] It's interesting to see that some solutions to problems that would be extremely hard in C or Pascal come out trivial in the case of Python, mostly because dictionaries and long integers are readily available. Try out your Python skills by trying to solve some of the problems :) -- Remco Gerlich From kalle@gnupung.net Tue Mar 20 15:28:15 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 20 Mar 2001 16:28:15 +0100 Subject: [Tutor] Re: Linked Lists In-Reply-To: <3AB7711B.DC3B83A2@lindbergs.org>; from van@lindbergs.org on Tue, Mar 20, 2001 at 08:02:51AM -0700 References: <3AB7711B.DC3B83A2@lindbergs.org> Message-ID: <20010320162815.B10786@father> Sez VanL: > Say, for instance, that you have a 10MB file. Is readlines() smart > enough to not load the whole thing into > memory at once? I know that readline() will only return one line, > but it was my impression that it was a one-at a time dispatching > from an in-memory list. IIRC: read() and readline() read directly from the file, not from memory. readlines() reads the entire file into memory. xreadlines() (new in 2.1) reads a line at a time (or something), but supports the list interface. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From arcege@shore.net Tue Mar 20 15:48:37 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 20 Mar 2001 10:48:37 -0500 (EST) Subject: [Tutor] Re: Linked Lists In-Reply-To: <3AB7711B.DC3B83A2@lindbergs.org> from VanL at "Mar 20, 2001 8: 2:51 am" Message-ID: <E14fONB-0003GP-00@nautilus.shore.net> > Say, for instance, that you have a 10MB file. Is readlines() smart > enough to not load the whole thing into > memory at once? I know that readline() will only return one line, > but it was my impression that it was a one-at a time dispatching > from an in-memory list. By default, the readlines method would read the whole file into memory. But there is an optional argument that says what the maximum space to use when reading the file, the lines within that buffer would be returned and the file pointer is maintained for the next call to readline(), readlines(), etc. >>> large_file = open('very_large_file.txt', 'r') >>> for set_of_lines in large_file.readlines(8192): ... for line in set_of_lines: ... pass # do the other processing ... These all use C's stardard I/O library, which has buffering. It reads a block or blocks from disk, then takes the information it needs from there, keeping the rest for the next call. > In a similar vein, how would you use Python's native data types to > represent a linked list? It depends on the implimentation of a linked list and how abstract you wish it to be. List, dictionaries, classes, take your pick. def new_node_list(data, rest): """Create a node out of a two-element list where the first is the datum and the second is the rest of the list. Each is modifiable, if this was a tuple, we couldn't change as we might like.""" return [data, rest] def new_node_dict(data, rest): """Create a node out of a dictionary with keys of "datum" and "next".""" return {'datum': data, 'next': rest} class new_node_class: """Create a node out of a class instance with attributes for "datum" and "next".""" def __init__(self, data, rest): self.datum = data self.next = rest You could get more arcane (using new modules instead of the above, etc.). But really it depends on what you need it for and how you wish to use it. Frankly, I wouldn't use a "linked list" in Python. The existing list data type is MUCH more flexible than a linked list. The insertion and searching routines are more than adequate for a "linked list"-type data type. If I was going to have something like this, I would probably create a "container" class implemented as a Python list. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From van@lindbergs.org Tue Mar 20 16:37:07 2001 From: van@lindbergs.org (VanL) Date: Tue, 20 Mar 2001 09:37:07 -0700 Subject: [Tutor] Re: Linked Lists References: <E14fONB-0003GP-00@nautilus.shore.net> Message-ID: <3AB78733.A65C12F9@lindbergs.org> "Michael P. Reilly" wrote: > Frankly, I wouldn't use a "linked list" in Python. The existing list > data type is MUCH more flexible than a linked list. The insertion > and searching routines are more than adequate for a "linked list"-type > data type. If I was going to have something like this, I would probably > create a "container" class implemented as a Python list. Please understand that my interest is academic, rather than practical. So far, especially considering what people have said, I can't think of a reason that I would ever use a home-cooked linked list. Rather, I just wanted to know what one looked like. So everyone understands, I have been going through "Mastering Algorithms with Perl" and rewriting the data structures and algorithms in Python. I thought that rewriting and optimizing all of them would give me a good introduction to serious programming with Python. Linked lists are just the first -- I don't have any particular fondness for them. I still have graphs, sets, trees, etc. to go. As part of that, if anyone sees any efficiency-killers in code snippets I post, please point them out. I am just doing this to learn, anyway. Thanks, VanL From dyoo@hkn.eecs.berkeley.edu Tue Mar 20 16:51:09 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 20 Mar 2001 08:51:09 -0800 (PST) Subject: [Tutor] Re: Linked Lists In-Reply-To: <3AB7711B.DC3B83A2@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103200828070.8429-100000@hkn.eecs.berkeley.edu> On Tue, 20 Mar 2001, VanL wrote: > One person said: > > Given that lists are built into Python, and much more powerfull > than this besides, it is of cource a pointless class. > > Another said: > > I find I never use linked lists in Python by the way, always just > Python > > lists. And so many other standard hard algorithms and data > structures become > > trivial when you have dictionaries available :). > > Yeah, the native Python lists support a log more operations. But I > was under the impression that linked lists > and lists were completely different data structures. They are different data structures, because certain operations will take less time, like insertion. Insertion in a linked list takes "constant" time, so it's very easy to support insertions anywhere in your structure. Python lists, too, support arbitrary insertion. I haven't taken a look at the data structure, but I'm assuming that they've implemented it as a dynamic array that grows if it needs to. If this is true, then inserting at the end of a list is easy, but inserting anywhere else is costly: we'd need to migrate all the elements to the right by one index. So that's one place where linked lists win. There are always tradeoffs --- if you're doing to do arbitrary insertion, you'll find the linked list useful. However, remember that linked lists don't support arbitrary indexing --- in order to get the fifth element of a linked list, we have "next().next().next().next()". Whew! Practically speaking, I think that dynamic arrays are more useful than linked lists, but that's just an opinion. > In a similar vein, how would you use Python's native data types to > represent a linked list? What you had, with the class structure, is a good way to represent linked lists. Another way to do it is to use a paired structure, a la Scheme: ### >>> def cons(a, b): ... return [a, b] ... >>> def first(pair): ... return pair[0] ... >>> def rest(pair): ... return pair[1] ... >>> cons(1, cons(2, cons(3, cons(4, None)))) [1, [2, [3, [4, None]]]] >>> myLinkedList = cons('a', cons('b', cons('c', None))) >>> first(rest(rest(myLinkedList))) 'c' ### This is an alternative way to develop linked lists. It might look funny to have all those nested lists, but it's very similar to the previous class definition. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Tue Mar 20 16:56:10 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 20 Mar 2001 08:56:10 -0800 (PST) Subject: [Tutor] Re: Linked Lists In-Reply-To: <3AB78733.A65C12F9@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103200851510.9056-100000@hkn.eecs.berkeley.edu> On Tue, 20 Mar 2001, VanL wrote: > Please understand that my interest is academic, rather than practical. > So far, especially considering what people have said, I can't think of a > reason that I would ever use a home-cooked linked list. Rather, I just > wanted to know what one looked like. We're just very defensive about our native data structures. It's very strange to be so emotional about box and pointer diagrams, but, we're human. *grin* > So everyone understands, I have been going through "Mastering Algorithms > with Perl" and rewriting the data structures and algorithms in Python. > I thought that rewriting and optimizing all of them would give me a good > introduction to serious programming with Python. Linked lists are just > the first -- I don't have any particular fondness for them. I still > have graphs, sets, trees, etc. to go. Very cool! If you want, you might want to submit your stuff to Useless Python later: http://www.lowerstandard.com/python/pythonsource.html to let others see how these structures can be written. > As part of that, if anyone sees any efficiency-killers in code snippets > I post, please point them out. I am just doing this to learn, anyway. No problem; keep the posts coming. Good luck to you! From britt_green@hotmail.com Tue Mar 20 17:08:20 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 20 Mar 2001 09:08:20 -0800 Subject: [Tutor] Speaking of Linked Lists... Message-ID: <F68o8yfogkJXrRjbDt300005bcd@hotmail.com> Since the topic of linked lists came up recently, I was hoping someone could tell me exactly what they're used for. I understand the how-to of coding them, but not the why. Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Tue Mar 20 17:37:06 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 20 Mar 2001 09:37:06 -0800 (PST) Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <F68o8yfogkJXrRjbDt300005bcd@hotmail.com> Message-ID: <Pine.LNX.4.21.0103200916070.9835-100000@hkn.eecs.berkeley.edu> On Tue, 20 Mar 2001, Britt Green wrote: > Since the topic of linked lists came up recently, I was hoping someone > could tell me exactly what they're used for. I understand the how-to > of coding them, but not the why. Introductory computer science courses talk about linked lists a lot, because they're one of the "simpler" data structures. Here's what one node of a linked list looks like. ------------- | | | | | | ------------- Traditionally, the first box stores a little bit of information, and the second box directs us to the next box. As an analogy, think about stringing these nodes together with string: ------- ------- | | -|-------| | -|----->None ------- ------- The second box is responsible for the string. Usually, the programmer always has a reference to the first node of a linked list, and by tugging at the string, the programmer can get at any element in the list. As soon as we hit None, we should stop pulling; there's nothing left to look at. It's somewhat similar to a native Python list, but the mechanisms underneath are all different. Linked lists are a "container" --- like lists, they're used to store things. What people have found useful about them is that they have a really simple structure, and it's easy to insert a new node into a list of items. If you have two pieces of rope, it's very easy to tie them together: one piece of rope another piece of rope o------------------o o------------------o ----> <------ bringing them together o-------------------------------------------o one long piece of rope Same thing with linked lists; what's involved is changing the "link" part of a node to tie to something else. What's cool is that we're not just restricted to "concatenating" lists: we can even make them loop around! o------------------------------o if you twist this into a loop: o------------- | | o------------- And suddenly, we have a "list" that has no end! It's the concept of being able to twist and tie these things together that make linked lists useful. After working with these things, computer science curriculums can then introduce stuff like binary trees and other twisted data structures, without making heads explode. Now I'd better get to class. *grin* Talk to you later! From wesc@deirdre.org Tue Mar 20 19:42:52 2001 From: wesc@deirdre.org (Wesley J. Chun) Date: Tue, 20 Mar 2001 11:42:52 -0800 Subject: [Tutor] Speaking of Linked Lists... Message-ID: <200103201942.LAA21644@emperor.deirdre.org> <Úÿ¿¢û > From: "Britt Green" <britt_green@hotmail.com> > Subject: [Tutor] Speaking of Linked Lists... > Date: Tue, 20 Mar 2001 09:08:20 -0800 > > Since the topic of linked lists came up recently, I was > hoping someone could tell me exactly what they're used > for. I understand the how-to of coding them, but not the why. britt, excellent question, esp. for newbies. it almost sounds like techno-babble until you start think about their application. but, to answer your question in brief, they can be used for just about anything where they make sense. you said in your message that you understand the "how-to" of coding them. in daniel's reply, he gave a "how-to" on visualizing them -- you need to think about them in that way while you're coding otherwise it's much harder to come up with the code believe it or not! now the "why." dealing with data is one of the main reasons for creating computer programs. you are either gathering it, updating it, maintaining it, searching for it, or deleting it. now, before i start, this primarily applies to languages where the programmer is responsible for allocating these "nodes" or basically memory to contain this data -- it's easy to get spoiled by Python where this is not necessary! often times when you're dealing with an unknown amount of data, for example, a "blackbook" name and adress book application for you to store contact information for your friends, family, etc. you store this data on disk and create a routine to read all this data into memory. the problem is, you are not sure how many names and addresses are in your database so you don't know how much memory to allo- cate! a linked list allows you to read in one entry, and check if there are any more entries to be read. if so, read in one more, "hook it up" to the first guy, and repeat. by the time you're done, you've read everything into memory, and because they are all hooked together like train cars, you can go down the list and print them out, search for someone, etc. note that in daniel's explantion, you can even choose *where* to insert them into the list. it is them possible to not only read in all the data from disk, but you can even alphabetize the order just by inserting each entry into the right spot in a linked list! i hope that was a helpful introduction! in college, this material is taught in a class called "Data Structures" and is usually an undergraduate lower division course which you take in your 2nd year. it's a real doozy and will provide you plenty of sleepless nights in the lab! i'm sure daniel can attest to that!! ;-) (is it still CS 61C?) cheers! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Silicon Valley-SF Bay Area Python users group: http://www.baypiggies.org "Core Python Programming", Prentice Hall PTR, December 2000 http://starship.python.net/crew/wesc/cpp/ wesley.j.chun :: wesc@baypiggies.org cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From arcege@shore.net Tue Mar 20 19:46:09 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 20 Mar 2001 14:46:09 -0500 (EST) Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <F68o8yfogkJXrRjbDt300005bcd@hotmail.com> from Britt Green at "Mar 20, 2001 9: 8:20 am" Message-ID: <E14fS53-0000BL-00@nautilus.shore.net> > Since the topic of linked lists came up recently, I was hoping someone could > tell me exactly what they're used for. I understand the how-to of coding > them, but not the why. Linked lists (and it's brethren: doublely, circular, etc.) are usually just concepts to be used for bigger, "more" important (conceptually) data structures like queues, stacks, sparce matrices and in a different way, trees. As an example of how they are used, take an operating system with one large process table. Only one process can run on a CPU at any one time, others will be waiting to for time on the CPU, and others will be waiting for various devices. There is one field in each entry in the process table which points to the "next process waiting" for some resource (CPU, hard drive, network, etc.). Following the chain of processes creates a queue. A process can be removed from one queue and placed on another (one stopped waiting for the hard drive and is now waiting for the CPU) by changing the "next process waiting" field, not by copying the process entry to a different data structure. In short, linked lists are generally used when dealing with large structures, to keep the structures nicely organized by only changing a few words. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dsh8290@rit.edu Tue Mar 20 20:01:15 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 20 Mar 2001 15:01:15 -0500 Subject: [Tutor] readlinesX In-Reply-To: <20010319180529.A5179@valinux.com>; from shaleh@valinux.com on Mon, Mar 19, 2001 at 06:05:29PM -0800 References: <326FFBE574BED411ACA100D0B79DC2B53F256C@ma001dataaege.ae.ge.com> <20010320000924.A359@apone.network.loc> <"from kalle"@gnupung.net> <20010319180529.A5179@valinux.com> Message-ID: <20010320150114.A27130@harmony.cs.rit.edu> On Mon, Mar 19, 2001 at 06:05:29PM -0800, Sean 'Shaleh' Perry wrote: | python 2.x, always use xreadlines() instead of readlines(). Works the same, for x > 0. xreadlines was added after 2.0 was released. -D From deirdre@deirdre.net Tue Mar 20 20:25:01 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 20 Mar 2001 12:25:01 -0800 (PST) Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <F68o8yfogkJXrRjbDt300005bcd@hotmail.com> Message-ID: <Pine.LNX.4.31.0103201223440.22093-100000@emperor.deirdre.org> On Tue, 20 Mar 2001, Britt Green wrote: > Since the topic of linked lists came up recently, I was hoping someone > could tell me exactly what they're used for. I understand the how-to > of coding them, but not the why. Well, if you don't know how many of something you'll have, but you know it'll be more than one. For example, linked lists are often used to store information about the documents an application has open (i.e., its file name, whether or not the doc is "dirty" (has unsaved changes), what window(s) it might have associated with it). -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From dsh8290@rit.edu Tue Mar 20 21:06:19 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 20 Mar 2001 16:06:19 -0500 Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <200103201942.LAA21644@emperor.deirdre.org>; from wesc@deirdre.org on Tue, Mar 20, 2001 at 11:42:52AM -0800 References: <200103201942.LAA21644@emperor.deirdre.org> Message-ID: <20010320160619.A27244@harmony.cs.rit.edu> On Tue, Mar 20, 2001 at 11:42:52AM -0800, Wesley J. Chun wrote: | > From: "Britt Green" <britt_green@hotmail.com> | > Subject: [Tutor] Speaking of Linked Lists... | > Date: Tue, 20 Mar 2001 09:08:20 -0800 | > | > Since the topic of linked lists came up recently, I was | > hoping someone could tell me exactly what they're used | > for. I understand the how-to of coding them, but not the why. | | i hope that was a helpful introduction! in college, this | material is taught in a class called "Data Structures" and | is usually an undergraduate lower division course which you | take in your 2nd year. it's a real doozy and will provide | you plenty of sleepless nights in the lab! i'm sure daniel | can attest to that!! ;-) (is it still CS 61C?) I can, even if Daniel can't ;-). I don't know what Berkely calls it, but RIT calls is "Computer Science 3" (0603-233). For Comp Sci and Soft Eng majors it is taken spring quarter of the first year (RIT is on a quarter system, and CS and SE are 5 year programs with co-op in between). Let me give you a more concrete example. Say you were writing a program in C that had to read in the coefficients and exponents for a polynomial, then find a numerical approximation of root of that polynomial. (This was from "Scientific Applications Programming", I forget what the course number was) You could have : float coeffs[10] ; float exponents[10] ; int i ; /* an index */ for ( i = 0 ; i < 10 ; i++ ) { /* read a float into the array */ scanf( "%f" , & coeffs[i] ) ; } ... Now what would happen if someone wanted to use your program to approximate the root of a 11th degree polynomial? It would fail with either a buffer overrun (not here since I checked the index), or it would get lost in the input since there were more coefficients than it expected. On the other hand, you can ask the user how many terms there will be, then malloc an array big enough, and remember to free it later. Or you can use a linked list to read the terms one at a time and create the nodes as needed. Then the user can give as many terms as there is memory in the machine and it will still work. Also, note that in my example, the array has a length of 10. If the user only ever inputs polynomials that have, say, 5 or less terms the extra memory is wasted. With a linked list, the program will only create enough nodes to hold the data, and no extras. Of course, it is a balancing act since each node must have the extra room to hold a pointer to the next element. In languages like C where such high-level data structures aren't built-in, implementing linked lists and other structures is more interesting than in python. The list that python has built-in is somewhat linked I think, but I haven't checked the source for it. It is quite fast so except is special cases it negates the need for creating a class-based linked list. For VanL, however, who is interested in the academics of learning python the purpose is to learn python, not to create a useful linked list. At least he can take his time and isn't being graded on it. It's a real headache when your pointer manipulation and book keeping isn't quite right and the lab is due by midnight. (Ok, so the data structures course was taught using Eiffel, but it had references to manipulate, you just don't get segfaults) HTH, -D From dsh8290@rit.edu Tue Mar 20 21:14:41 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 20 Mar 2001 16:14:41 -0500 Subject: [Tutor] Defining a new class In-Reply-To: <3AB6EC2E.944DE5F4@lindbergs.org>; from van@lindbergs.org on Mon, Mar 19, 2001 at 10:35:42PM -0700 References: <3AB6EC2E.944DE5F4@lindbergs.org> Message-ID: <20010320161441.B27244@harmony.cs.rit.edu> On Mon, Mar 19, 2001 at 10:35:42PM -0700, VanL wrote: | Hello, | | I am just getting started with Python so I thought I would implement | a lot of the classical data structures in Python so as to get a feel | for it. I am running into a few difficulties, tho. Here is my | first Python class: | | class LinkedList: | | def __init__(self, name, object=None): | self.label = name | if object: self.link = object | else: self.link = None I just want to ask why you check the value of 'object' here? If the client doesn't give a value for object it will be None, which is what you set it to in the else clause. I think that the following will be semantically equivalent to what you want: def __init__( self , name , object=None ) : self.label = name self.link = object | | def next(self): | if self.link: return link | else: return None same here. self.link will already be None, so why return None explictly? Another consideration : if you provide a function such as is_last() or has_next() that will indicate whether or not there is another node in the list, this function can throw an exception when there is nothing left in the list. I don't think perl has exceptions, so your Perl book probably uses a C-like setinel return value to indicate an error (null , None , etc). Python has exceptions which make error handling much nicer and easier. (if you want some more info/examles using exception just holler, or check the archives of this and python-list for messages from me (they center around raw_input and converting to a number)) | def label(self): | return self.label | | def link(self, object): | self.link = object | | def unlink(self): | self.link = None | | def rename(self, name): | self.label = name | | | Some things work as expected; I can declare an object of type | LinkedList. I get some strange results overall, tho. For example: I'll assume you have already corrected these from everyone else's responses ;-). | Thanks very much, | | Van From dyoo@hkn.eecs.berkeley.edu Tue Mar 20 21:56:01 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 20 Mar 2001 13:56:01 -0800 (PST) Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <200103201942.LAA21644@emperor.deirdre.org> Message-ID: <Pine.LNX.4.21.0103201355240.18023-100000@hkn.eecs.berkeley.edu> On Tue, 20 Mar 2001, Wesley J. Chun wrote: > i hope that was a helpful introduction! in college, this > material is taught in a class called "Data Structures" and > is usually an undergraduate lower division course which you > take in your 2nd year. it's a real doozy and will provide > you plenty of sleepless nights in the lab! i'm sure daniel > can attest to that!! ;-) (is it still CS 61C?) Yes. *grin* From vlindberg@verio.net Tue Mar 20 22:24:44 2001 From: vlindberg@verio.net (VanL) Date: Tue, 20 Mar 2001 15:24:44 -0700 Subject: [Tutor] Speaking of Linked Lists... References: <Pine.LNX.4.31.0103201223440.22093-100000@emperor.deirdre.org> Message-ID: <3AB7D8AC.921F174C@verio.net> Here is one sort of useless, sort of cool application: This can represent any infinite series. Right now compute_nextval is such that it computes the Fibonacci series, but that can be overloaded or replaced with whatever you might like. class InfiniteList: """ This is an implementation of an infinite list, where the next() method computes and caches the result of a series of calculations of an infinite list. """ def __init__(self, index=1, value=1, objprev=None): self.__index = index self.__value = value self.__nextlink = None if objprev: self.__prevlink = objprev else: self.__prevlink = self def next(self): if (self.__nextlink): return self.__nextlink else: nextind = self.__index + 1 nextval = self.compute_nextval() self.__nextlink = InfiniteList_Fib(nextind, nextval, self) return self.__nextlink def prev(self): if self.__prevlink: return self.__prevlink else: return None def index(self): return self.__index def value(self): return self.__value def unlink(self): self.__prevlink = None self.__nextlink = None def compute_nextval(self): val = self.__value + (self.__prevlink).__value return val From kalle@gnupung.net Tue Mar 20 22:42:00 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 20 Mar 2001 23:42:00 +0100 Subject: [Tutor] Speaking of Linked Lists... In-Reply-To: <20010320160619.A27244@harmony.cs.rit.edu>; from dsh8290@rit.edu on Tue, Mar 20, 2001 at 04:06:19PM -0500 References: <200103201942.LAA21644@emperor.deirdre.org> <20010320160619.A27244@harmony.cs.rit.edu> Message-ID: <20010320234200.A1875@apone.network.loc> Sez D-Man: [snip great stuff] > The list that python has built-in is somewhat linked I think, but I > haven't checked the source for it. Well, I got curious and checked. It seems to be implemented as an array of PyObject pointers, grown as needed, and not a linked list. Then I read how list.sort() is implemented, got scared and left. <0.9 wink> [snip] > At least he can take his time and isn't being graded on > it. It's a real headache when your pointer manipulation and book > keeping isn't quite right and the lab is due by midnight. (Ok, so the > data structures course was taught using Eiffel, but it had references > to manipulate, you just don't get segfaults) Pha, give me pointers any day. They had me reading human-computer interaction! <0.6 wink> Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From douglas.shawhan@ae.ge.com Tue Mar 20 23:03:27 2001 From: douglas.shawhan@ae.ge.com (Shawhan, Douglas (GEAE, GECC)) Date: Tue, 20 Mar 2001 18:03:27 -0500 Subject: [Tutor] list index out of range error Message-ID: <326FFBE574BED411ACA100D0B79DC2B53F2583@ma001dataaege.ae.ge.com> When I attempt to run the following: --------------begin yamo.py------------------------ import glob import string gunther=open('/windows/desktop/merciful_wombat.html', 'w') yamo=glob.glob("/windows/desktop/*.html") a=0;b=100 while a < b: gunther.write('<html><body bgcolor=white><table><tr><td>'+`yamo[a]`+'<tr><td bgcolor=#aaaaaa> </table>'), a=a+1 gunther.close() os.system('iexplore.exe /windows/desktop/merciful_wombat.html') --------------end yamo.py--------------------------- I get the following error: --------------erratta mondatta---------------------- C:\WINDOWS\DESKTOP>python yamo.py Traceback (most recent call last): File "yamo.py", line 7, in ? gunther.write('<html><body bgcolor=white><table><tr><td>'+`yamo[a]`+'<tr><td bgcolor=#aaaaaa> </table>'), IndexError: list index out of range --------------end erratta mondatta---------------- It writes the file "merciful_wombat.html" file just fine. But it gives me the error message all the same. Too many iterations in my while? And another thing: import os os.system('notepad.exe') works fine, while import os os.system ('iexplore.exe') does not. Is there a path problem here? From scarblac@pino.selwerd.nl Tue Mar 20 23:12:24 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 00:12:24 +0100 Subject: [Tutor] list index out of range error In-Reply-To: <326FFBE574BED411ACA100D0B79DC2B53F2583@ma001dataaege.ae.ge.com>; from douglas.shawhan@ae.ge.com on Tue, Mar 20, 2001 at 06:03:27PM -0500 References: <326FFBE574BED411ACA100D0B79DC2B53F2583@ma001dataaege.ae.ge.com> Message-ID: <20010321001224.A12764@pino.selwerd.nl> On Tue, Mar 20, 2001 at 06:03:27PM -0500, Shawhan, Douglas (GEAE, GECC) wrote: > When I attempt to run the following: > > --------------begin yamo.py------------------------ > import glob > import string > gunther=open('/windows/desktop/merciful_wombat.html', 'w') > yamo=glob.glob("/windows/desktop/*.html") > a=0;b=100 > while a < b: > gunther.write('<html><body > bgcolor=white><table><tr><td>'+`yamo[a]`+'<tr><td > bgcolor=#aaaaaa> </table>'), > a=a+1 > gunther.close() > os.system('iexplore.exe /windows/desktop/merciful_wombat.html') > > --------------end yamo.py--------------------------- > > I get the following error: > > --------------erratta mondatta---------------------- > > C:\WINDOWS\DESKTOP>python yamo.py > Traceback (most recent call last): > File "yamo.py", line 7, in ? > gunther.write('<html><body > bgcolor=white><table><tr><td>'+`yamo[a]`+'<tr><td > bgcolor=#aaaaaa> </table>'), > IndexError: list index out of range > > --------------end erratta mondatta---------------- > > It writes the file "merciful_wombat.html" file just fine. But it gives me > the error message all the same. > > Too many iterations in my while? You do exactly 100 iterations. If the desktop has fewer html files, you get that error; if it has more, you will omit some. Change the while to 'while a < len(yamo)'. Or even to 'for y in yamo' and use `y` in the html thingy instead of `yamo[a]`. > And another thing: > > import os > os.system('notepad.exe') > > works fine, while > > import os > os.system ('iexplore.exe') > > does not. Is there a path problem here? I'll let someone else answer that since I don't use Windows. -- Remco Gerlich From vlindberg@verio.net Tue Mar 20 23:26:07 2001 From: vlindberg@verio.net (VanL) Date: Tue, 20 Mar 2001 16:26:07 -0700 Subject: [Tutor] list index out of range error References: <326FFBE574BED411ACA100D0B79DC2B53F2583@ma001dataaege.ae.ge.com> Message-ID: <3AB7E70F.216264F8@verio.net> > And another thing: > > import os > os.system('notepad.exe') > > works fine, while > > import os > os.system ('iexplore.exe') > > does not. Is there a path problem here? Yep, path problem. Notepad.exe is in the \windows directory, which is in the search path. Strange as it may seem, \Program Files is not. This works: os.system('\\Progra~1\\Intern~1\\IEXPLORE.EXE') (Using dos filenames to get around the unescapable spaces in directory names) VanL From britt_green@hotmail.com Wed Mar 21 00:16:51 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 20 Mar 2001 16:16:51 -0800 Subject: [Tutor] Linked Lists Message-ID: <F201NOUivlQoMuDGzxT000065fd@hotmail.com> Thanks to everyone who answered my question about linked lists. They're a bit less vague know. As I told someone earlier, I think this will be one of those things like overloading: It doesn't make a lot of sense until I actually start doing it, then it will become really clear! Britt _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Wed Mar 21 00:20:55 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 20 Mar 2001 16:20:55 -0800 (PST) Subject: [Tutor] list index out of range error In-Reply-To: <3AB7E70F.216264F8@verio.net> Message-ID: <Pine.LNX.4.31.0103201620080.24038-100000@emperor.deirdre.org> On Tue, 20 Mar 2001, VanL wrote: > This works: > os.system('\\Progra~1\\Intern~1\\IEXPLORE.EXE') > > (Using dos filenames to get around the unescapable spaces in directory names) Spaces are escapable; perhaps not on Windows, but a single \ should do it. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From vlindberg@verio.net Wed Mar 21 00:36:54 2001 From: vlindberg@verio.net (VanL) Date: Tue, 20 Mar 2001 17:36:54 -0700 Subject: [Tutor] list index out of range error References: <Pine.LNX.4.31.0103201620080.24038-100000@emperor.deirdre.org> Message-ID: <3AB7F7A6.32DC03A6@verio.net> On Unix, you are right. On Windows, that doesn't work. At least, I can't make it work. -V- Deirdre Saoirse wrote: > On Tue, 20 Mar 2001, VanL wrote: > > > This works: > > os.system('\\Progra~1\\Intern~1\\IEXPLORE.EXE') > > > > (Using dos filenames to get around the unescapable spaces in directory names) > > Spaces are escapable; perhaps not on Windows, but a single \ should do it. > > -- > _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams From jethro@163bj.com Wed Mar 21 03:52:40 2001 From: jethro@163bj.com (Jethro Cramp) Date: Wed, 21 Mar 2001 11:52:40 +0800 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 Message-ID: <JMEOIILNBOJMOPBDBMGMAEGECHAA.jethro@163bj.com> I have written a small number of functions for converting measurements from one unit to another for example from centimetres to metres. An example of this function is: def cmTOm(length): return length/100 When I tested this with cmTOm(98) I found that I had fallen into the first trap of using numbers in python when I was returned 0. I checked and realised that this was normal. My understanding is that I should change the length to a float first so I used: def cmTOm(length): return float(length)/100 When I tested this with cmTOm(98) I was surprised to get the answer: 0.97999999999999998 Although pretty accurate this is not the correct answer and will certainly cause minor unacceptable errors to creep into my application. I thought that if I rounded the digit to 2 decimal places this should solve the problem. But using the function round(number, 2) gives me the result: 0.97999999999999998 What should I be doing to get the correct result of 0.98? I am using Python 2.0 on WindowsME. Thanks in advance, Jethro From doug@pop.nsacom.net Wed Mar 21 06:41:10 2001 From: doug@pop.nsacom.net (doug) Date: Tue, 20 Mar 2001 22:41:10 -0800 Subject: [Tutor] Which postgres method? Message-ID: <20010320224110.A17197@pop.nsacom.net> I have a need to (stop me if you've heard this before...) use python with apache to access a postgresql database. So far I have found much that looks pretty stale and darn few hand-holding, fanny powdering HOWTOS. So I ask: What method is the most painless for the newbie? The PyApache page at http://www.bel-epa.com/pyapache/Python/postgres has a pre-2.0 module therupon. PyGreSQL looks pretty good and has source examples (yay D'Arcy!), but the ftp site is down. Clues? From BobbyMcGrawBobby@aol.com Wed Mar 21 10:05:46 2001 From: BobbyMcGrawBobby@aol.com (BobbyMcGrawBobby@aol.com) Date: Wed, 21 Mar 2001 05:05:46 EST Subject: [Tutor] Beginning Message-ID: <3c.914bcf1.27e9d6fa@aol.com> Ive started reading the python tutorial and am wondering if python is a good programming language fro beginners? I have never programmed anything. i need to know what i need to download to start to program. Bobby From scarblac@pino.selwerd.nl Wed Mar 21 10:16:53 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 11:16:53 +0100 Subject: [Tutor] Beginning In-Reply-To: <3c.914bcf1.27e9d6fa@aol.com>; from BobbyMcGrawBobby@aol.com on Wed, Mar 21, 2001 at 05:05:46AM -0500 References: <3c.914bcf1.27e9d6fa@aol.com> Message-ID: <20010321111653.A13678@pino.selwerd.nl> On Wed, Mar 21, 2001 at 05:05:46AM -0500, BobbyMcGrawBobby@aol.com wrote: > Ive started reading the python tutorial and am wondering if python is a good > programming language fro beginners? I have never programmed anything. > i need to know what i need to download to start to program. It is absolutely, but the official Python tutorial assumes you have some programming experience. There are several tutorials especially for complete newbies, see Alan Gauld's "Learning to Program using Python" http://www.crosswinds.net/~agauld/ Josh Cogliati's "Non-programmers tutorial for Python" http://www.honors.montana.edu/~jjc/easytut/easytut/ There's also http://www.hetland.org/python/instant-hacking.php and http://www.ibiblio.org/obp/thinkCSpy.html But those two at least assume you have a Python interpreter installed and know how to start it (that's explained in the first two). -- Remco Gerlich From doc_pepin@yahoo.com Wed Mar 21 10:26:01 2001 From: doc_pepin@yahoo.com (doc pepin) Date: Wed, 21 Mar 2001 02:26:01 -0800 (PST) Subject: [Tutor] help with tkinter? Message-ID: <20010321102601.10010.qmail@web2306.mail.yahoo.com> i've made a timer program with python and tkinter but the problem is i don't know how to display the result or output on the main window and not on the console. __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From scarblac@pino.selwerd.nl Wed Mar 21 10:30:33 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 11:30:33 +0100 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <JMEOIILNBOJMOPBDBMGMAEGECHAA.jethro@163bj.com>; from jethro@163bj.com on Wed, Mar 21, 2001 at 11:52:40AM +0800 References: <JMEOIILNBOJMOPBDBMGMAEGECHAA.jethro@163bj.com> Message-ID: <20010321113033.B13678@pino.selwerd.nl> On Wed, Mar 21, 2001 at 11:52:40AM +0800, Jethro Cramp wrote: > I have written a small number of functions for converting measurements from > one unit to another for example from centimetres to metres. An example of > this function is: > > def cmTOm(length): > return length/100 > > When I tested this with cmTOm(98) I found that I had fallen into the first > trap of using numbers in python when I was returned 0. I checked and > realised that this was normal. My understanding is that I should change the > length to a float first so I used: > > def cmTOm(length): > return float(length)/100 You could also simply divide by 100.0. > When I tested this with cmTOm(98) I was surprised to get the answer: > > 0.97999999999999998 > > Although pretty accurate this is not the correct answer and will certainly > cause minor unacceptable errors to creep into my application. I thought that > if I rounded the digit to 2 decimal places this should solve the problem. > But using the function round(number, 2) gives me the result: > > 0.97999999999999998 > > What should I be doing to get the correct result of 0.98? I was going to refer you to the FAQ, but it seems this is still not in there, will try to make an entry later today. The problem is that computers store floats with a finite amount of binary digits, and '0.98' cannot be represented that way, just like '1/3' can't be represented in decimal floating point. Note that if you do 'print cmTom(98)' it *does* print 0.98. However when you type it into the interpreter, repr() tells the complete truth. So in short, computers aren't any more exact than this, period. Floats are tricky. Try not to compare two floating point numbers for equality with ==, since they're often slightly different. This is not a Python problem. I think that if you round them to 15 decimal places after every computation, you can always keep the error really small. Hmm, there is a small fixed decimal precision arithmetic library called FixedPoint that you probably want to use, see FixedPoint.py and .README in ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/DataStructures/ . -- Remco Gerlich From bdupire@seatech.fau.edu Wed Mar 21 13:50:17 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 21 Mar 2001 08:50:17 -0500 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 References: <JMEOIILNBOJMOPBDBMGMAEGECHAA.jethro@163bj.com> <20010321113033.B13678@pino.selwerd.nl> Message-ID: <3AB8B199.BDA6BD76@seatech.fau.edu> Remco Gerlich wrote: > On Wed, Mar 21, 2001 at 11:52:40AM +0800, Jethro Cramp wrote: > > > 0.97999999999999998 > > > > What should I be doing to get the correct result of 0.98? > > I was going to refer you to the FAQ, but it seems this is still not in > there, will try to make an entry later today. how > > > The problem is that computers store floats with a finite amount of binary > digits, and '0.98' cannot be represented that way, just like '1/3' can't be > represented in decimal floating point. > > Note that if you do 'print cmTom(98)' it *does* print 0.98. However when you > type it into the interpreter, repr() tells the complete truth. > right! repr() and str() are not the same in Python 2.0 str() prints the 12 first digits, so rounds the last digits repr() prints the 18 first digits... I did not remember where I see the above, but i * think*it should be in a post on the Python newsgroup when you return an object, Python uses it repr... so you end up with 0.9799999 BTW, For unit conversions, I saw, during the Python conference, that someone came up a module called Unum The URL i got is: http://gallery.uunet.be/Pierre-et-Liliane.DENIS/Unum.html From scarblac@pino.selwerd.nl Wed Mar 21 14:07:42 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 15:07:42 +0100 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <3AB8B199.BDA6BD76@seatech.fau.edu>; from bdupire@seatech.fau.edu on Wed, Mar 21, 2001 at 08:50:17AM -0500 References: <JMEOIILNBOJMOPBDBMGMAEGECHAA.jethro@163bj.com> <20010321113033.B13678@pino.selwerd.nl> <3AB8B199.BDA6BD76@seatech.fau.edu> Message-ID: <20010321150742.A14211@pino.selwerd.nl> On Wed, Mar 21, 2001 at 08:50:17AM -0500, Benoit Dupire wrote: > Remco Gerlich wrote: > > > On Wed, Mar 21, 2001 at 11:52:40AM +0800, Jethro Cramp wrote: > > > > > 0.97999999999999998 > > > > > > What should I be doing to get the correct result of 0.98? > > > > I was going to refer you to the FAQ, but it seems this is still not in > > there, will try to make an entry later today. > > how Bah. I thought everyone could add things to the FAQ with the FAQ Wizard, but it's only for PSA members. I thought the PSA was defunct, but then then things has changed so fast in the last half year... www.python.org is hosted by CNRI, has BeOpen logos here and there, and has things run by the PSA on it... But I digress. So I'm not adding to the FAQ after all. I could mail someone but I'm lazy at the moment. -- Remco Gerlich From scarblac@pino.selwerd.nl Wed Mar 21 15:30:50 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 16:30:50 +0100 Subject: [Tutor] Re: re.match In-Reply-To: <20010321100455.M10129@nortelnetworks.com>; from msoulier@nortelnetworks.com on Wed, Mar 21, 2001 at 10:04:55AM -0500 References: <997skf$qoc$1@bmerhc5e.ca.nortel.com> <TrMt6.2490$4N4.318602@newsc.telia.net> <99874d$4tp$1@bmerhc5e.ca.nortel.com> <j4r8zsi3pw.fsf@informatik.hu-berlin.de> <998hhn$cep$1@bmerhc5e.ca.nortel.com> <20010320231905.12793.qmail@pino.selwerd.nl> <20010321100455.M10129@nortelnetworks.com> Message-ID: <20010321163050.A14543@pino.selwerd.nl> On Wed, Mar 21, 2001 at 10:04:55AM -0500, Michael Soulier wrote: > On Tue, Mar 20, 2001 at 11:19:05PM -0000, scarblac@pino.selwerd.nl wrote: > > > > Please, you saw Fredrik at a bad moment, it seems. c.l.p is one of the > > friendliest groups on Usenet, and we *don't* have a lack of tolerance here. > > Fredrik is an absolute guru on many subjects and extremely helpful, but > > sometimes he posts a irritated one line reply. It's the exception. > > You're not the only one to tell me that. Thanks. > > Personally, I refuse to allow someone's proficiency to explain their > rudeness. I wish the world would follow in kind. I suppose I've been guilty of > the same thing on occasion though. Come on, he said "no, it's not. read the documentation again". If that's the rudest we ever see, maybe the world is not going to end after all. On the other hand he has a book published that is a compilation of his newsgroup posts, and it's very useful... not many people can claim that. -- Remco Gerlich From scarblac@pino.selwerd.nl Wed Mar 21 15:38:55 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 16:38:55 +0100 Subject: [Tutor] Re: re.match In-Reply-To: <20010321163050.A14543@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Wed, Mar 21, 2001 at 04:30:50PM +0100 References: <997skf$qoc$1@bmerhc5e.ca.nortel.com> <TrMt6.2490$4N4.318602@newsc.telia.net> <99874d$4tp$1@bmerhc5e.ca.nortel.com> <j4r8zsi3pw.fsf@informatik.hu-berlin.de> <998hhn$cep$1@bmerhc5e.ca.nortel.com> <20010320231905.12793.qmail@pino.selwerd.nl> <20010321100455.M10129@nortelnetworks.com> <20010321163050.A14543@pino.selwerd.nl> Message-ID: <20010321163855.A14570@pino.selwerd.nl> On Wed, Mar 21, 2001 at 04:30:50PM +0100, Remco Gerlich wrote: Argh, this sucks. This was personal email to Michael Soulier, should not have shown up here. :-( I get so used to changing a From: address to tutor@python.org that I start doing it on other mail as well... -- Remco Gerlich From dsh8290@rit.edu Wed Mar 21 16:44:27 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 21 Mar 2001 11:44:27 -0500 Subject: [Tutor] list index out of range error In-Reply-To: <3AB7F7A6.32DC03A6@verio.net>; from vlindberg@verio.net on Tue, Mar 20, 2001 at 05:36:54PM -0700 References: <Pine.LNX.4.31.0103201620080.24038-100000@emperor.deirdre.org> <3AB7F7A6.32DC03A6@verio.net> Message-ID: <20010321114427.A2862@harmony.cs.rit.edu> On Tue, Mar 20, 2001 at 05:36:54PM -0700, VanL wrote: | On Unix, you are right. On Windows, that doesn't work. At least, | I can't make it work. | | -V- You are right, Windows is horrible. Example : (the path does exist, and works when building the project using ant (a make replacement for java)) Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import os >>> os.system( "C:/Program Files/Microsoft Visual Studio/VSS/win32" ) 'C:/Program' is not recognized as an internal or external command, operable program or batch file. 1 >>> os.system( "C:/Program\ Files/Microsoft\ Visual\ Studio/VSS/win32" >>> ) 'C:/Program\' is not recognized as an internal or external command, operable program or batch file. 1 >>> os.system( "C:/Program\\ Files/Microsoft\\ Visual\\ >>> Studio/VSS/win32" ) 'C:/Program\' is not recognized as an internal or external command, operable program or batch file. 1 >>> I think it is the windows shell that get's forked when os.system is called that is choking on the windows path. -D From scarblac@pino.selwerd.nl Wed Mar 21 16:47:44 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 21 Mar 2001 17:47:44 +0100 Subject: [Tutor] list index out of range error In-Reply-To: <20010321114427.A2862@harmony.cs.rit.edu>; from dsh8290@rit.edu on Wed, Mar 21, 2001 at 11:44:27AM -0500 References: <Pine.LNX.4.31.0103201620080.24038-100000@emperor.deirdre.org> <3AB7F7A6.32DC03A6@verio.net> <20010321114427.A2862@harmony.cs.rit.edu> Message-ID: <20010321174744.A14682@pino.selwerd.nl> On Wed, Mar 21, 2001 at 11:44:27AM -0500, D-Man wrote: > On Tue, Mar 20, 2001 at 05:36:54PM -0700, VanL wrote: > | On Unix, you are right. On Windows, that doesn't work. At least, > | I can't make it work. > | > | -V- > > You are right, Windows is horrible. Example : (the path does exist, > and works when building the project using ant (a make replacement for > java)) > > Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > >>> import os > >>> os.system( "C:/Program Files/Microsoft Visual Studio/VSS/win32" ) > 'C:/Program' is not recognized as an internal or external command, > operable program or batch file. > 1 > >>> os.system( "C:/Program\ Files/Microsoft\ Visual\ Studio/VSS/win32" > >>> ) > 'C:/Program\' is not recognized as an internal or external command, > operable program or batch file. > 1 > >>> os.system( "C:/Program\\ Files/Microsoft\\ Visual\\ > >>> Studio/VSS/win32" ) > 'C:/Program\' is not recognized as an internal or external command, > operable program or batch file. > 1 > >>> > > > I think it is the windows shell that get's forked when os.system is > called that is choking on the windows path. IIRC, putting it between "double quotes" works in a DOS box, so with os.system as well? What does os.system('C:/"Program Files"/"Microsoft Visual Studio"/VSS/win32') do? (it's still a pain to put each part between their own double quotes). Ah, the evil of having spaces in filenames. Fortunately "Program Files" and "My Documents" are never used... -- Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Wed Mar 21 17:17:59 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 21 Mar 2001 09:17:59 -0800 (PST) Subject: [Tutor] help with tkinter? In-Reply-To: <20010321102601.10010.qmail@web2306.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103210858410.12606-100000@hkn.eecs.berkeley.edu> On Wed, 21 Mar 2001, doc pepin wrote: > i've made a timer program with python and tkinter but > the problem is i don't know how to display the result > or output on the main window and not on the console. Hmmm... I believe you should be able to use the Label widget with a StringVar, which will let you change the Label's contents on the fly. For example: ### from Tkinter import * root = Tk() s = StringVar() s.set("Hello World") Label(textvariable = s).pack(side=LEFT) def rotate(svar = s): mystr = s.get() s.set(mystr[1:] + mystr[0]) Button(text="Press me to rotate the label", command=rotate).pack(side=LEFT) mainloop() ### However, there might be a better way of doing this; I haven't gotten past StringVars yet. Hope this helps! From fasal.waseem@cis.co.uk Wed Mar 21 17:23:18 2001 From: fasal.waseem@cis.co.uk (fasal.waseem@cis.co.uk) Date: Wed, 21 Mar 2001 17:23:18 +0000 Subject: [Tutor] Python documentation For v1.4 Message-ID: <OF4F345CEE.12A67471-ON00256A16.005F4F4C@cis.co.uk> Hi There I was wondering does any body know where can I get hold of documentation for v1.4, I would appreciate if any one can let me know. Regards Faz ************************************************************************* This e-mail may contain confidential information or be privileged. It is intended to be read and used only by the named recipient(s). If you are not the intended recipient(s) please notify us immediately so that we can make arrangements for its return: you should not disclose the contents of this e-mail to any other person, or take any copies. Unless stated otherwise by an authorised individual, nothing contained in this e-mail is intended to create binding legal obligations between us and opinions expressed are those of the individual author. The CIS marketing group, which is regulated for Investment Business by the Personal Investment Authority, includes: Co-operative Insurance Society Limited Registered in England number 3615R - for life assurance and pensions CIS Unit Managers Limited Registered in England and Wales number 2369965 (also regulated by IMRO) - for unit trusts and PEPs CIS Policyholder Services Limited Registered in England and Wales number 3390839 - for ISAs and investment products bearing the CIS name Registered offices: Miller Street, Manchester M60 0AL Telephone 0161-832-8686 Internet http://www.cis.co.uk E-mail cis@cis.co.uk CIS Deposit and Instant Access Savings Accounts are held with The Co-operative Bank p.l.c., registered in England and Wales number 990937, P.O. Box 101, 1 Balloon Street, Manchester M60 4EP, and administered by CIS Policyholder Services Limited as agent of the Bank. CIS & the CIS logo (R) Co-operative Insurance Society Limited ******************************************************************************** From dyoo@hkn.eecs.berkeley.edu Wed Mar 21 17:26:47 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 21 Mar 2001 09:26:47 -0800 (PST) Subject: [Tutor] help with tkinter? In-Reply-To: <Pine.LNX.4.21.0103210858410.12606-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.21.0103210922380.13318-100000@hkn.eecs.berkeley.edu> On Wed, 21 Mar 2001, Daniel Yoo wrote: > def rotate(svar = s): > mystr = s.get() > s.set(mystr[1:] + mystr[0]) Must... make... corrections... ### def rotate(svar=s): mystr = svar.get() svar.set(mystr[1:] + mystr[0]) ### Sorry; wasn't paying attention for a moment. From pdiaz88@terra.es Wed Mar 21 18:25:21 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Wed, 21 Mar 2001 19:25:21 +0100 Subject: [Tutor] Which postgres method? In-Reply-To: <20010320224110.A17197@pop.nsacom.net> References: <20010320224110.A17197@pop.nsacom.net> Message-ID: <01032119252100.09910@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Well, you should start reading the Python-Db API, which is found in www.python.org. Try to make simple examples (stay apart from apache until you understand fully the Db-API) To interact with the web server, you have many alternatives. Maybe the most simple (and somewhat slower) is making a CGI. You have another alternatives which I havent used, like mod-python. Cheers Pedro On Wednesday 21 March 2001 07:41, doug wrote: > I have a need to (stop me if you've heard this before...) use python with > apache to access a postgresql database. So far I have found much that looks > pretty stale and darn few hand-holding, fanny powdering HOWTOS. > > So I ask: What method is the most painless for the newbie? The PyApache > page at http://www.bel-epa.com/pyapache/Python/postgres has a pre-2.0 > module therupon. PyGreSQL looks pretty good and has source examples (yay > D'Arcy!), but the ftp site is down. > > Clues? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6uPIZnu53feEYxlERAg3sAJ4nfuOqdPh/6xSWvzKgT3Y9ZqlVwwCg06JV S4Ue4mPWxcfGL3z+JGotZFk= =1sJC -----END PGP SIGNATURE----- From britt_green@hotmail.com Wed Mar 21 17:27:50 2001 From: britt_green@hotmail.com (Britt Green) Date: Wed, 21 Mar 2001 09:27:50 -0800 Subject: [Tutor] Beginning Message-ID: <F283YL91hoVyKi30d6n00007518@hotmail.com> Hi Bobby, Welcome aboard. I'm also pretty new to programming, and I found a book called Learn to Program Using Python by Alan Gauld to be a really good introductory book to programming. You might give that a try. Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From arcege@shore.net Wed Mar 21 17:42:37 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 21 Mar 2001 12:42:37 -0500 (EST) Subject: [Tutor] help with tkinter? In-Reply-To: <Pine.LNX.4.21.0103210858410.12606-100000@hkn.eecs.berkeley.edu> from Daniel Yoo at "Mar 21, 2001 9:17:59 am" Message-ID: <E14fmd3-0004TW-00@nautilus.shore.net> > On Wed, 21 Mar 2001, doc pepin wrote: > > > i've made a timer program with python and tkinter but > > the problem is i don't know how to display the result > > or output on the main window and not on the console. > > Hmmm... I believe you should be able to use the Label widget with a > StringVar, which will let you change the Label's contents on the fly. For > example: [snipped] > However, there might be a better way of doing this; I haven't gotten past > StringVars yet. You can also change the text field manually. >>> from Tkinter import * >>> l = Label(None, text='Hi there') >>> l.pack() >>> # there should be a flat widget with "Hi there" now ... >>> l['text'] = 'Whassup' >>> # and now the text has changed ... >>> l.config(text='Goodbye') About the only time you need the Variable classes is when you want to share values across widgets (mostly the Radiobutton widget). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Wed Mar 21 17:53:09 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 21 Mar 2001 12:53:09 -0500 (EST) Subject: [Tutor] Python documentation For v1.4 In-Reply-To: <OF4F345CEE.12A67471-ON00256A16.005F4F4C@cis.co.uk> from "fasal.waseem@cis.co.uk" at "Mar 21, 2001 5:23:18 pm" Message-ID: <E14fmnF-00075Y-00@nautilus.shore.net> > I was wondering does any body know where can I get hold of documentation > for v1.4, I would appreciate if any one can let me know. > > Regards > > Faz <URL: http://www.python.org/doc/1.4/> Is the published documentation for Python 1.4. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From Glen@ihello-inc.com Wed Mar 21 20:04:31 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 21 Mar 2001 12:04:31 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A474@go.ihello.com> Hi, I just wrote my first python program that works. I am happy. I am also trying to figure out how to make it better. One of the things that I have done is hard code a dictionary in the program. I am trying to get it to read from a config file that I have created which has two values in it, a server name and a url. I have seperated them with a ;. How can I get python to read from the file and use the first value as a ky ant the second as a value and enter it into a dictionary? I can get it to read in the file but when I try to use re.split or string.split and then print out the value, it only prints out the ;. Any help would be appreciated. Thanks Glen From dyoo@hkn.eecs.berkeley.edu Wed Mar 21 20:24:51 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 21 Mar 2001 12:24:51 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A474@go.ihello.com> Message-ID: <Pine.LNX.4.21.0103211209300.17740-100000@hkn.eecs.berkeley.edu> On Wed, 21 Mar 2001, Glen Bunting wrote: > I just wrote my first python program that works. I am happy. I am also > trying to figure out how to make it better. One of the things that I have > done is hard code a dictionary in the program. I am trying to get it to > read from a config file that I have created which has two values in it, a > server name and a url. I have seperated them with a ;. How can I get > python to read from the file and use the first value as a ky ant the second > as a value and enter it into a dictionary? I can get it to read in the file > but when I try to use re.split or string.split and then print out the value, > it only prints out the ;. Any help would be appreciated. Using string.split is the right idea. Here's a small interpreter session that plays around with string.split(): ### >>> myinput = '''name ; glen ... mailing list ; tutor@python.org''' >>> import string >>> lines = string.split(myinput, '\n') >>> lines ['name ; glen', 'mailing list ; tutor@python.org'] >>> for l in lines: ... name, value = string.split(l, ';') ... print "The name is: ", name ... print "The value is: ", value ... The name is: name The value is: glen The name is: mailing list The value is: tutor@python.org ### Before inserting in your dictionary, let's make make sure that the splitting is working ok. If you want, you can show us what you have, and we can see why it's not splitting well. Also, it might be necessary to "strip" your keys and values: using string.strip() on both the keys and values might be a good thing, to get rid of the leading and trailing whitespace. Oh, also, if you want to be really fancy, there's a module called the "ConfigParser" that does name/value pair stuff. The documentation for it is here: http://python.org/doc/current/lib/module-ConfigParser.html but it's definitely overkill for your application. Good luck to you. From kauphlyn@speakeasy.org Wed Mar 21 20:39:47 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Wed, 21 Mar 2001 12:39:47 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A474@go.ihello.com> Message-ID: <Pine.LNX.4.21.0103211235130.9184-100000@grace.speakeasy.org> > server name and a url. I have seperated them with a ;. How can I get > python to read from the file and use the first value as a ky ant the second > as a value and enter it into a dictionary? I can get it to read in the file > but when I try to use re.split or string.split and then print out the value, > it only prints out the ;. Any help would be appreciated. how 'bout: def Function(string) # your string 'server;url' List = string.split(';') Dictionary = {List[0]:List[1]} Then you can do whatever you want with Dictionary. Hope this helps ~d From Glen@ihello-inc.com Wed Mar 21 21:41:49 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 21 Mar 2001 13:41:49 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A475@go.ihello.com> When I try : >>> import string >>> CONFIG = open('webconf.txt').read() >>> for 1 in CONFIG: ... key, value = string.split(1, ';') ... print 'The key is : ', key ... print 'The value is : ', value SyntaxError: Can't assign to literal Thanks Glen -----Original Message----- From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Wednesday, March 21, 2001 12:25 PM To: Glen Bunting Cc: 'tutor@python.org' Subject: Re: [Tutor] (no subject) On Wed, 21 Mar 2001, Glen Bunting wrote: > I just wrote my first python program that works. I am happy. I am also > trying to figure out how to make it better. One of the things that I have > done is hard code a dictionary in the program. I am trying to get it to > read from a config file that I have created which has two values in it, a > server name and a url. I have seperated them with a ;. How can I get > python to read from the file and use the first value as a ky ant the second > as a value and enter it into a dictionary? I can get it to read in the file > but when I try to use re.split or string.split and then print out the value, > it only prints out the ;. Any help would be appreciated. Using string.split is the right idea. Here's a small interpreter session that plays around with string.split(): ### >>> myinput = '''name ; glen ... mailing list ; tutor@python.org''' >>> import string >>> lines = string.split(myinput, '\n') >>> lines ['name ; glen', 'mailing list ; tutor@python.org'] >>> for l in lines: ... name, value = string.split(l, ';') ... print "The name is: ", name ... print "The value is: ", value ... The name is: name The value is: glen The name is: mailing list The value is: tutor@python.org ### Before inserting in your dictionary, let's make make sure that the splitting is working ok. If you want, you can show us what you have, and we can see why it's not splitting well. Also, it might be necessary to "strip" your keys and values: using string.strip() on both the keys and values might be a good thing, to get rid of the leading and trailing whitespace. Oh, also, if you want to be really fancy, there's a module called the "ConfigParser" that does name/value pair stuff. The documentation for it is here: http://python.org/doc/current/lib/module-ConfigParser.html but it's definitely overkill for your application. Good luck to you. From deirdre@deirdre.net Wed Mar 21 21:56:29 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 21 Mar 2001 13:56:29 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A475@go.ihello.com> Message-ID: <Pine.LNX.4.31.0103211352120.4076-100000@emperor.deirdre.org> On Wed, 21 Mar 2001, Glen Bunting wrote: > When I try : > > >>> import string > >>> CONFIG = open('webconf.txt').read() > >>> for 1 in CONFIG: > ... key, value = string.split(1, ';') > ... print 'The key is : ', key > ... print 'The value is : ', value > > SyntaxError: Can't assign to literal You probably want: for l in CONFIG: 1 is a number and can't be assigned a value. Also, likely you want .readlines() rather than .read() -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From Glen@ihello-inc.com Wed Mar 21 22:05:32 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 21 Mar 2001 14:05:32 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A476@go.ihello.com> When I make the changes: >>> import string >>> CONFIG = open('webconf.txt').readlines() >>> for eachLine in CONFIG: ... key, value = string.split(eachLine, ';') ... print 'The key is : ', key ... Traceback (innermost last): File "<stdin>", line 2, in ? ValueError: unpack list of wrong size What does that mean and what am I doing wrong? Glen -----Original Message----- From: Deirdre Saoirse [mailto:deirdre@deirdre.net] Sent: Wednesday, March 21, 2001 1:56 PM To: Glen Bunting Cc: 'Daniel Yoo'; 'tutor@python.org' Subject: RE: [Tutor] (no subject) On Wed, 21 Mar 2001, Glen Bunting wrote: > When I try : > > >>> import string > >>> CONFIG = open('webconf.txt').read() > >>> for 1 in CONFIG: > ... key, value = string.split(1, ';') > ... print 'The key is : ', key > ... print 'The value is : ', value > > SyntaxError: Can't assign to literal You probably want: for l in CONFIG: 1 is a number and can't be assigned a value. Also, likely you want .readlines() rather than .read() -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From deirdre@deirdre.net Wed Mar 21 22:11:09 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 21 Mar 2001 14:11:09 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A476@go.ihello.com> Message-ID: <Pine.LNX.4.31.0103211409580.4076-100000@emperor.deirdre.org> On Wed, 21 Mar 2001, Glen Bunting wrote: > When I make the changes: > > >>> import string > >>> CONFIG = open('webconf.txt').readlines() > >>> for eachLine in CONFIG: > ... key, value = string.split(eachLine, ';') > ... print 'The key is : ', key > ... > > Traceback (innermost last): > File "<stdin>", line 2, in ? > ValueError: unpack list of wrong size > > What does that mean and what am I doing wrong? It means that one of your lines doesn't have two elements when split. You can fix this by: try: key, value = string.split(eachLine, ';') else: key = eachLine value = '' -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kalle@gnupung.net Wed Mar 21 22:18:26 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 21 Mar 2001 23:18:26 +0100 Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A476@go.ihello.com>; from Glen@ihello-inc.com on Wed, Mar 21, 2001 at 02:05:32PM -0800 References: <A50594A71D5FD311A00200902745F06F18A476@go.ihello.com> Message-ID: <20010321231825.B807@apone.network.loc> Sez Glen Bunting: > When I make the changes: > > >>> import string > >>> CONFIG = open('webconf.txt').readlines() > >>> for eachLine in CONFIG: > ... key, value = string.split(eachLine, ';') > ... print 'The key is : ', key > ... > > Traceback (innermost last): > File "<stdin>", line 2, in ? > ValueError: unpack list of wrong size > > What does that mean and what am I doing wrong? There is more than one ";" in the line, so string.split returns more than two elements. But you try to assign them to key, value. Only two elements. There are many ways to solve it. For example, try: import string CONFIG = open('webconf.txt').readlines() for eachLine in CONFIG: elements = string.split(eachLine, ';') print 'The key is : ', elements[0] # the first element print 'The rest is : ', elements[1:] # the rest Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From kalle@gnupung.net Wed Mar 21 22:46:43 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 21 Mar 2001 23:46:43 +0100 Subject: [Tutor] (no subject) In-Reply-To: <20010321231825.B807@apone.network.loc>; from kalle@gnupung.net on Wed, Mar 21, 2001 at 11:18:26PM +0100 References: <A50594A71D5FD311A00200902745F06F18A476@go.ihello.com> <20010321231825.B807@apone.network.loc> Message-ID: <20010321234643.C807@apone.network.loc> Sez Kalle Svensson: > Sez Glen Bunting: > > When I make the changes: > > > > >>> import string > > >>> CONFIG = open('webconf.txt').readlines() > > >>> for eachLine in CONFIG: > > ... key, value = string.split(eachLine, ';') > > ... print 'The key is : ', key > > ... > > > > Traceback (innermost last): > > File "<stdin>", line 2, in ? > > ValueError: unpack list of wrong size > > > > What does that mean and what am I doing wrong? > > There is more than one ";" in the line, so string.split returns more than > two elements. But you try to assign them to key, value. Only two elements. > There are many ways to solve it. For example, try: Aaargh! I'm so stupid! Don't listen to me, read Deirdre's post instead... Suits me right for doing more than one thing at a time. (For your convenince: There could of course be less than one ";" also.) Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From Glen@ihello-inc.com Wed Mar 21 22:41:11 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 21 Mar 2001 14:41:11 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A477@go.ihello.com> Thanks, now that I've got that figured out, how do I put teh values key and value into a dictionary. >>> import string >>> dict {} >>> CONFIG = open('webconf.txt').readlines() >>> for eachLine in CONFIG: ... key, value = string.split(eachLine, ';') ... dict = {key, value} but when I do that, only the last values are saved in the dictionary. All the previous ones are erased. Glen -----Original Message----- From: Deirdre Saoirse [mailto:deirdre@deirdre.net] Sent: Wednesday, March 21, 2001 2:11 PM To: Glen Bunting Cc: 'Daniel Yoo'; 'tutor@python.org' Subject: RE: [Tutor] (no subject) On Wed, 21 Mar 2001, Glen Bunting wrote: > When I make the changes: > > >>> import string > >>> CONFIG = open('webconf.txt').readlines() > >>> for eachLine in CONFIG: > ... key, value = string.split(eachLine, ';') > ... print 'The key is : ', key > ... > > Traceback (innermost last): > File "<stdin>", line 2, in ? > ValueError: unpack list of wrong size > > What does that mean and what am I doing wrong? It means that one of your lines doesn't have two elements when split. You can fix this by: try: key, value = string.split(eachLine, ';') else: key = eachLine value = '' -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From kalle@gnupung.net Wed Mar 21 22:58:53 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 21 Mar 2001 23:58:53 +0100 Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A477@go.ihello.com>; from Glen@ihello-inc.com on Wed, Mar 21, 2001 at 02:41:11PM -0800 References: <A50594A71D5FD311A00200902745F06F18A477@go.ihello.com> Message-ID: <20010321235853.E807@apone.network.loc> Sez Glen Bunting: > Thanks, now that I've got that figured out, how do I put teh values key and > value into a dictionary. > > >>> import string > >>> dict {} > >>> CONFIG = open('webconf.txt').readlines() > >>> for eachLine in CONFIG: > ... key, value = string.split(eachLine, ';') > ... dict = {key, value} Try dict[key] = value on the last line. > but when I do that, only the last values are saved in the dictionary. All > the previous ones are erased. That's because your code binds a new dictionary (created by {key, value}) to the variable dict each time through the loop. More about dictionaries: http://www.python.org/doc/current/lib/typesmapping.html Hope I'm right this time... Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From Glen@ihello-inc.com Wed Mar 21 22:54:22 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 21 Mar 2001 14:54:22 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A478@go.ihello.com> Please disregard. I think I figured it out. Glen -----Original Message----- From: Glen Bunting [mailto:Glen@ihello-inc.com] Sent: Wednesday, March 21, 2001 2:41 PM To: 'Deirdre Saoirse' Cc: 'Daniel Yoo'; 'tutor@python.org' Subject: RE: [Tutor] (no subject) Thanks, now that I've got that figured out, how do I put teh values key and value into a dictionary. >>> import string >>> dict {} >>> CONFIG = open('webconf.txt').readlines() >>> for eachLine in CONFIG: ... key, value = string.split(eachLine, ';') ... dict = {key, value} but when I do that, only the last values are saved in the dictionary. All the previous ones are erased. Glen -----Original Message----- From: Deirdre Saoirse [mailto:deirdre@deirdre.net] Sent: Wednesday, March 21, 2001 2:11 PM To: Glen Bunting Cc: 'Daniel Yoo'; 'tutor@python.org' Subject: RE: [Tutor] (no subject) On Wed, 21 Mar 2001, Glen Bunting wrote: > When I make the changes: > > >>> import string > >>> CONFIG = open('webconf.txt').readlines() > >>> for eachLine in CONFIG: > ... key, value = string.split(eachLine, ';') > ... print 'The key is : ', key > ... > > Traceback (innermost last): > File "<stdin>", line 2, in ? > ValueError: unpack list of wrong size > > What does that mean and what am I doing wrong? It means that one of your lines doesn't have two elements when split. You can fix this by: try: key, value = string.split(eachLine, ';') else: key = eachLine value = '' -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From BobbyMcGrawBobby@aol.com Thu Mar 22 01:31:12 2001 From: BobbyMcGrawBobby@aol.com (BobbyMcGrawBobby@aol.com) Date: Wed, 21 Mar 2001 20:31:12 EST Subject: [Tutor] Doesnt Work Message-ID: <46.1249d9b0.27eaafe0@aol.com> http://www.crosswinds.net/~agauld/ doesnt work. Bobby From margaret@retriever.com.au Thu Mar 22 02:46:45 2001 From: margaret@retriever.com.au (Margaret Brierton) Date: Thu, 22 Mar 2001 13:46:45 +1100 Subject: [Tutor] threads Message-ID: <3AB96795.CF906576@retriever.com.au> Hi Can someone tell me where the threading modules are........? cheers From profkyne@yahoo.com Thu Mar 22 01:41:51 2001 From: profkyne@yahoo.com (profkyne@yahoo.com) Date: Wed, 21 Mar 2001 17:41:51 -0800 (PST) Subject: [Tutor] Yahoo! Auto Response Message-ID: <20010322014151.45725.qmail@mta317.mail.yahoo.com> Greetings: Unfortunately, you've tried to reach me while I'm on vacation. I should be back by Saturday (the 18th) or possibly Sunday. Hope you're doing well, though. Just think of Florida, and then think, "heck, I forgot to brush my teeth." Now go brush. -- Professor Kyne -------------------- Original Message: >From tutor-admin@python.org Thu Mar 22 01:41:45 2001 Return-Path: <tutor-admin@python.org> X-Track: 1: 40 Received: from mail.python.org (63.102.49.29) by mta317.mail.yahoo.com with SMTP; 21 Mar 2001 09:39:37 -0800 (PST) Received: from localhost.localdomain ([127.0.0.1] helo=mail.python.org) by mail.python.org with esmtp (Exim 3.21 #1) id 14flyv-0000cp-00; Wed, 21 Mar 2001 12:01:09 -0500 From: tutor-request@python.org Subject: Tutor digest, Vol 1 #676 - 16 msgs Reply-to: tutor@python.org X-Mailer: Mailman v2.0.3 (101270) MIME-version: 1.0 Content-type: text/plain To: tutor@python.org Sender: tutor-admin@python.org Errors-To: tutor-admin@python.org X-BeenThere: tutor@python.org X-Mailman-Version: 2.0.3 (101270) Precedence: bulk List-Help: <mailto:tutor-request@python.org?subject=help> List-Post: <mailto:tutor@python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/tutor>, <mailto:tutor-request@python.org?subject=subscribe> List-Id: Discussion for learning programming w _________________________________________________________ DO YOU YAHOO!? Get your free @yahoo.com address at http://mail.yahoo.com From gruschow2@hotmail.com Thu Mar 22 04:36:12 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 21 Mar 2001 22:36:12 -0600 Subject: [Tutor] I think I got a final version of a clock program, it is in this post. Message-ID: <OE76nYTlLyUuMSe7fpA00002f74@hotmail.com> This is a multi-part message in MIME format. ------=_NextPart_000_00A2_01C0B257.5511C260 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I think I got a final version of a clock program, it is in this post. Charles Gruschow gruschow2@hotmail.com from Tkinter import * from time import * from locale import * class Clock(Frame): def __init__(self, master, format=3D"Our local time is now %X"): Frame.__init__(self, master) self.time =3D localtime(time()) self.timeformat =3D format self.display =3D Label(self, fg=3D"green", bg=3D"black", text=3Dstrftime(self.timeformat, self.time)) self.display.pack(side=3DTOP, expand=3DYES, fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time =3D localtime(time()) self.display.configure(text=3Dstrftime(self.timeformat, = self.time)) self.after(1000, self.updateDisplay) class Uptime(Frame): def __init__(self,master,format2=3D"Dune UpTime is %d weeks %d days = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(w,d,h1,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] self.time4=3Dself.time[3] self.time5=3Dself.time[4] self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time5=3Dself.time5+1 if self.time5=3D=3D60: self.time5=3D0 self.time4=3Dself.time4+1 if self.time4=3D=3D60: self.time4=3D0 self.time3=3Dself.time3+1 if self.time3=3D=3D24: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D7: self.time2=3D0 self.time1=3Dself.time1+1 = self.time=3D(self.time1,self.time2,self.time3,self.time4,self.time5) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock18(Frame): def __init__(self,master,format2=3D"Time so far on 18 hr. planet is = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(h,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] if self.time1>18: self.time1=3Dself.time1 % 18 self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time3=3Dself.time3+1 if self.time3=3D=3D60: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D60: self.time2=3D0 self.time1=3Dself.time1+1 if self.time1=3D=3D18: self.time1=3D0 self.time=3D(self.time1,self.time2,self.time3) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock21(Frame): def __init__(self,master,format2=3D"Time so far on 21 hr. planet is = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(h,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] if self.time1>21: self.time1=3Dself.time1 % 21 self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time3=3Dself.time3+1 if self.time3=3D=3D60: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D60: self.time2=3D0 self.time1=3Dself.time1+1 if self.time1=3D=3D21: self.time1=3D0 self.time=3D(self.time1,self.time2,self.time3) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock24(Frame): def __init__(self,master,format2=3D"Time so far on 24 hr. planet is = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(h,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] if self.time1>24: self.time1=3Dself.time1 % 24 self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time3=3Dself.time3+1 if self.time3=3D=3D60: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D60: self.time2=3D0 self.time1=3Dself.time1+1 if self.time1=3D=3D24: self.time1=3D0 self.time=3D(self.time1,self.time2,self.time3) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock28(Frame): def __init__(self,master,format2=3D"Time so far on 28 hr. planet is = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(h,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] if self.time1>28: self.time1=3Dself.time1 % 28 self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time3=3Dself.time3+1 if self.time3=3D=3D60: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D60: self.time2=3D0 self.time1=3Dself.time1+1 if self.time1=3D=3D28: self.time1=3D0 self.time=3D(self.time1,self.time2,self.time3) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock36(Frame): def __init__(self,master,format2=3D"Time so far on 36 hr. planet is = %d:%d:%d"): Frame.__init__(self,master) self.time=3D(h,m,s) self.time1=3Dself.time[0] self.time2=3Dself.time[1] self.time3=3Dself.time[2] if self.time1>36: self.time1=3Dself.time1 % 36 self.timeformat=3Dformat2 self.display=3DLabel(self,fg=3D"green",bg=3D"black", text=3Dformat(self.timeformat,self.time)) self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH) self.updateDisplay() def updateDisplay(self): self.time3=3Dself.time3+1 if self.time3=3D=3D60: self.time3=3D0 self.time2=3Dself.time2+1 if self.time2=3D=3D60: self.time2=3D0 self.time1=3Dself.time1+1 if self.time1=3D=3D36: self.time1=3D0 self.time=3D(self.time1,self.time2,self.time3) self.display.configure(text=3Dformat(self.timeformat,self.time)) self.after(1000,self.updateDisplay) if __name__ =3D=3D "__main__": print "Dune MUD Time Giver" print "by Charles Gruschow" print "email: gruschow2@hotmail.com" print w=3Dinput("Number of uptime weeks (this will be w) ? ") d=3Dinput("Number of uptime days (this will be d) ? ") h=3Dinput("Number of uptime hours (this will be h) ? ") m=3Dinput("Number of uptime minutes (this will be m) ? ") s=3Dinput("Number of uptime seconds (this will be s) ? ") s3=3D(w*7*24*3600)+(d*24*3600)+(h*3600)+(m*60)+s print print "Seconds uptime is: ",s3 s3=3D(1-0.00303674226326)*s3 print "Seconds uptime less 0.303674226326%: ",s3 print "That factor was since planet times lag behind uptime." w3=3Dw d3=3Dd h3=3Dh m3=3Dm if s3>604800: w3=3Dint(s3/604800) d3=3Dw3*7 h3=3Dd3*24 m3=3Dh3*60 s3=3Ds3-(w3*604800) if s3>86400: d3=3Dint(s3/86400) h3=3Dd3*24 m3=3Dh3*60 s3=3Ds3-(d3*86400) if s3>3600: h3=3Dint(s3/3600) m3=3Dh3*60 s3=3Ds3-(h3*3600) if s3>60: m3=3Dint(s3/60) s3=3Ds3-(m3*60) w3=3Dint(w3) d3=3Dint(d3) h3=3Dint(h3) m3=3Dint(m3) s3=3Dint(s3) print print "Corrected: wks.: %d, dys.: %d, hrs.: %d, min.: %d, sec.: %d" = % (w3,d3,h3,m3,s3) print "These corrected values will show themselves most readily in = the 24 hr. planets." w=3Dint(abs(w)) d=3Dint(abs(d)) h1=3Dint(abs(h)) h=3Dh+(w*7*24)+(d*24) h=3Dint(abs(h)) m=3Dint(abs(m)) s=3Dint(abs(s)) =20 =20 if s>60: s1=3Ds s=3Ds%60 m=3Dm+int(s1/60) if m>60: m1=3Dm m=3Dm%60 h1=3Dh1+int(m1/60) if h1>24: h2=3Dh1 h1=3Dh1%24 d=3Dd+int(h2/24) if d>7: d1=3Dd d=3Dd%7 w=3Dw+int(d1/7) =20 tkroot =3D Tk() tkroot.title("Dune MUD Time Giver") labelx =3D Label(tkroot,fg=3D"red",text=3D"Dune MUD (based on works = of Frank Herbert) Time Giver",font=3D("Times",14)) labelx.pack() labelx =3D Label(tkroot,fg=3D"blue",text=3D"for info contact = gruschow2@hotmail.com") labelx.pack() labelx =3D Label(tkroot) labelx["height"] =3D 1 labelx.pack() Clock(tkroot, "Our local time is now %X").pack(side=3DTOP) Uptime(tkroot,"Dune UpTime is %d weeks %d days = %d:%d:%d").pack(side=3DTOP,pady=3D5) h=3Dh3 m=3Dm3 s=3Ds3 labelx =3D Label(tkroot) labelx["height"] =3D 1 labelx.pack() labelx =3D Label(tkroot,text=3D"Planets of Chapterhouse and = Wallach") labelx.pack() Clock18(tkroot,"Time so far on 18 hr. planet is = %d:%d:%d").pack(side=3DTOP) labelx =3D Label(tkroot,text=3D"Planet of Salusa") labelx.pack() Clock21(tkroot,"Time so far on 21 hr. planet is = %d:%d:%d").pack(side=3DTOP) labelx =3D Label(tkroot,text=3D"Planets of Arrakis (Dune) and Ix") labelx.pack() Clock24(tkroot,"Time so far on 24 hr. planet is = %d:%d:%d").pack(side=3DTOP) labelx =3D Label(tkroot,text=3D"Planet of Geidi Prime") labelx.pack() Clock28(tkroot,"Time so far on 28 hr. planet is = %d:%d:%d").pack(side=3DTOP) labelx =3D Label(tkroot,text=3D"Planet of Caladan") labelx.pack() Clock36(tkroot,"Time so far on 36 hr. planet is = %d:%d:%d").pack(side=3DTOP) labelx =3D Label(tkroot) labelx["height"] =3D 1 labelx.pack() labelx =3D Label(tkroot,fg=3D"blue",text=3D"Due to electromagnetic = properties of the planet Tleilax,") labelx.pack() labelx =3D Label(tkroot,fg=3D"blue",text=3D"it isn't necessary to = calculate time for there.") labelx.pack() labelx =3D Label(tkroot,fg=3D"blue",text=3D"Also, the times for the = planets can only be approximated.") labelx.pack() tkroot.mainloop() =20 =20 =20 ------=_NextPart_000_00A2_01C0B257.5511C260 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.3019.2500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2><FONT size=3D2> <P>I think I got a final version of a clock program, it is in this=20 post.</P></FONT></FONT></DIV> <DIV><FONT face=3DArial size=3D2>Charles Gruschow</FONT></DIV> <DIV><FONT face=3DArial size=3D2><A=20 href=3D"mailto:gruschow2@hotmail.com">gruschow2@hotmail.com</A></FONT></D= IV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>from Tkinter import *<BR>from time = import *<BR>from=20 locale import *</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2><BR>class Clock(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def __init__(self, = master,=20 format=3D"Our local time is now %X"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self, master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time =3D = localtime(time())<BR> =20 self.timeformat =3D format<BR> = self.display =3D Label(self, fg=3D"green",=20 bg=3D"black",<BR> &n= bsp; =20 text=3Dstrftime(self.timeformat,=20 self.time))<BR> =20 self.display.pack(side=3DTOP, expand=3DYES,=20 fill=3DBOTH)<BR> =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time =3D = localtime(time())<BR> =20 self.display.configure(text=3Dstrftime(self.timeformat,=20 self.time))<BR> = self.after(1000,=20 self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Uptime(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Dune UpTime is %d weeks %d days=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(w,d,h1,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]<BR> =20 self.time4=3Dself.time[3]<BR> =20 self.time5=3Dself.time[4]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time5=3Dself.time5+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time5=3D=3D60:<BR> &n= bsp; =20 self.time5=3D0<BR> &= nbsp; =20 self.time4=3Dself.time4+1<BR> = if=20 self.time4=3D=3D60:<BR> &n= bsp; =20 self.time4=3D0<BR> &= nbsp; =20 self.time3=3Dself.time3+1<BR> = if=20 self.time3=3D=3D24:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D7:<BR> &nb= sp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3,self.time4,self.time5)<BR>&= nbsp; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Clock18(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Time so far on 18 hr. planet is=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(h,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time1>18:<BR> &nbs= p; =20 self.time1=3Dself.time1 % 18</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time3=3Dself.time3+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time3=3D=3D60:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D60:<BR> &n= bsp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1<BR> = if=20 self.time1=3D=3D18:<BR> &n= bsp; =20 self.time1=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3)<BR>  = ; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Clock21(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Time so far on 21 hr. planet is=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(h,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time1>21:<BR> &nbs= p; =20 self.time1=3Dself.time1 % 21</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time3=3Dself.time3+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time3=3D=3D60:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D60:<BR> &n= bsp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1<BR> = if=20 self.time1=3D=3D21:<BR> &n= bsp; =20 self.time1=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3)<BR>  = ; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Clock24(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Time so far on 24 hr. planet is=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(h,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time1>24:<BR> &nbs= p; =20 self.time1=3Dself.time1 % 24</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time3=3Dself.time3+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time3=3D=3D60:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D60:<BR> &n= bsp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1<BR> = if=20 self.time1=3D=3D24:<BR> &n= bsp; =20 self.time1=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3)<BR>  = ; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Clock28(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Time so far on 28 hr. planet is=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(h,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time1>28:<BR> &nbs= p; =20 self.time1=3Dself.time1 % 28</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time3=3Dself.time3+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time3=3D=3D60:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D60:<BR> &n= bsp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1<BR> = if=20 self.time1=3D=3D28:<BR> &n= bsp; =20 self.time1=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3)<BR>  = ; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>class Clock36(Frame):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 __init__(self,master,format2=3D"Time so far on 36 hr. planet is=20 %d:%d:%d"):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 Frame.__init__(self,master)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(h,m,s)<BR> =20 self.time1=3Dself.time[0]<BR> =20 self.time2=3Dself.time[1]<BR> =20 self.time3=3Dself.time[2]</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time1>36:<BR> &nbs= p; =20 self.time1=3Dself.time1 % 36</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.timeformat=3Dformat2<BR> =20 self.display=3DLabel(self,fg=3D"green",bg=3D"black",<BR>  = ; = =20 text=3Dformat(self.timeformat,self.time))<BR> &nbs= p; =20 self.display.pack(side=3DTOP,expand=3DYES,fill=3DBOTH)<BR> &nb= sp; =20 self.updateDisplay()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> def=20 updateDisplay(self):</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time3=3Dself.time3+1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> if=20 self.time3=3D=3D60:<BR> &n= bsp; =20 self.time3=3D0<BR> &= nbsp; =20 self.time2=3Dself.time2+1<BR> = if=20 self.time2=3D=3D60:<BR> &n= bsp; =20 self.time2=3D0<BR> &= nbsp; =20 self.time1=3Dself.time1+1<BR> = if=20 self.time1=3D=3D36:<BR> &n= bsp; =20 self.time1=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 self.time=3D(self.time1,self.time2,self.time3)<BR>  = ; =20 self.display.configure(text=3Dformat(self.timeformat,self.time))<BR> = ; =20 self.after(1000,self.updateDisplay)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>if __name__ =3D=3D = "__main__":</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2><BR> print "Dune MUD = Time=20 Giver"<BR> print "by Charles = Gruschow"<BR> =20 print "email: <A=20 href=3D"mailto:gruschow2@hotmail.com">gruschow2@hotmail.com</A>"<BR> = ; =20 print<BR> w=3Dinput("Number of uptime weeks (this will = be w) ?=20 ")<BR> d=3Dinput("Number of uptime days (this will be = d) ?=20 ")<BR> h=3Dinput("Number of uptime hours (this will be = h) ?=20 ")<BR> m=3Dinput("Number of uptime minutes (this will = be m) ?=20 ")<BR> s=3Dinput("Number of uptime seconds (this will = be s) ?=20 ")<BR> =20 s3=3D(w*7*24*3600)+(d*24*3600)+(h*3600)+(m*60)+s<BR> =20 print<BR> print "Seconds uptime is: = ",s3<BR> =20 s3=3D(1-0.00303674226326)*s3<BR> print "Seconds uptime = less=20 0.303674226326%: ",s3<BR> print "That factor was since = planet=20 times lag behind uptime."<BR> = w3=3Dw<BR> =20 d3=3Dd<BR> h3=3Dh<BR> = m3=3Dm<BR> =20 if s3>604800:<BR> =20 w3=3Dint(s3/604800)<BR> =20 d3=3Dw3*7<BR> =20 h3=3Dd3*24<BR> =20 m3=3Dh3*60<BR> =20 s3=3Ds3-(w3*604800)<BR> if=20 s3>86400:<BR> =20 d3=3Dint(s3/86400)<BR> =20 h3=3Dd3*24<BR> =20 m3=3Dh3*60<BR> =20 s3=3Ds3-(d3*86400)<BR> if=20 s3>3600:<BR> =20 h3=3Dint(s3/3600)<BR> =20 m3=3Dh3*60<BR> =20 s3=3Ds3-(h3*3600)<BR> if=20 s3>60:<BR> =20 m3=3Dint(s3/60)<BR> =20 s3=3Ds3-(m3*60)<BR> w3=3Dint(w3)<BR> = d3=3Dint(d3)<BR> h3=3Dint(h3)<BR> =20 m3=3Dint(m3)<BR> s3=3Dint(s3)<BR> =20 print<BR> print "Corrected: wks.: %d, dys.: %d, hrs.: = %d,=20 min.: %d, sec.: %d" % (w3,d3,h3,m3,s3)<BR> print = "These=20 corrected values will show themselves most readily in the 24 hr.=20 planets."<BR> w=3Dint(abs(w))<BR> =20 d=3Dint(abs(d))<BR> = h1=3Dint(abs(h))<BR> =20 h=3Dh+(w*7*24)+(d*24)<BR> = h=3Dint(abs(h))<BR> =20 m=3Dint(abs(m))<BR> = s=3Dint(abs(s))<BR> =20 <BR> <BR> if=20 s>60:<BR> =20 s1=3Ds<BR> =20 s=3Ds%60<BR> =20 m=3Dm+int(s1/60)<BR> if=20 m>60:<BR> =20 m1=3Dm<BR> =20 m=3Dm%60<BR> =20 h1=3Dh1+int(m1/60)<BR> if=20 h1>24:<BR> =20 h2=3Dh1<BR> =20 h1=3Dh1%24<BR> =20 d=3Dd+int(h2/24)<BR> if=20 d>7:<BR> =20 d1=3Dd<BR> =20 d=3Dd%7<BR> =20 w=3Dw+int(d1/7)<BR> =20 <BR> tkroot =3D Tk()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> tkroot.title("Dune = MUD Time=20 Giver")</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot,fg=3D"red",text=3D"Dune MUD (based on works of Frank = Herbert) Time=20 Giver",font=3D("Times",14))<BR> =20 labelx.pack()<BR> labelx =3D = Label(tkroot,fg=3D"blue",text=3D"for=20 info contact <A=20 href=3D'mailto:gruschow2@hotmail.com")'>gruschow2@hotmail.com")</A><BR>&n= bsp; =20 labelx.pack()<BR> labelx =3D = Label(tkroot)<BR> =20 labelx["height"] =3D 1<BR> labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock(tkroot, "Our = local time is=20 now %X").pack(side=3DTOP)<BR> Uptime(tkroot,"Dune = UpTime is %d=20 weeks %d days %d:%d:%d").pack(side=3DTOP,pady=3D5)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> = h=3Dh3<BR> =20 m=3Dm3<BR> s=3Ds3</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot)<BR> labelx["height"] =3D = 1<BR> =20 labelx.pack()<BR> labelx =3D = Label(tkroot,text=3D"Planets of=20 Chapterhouse and Wallach")<BR> = labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock18(tkroot,"Time = so far on=20 18 hr. planet is %d:%d:%d").pack(side=3DTOP)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot,text=3D"Planet of Salusa")<BR> =20 labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock21(tkroot,"Time = so far on=20 21 hr. planet is %d:%d:%d").pack(side=3DTOP)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot,text=3D"Planets of Arrakis (Dune) and = Ix")<BR> =20 labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock24(tkroot,"Time = so far on=20 24 hr. planet is %d:%d:%d").pack(side=3DTOP)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot,text=3D"Planet of Geidi Prime")<BR> =20 labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock28(tkroot,"Time = so far on=20 28 hr. planet is %d:%d:%d").pack(side=3DTOP)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot,text=3D"Planet of Caladan")<BR> =20 labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> Clock36(tkroot,"Time = so far on=20 36 hr. planet is %d:%d:%d").pack(side=3DTOP)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> labelx =3D=20 Label(tkroot)<BR> labelx["height"] =3D = 1<BR> =20 labelx.pack()<BR> labelx =3D = Label(tkroot,fg=3D"blue",text=3D"Due to=20 electromagnetic properties of the planet = Tleilax,")<BR> =20 labelx.pack()<BR> labelx =3D = Label(tkroot,fg=3D"blue",text=3D"it=20 isn't necessary to calculate time for there.")<BR> =20 labelx.pack()<BR> labelx =3D = Label(tkroot,fg=3D"blue",text=3D"Also,=20 the times for the planets can only be = approximated.")<BR> =20 labelx.pack()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> = tkroot.mainloop()</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial=20 size=3D2> <BR> = =20 </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2> =20 <BR></FONT></DIV></BODY></HTML> ------=_NextPart_000_00A2_01C0B257.5511C260-- From gruschow2@hotmail.com Thu Mar 22 04:53:27 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 21 Mar 2001 22:53:27 -0600 Subject: [Tutor] I think I got a final version of a clock program, it is in this post. Message-ID: <OE265BBBVhyemYewQ1N000034b0@hotmail.com> I think I got a final version of a clock program, it is in this post. Charles Gruschow gruschow2@hotmail.com from Tkinter import * from time import * from locale import * class Clock(Frame): def __init__(self, master, format="Our local time is now %X"): Frame.__init__(self, master) self.time = localtime(time()) self.timeformat = format self.display = Label(self, fg="green", bg="black", text=strftime(self.timeformat, self.time)) self.display.pack(side=TOP, expand=YES, fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time = localtime(time()) self.display.configure(text=strftime(self.timeformat, self.time)) self.after(1000, self.updateDisplay) class Uptime(Frame): def __init__(self,master,format2="Dune UpTime is %d weeks %d days %d:%d:%d"): Frame.__init__(self,master) self.time=(w,d,h1,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] self.time4=self.time[3] self.time5=self.time[4] self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time5=self.time5+1 if self.time5==60: self.time5=0 self.time4=self.time4+1 if self.time4==60: self.time4=0 self.time3=self.time3+1 if self.time3==24: self.time3=0 self.time2=self.time2+1 if self.time2==7: self.time2=0 self.time1=self.time1+1 self.time=(self.time1,self.time2,self.time3,self.time4,self.time5) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock18(Frame): def __init__(self,master,format2="Time so far on 18 hr. planet is %d:%d:%d"): Frame.__init__(self,master) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>18: self.time1=self.time1 % 18 self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==18: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock21(Frame): def __init__(self,master,format2="Time so far on 21 hr. planet is %d:%d:%d"): Frame.__init__(self,master) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>21: self.time1=self.time1 % 21 self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==21: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock24(Frame): def __init__(self,master,format2="Time so far on 24 hr. planet is %d:%d:%d"): Frame.__init__(self,master) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>24: self.time1=self.time1 % 24 self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==24: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock28(Frame): def __init__(self,master,format2="Time so far on 28 hr. planet is %d:%d:%d"): Frame.__init__(self,master) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>28: self.time1=self.time1 % 28 self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==28: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class Clock36(Frame): def __init__(self,master,format2="Time so far on 36 hr. planet is %d:%d:%d"): Frame.__init__(self,master) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>36: self.time1=self.time1 % 36 self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==36: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) if __name__ == "__main__": print "Dune MUD Time Giver" print "by Charles Gruschow" print "email: gruschow2@hotmail.com" print w=input("Number of uptime weeks (this will be w) ? ") d=input("Number of uptime days (this will be d) ? ") h=input("Number of uptime hours (this will be h) ? ") m=input("Number of uptime minutes (this will be m) ? ") s=input("Number of uptime seconds (this will be s) ? ") s3=(w*7*24*3600)+(d*24*3600)+(h*3600)+(m*60)+s print print "Seconds uptime is: ",s3 s3=(1-0.00303674226326)*s3 print "Seconds uptime less 0.303674226326%: ",s3 print "That factor was since planet times lag behind uptime." w3=w d3=d h3=h m3=m if s3>604800: w3=int(s3/604800) d3=w3*7 h3=d3*24 m3=h3*60 s3=s3-(w3*604800) if s3>86400: d3=int(s3/86400) h3=d3*24 m3=h3*60 s3=s3-(d3*86400) if s3>3600: h3=int(s3/3600) m3=h3*60 s3=s3-(h3*3600) if s3>60: m3=int(s3/60) s3=s3-(m3*60) w3=int(w3) d3=int(d3) h3=int(h3) m3=int(m3) s3=int(s3) print print "Corrected: wks.: %d, dys.: %d, hrs.: %d, min.: %d, sec.: %d" % (w3,d3,h3,m3,s3) print "These corrected values will show themselves most readily in the 24 hr. planets." w=int(abs(w)) d=int(abs(d)) h1=int(abs(h)) h=h+(w*7*24)+(d*24) h=int(abs(h)) m=int(abs(m)) s=int(abs(s)) if s>60: s1=s s=s%60 m=m+int(s1/60) if m>60: m1=m m=m%60 h1=h1+int(m1/60) if h1>24: h2=h1 h1=h1%24 d=d+int(h2/24) if d>7: d1=d d=d%7 w=w+int(d1/7) tkroot = Tk() tkroot.title("Dune MUD Time Giver") labelx = Label(tkroot,fg="red",text="Dune MUD (based on works of Frank Herbert) Time Giver",font=("Times",14)) labelx.pack() labelx = Label(tkroot,fg="blue",text="for info contact gruschow2@hotmail.com") labelx.pack() labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() Clock(tkroot, "Our local time is now %X").pack(side=TOP) Uptime(tkroot,"Dune UpTime is %d weeks %d days %d:%d:%d").pack(side=TOP,pady=5) h=h3 m=m3 s=s3 labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() labelx = Label(tkroot,text="Planets of Chapterhouse and Wallach") labelx.pack() Clock18(tkroot,"Time so far on 18 hr. planet is %d:%d:%d").pack(side=TOP) labelx = Label(tkroot,text="Planet of Salusa") labelx.pack() Clock21(tkroot,"Time so far on 21 hr. planet is %d:%d:%d").pack(side=TOP) labelx = Label(tkroot,text="Planets of Arrakis (Dune) and Ix") labelx.pack() Clock24(tkroot,"Time so far on 24 hr. planet is %d:%d:%d").pack(side=TOP) labelx = Label(tkroot,text="Planet of Geidi Prime") labelx.pack() Clock28(tkroot,"Time so far on 28 hr. planet is %d:%d:%d").pack(side=TOP) labelx = Label(tkroot,text="Planet of Caladan") labelx.pack() Clock36(tkroot,"Time so far on 36 hr. planet is %d:%d:%d").pack(side=TOP) labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() labelx = Label(tkroot,fg="blue",text="Due to electromagnetic properties of the planet Tleilax,") labelx.pack() labelx = Label(tkroot,fg="blue",text="it isn't necessary to calculate time for there.") labelx.pack() labelx = Label(tkroot,fg="blue",text="Also, the times for the planets can only be approximated.") labelx.pack() tkroot.mainloop() From gruschow2@hotmail.com Thu Mar 22 05:03:33 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 21 Mar 2001 23:03:33 -0600 Subject: [Tutor] I didn't do any input inside my gui interface since I could not fugure out how to do that. Message-ID: <OE56NhFCfywEsGmjm0800002d26@hotmail.com> I didn't do any input inside my gui interface since I could not fugure out how to do that. I can figure out how to do the basic widgets. I can not figure out how to use them for input purposes. And if I did use them for input purposes, I dont see how you could change values whenever you wanted. For example adjusting hours or minutes or seconds on a particular clock up and down whenever you wanted with say scale widgets. Scale widgets are the worst about this, I can do a button that does a callback to show current value of scale but that does not help me at all with using a scale widget as a means to set hours or minutes or seconds on a clock which should be adjustable whenever one wants it to be with very small scales for each value. The only way I can see me understanding how to do this right (these input widgets, especially the scale one) is to see example code somewhere. So what I ended up doing was have the user enter initial values from the command console dos-like window, and used the GUI interface to show the clocks and some descriptive labels. Charles Gruschow gruschow2@hotmail.com From gruschow2@hotmail.com Thu Mar 22 05:16:01 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 21 Mar 2001 23:16:01 -0600 Subject: [Tutor] I figured out how to turn my clock program into a distributable form. Message-ID: <OE27gtc2S6AATiyhGvD0000360a@hotmail.com> I figured out how to turn my clock program into a distributable form. Using the McMillan Enterprises, Inc. (http://www.mcmillan-inc.com/index.html) Freeze/Python program distributing program thing. This freezing/distributing utility did not work well with my Python 1.5.2 so I downloaded Python 2.0 and the version of the utility for Python 2.0 and got all I needed to distribute my program into one folder and it did work on someone elses computer. It created an executable for my program. I thought it was pretty neat. Charles Gruschow gruschow2@hotmail.com From gruschow2@hotmail.com Thu Mar 22 05:30:24 2001 From: gruschow2@hotmail.com (Charles Gruschow, Jr.) Date: Wed, 21 Mar 2001 23:30:24 -0600 Subject: [Tutor] I then figured out how to turn that distribution folder that contained my exe into a distribution folder exe by..... Message-ID: <OE32LV69ArTCSdY5vle00003644@hotmail.com> I then figured out how to turn that distribution folder that contained my exe into a distribution folder exe by..... using Ghost Installer utility from http://www.ginstall.com/ . That utility turned my folder and all its files into a distributable executable complete with readme file and license file and asking where the folder should be installed and so forth. Python was free, the freezing thing from McMillan Enterprises, Inc. was free, and this Ghost Installer was free, I like free, don't you. If I wanted to I could get that Ghost Installer to edit registry or ini files or ask for what program group to use among other things. *******IF YOU WANT TO SEE MY FINAL EXE FROM THE GHOST UTILITY LET ME KNOW********* Charles Gruschow gruschow2@hotmail.com From dyoo@hkn.eecs.berkeley.edu Thu Mar 22 07:17:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 21 Mar 2001 23:17:14 -0800 (PST) Subject: [Tutor] threads In-Reply-To: <3AB96795.CF906576@retriever.com.au> Message-ID: <Pine.LNX.4.21.0103212315160.6570-100000@hkn.eecs.berkeley.edu> On Thu, 22 Mar 2001, Margaret Brierton wrote: > Can someone tell me where the threading modules are........? Here you go: http://python.org/doc/current/lib/module-thread.html and http://python.org/doc/current/lib/module-threading.html both describe thread modules. For synchronization, you'll probably find: http://python.org/doc/current/lib/module-mutex.html useful; it describes mutex objects. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu Mar 22 07:20:20 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 21 Mar 2001 23:20:20 -0800 (PST) Subject: [Tutor] Doesnt Work In-Reply-To: <46.1249d9b0.27eaafe0@aol.com> Message-ID: <Pine.LNX.4.21.0103212318200.6570-100000@hkn.eecs.berkeley.edu> On Wed, 21 Mar 2001 BobbyMcGrawBobby@aol.com wrote: > http://www.crosswinds.net/~agauld/ doesnt work. Hmmm... seems to be down. I hope it's not the California energy crisis. *grin* Until it comes back up, there's an older mirror here: http://members.nbci.com/alan_gauld/tutor/tutindex.htm It sounds like it's a little outdated compared to the main site, but it should be helpful. If you have any questions, feel free to ask. From sheila@thinkspot.net Thu Mar 22 08:02:23 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 22 Mar 2001 00:02:23 -0800 Subject: [Tutor] User Groups Message-ID: <FF7B2B0D05@kserver.org> I notice that the BayPiggies (San Francisco area Python User Group) is quite active. I've been to the Python website, and searched a bit, but don't find that there are many Python UGs around. Is there one in the Southern California (esp. Los Angeles/Orange County) area? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From cooler12001@yahoo.com Thu Mar 22 08:37:07 2001 From: cooler12001@yahoo.com (Matthews James) Date: Thu, 22 Mar 2001 00:37:07 -0800 (PST) Subject: [Tutor] I need help with saving to files Message-ID: <20010322083707.20207.qmail@web11408.mail.yahoo.com> This is what i need help on ##################################################### # File: JacksRecords.py def print_slip(): print '_______________________________' print ' ',Name,', ',Date print 'EMP # CAT IN' print Empnum,' ',CAT,' ',FIRSTIN print ' IN OUT' print ' ',FIRSTIN,' ',FIRSTOUT print ' IN' print ' ',SECIN print ' IN OUT' print ' ',SECIN,' ',SECOUT print '-------------------------------' Name = raw_input("What is the employees name: ") Date = raw_input("What is the Date: ") Empnum = input("What is the Employees Number: ") CAT = input("What is the CAT number: ") FIRSTIN = raw_input("What time did (he, she) come in: ") FIRSTOUT = raw_input("What time did (he, she) go on break: ") SECIN = raw_input("What time did (he, she) come in from break: ") SECOUT = raw_input("What time did (he, she) clock out to go home: ") print_slip() ##################################################### I want to beable to save 'print_slip()' to a file and then add more to that same file. I also want it to look like this when it saves the file _____________________________________________ John Doe, 3/21/2001 EMP # CAT IN 4578 1 7:54 IN OUT 7:45 8:25 IN 8:55 IN OUT 8:55 23:54 --------------------------------------------- I really dont know that much about python and i was wondering if anyone could help me out on this. I am going to use it so that i will not have to keep all my time slips from work. __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From kauphlyn@speakeasy.org Thu Mar 22 10:34:15 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Thu, 22 Mar 2001 02:34:15 -0800 (PST) Subject: [Tutor] I need help with saving to files In-Reply-To: <20010322083707.20207.qmail@web11408.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103220216120.11168-100000@grace.speakeasy.org> On Thu, 22 Mar 2001, Matthews James wrote: > This is what i need help on > I want to beable to save 'print_slip()' to a file > and then add more to that same file. first off, in your print_slip() you need to associate a variable with a file: def print_slip(): file = open('timesheet.txt', 'a') # the 'a' is for a appending. then instead of printing you need to write to the file: file.write('-----------------------------\n') # you will need to add the '\n' to maintain your formating. and finally, you'll need to change some of the string formats. I think replacing the commas with + should do the trick. (Otherwise, my interpriter treats it as a tuple rather than a string. Not quite sure why it chokes on that.) so print(Empnum,' ',CAT,' ',Firstin) should become file.write(Empnum + ' ' + CAT + ' ' + Firstin) etc. Hope this helps ~d From lha2@columbia.edu Thu Mar 22 11:40:16 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Thu, 22 Mar 2001 06:40:16 -0500 Subject: [Tutor] Re: Tutor digest, Vol 1 #678 - 7 msgs References: <E14fwsK-0008Ul-00@mail.python.org> Message-ID: <3AB9E4A0.434FB6D8@mail.verizon.net> Not to be offtopic, but is there a reason that 1/4 of the messages on this group are littered with "=3D" and "=20"? Is there a convenient way to filter these into regular equals signs and ?tabs? in Netscape (I haven't made the Debian leap yet)? It seems to be a particular problem with messages that are multipart MIME blah blah blah. Only bugs me when I'm wussy and read the plaintext instead of the HTML. -LHA From arcege@shore.net Thu Mar 22 12:14:40 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 22 Mar 2001 07:14:40 -0500 (EST) Subject: [Tutor] I didn't do any input inside my gui interface since I could not fugure out how to do that. In-Reply-To: <OE56NhFCfywEsGmjm0800002d26@hotmail.com> from "Charles Gruschow, Jr." at "Mar 21, 2001 11: 3:33 pm" Message-ID: <E14g3zE-0000r5-00@nautilus.shore.net> > I didn't do any input inside my gui interface since I could not fugure out > how to do that. > > I can figure out how to do the basic widgets. > > I can not figure out how to use them for input purposes. > > And if I did use them for input purposes, I dont see how you could change > values whenever you wanted. For example adjusting hours or minutes or > seconds on a particular clock up and down whenever you wanted with say scale > widgets. > > Scale widgets are the worst about this, I can do a button that does a > callback to show current value of scale but that does not help me at all > with using a scale widget as a means to set hours or minutes or seconds on a > clock which should be adjustable whenever one wants it to be with very small > scales for each value. > > The only way I can see me understanding how to do this right (these input > widgets, especially the scale one) is to see example code somewhere. > > So what I ended up doing was have the user enter initial values from the > command console dos-like window, and used the GUI interface to show the > clocks and some descriptive labels. There are various input widgets, Entry, Text, Button, Checkbutton, Scalebutton, Listbox, Scale. Often times, you will want to bind an event to get the input to envoke some of your own code. from Tkinter import * import Tkinter # to get _cnfmerge class EntryWithStatus(Entry): def __init__(self, master, status, cnf={}, **kws): cnf = Tkinter._cnfmerge( (cnf, kws) ) Entry.__init__(self, master, cnf=cnf) self.status_widget = status # to be used when we get the data self.bind('<Return>', self.enter) def enter(self, event): data = self.get() self.status_widget['text'] = ('Someone typed in "%s"' % data) status = Label(None) status.pack(side=BOTTOM, fill=X, expand=YES) EntryWithStatus(None, status=status).pack(side=TOP) mainloop() Whenever the return key is pressed in the Entry widget, a message is placed in the Label widget. If you want to change the hour/minute/second, then I'd suggest looking into Pmw's Counter widget (Pmw is a library on top of Tkinter). But the Scale widget "command" is a function that would take at least one argument which is the number being set. An example from Grayson's book is: def setHeight(canvas, heightStr): height = string.atoi(heightStr) height = height + 21 y2 = height - 30 if y2 < 21: y2 = 21 canvas.coords('poly', 12,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20) canvas.coords('line', 12,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20) canvas = Canvas(root, width=50, height=50, bd=0, highlightthickness=0) canvas.create_polygon(0,0,1,1,2,2,fill='cadetblue', tags='poly') canvas.create_line(0,0,1,1,2,2,0,0, fill='black', tags='line') scale = Scale(root, orient=VERTICAL, length=284, from_=0, to=250, tickinterval=50, command=lambda h, c=canvas: setHeight(c, h)) scale.grid(row=0, column=0, sticky='NE') canvas.grid(row=0, column=1, sticky='NWSE') scale.set(100) This lets you interactively "grow" the displayed arrow by moving the scale. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From jsp@opencom.de Thu Mar 22 13:49:54 2001 From: jsp@opencom.de (=?iso-8859-1?Q?J=F6rg_Sporer?=) Date: Thu, 22 Mar 2001 14:49:54 +0100 Subject: [Tutor] Help with freeze needed Message-ID: <000101c0b2d6$fa6c2230$3701000a@arthur> SGVsbG8hDQoNCldoZW4gSSB0cnkgdG8gZnJlZXplIG15IGFwcGxpY2F0aW9uLCBhbGwgSSBnZXQg aXMgYW4gZXJyb3IgbWVzc2FnZSBsaWtlDQp0aGlzOg0KDQpBdHRyaWJ1dGVFcnJvcjogJ1BZWlRh cmdldCcgaW5zdGFuY2UgaGFzIG5vIGF0dHJpYnV0ZSAnX19uYW1lX18nDQoNCldoYXQgaXMgd3Jv bmcgd2l0aCBteSBwcm9ncmFtPw0KDQpUaGFua3MgZm9yIHlvdXRyIGhlbHANCkr2cmcNCg0K From arcege@shore.net Thu Mar 22 14:00:51 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 22 Mar 2001 09:00:51 -0500 (EST) Subject: [Tutor] threads In-Reply-To: <3AB96795.CF906576@retriever.com.au> from Margaret Brierton at "Mar 22, 2001 1:46:45 pm" Message-ID: <E14g5dz-0000ok-00@nautilus.shore.net> > Hi > > Can someone tell me where the threading modules are........? > > cheers The base module is called "thread" - a built-in module. If you cannot import that module, then Python is not compiled with thread support. There are some operating systems which do not support threads. If your system does support threads, then you may need to reconfigure Python from sources with the --with-threads option. When you have the "thread" module, you will probably want to use the "threading" module instead. It has more support for threading constructs like semaphores, condition variables, read/write locks. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From kojo@tamu.edu Thu Mar 22 15:52:36 2001 From: kojo@tamu.edu (Kojo Idrissa) Date: Thu, 22 Mar 2001 09:52:36 -0600 Subject: [Tutor] Doesnt Work In-Reply-To: <46.1249d9b0.27eaafe0@aol.com> Message-ID: <5.0.2.1.0.20010322095211.02293b50@pop3.norton.antivirus> Works now. I just tried it. At 08:31 PM 3/21/01 -0500, BobbyMcGrawBobby@aol.com wrote: >http://www.crosswinds.net/~agauld/ doesnt work. > >Bobby > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor **************************** Kojo Idrissa KPMG Scholar Accounting Doctoral Student Texas A&M University Kojo@tamu.edu 401M Wehner Bldg. 979-862-2726 **************************** From dyoo@hkn.eecs.berkeley.edu Thu Mar 22 15:55:49 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 22 Mar 2001 07:55:49 -0800 (PST) Subject: [Tutor] I need help with saving to files In-Reply-To: <20010322083707.20207.qmail@web11408.mail.yahoo.com> Message-ID: <Pine.LNX.4.21.0103220726320.18262-100000@hkn.eecs.berkeley.edu> On Thu, 22 Mar 2001, Matthews James wrote: > This is what i need help on > > ##################################################### > # File: JacksRecords.py > > def print_slip(): > print '_______________________________' > print ' ',Name,', ',Date > print 'EMP # CAT IN' > print Empnum,' ',CAT,' ',FIRSTIN > print ' IN OUT' > print ' ',FIRSTIN,' ',FIRSTOUT > print ' IN' > print ' ',SECIN > print ' IN OUT' > print ' ',SECIN,' ',SECOUT > print '-------------------------------' Another way to do this is to change your print_slip() into a get_slip(): instead of having it print the slip out, you can write a function that returns a string: def get_slip(): return '''_______________________________ %s %s EMP # CAT IN' %s %s %s IN OUT %s %s IN %s IN OUT %s %s -------------------------------''' % (Name, Date, EmpNum, CAT, FIRSTIN, FIRSTIN, FIRSTOUT, SECIN, SECIN, SECOUT) For conciseness, we're using triple-quoted strings, which go on until we hit another set of triple quotes --- useful when we're building forms. Also, the function above does something really interesting called string interpolation: wherever you see '%s', it tries to fill in with an appropriate variable. (For more information on these two topics, take a look here:) http://python.org/doc/current/tut/node9.html#SECTION009100000000000000000 The reason this function is nice is because now it can be used in both file writing and in printing to the screen: print get_slip() some_file.write(get_slip()) can work with get_slip() equally well. It also "feels" less cluttered, although I know that's a subjective opinion. > I want to beable to save 'print_slip()' to a file > and then add more to that same file. Daniel Coughlin mentioned how to open files so that appending --- adding stuff to a file's end --- works out well. > I also want it to look like this when it saves the > file > _____________________________________________ > John Doe, 3/21/2001 > EMP # CAT IN > 4578 1 7:54 > IN OUT > 7:45 8:25 > IN > 8:55 > IN OUT > 8:55 23:54 > --------------------------------------------- You'll want to experiment with string interpolation: it gives you fine control over how many spaces something takes in. For example, here's a small interpreter session that gives a taste of what this means: ### >>> for i in range(10): ... print '%5s %5s %5s' % (i, i**2, i**3) ... 0 0 0 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 ### Instead of just putting '%s', now we have '%5s', which tells Python: "This will take at least 5 spaces worth of characters to print, so leave that much space for us to work with." If you fiddle around with this, you'll be able to get a nicely indented form. It's also mentioned in the URL: http://python.org/doc/current/tut/node9.html#SECTION009100000000000000000 around halfway through that page. (On the other hand you might consider having your program output something besides plain text: you can have it spit out HTML. Doing this will be nice, since HTML has table-formatting commands that should be easier to work with than counting spaces.) (Also, you might want to save your timestamps in two different ways: one that's easy for the computer to understand, and one that's easy for you to read. Although it might seem redundant, it might also be useful, if you ever want to write programs that study or search your time cards.) Good luck to you! From deirdre@deirdre.net Thu Mar 22 16:28:34 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 22 Mar 2001 08:28:34 -0800 (PST) Subject: [Tutor] User Groups In-Reply-To: <FF7B2B0D05@kserver.org> Message-ID: <Pine.LNX.4.31.0103220827520.14375-100000@emperor.deirdre.org> On Thu, 22 Mar 2001, Sheila King wrote: > I notice that the BayPiggies (San Francisco area Python User Group) is > quite active. I've been to the Python website, and searched a bit, but > don't find that there are many Python UGs around. Well, it has its moments. We've hosted Guido twice. > Is there one in the Southern California (esp. Los Angeles/Orange > County) area? Not as far as I know, but you're welcome to start one. :) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From van@lindbergs.org Thu Mar 22 21:11:49 2001 From: van@lindbergs.org (VanL) Date: Thu, 22 Mar 2001 14:11:49 -0700 Subject: [Tutor] Wrapping C++ in Python? Message-ID: <3ABA6A95.F68FFFAA@lindbergs.org> Hello all, I've got some C++ files (a very modest implementation of a an OpenGL-animated world) and I would like to wrap them in Python, so that I can script the actions of players in the world by using Python. Any pointers on where to start looking? Docs, etc? Thnx, VanL From kalle@gnupung.net Thu Mar 22 21:19:24 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 22 Mar 2001 22:19:24 +0100 Subject: [Tutor] Wrapping C++ in Python? In-Reply-To: <3ABA6A95.F68FFFAA@lindbergs.org>; from van@lindbergs.org on Thu, Mar 22, 2001 at 02:11:49PM -0700 References: <3ABA6A95.F68FFFAA@lindbergs.org> Message-ID: <20010322221924.B984@apone.network.loc> Sez VanL: > Hello all, > > I've got some C++ files (a very modest implementation of a an > OpenGL-animated world) and I would like to wrap them in Python, so > that I can script the actions of players in the world by using > Python. > > Any pointers on where to start looking? Docs, etc? I've heard that Boost Python is good. http://www.boost.org/libs/python/doc/index.html There is a tool called SIP, part of PyKDE. http://www.thekompany.com/projects/pykde/ And, of course, a look at the standard documentation is recommended, although I think the extending/embedding/api parts are a little weak. They are more geared towards C than C++, too. http://www.python.org/doc/current/ext/ http://www.python.org/doc/current/api/ Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From dsh8290@rit.edu Thu Mar 22 21:24:39 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 22 Mar 2001 16:24:39 -0500 Subject: [Tutor] bad formatting in MUA In-Reply-To: <3AB9E4A0.434FB6D8@mail.verizon.net>; from vze2f978@mail.verizon.net on Thu, Mar 22, 2001 at 06:40:16AM -0500 References: <E14fwsK-0008Ul-00@mail.python.org> <3AB9E4A0.434FB6D8@mail.verizon.net> Message-ID: <20010322162439.B8967@harmony.cs.rit.edu> Must be a netscape problem (not understanding the encoding, etc). I remember having seen that before, sometime while I used Netscape or Balsa. Now I use mutt. Are you running Windows or Linux? You can probably get prebuilt binaries of mutt for most *nix systems, I have a Win2k version I can send you if you want (it may work on other win* systems, I don't know). BTW, Debian is the best distro ;-). -D On Thu, Mar 22, 2001 at 06:40:16AM -0500, Lloyd Hugh Allen wrote: | Not to be offtopic, but is there a reason that 1/4 of the messages on | this group are littered with "=3D" and "=20"? Is there a convenient way | to filter these into regular equals signs and ?tabs? in Netscape (I | haven't made the Debian leap yet)? | | It seems to be a particular problem with messages that are multipart | MIME blah blah blah. Only bugs me when I'm wussy and read the plaintext | instead of the HTML. | | -LHA From iumarumo@eidosnet.co.uk Thu Mar 22 21:57:28 2001 From: iumarumo@eidosnet.co.uk (iumarumo@eidosnet.co.uk) Date: Thu, 22 Mar 2001 21:57:28 +0000 Subject: [Tutor] bad formatting in MUA In-Reply-To: <20010322162439.B8967@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Mar 22, 2001 at 04:24:39PM -0500 References: <E14fwsK-0008Ul-00@mail.python.org> <3AB9E4A0.434FB6D8@mail.verizon.net> <20010322162439.B8967@harmony.cs.rit.edu> Message-ID: <20010322215727.A1160@eidosnet.co.uk> On Thu, Mar 22, 2001 at 04:24:39PM -0500, D-Man wrote: > > Must be a netscape problem (not understanding the encoding, etc). I > remember having seen that before, sometime while I used Netscape or > Balsa. Now I use mutt. Are you running Windows or Linux? You can > probably get prebuilt binaries of mutt for most *nix systems, I have a > Win2k version I can send you if you want (it may work on other win* > systems, I don't know). > Mutt is an excellent MUA.... > BTW, Debian is the best distro ;-). > I agree with this statement - Debian is the "best" bar none! Kindest regards, --ibs. -- Software production is assumed to be a line function, but it is run like a staff function. -- Paul Licker From alan.gauld@bt.com Thu Mar 22 23:36:32 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 22 Mar 2001 23:36:32 -0000 Subject: [Tutor] Doesnt Work Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D662@mbtlipnt02.btlabs.bt.co.uk> > http://www.crosswinds.net/~agauld/ doesnt work. The server seemed to go down but it should be back now... Alan G. PS Note that the contact email address for questions on my tutor is changing to: agauld@crosswinds.net The old xoommail address is being discontinued by NBCi. From alan.gauld@bt.com Thu Mar 22 23:46:03 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 22 Mar 2001 23:46:03 -0000 Subject: [Tutor] I need help with saving to files Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D663@mbtlipnt02.btlabs.bt.co.uk> > first off, in your print_slip() you need to associate a > variable with a file: Or just get printslip to return a long string... then print that to a file. > formats. I think replacing > the commas with + should do the trick. (Otherwise, my > interpriter treats it as a > tuple rather than a string. Not quite sure why it chokes on that.) so > > print(Empnum,' ',CAT,' ',Firstin) You don't need the parens with print - its a command not a function. The patrens tell Python to treat it as a tuple. However a better general solution is to use format strings since these allow you to specify the filed widths. eg print "%7s\t%5s\t%20s" % (Empnum,CAT,Firstin) Will force Empnum to be 7 spaces etc. This should make sure your formatting is consistent. You can even assign the format string to a variable so that all the lines are the same and modifications only need to be done once: format = "%7s\t%5s\t%20s" print format % (Empnum,CAT,Firstin) OR file.write(format % (Emp,CAT,First) etc... Alan G From sarnold@earthling.net Fri Mar 23 03:06:32 2001 From: sarnold@earthling.net (Stephen L Arnold) Date: Thu, 22 Mar 2001 19:06:32 -0800 Subject: [Tutor] Wrapping C++ in Python? In-Reply-To: <20010322221924.B984@apone.network.loc> References: <3ABA6A95.F68FFFAA@lindbergs.org>; from van@lindbergs.org on Thu, Mar 22, 2001 at 02:11:49PM -0700 Message-ID: <20010323030633.6BDB41F661@shiva.arnolds.bogus> On 22 Mar 01, at 22:19, Kalle Svensson wrote: > Sez VanL: > > Hello all, > > > > I've got some C++ files (a very modest implementation of a an > > OpenGL-animated world) and I would like to wrap them in Python, so > > that I can script the actions of players in the world by using > > Python. > > > > Any pointers on where to start looking? Docs, etc? > > I've heard that Boost Python is good. > http://www.boost.org/libs/python/doc/index.html > > There is a tool called SIP, part of PyKDE. > http://www.thekompany.com/projects/pykde/ [snip] I think the one you want to try first is SWIG: http://www.swig.org The others are SIP, SILOON, and py_cpp. I can't tell you much more than that (no personal experience) but what I did say is fresh from the Python conference two weeks ago. I highly recommend the Python conference (it's the best nerd gathering I've ever been to). If you can swing the next one, go (you'll be glad you did). Steve ************************************************************* Steve Arnold sarnold@arnolds.dhs.org Assoc. Faculty, Dept of Geography, Allan Hancock College http://arnolds.dhs.org/geography.html Linux: It's not just for nerds anymore... From syrinx@simplecom.net Fri Mar 23 03:42:20 2001 From: syrinx@simplecom.net (Scott) Date: Thu, 22 Mar 2001 21:42:20 -0600 Subject: [Tutor] converting list to string Message-ID: <73hlbt0gi2mv3e8tpi7fj04jhrp6jkl3fk@4ax.com> Please forgive this question, but, I thought this: x =3D ['h', 'e', 'l', 'l', 'o'] print str(x) would print: hello instead I get ['h', 'e', 'l', 'l', 'o'] What am I doing wrong? I realize it's a silly question, but these immutable strings just aren't being kind to me. :-( What's the correct way to get a string from a list? Thanks. From bdupire@seatech.fau.edu Fri Mar 23 03:52:51 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 22 Mar 2001 22:52:51 -0500 Subject: [Tutor] converting list to string References: <73hlbt0gi2mv3e8tpi7fj04jhrp6jkl3fk@4ax.com> Message-ID: <3ABAC893.98EFD@seatech.fau.edu> Scott wrote: > Please forgive this question, but, I thought this: > > x = ['h', 'e', 'l', 'l', 'o'] > print str(x) > > would print: > > hello > > instead I get > > ['h', 'e', 'l', 'l', 'o'] > > What am I doing wrong? I realize it's a silly question, but these > immutable strings just aren't being kind to me. :-( > > What's the correct way to get a string from a list? Thanks. > like this >>> x = ['h', 'e', 'l', 'l', 'o'] >>>import operator >>>a=reduce(operator.add, x) >>> a 'hello' >>> From joejava@dragoncat.net Fri Mar 23 03:54:17 2001 From: joejava@dragoncat.net (JRicker) Date: Thu, 22 Mar 2001 22:54:17 -0500 Subject: [Tutor] Sockets -- huh? Message-ID: <001301c0b34c$f36a72e0$de814cd8@ceo> Decided to learn about sockets and python. The object of my desire so to speak would be a helper program for a game called Tradewars. Used to be played on alot of BBSs back when they were more prevalent and now several servers are running it. I'm trying to telnet in if that makes a difference. I started small and simple: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("216.211.84.44", 23)) except Exception, e: print e s.send("\n\n") # this line was added after the rest, hoping to get a response. test = s.recv(1024) s.close() print test but test isn't printing anything out. I'm expecting to get at least: Telnet connection detected. Please enter your name (ENTER for none): I know that at least a connection is being made because while my script was running, I tried logging in with telnet. The server only allows one connection from any one IP address and it denied me entrance until the script finished running. Any thoughts? Thanks Joel ----------------------------------- Nomopoly III now open. Join Today! http://www.justthefaqs.org/nomopoly/ From rick@niof.net Fri Mar 23 04:07:26 2001 From: rick@niof.net (Rick Pasotto) Date: Thu, 22 Mar 2001 23:07:26 -0500 Subject: [Tutor] converting list to string In-Reply-To: <3ABAC893.98EFD@seatech.fau.edu>; from bdupire@seatech.fau.edu on Thu, Mar 22, 2001 at 10:52:51PM -0500 References: <73hlbt0gi2mv3e8tpi7fj04jhrp6jkl3fk@4ax.com> <3ABAC893.98EFD@seatech.fau.edu> Message-ID: <20010322230726.A9292@tc.niof.net> On Thu, Mar 22, 2001 at 10:52:51PM -0500, Benoit Dupire wrote: > > Scott wrote: > > > Please forgive this question, but, I thought this: > > > > x = ['h', 'e', 'l', 'l', 'o'] > > print str(x) > > > > would print: > > > > hello > > > > instead I get > > > > ['h', 'e', 'l', 'l', 'o'] > > > > What am I doing wrong? I realize it's a silly question, but these > > immutable strings just aren't being kind to me. :-( > > > > What's the correct way to get a string from a list? Thanks. > > > > like this > >>> x = ['h', 'e', 'l', 'l', 'o'] > >>>import operator > >>>a=reduce(operator.add, x) > >>> a > 'hello' > >>> Gosh! Just like that other language "there's more than one way to do it." >>> x=['h','e','l','l','o'] >>> import string >>> a=string.join(x,'') >>> a 'hello' >>> -- "FIJA is not a double-edged sword --- it is a shield against the sword of government." --- Tom Glass Rick Pasotto email: rickp@telocity.com From dyoo@hkn.eecs.berkeley.edu Fri Mar 23 04:18:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 22 Mar 2001 20:18:43 -0800 (PST) Subject: [Tutor] Wrapping C++ in Python? In-Reply-To: <20010322221924.B984@apone.network.loc> Message-ID: <Pine.LNX.4.21.0103222014280.5564-100000@hkn.eecs.berkeley.edu> On Thu, 22 Mar 2001, Kalle Svensson wrote: > > I've got some C++ files (a very modest implementation of a an > > OpenGL-animated world) and I would like to wrap them in Python, so > > that I can script the actions of players in the world by using > > Python. > > > > Any pointers on where to start looking? Docs, etc? > > I've heard that Boost Python is good. > http://www.boost.org/libs/python/doc/index.html > > There is a tool called SIP, part of PyKDE. > http://www.thekompany.com/projects/pykde/ > > And, of course, a look at the standard documentation is recommended, > although I think the extending/embedding/api parts are a little weak. > They are more geared towards C than C++, too. > http://www.python.org/doc/current/ext/ > http://www.python.org/doc/current/api/ A few more links to recommend: http://www.swig.org/ SWIG is supposed to make it easy to write wrappers for Python (and for many other scripting languages too!) I've played around with it once, and found it pretty neat. Also, if you're doing OpenGL stuff, you might be interested in: http://pyopengl.sourceforge.net/ Anyway, good luck to you. From doug@nsacom.net Fri Mar 23 06:59:47 2001 From: doug@nsacom.net (doug@nsacom.net) Date: Thu, 22 Mar 2001 22:59:47 -0800 (PST) Subject: [Tutor] PyGreSQL compiliation difficulties Message-ID: <200103230659.f2N6xfr10221@pop.nsacom.net> I got the PyGreSQL module from druid.net and have attempted to build it into my Python interpreter. It appears that PyGreSQL was written for Python 1.5 and it's installation instructions seem to be somewhat different from the realities of my particular setup. The installation instructions in README.linux instruct me to: __________________________________________________ BUILT-IN TO PYTHON INTERPRETER * Find the directory where your 'Setup' file lives (usually ??/Modules) in the Python source hierarchy and copy or symlink the 'pgmodule.c' file there. * Add the following line to your Setup file _pg pgmodule.c -I[pgInc] -L[pgLib] -lpq # -lcrypt # needed on some systems where: [pgInc] = path of PostgreSQL include (often /usr/local/include/python1.5) [pgLib] = path of the PostgreSQL libraries (often /usr/local/lib/python1.5) ___________________________________________________ My first confusion is: Why is it looking for the PostGreSQL inclue and libraries in /usr/local/lib/python.x? Undaunted by fear I included the line: _pg pgmodule.c -I /usr/local/include/python2.0 -L /usr/local/lib/python2.0 - lpq -lcrypt which promptly craps with: bad word /usr/local/lib/python2.0 in _pg pgmodule.c - I /usr/local/include/python2.0 -L /usr/local/lib/python2.0 -lpq -lcrypt which made me say bad words. So I got to thinking (O!) Perhaps the instructions contained a typo and it actually wants the path to the PostGreSQL includes etc. ...So: _pg pgmodule.c -I /usr/local/pgsql/include/ -L /usr/local/pgsql/lib/cd - lpq -lcrypt which gave me the same error. Then I really got to wondering: Isn't all this mapping out of include files done for us by the deep, unfathomable majick of ./configure? so I tried the vanilla approach: _pg pgmodule.c -lpq -lcrypt Which seemed to be percolating along nicely until: ./pgmodule.c:30: libpq-fe.h: No such file or directory I do indeed have libpq installed as part of postgres: /usr/local/postgres/libpq-fe.h Obviously it is crapping out because I don't have the path included that causes it to crap out. ;-) So what am I missing? I am building this on Slackware 7.0. Python and Postgres have built and functioned just fine thereupon. Is there a way to include the pgmodule.c and it's attendant files in ./configure? (I am sure this is where part of the answer lies...) Python needs to know where the pgsql libraries are when it builds and it needs to know to build the pygres module... now I need to know how to tell configure! Thanks folks From syrinx@simplecom.net Fri Mar 23 06:36:04 2001 From: syrinx@simplecom.net (Scott) Date: Fri, 23 Mar 2001 00:36:04 -0600 Subject: [Tutor] mutable strings? Message-ID: <nirlbtoour38qbcc36kg3ku2tur3d5a93m@4ax.com> What is the procedure to use if you want a couple of global, mutable, string-like objects? TIA From smoralis@aias.gr Fri Mar 23 08:01:40 2001 From: smoralis@aias.gr (smoralis@aias.gr) Date: Fri, 23 Mar 2001 10:01:40 +0200 Subject: [Tutor] Hey, there is a newbie! Message-ID: <20010323080140.FPIX17140.iridium1@[172.31.10.20]> I am very new in computer programming (actually I couldn't be newer!). I would like know about sites for elementary programmers. From cooler12001@yahoo.com Fri Mar 23 11:19:46 2001 From: cooler12001@yahoo.com (Matthews James) Date: Fri, 23 Mar 2001 03:19:46 -0800 (PST) Subject: [Tutor] Need help with saving files to a specific folder... Message-ID: <20010323111946.86301.qmail@web11404.mail.yahoo.com> I need help with saving a file to a specific folder like this: ####################################################### List = [] def save_list(numbers,filename): out_file = open(filename,'w') out_file.write(get_slip()) out_file.close() def get_slip(): return ''' ___________________________ %s %s EMP # CAT IN OUT %s %s %s %s IN OUT %s %s ------------------------------------------ ''' % (Name, Date, Empnum, CAT, FIRSTIN, FIRSTOUT, SECIN, SECOUT) Name = raw_input("What is the employees name: ") Date = raw_input("What is the Date: ") Empnum = input("What is the Employees Number: ") CAT = input("What is the CAT number: ") FIRSTIN = raw_input("What time did (he, she) come in: ") FIRSTOUT = raw_input("What time did (he, she) go on break: ") SECIN = raw_input("What time did (he, she) come in from break: ") SECOUT = raw_input("What time did (he, she) clock out to go home: ") print get_slip filename = raw_input('What do you want to call the file: ') save_list(List,filename+'.txt') ###################################################### I am want to save the file to a folder called Times so that my program will be organized instead of clumped up all in one place. This is the setup that i want: MainFolder program dlls SubFolder saved files I cant figure out how to do this __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From arcege@shore.net Fri Mar 23 12:43:24 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 23 Mar 2001 07:43:24 -0500 (EST) Subject: [Tutor] Need help with saving files to a specific folder... In-Reply-To: <no.id> from "Matthews James" at Mar 23, 2001 03:19:46 AM Message-ID: <E14gQua-0004Oa-00@nautilus.shore.net> > I need help with saving a file to a specific folder > like this: > ####################################################### > List = [] > > def save_list(numbers,filename): > out_file = open(filename,'w') > out_file.write(get_slip()) > out_file.close() > > def get_slip(): > return ''' > ___________________________ > %s %s > EMP # CAT IN OUT > %s %s %s %s > IN OUT > %s %s > ------------------------------------------ > ''' % (Name, Date, Empnum, CAT, FIRSTIN, FIRSTOUT, > SECIN, SECOUT) > > Name = raw_input("What is the employees name: ") > Date = raw_input("What is the Date: ") > Empnum = input("What is the Employees Number: ") > CAT = input("What is the CAT number: ") > FIRSTIN = raw_input("What time did (he, she) come in: > ") > FIRSTOUT = raw_input("What time did (he, she) go on > break: ") > SECIN = raw_input("What time did (he, she) come in > from break: ") > SECOUT = raw_input("What time did (he, she) clock out > to go home: ") > > print get_slip > filename = raw_input('What do you want to call the > file: ') > save_list(List,filename+'.txt') > ###################################################### > I am want to save the file to a folder called > Times so that my program will be organized instead > of clumped up all in one place. > > This is the setup that i want: > MainFolder > program > dlls > SubFolder > saved files > > I cant figure out how to do this There are routines in the os.path module to allow you to manipulate pathnames for your platform. Specifically you want the os.path.join() function: save_list(List, os.path.join('Times', filename + '.txt')) And to make sure the directory exists before you attempt to write there: if not os.path.isdir('Times'): os.mkdir('Times') -Arcege References: Python Library Reference, sec 6.2 os.path -- Common pathname manipulations http://www.python.org/doc/current/lib/module-os.path.html -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From charlie@webmind.com Fri Mar 23 12:57:27 2001 From: charlie@webmind.com (Charlie Derr) Date: Fri, 23 Mar 2001 07:57:27 -0500 Subject: [Tutor] PyGreSQL compiliation difficulties In-Reply-To: <200103230659.f2N6xfr10221@pop.nsacom.net> Message-ID: <LOBBJCAMDNLNCGCCHGEIAEIHKCAA.charlie@webmind.com> I think what you are missing is the correct syntax. I would guess that you are right about the typo in the instructions. Try the command without a space between the -I and the path, ie. -I//usr/local/pgsql/include/ hth, ~c ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ doug@nsacom.net ~ Sent: Friday, March 23, 2001 2:00 AM ~ To: tutor@python.org ~ Subject: [Tutor] PyGreSQL compiliation difficulties ~ ~ ~ I got the PyGreSQL module from druid.net and have attempted to ~ build it into ~ my Python interpreter. It appears that PyGreSQL was written for ~ Python 1.5 ~ and it's installation instructions seem to be somewhat different from the ~ realities of my particular setup. ~ ~ The installation instructions in README.linux instruct me to: ~ __________________________________________________ ~ ~ BUILT-IN TO PYTHON INTERPRETER ~ ~ * Find the directory where your 'Setup' file lives (usually ~ ??/Modules) in ~ the Python source hierarchy and copy or symlink the ~ 'pgmodule.c' file there. ~ ~ * Add the following line to your Setup file ~ _pg pgmodule.c -I[pgInc] -L[pgLib] -lpq # -lcrypt # needed on some ~ systems ~ where: ~ [pgInc] = path of PostgreSQL include (often ~ /usr/local/include/python1.5) ~ [pgLib] = path of the PostgreSQL libraries ~ (often /usr/local/lib/python1.5) ~ ~ ___________________________________________________ ~ ~ My first confusion is: Why is it looking for the PostGreSQL inclue and ~ libraries in /usr/local/lib/python.x? ~ ~ Undaunted by fear I included the line: ~ ~ _pg pgmodule.c -I /usr/local/include/python2.0 -L ~ /usr/local/lib/python2.0 - ~ lpq -lcrypt ~ ~ which promptly craps with: ~ ~ bad word /usr/local/lib/python2.0 in _pg pgmodule.c - ~ I /usr/local/include/python2.0 -L /usr/local/lib/python2.0 -lpq -lcrypt ~ ~ which made me say bad words. ~ ~ So I got to thinking (O!) Perhaps the instructions contained a ~ typo and it ~ actually wants the path to the PostGreSQL includes etc. ...So: ~ ~ _pg pgmodule.c -I /usr/local/pgsql/include/ -L /usr/local/pgsql/lib/cd - ~ lpq -lcrypt ~ ~ which gave me the same error. ~ ~ Then I really got to wondering: Isn't all this mapping out of ~ include files ~ done for us by the deep, unfathomable majick of ./configure? ~ ~ so I tried the vanilla approach: ~ ~ _pg pgmodule.c -lpq -lcrypt ~ ~ Which seemed to be percolating along nicely until: ~ ~ ./pgmodule.c:30: libpq-fe.h: No such file or directory ~ ~ I do indeed have libpq installed as part of ~ postgres: /usr/local/postgres/libpq-fe.h ~ ~ Obviously it is crapping out because I don't have the path included that ~ causes it to crap out. ;-) ~ ~ ~ So what am I missing? I am building this on Slackware 7.0. Python and ~ Postgres have built and functioned just fine thereupon. Is there a way to ~ include the pgmodule.c and it's attendant files in ./configure? ~ (I am sure ~ this is where part of the answer lies...) Python needs to know where the ~ pgsql libraries are when it builds and it needs to know to build ~ the pygres ~ module... now I need to know how to tell configure! ~ ~ Thanks folks ~ ~ ~ ~ ~ ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor ~ From charlie@webmind.com Fri Mar 23 13:21:51 2001 From: charlie@webmind.com (Charlie Derr) Date: Fri, 23 Mar 2001 08:21:51 -0500 Subject: [Tutor] PyGreSQL compiliation difficulties In-Reply-To: <LOBBJCAMDNLNCGCCHGEIAEIHKCAA.charlie@webmind.com> Message-ID: <LOBBJCAMDNLNCGCCHGEIKEIIKCAA.charlie@webmind.com> Argh. The example wasn't supposed to have two slashes in a row like that. What you want is to do it this way: -I/usr/local/pgsql/include/ sorry about any confusion, ~c ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ Charlie Derr ~ Sent: Friday, March 23, 2001 7:57 AM ~ To: doug@nsacom.net; tutor@python.org ~ Subject: RE: [Tutor] PyGreSQL compiliation difficulties ~ ~ ~ I think what you are missing is the correct syntax. I would ~ guess that you ~ are right about the typo in the instructions. Try the command without a ~ space between the -I and the path, ie. ~ ~ -I//usr/local/pgsql/include/ ~ ~ hth, ~ ~c ~ ~ ~ -----Original Message----- ~ ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ ~ doug@nsacom.net ~ ~ Sent: Friday, March 23, 2001 2:00 AM ~ ~ To: tutor@python.org ~ ~ Subject: [Tutor] PyGreSQL compiliation difficulties ~ ~ ~ ~ ~ ~ I got the PyGreSQL module from druid.net and have attempted to ~ ~ build it into ~ ~ my Python interpreter. It appears that PyGreSQL was written for ~ ~ Python 1.5 ~ ~ and it's installation instructions seem to be somewhat ~ different from the ~ ~ realities of my particular setup. ~ ~ ~ ~ The installation instructions in README.linux instruct me to: ~ ~ __________________________________________________ ~ ~ ~ ~ BUILT-IN TO PYTHON INTERPRETER ~ ~ ~ ~ * Find the directory where your 'Setup' file lives (usually ~ ~ ??/Modules) in ~ ~ the Python source hierarchy and copy or symlink the ~ ~ 'pgmodule.c' file there. ~ ~ ~ ~ * Add the following line to your Setup file ~ ~ _pg pgmodule.c -I[pgInc] -L[pgLib] -lpq # -lcrypt # needed on some ~ ~ systems ~ ~ where: ~ ~ [pgInc] = path of PostgreSQL include (often ~ ~ /usr/local/include/python1.5) ~ ~ [pgLib] = path of the PostgreSQL libraries ~ ~ (often /usr/local/lib/python1.5) ~ ~ ~ ~ ___________________________________________________ ~ ~ ~ ~ My first confusion is: Why is it looking for the PostGreSQL inclue and ~ ~ libraries in /usr/local/lib/python.x? ~ ~ ~ ~ Undaunted by fear I included the line: ~ ~ ~ ~ _pg pgmodule.c -I /usr/local/include/python2.0 -L ~ ~ /usr/local/lib/python2.0 - ~ ~ lpq -lcrypt ~ ~ ~ ~ which promptly craps with: ~ ~ ~ ~ bad word /usr/local/lib/python2.0 in _pg pgmodule.c - ~ ~ I /usr/local/include/python2.0 -L /usr/local/lib/python2.0 -lpq -lcrypt ~ ~ ~ ~ which made me say bad words. ~ ~ ~ ~ So I got to thinking (O!) Perhaps the instructions contained a ~ ~ typo and it ~ ~ actually wants the path to the PostGreSQL includes etc. ...So: ~ ~ ~ ~ _pg pgmodule.c -I /usr/local/pgsql/include/ -L ~ /usr/local/pgsql/lib/cd - ~ ~ lpq -lcrypt ~ ~ ~ ~ which gave me the same error. ~ ~ ~ ~ Then I really got to wondering: Isn't all this mapping out of ~ ~ include files ~ ~ done for us by the deep, unfathomable majick of ./configure? ~ ~ ~ ~ so I tried the vanilla approach: ~ ~ ~ ~ _pg pgmodule.c -lpq -lcrypt ~ ~ ~ ~ Which seemed to be percolating along nicely until: ~ ~ ~ ~ ./pgmodule.c:30: libpq-fe.h: No such file or directory ~ ~ ~ ~ I do indeed have libpq installed as part of ~ ~ postgres: /usr/local/postgres/libpq-fe.h ~ ~ ~ ~ Obviously it is crapping out because I don't have the path included that ~ ~ causes it to crap out. ;-) ~ ~ ~ ~ ~ ~ So what am I missing? I am building this on Slackware 7.0. Python and ~ ~ Postgres have built and functioned just fine thereupon. Is ~ there a way to ~ ~ include the pgmodule.c and it's attendant files in ./configure? ~ ~ (I am sure ~ ~ this is where part of the answer lies...) Python needs to know where the ~ ~ pgsql libraries are when it builds and it needs to know to build ~ ~ the pygres ~ ~ module... now I need to know how to tell configure! ~ ~ ~ ~ Thanks folks ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ _______________________________________________ ~ ~ Tutor maillist - Tutor@python.org ~ ~ http://mail.python.org/mailman/listinfo/tutor ~ ~ ~ ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Fri Mar 23 15:49:22 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 23 Mar 2001 07:49:22 -0800 (PST) Subject: [Tutor] Hey, there is a newbie! In-Reply-To: <20010323080140.FPIX17140.iridium1@[172.31.10.20]> Message-ID: <Pine.LNX.4.21.0103230740350.20609-100000@hkn.eecs.berkeley.edu> On Fri, 23 Mar 2001 smoralis@aias.gr wrote: > I am very new in computer programming (actually I couldn't be newer!). > I would like know about sites for elementary programmers. Welcome! Alan Gauld's tutorial on how to learn programming is very good: http://www.crosswinds.net/~agauld/ It starts from the very beginning, up to object oriented programming. I highly recommend it, not just because it's good, but because the author frequently posts here. *grin* There are a bunch of other introductions here: http://www.python.or/doc/Intros.html but as you'd expect, it's just slightly Python-centric. Personally, I don't think that's a bad thing, but if you want another view, there's another site called TeachScheme which is also very nice: http://www.cs.rice.edu/CS/PLT/Teaching/ Instead of using Python, the TeachScheme people use the Scheme language to do problem solving; it's also a fun language to learn. The choice depends on what you want to learn, so explore a little, and see what you enjoy. If you have any questions, please feel free to ask us. From sburr@home.com Fri Mar 23 15:52:15 2001 From: sburr@home.com (Steven Burr) Date: Fri, 23 Mar 2001 08:52:15 -0700 Subject: [Tutor] converting list to string Message-ID: <20010323155215.UFEH4355.mail1.rdc1.az.home.com@localhost> On Thursday, March 22, 2001, at 08:52 PM, Benoit Dupire wrote: > Scott wrote:=20 > =20 > > Please forgive this question, but, I thought this:=20 > >=20 > > x =3D ['h', 'e', 'l', 'l', 'o']=20 > > print str(x)=20 > >=20 > > would print:=20 > >=20 > > hello=20 > >=20 > > instead I get=20 > >=20 > > ['h', 'e', 'l', 'l', 'o']=20 > >=20 > > What am I doing wrong? I realize it's a silly question, but these=20= > > immutable strings just aren't being kind to me. :-(=20 > >=20 > > What's the correct way to get a string from a list? Thanks.=20 > >=20 > =20 > like this=20 > >>> x =3D ['h', 'e', 'l', 'l', 'o']=20 > >>>import operator=20 > >>>a=3Dreduce(operator.add, x)=20 > >>> a=20 > 'hello'=20 > >>>=20 Or like this: >>> x =3D ['h', 'e', 'l', 'l', 'o']=0D>>> x =3D ''.join(x)=0D>>> print x=0D= hello=0D Where '' is an empty string. If like some people you have an aversion to the <string = literal>.join(<list>) syntax,=20 you can substitute: >>> import string=0D>>> x =3D string.join(x, '')= From dyoo@hkn.eecs.berkeley.edu Fri Mar 23 16:08:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 23 Mar 2001 08:08:42 -0800 (PST) Subject: [Tutor] mutable strings? [and global stuff] In-Reply-To: <nirlbtoour38qbcc36kg3ku2tur3d5a93m@4ax.com> Message-ID: <Pine.LNX.4.21.0103230755080.20609-100000@hkn.eecs.berkeley.edu> On Fri, 23 Mar 2001, Scott wrote: > What is the procedure to use if you want a couple of global, mutable, > string-like objects? Strings are immutable, but from your previous post, it looks like you've found out about using mutable lists; that's one way of doing it. Could you tell us the context of the program you're writing, or is your question just to explore? About global stuff... there's some pitfalls that we need to talk about: Any variable defined outside of a function definition is global, and any variable defined inside is local. Simple enough, but you'll run into a few snags here and there: ### myglobal = 'a' def test(): print myglobal ### This works as you might expect, but: ### myglobal = 'a' def test(): print myglobal myglobal = 'z' print myglobal ### does _not_ work; the reason is because, within test(), Python senses that we're doing an assignment of 'myglobal', so it thinks that it must be a local variable. (You'll run into one of the weirder error messages that myglobal isn't defined with test()!) Most python programs want local-scope, which is why you'll run into some problems when dealing with globals. What we need to do is label 'myglobal' as a global: ### myglobal = 'a' def test(): global myglobal print myglobal myglobal = 'z' print myglobal ### What was that term for the phenomena that happens when you say a word over and over, till it loses its meaning? Global global global global global. Sorry about that. *grin* (Personally, I try to avoid globals as much as possible, so that's why I'm a little hesitant --- I haven't concienciously made a global variable for a while. *grin*) From dsh8290@rit.edu Fri Mar 23 17:03:11 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 23 Mar 2001 12:03:11 -0500 Subject: [Tutor] Sockets -- huh? In-Reply-To: <001301c0b34c$f36a72e0$de814cd8@ceo>; from joejava@dragoncat.net on Thu, Mar 22, 2001 at 10:54:17PM -0500 References: <001301c0b34c$f36a72e0$de814cd8@ceo> Message-ID: <20010323120311.A11168@harmony.cs.rit.edu> Have you tried telnetlib? >>> import telnetlib >>> conn = telnetlib.Telnet() >>> conn.open( "harmony.cs.rit.edu" ) >>> print conn.read_until( "login:" , 10 ) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! -- Department of Computer Science at RIT -- !! !! !! !! All activity may be logged or monitored. Unauthorized connections !! !! are prohibited. Disconnect immediately if you object to this policy. !! !! !! !! As of June 2001 telnet will no longer be available. Please use ssh. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! harmony.cs.rit.edu login: >>> I tried with the ip address you gave, it worked for plain telnet (ie, the 'telnet' program that is part of windows or cygwin (I don't know which is first in path)). When I tried using python, sometimes I got various other messages at different times: Failed to detect protocol... Telnet connection detected. Only one connection is allowed for a single IP address. HTH, -D On Thu, Mar 22, 2001 at 10:54:17PM -0500, JRicker wrote: | Decided to learn about sockets and python. The object of my desire so | to speak would be a helper program for a game called Tradewars. Used to | be played on alot of BBSs back when they were more prevalent and now | several servers are running it. I'm trying to telnet in if that makes a | difference. I started small and simple: | | import socket | | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | try: | s.connect(("216.211.84.44", 23)) | except Exception, e: print e | | s.send("\n\n") # this line was added after the rest, hoping to get a | response. | | test = s.recv(1024) | s.close() | print test | | but test isn't printing anything out. I'm expecting to get at least: | | Telnet connection detected. | | Please enter your name (ENTER for none): | | I know that at least a connection is being made because while my script | was running, I tried logging in with telnet. The server only allows one | connection from any one IP address and it denied me entrance until the | script finished running. | | Any thoughts? | | Thanks | Joel From syrinx@simplecom.net Fri Mar 23 17:37:59 2001 From: syrinx@simplecom.net (Scott) Date: Fri, 23 Mar 2001 11:37:59 -0600 Subject: [Tutor] mutable strings? [and global stuff] In-Reply-To: <Pine.LNX.4.21.0103230755080.20609-100000@hkn.eecs.berkeley.edu> References: <nirlbtoour38qbcc36kg3ku2tur3d5a93m@4ax.com> <Pine.LNX.4.21.0103230755080.20609-100000@hkn.eecs.berkeley.edu> Message-ID: <c52nbtk38ls3caic97kovs0sjthqr7j1kb@4ax.com> >Strings are immutable, but from your previous post, it looks like you've >found out about using mutable lists; that's one way of doing it. Could >you tell us the context of the program you're writing, or is your = question >just to explore? Mainly just an effort to learn the language. But having little patience for "Hello, world" programs, I'm trying to make something semi-useful in the process. I'm trying to write a little script to use for interactively renaming files, ie. tidying up mp3 names. I want to be able to navigate through my file system, and I need some type of changeable string, so I can keep track of where I am. I'm using Linux, if it makes any difference. Thank you. From arcege@shore.net Fri Mar 23 19:48:33 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 23 Mar 2001 14:48:33 -0500 (EST) Subject: [Tutor] Aversion to features (was: converting list to string) In-Reply-To: <20010323155215.UFEH4355.mail1.rdc1.az.home.com@localhost> from "Steven Burr" at Mar 23, 2001 08:52:15 AM Message-ID: <E14gXY1-0006FF-00@nautilus.shore.net> > If like some people you have an aversion to the <string = > literal>.join(<list>) syntax,=20 > you can substitute: > > >>> import string=0D>>> x =3D string.join(x, '')= It is not an aversion for some people, it is reality. String methods is a feature that is only one release old, and at that, only six months old. It is very likely that 90% of the interpreters out there are going to be Python 1.5.2 and un-upgradable and will be for the next six months; and as we found out here in this list, some people are still using Python 1.4 (1.5.2 came out about two years ago, 1.5 about a year before that). Using compatible techniques won't confuse the newbies here; show the new and the reality. As people move from 1.5 to 2.0, they will know both. If in doubt, use the idioms that have been in the community since the beginning. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From wesc@deirdre.org Fri Mar 23 20:18:45 2001 From: wesc@deirdre.org (Wesley Chun) Date: Fri, 23 Mar 2001 12:18:45 -0800 (PST) Subject: [Tutor] Hey, there is a newbie! In-Reply-To: <Pine.LNX.4.21.0103230740350.20609-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.31.0103231215570.30697-100000@emperor.deirdre.org> don't forget about "How to Think like a Computer Scientist" which introduces programming concepts. you choose the language, there's one in C++, Java, and now one in Python. all versions are accessible here: http://www.ibiblio.org/obp/ good luck! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, December 2000 http://starship.python.net/crew/wesc/cpp/ wesley.j.chun :: wesc@baypiggies.org cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ On Fri, 23 Mar 2001, Daniel Yoo wrote: > On Fri, 23 Mar 2001 smoralis@aias.gr wrote: > > > I am very new in computer programming (actually I couldn't be newer!). > > I would like know about sites for elementary programmers. > > Alan Gauld's tutorial on how to learn programming is very good: > > http://www.crosswinds.net/~agauld/ > > It starts from the very beginning, up to object oriented programming. I > highly recommend it, not just because it's good, but because the author > frequently posts here. *grin* > > > There are a bunch of other introductions here: > > http://www.python.or/doc/Intros.html > > but as you'd expect, it's just slightly Python-centric. Personally, I > don't think that's a bad thing, but if you want another view, there's > another site called TeachScheme which is also very nice: > > http://www.cs.rice.edu/CS/PLT/Teaching/ > > Instead of using Python, the TeachScheme people use the Scheme language to > do problem solving; it's also a fun language to learn. The choice depends > on what you want to learn, so explore a little, and see what you enjoy. > If you have any questions, please feel free to ask us. From dyoo@hkn.eecs.berkeley.edu Fri Mar 23 21:44:48 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 23 Mar 2001 13:44:48 -0800 (PST) Subject: [Tutor] clock program critique In-Reply-To: <OE265BBBVhyemYewQ1N000034b0@hotmail.com> Message-ID: <Pine.LNX.4.21.0103231333030.29639-100000@hkn.eecs.berkeley.edu> On Wed, 21 Mar 2001, Charles Gruschow, Jr. wrote: > I think I got a final version of a clock program, it is in this post. Hiya Charles, I'll take a look at your program this weekend; from an initial glance, I think there are a few things you can do to make it a lot shorter. For example, there's a lot of fragments that repeat other parts: > if self.time3==60: > self.time3=0 > self.time2=self.time2+1 > if self.time2==60: > self.time2=0 > self.time1=self.time1+1 > if self.time1==24: > self.time1=0 It's true that it works, but there's probably an easier way to write it. For example, if you write a function to do this trickling-time calculation, you'll only need to write this functionality once, instead of have rewritten throughout your program. Also, there's a lot of classes that you've written that take care of displaying different times. I think that it's possible to write one class that unifies all of them into one general case, but I'll have to look at your program in detail to see where generalization will work. In the meantime, take a look at your program and see if there are places where you can make things shorter. Talk to you later! From XtreemGamer@aol.com Sat Mar 24 02:33:43 2001 From: XtreemGamer@aol.com (XtreemGamer@aol.com) Date: Fri, 23 Mar 2001 21:33:43 EST Subject: [Tutor] Hello... Message-ID: <e1.12159b66.27ed6187@aol.com> --part1_e1.12159b66.27ed6187_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hello I was woundering how to make an entry feild work as a prompt variable to store data witch effects a label or a message or something witch is called after the Entry feild has been entered?(Tkinter question incase you didn't know) thx,and goodbye, -~-X-t-r-e-e-m-G-a-m-e-r-~- --part1_e1.12159b66.27ed6187_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit <HTML><FONT FACE=arial,helvetica><BODY BGCOLOR="#ff8000"><FONT COLOR="#000080" SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0"><B>Hello I was woundering how to make an entry feild work as a prompt variable <BR>to store data witch effects a label or a message or something witch is called <BR>after the Entry feild has been entered?(Tkinter question incase you didn't <BR>know) <BR> <BR>thx,and goodbye, <BR> <BR> <BR> <BR></FONT></FONT><FONT COLOR="#ff0000" SIZE=4 FACE="Calligrapher" LANG="0"><U>-~-X-t-r-e-e-m-G-a-m-e-r-~-</B></U></FONT></HTML> --part1_e1.12159b66.27ed6187_boundary-- From joejava@dragoncat.net Sat Mar 24 05:18:37 2001 From: joejava@dragoncat.net (JRicker) Date: Sat, 24 Mar 2001 00:18:37 -0500 Subject: [Tutor] Sockets -- huh? References: <001301c0b34c$f36a72e0$de814cd8@ceo> <20010323120311.A11168@harmony.cs.rit.edu> Message-ID: <001d01c0b421$e4c04460$60a1d6d1@ceo> : Have you tried telnetlib? No I didn't. My reference has been Python Essential Reference, written for 1.5 and it said telnetlib was undocumented. I figured sockets was a replacement. Though telnetlib will be much better for my needs, any reason why sockets wouldn't work? Joel From J Fri Mar 23 23:29:26 2001 From: J (J) Date: Fri, 23 Mar 2001 23:29:26 Subject: [Tutor] Grow a Money Tree From Home! Message-ID: <E14gga3-0004T7-00@mail.python.org> Dear Friends & Future Millionaire: AS SEEN ON NATIONAL TV: Making over half million dollars every 4 to 5 months from your home for an investment of only $25 U.S. Dollars expense one time THANK'S TO THE COMPUTER AGE AND THE INTERNET ! ================================================== BE A MILLIONAIRE LIKE OTHERS WITHIN A YEAR!!! Before you say ''Bull'', please read the following. This is the letter you have been hearing about on the news lately. Due to the popularity of this letter on the Internet, a national weekly news program recently devoted an entire show to the investigation of this program described below, to see if it really can make people money. The show also investigated whether or not the program was legal. Their findings proved once and for all that there are ''absolutely NO Laws prohibiting the participation in the program and if people can -follow the simple instructions, they are bound to make some mega bucks with only $25 out of pocket cost''. DUE TO THE RECENT INCREASE OF POPULARITY & RESPECT THIS PROGRAM HAS ATTAINED, IT IS CURRENTLY WORKING BETTER THAN EVER. This is what one had to say: ''Thanks to this profitable opportunity. I was approached many times before but each time I passed on it. I am so glad I finally joined just to see what one could expect in return for the minimal effort and money required. To my astonishment, I received total $ 610,470.00 in 21 weeks, with money still coming in." Pam Hedland, Fort Lee, New Jersey. =================================================== Here is another testimonial: "This program has been around for a long time but I never believed in it. But one day when I received this again in the mail I decided to gamble my $25 on it. I followed the simple instructions and walaa ..... 3 weeks later the money started to come in. First month I only made $240.00 but the next 2 months after that I made a total of $290,000.00. So far, in the past 8 months by re-entering the program, I have made over $710,000.00 and I am playing it again. The key to success in this program is to follow the simple steps and NOT change anything.'' More testimonials later but first, ===== PRINT THIS NOW FOR YOUR FUTUREREFERENCE ====== $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ If you would like to make at least $500,000 every 4 to 5 months easily and comfortably, please read the following...THEN READ IT AGAIN and AGAIN!!! $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ FOLLOW THE SIMPLE INSTRUCTION BELOW AND YOUR FINANCIAL DREAMS WILL COME TRUE, GUARANTEED! INSTRUCTIONS: =====Order all 5 reports shown on the list below ===== For each report, send $5 CASH, THE NAME & NUMBER OF THE REPORT YOU ARE ORDERING and YOUR E-MAIL ADDRESS to the person whose name appears ON THAT LIST next to the report. MAKE SURE YOUR RETURN ADDRESS IS ON YOUR ENVELOPE TOP LEFT CORNER in case of any mail problems. === When you place your order, make sure you order each of the 5 reports. You will need all 5 reports so that you can save them on your computer and resell them. YOUR TOTAL COST $5 X 5=$25.00. Within a few days you will receive, via e-mail, each of the 5 reports from these 5 different individuals. Save them on your computer so they will be accessible for you to send to the 1,000's of people who will order them from you. Also make a floppy of these reports and keep it on your desk in case something happen to your computer. IMPORTANT - DO NOT alter the names of the people who are listed next to each report, or their sequence on the list, in any way other than what is instructed below in step '' 1 through 6 '' or you will loose out on majority of your profits. Once you understand the way this works, you will also see how it does not work if you change it. Remember, this method has been tested, and if you alter, it will NOT work !!! People have tried to put their friends/relatives names on all five thinking they could get all the money. But it does not work this way. Believe us, we all have tried to be greedy and then nothing happened. So do not try to change anything other than what is instructed. Because if you do, it will not work for you. Remember, honesty reaps the reward!!! 1.... After you have ordered all 5 reports, take this advertisement and REMOVE the name & address of the person in REPORT # 5. This person has made it through the cycle and is no doubt counting their fortune. 2.... Move the name & address in REPORT # 4 down TO REPORT # 5. 3.... Move the name & address in REPORT # 3 down TO REPORT # 4. 4.... Move the name & address in REPORT # 2 down TO REPORT # 3. 5.... Move the name & address in REPORT # 1 down TO REPORT # 2 6.... Insert YOUR name & address in the REPORT # 1 Position. PLEASE MAKE SURE you copy every name & address ACCURATELY! ========================================================== **** Take this entire letter, with the modified list of names, and save it on your computer. DO NOT MAKE ANY OTHER CHANGES. Save this on a disk as well just in case if you loose any data. To assist you with marketing your business on the Internet, the 5 reports you purchase will provide you with invaluable marketing information which includes how to send bulk e-mails legally, where to find thousands of free classified ads and much more. There are 2 Primary methods to get this venture going: METHOD # 1: BY SENDING BULK E-MAIL LEGALLY ========================================================== Let's say that you decide to start small, just to see how it goes, and we will assume You and those involved send out only 5,000 e-mails each. Let's also assume that the mailing receive only a 0.2% response (the response could be much better but lets just say it is only 0.2%. Also many people will send out hundreds of thousands e-mails instead of only 5,000 each). Continuing with this example, you send out only 5,000 e-mails. With a 0.2% response, that is only 10 orders for report # 1. Those 10 people responded by sending out 5,000 e-mail each for a total of 50,000. Out of those 50,000 e-mails only 0.2% responded with orders. That's=100 people responded and ordered Report # 2. Those 100 people mail out 5,000 e-mails each for a total of 500,000 e-mails. The 0.2% response to that is 1000 orders for Report # 3. Those 1000 people send out 5,000 e-mails each for a total of 5 million e-mails sent out. The 0.2% response to that is 10,000 orders for Report # 4. Those 10,000 people send out 5,000 e-mails each for a total of 50,000,000 (50 million) e-mails. The 0.2% response to that is 100,000 orders for Report # 5 THAT'S 100,000 ORDERS TIMES $5 EACH=$500,000.00 (half million). Your total income in this example is: 1..... $50 + 2..... $500 + 3..... $5,000 + 4 ... $50,000 + 5..... $500,000 ........ Grand Total=$555,550.00 NUMBERS DO NOT LIE. GET A PENCIL & PAPER AND FIGUREOUT THE WORST POSSIBLE RESPONSES AND NO MATTER HOW YOU CALCULATE IT, YOU WILL STILL MAKE A LOT OF MONEY ! ========================================================= REMEMBER FRIEND, THIS IS ASSUMING ONLY 10 PEOPLE ORDERING OUT OF 5,000 YOU MAILED TO. Dare to think for a moment what would happen if everyone or half or even one 4th of those people mailed 100,000e-mails each or more? There are over 150 million people on the Internet worldwide and counting. Believe me, many people will do just that, and more! METHOD # 2 : BY PLACING FREE ADS ON THE INTERNET ======================================================= Advertising on the net is very, very inexpensive and there are hundreds of FREE places to advertise. Placing a lot of free ads on the Internet will easily get a larger response. We strongly suggest you start with Method # 1 and ad METHOD # 2 as you go along. For every $5 you receive, all you must do is e-mail them the Report they ordered. That's it. Always provide same day service on all orders. This will guarantee that the e-mail they send out, with your name and address on it, will be prompt because they can not advertise until they receive the report. =========== AVAILABLE REPORTS ==================== ORDER EACH REPORT BY ITS NUMBER & NAME ONLY. Notes: Always send $5 cash (U.S. CURRENCY) for each Report. Checks NOT accepted. Make sure the cash is concealed by wrapping it in at least 2 sheets of paper. On one of those sheets of paper, Write the NUMBER & the NAME of the Report you are ordering, YOUR E-MAIL ADDRESS and your name and postal address. PLACE YOUR ORDER FOR THESE REPORTS NOW: ==================================================== REPORT# 1: The Insider's Guide to Advertising for Free on the Net Order Report #1 from: J & D. Baugh P.O. Box 1602 Appleton, WI 54915 USA ________________________________________________________ REPORT # 2: The Insider's Guide to Sending Bulk e-mail on the Net Order Report # 2 from: A.L Hiltz 4076 Pine Tree Rd. Jonestone, PA 17038 USA _________________________________________________________________ REPORT # 3: Secret to Multilevel marketing on the net Order Report # 3 from : A. Smith P.O. Box 573072 Houston, TX 77257-3072 USA ____________________________________________________________ REPORT # 4: "How to Become a Millionaire Utilizing MLM & the Net" Order Report # 4 from: C.J. Kalata P.O. Box 130157 Roseville, MN 55113-0002 USA ____________________________________________________________ REPORT #5: "How to Send Out 0ne Million e-mails for Free" Order Report # 5 from: R. B. Box. 21115, Grande Prairie Alberta, T8V-6W7 Canada ____________________________________________________________ $$$$$$$$$ YOUR SUCCESS GUIDELINES $$$$$$$$$$$ Follow these guidelines to guarantee your success: === If you do not receive at least 10 orders for Report #1 within 2 weeks, continue sending e-mails until you do. === After you have received 10 orders, 2 to 3 weeks after that you should receive 100 orders or more for REPORT # 2. If you did not, continue advertising or sending e-mails until you do. === Once you have received 100 or more orders for Report # 2, YOU CAN RELAX, because the system is already working for you, and the cash will continue to roll in ! THIS IS IMPORTANT TO REMEMBER: Every time your name is moved down on the list, you are placed in front of a Different report. You can KEEP TRACK of your PROGRESS by watching which report people are ordering from you. IF YOU WANT TO GENERATE MORE INCOME SEND ANOTHER BATCH OF E-MAILS AND START THE WHOLE PROCESS AGAIN. There is NO LIMIT to the income you can generate from this business!!! ====================================================== FOLLOWING IS A NOTE FROM THE ORIGINATOR OF THIS PROGRAM: You have just received information that can give you financial freedom for the rest of your life, with NO RISK and JUST A LITTLE BIT OF EFFORT. You can make more money in the next few weeks and months than you have ever imagined. Follow the program EXACTLY AS INSTRUCTED. Do Not change it in any way. It works exceedingly well as it is now. Remember to e-mail a copy of this exciting report after you have put your name and address in Report #1 and moved others to #2 ...........# 5 as instructed above. One of the people you send this to may send out 100,000 or more e-mails and your name will be on every one of them. Remember though, the more you send out the more potential customers you will reach. So my friend, I have given you the ideas, information, materials and opportunity to become financially independent. IT IS UP TO YOU NOW ! ============ MORE TESTIMONIALS ================ "My name is Mitchell. My wife, Jody and I live in Chicago. I am an accountant with a major U.S. Corporation and I make pretty good money. When I received this program I grumbled to Jody about receiving ''junk mail''. I made fun of the whole thing, spouting my knowledge of the population and percentages involved. I ''knew'' it wouldn't work. Jody totally ignored my supposed intelligence and few days later she jumped in with both feet. I made merciless fun of her, and was ready to lay the old ''I told you so'' on her when the thing didn't work. Well, the laugh was on me! Within 3 weeks she had received 50 responses. Within the next 45 days she had received total $ 147,200.00 ........... all cash! I was shocked. I have joined Jody in her ''hobby''. Mitchell Wolf M.D., Chicago, Illinois ====================================================== ''Not being the gambling type, it took me several weeks to make up my mind to participate in this plan. But conservative that I am, I decided that the initial investment was so little that there was just no way that I wouldn't get enough orders to at least get my money back''. '' I was surprised when I found my medium size post office box crammed with orders. I made $319,210.00in the first 12 weeks. The nice thing about this deal is that it does not matter where people live. There simply isn't a better investment with a faster return and so big." Dan Sondstrom, Alberta, Canada ======================================================= ''I had received this program before. I deleted it, but later I wondered if I should have given it a try. Of course, I had no idea who to contact to get another copy, so I had to wait until I was e-mailed again by someone else.........11 months passed then it luckily came again...... I did not delete this one! I made more than $490,000 on my first try and all the money came within 22 weeks." Susan De Suza, New York, N.Y. ======================================================= ''It really is a great opportunity to make relatively easy money with little cost to you. I followed the simple instructions carefully and within 10 days the money started to come in. My first month I made $20,560.00 and by the end of third month my total cash count was $362,840.00. Life is beautiful, Thanks to Internet.". Fred Dellaca, Westport, New Zealand ======================================================= ORDER YOUR REPORTS TODAY AND GET STARTED ON 'YOUR' ROAD TO FINANCIAL FREEDOM ! ======================================================= If you have any questions of the legality of this program, contact the Office of Associate Director for Marketing Practices, Federal Trade Commission, Bureau of Consumer Protection, Washington, D.C. From lumbricus@gmx.net Sat Mar 24 09:12:32 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sat, 24 Mar 2001 10:12:32 +0100 (MET) Subject: [Tutor] Sockets -- huh? References: <001d01c0b421$e4c04460$60a1d6d1@ceo> Message-ID: <22071.985425152@www46.gmx.net> > : Have you tried telnetlib? > > No I didn't. My reference has been Python Essential Reference, written > for 1.5 and it said telnetlib was undocumented. I figured sockets was a > replacement. Though telnetlib will be much better for my needs, any > reason why sockets wouldn't work? after the setup of the connection via socket telnet goes through a negotiation process (don't know the details --- read rfc0854) peer sends some garbage, setting TERM etc ... a plain socket won't make it through that to the login prompt for a programming-example see netcat.c (the part after #ifdef TELNET) grrrrreetz jö!!! -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From bdupire@seatech.fau.edu Sat Mar 24 15:30:34 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sat, 24 Mar 2001 10:30:34 -0500 Subject: [Tutor] Is Python really dynamic ? References: <001301c0b34c$f36a72e0$de814cd8@ceo> <20010323120311.A11168@harmony.cs.rit.edu> <001d01c0b421$e4c04460$60a1d6d1@ceo> Message-ID: <3ABCBD9A.FD9895B8@seatech.fau.edu> My goal is to dynamically import a module called 'func' from 'prog1.py' and to get the references to the objects that 'func' created. # prog1.py class foo: def __init__(self, module): self.aa=__import__(module) # dynamically import func chRef= getattr(self.aa, 'setheading') # get reference to func objects chRef.run() my_foo = foo('func') # ---------------------------------- # func.py class SetHeading: def run(self): print 'test' setheading=SetHeading() It works fine. The result is: >>>reload(prog1) test <module 'prog1' from 'C:\Python20\prog1.pyc'> Now I change func.py, replacing 'setheading=SetHeading()' with 'toto=SetHeading()' Normally, this should create an error when I run prog1.py, because the setheading object does not exist anymore and prog1 references it. However: >>> reload(prog1) test <module 'prog1' from 'C:\Python20\prog1.pyc'> prog1.py is not recompiled. func is not reimported! How can I force prog1.py to dynamically reload module='func' ? Any ideas ? Thank you very much Benoit From moshez@zadka.site.co.il Sat Mar 24 15:52:06 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Sat, 24 Mar 2001 17:52:06 +0200 Subject: [Tutor] Is Python really dynamic ? In-Reply-To: <3ABCBD9A.FD9895B8@seatech.fau.edu> References: <3ABCBD9A.FD9895B8@seatech.fau.edu>, <001301c0b34c$f36a72e0$de814cd8@ceo> <20010323120311.A11168@harmony.cs.rit.edu> <001d01c0b421$e4c04460$60a1d6d1@ceo> Message-ID: <E14gqKk-0006wU-00@darjeeling> On Sat, 24 Mar 2001, Benoit Dupire <bdupire@seatech.fau.edu> wrote: > My goal is to dynamically import a module called 'func' from 'prog1.py' > and to get the references to the objects that 'func' created. <snip> > self.aa=__import__(module) # dynamically import func <snip> <snip> > >>> reload(prog1) > test > <module 'prog1' from 'C:\Python20\prog1.pyc'> <snip> > prog1.py is not recompiled. func is not reimported! Of course. you haven't reloaded it! Python caches imports. > How can I force prog1.py to dynamically reload module='func' ? Use reload() -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org From bdupire@seatech.fau.edu Sat Mar 24 16:23:02 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sat, 24 Mar 2001 11:23:02 -0500 Subject: [Tutor] Is Python really dynamic ? References: <3ABCBD9A.FD9895B8@seatech.fau.edu>, <001301c0b34c$f36a72e0$de814cd8@ceo> <20010323120311.A11168@harmony.cs.rit.edu> <001d01c0b421$e4c04460$60a1d6d1@ceo> <E14gqKk-0006wU-00@darjeeling> Message-ID: <3ABCC9E6.88068706@seatech.fau.edu> Moshe Zadka wrote: > On Sat, 24 Mar 2001, Benoit Dupire <bdupire@seatech.fau.edu> wrote: > > > How can I force prog1.py to dynamically reload module='func' ? > > Use reload() > Thank you Moshe....II already tried reload() but it didn't seem to work.. >>> import prog1 test That works fine...! Now change func.py, replacing 'setheading=SetHeading()' with 'toto=SetHeading()' >>> reload(prog1) test <module 'prog1' from 'C:\Python20\prog1.pyc'> Why does this still work ? setheading does not exist anymore.... I had no clue... until i run this from the command line, where i got the correct results, and not from IDLE. Could someone explain me why IDLE is messing everything up ? Benoit # func.py class SetHeading: def run(self): print 'test' stHeading=SetHeading() # prog1.py class foo: def __init__(self, module): self.aa=__import__(module) reload(self.aa) chRef= getattr(self.aa, 'stHeading') chRef.run() my_foo = foo('func') From wilson@visi.com Sat Mar 24 18:16:11 2001 From: wilson@visi.com (Timothy Wilson) Date: Sat, 24 Mar 2001 12:16:11 -0600 (CST) Subject: [Tutor] OOP design (w/ example :-) Message-ID: <Pine.GSO.4.21.0103241207570.24290-100000@isis.visi.com> Hey everyone, I'm back working on a little Python program, trying to scratch a specific itch that I keep having with my students at school. Specifically, I often want to put my students in small groups to work on class work, labs, or whatever we're working on that day. It's too time consuming to go through a big process every day and I want to rearrange the groups often. I thought a small computer program would be just the ticket. To keep things simple for now, I'm storing the students in a simple text file with last name, first name, and gender. (At some point I'd like to have the option of mixing gender in the groups.) Here's a sample file: van Rossum,Guido,M Boop,Betty,F Gauld,Alan,M Flintstone,Wilma,F Rubble,Betty,F Yoo,Danny,M Wilson,Tim,M Crawford,Cindy,F Van Laningham,Ivan,M Lutz,Mark,M Ascher,David,M Watters,Aaron,M I'd like to try a OOP approach, but one of the things I struggle with is the initial design stage. I've asked about this before and I've done some reading, but I still haven't found a way of thinking about problems like this that make a lot of sense to me. My program, it would seem, would logically have classes the correspond to individual students, groups, and perhaps the class as a whole. Here's what I've come up with so far: class Student: def __init__(self, ln, fn, gender): self.ln = ln self.fn = fn self.gender = gender class Group: def __init__(self, studentList): self.studentList = studentList def display(studentList): pass class Roster: def __init__(self): pass def loadFile(self, filename): import string classList = [] f = open(filename, 'r') while 1: try: record = f.readline() student = string.split(record, ',') ln = student[0] fn = student[1] gender = student[2][:1] classList.append(Student(ln, fn, gender)) except EOFError: break return classList Note, this code doesn't currently work. I get this: Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import group >>> roster = group.Roster() >>> classList = roster.loadFile('class.dat') Traceback (innermost last): File "<stdin>", line 1, in ? File "group.py", line 29, in loadFile fn = student[1] IndexError: list index out of range >>> I'd love to hear some advice from others on the list. What design advice can you give? Any other suggestions? -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 | <dtml-var pithy_quote> | http://linux.com/ From dyoo@hkn.eecs.berkeley.edu Sat Mar 24 18:16:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 10:16:05 -0800 (PST) Subject: [Tutor] Is Python really dynamic ? In-Reply-To: <3ABCC9E6.88068706@seatech.fau.edu> Message-ID: <Pine.LNX.4.21.0103241008020.23529-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, Benoit Dupire wrote: > Why does this still work ? setheading does not exist anymore.... I had > no clue... until i run this from the command line, where i got the > correct results, and not from IDLE. > Could someone explain me why IDLE is messing everything up ? You're not going to like this: According to the reference documentation: "When a module is reloaded, its dictionary (containing the module's global variables) is retained. Redefinition of names will override the old definitions, so this is generally not a problem. If the new version of a module does not define a name that was defined by the old version, the old definition remains." This comes from: http://python.org/doc/current/lib/built-in-funcs.html So that's why: setheading persists in the module definition if it hasn't been overridden, so erasing it won't take affect until we restart Python. This explains the weirdness that was happening before. Try writing your code to change the behavior of setheading, instead of removing it entirely. I wonder if there's a way of "clearing" out a module's definition, by calling "del" on its dictionary of methods. At the moment, I don't have easy access to a Python interpreter (the horror! the horror!), so I can't confirm this yet. Hope this helps! From deirdre@deirdre.net Sat Mar 24 19:25:29 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 24 Mar 2001 11:25:29 -0800 (PST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.GSO.4.21.0103241207570.24290-100000@isis.visi.com> Message-ID: <Pine.LNX.4.31.0103241125090.32096-100000@emperor.deirdre.org> On Sat, 24 Mar 2001, Timothy Wilson wrote: > To keep things simple for now, I'm storing the students in a simple text > file with last name, first name, and gender. (At some point I'd like to have > the option of mixing gender in the groups.) Here's a sample file: > > van Rossum,Guido,M What, I don't rate? :) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From wilson@visi.com Sat Mar 24 19:36:32 2001 From: wilson@visi.com (Timothy Wilson) Date: Sat, 24 Mar 2001 13:36:32 -0600 (CST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.LNX.4.31.0103241125090.32096-100000@emperor.deirdre.org> Message-ID: <Pine.GSO.4.21.0103241334280.28415-100000@isis.visi.com> On Sat, 24 Mar 2001, Deirdre Saoirse wrote: > > To keep things simple for now, I'm storing the students in a simple text > > file with last name, first name, and gender. (At some point I'd like to have > > the option of mixing gender in the groups.) Here's a sample file: > > > > van Rossum,Guido,M > > What, I don't rate? :) Sorry, I was going off the top of my head and looking at my stash of Python books at the same time. I'll add you to the file immediately! :-) -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 | <dtml-var pithy_quote> | http://linux.com/ From arcege@shore.net Sat Mar 24 19:43:28 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sat, 24 Mar 2001 14:43:28 -0500 (EST) Subject: [Tutor] Is Python really dynamic ? In-Reply-To: <no.id> from "Benoit Dupire" at Mar 24, 2001 11:23:02 AM Message-ID: <E14gtwe-0003Sp-00@nautilus.shore.net> > Moshe Zadka wrote: > > > On Sat, 24 Mar 2001, Benoit Dupire <bdupire@seatech.fau.edu> wrote: > > > > > How can I force prog1.py to dynamically reload module='func' ? > > > > Use reload() > > > > Thank you Moshe....II already tried reload() but it didn't seem to work.. > > >>> import prog1 > test > > That works fine...! > > Now change func.py, replacing > 'setheading=SetHeading()' > with 'toto=SetHeading()' > > >>> reload(prog1) > test > <module 'prog1' from 'C:\Python20\prog1.pyc'> > > Why does this still work ? setheading does not exist anymore.... > I had no clue... until i run this from the command line, where i got the correct > results, and not from IDLE. > > Could someone explain me why IDLE is messing everything up ? > > Benoit > > # func.py > class SetHeading: > def run(self): > print 'test' > stHeading=SetHeading() > > # prog1.py > class foo: > def __init__(self, module): > self.aa=__import__(module) > reload(self.aa) > chRef= getattr(self.aa, 'stHeading') > chRef.run() > > my_foo = foo('func') Actually it is because Python _is_ dynamic that you are having this function. Each module is independant, this includes when reloading modules. You will want to first reload func (accessible from sys.modules), then reload prog1. The reload function takes a module object, not a module name. But also Python _IS_ dynamic, you are only reloading a module, not creating a new module and executing func.py from scratch. This means that the stHeading still exists with the same object is had. >>> import proc1 test >>> reload(proc1) test <module 'proc1'> >>> # made your changes to func.py ... >>> reload(sys.modules['func']) <module 'func'> >>> reload(proc1) test <module 'proc1'> >>> dir(sys.modules['func']) ['SetHeading', '__builtins__', '__doc__', '__file__', '__name__', 'stHeading', 'toto'] >>> Notice that we get both "stHeading" and "toto"? -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From sheila@thinkspot.net Sat Mar 24 19:49:41 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 24 Mar 2001 11:49:41 -0800 Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.GSO.4.21.0103241207570.24290-100000@isis.visi.com> References: <Pine.GSO.4.21.0103241207570.24290-100000@isis.visi.com> Message-ID: <FA95A81C94@kserver.org> On Sat, 24 Mar 2001 12:16:11 -0600 (CST), Timothy Wilson <wilson@visi.com> wrote about [Tutor] OOP design (w/ example :-): :Hey everyone, : :I'm back working on a little Python program, trying to scratch a specific :itch that I keep having with my students at school. Specifically, I often :want to put my students in small groups to work on class work, labs, or :whatever we're working on that day. It's too time consuming to go through a :big process every day and I want to rearrange the groups often. I thought a :small computer program would be just the ticket. FYI: I use a deck of cards. If I have 24 students present, and I want groups of four, I choose all the cards Ace through six, shuffle them, and go around having the students each draw one card. Then everyone who drew an Ace forms one group, all the twos form another group, and so on. If I want them in pairs, then the two red Aces are a pair, and the two black Aces are a pair, and so on. Obviously, this doesn't ensure gender mixing and so on. And I like the idea of your little program very much. Heh, if you get it working, I wouldn't mind a copy, myself. :To keep things simple for now, I'm storing the students in a simple text :file with last name, first name, and gender. (At some point I'd like to have :the option of mixing gender in the groups.) Here's a sample file: : :van Rossum,Guido,M :Boop,Betty,F :Gauld,Alan,M :Flintstone,Wilma,F :Rubble,Betty,F :Yoo,Danny,M :Wilson,Tim,M :Crawford,Cindy,F :Van Laningham,Ivan,M :Lutz,Mark,M :Ascher,David,M :Watters,Aaron,M : :I'd like to try a OOP approach, but one of the things I struggle with is the :initial design stage. I've asked about this before and I've done some :reading, but I still haven't found a way of thinking about problems like :this that make a lot of sense to me. : :My program, it would seem, would logically have classes the correspond to :individual students, groups, and perhaps the class as a whole. Here's what :I've come up with so far: : :class Student: : def __init__(self, ln, fn, gender): : self.ln = ln : self.fn = fn : self.gender = gender : :class Group: : def __init__(self, studentList): : self.studentList = studentList : def display(studentList): : pass : :class Roster: : def __init__(self): : pass : def loadFile(self, filename): : import string : classList = [] : f = open(filename, 'r') ...<snipped>... (BTW, I give you permission to add me to the list ;) We sure have a dearth of female types on these programming lists, don't we?) :I'd love to hear some advice from others on the list. What design advice can :you give? Any other suggestions? Heh, I'll wait and see what some of the "experts" suggest. Right now I'm working on some cgi scripts. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From hobgoblin@tolkien.nu Sat Mar 24 20:49:26 2001 From: hobgoblin@tolkien.nu (Steve Collins) Date: Sat, 24 Mar 2001 12:49:26 -0800 Subject: [Tutor] Windows Programs Message-ID: <200103242049.MAA13132@mail25.bigmailbox.com> I'm trying to find out how to create windows programs with python (also perl & c). Every language I learn I always finish at dos programs and can never find out how to create programs for windows. (I've come across win 95 assembly language, does this have to be used some how?) any help would be fantastic! ------------------------------------------------------------ Get your own Tolkien Network e-mail address: http://www.tolkien.nu From wilson@visi.com Sat Mar 24 22:27:46 2001 From: wilson@visi.com (Timothy Wilson) Date: Sat, 24 Mar 2001 16:27:46 -0600 (CST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <FA95A81C94@kserver.org> Message-ID: <Pine.GSO.4.21.0103241624430.5760-100000@isis.visi.com> Here's what I think is an improved version of my program. I'm able to create a roster of student objects. (See interpretor session below.) What to do next? class Student: def __init__(self, ln, fn, gender): self.ln = ln self.fn = fn self.gender = gender class Group: def __init__(self, groupList): self.groupList = groupList def display(groupList): for i in groupList: print "%s, %s" % (self.ln, self.fn) class Roster: def __init__(self, studentList): self.studentList = studentList def loadFile(filename): import string f = open(filename, 'r') nameList = f.readlines() studentList = [] for i in nameList: student = string.split(i, ',') ln = student[0] fn = student[1] gender = student[2][:1] studentList.append(Student(ln, fn, gender)) return Roster(studentList) Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import group >>> roster = group.loadFile('class.dat') >>> roster <group.Roster instance at 8085c58> >>> roster.studentList[0] <group.Student instance at 8081258> >>> roster.studentList[0].fn 'Guido' >>> It's getting there...I think. -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 | <dtml-var pithy_quote> | http://linux.com/ From sheila@thinkspot.net Sat Mar 24 22:46:47 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 24 Mar 2001 14:46:47 -0800 Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.GSO.4.21.0103241624430.5760-100000@isis.visi.com> References: <FA95A81C94@kserver.org> <Pine.GSO.4.21.0103241624430.5760-100000@isis.visi.com> Message-ID: <5F14E90B67@kserver.org> I had been thinking a bit about this. Why not have classes: Student, Group and Class And Class is a class that has a Roster, which is a dictionary of Students. And it also has a GroupList, which is a dictionary of all the groups in the class. And each student has a field, that is a Group, which has a value of the group identifier that the student is assigned to. Otherwise, it has a value of None. And each group has a field, MaxNumber, which is the maximum number of students that you want in a group. Then, you could load your data file into the Roster of the Class. Then class could have a method that assigns groups. Make a temporary copy of the Roster dictionary. Then randomly select students from it, to assign to groups. When a student is selected, remove them from the temporary dictionary, so that the student cannot be selected again (so you don't have to check for dupe selections). Hm..just thinking out loud. I'm still interested to see suggestions from the experts on this problem. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sat, 24 Mar 2001 16:27:46 -0600 (CST), Timothy Wilson <wilson@visi.com> wrote about Re: [Tutor] OOP design (w/ example :-): :Here's what I think is an improved version of my program. I'm able to create :a roster of student objects. (See interpretor session below.) What to do :next? : :class Student: : def __init__(self, ln, fn, gender): : self.ln = ln : self.fn = fn : self.gender = gender : :class Group: : def __init__(self, groupList): : self.groupList = groupList : def display(groupList): : for i in groupList: : print "%s, %s" % (self.ln, self.fn) : :class Roster: : def __init__(self, studentList): : self.studentList = studentList ...<snipped>... From dyoo@hkn.eecs.berkeley.edu Sat Mar 24 22:47:18 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 14:47:18 -0800 (PST) Subject: [Tutor] clock programs (and generalization) In-Reply-To: <OE265BBBVhyemYewQ1N000034b0@hotmail.com> Message-ID: <Pine.LNX.4.21.0103241410560.27123-100000@hkn.eecs.berkeley.edu> Ok, I've taken a small look at each of your clock classes; you can definitely shrink this down to just one clock class. The thing i see is differnt is the treatment of self.time1. What makes a class useful is that you tell the general form, or shape of the thing you're making, but leave some information "floating" or variable, until you instantiate it. Let's let the Clock class make different kinds of clocks which vary by how long the hour is --- when we make a Clock, let's tell it also how long a day is. I'll use the variable "hourlength" to hold this information. ### class Clock(Frame): def __init__(self, master, hourlength): Frame.__init__(self,master) self.hourlength = hourlength timeformat2="Time so far on " + hourlength + \ " hr. planet is %d:%d:%d"): self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>self.hourlength: self.time1=self.time1 % self.hourlength self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==self.hourlength: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) ### With this one definition of a Clock, now we can make Clock18's, Clock21's, or any other kind of clock whenever we instantiate the clock. For example, whenever we say; Clock21(tkroot).pack(side=TOP) now we can say: Clock(tkroot, 21).pack(side=TOP) and have it do a similar thing! Not too exciting yet, but the savings become significant as soon as we make different clocks, because making a Clock24 now involves just slightly calling Clock differently: Clock(tkroot, 24).pack(side=TOP) By generalizing things, we don't have a need to write 5 different class definitions anymore, because it's all covered by Clock. Generalization is one of the biggest reasons we have classes --- if you find yourself writing something over and over, take another look and see if generalizing it is possible. There are other idioms specific to Python that can help make things shorter, but the biggest savings comes from generalization. It's not an exciting message, but it's an important one. *grin* Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Mar 24 23:11:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 15:11:26 -0800 (PST) Subject: [Tutor] Windows Programs In-Reply-To: <200103242049.MAA13132@mail25.bigmailbox.com> Message-ID: <Pine.LNX.4.21.0103241503440.29152-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, Steve Collins wrote: > I'm trying to find out how to create windows programs with python > (also perl & c). Every language I learn I always finish at dos > programs and can never find out how to create programs for windows. > (I've come across win 95 assembly language, does this have to be used > some how?) any help would be fantastic! By a Windows program, do you mean one with menubars, buttons, and labels? If so, then you'll want to look into Tkinter. (I know that Perl has something similar called Perl::Tk, but for C... hmm... I guess you could work with straight Tk.) Tkinter is a module that helps us make graphical, windowed programs. You'll be happy to learn that the programs you write with Tkinter will be portable across platforms: ideally, they should work on Windows, macs, and any other computer that supports Tkinter. For example: ### from Tkinter import * Label(text="Hello World").pack(side=LEFT) mainloop() ### is one of the simplest graphical programs that you can write with Tkinter. It prints out the glorious message, 'Hello World', in a nice window, and it runs anywhere, which is pretty cool. I wouldn't touch Win95 assembly with a long pole, thank you. *grin* There's quite a few of us trying to learn Tkinter here (I'm also a newbie), so feel free to ask about Tkinter. There are a few resources here: http://python.org/topics/tkinter/ Good luck to you! From dyoo@hkn.eecs.berkeley.edu Sat Mar 24 23:27:38 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 15:27:38 -0800 (PST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.GSO.4.21.0103241624430.5760-100000@isis.visi.com> Message-ID: <Pine.LNX.4.21.0103241511590.29152-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, Timothy Wilson wrote: > Here's what I think is an improved version of my program. I'm able to create > a roster of student objects. (See interpretor session below.) What to do > next? > > class Student: > def __init__(self, ln, fn, gender): > self.ln = ln > self.fn = fn > self.gender = gender It might be nice to give your Student class a convenient "string" function that will print out what a Student looks like when we try printing it out. You've encountered: > >>> roster.studentList[0] > <group.Student instance at 8081258> which shows that it exists, but doesn't quite show it nicely. Let's add one more method to your Student: ### def __str__(self): return "%s, %s. Gender: %s" % (self.ln, self.fn, self.gender) ### You'll notice that you'll still get: >>> roster.studentList[0] <group.Student instance at 8081258> which hasn't changed from the last time. But if you try: >>> print roster.studentList[0] you should see something more pleasant. The difference is between something's string repr() ("representation"), and in something's str() (string). [slightly wordy explanation coming up] It's a little weird, but all Python objects have two distinct ways of transforming into strings, through repr() and str(), and making your objects work with these functions nicely involves writing '__repr__()' or '__str__()' methods respectively. There's a semantic different between the two --- repr() should print out something that's very close to how Python represents things. For example, a hypothetical repr() for our student would, ideally, look like this: def __repr__(self): return "Student('%s', '%s', '%s')" % (self.ln, self.fn, self.gender) That is, by doing a repr() of any object, we should get back a string that's so close to how Python represents it that we should be able to just feed the result back to Python, and get back the same object. str(), on the other hand, is for human consumption. You don't have to do this for every single class you write, but for objects that are prime material for printing or examining, it's often very useful to write these methods. > class Group: > def __init__(self, groupList): > self.groupList = groupList > def display(groupList): > for i in groupList: > print "%s, %s" % (self.ln, self.fn) Warning: don't forget to put "self" in display's argument list. def display(self, groupList): ... I always forget this every once in a while. *grin* Anyway, good luck! I'm very interested to see how your program develops over time. From deirdre@deirdre.net Sat Mar 24 23:37:01 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 24 Mar 2001 15:37:01 -0800 (PST) Subject: [Tutor] Windows Programs In-Reply-To: <200103242049.MAA13132@mail25.bigmailbox.com> Message-ID: <Pine.LNX.4.31.0103241533150.32096-100000@emperor.deirdre.org> On Sat, 24 Mar 2001, Steve Collins wrote: > I'm trying to find out how to create windows programs with python > (also perl & c). Every language I learn I always finish at dos > programs and can never find out how to create programs for windows. For all platforms, there are GUI libraries, such as the ones for Windows. You need to learn the calls for that. In C++, it's called the Microsoft Foundation Classes (which also work on the Macintosh, which is the only reason I know it), but I know there's a lower level than that available. Sorry I can't be more helpful; have you looked at the book about programming python on win32? > (I've come across win 95 assembly language, does this have to be used > some how?) any help would be fantastic! No assembly language is required. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From deirdre@deirdre.net Sat Mar 24 23:38:28 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 24 Mar 2001 15:38:28 -0800 (PST) Subject: [Tutor] Windows Programs In-Reply-To: <Pine.LNX.4.21.0103241503440.29152-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.31.0103241537370.32096-100000@emperor.deirdre.org> On Sat, 24 Mar 2001, Daniel Yoo wrote: > By a Windows program, do you mean one with menubars, buttons, and > labels? If so, then you'll want to look into Tkinter. (I know that > Perl has something similar called Perl::Tk, but for C... hmm... I > guess you could work with straight Tk.) Well, Tkinter is easy and cross-platform but ugh it's ugly (and poorly documented). -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From scarblac@pino.selwerd.nl Sat Mar 24 23:44:50 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 25 Mar 2001 00:44:50 +0100 Subject: [Tutor] Windows Programs In-Reply-To: <Pine.LNX.4.31.0103241537370.32096-100000@emperor.deirdre.org>; from deirdre@deirdre.net on Sat, Mar 24, 2001 at 03:38:28PM -0800 References: <Pine.LNX.4.21.0103241503440.29152-100000@hkn.eecs.berkeley.edu> <Pine.LNX.4.31.0103241537370.32096-100000@emperor.deirdre.org> Message-ID: <20010325004450.A19841@pino.selwerd.nl> On Sat, Mar 24, 2001 at 03:38:28PM -0800, Deirdre Saoirse wrote: > On Sat, 24 Mar 2001, Daniel Yoo wrote: > > > By a Windows program, do you mean one with menubars, buttons, and > > labels? If so, then you'll want to look into Tkinter. (I know that > > Perl has something similar called Perl::Tk, but for C... hmm... I > > guess you could work with straight Tk.) > > Well, Tkinter is easy and cross-platform but ugh it's ugly (and poorly > documented). "An Introduction to Tkinter" by Fredrik Lundh is pretty good, at http://www.secretlabs.com/library/tkinter/introduction/index.htm However, I think that wxWindows is much better than Tk; it's a cross platform library that uses the native tools on every platform, so that the same Python program using wxPython looks like a Windows program on Windows, a Unix program on Unix, et cetera. Alas, I haven't found good documentation for it yet (haven't done much research, I rarely need GUI things). But there was an article on it about two weeks ago at the following URL: http://www-106.ibm.com/developerworks/library/l-wxpy See also http://www.wxwindows.org and http://www.wxpython.org . -- Remco Gerlich From charlie@webmind.com Sat Mar 24 23:53:35 2001 From: charlie@webmind.com (Charlie Derr) Date: Sat, 24 Mar 2001 18:53:35 -0500 Subject: [Tutor] PyGreSQL compiliation difficulties In-Reply-To: <200103250047.f2P0l7r22783@pop.nsacom.net> Message-ID: <LOBBJCAMDNLNCGCCHGEIIENOKCAA.charlie@webmind.com> I had no problem with the instructions in the README file. The last step in installing as a standalone module says: * Finally, move the _pg.so, pg.py, and pgdb.py to a directory in your PYTHONPATH. A good place would be /usr/lib/python1.5/site-python if your Python modules are in /usr/lib/python1.5. I have no idea what more information you may be seeking, as this seemed sufficient for me. Also, for the record there is a pygresql list -- info at http://www.vex.net/mailman/listinfo/pygresql -- you'll probably get much better information there (after all, i'm basically a newbie to pygresql myself). Please don't interpret this response as a vote against a _pg.module.beginner.HOWTO -- i think that would be a great idea. good luck, ~c ~ -----Original Message----- ~ From: doug@nsacom.net [mailto:doug@nsacom.net] ~ Sent: Saturday, March 24, 2001 7:47 PM ~ To: Charlie Derr; Charlie Derr; doug@nsacom.net; tutor@python.org ~ Subject: RE: [Tutor] PyGreSQL compiliation difficulties ~ ~ ~ Charlie Derr <charlie@webmind.com> said: ~ ~ > Argh. ~ > ~ > The example wasn't supposed to have two slashes in a row like that. ~ > What you want is to do it this way: ~ > ~ > ~ > -I/usr/local/pgsql/include/ ~ > ~ ~ ~ Well that worked just dandy. It appeared to compile for the ~ built-in method, ~ but I could not make the example code work. However, when it was ~ recompiled ~ as a module, everything worked swimmingly. I can actually bump up against ~ PostGreSQL! Yay! ~ ~ Unfortunately now I cannot figure out where to *put* the blinking thing. ~ Where is the standard path for installation of python modules? ~ Are their any ~ caveats about building and installing them? ~ ~ I believe that the creator of the module has made a tutuorial on ~ how to use ~ it with postgresql. Unfortunately it assumes that you have the native ~ intelligence and cleverness of mind to install and connect to the ~ database in ~ the first place. Grrr. ~ ~ When I am successfully using this module in a few days I will write a ~ _pg.module.beginner.HOWTO that will explain all of this in words of one ~ syllable for the clue-challenged that will follow behind me. ~ ~ This I swear by the Horny Callouses of Racksput The Jogger. ~ ~ ~ > ~ > ~ > sorry about any confusion, ~ -------------------|much nonsense cut|-------------------- From tim@johnsons-web.com Sun Mar 25 00:39:51 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sat, 24 Mar 2001 15:39:51 -0900 Subject: [Tutor] Windows Programs References: <Pine.LNX.4.31.0103241537370.32096-100000@emperor.deirdre.org> Message-ID: <01032416005500.15172@shecom> Hello: On Sat, 24 Mar 2001, Deirdre Saoirse wrote: > On Sat, 24 Mar 2001, Daniel Yoo wrote: > > > By a Windows program, do you mean one with menubars, buttons, and > > labels? If so, then you'll want to look into Tkinter. (I know that > > Perl has something similar called Perl::Tk, but for C... hmm... I > > guess you could work with straight Tk.) > > Well, Tkinter is easy and cross-platform but ugh it's ugly (and poorly > documented). I would concur with Dierdre here, however, python does provide with tkinter a "free" way to build windows-style GUIs, whether for MS-Windows or XWindows. Two Books to mention: 1)"Teach yourself Python in 24 Hours" by Ivan Van Laningham, gets into tkinter from beginners level upward. I found it a good way to start. 2)"Python and Tkinter Programming" by John Grayson is very indepth with tkinter, but is pretty advanced. Purchase of the book does give you access to a private website for support, and from what I have seen of it, Grayson answers many of the questions himself. Also, since this thread does seem to consider some other languages: Dynace: http://server1.florida-software.com/algorithms/ is an object-oriented extension of C (not C++) , with a (MS)window interface, and has a egroup list, I believe. Rebol: www.rebol.com is a scripting language - like and unlike - python with has it's own GUI overlay called "view". That is, rebol offers a series of incrementally more complex binary interpreters, starting with "core", then "view" with the GUI ability, those are free. Successive enhancements have to be purchased Borland and Microsoft offer drag-and-drop development environments for GUI development in C++ but : 1)They are quite proprietory 2)And you pay....... Starting with python and tkinter is really a good way to go. -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From rodeored@netstep.net Sun Mar 25 01:35:51 2001 From: rodeored@netstep.net (Rodeo Red) Date: Sat, 24 Mar 2001 20:35:51 -0500 Subject: [Tutor] mailman html page Message-ID: <3ABD4B77.4A106C5D@netstep.net> This is from the Mailman interface. I think this is a python question, I think these tags are for python, but I could be wrong: <td> <MM-Undigest-Radio-Button> No <MM-Digest-Radio-Button> Yes </TD> </tr> <tr> <td colspan="3"> <center><MM-Subscribe-Button> Anyway, what i want to do is change it so there is only a subscribe button, without giving the user a choice. It's only supposed to subscribe them to the digest version. The best I can get is to leave the Undigest button out, but if the user doesn't check the digest button they get the undigest version. Is there a way to do this ? From dyoo@hkn.eecs.berkeley.edu Sun Mar 25 04:10:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 20:10:14 -0800 (PST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <FA95A81C94@kserver.org> Message-ID: <Pine.LNX.4.21.0103241959560.1811-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, Sheila King wrote: > FYI: I use a deck of cards. If I have 24 students present, and I want > groups of four, I choose all the cards Ace through six, shuffle them, > and go around having the students each draw one card. Then everyone > who drew an Ace forms one group, all the twos form another group, and > so on. If I want them in pairs, then the two red Aces are a pair, and > the two black Aces are a pair, and so on. Obviously, this doesn't > ensure gender mixing and so on. And I like the idea of your little > program very much. Heh, if you get it working, I wouldn't mind a copy, > myself. There was a small discussion on shuffling, by the way, on the Edu-Sig mailing list a while back... *grin*: http://mail.python.org/pipermail/edu-sig/2000-November/000772.html I'm not quite sure how it would handle gender mixing either. One solution would be to shuffle people around, and then try to divide people into groups. If it's not mixed "well", according to some heuristic measurement of "wellness", toss out the result and try it again. So the pseudo-code would be something like: ### while 1: mixed_people = shuffle(people) split_groups = splitUpTheGroupsEvenly(mixed_people) if goodDistribution(split_groups): break ### > :I'd like to try a OOP approach, but one of the things I struggle with is the > :initial design stage. I've asked about this before and I've done some > :reading, but I still haven't found a way of thinking about problems like > :this that make a lot of sense to me. Subjective comments: I like the decomposition of lines of text into a list of Students. I don't think it's too necessary to take the OOP any further, since normal Python lists should be able to handle groups fairly well. Another recommendation: don't force OOP into your design if it doesn't fit well. From van@lindbergs.org Sun Mar 25 04:44:39 2001 From: van@lindbergs.org (VanL) Date: Sat, 24 Mar 2001 21:44:39 -0700 Subject: [Tutor] Variables in regular expressions Message-ID: <3ABD77B7.B4E5080F@lindbergs.org> Hello, Is it possible to use variables in regular expressions: I tried this, but it didn't work: >>> import re >>> matchstr = 'fleas' >>> sentence = 'my dog has fleas' >>> if re.match(matchstr, sentence): print "Yes, it works." ... >>> Is this impossible to do, or am I doing it wrong? Thanks, VanL From dyoo@hkn.eecs.berkeley.edu Sun Mar 25 04:34:41 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 20:34:41 -0800 (PST) Subject: [Tutor] mailman html page In-Reply-To: <3ABD4B77.4A106C5D@netstep.net> Message-ID: <Pine.LNX.4.21.0103242024060.1811-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, Rodeo Red wrote: > This is from the Mailman interface. I think this is a python question, I > think these tags are for python, but I could be wrong: > > <td> > <MM-Undigest-Radio-Button> No > <MM-Digest-Radio-Button> Yes > > </TD> > </tr> > <tr> > <td colspan="3"> > <center><MM-Subscribe-Button> > > Anyway, what i want to do is change it so there is only a subscribe > button, without giving the user a choice. It's only supposed to > subscribe them to the digest version. The best I can get is to leave the > Undigest button out, but if the user doesn't check the digest button > they get the undigest version. (Side note: you'd probably get a better answer if you sent you question to the Mailman people, since we focus more on Python as a language, not as Python in a practical setting. Ahem.) It sounds like you want to change the default settings of your list. I did a quick search, and from looking at /home/mailman/Mailman/Defaults.py, the following text catches the eye: ### You should NOT edit the values here unless you're changing settings for distribution. For site-specific settings, put your definitions in mm_cfg.py after the point at which it includes (via 'from ... import *') this file, to override the distributed defaults with site-specific ones. ... [later on...] DEFAULT_DIGEST_IS_DEFAULT = 0 ### So yes, there appears to be a way to have it, by default, assign your mailing list to use digest as its delivery method. You'll want to edit to edit /home/mailman/Mailman/mm_cfg.py, and right below the line: ### from Defaults import * ### put the line: ### DEFAULT_DIGEST_IS_DEFAULT = 1 ### which, with luck, should set things up properly. Afterwards, if you remove the button from your HTML template, it should go for digests. Still, send your question to the Mailman folks, because I'm only guessing at this point. You can find them here: http://mail.python.org/mailman/listinfo/mailman-users From dyoo@hkn.eecs.berkeley.edu Sun Mar 25 04:43:57 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 24 Mar 2001 20:43:57 -0800 (PST) Subject: [Tutor] Variables in regular expressions In-Reply-To: <3ABD77B7.B4E5080F@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103242037450.2861-100000@hkn.eecs.berkeley.edu> On Sat, 24 Mar 2001, VanL wrote: > Hello, > > Is it possible to use variables in regular expressions: I tried > this, but it didn't work: > > >>> import re > >>> matchstr = 'fleas' > >>> sentence = 'my dog has fleas' > >>> if re.match(matchstr, sentence): print "Yes, it works." > ... > >>> > > Is this impossible to do, or am I doing it wrong? It's possible. Um... I mean, that it's possible to do, not that it's possible that you're doing it wrong. Gosh, that sounded funny. Using variables with it should work. However, try re.search() instead: ### >>> import re >>> if re.search('fleas', 'my dog has fleas'): print 'yes!' ... yes! ### There's a difference between match() and search(): match() will start at the very beginning of the thing we're searching through, and if it doesn't match at the beginning, then it doesn't work. search(), on the other hand, does search through the whole string to see if it pattern-matches, and behaves the way you probably expect it to. For more information, take a look at: http://python.org/doc/current/lib/matching-searching.html which explains in more detail why they're different from each other. Hope this helps! From wilson@visi.com Sun Mar 25 05:36:00 2001 From: wilson@visi.com (Timothy Wilson) Date: Sat, 24 Mar 2001 23:36:00 -0600 (CST) Subject: [Tutor] OOP design (w/ example :-) In-Reply-To: <Pine.LNX.4.21.0103241959560.1811-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.GSO.4.21.0103242333040.18911-100000@isis.visi.com> On Sat, 24 Mar 2001, Daniel Yoo wrote: > Subjective comments: I like the decomposition of lines of text into a list > of Students. I don't think it's too necessary to take the OOP any > further, since normal Python lists should be able to handle groups fairly > well. Another recommendation: don't force OOP into your design if it > doesn't fit well. Thanks for the suggestions. I'm just looking for something to work on so I can figure out OOP techniques. You've kind of hit the central point, however, with your suggestion about not forcing OOP. Unfortunately I have yet to find a methodology for analyzing a problem and determining whether it's a good candidate for an OO approach or not. Suggestions welcomed. :-) -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 | <dtml-var pithy_quote> | http://linux.com/ From dsh8290@rit.edu Sun Mar 25 19:39:52 2001 From: dsh8290@rit.edu (D-Man) Date: Sun, 25 Mar 2001 14:39:52 -0500 Subject: [Tutor] Sockets -- huh? In-Reply-To: <001d01c0b421$e4c04460$60a1d6d1@ceo>; from joejava@dragoncat.net on Sat, Mar 24, 2001 at 12:18:37AM -0500 References: <001301c0b34c$f36a72e0$de814cd8@ceo> <20010323120311.A11168@harmony.cs.rit.edu> <001d01c0b421$e4c04460$60a1d6d1@ceo> Message-ID: <20010325143952.A20600@harmony.cs.rit.edu> On Sat, Mar 24, 2001 at 12:18:37AM -0500, JRicker wrote: | : Have you tried telnetlib? | | No I didn't. My reference has been Python Essential Reference, written | for 1.5 and it said telnetlib was undocumented. I figured sockets was a | replacement. Though telnetlib will be much better for my needs, any | reason why sockets wouldn't work? | Telnetlib is documented here : http://www.python.org/doc/lib/module-telnetlib.html As Jorg said, telnet is a protocol that is built on top of sockets. Sockets are a very low level of communication. The server is probably waiting for you to declar (according to the telnet protocol) what your TERM, etc, are. HTH, -D From scarblac@pino.selwerd.nl Sun Mar 25 20:07:43 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 25 Mar 2001 22:07:43 +0200 Subject: [Tutor] Re: your mail In-Reply-To: <NEBBKHOKILNDMNNKBBGHCEDCCAAA.slag@lnet.myweb.nl>; from slag@lnet.myweb.nl on Sun, Mar 25, 2001 at 05:13:36PM +0200 References: <NEBBKHOKILNDMNNKBBGHCEDCCAAA.slag@lnet.myweb.nl> Message-ID: <20010325220743.A21358@pino.selwerd.nl> On Sun, Mar 25, 2001 at 05:13:36PM +0200, Gerben Slag wrote: > Zo jongen wat hoor ik nou dan weer: > > Gij zult geen ruzie maken > > En vooral niet met chauffeurs van “het concern…….” Nieuws gaat veel te snel, blijkbaar... R From jthing@frisurf.no Sun Mar 25 20:44:17 2001 From: jthing@frisurf.no (John Thingstad) Date: Sun, 25 Mar 2001 22:44:17 +0200 Subject: [Tutor] Windows systems for Python Message-ID: <200103252045.WAA21032@mail48.fg.online.no> There are a number of different windows systems for Python. Most of these are operating system dependent. There are, however, a few that arn't. There is TKinter and a toolkitbuildt on top of this Python Mega Widgets. This should come with your Python distribution. (Pythom Mega Widgets are located in <pythondir>/Lib/site-packages/PmW on my Win. distr.) You may have to put the PmW into you python path before it will work. In additon there is a neat system called wxWindows. This Windows library resembles MFC in structure. The library is written in C++ and has a C++ interface. There is altso a Python and a Perl interface which resembels in structure. It is portable to Windows and Unix (using Gnome toolkit) today. Mackintosh C++ interfaces (and Motif/KDE, BeOS) are availabe and will problaby be included soon. This system has a better native look and feel than TKinter widgets do (at least in a (win)Doze environment). Since it dosn't require Tcl to be run it is also smaller and faster. This is what I use these days. I particulary like the fact that is cross portable and that I can use the same interace for Python and C++. If the Python code is too slow (rare) the I can write the dialog, say, in C++ and use it in the Python app. I don't know of any other crossportable library that lets you do this. (Though theorectically you could write a Tk interface in C++ you wouldn't get much of a speed improvement.) Look at the cite www.wxpython.org and www.wxwindows.org for more information. Hope this is helpfull. John From doug@nsacom.net Sat Mar 24 23:09:30 2001 From: doug@nsacom.net (doug@nsacom.net) Date: Sat, 24 Mar 2001 15:09:30 -0800 (PST) Subject: [Tutor] Installing modules Message-ID: <200103242309.f2ON9Pr23508@pop.nsacom.net> I have built the PyGreSQL module and would now like to install it. I know this is probably a RTFM, but where does one install a new module? thanks! From s349929@student.uq.edu.au Mon Mar 26 02:35:10 2001 From: s349929@student.uq.edu.au (Suzanne Little) Date: Mon, 26 Mar 2001 12:35:10 +1000 (GMT+1000) Subject: [Tutor] Pickling Message-ID: <Pine.OSF.4.30.0103261217460.22110-100000@student.uq.edu.au> Hello, I'm trying to use pickle to store a DOM (from xml.dom.minidom). It appears to perform the dump fine but I can't load the object. Is this because minidom doesn't support pickling? Or am I mis-understanding something about the way pickling works? According to the Library Reference attempts to pickle an unpicklable object will result in a PicklingError exception but I'm not getting this. Sample session follows: Python 2.0 (#1, Feb 14 2001, 10:51:28) [GCC 2.95.2 19991024 (release)] on sunos5 Type "copyright", "credits" or "license" for more information. >>> from xml.dom.minidom import parse >>> import pickle >>> f = open('pickleTest', 'w') >>> d = parse('xmlTest.xml') >>> pickle.dump(d, f) >>> $ python2.0 Python 2.0 (#1, Feb 14 2001, 10:51:28) [GCC 2.95.2 19991024 (release)] on sunos5 Type "copyright", "credits" or "license" for more information. >>> import pickle >>> f = open('xmlTest.xml', 'r') >>> pickle.load(f) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in load return Unpickler(file).load() File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in load dispatch[key](self) KeyError: < >>> Okay. Sometimes I get a blank line and nothing listed for the KeyError. The xmlTest.xml file is listed below. I'm using python 2.0 on a solaris. xmlTest.xml: <?xml version="1.0"?> <parent id="top"><child1 name="paul">Text goes here</child1> <child2 name="fred">More text</child2> </parent> --- I have also had a few doms not pickle with the following error. There's a lot more (it shoots up the screen) but here's the last bit. Notably the xml that this dom was based on was a lot bigger and more complicated than xmlTest File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 202, in save f(self, object) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 433, in save_inst save(stuff) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 202, in save f(self, object) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 382, in save_dict save(value) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 202, in save f(self, object) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 433, in save_inst save(stuff) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 202, in save f(self, object) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 381, in save_dict save(key) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 128, in save pid = self.persistent_id(object) RuntimeError: Maximum recursion depth exceeded >>> Thanks as always, Suzanne BTW: Isn't pickle a great name! :) "What are you doing?" "I'm trying to pickle my doms" -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From kromag@nsacom.net Mon Mar 26 04:52:17 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Sun, 25 Mar 2001 20:52:17 -0800 (PST) Subject: [Tutor] PyGreSQL tutorial Message-ID: <200103260452.f2Q4qHF11388@pop.nsacom.net> I am attempting to get the PyGreSQL tutorial scripts to run, but I can't for the life of me figure out the proper settings for postgres. The examples in the HOWTO work great (although I am having a little trouble writing my querys out, I keep getting <python query output> or some such instead of my glamourous data) Terribly exiting stuff! Thanks! From gruschow2@hotmail.com Mon Mar 26 05:29:49 2001 From: gruschow2@hotmail.com (Charles Gruschow) Date: Sun, 25 Mar 2001 23:29:49 -0600 Subject: [Tutor] clock programs (and generalization) Message-ID: <F138kDeE9KQxnNTFiPd0000aad6@hotmail.com> Is this any better (it is simplified somewhat, and it is more exact): from Tkinter import * from time import * from locale import * class Clock(Frame): def __init__(self, master, format="Our local time is now %X"): Frame.__init__(self, master) self.time = localtime(time()) self.timeformat = format self.display = Label(self, fg="green", bg="black", text=strftime(self.timeformat, self.time)) self.display.pack(side=TOP, expand=YES, fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time = localtime(time()) self.display.configure(text=strftime(self.timeformat, self.time)) self.after(1000, self.updateDisplay) class Uptime(Frame): def __init__(self,master,format2="Dune UpTime is %d weeks %d days %d:%d:%d"): Frame.__init__(self,master) self.time=(w1,d1,h1,m1,s1) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] self.time4=self.time[3] self.time5=self.time[4] self.timeformat=format2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time5=self.time5+1 if self.time5==60: self.time5=0 self.time4=self.time4+1 if self.time4==60: self.time4=0 self.time3=self.time3+1 if self.time3==24: self.time3=0 self.time2=self.time2+1 if self.time2==7: self.time2=0 self.time1=self.time1+1 self.time=(self.time1,self.time2,self.time3,self.time4,self.time5) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) class ClockPlanet(Frame): def __init__(self,master,daylength): Frame.__init__(self,master) self.daylength=daylength timeformat2='Time so far on ' + str(daylength) + \ ' hr. planet is %d:%d:%d' h1=s3/3600 h=h1 % self.daylength s=s3-(int(h1)*3600) m=s/60 s=s-(int(m)*60) h=int(h) m=int(m) s=int(s) self.time=(h,m,s) self.time1=self.time[0] self.time2=self.time[1] self.time3=self.time[2] if self.time1>self.daylength: self.time1=self.time1 % self.daylength self.timeformat=timeformat2 self.display=Label(self,fg="green",bg="black", text=format(self.timeformat,self.time)) self.display.pack(side=TOP,expand=YES,fill=BOTH) self.updateDisplay() def updateDisplay(self): self.time3=self.time3+1 if self.time3==60: self.time3=0 self.time2=self.time2+1 if self.time2==60: self.time2=0 self.time1=self.time1+1 if self.time1==self.daylength: self.time1=0 self.time=(self.time1,self.time2,self.time3) self.display.configure(text=format(self.timeformat,self.time)) self.after(1000,self.updateDisplay) if __name__ == "__main__": #put a blank line and a asterisk-line and a blank line before official beginning of program print print "***m*y* *p*r*o*g*r*a*m* *b*e*g*i*n*s* *n*o*w***" print print "Dune MUD Time Giver" print "by Charles Gruschow" print "email: gruschow2@hotmail.com" print w=input("Number of uptime weeks (this will be w) ? ") d=input("Number of uptime days (this will be d) ? ") h=input("Number of uptime hours (this will be h) ? ") m=input("Number of uptime minutes (this will be m) ? ") s=input("Number of uptime seconds (this will be s) ? ") w=abs(w) d=abs(d) h=abs(h) m=abs(m) s=abs(s) s2=(w*7*24*3600)+(d*24*3600)+(h*3600)+(m*60)+s print print "Seconds uptime is: ",s2 #I got the 0.00303674226326 value from observation s3=(1-0.00303674226326)*s2 print "Seconds uptime less 0.303674226326%: ",s3 print "That factor was since planet times lag behind uptime." print print "Seconds lag was: ",s2-s3 ml=(s2-s3)/60 sl=(s2-s3)-(int(ml)*60) print "which was %d minutes and %f seconds" % (ml,sl) print #for those who don't know: there are 604800 seconds in a week and 86400 seconds in a day #and 3600 seconds in an hour #the corrected w=s3/604800 s4=s3-(int(w)*604800) d=s4/86400 s5=s4-(int(d)*86400) h=s5/3600 s6=s5-(int(h)*3600) m=s6/60 s=s6-(int(m)*60) w=int(w) d=int(d) h=int(h) m=int(m) s=int(s) #the uncorrected w1=s2/604800 s7=s2-(int(w1)*604800) d1=s7/86400 s8=s7-(int(d1)*86400) h1=s8/3600 s9=s8-(int(h1)*3600) m1=s9/60 s1=s9-(int(m1)*60) w1=int(w1) d1=int(d1) h1=int(h1) m1=int(m1) s1=int(s1) print "Corrected: wks.: %d, dys.: %d, hrs.: %d, min.: %d, sec.: %d" % (w,d,h,m,s) print "These corrected values will show themselves most readily in the 24 hr. planets." print tkroot = Tk() tkroot.title("Dune MUD Time Giver") labelx = Label(tkroot,fg="red",text="Dune MUD (based on works of Frank Herbert) Time Giver",font=("Times",14)) labelx.pack() labelx = Label(tkroot,fg="blue",text="for info contact gruschow2@hotmail.com") labelx.pack() labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() Clock(tkroot, "Our local time is now %X").pack(side=TOP) Uptime(tkroot,"Dune UpTime is %d weeks %d days %d:%d:%d").pack(side=TOP,pady=5) labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() labelx = Label(tkroot,text="Planets of Chapterhouse and Wallach") labelx.pack() ClockPlanet(tkroot,18).pack(side=TOP) labelx = Label(tkroot,text="Planet of Salusa") labelx.pack() ClockPlanet(tkroot,21).pack(side=TOP) labelx = Label(tkroot,text="Planets of Arrakis (Dune) and Ix") labelx.pack() ClockPlanet(tkroot,24).pack(side=TOP) labelx = Label(tkroot,text="Planet of Geidi Prime") labelx.pack() ClockPlanet(tkroot,28).pack(side=TOP) labelx = Label(tkroot,text="Planet of Caladan") labelx.pack() ClockPlanet(tkroot,36).pack(side=TOP) labelx = Label(tkroot) labelx["height"] = 1 labelx.pack() labelx = Label(tkroot,fg="blue",text="Due to electromagnetic properties of the planet Tleilax,") labelx.pack() labelx = Label(tkroot,fg="blue",text="it isn't necessary to calculate time for there.") labelx.pack() labelx = Label(tkroot,fg="blue",text="Also, the times for the planets can only be approximated.") labelx.pack() tkroot.mainloop() >From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu> >To: "Charles Gruschow, Jr." <gruschow2@hotmail.com> >CC: tutor@python.org >Subject: Re: [Tutor] clock programs (and generalization) >Date: Sat, 24 Mar 2001 14:47:18 -0800 (PST) > > >Ok, I've taken a small look at each of your clock classes; you can >definitely shrink this down to just one clock class. The thing i see is >differnt is the treatment of self.time1. > >What makes a class useful is that you tell the general form, or shape of >the thing you're making, but leave some information "floating" or >variable, until you instantiate it. Let's let the Clock class make >different kinds of clocks which vary by how long the hour is --- when we >make a Clock, let's tell it also how long a day is. I'll use the variable >"hourlength" to hold this information. > >### >class Clock(Frame): > def __init__(self, master, hourlength): > Frame.__init__(self,master) > self.hourlength = hourlength > timeformat2="Time so far on " + hourlength + \ > " hr. planet is %d:%d:%d"): > > self.time=(h,m,s) > self.time1=self.time[0] > self.time2=self.time[1] > self.time3=self.time[2] > > if self.time1>self.hourlength: > self.time1=self.time1 % self.hourlength > > self.timeformat=format2 > self.display=Label(self,fg="green",bg="black", > text=format(self.timeformat,self.time)) > self.display.pack(side=TOP,expand=YES,fill=BOTH) > self.updateDisplay() > > def updateDisplay(self): > self.time3=self.time3+1 > > if self.time3==60: > self.time3=0 > self.time2=self.time2+1 > if self.time2==60: > self.time2=0 > self.time1=self.time1+1 > if self.time1==self.hourlength: > self.time1=0 > > self.time=(self.time1,self.time2,self.time3) > self.display.configure(text=format(self.timeformat,self.time)) > self.after(1000,self.updateDisplay) >### > >With this one definition of a Clock, now we can make Clock18's, Clock21's, >or any other kind of clock whenever we instantiate the clock. For >example, whenever we say; > > Clock21(tkroot).pack(side=TOP) > >now we can say: > > Clock(tkroot, 21).pack(side=TOP) > >and have it do a similar thing! Not too exciting yet, but the savings >become significant as soon as we make different clocks, because making a >Clock24 now involves just slightly calling Clock differently: > > Clock(tkroot, 24).pack(side=TOP) > >By generalizing things, we don't have a need to write 5 different class >definitions anymore, because it's all covered by Clock. Generalization is >one of the biggest reasons we have classes --- if you find yourself >writing something over and over, take another look and see if generalizing >it is possible. There are other idioms specific to Python that can help >make things shorter, but the biggest savings comes from generalization. > >It's not an exciting message, but it's an important one. *grin* Hope this >helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From alan.gauld@bt.com Mon Mar 26 10:25:50 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 11:25:50 +0100 Subject: [Tutor] Is Python really dynamic ? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D669@mbtlipnt02.btlabs.bt.co.uk> > I had no clue... until i run this from the command line, > where i got the correct results, and not from IDLE. > > Could someone explain me why IDLE is messing everything up ? I can't explain it but I can say that neither IDLE not PythonWin are great at reloading as you'd expect. They are both fine for general interactive use but if anything strange happens I find that it's always a good idea to try it at a command line prompt too... Alan G From alan.gauld@bt.com Mon Mar 26 10:46:51 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 11:46:51 +0100 Subject: [Tutor] OOP design (w/ example :-) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66A@mbtlipnt02.btlabs.bt.co.uk> > Specifically, I often want to put my students in > small groups to work on class work, labs, or > whatever we're working on that day. It's too time > consuming to go through a big process every day > and I want to rearrange the groups often. > To keep things simple for now, I'm storing the students in a > simple text file with last name, first name, and gender. Seems fine. Maybe you want to store the current groupings too? Can they be in more than one group at a time? eg for different class periods or projects? If not then a single extra field with the current group name should do it. > I'd like to try a OOP approach, but one of the things I > struggle with is the initial design stage. I've asked > about this before and I've done some reading, but I > still haven't found a way of thinking about problems > like this that make a lot of sense to me. As ever you need to have an idea of the functionality of the system. What do you want to do with the various objects - then on that basis assign their responsibilities. For examnple you need to assign students to groups and move students from one group to another. You probably want to list the students in a group. Applying the principle that objects should "do it to themselves" (sometimes known as the law of demeter(sp?)) then students probably need a method to setGroup() and/or moveGroup(group). The group objects need a listStudents() method too. What else do you need? > My program, it would seem, would logically have classes the > correspond to individual students, groups, and perhaps > the class as a whole. Maybe. To list available groups perhaps? What would be the class' job? > I've come up with so far: > > class Student: > def __init__(self, ln, fn, gender): > self.ln = ln > self.fn = fn > self.gender = gender self.group = ??? def setGroup(aGroup): ... > class Group: > def __init__(self, studentList): > self.studentList = studentList > def display(studentList): > pass No need to parameterise studentlist its already an attribute. It would be very strange to ask one group to display another groups studentList! > class Roster: > def __init__(self): > pass > def loadFile(self, filename): Now why would the roster hold all the students? It may be sensible depending on what you want to do. If the roster generates a set of new groups then its perfectly valid. Although a more OO way to do this might be to have the __init__ of Student take a filename parameter so that if filename != '' it reads the values from the file. Another case of student doing it to themselves. (One big thing I'd like in Python is the ability to overload constructors ala Delphi/OP, sigh) > f = open(filename, 'r') > while 1: > record = f.readline() > student = string.split(record, ',') > ln = student[0] > fn = student[1] If this fails it suggest a faulty input string. Have you tried putting a print statement in after the split to see what the list looks like? Does it fact have 3 fields for the line that fails? > File "group.py", line 29, in loadFile > fn = student[1] > IndexError: list index out of range As suggested is the problem here... Alan G (catching up on 3 days digests...) From alan.gauld@bt.com Mon Mar 26 10:56:16 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 11:56:16 +0100 Subject: [Tutor] Windows Programs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66B@mbtlipnt02.btlabs.bt.co.uk> > I'm trying to find out how to create windows programs with > python (also perl & c). Every language I learn I always > finish at dos programs Theres a good reason for that - its very hard to write windows programs compared to DOS ones! :-) > and can never find out how to create programs for windows. In Python you want to look at one of the GUI toolkits. The one that comes as standard with Python is Tkinter and there is a good tutorial linked from the Python Web site under the Tkinter area. There is also a book available. However Tkinter is not much like most windows tookits so if you want to use MFC or Delphi or even VB later you probably want to look at wxWindows and its Python version or maybe even the GTk bindings. But there are not nearly so well documented for a beginner. You can also use the MFC classes as found in the winall package (or by default if you have ActiveState rather than BeOpen Python) > (I've come across win 95 assembly language, does this > have to be used some how?) No, avoid assembly like the plague for GUI programming! As a very lightweight intro to GUI programming try the event driven pages of my online tutor and the latter section of the case study. (I'm toying with the idea of adding a Tkinter topic to the tutor to explain it better) Alan G http://www.crosswinds.net/~agauld From alan.gauld@bt.com Mon Mar 26 11:03:20 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 12:03:20 +0100 Subject: [Tutor] Windows Programs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66C@mbtlipnt02.btlabs.bt.co.uk> > Borland and Microsoft offer drag-and-drop development > environments for GUI development in C++ but... I don't think even M$ would claim their C++ environment was drag and drop! Certainly not in the way that Borlands C++ Builder is. But the easiest way to develop GUI prpgrams on windows is using either VB or Delphi. Delphi has the edge for programmers(especially Python ones) but VB is easier for beginners and usually is slightly ahead in supporting the latest M$ tehnologies (like COM+ etc) Python can be made to work with both. See the win32 O'Reilly book for details. Alan G. From alan.gauld@bt.com Mon Mar 26 11:05:12 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 12:05:12 +0100 Subject: [Tutor] Variables in regular expressions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66D@mbtlipnt02.btlabs.bt.co.uk> > >>> import re > >>> matchstr = 'fleas' > >>> sentence = 'my dog has fleas' > >>> if re.match(matchstr, sentence): print "Yes, it works." > ... try re.search() match() only matches if 'fleas' is at the start of the line. Alan G From wheelege@tsn.cc Mon Mar 26 11:10:27 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 26 Mar 2001 21:10:27 +1000 Subject: [Tutor] Windows Programs References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66B@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <046801c0b5e5$5d358260$0200a8c0@ACE> <snip!> > As a very lightweight intro to GUI programming try the > event driven pages of my online tutor and the latter > section of the case study. (I'm toying with the idea > of adding a Tkinter topic to the tutor to explain it > better) > <beg>Please do! It would help out the growing masses of Tkinter beginners incredibly - especially if it was of the same quality as the rest of your tutorial :)</beg> Anywho, I'm serious. I'm past the stage of total beginner, but I can say that I really would of liked a Tkinter section of your tutorial when I started programming python - as it was I did your tutorial, argued with the Grayson book for a week, read Fredrik's docs, argued with the Grayson book for a week, then started the Grayson book. Not that it is a bad book - it's a superb book, it's just really hard to get for people who only started python-ing 2 weeks beforehand. Alot of people I know have given up Tkinter because of the advanced-ness of the Grayson book - they just need a stepping up stone. Hmmm....of course you could try your hand at writing a book like Mr Grayson - except starting of a little less extreme :) Thanks, Glen. From alan.gauld@bt.com Mon Mar 26 11:12:15 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 12:12:15 +0100 Subject: [Tutor] mutable strings? [and global stuff] Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66E@mbtlipnt02.btlabs.bt.co.uk> > semi-useful in the process. I'm trying to write a > little script to use for interactively renaming files, > want to be able to navigate through my file system, > and I need some type of changeable string, so I can > keep track of where I am. I wonder if you are confusing variables and references/names? You need a name that can point to several different strings. You don't need to change the strings themselves you need to change which string the name points at. eg foo = "myfile.mp3" # do some messing here foo = "newfile.mp3" # do more messing foo = foo[:-3]+"txt" # change foo to store newfile.txt Is that what you mean? In the last line I didn't change the string "newfile.mp3" but I did create a new string based on the original. Does that meet your needs? Do you really need to change the original string? Thats very unusual... Alan G. From alan.gauld@bt.com Mon Mar 26 11:20:50 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 12:20:50 +0100 Subject: [Tutor] Windows systems for Python Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D66F@mbtlipnt02.btlabs.bt.co.uk> > This system has a better native look and feel than TKinter > widgets do (at least in a (win)Doze environment). I can see the soimilarity of wxWindows to the conventional windoze programming style but I don't see the difference in look n feel... That may be because I use such a mix of look n feels on my desktop(Openlook, Motif, Windows 3.1/95/98 etc) that I just don't notice the subtleties. Can someone give me a list of the differences between Tkinter and Windoze? I can't see any major differences. [ The old Tk widgets were very Motif like but since Tk 8.0 came out I can't see a lot of differences? ] Just curious, Alan g. From XQ.Xia@ccsr.cam.ac.uk Mon Mar 26 13:49:34 2001 From: XQ.Xia@ccsr.cam.ac.uk (XIA Xiao-Qin) Date: Mon, 26 Mar 2001 14:49:34 +0100 Subject: [Tutor] enquiry Message-ID: <200103261449340590.1ACCCF51@mail-serv.ccsr.cam.ac.uk> --=====_98561457441=_ Content-Type: text/plain; charset="WINDOWS-1250" Content-Transfer-Encoding: quoted-printable Dear Sir/Madam, Is there any method to display words vertically in Tkinter? It is necessary= when drawing the notes to y-axis of a chart on a canvas. Many thanks, Xia XQ --=====_98561457441=_ Content-Type: text/html; charset="WINDOWS-1250" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1250"> <META content="MSHTML 5.50.4134.600" name=GENERATOR></HEAD> <BODY style="FONT-FAMILY: Arial" text=#000000 bgColor=#ffffff> <DIV><FONT size=2>Dear Sir/Madam,</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>Is there any method to display words vertically in Tkinter? It is necessary when drawing the notes to y-axis of a chart on a canvas.</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>Many thanks,</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>Xia XQ</FONT></DIV></BODY></HTML> --=====_98561457441=_-- From gibbs05@flash.net Mon Mar 26 15:27:31 2001 From: gibbs05@flash.net (Harry Kattz) Date: Mon, 26 Mar 2001 09:27:31 -0600 Subject: [Tutor] OOP design - Law of Demeter References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66A@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <001f01c0b609$50b3dea0$e4de3040@gibbs05> Greetings All, > For examnple you need to assign students to groups and > move students from one group to another. You probably > want to list the students in a group. Applying the > principle that objects should "do it to themselves" > (sometimes known as the law of demeter(sp?)) then > students probably need a method to setGroup() and/or > moveGroup(group). The group objects need a listStudents() > method too. Here's the Law of Demeter: Do not refer to class C in method m unless C is the type of 1). an instance variable; 2). an argument of m; 3). an object created in m; 4). a global variable. Good luck, Sam From tim@johnsons-web.com Mon Mar 26 16:35:52 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 26 Mar 2001 07:35:52 -0900 Subject: [Tutor] Windows Programs References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66C@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01032607413804.16086@shecom> On Mon, 26 Mar 2001, alan.gauld@bt.com wrote: > > Borland and Microsoft offer drag-and-drop development > > environments for GUI development in C++ but... > > I don't think even M$ would claim their C++ environment > was drag and drop! Certainly not in the way that > Borlands C++ Builder is. I mispoke.... Alan is obviously more familiar with M$ VC++ than I.... > But the easiest way to develop GUI prpgrams on windows > is using either VB or Delphi. Delphi has the edge for > programmers(especially Python ones) but VB is easier > for beginners and usually is slightly ahead in > supporting the latest M$ tehnologies (like COM+ etc) What we are talking about here are not "free" like python. However, if one just happens to have Microsoft Word or Access, VBA (subset of VB) is available as sort of a a "macro" language, running within Microsoft Office suite Applications. It would be a good way to get acquainted with that language. > Python can be made to work with both. See the win32 > O'Reilly book for details. > > Alan G. -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Mon Mar 26 16:44:23 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 26 Mar 2001 07:44:23 -0900 Subject: [Tutor] Windows Programs References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66B@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01032607555005.16086@shecom> On Mon, 26 Mar 2001, alan.gauld@bt.com wrote: > Theres a good reason for that - its very hard to write windows programs > compared to DOS ones! > > :-) > > > and can never find out how to create programs for windows. > > In Python you want to look at one of the GUI toolkits. > The one that comes as standard with Python is Tkinter and > there is a good tutorial linked from the Python Web site > under the Tkinter area. There is also a book available. > > However Tkinter is not much like most windows tookits so > if you want to use MFC or Delphi or even VB later you > probably want to look at wxWindows and its Python version > or maybe even the GTk bindings. But there are not nearly > so well documented for a beginner. > No, avoid assembly like the plague for GUI programming! > > As a very lightweight intro to GUI programming try the > event driven pages of my online tutor and the latter > section of the case study. (I'm toying with the idea > of adding a Tkinter topic to the tutor to explain it > better) ==>> I would strongly urge Alan to follow this course, (if you have the time, Alan). Perhaps you may wish to cover both of tkinter and wxWindows? I have found much material in the Sams book of an introductory nature, and much in depth with the Grayson. The problem I have found with both is that modifications to existing code is difficult. some of the documentation seems contradictory and counter-intuitive. Building on this could be helpful to the learner. Given the relentless increase in clock speed, the overhead associated with interpreters is becoming less of an issue and many users are would be open to full-fledged "windows" applications driven by Python. -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Mon Mar 26 16:58:59 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 26 Mar 2001 07:58:59 -0900 Subject: [Tutor] Windows Programs vs. Text-Cell Graphics References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66C@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01032608063206.16086@shecom> One of the topics I have never seen covered in this list is that of text-cell graphics. On the linux side, Midnight Command and Nftp are good examples of this approach. Windows side there is Ztree, which is one of the best all-around applications ever written, IMHO. Several years ago, I was asked by a construction firm to write an estimator program. My client did not want the application to be "mouse enabled" at all. He did want maximum speed and something like a gui interface. The result was written in C and very fast even on a 486/100. Personally, I think it would be great to see an API in python to such an effect. Awful busy right now, but here's my question: Is there anything like this available to python? If not, how does one write a color/character pair to video memory in python? That is where it starts. -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From alan.gauld@bt.com Mon Mar 26 16:57:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Mar 2001 17:57:25 +0100 Subject: [Tutor] Windows Programs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D673@mbtlipnt02.btlabs.bt.co.uk> > > section of the case study. (I'm toying with the idea > > of adding a Tkinter topic to the tutor to explain it > ==>> > I would strongly urge Alan to follow this course, > (if you have the time, Alan). OK, It was a slow day at work so the first section of the topic is there - 'hello world', what else :-) Also some introductory concepts and definitions. Very early days but it's on my website at: http://www.crosswinds.net/~agauld/tutgui.htm Feedback on approach, level etc is, as ever, welcome. I'm aiming at a kind of expanded "Life Preserver" level for those familiar with Matt Conway's opus... > Perhaps you may wish to cover both of tkinter and wxWindows? I think Tkinter is quite enough thank you :-) Alan g. PS. I'm still trying to upload it - crosswinds ftp server is awfully slow! Try it later and it should be there. From scarblac@pino.selwerd.nl Mon Mar 26 17:20:21 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 26 Mar 2001 19:20:21 +0200 Subject: [Tutor] Windows Programs vs. Text-Cell Graphics In-Reply-To: <01032608063206.16086@shecom>; from tim@johnsons-web.com on Mon, Mar 26, 2001 at 07:58:59AM -0900 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66C@mbtlipnt02.btlabs.bt.co.uk> <01032608063206.16086@shecom> Message-ID: <20010326192021.A23527@pino.selwerd.nl> On Mon, Mar 26, 2001 at 07:58:59AM -0900, Tim Johnson wrote: > On the linux side, Midnight Command and Nftp are good > examples of this approach. > > Windows side there is Ztree, which is one of the best all-around > applications ever written, IMHO. > > Several years ago, I was asked by a construction firm to write an > estimator program. My client did not want the application > to be "mouse enabled" at all. He did want maximum speed and > something like a gui interface. > The result was written in C and very fast even on a 486/100. > Personally, I think it would be great to see an API in python > to such an effect. > > Awful busy right now, but here's my question: > Is there anything like this available to python? > > If not, how does one write a color/character pair to video memory > in python? That is where it starts. Ncurses. Curses (and ncurses, "new curses") is a library for putting text on some place on a terminal (or screen). Writing directly to video memory is silly, this is not the 80s... Curses is cross platform, works over Telnet, etc. You can build a Unix Python with curses easily (it's standard on Unix I think) but it might be a little more work to get it for Windows (but still not hard). Midnight Commander also uses ncurses, I think. The game 'rogue' was developed by the same authors as curses, and they added features to rogue that used new curses features, and they added things to curses as the game needed them... creating a whole genre of cool games leading up to NetHack, ZAngband, et cetera. -- Remco Gerlich From deirdre@deirdre.net Mon Mar 26 17:45:40 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 26 Mar 2001 09:45:40 -0800 (PST) Subject: [Tutor] Windows Programs vs. Text-Cell Graphics In-Reply-To: <20010326192021.A23527@pino.selwerd.nl> Message-ID: <Pine.LNX.4.31.0103260944490.14332-100000@emperor.deirdre.org> On Mon, 26 Mar 2001, Remco Gerlich wrote: > Ncurses. Curses (and ncurses, "new curses") is a library for putting > text on some place on a terminal (or screen). Writing directly to > video memory is silly, this is not the 80s... Curses is cross > platform, works over Telnet, etc. Ncurses is wonderful, but the python support for it is very poorly documented. I once took a stab at it and basically just decided to give up for now. I prefer ncurses apps actually. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From van@lindbergs.org Mon Mar 26 19:00:15 2001 From: van@lindbergs.org (VanL) Date: Mon, 26 Mar 2001 12:00:15 -0700 Subject: [Tutor] C Implementation of data structures Message-ID: <3ABF91BF.6E3F5866@lindbergs.org> Hello, I was wondering about the underlying (C) implementation of tuples and dictionaries. I know that lists are dynamically sized arrays, and as such are O(1) for retrieval and O(n) for search and insert operations. What about tuples and dictionaries? Dictionaries would seem to fit naturally onto hash tables, but a note in Programming Python mentioned that the __getattr__ method, which allows searching by key, works by repeatedly indexing the object. This would suggest another array. In a similar vein, I don't know how user-defined data structures are implemented either. Conceivably, an (apparently) efficient structure could be hampered by an inefficient (at least for the purpose) underlying implementation. I'm not trying to call Guido's experitise as a language designer into question, I'm just trying to understand better how things fit together. Could anyone enlighten me on the underlying implementation of Python's data structures? Thanks, V From shaleh@valinux.com Mon Mar 26 19:10:18 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 26 Mar 2001 11:10:18 -0800 (PST) Subject: [Tutor] C Implementation of data structures In-Reply-To: <3ABF91BF.6E3F5866@lindbergs.org> Message-ID: <XFMail.20010326111018.shaleh@valinux.com> On 26-Mar-2001 VanL wrote: > Hello, > > I was wondering about the underlying (C) implementation of tuples and > dictionaries. I know that lists are dynamically sized arrays, and as > such are O(1) for retrieval and O(n) for search and insert operations. > > What about tuples and dictionaries? Dictionaries would seem to fit > naturally onto hash tables, but a note in Programming Python mentioned > that the __getattr__ method, which allows searching by key, works by > repeatedly indexing the object. This would suggest another array. > look in the source of python, the Objects/ directory. You should find the answers you seek there. Like the .py files, the C source is fairly legible and well commented. From britt_green@hotmail.com Mon Mar 26 19:50:40 2001 From: britt_green@hotmail.com (Britt Green) Date: Mon, 26 Mar 2001 11:50:40 -0800 Subject: [Tutor] Done at Last! Message-ID: <F258lxZrRx6BUPJRhJ60000cbe8@hotmail.com> Alright. I'm done with my first program. It works...most of the time! :) I would really appreciate some feedback on it because I know how ugly it is. Also, it tends to crash every now and then. I've attatched the error message Python gives me at the bottom. Basically, the program goes into our FTP site and checks to be sure that a restaurant uploaded a backup of its data, and that its size is +/- 15 percent of the average size (anything bigger/smaller means the backup.zip was probably corrupt.) How it works is this: the user selects the city to check the backup. The program opens the folder for that city (ie: ftp.cwd(boston/)). Once in that folder, it compiles a list of directories that it will go into and check. Once it has this list, it begins to go into them one by one. Inside a one of these restaurant folders, it first checks to see if a backup was done today. It matches the date string (ie: Mar 26). If this datestring wasn't found for any of the files, no backup was done for that day, and it gets noted. If the string was found, it then checks to be sure that the file for that day was a backup (ie: dayofweek.zip). Sometimes people upload floorplans and whatnot. If it found a backup for today, it will then check to be sure the size looks good. Finally, it prints out a listing of the results for the restaurants. I know this program is ugly and very amateurish, but hey, its my first one! If anyone can point out how to improve it, I would be really grateful. Thanks! Britt import string, re, time from ftplib import FTP def getDayOfWeek(): #Thanks to Alan Gauld and his book for this days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] theTime = time.localtime(time.time() ) DayNum = theTime[6] return days[DayNum] #Get the date of the file to look for def todaysDate(): months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] theTime = time.localtime(time.time() ) month = theTime[1] month = month - 1 theTime = time.localtime(time.time() ) day = theTime[2] if day < 10: theDate = months[month] + ' ' + str(day) else: theDate = months[month] + ' ' + str(day) return theDate #This function courtesy of Danny Yoo def getftplist(ftp): ftp.sendcmd('TYPE A') conn = ftp.transfercmd('LIST') resp = conn.makefile('r').read() conn.close() ftp.voidresp() return resp #This function checks to be sure the file is not an abnormal size def checkSize(file, x): validDays = ['monday.zip', 'tuesday.zip', 'wednesday.zip', 'thursday.zip', 'friday.zip', 'saturday.zip', 'sunday.zip', 'Monday.zip', 'Tuesday.zip', 'Wednesday.zip', 'Thursday.zip', 'Friday.zip', 'Saturday.zip', 'Sunday.zip'] myFile = file theFiles = x fileSize = ftp.size(myFile) allTheFiles = [] totalSize = 0 sizeList = [] #This block seeks that the file with today's date fits one in the #validDays list. for item in theFiles: splitItem = string.split(item) for z in range(len(splitItem)): if z == 8: if splitItem[8] in validDays: allTheFiles.append(splitItem[8]) #Get the total size of all the files in the directory for file in allTheFiles: totalSize += ftp.size(file) #Find the average size of the files in the directory averageSize = totalSize / len(allTheFiles) #Is the file too little, too big or just right? if (averageSize * .85) > fileSize: sizeList = [1, fileSize, averageSize] return sizeList elif (averageSize * 1.15) < fileSize: sizeList = [2, fileSize, averageSize] return sizeList else: sizeList = [3] return sizeList #As its name implies, this function checks to see if the file found has a valid #size. Files +/- 15% will be flagged. #Some bitch capitlized the first letter of some of the files just to break #my code! def getsTodaysFile(today, dirListing): todaysFile = getDayOfWeek() todaysFile = todaysFile + ".zip" dateString = today theFiles = string.split(dirListing, '\n') filesToSize = [] #This routine extracts the dir listing with today's date on it for x in theFiles: if re.search(dateString, x): filesToSize.append(x) #Sometimes there will be more than one file for today. Lets get #the correct one and size it for item in filesToSize: y = string.split(item) for z in range(len(y)): if z == 8: if string.lower(y[8]) == todaysFile: correctFileName = y[8] rv = checkSize(correctFileName, theFiles) return rv def makeChoice(): choices = ['atl/', 'austin/', 'boston/', 'chicago/', 'dallas/', 'dc/', 'galveston/', 'houston/', 'la/', 'miami/', 'nola/', 'ny/', 'phl/', 'portland/', 'sd/', 'seattle/', 'sf/', 'slc/', 'Vail/'] print """ Which cities would you like to check? 1) Atlanta 2) Boston 3) Chicago 4) DC 5) Los Angeles 6) Miami 7) New Orleans 8) New York 9) Philidelphia 10) Portland and Vail 11) San Diego 12) Seattle 13) San Francisco 14) Salt Lake City 15) Texas 16) All """ try: answer = input("-->") if answer == 1: ftpdirs = ['atl/'] return ftpdirs elif answer == 2: ftpdirs = ['boston/'] return ftpdirs elif answer == 3: ftpdirs = ['chicago/'] return ftpdirs elif answer == 4: ftpdirs = ['dc/'] return ftpdirs elif answer == 5: ftpdirs = ['la/'] return ftpdirs elif answer == 6: ftpdirs = ['miami/'] return ftpdirs elif answer == 7: ftpdirs = ['nola/'] return ftpdirs elif answer == 8: ftpdirs = ['ny/'] return ftpdirs elif answer == 9: ftpdirs = ['phl/'] return ftpdirs elif answer == 10: ftpdirs = ['portland/', 'Vail/'] return ftpdirs elif answer == 11: ftpdirs = ['sd/'] return ftpdirs elif answer == 12: ftpdirs = ['seattle/'] return ftpdirs elif answer == 13: ftpdirs = ['sf/'] return ftpdirs elif answer == 14: ftpdirs = ['slc/'] return ftpdirs elif answer == 15: ftpdirs = ['austin/', 'dallas/', 'galveston/', 'houston/'] return ftpdirs elif answer == 16: ftpdirs = choices return ftpdirs else: print "Lets choose a number in the menu, sparky!" makeChoice() except (NameError): print "NameError" makeChoice() if __name__ == '__main__': dirList = makeChoice() dirsToCheck = [] dirsWithNoFiles = [] dirTooSmall = [] dirTooBig = [] fileJustRight = [] today = todaysDate() fileIntegrity = [] ftp = FTP('ftp.opentable.com', 'account', 'password') #This block comes up with a list of directories to enter from the root dir for element in dirList: print "Getting a list of directories to check for " + element ftp.cwd(element) dirListing = getftplist(ftp) splitListing = string.split(dirListing, '\n') for item in splitListing: moreSplit = string.split(item) dirsToCheck.append(element + string.join(moreSplit[8:])) print dirsToCheck ftp.cwd('..') for directory in dirsToCheck: ftp.cwd(directory) dirListing = getftplist(ftp) #This checks to see if a file with today's date is in the directory m = re.search(today, dirListing) if m: #If a file with todays date is found: print directory + " backed up today." fileIntegrity = getsTodaysFile(today, dirListing) if fileIntegrity == [3]: fileJustRight.append(directory) else: if fileIntegrity != None: if fileIntegrity[0] == 1: small = directory + '\t\t' + str(fileIntegrity[1]) + '\t' + str(fileIntegrity[2]) dirTooSmall.append(small) else: big = directory + '\t\t' + str(fileIntegrity[1]) + '\t' + str(fileIntegrity[2]) dirTooBig.append(big) else:#A file with today's date was not found in this directory. print "No file for today in " + directory dirsWithNoFiles.append(directory) ftp.cwd('/') print "\n" + "Done checking files." + "\n" print "These directories did not have a backup today." for i in dirsWithNoFiles: print i print "\n" print "The files in these directories look a bit small." for z in dirTooSmall: print z print "\n" print "The files in these directories look a bit big." for k in dirTooBig: print k print "\n" ftp.quit() #End of program All works good, except I get this error message pretty regularly. I can't seem to figure out whats causing it. More than anything else, I'd love a solution to this difficulty. Traceback (innermost last): File "C:/Python20/Code/Copy of dirs.py", line 220, in ? dirListing = getftplist(ftp) File "C:/Python20/Code/Copy of dirs.py", line 36, in getftplist conn = ftp.transfercmd('LIST') File "c:\python20\lib\ftplib.py", line 297, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "c:\python20\lib\ftplib.py", line 283, in ntransfercmd sock = self.makeport() File "c:\python20\lib\ftplib.py", line 254, in makeport resp = self.sendport(host, port) File "c:\python20\lib\ftplib.py", line 244, in sendport return self.voidcmd(cmd) File "c:\python20\lib\ftplib.py", line 234, in voidcmd return self.voidresp() File "c:\python20\lib\ftplib.py", line 209, in voidresp resp = self.getresp() File "c:\python20\lib\ftplib.py", line 195, in getresp resp = self.getmultiline() File "c:\python20\lib\ftplib.py", line 181, in getmultiline line = self.getline() File "c:\python20\lib\ftplib.py", line 168, in getline line = self.file.readline() File "c:\python20\lib\socket.py", line 221, in readline new = self._sock.recv(self._rbufsize) error: (10054, 'Connection reset by peer') _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From britt_green@hotmail.com Mon Mar 26 19:50:50 2001 From: britt_green@hotmail.com (Britt Green) Date: Mon, 26 Mar 2001 11:50:50 -0800 Subject: [Tutor] Done at Last! Message-ID: <F259Admb9syeaib8z6c000038bc@hotmail.com> Alright. I'm done with my first program. It works...most of the time! :) I would really appreciate some feedback on it because I know how ugly it is. Also, it tends to crash every now and then. I've attatched the error message Python gives me at the bottom. Basically, the program goes into our FTP site and checks to be sure that a restaurant uploaded a backup of its data, and that its size is +/- 15 percent of the average size (anything bigger/smaller means the backup.zip was probably corrupt.) How it works is this: the user selects the city to check the backup. The program opens the folder for that city (ie: ftp.cwd(boston/)). Once in that folder, it compiles a list of directories that it will go into and check. Once it has this list, it begins to go into them one by one. Inside a one of these restaurant folders, it first checks to see if a backup was done today. It matches the date string (ie: Mar 26). If this datestring wasn't found for any of the files, no backup was done for that day, and it gets noted. If the string was found, it then checks to be sure that the file for that day was a backup (ie: dayofweek.zip). Sometimes people upload floorplans and whatnot. If it found a backup for today, it will then check to be sure the size looks good. Finally, it prints out a listing of the results for the restaurants. I know this program is ugly and very amateurish, but hey, its my first one! If anyone can point out how to improve it, I would be really grateful. Thanks! Britt import string, re, time from ftplib import FTP def getDayOfWeek(): #Thanks to Alan Gauld and his book for this days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] theTime = time.localtime(time.time() ) DayNum = theTime[6] return days[DayNum] #Get the date of the file to look for def todaysDate(): months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] theTime = time.localtime(time.time() ) month = theTime[1] month = month - 1 theTime = time.localtime(time.time() ) day = theTime[2] if day < 10: theDate = months[month] + ' ' + str(day) else: theDate = months[month] + ' ' + str(day) return theDate #This function courtesy of Danny Yoo def getftplist(ftp): ftp.sendcmd('TYPE A') conn = ftp.transfercmd('LIST') resp = conn.makefile('r').read() conn.close() ftp.voidresp() return resp #This function checks to be sure the file is not an abnormal size def checkSize(file, x): validDays = ['monday.zip', 'tuesday.zip', 'wednesday.zip', 'thursday.zip', 'friday.zip', 'saturday.zip', 'sunday.zip', 'Monday.zip', 'Tuesday.zip', 'Wednesday.zip', 'Thursday.zip', 'Friday.zip', 'Saturday.zip', 'Sunday.zip'] myFile = file theFiles = x fileSize = ftp.size(myFile) allTheFiles = [] totalSize = 0 sizeList = [] #This block seeks that the file with today's date fits one in the #validDays list. for item in theFiles: splitItem = string.split(item) for z in range(len(splitItem)): if z == 8: if splitItem[8] in validDays: allTheFiles.append(splitItem[8]) #Get the total size of all the files in the directory for file in allTheFiles: totalSize += ftp.size(file) #Find the average size of the files in the directory averageSize = totalSize / len(allTheFiles) #Is the file too little, too big or just right? if (averageSize * .85) > fileSize: sizeList = [1, fileSize, averageSize] return sizeList elif (averageSize * 1.15) < fileSize: sizeList = [2, fileSize, averageSize] return sizeList else: sizeList = [3] return sizeList #As its name implies, this function checks to see if the file found has a valid #size. Files +/- 15% will be flagged. #Some bitch capitlized the first letter of some of the files just to break #my code! def getsTodaysFile(today, dirListing): todaysFile = getDayOfWeek() todaysFile = todaysFile + ".zip" dateString = today theFiles = string.split(dirListing, '\n') filesToSize = [] #This routine extracts the dir listing with today's date on it for x in theFiles: if re.search(dateString, x): filesToSize.append(x) #Sometimes there will be more than one file for today. Lets get #the correct one and size it for item in filesToSize: y = string.split(item) for z in range(len(y)): if z == 8: if string.lower(y[8]) == todaysFile: correctFileName = y[8] rv = checkSize(correctFileName, theFiles) return rv def makeChoice(): choices = ['atl/', 'austin/', 'boston/', 'chicago/', 'dallas/', 'dc/', 'galveston/', 'houston/', 'la/', 'miami/', 'nola/', 'ny/', 'phl/', 'portland/', 'sd/', 'seattle/', 'sf/', 'slc/', 'Vail/'] print """ Which cities would you like to check? 1) Atlanta 2) Boston 3) Chicago 4) DC 5) Los Angeles 6) Miami 7) New Orleans 8) New York 9) Philidelphia 10) Portland and Vail 11) San Diego 12) Seattle 13) San Francisco 14) Salt Lake City 15) Texas 16) All """ try: answer = input("-->") if answer == 1: ftpdirs = ['atl/'] return ftpdirs elif answer == 2: ftpdirs = ['boston/'] return ftpdirs elif answer == 3: ftpdirs = ['chicago/'] return ftpdirs elif answer == 4: ftpdirs = ['dc/'] return ftpdirs elif answer == 5: ftpdirs = ['la/'] return ftpdirs elif answer == 6: ftpdirs = ['miami/'] return ftpdirs elif answer == 7: ftpdirs = ['nola/'] return ftpdirs elif answer == 8: ftpdirs = ['ny/'] return ftpdirs elif answer == 9: ftpdirs = ['phl/'] return ftpdirs elif answer == 10: ftpdirs = ['portland/', 'Vail/'] return ftpdirs elif answer == 11: ftpdirs = ['sd/'] return ftpdirs elif answer == 12: ftpdirs = ['seattle/'] return ftpdirs elif answer == 13: ftpdirs = ['sf/'] return ftpdirs elif answer == 14: ftpdirs = ['slc/'] return ftpdirs elif answer == 15: ftpdirs = ['austin/', 'dallas/', 'galveston/', 'houston/'] return ftpdirs elif answer == 16: ftpdirs = choices return ftpdirs else: print "Lets choose a number in the menu, sparky!" makeChoice() except (NameError): print "NameError" makeChoice() if __name__ == '__main__': dirList = makeChoice() dirsToCheck = [] dirsWithNoFiles = [] dirTooSmall = [] dirTooBig = [] fileJustRight = [] today = todaysDate() fileIntegrity = [] ftp = FTP('ftp.opentable.com', 'account', 'password') #This block comes up with a list of directories to enter from the root dir for element in dirList: print "Getting a list of directories to check for " + element ftp.cwd(element) dirListing = getftplist(ftp) splitListing = string.split(dirListing, '\n') for item in splitListing: moreSplit = string.split(item) dirsToCheck.append(element + string.join(moreSplit[8:])) print dirsToCheck ftp.cwd('..') for directory in dirsToCheck: ftp.cwd(directory) dirListing = getftplist(ftp) #This checks to see if a file with today's date is in the directory m = re.search(today, dirListing) if m: #If a file with todays date is found: print directory + " backed up today." fileIntegrity = getsTodaysFile(today, dirListing) if fileIntegrity == [3]: fileJustRight.append(directory) else: if fileIntegrity != None: if fileIntegrity[0] == 1: small = directory + '\t\t' + str(fileIntegrity[1]) + '\t' + str(fileIntegrity[2]) dirTooSmall.append(small) else: big = directory + '\t\t' + str(fileIntegrity[1]) + '\t' + str(fileIntegrity[2]) dirTooBig.append(big) else:#A file with today's date was not found in this directory. print "No file for today in " + directory dirsWithNoFiles.append(directory) ftp.cwd('/') print "\n" + "Done checking files." + "\n" print "These directories did not have a backup today." for i in dirsWithNoFiles: print i print "\n" print "The files in these directories look a bit small." for z in dirTooSmall: print z print "\n" print "The files in these directories look a bit big." for k in dirTooBig: print k print "\n" ftp.quit() #End of program All works good, except I get this error message pretty regularly. I can't seem to figure out whats causing it. More than anything else, I'd love a solution to this difficulty. Traceback (innermost last): File "C:/Python20/Code/Copy of dirs.py", line 220, in ? dirListing = getftplist(ftp) File "C:/Python20/Code/Copy of dirs.py", line 36, in getftplist conn = ftp.transfercmd('LIST') File "c:\python20\lib\ftplib.py", line 297, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "c:\python20\lib\ftplib.py", line 283, in ntransfercmd sock = self.makeport() File "c:\python20\lib\ftplib.py", line 254, in makeport resp = self.sendport(host, port) File "c:\python20\lib\ftplib.py", line 244, in sendport return self.voidcmd(cmd) File "c:\python20\lib\ftplib.py", line 234, in voidcmd return self.voidresp() File "c:\python20\lib\ftplib.py", line 209, in voidresp resp = self.getresp() File "c:\python20\lib\ftplib.py", line 195, in getresp resp = self.getmultiline() File "c:\python20\lib\ftplib.py", line 181, in getmultiline line = self.getline() File "c:\python20\lib\ftplib.py", line 168, in getline line = self.file.readline() File "c:\python20\lib\socket.py", line 221, in readline new = self._sock.recv(self._rbufsize) error: (10054, 'Connection reset by peer') _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From shaleh@valinux.com Mon Mar 26 20:09:57 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 26 Mar 2001 12:09:57 -0800 (PST) Subject: [Tutor] Done at Last! In-Reply-To: <F259Admb9syeaib8z6c000038bc@hotmail.com> Message-ID: <XFMail.20010326120957.shaleh@valinux.com> > if day < 10: > theDate = months[month] + ' ' + str(day) > else: > theDate = months[month] + ' ' + str(day) > >>> num = 9 >>> long_num = 19 >>> print 'Num %2d\n' % num Num 9 >>> print 'Num %2d\n' % long_num Num 19 using the formatter makes string building easy if you make choices a tuple of the form '(dirname, printName)' you could make the menu easier to change later. So why does Atlanta have its own entry, but Austin, Dallas (and I assume Galveston) get lumped as 'Texas'? cities = (('atl', 'Atlanta'), ('boston', 'Boston')) for i in xrange(len(cities)): print '%d) %s' % (i, cities[i][1]) # print pretty name > def makeChoice(): > choices = ['atl/', 'austin/', 'boston/', 'chicago/', 'dallas/', 'dc/', > 'galveston/', 'houston/', 'la/', 'miami/', 'nola/', 'ny/', > 'phl/', 'portland/', 'sd/', 'seattle/', 'sf/', 'slc/', 'Vail/'] > > print """ > Which cities would you like to check? > 1) Atlanta > 2) Boston > 3) Chicago > 4) DC > 5) Los Angeles > 6) Miami > 7) New Orleans > 8) New York > 9) Philidelphia > 10) Portland and Vail > 11) San Diego > 12) Seattle > 13) San Francisco > 14) Salt Lake City > 15) Texas > 16) All > """ From dsh8290@rit.edu Mon Mar 26 20:19:29 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 26 Mar 2001 15:19:29 -0500 Subject: [Tutor] Re: [Jython-users] How to qualify "super"? In-Reply-To: <3AC0457E.FEE3DE70@pivot.net>; from infotechsys@pivot.net on Tue, Mar 27, 2001 at 02:47:10AM -0500 References: <3ABFF91F.2882B6F2@pivot.net> <20010326101750.B26431@harmony.cs.rit.edu> <3AC0457E.FEE3DE70@pivot.net> Message-ID: <20010326151929.A27072@harmony.cs.rit.edu> The following works for me. >>> import javax >>> class Foo( javax.swing.JFrame ) : ... def __init__( self , title ) : ... javax.swing.JFrame.__init__( self , title ) ... self.setVisible( 1 ) ... >>> frame = Foo( "Hello World" ) >>> It doesn't matter what module you instantiate the class from. One thing to point out -- if you change the widget (is call setTitle or something) after it is visible, it won't be updated unless you call repaint(). Send your code (to the list) and we'll see what isn't right with it. -D On Tue, Mar 27, 2001 at 02:47:10AM -0500, cindy wrote: | Hi, | | Thanks for the reply. I like to change the scenario a bit beacuse I | can't get the title | to show in the title bar. | I have a module name Foo.py and it inherit JFrame thus, class | foo(swing.JFrame). | The init in Foo looks like this def__init__(self, title). | In another module Bar.py I do a composit on Foo thus, self.aFoo = | Foo('title'). | The title doesn't show. When I try to put a constructor in Foo, - | swing.JFrame__init__(self, title), | I get an error tell me that there is a constructor already. | These are small example I could send you if you like. | Thanks. | Wayne From tim@johnsons-web.com Mon Mar 26 21:11:20 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 26 Mar 2001 12:11:20 -0900 Subject: [Tutor] Windows Programs vs. Text-Cell Graphics References: <20010326192021.A23527@pino.selwerd.nl> Message-ID: <01032610335307.16086@shecom> On Mon, 26 Mar 2001, you wrote: > Ncurses. Curses (and ncurses, "new curses") is a library for putting text on > some place on a terminal (or screen). Writing directly to video memory is > silly, this is not the 80s... Not silly on a 16-bit app. Very fast and clean actually.... But I don't do 16-bit anymore...... > Curses is cross platform, works over Telnet, > etc. Just curious, but I'd like to see the source code. Where is it available? Thanks -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From dyoo@hkn.eecs.berkeley.edu Mon Mar 26 21:18:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 26 Mar 2001 13:18:11 -0800 (PST) Subject: [Tutor] C Implementation of data structures In-Reply-To: <3ABF91BF.6E3F5866@lindbergs.org> Message-ID: <Pine.LNX.4.21.0103261305070.19098-100000@hkn.eecs.berkeley.edu> On Mon, 26 Mar 2001, VanL wrote: > What about tuples and dictionaries? Dictionaries would seem to fit > naturally onto hash tables, but a note in Programming Python mentioned > that the __getattr__ method, which allows searching by key, works by > repeatedly indexing the object. This would suggest another array. I believe that tuples are similar to lists: they're dynamically allocated arrays, but they have less overhead since they're guaranteed not to grow. About the question on dictionaries... hmm... weird... My guess is that Mark Lutz was talking about linear probing when he says "repeatedly indexing". As far as I know, dictionaries are hashtables; we can see this because the keys of hashtables work only if they support the hash() function. > In a similar vein, I don't know how user-defined data structures are > implemented either. Conceivably, an (apparently) efficient structure > could be hampered by an inefficient (at least for the purpose) > underlying implementation. At the moment, they're implemented with hashtables; that is, every instance of a class has an internal hashtable (that's what 'self' is!). One advantage of this is that we can dynamically modify instances of our classes and add new stuff to them. For example: ### class Proxy: pass x = Proxy() x.name = 'Roxanne' ### works because it's not hardcoded like a C structure. Of course, this means that there IS overhead involved, but that's usually not a concern until we start working with code that really needs to run fast. In those cases, that's where C extensions come into play. > I'm not trying to call Guido's experitise as a language designer into > question, I'm just trying to understand better how things fit > together. Could anyone enlighten me on the underlying implementation > of Python's data structures? As Sean has mentioned, play around with the underlying C source code. The Python/C API Reference Manual might be helpful for you: http://python.org/doc/current/api/api.html since it'll point out the important functions used in manipulating these data structures. From lha2@columbia.edu Mon Mar 26 23:48:17 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Mon, 26 Mar 2001 18:48:17 -0500 Subject: [Tutor] Done at Last! References: <E14hd30-0003oC-00@mail.python.org> Message-ID: <3ABFD541.576D5AED@mail.verizon.net> > Message: 7 > From: "Britt Green" <britt_green@hotmail.com> > To: tutor@python.org > Date: Mon, 26 Mar 2001 11:50:50 -0800 > Subject: [Tutor] Done at Last! > > Alright. I'm done with my first program. It works...most of the time! :) I > would really appreciate some feedback on it [snip] > try: > answer = input("-->") > > if answer == 1: > ftpdirs = ['atl/'] > return ftpdirs > elif answer == 2: > ftpdirs = ['boston/'] > return ftpdirs > elif answer == 3: > ftpdirs = ['chicago/'] > return ftpdirs > elif answer == 4: > ftpdirs = ['dc/'] > return ftpdirs > elif answer == 5: > ftpdirs = ['la/'] > return ftpdirs > elif answer == 6: > ftpdirs = ['miami/'] > return ftpdirs > elif answer == 7: > ftpdirs = ['nola/'] > return ftpdirs > elif answer == 8: > ftpdirs = ['ny/'] > return ftpdirs > elif answer == 9: > ftpdirs = ['phl/'] > return ftpdirs > elif answer == 10: > ftpdirs = ['portland/', 'Vail/'] > return ftpdirs > elif answer == 11: > ftpdirs = ['sd/'] > return ftpdirs > elif answer == 12: > ftpdirs = ['seattle/'] > return ftpdirs > elif answer == 13: > ftpdirs = ['sf/'] > return ftpdirs > elif answer == 14: > ftpdirs = ['slc/'] > return ftpdirs > elif answer == 15: > ftpdirs = ['austin/', 'dallas/', 'galveston/', 'houston/'] > return ftpdirs > elif answer == 16: > ftpdirs = choices > return ftpdirs > else: > print "Lets choose a number in the menu, sparky!" > makeChoice() for this chunk, I think you can implement a dictionary; maybe something along the lines of ftpdirs = {1:['atl/'], 2:['boston/'], #etcetc#, 15:['austin/', 'dallas/', 'galveston/', 'houston'], 16:choices} # up high in the code and then where you have all those elifs: return ftpdirs[answer] if that makes any sense, and if no one else said the same thing while I was waiting for digest form to digest. From dsh8290@rit.edu Mon Mar 26 23:49:48 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 26 Mar 2001 18:49:48 -0500 Subject: [Tutor] Re: [Jython-users] (oops) In-Reply-To: <20010326151929.A27072@harmony.cs.rit.edu>; from dsh8290@rit.edu on Mon, Mar 26, 2001 at 03:19:29PM -0500 References: <3ABFF91F.2882B6F2@pivot.net> <20010326101750.B26431@harmony.cs.rit.edu> <3AC0457E.FEE3DE70@pivot.net> <"from infotechsys"@pivot.net> <20010326151929.A27072@harmony.cs.rit.edu> Message-ID: <20010326184948.A28884@harmony.cs.rit.edu> Oops, sorry, I got a private repsonse and tried to bring it back to the list and got the wrong list. On Mon, Mar 26, 2001 at 03:19:29PM -0500, D-Man wrote: some nonsense the the tutor list probably doesn't care about <wink> From vlindberg@verio.net Tue Mar 27 00:13:41 2001 From: vlindberg@verio.net (VanL) Date: Mon, 26 Mar 2001 17:13:41 -0700 Subject: [Tutor] ftplib and zipfile question Message-ID: <3ABFDB35.7A50C5BD@verio.net> Hello, I am writing a program to download something from an ftp site. I have checked the ftplib documentation and I know that I need the retrbinary command. However, the docs say: retrbinary (command, callback[, maxblocksize[, rest]]) Retrieve a file in binary transfer mode. command should be an appropriate "RETR" command, i.e. 'RETR filename'. The callback function is called for each block of data received, with a single string argument giving the data block .... What is the callback command? Could anyone give an example of the use of this command to download a file and save it locally? Further, does python have anything like the Unix pipe? The file in question is a zip file. If possible, I would rather just pipe it through to the zipfile module. In short, is this possible? ++++++++++++++++++++++++++++++++++++++ import zlib, zipfile from ftplib import FTP ftp = FTP('mysite.com', 'anonymous', 'me@myaddress.com') ftp.cwd('newdir') myzip = Zipfile((ftp.retrbinary('binaryfile.zip', OTHER_ARGS_HERE), 'r') for filename in myzip.namelist: file = open(filename, 'w') file.write(myzip.read(filename)) ftp.close() +++++++++++++++++++++++++++++++++++++++++ If possible, I would like to process the file as it goes through, without either incurring huge memory usage or having to save the file to disk. If I have to choose one or the other, tho, I would store the file to disk. From shaleh@valinux.com Tue Mar 27 00:31:39 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 26 Mar 2001 16:31:39 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens Message-ID: <XFMail.20010326163139.shaleh@valinux.com> SO, I have a class Foo which maps to a directory. When you create Foo, it makes a directory of the form /tmp/foo-pid. I would like for this dir to be removed when the object leaves scope (i.e. when __del__ is called). However this does not seem to work if the object exists when python exists. Any ideas? From syrinx@simplecom.net Tue Mar 27 01:38:44 2001 From: syrinx@simplecom.net (Scott) Date: Mon, 26 Mar 2001 19:38:44 -0600 Subject: [Tutor] mutable strings? [and global stuff] In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D66E@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20751D66E@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <v9rvbt81girji8e6i0fuq80kfv6uk65eh3@4ax.com> I think I'm having a "mindset" problem. My programming experience has been mostly C, C++, Basic, and a little assembly. Python is a very different kind of animal. But thanks to you and Daniel (and others), I think it's starting to click (slowly). I think I'm just going to lurk a while and learn by osmosis. :) Thanks for your input. It's helped. =20 >I wonder if you are confusing variables and references/names? > >You need a name that can point to several different strings. >You don't need to change the strings themselves you need to=20 >change which string the name points at. >eg > >foo =3D "myfile.mp3" ># do some messing here >foo =3D "newfile.mp3" ># do more messing >foo =3D foo[:-3]+"txt" # change foo to store newfile.txt > >Is that what you mean? >In the last line I didn't change the string "newfile.mp3" >but I did create a new string based on the original. > >Does that meet your needs? Do you really need to change the original = string? >Thats very unusual... > >Alan G. From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 02:05:41 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 26 Mar 2001 18:05:41 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <XFMail.20010326163139.shaleh@valinux.com> Message-ID: <Pine.LNX.4.21.0103261802360.25955-100000@hkn.eecs.berkeley.edu> On Mon, 26 Mar 2001, Sean 'Shaleh' Perry wrote: > SO, I have a class Foo which maps to a directory. When you create > Foo, it makes a directory of the form /tmp/foo-pid. I would like for > this dir to be removed when the object leaves scope (i.e. when __del__ > is called). However this does not seem to work if the object exists > when python exists. Any ideas? It might be better to have a close() method in your Foo that explicitly removes the temporary directory. The semantics would be similar to how files close() themselves: they call close() through __del__, but they also allow the user to call close() directly to give finer control. If there aren't any more references to your Foo object, it should call __del__. Can you double check to see if something else has a link to your Foo? From wilson@visi.com Tue Mar 27 04:06:44 2001 From: wilson@visi.com (Timothy Wilson) Date: Mon, 26 Mar 2001 22:06:44 -0600 (CST) Subject: [Tutor] Creating instances (group program revisited) Message-ID: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> Hi everyone, I've been playing around with my random student group generating program a little tonight, and I've come to a question. Here's some code: class Student: def __init__(self, studentString): import string s = string.split(studentString, ',') self.ln = s[0] self.fn = s[1] self.gender = s[2] class Group: def __init__(self, groupList): self.groupList = groupList def loadFile(datafile): f = open(datafile, 'r') nameList = f.readlines() for i in nameList: Student(i) Notice that the Student __init__ method now "doesn't care" where the input string comes from. It could be from a file (via the loadFile method) or user input. Here's the question. I think the loadFile method creates a Student instance for each line in the datafile, but I'm puzzles about how I'm going to reference those instances later. Essentially, this is why a previous incarnation had a Roster class which functioned as a container for all the Student objects. Would someone care to comment on this? -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 | <dtml-var pithy_quote> | http://linux.com/ From bwinton@tor.dhs.org Tue Mar 27 04:36:17 2001 From: bwinton@tor.dhs.org (Blake Winton) Date: Mon, 26 Mar 2001 23:36:17 -0500 Subject: [Tutor] Creating instances (group program revisited) In-Reply-To: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> References: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> Message-ID: <20010326233617.B9898@tor.dhs.org> * Timothy Wilson <wilson@visi.com> [010326 23:07]: > Notice that the Student __init__ method now "doesn't care" where the > input string comes from. It could be from a file (via the loadFile > method) or user input. Always a good idea. But it might be smart to allow people to create a student with an empty string, and fill in the data values later. > Here's the question. I think the loadFile method creates a Student > instance for each line in the datafile, but I'm puzzles about how I'm > going to reference those instances later. Essentially, this is why a > previous incarnation had a Roster class which functioned as a > container for all the Student objects. Would someone care to comment > on this? That would be where you want to stick them into something. (note the lines I added...) > def loadFile(datafile): > f = open(datafile, 'r') > nameList = f.readlines() class = [] > for i in nameList: > Student(i) class.append( Student(i) ) Then you can pick people out of the class, and put them into groups. Later, Blake. -- 9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07 From bdupire@seatech.fau.edu Tue Mar 27 05:25:41 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 27 Mar 2001 00:25:41 -0500 Subject: [Tutor] Creating instances (group program revisited) References: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> Message-ID: <3AC02455.2CCF63F2@seatech.fau.edu> This is How I would solve the pb. In fact, I don't think you have to have a 'Class' class, because the Class is what you want to model. It's the whole! Instead of the word 'class', I ll use 'course' because it is confusing with the OO terminology... What you want to model is what a course id ? The first actor is the teacher... Yes.. because the teacher is going to make the group, not the students nor the 'course'.... A teacher has some the students. A teacher can make some groups, print the list of his students, and introduce himself! He can add some students to his course... Note1 : if you want your pb to be really OO, put the loadFile function in a class... (see below1) Note2: it's better to have the split() logic in the loadFile function: the file has to be decoded in this function because if you want to store the student names with a different syntax, what you really want to do is to modify the loadFile function and not the Student __init__ function. In OO you have to define interfaces, that 's the encapsulation principle. Now if i change something, it's very 'local'... import string class Student: def __init__(self, ln, fn, gender): self.ln = ln self.fn = fn self.gender = gender self.group= 0 def getName(self): return self.ln def __str__(self): return "%(ln)s %(fn)s %(gender)sin group: %(group)i" %self.__dict__ def setGroup(self, groupNumber): self.group= groupNumber class Teacher: def __init__(self, name): self.name=name self.studentList= [] self.nbStudent = 0 def __str__(self): return "My name is %s and my class has %i students" %(self.name, self.nbStudent) def addStudentFromFile(self, datafile): list= open(datafile, 'r').readlines() for entry in list: ln, fn, gender = entry.split(',') self.studentList.append(Student(ln, fn, gender)) self.nbStudent+=len(list) def makeGroup(self, nbgroup): i=0 for st in self.studentList: st.setGroup(i % nbgroup) i+=1 def printStudentList(self): for st in self.studentList: print st thePythonTeacher= Teacher('timothy') thePythonTeacher.addStudentFromFile('toto.txt') print thePythonTeacher thePythonTeacher.makeGroup(4) thePythonTeacher.printStudentList() >>> reload(student) My name is timothy and my class has 12 students van Rossum Guido M in group: 0 Boop Betty F in group: 1 Gauld Alan M in group: 2 Flintstone Wilma F in group: 3 Rubble Betty F in group: 0 Yoo Danny M in group: 1 Wilson Tim M in group: 2 Crawford Cindy F in group: 3 Van Laningham Ivan M in group: 0 Lutz Mark M in group: 1 Ascher David M in group: 2 Watters Aaron M in group: 3 <module 'student' from 'C:\Python20\student.py'> Yes, I enjoyed playing with your program! The function to make the group is not perfect, but you end up with Benoit From alan.gauld@bt.com Tue Mar 27 09:33:14 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 27 Mar 2001 10:33:14 +0100 Subject: [Tutor] Done at Last! Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D675@mbtlipnt02.btlabs.bt.co.uk> > def getDayOfWeek(): > #Thanks to Alan Gauld and his book for this You're welcome :-) > #This block seeks that the file with today's date fits one in the > #validDays list. > for item in theFiles: > splitItem = string.split(item) > for z in range(len(splitItem)): > if z == 8: This seems inefficient. You don't do anything with z unless its 8 so why not rewrite the test as: if len(slitItem) >= 8: > if splitItem[8] in validDays: > allTheFiles.append(splitItem[8]) That saves several unnecessary iterations... > > #This routine extracts the dir listing with today's date on it > for x in theFiles: > .... > for z in range(len(y)): > if z == 8: > Same again here > if string.lower(y[8]) == todaysFile: > correctFileName = y[8] > rv = checkSize(correctFileName, theFiles) > return rv > > def makeChoice(): > choices = ['atl/', 'austin/', 'boston/', 'chicago/', > 'dallas/', 'dc/', > 'galveston/', 'houston/', 'la/', 'miami/', 'nola/', 'ny/', > 'phl/', 'portland/', 'sd/', 'seattle/', 'sf/', > 'slc/', 'Vail/'] > > print """ > Which cities would you like to check? > 1) Atlanta > 2) Boston > 3) Chicago > etc... Hmm, why not dynamically build the list from the list of cities? It would help with maintenance. Create a dictionary of city and folders: choices = { 'Atlanta':['atl/'], 'Boston' :['boston/'], etc... 'other' :['austin/', 'dallas/', 'galveston/', 'houston/'] } Then generate the menu using choices.keys().sort() (and maybe an exclusion test to catch 'other' and tag it at the end) To add a new city add an entry to choices and the menu and folder list gets updated automatically... > File "c:\python20\lib\socket.py", line 221, in readline > new = self._sock.recv(self._rbufsize) > error: (10054, 'Connection reset by peer') Could just be a timeout? I get that regularly using commandline ftp programs. Alan G. From rwilkins@bigpond.net.au Tue Mar 27 12:13:27 2001 From: rwilkins@bigpond.net.au (Richard Wilkins) Date: Tue, 27 Mar 2001 20:13:27 +0800 Subject: [Tutor] Deleting from within a class Message-ID: <FPEHJJPEEOIPMAHOADBKEEIICCAA.rwilkins@bigpond.net.au> Hi everyone, I'm creating a matrix class for fun (?!). In the initialisation of the class I want it to check whether the matrix dimensions are all correct (this is sort of irrelevant, but I just wanted to set the scene). What I want to know, is how can I delete an instance within one of its methods - __init__() or something else if possible. I tried "del self", but the instance remains... class Matrix(self,array): def __init__(self,array=[[1,0],[0,1]]): for row in array: if len(row)!=len(array[0]): del self return self.dimensions=[0,0] self.elements=None self.update_elements(array) . . . Any and all help will be appreciated =) TIA, Andrew Wilkins From alan.gauld@bt.com Tue Mar 27 13:54:41 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 27 Mar 2001 14:54:41 +0100 Subject: [Tutor] Tkinter tutor page Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D67B@mbtlipnt02.btlabs.bt.co.uk> I've just added a bit about Layout Managers, and in particular the packer to my Tkinter tutor page. That's as far as it'll go this week coz I now start to get busy again... Any feedback before I go further is appreciated, not least because I'm still a beginner myself when it comes to Tkinter. I don't do a lot of GUI work and most of that has been using VB/Delphi! http://www.crosswinds.net/~agauld/tutgui.htm Alan G. From bdupire@seatech.fau.edu Tue Mar 27 14:25:05 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 27 Mar 2001 09:25:05 -0500 Subject: [Tutor] Deleting from within a class References: <FPEHJJPEEOIPMAHOADBKEEIICCAA.rwilkins@bigpond.net.au> Message-ID: <3AC0A2C1.C5EDDF2A@seatech.fau.edu> I wouldn't do it like that... A better design would be to raise an exception from the Matrix class, and then this exception will be caught by the guy who wanted to create Matrix. The later one can then decide to delete the matrix object. I hope this helps... Benoit Richard Wilkins wrote: > Hi everyone, > > I'm creating a matrix class for fun (?!). In the initialisation of the class > I want it to check whether the matrix dimensions are all correct (this is > sort of irrelevant, but I just wanted to set the scene). What I want to > know, is how can I delete an instance within one of its methods - __init__() > or something else if possible. I tried "del self", but the instance > remains... > > class Matrix(self,array): > def __init__(self,array=[[1,0],[0,1]]): > for row in array: > if len(row)!=len(array[0]): > del self > return > self.dimensions=[0,0] > self.elements=None > self.update_elements(array) > . > . > . > > Any and all help will be appreciated =) > > TIA, Andrew Wilkins > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From arcege@shore.net Tue Mar 27 16:41:11 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 27 Mar 2001 11:41:11 -0500 (EST) Subject: [Tutor] Deleting from within a class In-Reply-To: <FPEHJJPEEOIPMAHOADBKEEIICCAA.rwilkins@bigpond.net.au> from "Richard Wilkins" at Mar 27, 2001 08:13:27 PM Message-ID: <E14hwWt-0006Zl-00@nautilus.shore.net> > > Hi everyone, > > I'm creating a matrix class for fun (?!). In the initialisation of the class > I want it to check whether the matrix dimensions are all correct (this is > sort of irrelevant, but I just wanted to set the scene). What I want to > know, is how can I delete an instance within one of its methods - __init__() > or something else if possible. I tried "del self", but the instance > remains... [snipped] > Any and all help will be appreciated =) > > TIA, Andrew Wilkins The __init__ function is not generate a new object, but gets called on an object already created. The only way to "abort" the instance creation is to raise an exception (often ValueError or TypeError). At that time, the object is destroyed before it can be used by the next operation (assignment, method call, etc.). -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From curtis.larsen@Covance.Com Tue Mar 27 17:27:31 2001 From: curtis.larsen@Covance.Com (Curtis Larsen) Date: Tue, 27 Mar 2001 11:27:31 -0600 Subject: [Tutor] Q: Do Functions Have Any Class? Message-ID: <sac07940.050@madis2.truax.covance.com> Besides their design and concept differences, is there really any (performance-based) reason to use classes/methods in a script as opposed to using functions? Does it depend on how large your main script is? When would you want to use one over the other? 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. From shaleh@valinux.com Tue Mar 27 18:10:11 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 27 Mar 2001 10:10:11 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <Pine.LNX.4.21.0103261802360.25955-100000@hkn.eecs.berkeley.edu> Message-ID: <XFMail.20010327101011.shaleh@valinux.com> On 27-Mar-2001 Daniel Yoo wrote: > On Mon, 26 Mar 2001, Sean 'Shaleh' Perry wrote: > >> SO, I have a class Foo which maps to a directory. When you create >> Foo, it makes a directory of the form /tmp/foo-pid. I would like for >> this dir to be removed when the object leaves scope (i.e. when __del__ >> is called). However this does not seem to work if the object exists >> when python exists. Any ideas? > > It might be better to have a close() method in your Foo that explicitly > removes the temporary directory. The semantics would be similar to how > files close() themselves: they call close() through __del__, but they also > allow the user to call close() directly to give finer control. > this idea sounded good until I thought it through. The problem is Foo lives for most of the program. If the program terminates for some reason (i.e. a caught exception) I would like Foo to be cleaned up after. > If there aren't any more references to your Foo object, it should call > __del__. Can you double check to see if something else has a link to your > Foo? > none that are obvious to me. Would it matter that Foo is a derived class of Bar and Bar lacks a __del__ method? From kalle@gnupung.net Tue Mar 27 18:36:54 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 27 Mar 2001 20:36:54 +0200 Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <XFMail.20010327101011.shaleh@valinux.com>; from shaleh@valinux.com on Tue, Mar 27, 2001 at 10:10:11AM -0800 References: <Pine.LNX.4.21.0103261802360.25955-100000@hkn.eecs.berkeley.edu> <XFMail.20010327101011.shaleh@valinux.com> Message-ID: <20010327203653.A14597@apone.network.loc> Sez Sean 'Shaleh' Perry: > > On 27-Mar-2001 Daniel Yoo wrote: > > On Mon, 26 Mar 2001, Sean 'Shaleh' Perry wrote: > > > >> SO, I have a class Foo which maps to a directory. When you create > >> Foo, it makes a directory of the form /tmp/foo-pid. I would like for Just a note: IIRC, /tmp/foo-pid names are vulnerable to race conditions. Better use a more random name, I think. > >> this dir to be removed when the object leaves scope (i.e. when __del__ > >> is called). However this does not seem to work if the object exists > >> when python exists. Any ideas? > > > > It might be better to have a close() method in your Foo that explicitly > > removes the temporary directory. The semantics would be similar to how > > files close() themselves: they call close() through __del__, but they also > > allow the user to call close() directly to give finer control. > > > > this idea sounded good until I thought it through. The problem is Foo lives > for most of the program. If the program terminates for some reason (i.e. a > caught exception) I would like Foo to be cleaned up after. Have you looked at the atexit module? http://www.python.org/doc/current/lib/module-atexit.html Perhaps it could help. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From kalle@gnupung.net Tue Mar 27 18:38:27 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 27 Mar 2001 20:38:27 +0200 Subject: [Tutor] enquiry In-Reply-To: <200103261449340590.1ACCCF51@mail-serv.ccsr.cam.ac.uk>; from XQ.Xia@ccsr.cam.ac.uk on Mon, Mar 26, 2001 at 02:49:34PM +0100 References: <200103261449340590.1ACCCF51@mail-serv.ccsr.cam.ac.uk> Message-ID: <20010327203827.B14597@apone.network.loc> Sez XIA Xiao-Qin: > Is there any method to display words vertically in Tkinter? It is > necessary when drawing the notes to y-axis of a chart on a canvas. As far as I know, no. Sorry. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 18:39:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 10:39:37 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <XFMail.20010327101011.shaleh@valinux.com> Message-ID: <Pine.LNX.4.21.0103271037090.11322-100000@hkn.eecs.berkeley.edu> On Tue, 27 Mar 2001, Sean 'Shaleh' Perry wrote: > > >> when python exists. Any ideas? > > > > It might be better to have a close() method in your Foo that explicitly > > removes the temporary directory. The semantics would be similar to how > > files close() themselves: they call close() through __del__, but they also > > allow the user to call close() directly to give finer control. > > > > this idea sounded good until I thought it through. The problem is Foo lives > for most of the program. If the program terminates for some reason (i.e. a > caught exception) I would like Foo to be cleaned up after. It sounds like you'll want to clean up Foo, no matter what, when your program finishes. If so, you'll want to look at the atexit module: http://python.org/doc/current/lib/module-atexit.html I have to admit: I've never touched this beast before, but it sounds exactly like what you want. From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 18:44:22 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 10:44:22 -0800 (PST) Subject: [Tutor] Creating instances (group program revisited) In-Reply-To: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> Message-ID: <Pine.LNX.4.21.0103271040220.11322-100000@hkn.eecs.berkeley.edu> On Mon, 26 Mar 2001, Timothy Wilson wrote: > Here's the question. I think the loadFile method creates a Student instance > for each line in the datafile, but I'm puzzles about how I'm going to > reference those instances later. Essentially, this is why a previous > incarnation had a Roster class which functioned as a container for all the > Student objects. Would someone care to comment on this? Let's take a look. > def loadFile(datafile): > f = open(datafile, 'r') > nameList = f.readlines() > for i in nameList: > Student(i) So we're definitely constructing a student for every line in your datafile... but we need to capture the student, to put it in some sort of container. Otherwise, you're right --- there's no way to get at any particular student anymore, since we don't have a name for it. We could do something like this: def loadFile(datafile): f = open(datafile, 'r') nameList = f.readlines() students = [] for i in nameList: students.append(Student(i)) return students in which case, we use a list to store all the students, and return that back as loadFile's return value. From bdupire@seatech.fau.edu Tue Mar 27 18:42:03 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 27 Mar 2001 13:42:03 -0500 Subject: [Tutor] Q: Do Functions Have Any Class? References: <sac07940.050@madis2.truax.covance.com> Message-ID: <3AC0DEFB.9923A4FB@seatech.fau.edu> If it's just performance we are talking about, there is just a slight overhead when we use classes/ methods. The reason is that we don't access data directly but through methods, so there is one more layer. But really, for 99% of the projects, you don't care. Maybe i am missing something in your question.... Curtis Larsen wrote: > Besides their design and concept differences, is there really any > (performance-based) reason to use classes/methods in a script as opposed > to using functions? Does it depend on how large your main script is? > When would you want to use one over the other? > > 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. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From rick@niof.net Tue Mar 27 18:51:55 2001 From: rick@niof.net (Rick Pasotto) Date: Tue, 27 Mar 2001 13:51:55 -0500 Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <XFMail.20010327101011.shaleh@valinux.com>; from shaleh@valinux.com on Tue, Mar 27, 2001 at 10:10:11AM -0800 References: <Pine.LNX.4.21.0103261802360.25955-100000@hkn.eecs.berkeley.edu> <XFMail.20010327101011.shaleh@valinux.com> Message-ID: <20010327135155.F365@tc.niof.net> On Tue, Mar 27, 2001 at 10:10:11AM -0800, Sean 'Shaleh' Perry wrote: > > On 27-Mar-2001 Daniel Yoo wrote: > > On Mon, 26 Mar 2001, Sean 'Shaleh' Perry wrote: > > > >> SO, I have a class Foo which maps to a directory. When you create > >> Foo, it makes a directory of the form /tmp/foo-pid. I would like > >> for this dir to be removed when the object leaves scope (i.e. when > >> __del__ is called). However this does not seem to work if the > >> object exists when python exists. Any ideas? > > > > It might be better to have a close() method in your Foo that > > explicitly removes the temporary directory. The semantics would be > > similar to how files close() themselves: they call close() through > > __del__, but they also allow the user to call close() directly to > > give finer control. > > > > this idea sounded good until I thought it through. The problem is Foo > lives for most of the program. If the program terminates for some > reason (i.e. a caught exception) I would like Foo to be cleaned up > after. A standard unix trick is to create/open the temporary file and then immediately tell the o/s to delete it. The actual delete won't happen until the file is closed - either by you or by your process exiting. So you can continue to read/write your file until you close it. I don't do windoze but I suspect this wouldn't work there. (What happens is that the inode sticks around but the directory entry disappears.) -- "Action from principle, the perception and the performance of right, changes things and relations; it is essentially revolutionary... It not only divides states and churches, it divides families; aye, it divides the individual, separating the diabolical in him from the divine." -- Henry D. Thoreau, 1849 "Resistance to Civil Government" Rick Pasotto email: rickp@telocity.com From shaleh@valinux.com Tue Mar 27 19:02:01 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 27 Mar 2001 11:02:01 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <Pine.LNX.4.21.0103271037090.11322-100000@hkn.eecs.berkeley.edu> Message-ID: <XFMail.20010327110201.shaleh@valinux.com> > It sounds like you'll want to clean up Foo, no matter what, when your > program finishes. If so, you'll want to look at the atexit module: > > http://python.org/doc/current/lib/module-atexit.html > > I have to admit: I've never touched this beast before, but it sounds > exactly like what you want. > can I back port this to 1.5? This code is not 2.x dependant. From shaleh@valinux.com Tue Mar 27 19:04:09 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 27 Mar 2001 11:04:09 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <20010327203653.A14597@apone.network.loc> Message-ID: <XFMail.20010327110409.shaleh@valinux.com> >> >> SO, I have a class Foo which maps to a directory. When you create >> >> Foo, it makes a directory of the form /tmp/foo-pid. I would like for > > Just a note: IIRC, /tmp/foo-pid names are vulnerable to race conditions. > Better use a more random name, I think. > This is not an issue for this program. The item created is a directory and the way this program is used problems will not occur. But thanks for the sanity check. I am rewriting the existing code base from perl to python. The perl code is all functions, the new python code is mostly OO. The perl code has worked for 4 years but is showing its age and is making new features difficult to add. From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 19:04:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 11:04:28 -0800 (PST) Subject: [Tutor] Pickling In-Reply-To: <Pine.OSF.4.30.0103261217460.22110-100000@student.uq.edu.au> Message-ID: <Pine.LNX.4.21.0103271056090.11322-100000@hkn.eecs.berkeley.edu> On Mon, 26 Mar 2001, Suzanne Little wrote: > Python 2.0 (#1, Feb 14 2001, 10:51:28) > [GCC 2.95.2 19991024 (release)] on sunos5 > Type "copyright", "credits" or "license" for more information. > >>> import pickle > >>> f = open('xmlTest.xml', 'r') > >>> pickle.load(f) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in > load > return Unpickler(file).load() > File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in > load > dispatch[key](self) > KeyError: < > >>> Ah! Most likely, you'll need to import the minidom class; pickle assumes that the class is in Python's memory before you unpickle stuff. The problem about unpickling is that Python needs to know what the minidom class looks like --- and it's restricted from automatically loading classes, so that's why it's confused. This is a common error, so don't worry about it. If you do the line: from xml.dom import minidom before unpickling, it should work ok. The pickle documentation talks about this issue here: http://python.org/doc/current/lib/module-pickle.html Look for the words "There are some restrictions on the pickling of class instances..." I hope that this is the only issue that needs to be fixed. Good luck to you. From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 19:07:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 11:07:16 -0800 (PST) Subject: [Tutor] clock programs (and generalization) In-Reply-To: <F138kDeE9KQxnNTFiPd0000aad6@hotmail.com> Message-ID: <Pine.LNX.4.21.0103271105240.11322-100000@hkn.eecs.berkeley.edu> On Sun, 25 Mar 2001, Charles Gruschow wrote: > Is this any better (it is simplified somewhat, and it is more exact): This looks better. As you get more experience writing programs, take a look back, every so often, and see if you can make it better. I think you'll be pleasantly surprised. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 19:30:13 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 11:30:13 -0800 (PST) Subject: [Tutor] enquiry In-Reply-To: <200103261449340590.1ACCCF51@mail-serv.ccsr.cam.ac.uk> Message-ID: <Pine.LNX.4.21.0103271112320.11322-100000@hkn.eecs.berkeley.edu> On Mon, 26 Mar 2001, XIA Xiao-Qin wrote: > Is there any method to display words vertically in Tkinter? It is > necessary when drawing the notes to y-axis of a chart on a canvas. I could not find any standard Tkinter widget to write things vertically. However, we can write a new widget to do this. Here is a definition of a Vertical: ### from Tkinter import * class Vertical(Frame): def __init__(self, letters): Frame.__init__(self) for l in letters: Label(self, text=l).pack(side=TOP) ### The idea is to make a Frame, which contains single-letter labels arranged from the top, going down. Once we have something like the Vertical class, we can place it within a Canvas like this: ### Canvas = Canvas() v = Vertical('Hello World') canvas.create_window(50, 50, window=v) ### Unfortunately, the letters are spaced out a bit too distantly. If we want to make things nicer, it might be better to use a Canvas, instead of a Frame, to contain each letter --- if we do this, we'll get a bit more control over the way the letters draw. Still, this is a quick way of getting a vertical "Label". I hope this helps! From dyoo@hkn.eecs.berkeley.edu Tue Mar 27 19:42:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 11:42:16 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <XFMail.20010327110201.shaleh@valinux.com> Message-ID: <Pine.LNX.4.21.0103271138460.11322-100000@hkn.eecs.berkeley.edu> On Tue, 27 Mar 2001, Sean 'Shaleh' Perry wrote: > > It sounds like you'll want to clean up Foo, no matter what, when your > > program finishes. If so, you'll want to look at the atexit module: > > > > http://python.org/doc/current/lib/module-atexit.html > > > > I have to admit: I've never touched this beast before, but it sounds > > exactly like what you want. > > > > can I back port this to 1.5? This code is not 2.x dependant. Not quite sure. You can get equivalent behavior from the sys.exitfunc() function: http://python.org/doc/current/lib/module-sys.html So we could do something like this: ### >>> import sys >>> def goodbye(): print "Goodbye, goodbye" ... >>> sys.exitfunc = goodbye >>> ## At this point, I press Ctrl-D Goodbye, goodbye ### And this should be Python 1.52 compatible. Hope this helps! From arcege@shore.net Tue Mar 27 20:28:45 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 27 Mar 2001 15:28:45 -0500 (EST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <no.id> from "Sean 'Shaleh' Perry" at Mar 26, 2001 04:31:39 PM Message-ID: <E14i057-0007cV-00@nautilus.shore.net> > > SO, I have a class Foo which maps to a directory. When you create Foo, it > makes a directory of the form /tmp/foo-pid. I would like for this dir to be > removed when the object leaves scope (i.e. when __del__ is called). However > this does not seem to work if the object exists when python exists. Any ideas? What you want is to use the proper functions, but if Foo is long term, and gets destroyed at program-exit, then you may not have the "tools" to do the work you want/need. Specifically, the order of modules removed from the system cannot be specified. You'll want to use functions from the os module, but if that is destroyed before your object's __del__ method is called, then you'll run into problems. The best solution is to hold on to the functions you need (not the module) and use those in the __del__ method. For example, I have a TempFile class in my mimecntl module which goes something like: class TempFile: # The remove function is import directly so we have it bound, this # allows Python to destroy the os module when the program finishes # without destroying the os.remove function. import os __os_remove = os.remove del os def __init__(self, mode='wb+'): import tempfile self.name = name = tempfile.mktemp() self.mode = mode self.fp = open(name, mode) # other code removed def __del__(self): self.close() self.remove() def close(self): fp = self.fp if fp: fp.close() self.fp = None def remove(self): try: self.__os_remove(self.name) except: pass This should handle most all the cases that exist (it sounds like you'll want to have listdir, remove, rmdir, and others to handle any subfiles). If this is still a problem, then I would suggest that you create a close and/or remove method, and wrap the program in a try-finally statement. try: foo = Foo() ... finally: foo.close() foo.remove() -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From shaleh@valinux.com Tue Mar 27 20:56:26 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Tue, 27 Mar 2001 12:56:26 -0800 (PST) Subject: [Tutor] ensuring a __del__ method happens In-Reply-To: <E14i057-0007cV-00@nautilus.shore.net> Message-ID: <XFMail.20010327125626.shaleh@valinux.com> > > The best solution is to hold on to the functions you need (not the > module) and use those in the __del__ method. For example, I have a > TempFile class in my mimecntl module which goes something like: > > class TempFile: > <rest snipped> > This should handle most all the cases that exist (it sounds like you'll > want to have listdir, remove, rmdir, and others to handle any subfiles). > Hmmm, will look into this. I am still confused because I have my del method printing a 'I am exiting' string which I never see. I have Foo and TemporaryFoo. Foo does not have a __del__ method. TemporaryFoo does. The class is instantiated as: if need_temp: foo = TemporaryFoo() else: foo = Foo() ..... # time passes when foo is destroyed, either by sys.exit(), an exception, whatever I never see TemporaryFoo's del method. Do I need to add a dummy __del__ method to the base class? From DOUGS@oceanic.com Wed Mar 28 00:41:11 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Tue, 27 Mar 2001 14:41:11 -1000 Subject: [Tutor] Q: Do Functions Have Any Class? Message-ID: <8457258D741DD411BD3D0050DA62365907A706@huina.oceanic.com> [Benoit Dupire answered Curtis Larsen with:] > > Besides their design and concept differences, is there really any > > (performance-based) reason to use classes/methods in a script as opposed > > to using functions? > If it's just performance we are talking about, there is just a slight > overhead when we use classes/ methods. The reason is that we > don't access > data directly but through methods, so there is one more layer. One of the internals gurus might answer more in depth, but I think this is not true in Python. Because Python is OO through and through out of the box, you don't inherently gain or lose anything in performance by being object oriented versus functional. That difference has been optimized out in order to make the language as fast as it is. Also, Python doesn't force you to use accessor functions to get a value. You just use it. [Benoit Dupire again:] > But really, for 99% of the projects, you don't care. Depending on how this was meant, I might take exception with this or be in violent agreement. ;-) If I said this, I'd mean that it wouldn't matter how you started, if you are using a flexible process you'll find the right balance between functional and OO. > > When would you want to use one over the other? Don't think of it as a dichotomy, an either-or. Think of it as a win-win that Python integrates both approaches so well that you can do what is best for the task immediately at hand. As your requirements change or the program or system grows, you can add objects to a purely functional design as needed. More often than not I find the following is my process for development: I begin exploring a concept or scratching an itch by typing commands in to the interpreter. I then put the correct commands in to a file that I run as a script. As I find more use for the script I make it into a function or two with a main routine for the pseudo-code level logic. Those functions will continue to grow as I figure out more things to do with a particular data structure. Sooner (usually) or later I see an object emerging that ties together some functions and that data structure and I start to pull that out of the mess. That usually happens when I'm putting a lot of if then constructs in my programs. YMMV, but I think this can work in many situations. Mine happens to be one where the programming is in a support role to my job; producing the program is not my primary job. I see it as a continuum, script to functional to objects, and not a functional OR objects argument. Its important to have some structure around this process, but it doesn't have to be strenuous, just consistant. I use version control, some unit testing, and take a stab at doing refactoring correctly. Python is wonderful in the way that it helps instead of getting in the way. -Doug- From wong_chow_cheok@hotmail.com Wed Mar 28 01:32:00 2001 From: wong_chow_cheok@hotmail.com (wong chow cheok) Date: Wed, 28 Mar 2001 09:32:00 +0800 Subject: [Tutor] (no subject) Message-ID: <F95g7KazMfhgmu6HzTG000111c0@hotmail.com> hai. I am a student currently doing training and am using python. i ahve this problem. i am trying yo open the source code for a page and extract certain information on it for example : the temperature for the day and the title of the page. >>>import urllib >>>f=urllib.urlopen("http://www.kjc.gov.my/cgi-bin/fcastdisplay.cgi?lang=EN") >>>print f.read() this is the program but whenever i try to enter parameters it still outputs the whole source code. how do i do it? thank you for your help _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From dyoo@hkn.eecs.berkeley.edu Wed Mar 28 02:23:08 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 27 Mar 2001 18:23:08 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <F95g7KazMfhgmu6HzTG000111c0@hotmail.com> Message-ID: <Pine.LNX.4.21.0103271820001.23306-100000@hkn.eecs.berkeley.edu> On Wed, 28 Mar 2001, wong chow cheok wrote: > hai. I am a student currently doing training and am using python. i ahve > this problem. i am trying yo open the source code for a page and extract > certain information on it for example : the temperature for the day and the > title of the page. > > >>>import urllib > >>>f=urllib.urlopen("http://www.kjc.gov.my/cgi-bin/fcastdisplay.cgi?lang=EN") > >>>print f.read() > this is the program but whenever i try to enter parameters it still > outputs the whole source code. how do i do it? The last command: print f.read() is responsible for printing out the whole source. Instead of printing it, it sounds like you'll want to process it instead. Try something like: source = f.read() Then you'll have the whole html in your source variable, and you'll be able to manipulate it. How do you plan to extract the temperature or title from the source code? From jsc_lists@rock-tnsc.com Wed Mar 28 04:50:16 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Wed, 28 Mar 2001 12:50:16 +0800 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <20010321113033.B13678@pino.selwerd.nl> Message-ID: <JMEOIILNBOJMOPBDBMGMOEAMCIAA.jsc_lists@rock-tnsc.com> > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Remco Gerlich > Sent: Wednesday, March 21, 2001 6:31 PM > To: tutor@python.org > Subject: Re: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 > > > Hmm, there is a small fixed decimal precision arithmetic library called > FixedPoint that you probably want to use, see FixedPoint.py and .README in > ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/DataStructures/ . > Remco, Thanks for the info. I finally got around to trying to use FixedPoint today. However when I tested it in the python interpreter I found some very weird results: >>> x = FixedPoint("5.55") >>> print x .05 According to the docstrings the above should produce the result: >>> x = FixedPoint("5.55") # precision defaults to 2 >>> print x 5.55 I am using Python 2.0. Could this be caused by differences between 1.5.2 and 2.0? Anyother hints? TIA, Jethro From deirdre@deirdre.net Wed Mar 28 04:57:05 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 27 Mar 2001 20:57:05 -0800 (PST) Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <JMEOIILNBOJMOPBDBMGMOEAMCIAA.jsc_lists@rock-tnsc.com> Message-ID: <Pine.LNX.4.31.0103272056190.4624-100000@emperor.deirdre.org> On Wed, 28 Mar 2001, Jethro Cramp wrote: > >>> x = FixedPoint("5.55") > >>> print x > .05 This works correctly in 1.52. Have you tried it without the quote marks? That also works in 1.52, but I'm wondering if it gives a different result in 2.0. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From joerg.sporer@opencom.de Wed Mar 28 06:49:44 2001 From: joerg.sporer@opencom.de (=?iso-8859-1?Q?J=F6rg_Sporer?=) Date: Wed, 28 Mar 2001 08:49:44 +0200 Subject: [Tutor] Placing icons in the systray Message-ID: <000001c0b753$468b5980$3701000a@arthur> SGVsbG8hDQoNCkRvZXMgYW55Ym9keSBrbm93IGhvdyB0byBwbGFjZSBhbiBpY29uIGluIHRoZSBz eXN0cmF5ICh5b3Uga25vdyAtIG5leHQgdG8NCnRoZSBjbG9jaylpbiBXaW5kb3dzPw0KDQpUaGFu a3MgZm9yIHlvdXIgaGVscA0KDQpK9nJnDQoNCg== From tim.one@home.com Wed Mar 28 07:19:58 2001 From: tim.one@home.com (Tim Peters) Date: Wed, 28 Mar 2001 02:19:58 -0500 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <JMEOIILNBOJMOPBDBMGMOEAMCIAA.jsc_lists@rock-tnsc.com> Message-ID: <LNBBLJKPBEHFEDALKOLCKEMGJIAA.tim.one@home.com> [Remco Gerlich] > Hmm, there is a small fixed decimal precision arithmetic library called > FixedPoint that you probably want to use, see FixedPoint.py and > .README in > ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/DataStructures/ . [Jethro Cramp] > Thanks for the info. I finally got around to trying to use FixedPoint > today. However when I tested it in the python interpreter I found > some very weird results: > > >>> x = FixedPoint("5.55") > >>> print x > .05 > > According to the docstrings the above should produce the result: > >>> x = FixedPoint("5.55") # precision defaults to 2 > >>> print x > 5.55 > > I am using Python 2.0. Could this be caused by differences between > 1.5.2 and 2.0? Yuck, yes. For long (unbounded) integers i, str(i) *used* to produce the letter "L" at the end, but by popular demand it no longer does. That's how you're getting burned here. Replace this block of code: def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: frac = str(f)[:-1] frac = "0" * (p - len(frac)) + frac else: frac = "" return "-"[:n<0] + \ str(i)[:-1] + \ "." + frac with this: def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: frac = str(f) frac = "0" * (p - len(frac)) + frac else: frac = "" return "-"[:n<0] + \ str(i) + \ "." + frac (that simply gets rid of the two instances of [:-1], which stripped off the old trailing "L" but are now deleting the last digit(!)), and all will be well under 2.0. Or, maybe better, replace it with this: def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: frac = repr(f)[:-1] frac = "0" * (p - len(frac)) + frac else: frac = "" return "-"[:n<0] + \ repr(i)[:-1] + \ "." + frac (replacing the original "str" calls with "repr" calls -- repr(long) still produces an "L" at the end) and it should work fine under both. Unfortunately, I don't know of any way to get the ftp site updated anymore -- it's just an archive of old code. From jsc_lists@rock-tnsc.com Wed Mar 28 09:01:21 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Wed, 28 Mar 2001 17:01:21 +0800 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <LNBBLJKPBEHFEDALKOLCKEMGJIAA.tim.one@home.com> Message-ID: <JMEOIILNBOJMOPBDBMGMOEBBCIAA.jsc_lists@rock-tnsc.com> Tim, Thanks for the quick reply. The first section of code worked perfectly. The second section didn't work. Will have another look at it later on. > Yuck, yes. For long (unbounded) integers i, str(i) *used* to produce the > letter "L" at the end, but by popular demand it no longer does. > That's how > you're getting burned here. Replace this block of code: > > def __str__(self): > n, p = self.n, self.p > i, f = divmod(abs(n), _tento(p)) > if p: > frac = str(f)[:-1] > frac = "0" * (p - len(frac)) + frac > else: > frac = "" > return "-"[:n<0] + \ > str(i)[:-1] + \ > "." + frac > > with this: > > def __str__(self): > n, p = self.n, self.p > i, f = divmod(abs(n), _tento(p)) > if p: > frac = str(f) > frac = "0" * (p - len(frac)) + frac > else: > frac = "" > return "-"[:n<0] + \ > str(i) + \ > "." + frac > > (that simply gets rid of the two instances of [:-1], which > stripped off the > old trailing "L" but are now deleting the last digit(!)), and all will be > well under 2.0. Or, maybe better, replace it with this: > > def __str__(self): > n, p = self.n, self.p > i, f = divmod(abs(n), _tento(p)) > if p: > frac = repr(f)[:-1] > frac = "0" * (p - len(frac)) + frac > else: > frac = "" > return "-"[:n<0] + \ > repr(i)[:-1] + \ > "." + frac > > (replacing the original "str" calls with "repr" calls -- repr(long) still > produces an "L" at the end) and it should work fine under both. > > Unfortunately, I don't know of any way to get the ftp site > updated anymore -- > it's just an archive of old code. From jethro@163bj.com Wed Mar 28 10:00:10 2001 From: jethro@163bj.com (Jethro Cramp) Date: Wed, 28 Mar 2001 18:00:10 +0800 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? Message-ID: <JMEOIILNBOJMOPBDBMGMCEBECIAA.jethro@163bj.com> Thanks for everyone's help in sorting out the problems I was having with floating point numbers. Now I have all my numbers and all the calculations done I would like to format the output for example if I have the numbers: 3306525.45 and 510575.98 I would like to format them as: 3,306,525.45 and 510,575.98 Now I could roll my own formatter but I am sure that this is such a common task that it must have be a standard feature/module of python. Unfortunately I lost my copy of New Riders Python Reference a few weeks ago and I can't find something specifically in the Python Documentation (should one of the options for % work?) so I am flailing in the dark. Any and all suggestions much appreciated. Jethro From scarblac@pino.selwerd.nl Wed Mar 28 11:00:21 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 28 Mar 2001 13:00:21 +0200 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <JMEOIILNBOJMOPBDBMGMCEBECIAA.jethro@163bj.com>; from jethro@163bj.com on Wed, Mar 28, 2001 at 06:00:10PM +0800 References: <JMEOIILNBOJMOPBDBMGMCEBECIAA.jethro@163bj.com> Message-ID: <20010328130021.A26971@pino.selwerd.nl> On Wed, Mar 28, 2001 at 06:00:10PM +0800, Jethro Cramp wrote: > Thanks for everyone's help in sorting out the problems I was having with > floating point numbers. > > Now I have all my numbers and all the calculations done I would like to > format the output for example if I have the numbers: > > 3306525.45 and 510575.98 > > I would like to format them as: > > 3,306,525.45 and 510,575.98 > > Now I could roll my own formatter but I am sure that this is such a common > task that it must have be a standard feature/module of python. Unfortunately > I lost my copy of New Riders Python Reference a few weeks ago and I can't > find something specifically in the Python Documentation (should one of the > options for % work?) so I am flailing in the dark. > > Any and all suggestions much appreciated. This is an internationalization issue. For instance, the notation above is common in the US, but in .nl we would write 3.306.525,45. The solution should be in the locale module. Unfortunately on my weird Linux system it's not working well, but something like the following should work: import locale locale.setlocale(locale.LC_ALL, "us") # Try to set it to US, fails for me print locale.format("%f", 3306525.45) -- Remco Gerlich From alan.gauld@bt.com Wed Mar 28 11:47:52 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 28 Mar 2001 12:47:52 +0100 Subject: [Tutor] Q: Do Functions Have Any Class? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D681@mbtlipnt02.btlabs.bt.co.uk> > Besides their design and concept differences, is there really any > (performance-based) reason to use classes/methods in a script OOP is all about two things - organisation and reuse. If its simple the organisation may not be significant but being able to reuse things might be. One major difference is elimination of global variables - and the implicit ability to have multiple instances. Take a look at the Case Study in my online tutor. It shows this. The word counter as functions relies on global vas and this can only analyze one file at a time. By making a class we can have a counter per file... But if you are writing a one-off very simple script just use functions... There is no performance advantage in using classes unless you have a lot of different types and your code is full of if/elif constructs that call different functions depending on type. This will be faster using polymorphic classes. (Or dictionaries of function references - which is how the class does it :-) Alan G From jsc_lists@rock-tnsc.com Wed Mar 28 14:06:23 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Wed, 28 Mar 2001 22:06:23 +0800 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <20010328130021.A26971@pino.selwerd.nl> Message-ID: <JMEOIILNBOJMOPBDBMGMMEBHCIAA.jsc_lists@rock-tnsc.com> > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Remco Gerlich > Sent: Wednesday, March 28, 2001 7:00 PM > To: tutor@python.org > Subject: Re: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 > > > This is an internationalization issue. For instance, the notation above is > common in the US, but in .nl we would write 3.306.525,45. > > The solution should be in the locale module. Unfortunately on my > weird Linux > system it's not working well, but something like the following > should work: > > import locale > locale.setlocale(locale.LC_ALL, "us") # Try to set it to US, fails for me > print locale.format("%f", 3306525.45) > Thank you. I had thought that it must be possible through the locale module and had played with it in the interpreter but hadn't understood the "format" in locale.format("format", val) part of the method. I have tried your suggestion and several variations. Here are the results below (Windows ME, Python 2.0): >>> x = 33456.12 >>> locale.format("%f", x) '33456.120000' >>> locale.format("%d", x) '33456' >>> locale.format("%e", x) '3.345612e+004' >>> locale.format("%E", x) '3.345612E+004' >>> locale.format("%g", x) '33456.1' >>> locale.format("%G", x) '33456.1' >>> locale.format("%i", x) '33456' >>> locale.format("%u", x) '33456' >>> locale.format("%i", x) '33456' Some of these are expected, but still none of them are X,XXX.XX. Is this some peculiarity of my system (will try it on my Linux box tomorrow)? Or should I be using the locale.format() function differently. The idea of being able to change the formatting just by changing the locale is very appealing (I have clients all over Europe and formatting output to their locale would be appreciated by them). This leads me then to the question of how does one use the locale module to format a monetary value? If you have a value in (say) DEM what function would use to have it output correctly? TIA, Jethro From kromag@nsacom.net Wed Mar 28 16:21:51 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Wed, 28 Mar 2001 08:21:51 -0800 (PST) Subject: [Tutor] PyApache Module questions Message-ID: <200103281621.f2SGLpC22135@pop.nsacom.net> I compiled the PyApache module into apache 1.3.19. Everything seems to work fine except for a small weirdness. It seems that one must add a couple of "print"s to the beginning of one's cgi script for the module to write out to the browser. ie #!/usr/bin/python import os, <among others> print print print "Hi there, handsome..." works fine but #!/usr/bin/python import os print "Hi there, handsome..." produces a blank page. I noticed that the demo script that comes with this module had two leading print statements, which clued me in a little. Is this a known idiosyncracy? Are there any other caveats associated with PyApache? Thanks! From scarblac@pino.selwerd.nl Wed Mar 28 14:17:25 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 28 Mar 2001 16:17:25 +0200 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <JMEOIILNBOJMOPBDBMGMMEBHCIAA.jsc_lists@rock-tnsc.com>; from jsc_lists@rock-tnsc.com on Wed, Mar 28, 2001 at 10:06:23PM +0800 References: <20010328130021.A26971@pino.selwerd.nl> <JMEOIILNBOJMOPBDBMGMMEBHCIAA.jsc_lists@rock-tnsc.com> Message-ID: <20010328161725.A27160@pino.selwerd.nl> On Wed, Mar 28, 2001 at 10:06:23PM +0800, Jethro Cramp wrote: > Some of these are expected, but still none of them are X,XXX.XX. Is this > some peculiarity of my system (will try it on my Linux box tomorrow)? Or > should I be using the locale.format() function differently. The idea of > being able to change the formatting just by changing the locale is very > appealing (I have clients all over Europe and formatting output to their > locale would be appreciated by them). The correct command seems to be 'locale.format("%f", f, 1). The '1' means that grouping is used, i.e. commas every three figures. As least, if I read the docs correctly (http://www.python.org/doc/current/lib/module-locale.html). Did the setlocale(LC_ALL,"us") work? What's the output of locale.localeconv()? > This leads me then to the question of how does one use the locale module to > format a monetary value? If you have a value in (say) DEM what function > would use to have it output correctly? The currency symbol is in locale.localeconv()['currency_symbol'], apparently. I can't test here and I've never used it, so I'm getting it from the docs... -- Remco Gerlich From rick@niof.net Wed Mar 28 17:20:33 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 28 Mar 2001 12:20:33 -0500 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <20010328161725.A27160@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Wed, Mar 28, 2001 at 04:17:25PM +0200 References: <20010328130021.A26971@pino.selwerd.nl> <JMEOIILNBOJMOPBDBMGMMEBHCIAA.jsc_lists@rock-tnsc.com> <20010328161725.A27160@pino.selwerd.nl> Message-ID: <20010328122033.C26119@tc.niof.net> On Wed, Mar 28, 2001 at 04:17:25PM +0200, Remco Gerlich wrote: > On Wed, Mar 28, 2001 at 10:06:23PM +0800, Jethro Cramp wrote: > > Some of these are expected, but still none of them are X,XXX.XX. Is > > this some peculiarity of my system (will try it on my Linux box > > tomorrow)? Or should I be using the locale.format() function > > differently. The idea of being able to change the formatting just by > > changing the locale is very appealing (I have clients all over > > Europe and formatting output to their locale would be appreciated by > > them). > > The correct command seems to be 'locale.format("%f", f, 1). > > The '1' means that grouping is used, i.e. commas every three figures. > As least, if I read the docs correctly > (http://www.python.org/doc/current/lib/module-locale.html). > > Did the setlocale(LC_ALL,"us") work? What's the output of > locale.localeconv()? When I do that [actually, locale.setlocale(locale.LC_ALL,"us")] I get 'locale setting not supported.' What do I need to do to get it supported? I'm running debian and the 'locales' package is installed. -- Freedom can be lost as surely tax by tax, regulation by regulation, as it can be bullet by bullet, missile by missile. Rick Pasotto email: rickp@telocity.com From shaleh@valinux.com Wed Mar 28 17:38:03 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 28 Mar 2001 09:38:03 -0800 (PST) Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 In-Reply-To: <20010328122033.C26119@tc.niof.net> Message-ID: <XFMail.20010328093803.shaleh@valinux.com> > > When I do that [actually, locale.setlocale(locale.LC_ALL,"us")] I get > 'locale setting not supported.' What do I need to do to get it > supported? I'm running debian and the 'locales' package is installed. > because debian currently ships with locales support enabled but the actual locales are not being generated (to save space/time at the request of our users). cd /etc/ and edit locale.gen, then run locale-gen as root. From scarblac@pino.selwerd.nl Wed Mar 28 17:37:01 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 28 Mar 2001 19:37:01 +0200 Subject: [Tutor] Formatting Numbers as Strings In-Reply-To: <20010328122033.C26119@tc.niof.net>; from rick@niof.net on Wed, Mar 28, 2001 at 12:20:33PM -0500 References: <20010328130021.A26971@pino.selwerd.nl> <JMEOIILNBOJMOPBDBMGMMEBHCIAA.jsc_lists@rock-tnsc.com> <20010328161725.A27160@pino.selwerd.nl> <20010328122033.C26119@tc.niof.net> Message-ID: <20010328193701.A27929@pino.selwerd.nl> On Wed, Mar 28, 2001 at 12:20:33PM -0500, Rick Pasotto wrote: > When I do that [actually, locale.setlocale(locale.LC_ALL,"us")] I get > 'locale setting not supported.' What do I need to do to get it > supported? I'm running debian and the 'locales' package is installed. I don't know. I don't have any locales installed, and standard GNU libc locale support sucks (read the end of 'man setlocale', for instance). Maybe "us" is not the right string, "en", "en_US" or something like that might be better. Try to look inside the locales package, maybe there is a list somewhere... I was hoping an expert would enter the thread :). Did setting it work on a Windows box? -- Remco Gerlich From rick@niof.net Wed Mar 28 17:44:14 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 28 Mar 2001 12:44:14 -0500 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 In-Reply-To: <XFMail.20010328093803.shaleh@valinux.com>; from shaleh@valinux.com on Wed, Mar 28, 2001 at 09:38:03AM -0800 References: <20010328122033.C26119@tc.niof.net> <XFMail.20010328093803.shaleh@valinux.com> Message-ID: <20010328124414.D26119@tc.niof.net> On Wed, Mar 28, 2001 at 09:38:03AM -0800, Sean 'Shaleh' Perry wrote: > > > > When I do that [actually, locale.setlocale(locale.LC_ALL,"us")] I get > > 'locale setting not supported.' What do I need to do to get it > > supported? I'm running debian and the 'locales' package is installed. > > > > because debian currently ships with locales support enabled but the actual > locales are not being generated (to save space/time at the request of our > users). cd /etc/ and edit locale.gen, then run locale-gen as root. Not quite, but your response led me to the answer. It should be: locale.setlocale(locale.LC_ALL,"en_US") There are several english formats, several french formats, etc. How platform (in)dependent is this "us" vs "en_US"? -- "If ye love wealth better than liberty, the tranquility of servitude better than the animating contest of freedom, go home from us in peace. We seek not your counsels or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen." -- Samuel Adams Rick Pasotto email: rickp@telocity.com From van@lindbergs.org Wed Mar 28 17:43:12 2001 From: van@lindbergs.org (VanL) Date: Wed, 28 Mar 2001 10:43:12 -0700 Subject: [Tutor] Installing a local package? Message-ID: <3AC222B0.E1731F2D@lindbergs.org> Hello, I am trying to install a package on a shared server where I don't have write access to the /usr/local/lib/python* directories. Does anyone know how I can define and install to a local site-packages directory? Thanks, VanL From kromag@nsacom.net Wed Mar 28 19:53:53 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Wed, 28 Mar 2001 11:53:53 -0800 (PST) Subject: [Tutor] Which python+apache scheme is preferred? Message-ID: <200103281953.f2SJrrC31741@pop.nsacom.net> I recently got PyApache working. Everything seems to work just fine. I have just seen mod_python, and it seems to be better documented and have a more active development site. Is there a general concensus on which of these modules is best for a beginner? Thanks! From shaleh@valinux.com Wed Mar 28 17:52:35 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 28 Mar 2001 09:52:35 -0800 (PST) Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 In-Reply-To: <20010328124414.D26119@tc.niof.net> Message-ID: <XFMail.20010328095235.shaleh@valinux.com> >> >> because debian currently ships with locales support enabled but the actual >> locales are not being generated (to save space/time at the request of our >> users). cd /etc/ and edit locale.gen, then run locale-gen as root. > > Not quite, but your response led me to the answer. It should be: > > locale.setlocale(locale.LC_ALL,"en_US") > > There are several english formats, several french formats, etc. > > How platform (in)dependent is this "us" vs "en_US"? > you want to use en_US or de_DE. Or better yet, do not frob the value of locale in the script at all. The user should have his locale set if he wants things to use it anyways. And unless you enabled other locales, debian does ship with them disabled. I tried to set de_DE to test your code example and received the same message you did. Then I enabled de and all was well. From kalle@gnupung.net Wed Mar 28 17:51:04 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 28 Mar 2001 19:51:04 +0200 Subject: [Tutor] Installing a local package? In-Reply-To: <3AC222B0.E1731F2D@lindbergs.org>; from van@lindbergs.org on Wed, Mar 28, 2001 at 10:43:12AM -0700 References: <3AC222B0.E1731F2D@lindbergs.org> Message-ID: <20010328195104.C1360@apone.network.loc> Sez VanL: > Hello, > > I am trying to install a package on a shared server where I don't have > write access to the /usr/local/lib/python* directories. Does anyone > know how I can define and install to a local site-packages directory? Just set up your environment so that your directory is in $PYTHONPATH. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From scarblac@pino.selwerd.nl Wed Mar 28 17:48:30 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 28 Mar 2001 19:48:30 +0200 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 In-Reply-To: <20010328124414.D26119@tc.niof.net>; from rick@niof.net on Wed, Mar 28, 2001 at 12:44:14PM -0500 References: <20010328122033.C26119@tc.niof.net> <XFMail.20010328093803.shaleh@valinux.com> <20010328124414.D26119@tc.niof.net> Message-ID: <20010328194830.A27978@pino.selwerd.nl> On Wed, Mar 28, 2001 at 12:44:14PM -0500, Rick Pasotto wrote: > How platform (in)dependent is this "us" vs "en_US"? This "us" was a guess of mine. Disregard... -- Remco Gerlich From kalle@gnupung.net Wed Mar 28 18:02:06 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 28 Mar 2001 20:02:06 +0200 Subject: [Tutor] Which python+apache scheme is preferred? In-Reply-To: <200103281953.f2SJrrC31741@pop.nsacom.net>; from kromag@nsacom.net on Wed, Mar 28, 2001 at 11:53:53AM -0800 References: <200103281953.f2SJrrC31741@pop.nsacom.net> Message-ID: <20010328200206.D1360@apone.network.loc> Sez kromag@nsacom.net: > I recently got PyApache working. Everything seems to work just fine. I > have just seen mod_python, and it seems to be better documented and have a > more active development site. Is there a general concensus on which of > these modules is best for a beginner? I was just wndering about that myself. There is another contender, mod_snake at http://modsnake.sourceforge.net/ mod_snake and mod_python seem to be more powerful than PyApache, and perhaps better documented too. Just from the feeling, I would go with mod_snake, but I don't have any good reasons at the moment. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From dsh8290@rit.edu Wed Mar 28 19:09:40 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 14:09:40 -0500 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 In-Reply-To: <20010328124414.D26119@tc.niof.net>; from rick@niof.net on Wed, Mar 28, 2001 at 12:44:14PM -0500 References: <20010328122033.C26119@tc.niof.net> <XFMail.20010328093803.shaleh@valinux.com> <"from shaleh"@valinux.com> <20010328124414.D26119@tc.niof.net> Message-ID: <20010328140940.A7102@harmony.cs.rit.edu> On Wed, Mar 28, 2001 at 12:44:14PM -0500, Rick Pasotto wrote: | On Wed, Mar 28, 2001 at 09:38:03AM -0800, Sean 'Shaleh' Perry wrote: | | How platform (in)dependent is this "us" vs "en_US"? See http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt for the ISO language codes and http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html for the ISO country codes. The format is lang_country (as in "en_US" or "en_GB" ) I got those links from the java.util.Locale class's documentation on java.sun.com. -D From dsh8290@rit.edu Wed Mar 28 19:17:13 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 14:17:13 -0500 Subject: [Tutor] Q: Do Functions Have Any Class? In-Reply-To: <sac07940.050@madis2.truax.covance.com>; from curtis.larsen@Covance.Com on Tue, Mar 27, 2001 at 11:27:31AM -0600 References: <sac07940.050@madis2.truax.covance.com> Message-ID: <20010328141713.B7102@harmony.cs.rit.edu> On Tue, Mar 27, 2001 at 11:27:31AM -0600, Curtis Larsen wrote: | Besides their design and concept differences, is there really any | (performance-based) reason to use classes/methods in a script as opposed | to using functions? Does it depend on how large your main script is? Classes are a template for instances which are a combination of data and functions. They are really useful when you have some data and some operations that are common for that data. You can hide the actual data under the functions so that if the implementation changes, clients won't have to know and will still work. Classes also allow you to have several different, indepents sets of the data (instances). Functions in a module can only have persistant state if it is in a global variable, which prevents it from being reentrant. This matters when using threads, or when you want to deal with 2 independent sets of data at the same time. If you have a simple script, or some operation that doesn't have any persistant state (such as math operations, for example) it is better to use a function. Take Java for example. Java forces one to use a class for everything. As a result, the Math class is composed entirely of static methods becuase things like sqrt and pow don't have any state. It is a ridiculous design brought about by the requirement of classes. When you are using python, performance is usually a moot point. There may be a slight difference in calling a standalone function versus an instance function but it is not enough to be significant. | When would you want to use one over the other? Use the one that fits the complexity and organization of your design. -D From dsh8290@rit.edu Wed Mar 28 19:24:26 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 14:24:26 -0500 Subject: [Tutor] Creating instances (group program revisited) In-Reply-To: <3AC02455.2CCF63F2@seatech.fau.edu>; from bdupire@seatech.fau.edu on Tue, Mar 27, 2001 at 12:25:41AM -0500 References: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> <3AC02455.2CCF63F2@seatech.fau.edu> Message-ID: <20010328142426.C7102@harmony.cs.rit.edu> On Tue, Mar 27, 2001 at 12:25:41AM -0500, Benoit Dupire wrote: | | Note1 : if you want your pb to be really OO, put the loadFile function in a | class... (see below) Not quite. OO stands for Object Oriented. You don't _need_ classes to make objects and operate in an object oriented way. Python is OO through and through. There is nothing in Python that isn't an object. Even functions are objects in Python. Putting the loadFile function into a class would be more class-based, but not necessarily more OO. I'm not arguing that the function shouldn't be in a class, that depends on the overall design, but to be OO doesn't require classes. Only in Java, Eiffel, C++, and Smalltalk (not sure about Smalltalk since I have never used or learned it). -D From dsh8290@rit.edu Wed Mar 28 19:32:01 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 14:32:01 -0500 Subject: [Tutor] Windows Programs vs. Text-Cell Graphics In-Reply-To: <01032610335307.16086@shecom>; from tim@johnsons-web.com on Mon, Mar 26, 2001 at 12:11:20PM -0900 References: <20010326192021.A23527@pino.selwerd.nl> <01032610335307.16086@shecom> Message-ID: <20010328143201.D7102@harmony.cs.rit.edu> On Mon, Mar 26, 2001 at 12:11:20PM -0900, Tim Johnson wrote: | On Mon, 26 Mar 2001, you wrote: | | > Ncurses. Curses (and ncurses, "new curses") is a library for putting text on | > some place on a terminal (or screen). Writing directly to video memory is | > silly, this is not the 80s... | | Not silly on a 16-bit app. Very fast and clean actually.... Clean if you only want it to work in a single environment. Curses is environment agnostic. If you wanted your app to run on both a VT100 and TN3270 and XTerm use curses. If you want to write it 3 times use direct access to the terminal. | > Curses is cross platform, works over Telnet, etc. | | Just curious, but I'd like to see the source code. Where is it available? Check with any Linux distribution. -D From mr804@users.757.org Wed Mar 28 22:02:42 2001 From: mr804@users.757.org (Mr 804) Date: Wed, 28 Mar 2001 17:02:42 -0500 (EST) Subject: [Tutor] (no subject) In-Reply-To: <20010328143201.D7102@harmony.cs.rit.edu> Message-ID: <Pine.BSO.4.21.0103281702150.13016-100000@users.757.org> can someone help me un-subscribe. I can't get it to work with lynx... From deirdre@deirdre.net Wed Mar 28 22:03:57 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 28 Mar 2001 14:03:57 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <Pine.BSO.4.21.0103281702150.13016-100000@users.757.org> Message-ID: <Pine.LNX.4.31.0103281402580.14042-100000@emperor.deirdre.org> On Wed, 28 Mar 2001, Mr 804 wrote: > can someone help me un-subscribe. I can't get it to work with lynx... I just unsubscribed you; if anyone has problems, they should email tutor-admin@python.org and it'll go only to Wes and myself. I'll also look into the lynx issue and, if necessary, file a bug. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From nally@radiks.net Wed Mar 28 22:21:04 2001 From: nally@radiks.net (Paul T. McNally) Date: Wed, 28 Mar 2001 16:21:04 -0600 Subject: [Tutor] (no subject) References: <Pine.BSO.4.21.0103281702150.13016-100000@users.757.org> Message-ID: <00e601c0b7d5$61297d80$ba54e8cf@LocalHost> We're gonna haf to ask you ta leave. ----- Original Message ----- From: "Mr 804" <mr804@users.757.org> To: <tutor@python.org> Cc: <tutor@python.org> Sent: Wednesday, March 28, 2001 4:02 PM Subject: [Tutor] (no subject) > > can someone help me un-subscribe. I can't get it to work with lynx... > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From bdupire@seatech.fau.edu Wed Mar 28 23:17:22 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 28 Mar 2001 18:17:22 -0500 Subject: [Tutor] Q: Do Functions Have Any Class? References: <sac07940.050@madis2.truax.covance.com> <20010328141713.B7102@harmony.cs.rit.edu> Message-ID: <3AC27102.3F71B0B7@seatech.fau.edu> D-Man wrote: > On Tue, Mar 27, 2001 at 11:27:31AM -0600, Curtis Larsen wrote: > | Besides their design and concept differences, is there really any > | (performance-based) reason to use classes/methods in a script as opposed > | to using functions? Does it depend on how large your main script is? > > If you have a simple script, or some operation that doesn't have any > persistant state (such as math operations, for example) it is better > to use a function. > > Take Java for example. Java forces one to use a class for everything. > As a result, the Math class is composed entirely of static methods > becuase things like sqrt and pow don't have any state. It is a > ridiculous design brought about by the requirement of classes. I don't think that Java is the first OO language to come up with such a design... It just makes it coherent with the rest of the language: these functions don't need a state so let's use them without defining a new object. But let's regroup them in the same class, because they really do belong to this class.... why ? Because a class is really something which is conceptual: it represents something coherent. The sqrt function is a behavior of the math concept.. In Python, there is another way to implement it: you've got a math module and some functions in it. But a Python module can also have a state (its global variables) What is the difference between a Python module and a class, when you don't instanciate the latter one ? Well you can derive the class and extend it.... I think that's coherent, if you want to add your own maths functions... In the ""module"" way to do it, you have to open the math module which comes with the Python distribution, edit it, and save it ? Is this better? It's really up to you. I never had to add another math function. But for other examples (parser...) it might be useful to have a class, (override a method, so that it behaves differently for the same token). For the Math module, you can also override a method, for example if you want sqrt() to return you something specific.. At the starting point, the OO 'spirit' consists of gaining benefits from modularity.. we want to build reusable module (not in the Python sense) A Module is just a reasonable independant chunk of a program, because there is a limit to how much one person can understand at any one time. A system is a collection of modules.... Modules might be: files, functions, procedures, subroutines, classes, larger language constructs (called modules in Python), or independant programs or subsystems. It depends on the context. Much of what makes a good module is true of modules at many levels of abstraction... So coming up with a Math class is not so weird. If you would like your language to be pure OO, then everything is an object, even integer and floats... so a = Float(); a.sqrt() where sqrt is a method, will be the correct way to do it. I heard that in Ruby, all was object... I don't know if they implement the language in this way ( a.sqrt() ) , but i assume yes... This brings us to the performance issue... I read in the Python newsgroup that Ruby was slower than Python for programs dealing with a lot of computations... Why ? because every thing is object, and OO is no faster than the structural programming paradigm (the extra-layer to access the data...) So, at this point, you begin to worry about it. Benoit From m_konermann@gmx.de Wed Mar 28 23:29:49 2001 From: m_konermann@gmx.de (Marcus Konermann) Date: Thu, 29 Mar 2001 01:29:49 +0200 Subject: [Tutor] i need help on builtin function math Message-ID: <3AC273ED.5DE82F3B@gmx.de> --------------A4E320A0682744D632A7562B Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit hello ! i want to use the sqrt() function of the builtin funtion math in that kind: import math ... a=0 a=sqrt(whatever) and than a NameError: sqrt occured and i don´t know why ? Is it depending on the OS (i use Windows98 and the pywin editor). Other functions, like pow(), from the math module are working. Can anyone help me with my problem ? thank´s a lot greetings Marcus --------------A4E320A0682744D632A7562B Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> hello ! <p>i want to use the sqrt() function of the builtin funtion math in that kind: <p><i>import math</i> <br><i>...</i> <br><i>a=0</i> <br><i>a=sqrt(whatever)</i> <p>and than a <b>NameError: sqrt</b> occured and i don´t know why ? Is it depending on the OS (i use Windows98 and the pywin editor). Other functions, like pow(), from the math module are working. <br>Can anyone help me with my problem ? <p>thank´s a lot <br>greetings <br>Marcus</html> --------------A4E320A0682744D632A7562B-- From bdupire@seatech.fau.edu Wed Mar 28 23:58:08 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 28 Mar 2001 18:58:08 -0500 Subject: [Tutor] Creating instances (group program revisited) References: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> <3AC02455.2CCF63F2@seatech.fau.edu> <20010328142426.C7102@harmony.cs.rit.edu> Message-ID: <3AC27A90.90100D4F@seatech.fau.edu> D-Man wrote: > On Tue, Mar 27, 2001 at 12:25:41AM -0500, Benoit Dupire wrote: > | > | Note1 : if you want your pb to be really OO, put the loadFile function in a > | class... (see below) > > Not quite. OO stands for Object Oriented. You don't _need_ classes > to make objects and operate in an object oriented way. I agree. The main idea is to have modules (see previous message). Just the way i'll do it.... > Python is OO > through and through. There is nothing in Python that isn't an object. Ints, Floats etc.. are not objects, but types. Files ???? > > Even functions are objects in Python. Putting the loadFile function > into a class would be more class-based, but not necessarily more OO. Because Python is typeless you don't see the advantage However, In C++ you can overload this function if you want to read from something else than a file. addStudent( File); addStudent(String); A better design in my mind would be to have a addStudent(File) method in Teacher, and a getStudent() method in the StudentListFile class, which derives from the File class. In this way, we don't have to modify the Teacher class implementation if we change the file format. If we modify the file syntax, we modify the internals of the File class. > > I'm not arguing that the function shouldn't be in a class, that > depends on the overall design, but to be OO doesn't require classes. > Only in Java, Eiffel, C++, and Smalltalk (not sure about Smalltalk > since I have never used or learned it). you can also remove C++ from the list... (Friend functions). > > > -D > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From bleh99@hotmail.com Thu Mar 29 00:11:03 2001 From: bleh99@hotmail.com (spi) Date: Wed, 28 Mar 2001 19:11:03 -0500 Subject: [Tutor] How do I use calldll and windll? Message-ID: <OE2xPTi68KtBsejEBCu000043bd@hotmail.com> I downloaded and installed calldll and dynwin and am able to import successfully but when I try to use an example I get this error: >>> import windll >>> kernel32 = windll.module('kernel32') Traceback (innermost last): File "<interactive input>", line 1, in ? AttributeError: module >>> From cdwom@mpinet.net Thu Mar 29 00:27:47 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Wed, 28 Mar 2001 19:27:47 -0500 Subject: [Tutor] Need some help with some Basic TKinter stuff Message-ID: <001c01c0b7e7$155b3080$fadc35d8@KellyJoW> I'm brand new here, brand new to python, and brand new to programing in general (I bet you get these alot :) Anywho. I've learned enough to tackle my first big project: A bigger badder Notepad. I figgured it'd be an easy project to start with, but it could progress to something very difficult, so it'd be my guide to learning python. I've peeked at the IDLE source a bit, and thats helped me alot, but there are still a few things I don't know how to do (probably a lot more than a few): 1. How can add Copy Cut and Paste to an edit menu? I know how to make the menu items, I just don't know how to assign them to Cut, Copy, and Paste actions. 2. I know that you can askopenfilename and asksaveas to bring up premade Open and Save As Dialogue boxes. Is there a similar one for print? 3. How can I add Keyboard shortcuts to menu items? Particuarlt Cut, Copy, Paste, Save, and Open if they are prebuilt, but I'd also like to know how to generate my own (for ex. If I added custom menuitem and wanted a shortcut to it) ummm.. thats all I can think of for now, I'm sure there will be tons more. This Python stuff is great though! Thanks in advance for any help!! So long, and thanks for all the fish! Corey Check out my Webpage at: schitzomedia.y0ru.net and vote for the top 10 games of all time!!! From tim@johnsons-web.com Thu Mar 29 00:31:40 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Wed, 28 Mar 2001 15:31:40 -0900 Subject: [Tutor] Windows Programs vs. Text-Cell Graphics References: <20010328143201.D7102@harmony.cs.rit.edu> Message-ID: <0103281541320G.18375@shecom> On Wed, 28 Mar 2001, you wrote: > On Mon, Mar 26, 2001 at 12:11:20PM -0900, Tim Johnson wrote: > | On Mon, 26 Mar 2001, you wrote: > | > | > Ncurses. Curses (and ncurses, "new curses") is a library for putting text on > | > some place on a terminal (or screen). Writing directly to video memory is > | > silly, this is not the 80s... > | > | Not silly on a 16-bit app. Very fast and clean actually.... > > Clean if you only want it to work in a single environment. Curses is > environment agnostic. If you wanted your app to run on both a VT100 > and TN3270 and XTerm use curses. If you want to write it 3 times use > direct access to the terminal. I haven't done anything 16-bit in years. My reference to direct video access was to distinguish between that and some of the other techniques that were used like writing to BIOS or ansi.sys. I know .... I'm dating myself > | > Curses is cross platform, works over Telnet, etc. > | > | Just curious, but I'd like to see the source code. Where is it available? > > Check with any Linux distribution. Yes, is on my machine, and I have been looking on it. <Sigh> Most of my customers blanch when they see "text graphics" these days, but it is still valid. On Window$, ZTree leaves windows explorer in the dust. and on my RH machine, xnftp leaves Igloo behind easily </sigh> thanks -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From rick@niof.net Thu Mar 29 00:39:57 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 28 Mar 2001 19:39:57 -0500 Subject: [Tutor] i need help on builtin function math In-Reply-To: <3AC273ED.5DE82F3B@gmx.de>; from m_konermann@gmx.de on Thu, Mar 29, 2001 at 01:29:49AM +0200 References: <3AC273ED.5DE82F3B@gmx.de> Message-ID: <20010328193957.E26119@tc.niof.net> On Thu, Mar 29, 2001 at 01:29:49AM +0200, Marcus Konermann wrote: > hello ! > > i want to use the sqrt() function of the builtin funtion math in that > kind: > > import math > ... > a=0 > a=sqrt(whatever) > > and than a NameError: sqrt occured and i don´t know why ? Is it > depending on the OS (i use Windows98 and the pywin editor). Other > functions, like pow(), from the math module are working. > Can anyone help me with my problem ? pow() is a builtin. You don't need to import math to use it. sqrt is part of the math module so you need to specify where to find it. a = math.sqrt(whatever) -- "Being an elected Libertarian is like being a designated driver in a bar." --- Michael Emerling Cloud Rick Pasotto email: rickp@telocity.com From s349929@student.uq.edu.au Thu Mar 29 00:57:06 2001 From: s349929@student.uq.edu.au (Suzanne Little) Date: Thu, 29 Mar 2001 10:57:06 +1000 (GMT+1000) Subject: [Tutor] Pickling In-Reply-To: <Pine.LNX.4.21.0103271056090.11322-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.OSF.4.30.0103291032490.8-100000@student.uq.edu.au> On Tue, 27 Mar 2001, Daniel Yoo wrote: > > Ah! Most likely, you'll need to import the minidom class; pickle assumes > that the class is in Python's memory before you unpickle stuff. The > problem about unpickling is that Python needs to know what the minidom > class looks like --- and it's restricted from automatically loading > classes, so that's why it's confused. > > This is a common error, so don't worry about it. If you do the line: > > from xml.dom import minidom Thanks for your reply Daniel. What you've said makes sense and re-reading the documentation I can see what it means. Unfortunately this doesn't seem to be working in this case and I'm thoroughly confused. At the end of this message is a session showing what happened. Basically I'm getting the same error message regardless of importing and if I try it again (without changing anything) I get all sorts of different messages. I'm getting the feeling that pickle may not really work for what I'm aiming at. :( Even if I can get this simple example to work, I'm still getting different errors when I try to pickle.dump bigger xml files. I'm getting ready to move on and try something else but I'd like to work out why this isn't working so I'll keep picking at it. Thanks for any suggestions, Suzanne Python 2.0 (#1, Feb 14 2001, 10:51:28) [GCC 2.95.2 19991024 (release)] on sunos5 Type "copyright", "credits" or "license" for more information. >>> import pickle >>> from xml.dom import minidom >>> f = open('pickleTest') >>> pickle.load(f) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in load return Unpickler(file).load() File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in load dispatch[key](self) KeyError: >>> pickle.load(f) #because I have unerring faith that maybe I looked at #it wrong.... Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in load return Unpickler(file).load() File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in load dispatch[key](self) File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 797, in load_put self.memo[self.readline()[:-1]] = self.stack[-1] IndexError: list index out of range >>> This second, different error occurs regardless of what I load. Even if I don't load the minidom. If I try it again (why not! :) >>> pickle.load(f) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in load return Unpickler(file).load() File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in load dispatch[key](self) KeyError: 7 >>> Trying it once more shows a different message again (similar to the second but about self.stack). Then another different message and so on and so on. I'm going to stop now. :) -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From babyboy@oninet.pt Thu Mar 29 11:02:18 2001 From: babyboy@oninet.pt (wilson edgar) Date: Thu, 29 Mar 2001 03:02:18 -0800 Subject: [Tutor] object seriliazation Message-ID: <001401c0b83f$b93b1000$1f0c3ad5@wcimageqci2cvz> This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C0B7FC.AA72DD70 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable hiya=20 can someone please point me out a resource for object seriliazation (the = shelve module in particular). and just one more question :-) is there any particular trick while using = shelve with Tkinter objects (c'os can't get them to work together)=20 thanks in advance wilson edgar ------=_NextPart_000_0011_01C0B7FC.AA72DD70 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>hiya </FONT></DIV> <DIV><FONT face=3DArial size=3D2>can someone please point me out a = resource for=20 object seriliazation (the shelve module in particular).</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>and just one more question :-) is there = any=20 particular trick while using shelve with Tkinter objects (c'os can't get = them to=20 work together) </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>thanks in advance</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>wilson edgar</FONT></DIV></BODY></HTML> ------=_NextPart_000_0011_01C0B7FC.AA72DD70-- From girle999@csl.ajou.ac.kr Thu Mar 29 02:09:37 2001 From: girle999@csl.ajou.ac.kr (=?ks_c_5601-1987?B?seiw5rz2?=) Date: Thu, 29 Mar 2001 11:09:37 +0900 Subject: I don't want [Tutor] mailing list... (No context) Message-ID: <004201c0b7f5$4ecc5b60$aa141eca@girle999> This is a multi-part message in MIME format. ------=_NextPart_000_003F_01C0B840.BE679110 Content-Type: text/plain; charset="ks_c_5601-1987" Content-Transfer-Encoding: base64 DQpnaXJsZTk5OUB5YWhvby5jby5rcg0KDQo= ------=_NextPart_000_003F_01C0B840.BE679110 Content-Type: text/html; charset="ks_c_5601-1987" Content-Transfer-Encoding: base64 PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWtz X2NfNTYwMS0xOTg3IiBodHRwLWVxdWl2PUNvbnRlbnQtVHlwZT4NCjxNRVRBIGNvbnRlbnQ9Ik1T SFRNTCA1LjAwLjI5MjAuMCIgbmFtZT1HRU5FUkFUT1I+DQo8U1RZTEU+PC9TVFlMRT4NCjwvSEVB RD4NCjxCT0RZIGJnQ29sb3I9I2MwYzBjMD4NCjxESVY+Jm5ic3A7PC9ESVY+DQo8RElWPjxGT05U IHNpemU9Mj48QSANCmhyZWY9Im1haWx0bzpnaXJsZTk5OUB5YWhvby5jby5rciI+Z2lybGU5OTlA eWFob28uY28ua3I8L0E+PEJSPjwvRk9OVD48L0RJVj48L0JPRFk+PC9IVE1MPg0K ------=_NextPart_000_003F_01C0B840.BE679110-- From jsc_lists@rock-tnsc.com Thu Mar 29 02:38:31 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Thu, 29 Mar 2001 10:38:31 +0800 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <20010328122033.C26119@tc.niof.net> Message-ID: <JMEOIILNBOJMOPBDBMGMIECGCIAA.jsc_lists@rock-tnsc.com> > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Rick Pasotto > Sent: Thursday, March 29, 2001 1:21 AM > To: tutor@python.org > Subject: Re: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 > When I do that [actually, locale.setlocale(locale.LC_ALL,"us")] I get > 'locale setting not supported.' What do I need to do to get it > supported? I'm running debian and the 'locales' package is installed. > It worked fine on my Windows box. Haven't had a chance to check on Linux yet. On my Windows box if I try and set the locale to "de" it gives me the same error (locale setting not supported). I guess we are both missing important information in our setups. FYI if I set the locale to "us" and then "uk" I get the reply: >>> locale.setlocale(locale.LC_ALL, "us") 'English_United States.1252' >>> locale.setlocale(locale.LC_ALL, "uk") 'English_United Kingdom.1252' Regards, Jethro From jsc_lists@rock-tnsc.com Thu Mar 29 02:49:10 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Thu, 29 Mar 2001 10:49:10 +0800 Subject: [Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ? In-Reply-To: <20010328161725.A27160@pino.selwerd.nl> Message-ID: <JMEOIILNBOJMOPBDBMGMAECHCIAA.jsc_lists@rock-tnsc.com> > The correct command seems to be 'locale.format("%f", f, 1). > > The '1' means that grouping is used, i.e. commas every three figures. As > least, if I read the docs correctly > (http://www.python.org/doc/current/lib/module-locale.html). Thank you. That makes a *big* difference > Did the setlocale(LC_ALL,"us") work? What's the output of > locale.localeconv()? Yes. The output is: >>> locale.setlocale(locale.LC_ALL, "us") 'English_United States.1252' Interestingly enough though the attempt to set German using "de" didn't work. But France using "fr" was successful. I guess there are some more things that I will investigate here. > The currency symbol is in locale.localeconv()['currency_symbol'], > apparently. I can't test here and I've never used it, so I'm > getting it from > the docs... > Thanks. I was hoping there would be a function that given a number would return a properly formatted string with the currency symbol. This should be easy enough to right using the paramaters from locale. Once again Thanks. Jethro > From babyboy@oninet.pt Thu Mar 29 12:26:50 2001 From: babyboy@oninet.pt (wilson edgar) Date: Thu, 29 Mar 2001 04:26:50 -0800 Subject: [Tutor] i need help on builtin function math References: <3AC273ED.5DE82F3B@gmx.de> Message-ID: <002701c0b84b$888aa720$6a0d3ad5@wcimageqci2cvz> This is a multi-part message in MIME format. ------=_NextPart_000_0024_01C0B808.79930020 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable why don't you try this: >>> import math >>> a =3D 0 >>> b =3D math.sqrt(a) >>> print b 0.0 >>>=20 or if just want to use the sqrt function: >>> from math import sqrt >>> a =3D 0 >>> b =3D sqrt(a) >>> print b 0.0 the pow function is part of the builtin functions. it would be a good idea for you to read about the namespaces HTH wilson edgar ----- Original Message -----=20 From: Marcus Konermann=20 To: tutor@python.org=20 Sent: Wednesday, March 28, 2001 3:29 PM Subject: [Tutor] i need help on builtin function math hello !=20 i want to use the sqrt() function of the builtin funtion math in that = kind:=20 import math=20 ...=20 a=3D0=20 a=3Dsqrt(whatever)=20 and than a NameError: sqrt occured and i don=B4t know why ? Is it = depending on the OS (i use Windows98 and the pywin editor). Other = functions, like pow(), from the math module are working.=20 Can anyone help me with my problem ?=20 thank=B4s a lot=20 greetings=20 Marcus=20 ------=_NextPart_000_0024_01C0B808.79930020 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2>why don't you try this:</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>>>> import = math<BR>>>> a =3D=20 0<BR>>>> b =3D math.sqrt(a)<BR>>>> print=20 b<BR>0.0<BR>>>> </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>or if just want to use the sqrt=20 function:</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>>>> from math import = sqrt<BR>>>>=20 a =3D 0<BR>>>> b =3D sqrt(a)<BR>>>> print = b<BR>0.0</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>the pow function is part of the builtin = functions.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>it would be a good idea for you to read = about the=20 namespaces</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>HTH</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>wilson edgar</FONT></DIV></FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:m_konermann@gmx.de" = title=3Dm_konermann@gmx.de>Marcus=20 Konermann</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = href=3D"mailto:tutor@python.org"=20 title=3Dtutor@python.org>tutor@python.org</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, March 28, 2001 = 3:29=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] i need help on = builtin=20 function math</DIV> <DIV><BR></DIV>hello !=20 <P>i want to use the sqrt() function of the builtin funtion math in = that kind:=20 <P><I>import math</I> <BR><I>...</I> <BR><I>a=3D0</I>=20 <BR><I>a=3Dsqrt(whatever)</I>=20 <P>and than a <B>NameError: sqrt</B> occured and i don=B4t know why ? = Is it=20 depending on the OS (i use Windows98 and the pywin editor). Other = functions,=20 like pow(), from the math module are working. <BR>Can anyone help me = with my=20 problem ?=20 <P>thank=B4s a lot <BR>greetings <BR>Marcus = </P></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_0024_01C0B808.79930020-- From dsh8290@rit.edu Thu Mar 29 03:44:45 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 22:44:45 -0500 Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE2xPTi68KtBsejEBCu000043bd@hotmail.com>; from bleh99@hotmail.com on Wed, Mar 28, 2001 at 07:11:03PM -0500 References: <OE2xPTi68KtBsejEBCu000043bd@hotmail.com> Message-ID: <20010328224445.A9003@harmony.cs.rit.edu> On Wed, Mar 28, 2001 at 07:11:03PM -0500, spi wrote: | I downloaded and installed calldll and dynwin and am able to import | successfully | but when I try to use an example I get this error: | | >>> import windll | >>> kernel32 = windll.module('kernel32') | Traceback (innermost last): | File "<interactive input>", line 1, in ? | AttributeError: module | >>> | Apparently windll is a valid module (the import succeeded). Also, it apparently doesn't have any attributes name "module" (the error message). Try the following to see what attributes it does have : import windll dir( windll ) Other than that, I don't think I'll be of much help. I don't know what those modules are for either. -D From tim.one@home.com Thu Mar 29 03:50:39 2001 From: tim.one@home.com (Tim Peters) Date: Wed, 28 Mar 2001 22:50:39 -0500 Subject: [Tutor] Float Numbers. 98/100 returns 0.97999999999999998 In-Reply-To: <LNBBLJKPBEHFEDALKOLCKEMGJIAA.tim.one@home.com> Message-ID: <LNBBLJKPBEHFEDALKOLCKEPKJIAA.tim.one@home.com> FYI, wrt FixedPoint.py under ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/DataStructures/ Guido kindly replaced the hoary old code with a new version that *should* work under Python 1.5.2 and 2.0 (and 2.1, when it comes out next month). This has to do with that, for example, str(42L) used to produce "42L" but in recent Python produces "42" instead. In a decade of using Python, that's the only change that gave me real trouble; OTOH, it was a *good* change, so I'm not griping too loudly. sorry-for-the-hassle!-ly y'rs - tim From bleh99@hotmail.com Thu Mar 29 04:13:16 2001 From: bleh99@hotmail.com (spi) Date: Wed, 28 Mar 2001 23:13:16 -0500 Subject: [Tutor] How do I use calldll and windll? References: <OE2xPTi68KtBsejEBCu000043bd@hotmail.com> <20010328224445.A9003@harmony.cs.rit.edu> Message-ID: <OE63lbvTvCv3uS7sBdx000037cc@hotmail.com> Here is the result that I got: >>> dir (windll) ['__builtins__', '__doc__', '__file__', '__name__'] >>> This is a paste from the description of calldll located at http://www.nightmare.com/software.html >With this module you can call any function in any DLL. This means that you can do just about >anything on Win32. Includes an (occasionally-resurrected) library that gives access to lots of the >system GUI features. I have used this to build stand-alone Windows applications that are completely >implemented in Python (including the Message Loop). >Note: The calldll library has gotten quite large, and has been spun off into a separate distribution, >called DynWin. DynWin is now a full-blown Win32 GUI development environment Dynwin is the distribution that windll is located in. this is a paste of how they said I should use it Usage: To create a dll module object: >>> kernel32 = windll.module ('kernel32') >>> kernel32 <win32 module 'kernel32' (0 functions)> To reference a function: >>> kernel32.Beep <callable function "Beep"> To call a function: >>> kernel32.Beep (1000, 50) For the life of me I cannot get this to work.. if anyone can help me out on this I would greatly appreciate it. ----- Original Message ----- From: "D-Man" <dsh8290@rit.edu> To: <tutor@python.org> Sent: Wednesday, March 28, 2001 10:44 PM Subject: Re: [Tutor] How do I use calldll and windll? > On Wed, Mar 28, 2001 at 07:11:03PM -0500, spi wrote: > | I downloaded and installed calldll and dynwin and am able to import > | successfully > | but when I try to use an example I get this error: > | > | >>> import windll > | >>> kernel32 = windll.module('kernel32') > | Traceback (innermost last): > | File "<interactive input>", line 1, in ? > | AttributeError: module > | >>> > | > > Apparently windll is a valid module (the import succeeded). Also, it > apparently doesn't have any attributes name "module" (the error > message). Try the following to see what attributes it does have : > > import windll > dir( windll ) > > Other than that, I don't think I'll be of much help. I don't know > what those modules are for either. > > -D > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From dsh8290@rit.edu Thu Mar 29 04:32:55 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 28 Mar 2001 23:32:55 -0500 Subject: [Tutor] Creating instances (group program revisited) In-Reply-To: <3AC27A90.90100D4F@seatech.fau.edu>; from bdupire@seatech.fau.edu on Wed, Mar 28, 2001 at 06:58:08PM -0500 References: <Pine.GSO.4.21.0103262156590.11164-100000@isis.visi.com> <3AC02455.2CCF63F2@seatech.fau.edu> <20010328142426.C7102@harmony.cs.rit.edu> <3AC27A90.90100D4F@seatech.fau.edu> Message-ID: <20010328233255.B9003@harmony.cs.rit.edu> On Wed, Mar 28, 2001 at 06:58:08PM -0500, Benoit Dupire wrote: | D-Man wrote: | | > On Tue, Mar 27, 2001 at 12:25:41AM -0500, Benoit Dupire wrote: | > | | > | Note1 : if you want your pb to be really OO, put the loadFile | > | function in a class... (see below) | | > Not quite. OO stands for Object Oriented. You don't _need_ classes | > to make objects and operate in an object oriented way. | | I agree. The main idea is to have modules (see previous message). | Just the way i'll do it.... Good. <grin> I was beginning to wonder after your previous message defending's Java's class-based model. (and you are right that Java isn't the first/only language to use a strictly class-based moedl) | > Python is OO through and through. There is nothing in Python that | > isn't an object. | | Ints, Floats etc.. are not objects, but types. Files ???? ints floats string tuples list files, etc are objects. In _CPython_ the type/class split exists as an accident of implementation. The only difference is that integer objects are defined in C and thus have slight semantic differences to objects defined in python using the class construct. The difference is mainly that you can't add arbitrary members and there is no __class__ or __bases__ attribute. Jython, on the other hand, doesn't have this accident of implementation and all built-in types can be subclassed with python code. | > Even functions are objects in Python. Putting the loadFile function | > into a class would be more class-based, but not necessarily more OO. | | Because Python is typeless you don't see the advantage I think this is a common misconception. Python is _not_ typeless, it is simply _dynamicaly_ typed. If you write a function that takes a string argument, and I pass it an int, I will get a TypeError. In perl, otoh, you will have no way of knowing that I screwed up and your function will very happily and correctly give me the wrong anser. Here is an example, without even using functions >>> print "Hello " + 3 + " World" Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: cannot add type "int" to string >>> | However, In C++ you can overload this function if you want to read from | something else than a file. | addStudent( File); | addStudent(String); Overloading is a different issue, and I don't really miss it that much. It is also only marginally relevant for OO. C could use overloading just as effectively. | | A better design in my mind would be to have a addStudent(File) method | in Teacher, and a getStudent() method in the StudentListFile class, | which derives from the File class. | | In this way, we don't have to modify the Teacher class implementation | if we change the file format. If we modify the file syntax, we modify | the internals of the File class. How about having a StudentParser object (class, whatever ;-)) that can parse strings. Have a File that can load the file and hand the strings to the StudentParser to get back a Student. The Teacher can have a addStudent( file=None , astring=None ) function that overloads based on the keyword arguments. If you pass it a file, it will ask the File object to give back Students from it, which are actually created (ie new'ed or malloc'ed) by the StudentParser object. If you pass it a string, it will ask the StudentParser itself for the resulting Student object. | | > | > I'm not arguing that the function shouldn't be in a class, that | > depends on the overall design, but to be OO doesn't require classes. | > Only in Java, Eiffel, C++, and Smalltalk (not sure about Smalltalk | > since I have never used or learned it). | | you can also remove C++ from the list... (Friend functions). But C++'s object model is still class-based. I kind of actually liked Eiffel's acces modifers. C++ attempts a similar thing with Friend function/classes but isn't quite as flexible. I really like python's treament of everythin as first-class objects, including function and class objects. This makes it very cool to have a dictionary of options (ie user input) for keys and class objects as values. Then a simple dictionary lookup from the user's input to get the proper class object gives a nice polymorphic flow to the code. I used this (from Jython) to replace a long (ugly IMO) switch in Java code to get the right behavior. The situation was a menu for the user to pick a test to run on the code. It seems that we are mostly in agreement wrt OO. -D From dyoo@hkn.eecs.berkeley.edu Thu Mar 29 07:21:51 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 28 Mar 2001 23:21:51 -0800 (PST) Subject: I don't want [Tutor] mailing list... (No context) In-Reply-To: <004201c0b7f5$4ecc5b60$aa141eca@girle999> Message-ID: <Pine.LNX.4.21.0103282318480.26236-100000@hkn.eecs.berkeley.edu> On Thu, 29 Mar 2001, [ks_c_5601-1987] =B1=E8=B0=E6=BC=F6 wrote: Sorry to hear you're leaving! To unsubscribe, you'll need to visit the web site: http://mail.python.org/mailman/listinfo/tutor It's the same web site you used to subscribe --- you can change options there, including unsubscription. Go down the the bottom of that page, and if you go through the "Edit Options" menu, you'll be able to unsubscribe. Anyway, we hope to hear from you again. From dyoo@hkn.eecs.berkeley.edu Thu Mar 29 07:27:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 28 Mar 2001 23:27:37 -0800 (PST) Subject: [Tutor] PyApache Module questions In-Reply-To: <200103281621.f2SGLpC22135@pop.nsacom.net> Message-ID: <Pine.LNX.4.21.0103282322440.26236-100000@hkn.eecs.berkeley.edu> On Wed, 28 Mar 2001 kromag@nsacom.net wrote: > I compiled the PyApache module into apache 1.3.19. Everything seems to work > fine except for a small weirdness. > > It seems that one must add a couple of "print"s to the beginning of one's cgi > script for the module to write out to the browser. CGI's traditionally need to report their "content-type" --- a web browser takes a look at this to prepare itself to either do image or html outputting. By printing a bunch of blank lines, you're probably getting the browser to default to regular text output. However, a better way to do this is to really tell the browser what to expect. Try: print "content-type: text/html" or print "content-type: text/plain" at the very beginning of your CGI programs, and things should be ok. The first tells any web browser to expect HTML, while the other triggers plain-text output. Although I haven't worked with PyApache, this is my best guess about what's happening. Hope this helps! From alan.gauld@bt.com Thu Mar 29 08:13:39 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 29 Mar 2001 09:13:39 +0100 Subject: [Tutor] Placing icons in the systray Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D683@mbtlipnt02.btlabs.bt.co.uk> > Does anybody know how to place an icon in the systray (you > know - next to > the clock)in Windows? You will need to use the native Win32 API - possibly through the MFC wrapper in winall. But if MFC doesn't expose that API you would need to create a DLL and wrap Python around that... Alan G From alan.gauld@bt.com Thu Mar 29 08:17:47 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 29 Mar 2001 09:17:47 +0100 Subject: [Tutor] Q: Do Functions Have Any Class? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D684@mbtlipnt02.btlabs.bt.co.uk> > I heard that in Ruby, all was object... I don't know if they > implement the language in this way ( a.sqrt() ) , Exactly so. Alan G From dyoo@hkn.eecs.berkeley.edu Thu Mar 29 09:32:01 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 29 Mar 2001 01:32:01 -0800 (PST) Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE2xPTi68KtBsejEBCu000043bd@hotmail.com> Message-ID: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> On Wed, 28 Mar 2001, spi wrote: > I downloaded and installed calldll and dynwin and am able to import > successfully > but when I try to use an example I get this error: > > >>> import windll > >>> kernel32 = windll.module('kernel32') > Traceback (innermost last): > File "<interactive input>", line 1, in ? > AttributeError: module > >>> I couldn't find the module class within the calldll stuff. However, I did see it within dynwin: ### within DynWin's windll module: class module: callable_function_class = callable_function def __init__ (self, name, ext='.dll'): self.name = name self.handle = calldll.load_library (name+ext) ... ### So there should be a "module" defined inside it. Could you double check to see that there isn't another version of windll.py somewhere on your system? From apec@chinanusa.com Thu Mar 29 01:35:31 2001 From: apec@chinanusa.com (APEC) Date: Wed, 28 Mar 2001 17:35:31 -0800 Subject: [Tutor] An Invitation from the Asia-Pacific Rim Message-ID: <WEB-DEV1Wopcnvy3JdZ00001a54@web-dev1> This is a multi-part message in MIME format. ------=_NextPart_000_696C_01C0B7AD.7CB759F0 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 7bit Aiming at Asia-Pacific Market? Here's your one and only chance this year to target 21 developed and developing member economies in the Asia-Pacific rim <http://www.apec2001.org/apec_member.asp> . Industrial Science and Technology Cooperation Conference and Exhibition September 21 - 25, 2001 Suzhou, China An hour's drive from Shanghai, the biggest city in China Who Should Attend * Technology-oriented companies who want to demonstrate advanced technologies or to seek joint ventures * Venture capitalists and other investors who want to identify promising high-tech companies and investment opportunities * Entrepreneurs who are seeking market expansion to the Asia-Pacific region Best Chance to Showcase Technologies * Exhibition & transaction of high technology & hi-tech products. * Bid for technological cooperation. * Discussions & negotiations on technological transaction and cooperation. * APEC forum on science and technology. All the Opportunities! * Technomart is endorsed by APEC's 21 member economies that had a combined Gross Domestic Product of over US$18 trillion in 1999 and 43.85 percent of global trade. * In Technomart III, attendees included 1,000+ hi-tech exhibitors and recorded 37,000 visitors. * In Technomart III, over 5,000 business negotiations occurred, involving trade in excess of about US$ 100 million over the course of the five-day event. * Direct connection to China market. Service Center * Technomart representation * Exhibition Booth & Expense <http://www.apec2001.org/apec_booth.asp> * Booth arrangements and allocation * Transportation * Hotels <http://www.apec2001.org/apec_hotel.asp> * Sourcing/manufacturers visits * On-site public relation facilitation, media coverage * Collateral translation * Escort interpretation * Leisure touring in Suzhou and its vacinities Key Technological Areas * Biotechnology * Environmental and cleaner production technologies * Communication * Information technologies / electronics * Advanced materials * Mechatronics * Transportation * Resource management technology * Energy * Sustainable agriculture * Emergency preparedness and climate prediction * Exploitation of natural resources For more information about the upcoming APEC Technomart IV, please visit: http://www.apec2001.org For inquiring a brochure, please visit: http://www.apec2001.org/apec_register.asp For Technomart IV services, please visit: http://www.apec2001.org/apec_serve.asp For exhibition booth information, please visit: http://www.apec2001.org/apec_booth.asp For on-line registration information, please click: <http://www.apec2001.org/apec_registernow.asp> For further questions, please email us at apec@CHINAnUSA.com <mailto:apec@CHINAnUSA.com> or call Jessica Pan at (510) 497-8783. _____ CHINAnUSA.com is proud to represent APEC Technomart IV committee here in the US to work closely with you. It is our pleasure to assist you in every aspect for the most beneficial trade show. The past Technomart initiated trillions of transactions. Register today <http://www.apec2001.org/apec_registernow.asp> ! We look forward to your participation and seeing you in Suzhou, China. Authorized representative of APEC Technomart IV Unsubscribe: If you received this message in error or wish to unsubscribe from this subject, just click here: Click here. <http://www.apec2001.org/unsub/unsubscribe.asp?mail_id=tut4664100413601> Or you can reply to this email with 'Unsubscribe' as subject title. All trademarks are the property of their respective owners (C)2001 All rights reserved. ------=_NextPart_000_696C_01C0B7AD.7CB759F0 Content-Type: text/html; charset="big5" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR></HEAD> <BODY aLink=3Dblue link=3Dblue topMargin=3D3 vLink=3Dblue> <BLOCKQUOTE> <TABLE align=3Dcenter bgColor=3D#ffffff border=3D0 cellPadding=3D0 = cellSpacing=3D0=20 width=3D580> <TBODY> <TR> <TD><IMG border=3D0 height=3D20=20 src=3D"http://www.apec2001.org/email/images/email_head.jpg" = width=3D580=20 NOSEND=3D"1"></TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#ffffff border=3D0 cellPadding=3D5 = cellSpacing=3D0=20 width=3D580> <TBODY> <TR> <TD align=3Dmiddle><FONT color=3Dred face=3DArial = size=3D5><B>Aiming at=20 Asia-Pacific Market?</B></FONT></TD> <TR> <TD align=3Dmiddle><FONT color=3Dblue face=3DArial = size=3D3><B>Here's your one=20 and only chance this year to target <BR><A=20 href=3D"http://www.apec2001.org/apec_member.asp">21 developed = and developing member economies in the Asia-Pacific=20 rim</A>.</B></FONT></TD></TR></TBODY></TABLE><BR> <TABLE align=3Dcenter bgColor=3D#ffffff border=3D0 cellPadding=3D0 = cellSpacing=3D0=20 width=3D580> <TBODY> <TR> <TD align=3Dleft bgColor=3D#000000 vAlign=3Dtop width=3D"45%"> <TABLE align=3Dleft bgColor=3D#000000 border=3D0 cellPadding=3D2 = cellSpacing=3D0=20 width=3D"76%"> <TBODY> <TR> <TD align=3Dleft vAlign=3Dcenter> <IMG border=3D0 = height=3D47=20 src=3D"http://www.apec2001.org/email/images/apec_head.gif" = width=3D87=20 NOSEND=3D"1"></TD> <TD><IMG border=3D0 height=3D20=20 src=3D"http://www.apec2001.org/email/images/IV1.gif" = width=3D168=20 NOSEND=3D"1"></TD></TR> <TR> <TD colSpan=3D2> <FONT color=3D#ffffff face=3DArial=20 size=3D2><B>Industrial Science and Technology=20 Cooperation<BR> Conference and = Exhibition</B></FONT></TD></TR> <TR> <TD colSpan=3D2> <FONT color=3D#ffffff face=3DArial=20 size=3D2><B>September 21 - 25, 2001<BR> Suzhou,=20 China</B></FONT><BR><BR></TD></TR></TBODY></TABLE></TD> <TD bgColor=3D#000000 vAlign=3Dtop width=3D"15%"><IMG border=3D0 = height=3D122=20 src=3D"http://www.apec2001.org/email/images/map.gif" width=3D160 = NOSEND=3D"1"> <FONT color=3D#ffffff face=3DArial size=3D1>An = hour's drive from=20 Shanghai, the biggest city in China</FONT> = </TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#ffffff border=3D0 cellPadding=3D0 = cellSpacing=3D0=20 width=3D580> <TBODY> <TR> <TD colSpan=3D3><IMG border=3D0 height=3D7=20 src=3D"http://www.apec2001.org/email/images/white-dot.gif" = width=3D580=20 NOSEND=3D"1"></TD></TR> <TR> <TD bgColor=3D#fff5e7 vAlign=3Dtop width=3D"50%"> <TABLE align=3Dcenter bgColor=3D#f8f4f8 border=3D0 = cellPadding=3D2 cellSpacing=3D0=20 width=3D"100%"> <TBODY> <TR> <TD align=3Dmiddle bgColor=3D#b76b93><FONT color=3D#ffffff = face=3DArial=20 size=3D3><B>Who Should Attend</B></FONT></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Technology-oriented=20 companies who want to demonstrate = advanced=20 technologies or to seek joint=20 ventures</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Venture = capitalists and=20 other investors who want to = identify=20 promising high-tech companies and=20 investment opportunities</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Entrepreneurs who are=20 seeking market expansion to the=20 Asia-Pacific region</FONT></LI></TD></TR> <TR> <TD> </TD></TR></TBODY></TABLE> <TABLE align=3Dcenter border=3D0 cellPadding=3D0 cellSpacing=3D0 = width=3D"100%"> <TBODY> <TR> <TD><IMG border=3D0 height=3D5=20 src=3D"http://www.apec2001.org/email/images/dot_apec.gif"=20 width=3D"100%" NOSEND=3D"1"></TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#eff8ee border=3D0 = cellPadding=3D2 cellSpacing=3D0=20 width=3D"100%"> <TBODY> <TR> <TD align=3Dmiddle bgColor=3D#6ba763><FONT color=3D#ffffff = face=3DArial=20 size=3D3><B>Best Chance to Showcase = Technologies</B></FONT></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Exhibition = &=20 transaction of high technology &=20 hi-tech = products.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Bid for = technological=20 cooperation.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Discussions &=20 negotiations on technological = transaction=20 and cooperation.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>APEC forum = on science=20 and technology.</FONT></LI></TD></TR> <TR> <TD> </TD></TR></TBODY></TABLE> <TABLE align=3Dcenter border=3D0 cellPadding=3D0 cellSpacing=3D0 = width=3D"100%"> <TBODY> <TR> <TD><IMG border=3D0 height=3D5=20 src=3D"http://www.apec2001.org/email/images/dot_apec.gif"=20 width=3D"100%" NOSEND=3D"1"></TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#fff5e7 border=3D0 = cellPadding=3D2 cellSpacing=3D0=20 width=3D"100%"> <TBODY> <TR> <TD align=3Dmiddle bgColor=3D#ff6342><FONT color=3D#ffffff = face=3DArial=20 size=3D3><B>All the Opportunities!</B></FONT></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Technomart = is endorsed=20 by APEC's 21 member economies that = had a=20 combined Gross Domestic Product of = over=20 US$18 trillion in 1999 and 43.85 = percent=20 of global trade.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>In = Technomart III,=20 attendees included 1,000+ hi-tech=20 exhibitors and recorded 37,000 = visitors.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>In = Technomart III, over=20 5,000 business negotiations = occurred,=20 involving trade in excess of about = US$ 100=20 million over the course of the = five-day=20 event.</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Direct = connection to=20 China market.</FONT></LI></TD></TR> <TR> <TD> </TD></TR></TBODY></TABLE></TD> <TD><IMG border=3D0 height=3D"100%"=20 src=3D"http://www.apec2001.org/email/images/dot_apec.gif" = width=3D5=20 NOSEND=3D"1"></TD> <TD vAlign=3Dtop width=3D"50%"> <TABLE align=3Dcenter bgColor=3D#f0ffff border=3D0 = cellPadding=3D2 cellSpacing=3D0=20 width=3D"100%"> <TBODY> <TR> <TD align=3Dmiddle bgColor=3D#4b87d7><FONT color=3D#ffffff = face=3DArial=20 size=3D3><B>Service Center</B></FONT></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Technomart = representation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2><A=20 href=3D"http://www.apec2001.org/apec_booth.asp">Exhibition = Booth=20 & Expense</A></FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Booth = arrangements and=20 allocation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial=20 size=3D2>Transportation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2><A=20 = href=3D"http://www.apec2001.org/apec_hotel.asp">Hotels</A></FONT></LI></T= D></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Sourcing/manufacturers=20 visits</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>On-site = public relation=20 facilitation, media=20 coverage</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Collateral = translation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Escort=20 interpretation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Leisure = touring in=20 Suzhou and its vacinities</FONT></LI></TD></TR> <TR> <TD> </TD></TR></TBODY></TABLE> <TABLE align=3Dcenter border=3D0 cellPadding=3D0 cellSpacing=3D0 = width=3D"100%"> <TBODY> <TR> <TD><IMG border=3D0 height=3D5=20 src=3D"http://www.apec2001.org/email/images/dot_apec.gif"=20 width=3D"100%" NOSEND=3D"1"></TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#ffffef border=3D0 = cellPadding=3D2 cellSpacing=3D0=20 width=3D"100%"> <TBODY> <TR> <TD align=3Dmiddle bgColor=3D#edb94d><FONT color=3D#ffffff = face=3DArial=20 size=3D3><B>Key Technological Areas</B></FONT></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial=20 size=3D2>Biotechnology</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Environmental and=20 cleaner production=20 technologies</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial=20 size=3D2>Communication</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Information technologies=20 / electronics</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Advanced=20 materials</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial=20 size=3D2>Mechatronics</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial=20 size=3D2>Transportation</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Resource = management=20 technology</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Energy</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Sustainable=20 agriculture</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial size=3D2>Emergency = preparedness=20 and climate = prediction</FONT></LI></TD></TR> <TR> <TD> <LI><FONT color=3D#000000 face=3DArial = size=3D2>Exploitation of natural=20 resources</FONT></LI></TD></TR> <TR> = <TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE> <TABLE align=3Dcenter bgColor=3D#ffffff border=3D0 cellPadding=3D2 = cellSpacing=3D8=20 width=3D580> <TBODY> <TR> <TD vAlign=3Dtop><IMG border=3D0=20 src=3D"http://www.apec2001.org/email/images/yellow_square.gif"=20 NOSEND=3D"1"> <FONT color=3D#000000 face=3DArial = size=3D2><B>For more=20 information about the upcoming APEC Technomart IV, please=20 visit:</B><BR><A=20 = href=3D"http://www.apec2001.org">http://www.apec2001.org</A></FONT></TD><= /TR> <TR> <TD vAlign=3Dtop><IMG border=3D0=20 src=3D"http://www.apec2001.org/email/images/yellow_square.gif"=20 NOSEND=3D"1"> <FONT color=3D#000000 face=3DArial = size=3D2><B>For inquiring=20 a brochure, please visit:</B><BR><A=20 = href=3D"http://www.apec2001.org/apec_register.asp">http://www.apec2001.or= g/apec_register.asp</A></FONT></TD></TR> <TR> <TD vAlign=3Dtop><IMG border=3D0=20 src=3D"http://www.apec2001.org/email/images/yellow_square.gif"=20 NOSEND=3D"1"> <FONT color=3D#000000 face=3DArial = size=3D2><B>For Technomart=20 IV services, please visit:</B><BR><A=20 = href=3D"http://www.apec2001.org/apec_serve.asp">http://www.apec2001.org/a= pec_serve.asp</A></FONT></TD></TR> <TR> <TD vAlign=3Dtop><IMG border=3D0=20 src=3D"http://www.apec2001.org/email/images/yellow_square.gif"=20 NOSEND=3D"1"> <FONT color=3D#000000 face=3DArial = size=3D2><B>For exhibition=20 booth information, please visit:</B><BR><A=20 = href=3D"http://www.apec2001.org/apec_booth.asp">http://www.apec2001.org/a= pec_booth.asp</A></FONT></TD></TR> <TR> <TD vAlign=3Dtop><IMG border=3D0=20 src=3D"http://www.chinanusa.com/email/images/yellow_square.gif"=20 NOSEND=3D"1"> <FONT color=3D#000000 face=3DArial = size=3D2><B>For on-line registration information, please click:</B> <A=20 href=3D"http://www.apec2001.org/apec_registernow.asp"><IMG = border=3D0=20 src=3D"http://www.chinanusa.com/email/images/button.gif"=20 NOSEND=3D"1"></A><br> =20 For further questions, please email us at <a = href=3D"mailto:apec@CHINAnUSA.com">apec@CHINAnUSA.com</a> or call = Jessica Pan at (510) 497-8783. </FONT></TD></TR> </TBODY></TABLE><!--#footer--> <TABLE align=3Dcenter border=3D0 cellPadding=3D0 cellSpacing=3D0 = width=3D580> <TBODY> <TR> <TD> <DIV align=3Dcenter> <HR SIZE=3D1> </DIV></TD></TR> <TR> <TD> <DIV align=3Dcenter><FONT color=3D#000000 size=3D1><FONT=20 face=3DArial>CHINAnUSA.com is proud to represent APEC Technomart = IV=20 committee here in the US to work closely with you. It is our = pleasure to=20 assist you in every aspect for the most beneficial trade=20 show.<BR><BR>The past Technomart initiated trillions of=20 transactions.</FONT><A = href=3D"http://www.apec2001.org/apec_registernow.asp"><FONT=20 face=3DArial>Register today</FONT></A><FONT face=3DArial>! = <BR>We look=20 forward to your participation and seeing you in Suzhou,=20 China.<BR><BR>Authorized representative of APEC Technomart=20 IV<BR><BR> <FONT color=3Dblack size=3D2><SPAN = class=3D458364700-24032001>Unsubscribe:</SPAN></FONT></FONT></FONT></DIV>= <DIV align=3Dcenter><FONT color=3D#000000><FONT face=3DArial><FONT = color=3Dblack><SPAN class=3D458364700-24032001><FONT size=3D1>If you = received this message in error or wish to unsubscribe from this subject, = just click here: </FONT><A = href=3Dhttp://www.apec2001.org/unsub/unsubscribe.asp?mail_id=3Dtut4664100= 413601><FONT size=3D1></FONT><FONT size=3D1><U>Click = here.</U></A></SPAN><br>Or you can reply to this email with = 'Unsubscribe' as subject = title.</FONT></FONT></FONT></FONT></FONT></DIV><DIV align=3Dcenter><FONT = color=3D#000000><SPAN class=3D458364700-24032001><P><FONT size=3D1><FONT = color=3Dblack><FONT face=3DArial><br>All trademarks are the<SPAN = class=3D458364700-24032001> </SPAN>property of their respective = owners (C)2001 All rights<SPAN = class=3D458364700-24032001> </SPAN>reserved. = </FONT></FONT></FONT></P></SPAN></FONT><BR><BR></DIV></TD></TR></TBODY></= TABLE></BLOCKQUOTE></BODY></HTML> ------=_NextPart_000_696C_01C0B7AD.7CB759F0-- From dyoo@hkn.eecs.berkeley.edu Thu Mar 29 11:22:38 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 29 Mar 2001 03:22:38 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <F105XzBW76c4EOBHkJZ00008b51@hotmail.com> Message-ID: <Pine.LNX.4.21.0103290301100.29061-100000@hkn.eecs.berkeley.edu> On Wed, 28 Mar 2001, wong chow cheok wrote: > thanks a lot daniel. i think i am doing it wrong. i still have no idea how > to extract the information. i looked over the tutorial but i can't find much > that can help. still new to this language. if you have any ideas i would > really appreciate it. i tried using: > > params = urllib.urllencode > > but it seems that the parameters do not have any significance. i am still > learning as i go. very sorry if i cannot give you an answer yet but i will > get back to you if i find one. That's ok; take it step by step. You might find the regular expression functions useful. Regular expressions are tools that let us search and pull out portions of strings out of text. For example, we can use a regular expression to pull titles out of html fairly easily. Let's say that a "title" begins with a '<title>' and ends with a '</title>'. If we're given a whole web page, we can use regular expressions to encode this idea: ### title_re = re.compile('<title>.*</title>') ### This says to make a "regular expression" that knows that a title is made up of a beginning title tag "<title>", a bunch of other characters ".*", and an ending tag "</title>". With this information encoded, we can use a regular expression to search() any string for this pattern. Here's a program that tries to grab the titles out of any web site we give it: ### import re import urllib import sys def getTitle(url): title_re = re.compile('<title>(.*?)</title>', re.IGNORECASE | re.DOTALL) html = urllib.urlopen(url).read() result = title_re.search(html) if result: return result.group(1) if __name__ == '__main__': print getTitle(sys.argv[1]) ### There's some extra stuff in here that's extraneous, but I wanted to show a slightly realistic example that you'll be able to play around with. It sounds like your project will become easier if you use regular expressions, so I'd recommend experimenting with them. It has to be said, though, that regular expressions are weird at first. You'll want to take a look at a few introductions that talk about regular expressions. Here are a few references: http://python.org/doc/current/lib/module-re.html http://py-howto.sourceforge.net/regex/regex.html It doesn't hurt to look at Perl documentation on regular expressions either, since the idea (and the syntax!) is the same: http://language.perl.com/all_about/regexps.html and the rest of: http://www.perl.com/reference/query.cgi?regexp has lots of good stuff on regular expressions. If you have more questions, feel free to ask us on tutor@python.org. Good luck to you. From karimy@nipltd.com Thu Mar 29 11:30:07 2001 From: karimy@nipltd.com (Karim Yaici) Date: Thu, 29 Mar 2001 12:30:07 +0100 Subject: [Tutor] How can I make my script work without calling Python? Message-ID: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> This is a multi-part message in MIME format. ------=_NextPart_000_007C_01C0B84B.FD3C0140 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello there, I have quick question. let's say I have a script (foo.py) which takes = some parameters (x,y,z). the usual way to run is to type: >python foo.py x y z Is there anyway I can make it work without calling Python i.e >foo.py x y z=20 I know I can make it .EXE file (you'll understand that I am running = windoze:-) ) but I am sure I have seen people doing it with a raw python = script. Has anyone tried it? Cheers Karim ------=_NextPart_000_007C_01C0B84B.FD3C0140 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hello there,</FONT></DIV> <DIV><FONT face=3DArial size=3D2>I have quick question. let's say I have = a script=20 (foo.py) which takes some parameters (x,y,z). the usual way to run is to = type:</FONT></DIV> <DIV><FONT face=3DArial size=3D2>>python foo.py x y z</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Is there anyway I can make it work = without calling=20 Python i.e</FONT></DIV> <DIV><FONT face=3DArial size=3D2>>foo.py x y z </FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>I know I can make it .EXE file (you'll = understand=20 that I am running windoze:-) ) but I am sure I have seen people doing it = with a=20 raw python script.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Has anyone tried it?</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Cheers</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Karim</FONT></DIV></BODY></HTML> ------=_NextPart_000_007C_01C0B84B.FD3C0140-- From cdwom@mpinet.net Thu Mar 29 11:38:34 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Thu, 29 Mar 2001 06:38:34 -0500 Subject: [Tutor] Text Box Message-ID: <005901c0b844$ca5c2fe0$88dc35d8@KellyJoW> What is the easist well to tell if a text widget is empty? I tried all different solutions including: if textwidget.get(1.0,END) == "": if textwidget.get(1.0) == textwidget.get(END): if textwidget.compare(1.0,END): I'm sure some of those weren't even valid. :) What am I doin' wrong? So long, and thanks for all the fish! Corey Check out my Webpage at: schitzomedia.y0ru.net and vote for the top 10 games of all time!!! From dyoo@hkn.eecs.berkeley.edu Thu Mar 29 11:48:18 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 29 Mar 2001 03:48:18 -0800 (PST) Subject: [Tutor] PyApache Module questions In-Reply-To: <Pine.LNX.4.21.0103282322440.26236-100000@hkn.eecs.berkeley.edu> Message-ID: <Pine.LNX.4.21.0103290347070.31470-100000@hkn.eecs.berkeley.edu> On Wed, 28 Mar 2001, Daniel Yoo wrote: > Try: > > print "content-type: text/html" > > or > > print "content-type: text/plain" Err... clarification. There needs to be a blank space between the "content-type" line and whatever comes afterwards, so I need to correct this as: print "content-type: text/html\n" or print "content-type: text/plain\n" Apologies for the mistake. From rick@niof.net Thu Mar 29 14:09:58 2001 From: rick@niof.net (Rick Pasotto) Date: Thu, 29 Mar 2001 09:09:58 -0500 Subject: [Tutor] Text Box In-Reply-To: <005901c0b844$ca5c2fe0$88dc35d8@KellyJoW>; from cdwom@mpinet.net on Thu, Mar 29, 2001 at 06:38:34AM -0500 References: <005901c0b844$ca5c2fe0$88dc35d8@KellyJoW> Message-ID: <20010329090958.H26119@tc.niof.net> On Thu, Mar 29, 2001 at 06:38:34AM -0500, Corey Woodworth wrote: > What is the easist well to tell if a text widget is empty? I tried all > different solutions including: > > if textwidget.get(1.0,END) == "": > > if textwidget.get(1.0) == textwidget.get(END): > > if textwidget.compare(1.0,END): > > I'm sure some of those weren't even valid. :) What am I doin' wrong? I believe a Text widget is never really empty. It always contains at least a newline. Check for a length of 1. -- "I will not be pushed, filed, stamped, indexed, briefed, debriefed, or numbered. My life is my own." -- The Prisoner Rick Pasotto email: rickp@telocity.com From bleh99@hotmail.com Thu Mar 29 14:20:15 2001 From: bleh99@hotmail.com (spi) Date: Thu, 29 Mar 2001 09:20:15 -0500 Subject: [Tutor] How do I use calldll and windll? References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> Message-ID: <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> no other versions are there, currently they are located at D:\python20\lib\calldll\ D:\python20\lib\dynwin\ This is a cut from windll.py class module: callable_function_class = callable_function def __init__ (self, name, ext='.dll'): ---------------------------------------------------- It's there but keeps saying that it's not there if it makes any diffrence i'm using activestates interactive compiler to test this ----- Original Message ----- From: "Daniel Yoo" <dyoo@hkn.eecs.berkeley.edu> To: "spi" <bleh99@hotmail.com> Cc: <tutor@python.org> Sent: Thursday, March 29, 2001 4:32 AM Subject: Re: [Tutor] How do I use calldll and windll? > On Wed, 28 Mar 2001, spi wrote: > > > I downloaded and installed calldll and dynwin and am able to import > > successfully > > but when I try to use an example I get this error: > > > > >>> import windll > > >>> kernel32 = windll.module('kernel32') > > Traceback (innermost last): > > File "<interactive input>", line 1, in ? > > AttributeError: module > > >>> > > I couldn't find the module class within the calldll stuff. However, I did > see it within dynwin: > > ### within DynWin's windll module: > class module: > callable_function_class = callable_function > def __init__ (self, name, ext='.dll'): > self.name = name > self.handle = calldll.load_library (name+ext) > ... > ### > > So there should be a "module" defined inside it. Could you double check > to see that there isn't another version of windll.py somewhere on your > system? > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From dsh8290@rit.edu Thu Mar 29 15:22:14 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 10:22:14 -0500 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com>; from karimy@nipltd.com on Thu, Mar 29, 2001 at 12:30:07PM +0100 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> Message-ID: <20010329102214.E11119@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 12:30:07PM +0100, Karim Yaici wrote: | | Hello there, | | I have quick question. let's say I have a script (foo.py) which takes | some parameters (x,y,z). the usual way to run is to type: | | >python foo.py x y z | | Is there anyway I can make it work without calling Python i.e | | >foo.py x y z | | | I know I can make it .EXE file (you'll understand that I am running | windoze:-) ) but I am sure I have seen people doing it with a raw | python script. On Windows your choices are (1) to make an exe, (2) make the program a wrapper (ie .bat file) that runs the interpreter on the real script, or (3) not use the command line. Sample of choice number 2 : ---- foo.py ---- # this is my program ... ---- foo.bat ---- rem AFAIK batch files don't have the equivalence of $* in bash python foo.py %1 %2 %3 %4 %5 %6 %7 %8 %9 For choice number 3 you need to set the default action. Open _windows_ (not internet) explorer, click on view->options then click the "File Types" tab. Find .py files and specify (through the dialogs, ask if you want more details) that it should be run by the interpreter. Then when you double click on it in explorer it will run in the interpreter. No effect on the command line though. Of course, you can't pass commandline arguments using this method (ie sys.argv). If you use a *nix system (or fake it using cygwin on windows) you can put #!/usr/bin/env python as the very first line of the script, then the shell will know to run it using python. (Just one example of why *nix is superior to 'doze ;-)) HTH, -D From bwinton@tor.dhs.org Thu Mar 29 15:39:16 2001 From: bwinton@tor.dhs.org (Blake Winton) Date: Thu, 29 Mar 2001 10:39:16 -0500 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010329102214.E11119@harmony.cs.rit.edu> References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> Message-ID: <20010329103916.A13441@tor.dhs.org> * D-Man <dsh8290@rit.edu> [010329 10:29]: > On Thu, Mar 29, 2001 at 12:30:07PM +0100, Karim Yaici wrote: > | >python foo.py x y z > | Is there anyway I can make it work without calling Python i.e > | >foo.py x y z > On Windows your choices are (1) to make an exe, (2) make the program a > wrapper (ie .bat file) that runs the interpreter on the real script, > or (3) not use the command line. > For choice number 3 you need to set the default action. Open > _windows_ (not internet) explorer, click on view->options then click > the "File Types" tab. Find .py files and specify (through the > dialogs, ask if you want more details) that it should be run by the > interpreter. Then when you double click on it in explorer it will run > in the interpreter. No effect on the command line though. Of course, > you can't pass commandline arguments using this method (ie sys.argv). or (4) Set up your command line to just run python files. Choice #4 is the same as choice #3. In fact, if you follow the instructions for choice #3, you should be able to, at the command line, type "foo.py x y z", and it will work. As an added bonus, you might be able to edit your "PATHEXT" variable, and set it to something like ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY" So that you can then just type in "foo x y z", and it will still work. (I'm not sure whether that's only an NT thing, or if the other versions of Windows do the same thing.) > #!/usr/bin/env python > as the very first line of the script, then the shell will know to run > it using python. (Just one example of why *nix is superior to 'doze > ;-)) Because I need to tell _every_ python script I write that it's actually a python script? Surely if *nix is so great it could figure that out from the ".py" extension on my files. ;) Or at least have a way for me to only type it in once, instead of in _every_ file... (I'm actually a *nix bigot at heart, but I also enjoy a good debate. ;) Later, Blake. -- 9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07 From dsh8290@rit.edu Thu Mar 29 16:00:22 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 11:00:22 -0500 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010329103916.A13441@tor.dhs.org>; from bwinton@tor.dhs.org on Thu, Mar 29, 2001 at 10:39:16AM -0500 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> <20010329103916.A13441@tor.dhs.org> Message-ID: <20010329110022.J11119@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 10:39:16AM -0500, Blake Winton wrote: | * D-Man <dsh8290@rit.edu> [010329 10:29]: | | or (4) Set up your command line to just run python files. | | Choice #4 is the same as choice #3. In fact, if you follow the Oh, ok, that's nice. I guess I've never tried that. I didn't think setting the file type in windows would affect it's dos imitation. | > #!/usr/bin/env python | > as the very first line of the script, then the shell will know to run | > it using python. (Just one example of why *nix is superior to 'doze | > ;-)) | | Because I need to tell _every_ python script I write that it's | actually a python script? Surely if *nix is so great it could | figure that out from the ".py" extension on my files. ;) Or Of course. Say I did this (taken from a real project, but not mine) ---- /usr/bin/pmail #!/usr/bin/env python ... Without the #! how would the shell know that 'pmail' is a python program? Should I be required to write a sh script called 'pmail' that is nothing more than 'pmail.py $*' ? IMO that's a waste and an indication of shortsighted and inflexible design. The #! means you can mix and match any filename with any interpreter much like python's uniform treatment of all objects. (ie no primitive type vs. reference (object) type like in Java, etc) | at least have a way for me to only type it in once, instead of | in _every_ file... ---- ~/.vimrc ---- ; <most snipped> autocmd! BufNewFile *.py read ~/util/autoheaders/Python ---- ~/util/autoheaders/Python #!/usr/bin/env python # any other text (like name, license, etc) to appear automagically at # the beginning of each new .py file <grin> The only problem I have is that the first line (in the new buffer) is always blank with the header beginning on the second line. Is there a way to fix this? | (I'm actually a *nix bigot at heart, but I also enjoy a good | debate. ;) Following your lead ... ;-) -D From dsh8290@rit.edu Thu Mar 29 16:03:26 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 11:03:26 -0500 Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE29aaDi3dQT9dcmBqE00004107@hotmail.com>; from bleh99@hotmail.com on Thu, Mar 29, 2001 at 09:20:15AM -0500 References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> Message-ID: <20010329110326.K11119@harmony.cs.rit.edu> Try the following, but substitue "windll" for "cgi" (or "dynwin" I forgot which one you were trying to use) : >>> import cgi >>> print cgi <module 'cgi' from '/usr/local/lib/python2.0/cgi.pyc'> >>> dir( cgi ) ['FieldStorage', 'FormContent', 'FormContentDict', 'InterpFormContentDict', 'MiniFieldStorage', 'StringIO', 'SvFormContentDict', 'UserDict', '__builtins__', '__doc__', '__file__', '__name__', '__version__', 'dolog', 'escape', 'initlog', 'log', 'logfile', 'logfp', 'maxlen', 'mimetools', 'nolog', 'os', 'parse', 'parse_header', 'parse_multipart', 'parse_qs', 'parse_qsl', 'print_arguments', 'print_directory', 'print_environ', 'print_environ_usage', 'print_exception', 'print_form', 'rfc822', 'string', 'sys', 'test', 'urllib'] >>> Printing the module object will tell you where it got the module from. Using dir() will tell you excatly what python thinks is in the module. HTH, -D On Thu, Mar 29, 2001 at 09:20:15AM -0500, spi wrote: | no other versions are there, currently they are located at | D:\python20\lib\calldll\ | D:\python20\lib\dynwin\ | | This is a cut from windll.py | | class module: | callable_function_class = callable_function | def __init__ (self, name, ext='.dll'): | | ---------------------------------------------------- | | It's there but keeps saying that it's not there | if it makes any diffrence i'm using activestates | interactive compiler to test this From baptista@linuxsolutions.com.br Thu Mar 29 16:05:16 2001 From: baptista@linuxsolutions.com.br (Paulo Henrique Baptista de Oliveira) Date: Thu, 29 Mar 2001 13:05:16 -0300 Subject: [Tutor] Test Message-ID: <20010329130516.15d8771e.baptista@linuxsolutions.com.br> Hi all, where is the python tutorial? Much thanks, PH From bleh99@hotmail.com Thu Mar 29 16:21:53 2001 From: bleh99@hotmail.com (spi) Date: Thu, 29 Mar 2001 11:21:53 -0500 Subject: [Tutor] How do I use calldll and windll? References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> Message-ID: <OE767pYdFgja2mMdf85000033cf@hotmail.com> This is a multi-part message in MIME format. --Boundary_(ID_vqVNTC4E0Z3NrgSjKnlALw) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Here are the results I get, I don't understand why it's not showing the other modules I attached windll.py that I have, take a look >>> import windll >>> print windll <module 'windll' from 'd:\python20\lib\dynwin\windll.pyc'> >>> dir( windll ) ['__builtins__', '__doc__', '__file__', '__name__'] >>> any thoughts on why its not finding "windll.module()" it appears that a lot of people are using this to use win32 dll files, but the documentation on getting it to work is really parse ----- Original Message ----- From: "D-Man" <dsh8290@rit.edu> To: <tutor@python.org> Sent: Thursday, March 29, 2001 11:03 AM Subject: Re: [Tutor] How do I use calldll and windll? > > Try the following, but substitue "windll" for "cgi" (or "dynwin" I > forgot which one you were trying to use) : > > >>> import cgi > >>> print cgi > <module 'cgi' from '/usr/local/lib/python2.0/cgi.pyc'> > >>> dir( cgi ) > ['FieldStorage', 'FormContent', 'FormContentDict', > 'InterpFormContentDict', 'MiniFieldStorage', 'StringIO', > 'SvFormContentDict', 'UserDict', '__builtins__', '__doc__', > '__file__', '__name__', '__version__', 'dolog', 'escape', 'initlog', > 'log', 'logfile', 'logfp', 'maxlen', 'mimetools', 'nolog', 'os', > 'parse', 'parse_header', 'parse_multipart', 'parse_qs', 'parse_qsl', > 'print_arguments', 'print_directory', 'print_environ', > 'print_environ_usage', 'print_exception', 'print_form', 'rfc822', > 'string', 'sys', 'test', 'urllib'] > >>> > > > Printing the module object will tell you where it got the module from. > Using dir() will tell you excatly what python thinks is in the module. > > > HTH, > -D > > > On Thu, Mar 29, 2001 at 09:20:15AM -0500, spi wrote: > | no other versions are there, currently they are located at > | D:\python20\lib\calldll\ > | D:\python20\lib\dynwin\ > | > | This is a cut from windll.py > | > | class module: > | callable_function_class = callable_function > | def __init__ (self, name, ext='.dll'): > | > | ---------------------------------------------------- > | > | It's there but keeps saying that it's not there > | if it makes any diffrence i'm using activestates > | interactive compiler to test this > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor --Boundary_(ID_vqVNTC4E0Z3NrgSjKnlALw) Content-type: text/plain; name=windll.py Content-disposition: attachment; filename=windll.py Content-transfer-encoding: 7BIT # -*- Mode: Python; tab-width: 4 -*- # Author: Sam Rushing <rushing@nightmare.com> """\ lets you call functions in win32 dll directly, using the calldll module. Usage: To create a dll module object: >>> kernel32 = windll.module ('kernel32') >>> kernel32 <win32 module 'kernel32' (0 functions)> To reference a function: >>> kernel32.Beep <callable function "Beep"> To call a function: >>> kernel32.Beep (1000, 50) """ import calldll # A convenience for the vast majority of functions which take long # parameters (addresses or integers) and return a long. Assumes that # the caller knows the correct number of arguments! If you use the # wrong number of args it _will_ crash. Be especially wary of extra # arguments expected by 'X---Y--Ex' functions. class callable_function: def __init__ (self, address, name=''): self.address = address self.name = name self.called = 0 def __repr__ (self): return '<callable function "%s">' % self.name def __call__ (self, *args): self.called = self.called + 1 return calldll.call_foreign_function ( self.address, 'l'*len(args), 'l', args ) class module: callable_function_class = callable_function def __init__ (self, name, ext='.dll'): self.name = name self.handle = calldll.load_library (name+ext) if not self.handle: raise SystemError, "couldn't load module '%s'" % (name+ext) self.funs = {} self.loaded = 1 def unload (self): if self.loaded and self.handle: self.funs = {} calldll.free_library (self.handle) # this will never happen unless this module is deleted from # 'module_map' (see below). def __del__ (self): self.funs = {} self.unload() self.loaded = 0 def __repr__ (self): return "<win32 module '%s' (%d functions)>" % ( self.name, len(self.funs) ) def __getattr__ (self, name): if not self.loaded: raise SystemError, "module has been unloaded!" # I wonder which is faster, using try/except or <has_key> ? try: return self.funs[name] except KeyError: addr = calldll.get_proc_address (self.handle, name) if addr: self.funs[name] = self.callable_function_class (addr, name) else: # try tacking on the 'ASCII' modifier addr = calldll.get_proc_address (self.handle, name+'A') if addr: self.funs[name] = self.callable_function_class (addr, name) else: raise AttributeError, 'GetProcAddress failed for %s' % name return self.funs[name] # cache modules cmodule = module module_map = {} def module (name, ext='.dll'): full_name = name + ext if module_map.has_key (full_name): return module_map[full_name] else: mod = cmodule (name, ext) module_map[full_name] = mod return mod class _dll: "Can I use some feature of the package system to make this work?" def __getattr__ (self, name): return module (name) dll = _dll() def dump_module_info(): print '-'*20 print 'WINDLL Function Call Stats:' for mod in module_map.values(): print '--- %s ---' % mod fun_items = mod.funs.items() fun_items.sort() for name, fun in fun_items: print '%d\t%s' % (fun.called, name) import string class cstring: immortal = {} def __init__ (self, s, length=0, remember=0): # make sure to zero-terminate the string if length > len(s): s = s + '\000' * (length - len(s)) elif not s: s = '\000' elif s[-1] != '\000': s = s + '\000' self.mb = calldll.membuf (len(s)) self.mb.write (s) if remember: cstring.immortal[self.mb] = 1 def address (self): return self.mb.address() # Provides automatic conversion to an integer, for convenience. # This lets us pass in an object to call_foreign_function, rather # than calling 'address()' explicitly. __int__ = address def __len__ (self): # don't count the NULL char return self.mb.size() - 1 def __del__ (self): del self.mb def strlen (self): # this could be certainly be more efficient. 8^) return len(self.trunc()) def __repr__ (self): return "'%s'" % self.trunc() def __getitem__ (self, index): return self.value()[index] def value (self): return self.mb.read() def trunc (self): s = self.mb.read() i = string.find (s, '\000') if i != -1: return s[:i] else: return s def write (self, s): if len(s) >= self.mb.size()-1: raise ValueError, 'string too big for buffer' else: self.mb.write (s+'\000') # compatibility addressable_string = cstring class membuf: def __init__ (self, initval=None): # initval can be either a length, or a string # [most likely packed by struct/npstruct] if type(initval) == type(0): self.mb = calldll.membuf (initval) elif type(initval) == type (''): self.mb = calldll.membuf (len (initval)) self.mb.write (initval) def __len__ (self): return self.mb.size() def __getattr__ (self, attr): return getattr (self.mb, attr) def __int__ (self): return self.mb.address() def __getitem__ (self, index, size=1): return self.mb.read (index, size) def __setitem__ (self, index, value): self.mb.write (value, index) --Boundary_(ID_vqVNTC4E0Z3NrgSjKnlALw)-- From dsh8290@rit.edu Thu Mar 29 16:43:29 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 11:43:29 -0500 Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE767pYdFgja2mMdf85000033cf@hotmail.com>; from bleh99@hotmail.com on Thu, Mar 29, 2001 at 11:21:53AM -0500 References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> <OE767pYdFgja2mMdf85000033cf@hotmail.com> Message-ID: <20010329114329.A11607@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 11:21:53AM -0500, spi wrote: | Here are the results I get, I don't understand why it's not showing the | other modules | | >>> import windll | >>> print windll | <module 'windll' from 'd:\python20\lib\dynwin\windll.pyc'> | >>> dir( windll ) | ['__builtins__', '__doc__', '__file__', '__name__'] | >>> Ok, so it found the module in the directory you expected, but it came from the .pyc, not .py file. (.pyc's are simply bytecode versions of .py files) Also, the module doesn't contain anything except for it's name and docstring. You could try printing the docstring to see what (if anything) it says. I would recommend deleting the .pyc file so that the interpreter has to parse and re-bytecompile the .py file again. Perhaps you somehow ended up with an outdated or lacking .pyc file? HTH, -D PS. the previous message from "spi" was really a 'bounce' from my (see mutt's docs for a definition of the (overloaded) term) personal box. I hadn't noticed (in my hasty reading) the long code included, sorry for sending all such a long message From scarblac@pino.selwerd.nl Thu Mar 29 16:43:08 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 29 Mar 2001 18:43:08 +0200 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010329103916.A13441@tor.dhs.org>; from bwinton@tor.dhs.org on Thu, Mar 29, 2001 at 10:39:16AM -0500 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> <20010329103916.A13441@tor.dhs.org> Message-ID: <20010329184308.A29483@pino.selwerd.nl> On Thu, Mar 29, 2001 at 10:39:16AM -0500, Blake Winton wrote: > Because I need to tell _every_ python script I write that it's > actually a python script? Surely if *nix is so great it could > figure that out from the ".py" extension on my files. ;) Or > at least have a way for me to only type it in once, instead of > in _every_ file... Well, it's better than having a dozen programs claiming that ".doc" belongs to them... And I have scripts written in different versions of Python. Anyways, there is a cool hack you can do in DOS batch files, don't know if it's needed in the latest Windows, but it's fun to mention. Name your Python file foo.bat and start it with this: @echo off rem = """ python -x foo.bat goto end """ del rem # Your Python code here """ :end """ You can now start it as 'foo'. The python -x option makes python skip the first line of the file, and was added for this trick, iirc... -- Remco Gerlich From scarblac@pino.selwerd.nl Thu Mar 29 16:45:57 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 29 Mar 2001 18:45:57 +0200 Subject: [Tutor] Test In-Reply-To: <20010329130516.15d8771e.baptista@linuxsolutions.com.br>; from baptista@linuxsolutions.com.br on Thu, Mar 29, 2001 at 01:05:16PM -0300 References: <20010329130516.15d8771e.baptista@linuxsolutions.com.br> Message-ID: <20010329184557.A29534@pino.selwerd.nl> On Thu, Mar 29, 2001 at 01:05:16PM -0300, Paulo Henrique Baptista de Oliveira wrote: > Hi all, > where is the python tutorial? > Much thanks, PH Your test worked :). If you can already program, the Python tutorial is at http://www.python.org/doc/current/tut/tut.html If you're new to programming you will find that one hard going, but http://www.crosswinds.net/~agauld/ is good. You should receive two copies of this, one directly to you and one through the list. -- Remco Gerlich From dsh8290@rit.edu Thu Mar 29 17:31:40 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 12:31:40 -0500 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010329184308.A29483@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Mar 29, 2001 at 06:43:08PM +0200 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> <20010329103916.A13441@tor.dhs.org> <"from bwinton"@tor.dhs.org> <20010329184308.A29483@pino.selwerd.nl> Message-ID: <20010329123140.A11828@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 06:43:08PM +0200, Remco Gerlich wrote: | On Thu, Mar 29, 2001 at 10:39:16AM -0500, Blake Winton wrote: | > Because I need to tell _every_ python script I write that it's | > actually a python script? Surely if *nix is so great it could | > figure that out from the ".py" extension on my files. ;) Or | > at least have a way for me to only type it in once, instead of | > in _every_ file... | | Well, it's better than having a dozen programs claiming that ".doc" belongs | to them... And I have scripts written in different versions of Python. Good point as well. The worst is when you use multiple versions of Word (on different machines) and each one thinks it should be called .doc. Then you save with the new version and forget to specify the old format, ... | Anyways, there is a cool hack you can do in DOS batch files, don't know if | it's needed in the latest Windows, but it's fun to mention. Name your Python | file foo.bat and start it with this: <snipped> Nice trick! -D From kauphlyn@speakeasy.org Thu Mar 29 17:36:16 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Thu, 29 Mar 2001 09:36:16 -0800 (PST) Subject: [Tutor] trouble with odbc Message-ID: <Pine.LNX.4.21.0103290932370.16471-100000@grace.speakeasy.org> hello all, is anyone familiar with the odbc module? i am using it with ms sql server. all i am trying to do is return rows from a table: >>> db = odbc.odbc('northwind/sa') >>> cur = s.cursor() >>> cur.execute('select * from Customers') >>> print cur.description >>> while 1: >>> rec = cur.fetchall() >>> if not rec: break >>> print rec this runs fine and gives me a definition of each of the columns in table Customers and all the data. however, when i run the same script, swapping Customers with the Employees table, I get column definition and the following error: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index in FETCH The only thing that I have noticed is that the columns in the Customers table are all strings types while the columns in Employees are more varied, having such datatypes as number and date. is there any reason why this would cause a failure? any help at all would be appreciated. ~d ps - did i mention this is the best list in the world? From kauphlyn@speakeasy.org Thu Mar 29 18:05:43 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Thu, 29 Mar 2001 10:05:43 -0800 (PST) Subject: [Tutor] trouble with odbc In-Reply-To: <Pine.LNX.4.21.0103290932370.16471-100000@grace.speakeasy.org> Message-ID: <Pine.LNX.4.21.0103291002170.9629-100000@grace.speakeasy.org> > >>> db = odbc.odbc('northwind/sa') > >>> cur = s.cursor() Oops! this line is actually >>>cur = db.cursor() I typed the wrong code into my email message. Sorry for any confusion. > >>> cur.execute('select * from Customers') > >>> print cur.description > >>> while 1: > >>> rec = cur.fetchall() > >>> if not rec: break > >>> print rec From m_konermann@gmx.de Thu Mar 29 18:27:16 2001 From: m_konermann@gmx.de (Marcus Konermann) Date: Thu, 29 Mar 2001 20:27:16 +0200 Subject: [Tutor] i have got problems handling the types module Message-ID: <3AC37E84.C9580127@gmx.de> --------------C799FB2083D973E8121E701C Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hello ! i want to use the types module for different comparisons like the following: import types c=3.5 if type(c) == types.FloatType: print 'It´s a float !' the error output is the following: TypeError: call of non-function (type string) and i don´t know why. So, i need a solution to this problem. thanks a lot Marcus K. (and thanks a lot for all the great help before! :-) ) --------------C799FB2083D973E8121E701C Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> Hello ! <p>i want to use the types module for different comparisons like the following: <p><i>import types</i> <br><i>c=3.5</i> <br><i>if type(c) == types.FloatType:</i> <br><i>print 'It´s a float !'</i> <p>the error output is the following: <br><b>TypeError: call of non-function (type string)</b> <br>and i don´t know why. <br>So, i need a solution to this problem. <p>thanks a lot <br>Marcus K. <br>(and thanks a lot for all the great help before! :-) ) <br><i></i> <br><i></i> <br> </html> --------------C799FB2083D973E8121E701C-- From Glen@ihello-inc.com Thu Mar 29 18:54:42 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Thu, 29 Mar 2001 10:54:42 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A486@go.ihello.com> Hello, I am trying to find the equivalent to the linux command free. Specifically I would like to know how much free space I have on my machine separated by physical, actual, and swap memory. I think that it would be getrusage, but I am not sure how to use if or if it will even work the way I think it will. Any ideas? Thanks Glen From scarblac@pino.selwerd.nl Thu Mar 29 19:19:45 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 29 Mar 2001 21:19:45 +0200 Subject: [Tutor] i have got problems handling the types module In-Reply-To: <3AC37E84.C9580127@gmx.de>; from m_konermann@gmx.de on Thu, Mar 29, 2001 at 08:27:16PM +0200 References: <3AC37E84.C9580127@gmx.de> Message-ID: <20010329211945.A133@pino.selwerd.nl> On Thu, Mar 29, 2001 at 08:27:16PM +0200, Marcus Konermann wrote: > Hello ! > > i want to use the types module for different comparisons like the > following: > > import types > c=3.5 > if type(c) == types.FloatType: > print 'It´s a float !' > > the error output is the following: > TypeError: call of non-function (type string) > and i don´t know why. > So, i need a solution to this problem. You probably have a variable named 'type', containing a string. That overrides the builtin function called type. So now 'type(c)' is trying to do a function call on a string. Beware of giving variables names like 'type', 'str', et cetera. -- Remco Gerlich From cdwom@mpinet.net Thu Mar 29 20:40:21 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Thu, 29 Mar 2001 15:40:21 -0500 Subject: [Tutor] Text Box References: <005901c0b844$ca5c2fe0$88dc35d8@KellyJoW> <20010329090958.H26119@tc.niof.net> Message-ID: <002201c0b890$7a6f74a0$29dc35d8@KellyJoW> > I believe a Text widget is never really empty. It always contains at > least a newline. Check for a length of 1. Thanks! I got it working! I'm using it to see if a text item is empty when someone chooses Open from the File menu. If it is empty, the file is opened in the current window, otherwise its opened in a new window. It works fine, except for once it creates a new window and puts the file in it, the old window becomes the active window (The new one doesn't keep the focus if that makes sense.) Is there a topleve meathod to make a window recieve the focus, or is there just simply a better way to achieve this? Here is my code: def openfile(self): pl = END oname = askopenfilename(filetypes=[("Text files", "*.txt")]) if len(self.st.get(1.0,END)) == int(1): if oname: for line in fileinput.input(oname): self.st.insert(pl,line) self.t.title("PythonPadTk - "+oname) else: if oname: neweditor() for line in fileinput.input(oname): tl[len(tl)-1].st.insert(pl,line) tl[len(tl)-1].t.title("PythonPadTk - "+oname) tl[] is a list of the toplevel widgets, st is a scroll text object and i thing the rest is self explainatory. Thanks, Corey > -- > "I will not be pushed, filed, stamped, indexed, briefed, debriefed, or > numbered. My life is my own." > -- The Prisoner > Rick Pasotto email: rickp@telocity.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dsh8290@rit.edu Thu Mar 29 20:44:02 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 15:44:02 -0500 Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A486@go.ihello.com>; from Glen@ihello-inc.com on Thu, Mar 29, 2001 at 10:54:42AM -0800 References: <A50594A71D5FD311A00200902745F06F18A486@go.ihello.com> Message-ID: <20010329154402.E12401@harmony.cs.rit.edu> What system are you on? I don't know the answer anyways (unless you are looking for the "Task Manager" in Win(NT/2k)). -D On Thu, Mar 29, 2001 at 10:54:42AM -0800, Glen Bunting wrote: | Hello, | | I am trying to find the equivalent to the linux command free. Specifically | I would like to know how much free space I have on my machine separated by | physical, actual, and swap memory. I think that it would be getrusage, but I | am not sure how to use if or if it will even work the way I think it will. | Any ideas? | | Thanks | | Glen From Glen@ihello-inc.com Thu Mar 29 21:01:00 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Thu, 29 Mar 2001 13:01:00 -0800 Subject: [Tutor] (no subject) Message-ID: <A50594A71D5FD311A00200902745F06F18A488@go.ihello.com> Let me rephrase the question. I didn't state the question very clearly. I am trying to write a python script on Mandrake Linux that will check the amount of free memory available, similar to using the 'free' command. I already have a script written in sh which does this by calling the free command, but I am trying to re-write it completely in python. Thanks Glen ----------------- -----Original Message----- From: D-Man [mailto:dsh8290@rit.edu] Sent: Thursday, March 29, 2001 12:44 PM To: 'tutor@python.org' Subject: Re: [Tutor] (no subject) What system are you on? I don't know the answer anyways (unless you are looking for the "Task Manager" in Win(NT/2k)). -D On Thu, Mar 29, 2001 at 10:54:42AM -0800, Glen Bunting wrote: | Hello, | | I am trying to find the equivalent to the linux command free. Specifically | I would like to know how much free space I have on my machine separated by | physical, actual, and swap memory. I think that it would be getrusage, but I | am not sure how to use if or if it will even work the way I think it will. | Any ideas? | | Thanks | | Glen _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From dsh8290@rit.edu Thu Mar 29 21:30:04 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 16:30:04 -0500 Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A488@go.ihello.com>; from Glen@ihello-inc.com on Thu, Mar 29, 2001 at 01:01:00PM -0800 References: <A50594A71D5FD311A00200902745F06F18A488@go.ihello.com> Message-ID: <20010329163004.A12668@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 01:01:00PM -0800, Glen Bunting wrote: | Let me rephrase the question. I didn't state the question very clearly. I | am trying to write a python script on Mandrake Linux that will check the | amount of free memory available, similar to using the 'free' command. I | already have a script written in sh which does this by calling the free | command, but I am trying to re-write it completely in python. Oh, that's cool. I'd like it when you are done ;-). I don't think looking at free's implementation will help much because I think it looks at /proc/mem or something like that. -D From scarblac@pino.selwerd.nl Thu Mar 29 21:39:53 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 29 Mar 2001 23:39:53 +0200 Subject: [Tutor] (no subject) In-Reply-To: <20010329163004.A12668@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Mar 29, 2001 at 04:30:04PM -0500 References: <A50594A71D5FD311A00200902745F06F18A488@go.ihello.com> <20010329163004.A12668@harmony.cs.rit.edu> Message-ID: <20010329233953.A480@pino.selwerd.nl> On Thu, Mar 29, 2001 at 04:30:04PM -0500, D-Man wrote: > On Thu, Mar 29, 2001 at 01:01:00PM -0800, Glen Bunting wrote: > | Let me rephrase the question. I didn't state the question very clearly. I > | am trying to write a python script on Mandrake Linux that will check the > | amount of free memory available, similar to using the 'free' command. I > | already have a script written in sh which does this by calling the free > | command, but I am trying to re-write it completely in python. > > Oh, that's cool. I'd like it when you are done ;-). > > I don't think looking at free's implementation will help much because > I think it looks at /proc/mem or something like that. Yes, /proc/meminfo, so does top. There aren't any Python functions for this, I think. There's no way to do this in a portable way, not even between types of Unix. As far as I know. But of course, it's not hard to read and parse /proc/meminfo yourself, of course, if you only need it on Linux :). -- Remco Gerlich From deirdre@deirdre.net Thu Mar 29 22:30:53 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 29 Mar 2001 14:30:53 -0800 (PST) Subject: [Tutor] (no subject) In-Reply-To: <A50594A71D5FD311A00200902745F06F18A486@go.ihello.com> Message-ID: <Pine.LNX.4.31.0103291430360.28394-100000@emperor.deirdre.org> On Thu, 29 Mar 2001, Glen Bunting wrote: > I am trying to find the equivalent to the linux command free. And you are using what operating system? -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From cdwom@mpinet.net Thu Mar 29 22:37:11 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Thu, 29 Mar 2001 17:37:11 -0500 Subject: [Tutor] Text Box References: <005901c0b844$ca5c2fe0$88dc35d8@KellyJoW> <20010329090958.H26119@tc.niof.net> <002201c0b890$7a6f74a0$29dc35d8@KellyJoW> Message-ID: <001301c0b8a0$cc693920$29dc35d8@KellyJoW> > Thanks! I got it working! I'm using it to see if a text item is empty when > someone chooses Open from the File menu. If it is empty, the file is opened > in the current window, otherwise its opened in a new window. It works fine, > except for once it creates a new window and puts the file in it, the old > window becomes the active window (The new one doesn't keep the focus if that > makes sense.) Is there a topleve meathod to make a window recieve the focus, > or is there just simply a better way to achieve this? Here is my code: > > def openfile(self): > pl = END > oname = askopenfilename(filetypes=[("Text files", "*.txt")]) > if len(self.st.get(1.0,END)) == int(1): > if oname: > for line in fileinput.input(oname): > self.st.insert(pl,line) > self.t.title("PythonPadTk - "+oname) > else: > if oname: > neweditor() > for line in fileinput.input(oname): > tl[len(tl)-1].st.insert(pl,line) > tl[len(tl)-1].t.title("PythonPadTk - "+oname) > > tl[] is a list of the toplevel widgets, st is a scroll text object and i > thing the rest is self explainatory. Sorry for replying to my own post, but I found the awser hidden on the Python site. I just needed to add a line that says: tl[len(tl)-1].t.focus() Still, any help with my previous problems would be helpful: 1. How can add Copy Cut and Paste to an edit menu? I know how to make the menu items, I just don't know how to assign them to Cut, Copy, and Paste actions. 2. I know that you can askopenfilename and asksaveas to bring up premade Open and Save As Dialogue boxes. Is there a similar one for print? 3. How can I add Keyboard shortcuts to menu items? Particuarlt Cut, Copy, Paste, Save, and Open if they are prebuilt, but I'd also like to know how to generate my own (for ex. If I added custom menuitem and wanted a shortcut to it) Thanks again, Corey From mbc2@netdoor.com Thu Mar 29 22:45:39 2001 From: mbc2@netdoor.com (Brad Chandler) Date: Thu, 29 Mar 2001 16:45:39 -0600 Subject: [Tutor] trouble with odbc References: <Pine.LNX.4.21.0103291002170.9629-100000@grace.speakeasy.org> Message-ID: <002a01c0b8a1$fa76a9a0$111c0d0a@spb.state.ms.us> ----- Original Message ----- From: "Daniel Coughlin" <kauphlyn@speakeasy.org> To: <tutor@python.org> Sent: Thursday, March 29, 2001 12:05 PM Subject: Re: [Tutor] trouble with odbc > > > > >>> db = odbc.odbc('northwind/sa') > > >>> cur = s.cursor() > Oops! this line is actually > >>>cur = db.cursor() > I typed the wrong code into my email message. Sorry for any confusion. > > > >>> cur.execute('select * from Customers') > > >>> print cur.description > > >>> while 1: > > >>> rec = cur.fetchall() > > >>> if not rec: break > > >>> print rec Well, I'm not sure why yours isn't working, it may have something to do with the way your looping through your records. I'm just guessing, but that "if" statement may be causing the problem. I like to say something like: ###Begin Code cur.execute('select * from Customers') print cur.description result = cur.fetchall() numrows = len(result) # the number of rows returned by the query for x in range(0,numrows): numfields = len(result[x]) # the number of fields in each row for y in range(0,numfields): print result[x][y], print ###End Code This should print out each field in a row on a single line. That last print statement should add a break between rows. I haven't tested that exact code, but I use something like that whenever I query a database. I'm not saying that's the best method, but maybe it'll give you some ideas. Brad From bleh99@hotmail.com Fri Mar 30 00:22:14 2001 From: bleh99@hotmail.com (spi) Date: Thu, 29 Mar 2001 19:22:14 -0500 Subject: [Tutor] How do I use calldll and windll? References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> <OE767pYdFgja2mMdf85000033cf@hotmail.com> <20010329114329.A11607@harmony.cs.rit.edu> Message-ID: <OE17XLsxpTljBOh8s4K000045b9@hotmail.com> I figured out this issue, thought that I would post the solution in case anyone else had this problem I was importing the modules in the wrong order i was doing >>> import windll >>> import calldll The right way to do it is >>> import calldll >>> import windll ----- Original Message ----- From: "D-Man" <dsh8290@rit.edu> To: <tutor@python.org> Sent: Thursday, March 29, 2001 11:43 AM Subject: Re: [Tutor] How do I use calldll and windll? > On Thu, Mar 29, 2001 at 11:21:53AM -0500, spi wrote: > | Here are the results I get, I don't understand why it's not showing the > | other modules > | > | >>> import windll > | >>> print windll > | <module 'windll' from 'd:\python20\lib\dynwin\windll.pyc'> > | >>> dir( windll ) > | ['__builtins__', '__doc__', '__file__', '__name__'] > | >>> > > Ok, so it found the module in the directory you expected, but it came > from the .pyc, not .py file. (.pyc's are simply bytecode versions of > .py files) Also, the module doesn't contain anything except for it's > name and docstring. You could try printing the docstring to see what > (if anything) it says. > > I would recommend deleting the .pyc file so that the interpreter has > to parse and re-bytecompile the .py file again. Perhaps you somehow > ended up with an outdated or lacking .pyc file? > > HTH, > -D > > > PS. the previous message from "spi" was really a 'bounce' from my (see mutt's > docs for a definition of the (overloaded) term) personal box. I > hadn't noticed (in my hasty reading) the long code included, > sorry for sending all such a long message > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From dsh8290@rit.edu Fri Mar 30 00:56:05 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 29 Mar 2001 19:56:05 -0500 Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE17XLsxpTljBOh8s4K000045b9@hotmail.com>; from bleh99@hotmail.com on Thu, Mar 29, 2001 at 07:22:14PM -0500 References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> <OE767pYdFgja2mMdf85000033cf@hotmail.com> <20010329114329.A11607@harmony.cs.rit.edu> <OE17XLsxpTljBOh8s4K000045b9@hotmail.com> Message-ID: <20010329195605.A13204@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 07:22:14PM -0500, spi wrote: | I figured out this issue, thought that I would post the solution in | case anyone else had this problem | | I was importing the modules in the wrong order | | i was doing | | >>> import windll | >>> import calldll | | The right way to do it is | | >>> import calldll | >>> import windll Do you know why the order of import is significant? I don't think it should be, I think the module's designer should have windll import calldll if it needs it, though of course there may be an issue I'm not even thinking of now. -D From bleh99@hotmail.com Fri Mar 30 01:49:16 2001 From: bleh99@hotmail.com (spi) Date: Thu, 29 Mar 2001 20:49:16 -0500 Subject: [Tutor] How do I use calldll and windll? References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> <OE767pYdFgja2mMdf85000033cf@hotmail.com> <20010329114329.A11607@harmony.cs.rit.edu> <OE17XLsxpTljBOh8s4K000045b9@hotmail.com> <20010329195605.A13204@harmony.cs.rit.edu> Message-ID: <OE26Rf3sllNY30kkZIh00004452@hotmail.com> I'm just beginning at python so i have no idea why the order would be important, in fact windll imports calldll but for some reason, if I do it in that order it works otherwise I get nothing ----- Original Message ----- From: "D-Man" <dsh8290@rit.edu> To: <tutor@python.org> Sent: Thursday, March 29, 2001 7:56 PM Subject: Re: [Tutor] How do I use calldll and windll? > On Thu, Mar 29, 2001 at 07:22:14PM -0500, spi wrote: > | I figured out this issue, thought that I would post the solution in > | case anyone else had this problem > | > | I was importing the modules in the wrong order > | > | i was doing > | > | >>> import windll > | >>> import calldll > | > | The right way to do it is > | > | >>> import calldll > | >>> import windll > > Do you know why the order of import is significant? I don't think it > should be, I think the module's designer should have windll import > calldll if it needs it, though of course there may be an issue I'm > not even thinking of now. > > -D > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From cdwom@mpinet.net Fri Mar 30 02:27:33 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Thu, 29 Mar 2001 21:27:33 -0500 Subject: [Tutor] How do I use calldll and windll? References: <Pine.LNX.4.21.0103290127390.29061-100000@hkn.eecs.berkeley.edu> <OE29aaDi3dQT9dcmBqE00004107@hotmail.com> <20010329110326.K11119@harmony.cs.rit.edu> <OE767pYdFgja2mMdf85000033cf@hotmail.com> <20010329114329.A11607@harmony.cs.rit.edu> <OE17XLsxpTljBOh8s4K000045b9@hotmail.com> <20010329195605.A13204@harmony.cs.rit.edu> <OE26Rf3sllNY30kkZIh00004452@hotmail.com> Message-ID: <000f01c0b8c0$fb3a2fa0$46dd35d8@KellyJoW> > I'm just beginning at python so i have no idea why the order would be > important, > in fact windll imports calldll but for some reason, if I do it > in that order it works otherwise I get nothing Just a guess, but maybe its a problem with a funtion overwriting another one. So long, and thanks for all the fish! Corey Check out my Webpage at: schitzomedia.y0ru.net and vote for the top 10 games of all time!!! ANGBAND NEEDS MORE VOTES!!! From JohnH@PHM.GOV.AU Fri Mar 30 02:25:54 2001 From: JohnH@PHM.GOV.AU (Hirsch, John) Date: Fri, 30 Mar 2001 12:25:54 +1000 Subject: [Tutor] RE: Tutor digest, Vol 1 #699 - 16 msgs Message-ID: <A90DD8D7B82FD311B4D00008C7DBD6EAB5EBE7@phm-exch.phm.gov.au> You should not need to import calldll as windll imports it itself as you see below. If I do as in the usage example it works fine. There is a 'module' method in windll so you should be able to call it by windll.module() after importing windll. Copied from Windll.py >>>>> # -*- Mode: Python; tab-width: 4 -*- # Author: Sam Rushing <rushing@nightmare.com> """\ lets you call functions in win32 dll directly, using the calldll module. Usage: To create a dll module object: >>> kernel32 = windll.module ('kernel32') >>> kernel32 <win32 module 'kernel32' (0 functions)> To reference a function: >>> kernel32.Beep <callable function "Beep"> To call a function: >>> kernel32.Beep (1000, 50) """ import calldll # A convenience for the vast majority of functions which take long # parameters (addresses or integers) and return a long. Assumes that # the caller knows the correct number of arguments! If you use the # wrong number of args it _will_ crash. Be especially wary of extra # arguments expected by 'X---Y--Ex' functions. class callable_function: def __init__ (self, address, name=''): self.address = address self.name = name self.called = 0 <<<<<<<snip > I figured out this issue, thought that I would post the solution in > case anyone else had this problem > > I was importing the modules in the wrong order > > i was doing > > >>> import windll > >>> import calldll > > The right way to do it is > > >>> import calldll > >>> import windll From kromag@nsacom.net Fri Mar 30 05:56:51 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Thu, 29 Mar 2001 21:56:51 -0800 (PST) Subject: [Tutor] PyGreSQL tutorial difficulties redux (Long!) Message-ID: <200103300556.f2U5upC26388@pop.nsacom.net> I am having difficulty with the PyGreSQL tutorial modules that come with version3.1. I have built a vanilla PostGres (v 7.0.3) that by all appearances is functioning normally. After a few false starts I got PyGres to build and successfully connected to postgres through my python interpreter as described in the README. I had great fun playing with adding and removing data, but ran into trouble when I attempted to write the querys out to a file through python. Time for the tutoral. The problem I am having is: I cannot for the life of me figure out just how to construct the particular database that the tutoral modules need to connect to. I have created a database called 'doug' with createdb and have attempted to import and start the tutorial according to the instructions: __________________________________________________________________ MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL This module is designed for being imported from python prompt In order to run the samples included here, first create a connection using : cnx = basics.DB(...) The "..." should be replaced with whatever arguments you need to open an existing database. Usually all you need is the name of the database and, in fact, if it is the same as your login name, you can leave it empty. then start the demo with: basics.demo(cnx) ------------------------------------------------------------------ I am a little confused initially because when I attempt to follow the instructions: ------------begin python session (Warning! Long!)------------------ Python 2.0 (#2, Mar 23 2001, 19:43:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import _pg >>> cnx=basics.DB('doug','localhost') Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: There is no variable named 'basics' >>> #well, that didn't work .. >>> basics=_pg.connect('doug','localhost') >>> # well, that's a good sign! .. >>> #now to import the basics.py demo... .. >>> import basics.py __________________________________________________________________ MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL This module is designed for being imported from python prompt In order to run the samples included here, first create a connection using : cnx = basics.DB(...) The "..." should be replaced with whatever arguments you need to open an existing database. Usually all you need is the name of the database and, in fact, if it is the same as your login name, you can leave it empty. then start the demo with: basics.demo(cnx) __________________________________________________________________ Traceback (most recent call last): File "<stdin>", line 1, in ? File "basics.py", line 23, in ? from _pg import DB ImportError: cannot import name DB >>> --------------- End Python Session-------------------- Okay, what am I doing wrong? It will obviously do me no good whatsoever to attempt "cnx=basics.DB('doug', 'localhost') since 'DB' appears not to be loading. (Trust me, I've tried! :-) This wouldn't frustrate me much if I hadn't been able to connect with the usual: ---------------begin fun successful stuff------------- Python 2.0 (#2, Mar 23 2001, 19:43:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import _pg >>> db=_pg.connect('test','localhost') >>> db.query("select * from pork") sausage |eggs | date ---------------+------------------+---------- bob evans |free range |1999-06-18 tenessee pride |ground hippie meal|2001-06-12 generic |feces fed fowl |2000-02-19 hillbilly |clutter cluck clan|2000-08-03 hawg flesh 2000|Foghorn Leghorn |2033-03-14 beefy bitz |rectum stopper |1988-08-19 (6 rows) >>> >>> db.query("insert into pork values ('spam','emu omlette','06-18-1966')") 19232 >>> db.query("select eggs from pork") eggs ------------------ free range ground hippie meal feces fed fowl clutter cluck clan Foghorn Leghorn rectum stopper emu omlette (7 rows) ------------------------End successful stuff--------------- This is more fun than most things, but I would really like to get a clue on why I can't actually make the basics.py module function. I have read all the way through the module, hoping for clues, but it keeps coming back to the 'DB' function in the _pg module itself AFAICT Sorry for the long, long length, but I have been known to offer too little info! :-) Thanks! Doug From wilson@visi.com Fri Mar 30 03:51:41 2001 From: wilson@visi.com (Timothy Wilson) Date: Thu, 29 Mar 2001 21:51:41 -0600 (CST) Subject: [Tutor] Group generator works! Message-ID: <Pine.GSO.4.21.0103292143440.26896-100000@isis.visi.com> Hi everyone, Thanks to all who offered suggestions as I worked my way through one of my first OOP attempts. My small program to create random student groups now works! At the risk of filling you inboxes <g>, I've included the code and a sample interpretor session below. (I haven't coded a user interface yet.) Right now the program only allows the instructor to specify a certain number of groups and requires the students to be read from a file. Possible refinements: 1. Optional direct input of students at a prompt. 2. Create groups by specifying the group's size rather than number of groups. 3. Require gender mixing Current questions: 1. Do I need to seed the whrandom module to get more truly random numbers? 2. The assignGroups method looks rather crude to me. Can anyone suggest a more elegant solution? 3. Anyone see an OOP faux pas? Thanks again for the help. Here's the code: #!/usr/bin/python # makegroups.py by Tim Wilson <wilson@visi.com> # Thanks to Benoit Dupire, Blake Winton, and others on the tutor list # for their advice. import string, whrandom class Student: def __init__(self, ln, fn, gender): self.ln = ln self.fn = fn self.gender = gender self.group = 0 self.assignedToGroup = 0 def __str__(self): return "%s, %s" % (self.ln, self.fn) def setGroup(self, groupNumber): self.group = groupNumber class Teacher: def __init__(self, name): self.name = name self.studentRoster = [] self.numStudents = 0 self.groupList = [] self.numGroups = 0 def __str__(self): return "%s has %s students" % (self.name, self.numStudents) def addStudentFromFile(self, datafile): list = open(datafile, 'r').readlines() for entry in list: s = string.split(entry, ',') self.studentRoster.append(Student(s[0], s[1], s[2][:1])) self.numStudents = self.numStudents + len(list) def printStudentRoster(self): for st in self.studentRoster: print st def makeGroup(self, groupID): self.groupList.append(groupID) self.numGroups = self.numGroups + 1 def addStudentToGroup(self, st, grp): st.group = grp st.assignedToGroup = 1 def unassignStudent(self, st): st.__init__(st.ln, st.fn, st.gender) def printGroups(self): for grp in self.groupList: print "Group #%s" % grp print '==========' for st in self.studentRoster: if st.group == grp: print st print def clearGroups(self): for st in self.studentRoster: self.unassignStudent(st) self.groupList = [] def assignGroups(self, numGroups): self.numGroups = numGroups smallestGroupSize = self.numStudents/self.numGroups groupIndex = [] for i in range(numGroups): groupIndex.append(smallestGroupSize) for j in range(self.numStudents % self.numGroups): groupIndex[j] = groupIndex[j] + 1 for k in range(1, self.numGroups + 1): self.makeGroup(k) for grp in self.groupList: for x in range(groupIndex[grp-1]): unassignedStudents = [] for y in self.studentRoster: if not y.assignedToGroup: unassignedStudents.append(y) selected = whrandom.choice(unassignedStudents) self.addStudentToGroup(selected, grp) Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import makegroups >>> wilson = makegroups.Teacher('Tim Wilson') >>> wilson.addStudentFromFile('class.dat') >>> wilson.assignGroups(5) >>> wilson.printGroups() Group #1 ========== Boop, Betty Watters, Aaron Saoirse, Deirdre Group #2 ========== Gauld, Alan Rubble, Betty Lutz, Mark Group #3 ========== Flintstone, Wilma Yoo, Danny Van Laningham, Ivan Group #4 ========== Wilson, Tim Crawford, Cindy Group #5 ========== Van Rossum, Guido Ascher, David >>> wilson.clearGroups() >>> wilson.assignGroups(4) >>> wilson.printGroups() Group #1 ========== Van Rossum, Guido Boop, Betty Gauld, Alan Saoirse, Deirdre Group #2 ========== Yoo, Danny Wilson, Tim Van Laningham, Ivan Group #3 ========== Flintstone, Wilma Rubble, Betty Lutz, Mark Group #4 ========== Crawford, Cindy Ascher, David Watters, Aaron >>> -- 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 | <dtml-var pithy_quote> | http://linux.com/ From britt_green@hotmail.com Fri Mar 30 04:17:58 2001 From: britt_green@hotmail.com (Britt Green) Date: Thu, 29 Mar 2001 20:17:58 -0800 Subject: [Tutor] Timer? Message-ID: <F142oGKCiX96suzsttX0000eb57@hotmail.com> I was wondering how to make a timer in Python. Say every ten seconds, I want Python to print out a string of text. How might I do this? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From alan.gauld@bt.com Fri Mar 30 09:58:44 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 30 Mar 2001 10:58:44 +0100 Subject: [Tutor] Text Box Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D687@mbtlipnt02.btlabs.bt.co.uk> > if textwidget.get(1.0,END) == "": try putting the index instide quotes: if textwidget.get('1.0',END) == "": Should work... Alan g. From alan.gauld@bt.com Fri Mar 30 09:57:37 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 30 Mar 2001 10:57:37 +0100 Subject: [Tutor] How can I make my script work without calling Python? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D686@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0B8FF.D9A90D40 Content-type: text/plain; charset="iso-8859-1" I have quick question. let's say I have a script (foo.py) which takes some parameters (x,y,z). the usual way to run is to type: >python foo.py x y z Is there anyway I can make it work without calling Python i.e >foo.py x y z Sure just call it. for example if I create a file: C:\args.py that looks like: import sys for arg in sys.argv: print arg print 'Thats it' raw_input("Hit enter to exit") And bring up the run dalog from Start|Run I can type: c:\args.py 1 2 3 And get C:\args.py 1 2 3 Hit enter to exit All you need is Python in your PATH and the .py file extension associated with python.exe - both of which is done by the windoze installer. Just do it... Alan g. ------_=_NextPart_001_01C0B8FF.D9A90D40 Content-type: text/html; charset="iso-8859-1" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META content="MSHTML 5.00.3013.2600" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> <DIV><FONT face=Arial size=2>I have quick question. let's say I have a script (foo.py) which takes some parameters (x,y,z). the usual way to run is to type:</FONT></DIV> <DIV><FONT face=Arial size=2>>python foo.py x y z</FONT></DIV> <DIV><FONT face=Arial size=2>Is there anyway I can make it work without calling Python i.e</FONT></DIV> <DIV><FONT face=Arial size=2>>foo.py x y z </FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV> </DIV></BLOCKQUOTE> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>Sure just call it.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>for example if I create a file:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>C:\args.py that looks like:</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>import sys</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>for arg in sys.argv: print arg</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>print 'Thats it'</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>raw_input("Hit enter to exit")</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>And bring up the run dalog from Start|Run</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>I can type: c:\args.py 1 2 3</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>And get</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>C:\args.py</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>1</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>2</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>3</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>Hit enter to exit</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>All you need is Python in your PATH and the .py file extension associated with </SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>python.exe - both of which is done by the windoze installer.</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>Just do it...</SPAN></FONT></DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001></SPAN></FONT> </DIV> <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=380465709-30032001>Alan g.</SPAN></FONT></DIV></BODY></HTML> ------_=_NextPart_001_01C0B8FF.D9A90D40-- From alan.gauld@bt.com Fri Mar 30 09:49:46 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 30 Mar 2001 10:49:46 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D685@mbtlipnt02.btlabs.bt.co.uk> > It has to be said, though, that regular expressions are weird > at first. > You'll want to take a look at a few introductions that talk > about regular More blatant self promotion I'm afraid, but you might also find the article I werote on informIT.com useful. Its basically the first half of the Regex chapter of my book. http://www.informit.com/myinformit/login/index.asp?session_id={03ABD12E-8EA6 -4263-B7DB-D011A0F04257}&t={94AE5B48-1D7D-462A-A4A6-83CE19EC0705}&n={1CBD305 F-D503-49FA-9699-8B2C06C9C520} A horrid URL, If you have problems with it try searching for my name as author instead :-) You might have to register but informit is such a useful site for Linux and windows programmers that I can't imagine anyone not wanting to be registered on it! Alan g. From dyoo@hkn.eecs.berkeley.edu Fri Mar 30 12:38:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 30 Mar 2001 04:38:07 -0800 (PST) Subject: [Tutor] How do I use calldll and windll? In-Reply-To: <OE26Rf3sllNY30kkZIh00004452@hotmail.com> Message-ID: <Pine.LNX.4.21.0103300430280.29824-100000@hkn.eecs.berkeley.edu> On Thu, 29 Mar 2001, spi wrote: > I'm just beginning at python so i have no idea why the order would be > important, > in fact windll imports calldll but for some reason, if I do it > in that order it works otherwise I get nothing The same sort of dependency on order happens when working with ODBC stuff, at least when I last tried it. The documentation always said to do: ### import dbi import odbc ### in that particular order. Strange though, because windll does import calldll, so I can't see why it doesn't work. Hmmm... I must remind myself to install Windows one of these days to test this out. From scott@zenplex.com Fri Mar 30 14:38:49 2001 From: scott@zenplex.com (Scott Ralph Comboni) Date: 30 Mar 2001 09:38:49 -0500 Subject: [Tutor] Is There a Bugtracking tool written in Python Message-ID: <200103301436.JAA23470@scott.zenplex.com> Does anyone now if there is a bugtracking tool like bugzilla written in Python? Scott From mbc2@netdoor.com Fri Mar 30 15:09:03 2001 From: mbc2@netdoor.com (Brad Chandler) Date: Fri, 30 Mar 2001 09:09:03 -0600 Subject: [Tutor] PyGreSQL tutorial difficulties redux (Long!) References: <200103300556.f2U5upC26388@pop.nsacom.net> Message-ID: <000d01c0b92b$5b7b1860$111c0d0a@spb.state.ms.us> ----- Original Message ----- From: <kromag@nsacom.net> To: <tutor@python.org> Sent: Thursday, March 29, 2001 11:56 PM Subject: [Tutor] PyGreSQL tutorial difficulties redux (Long!) > I am having difficulty with the PyGreSQL tutorial modules that come with > version3.1. > > I have built a vanilla PostGres (v 7.0.3) that by all appearances is > functioning normally. After a few false starts I got PyGres to build and > successfully connected to postgres through my python interpreter as described > in the README. I had great fun playing with adding and removing data, but ran > into trouble when I attempted to write the querys out to a file through > python. Time for the tutoral. > > The problem I am having is: I cannot for the life of me figure out just how > to construct the particular database that the tutoral modules need to connect > to. > > I have created a database called 'doug' with createdb and have attempted to > import and start the tutorial according to the instructions: > > __________________________________________________________________ > MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL > > This module is designed for being imported from python prompt > > In order to run the samples included here, first create a connection > using : cnx = basics.DB(...) > > The "..." should be replaced with whatever arguments you need to open an > existing database. Usually all you need is the name of the database and, > in fact, if it is the same as your login name, you can leave it empty. > > then start the demo with: basics.demo(cnx) > ------------------------------------------------------------------ > > I am a little confused initially because when I attempt to follow the > instructions: > > ------------begin python session (Warning! Long!)------------------ > > > Python 2.0 (#2, Mar 23 2001, 19:43:00) > [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import _pg > >>> cnx=basics.DB('doug','localhost') > Traceback (most recent call last): > File "<stdin>", line 1, in ? > NameError: There is no variable named 'basics' > >>> #well, that didn't work > .. > >>> basics=_pg.connect('doug','localhost') > >>> # well, that's a good sign! > .. > >>> #now to import the basics.py demo... > .. > >>> import basics.py > Well, the PyGreSQL module seems to be working properly. I'm not familiar with the basics.py file but I think you would need to import the PyGreSQL module (I'm assuming that's what the _pg is) and then import the basics.py module, and then try to create the connection. In your example, you tried to use the basics variable before you imported the basics.py module. Try: import _pg, basics cnx = basics.DB('doug','localhost') From dsh8290@rit.edu Fri Mar 30 15:21:31 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 30 Mar 2001 10:21:31 -0500 Subject: [Tutor] Timer? In-Reply-To: <F142oGKCiX96suzsttX0000eb57@hotmail.com>; from britt_green@hotmail.com on Thu, Mar 29, 2001 at 08:17:58PM -0800 References: <F142oGKCiX96suzsttX0000eb57@hotmail.com> Message-ID: <20010330102131.A13498@harmony.cs.rit.edu> On Thu, Mar 29, 2001 at 08:17:58PM -0800, Britt Green wrote: | I was wondering how to make a timer in Python. Say every ten seconds, I want | Python to print out a string of text. How might I do this? | | Britt import time while 1 : time.sleep( 10 ) # sleep (wait) for 10 seconds print "Hello" Various state, such as keeping track of how many iterations, etc, can be added to this. If you want the program to continue to work (ie if you have a gui) while this is printing 'hello' every ten seconds it will need to be moved to a separate thread. HTH, -D From alan.gauld@bt.com Fri Mar 30 15:32:47 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 30 Mar 2001 16:32:47 +0100 Subject: [Tutor] Text Box Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D68E@mbtlipnt02.btlabs.bt.co.uk> > > if textwidget.get(1.0,END) == "": > try putting the index inside quotes: > > if textwidget.get('1.0',END) == "": Hmm, it doesn't because of the line end but interestingly missing the quotes does work - unlike Tcl/Tk... I assume because Tkinter wraps the arguments as strings before passing them to Tcl anyway... I really must try these things before I post them :-) Alan g. From ium@micromuse.com Fri Mar 30 16:47:39 2001 From: ium@micromuse.com (ium@micromuse.com) Date: Fri, 30 Mar 2001 17:47:39 +0100 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010329110022.J11119@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Mar 29, 2001 at 11:00:22AM -0500 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> <20010329103916.A13441@tor.dhs.org> <20010329110022.J11119@harmony.cs.rit.edu> Message-ID: <20010330174739.A1380@ignoramus.ukdev.micromuse.com> [D-Man wrote] -| -| ---- ~/.vimrc ---- -| ; <most snipped> -| -| autocmd! BufNewFile *.py read ~/util/autoheaders/Python -| -| -| ---- ~/util/autoheaders/Python -| #!/usr/bin/env python -| -| # any other text (like name, license, etc) to appear automagically at -| # the beginning of each new .py file <grin> -| -| -| The only problem I have is that the first line (in the new buffer) is -| always blank with the header beginning on the second line. Is there a -| way to fix this? -| try the following instead: autocmd! BufNewFile *.py 0r ~/util/autoheader/Python ^^ Kindest regards, --ibs. -- Commitment, n.: [The difference between involvement and] Commitment can be illustrated by a breakfast of ham and eggs. The chicken was involved, the pig was committed. From jcm@bigskytel.com Fri Mar 30 16:48:09 2001 From: jcm@bigskytel.com (David Porter) Date: Fri, 30 Mar 2001 09:48:09 -0700 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: <200103301436.JAA23470@scott.zenplex.com>; from scott@zenplex.com on Fri, Mar 30, 2001 at 09:38:49AM -0500 References: <200103301436.JAA23470@scott.zenplex.com> Message-ID: <20010330094808.A32505@bigskytel.com> * Scott Ralph Comboni <scott@zenplex.com>: > Does anyone now if there is a bugtracking tool like bugzilla written in > Python? See: http://www.faqts.com/knowledge_base/view.phtml/aid/1508 David From dsh8290@rit.edu Fri Mar 30 18:05:52 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 30 Mar 2001 13:05:52 -0500 Subject: [Tutor] How can I make my script work without calling Python? In-Reply-To: <20010330174739.A1380@ignoramus.ukdev.micromuse.com>; from ium@micromuse.com on Fri, Mar 30, 2001 at 05:47:39PM +0100 References: <007f01c0b843$9ba9f3e0$a5020a0a@private.nipltd.com> <20010329102214.E11119@harmony.cs.rit.edu> <20010329103916.A13441@tor.dhs.org> <20010329110022.J11119@harmony.cs.rit.edu> <"from dsh8290"@rit.edu> <20010330174739.A1380@ignoramus.ukdev.micromuse.com> Message-ID: <20010330130552.A14233@harmony.cs.rit.edu> On Fri, Mar 30, 2001 at 05:47:39PM +0100, ium@micromuse.com wrote: | [D-Man wrote] | -| | -| The only problem I have is that the first line (in the new buffer) is | -| always blank with the header beginning on the second line. Is there a | -| way to fix this? | -| | | try the following instead: | | autocmd! BufNewFile *.py 0r ~/util/autoheader/Python | ^^ Works great!! Thanks. -D From virketis@fas.harvard.edu Fri Mar 30 18:24:39 2001 From: virketis@fas.harvard.edu (Pijus Virketis) Date: Fri, 30 Mar 2001 13:24:39 -0500 Subject: [Tutor] how to read HyperText documentation? Message-ID: <200103301816.NAA29810@smtp3.fas.harvard.edu> I am playing around with the HTML generator program, HyperText right now, but I cannot get to its documentation. The author says that it's at HyperText.HTML40.__doc__. Sure enough, if I import HyperText, and check dir(HyperText), there is a __doc__ module there. But I do not know how to get to the info inside. I tried printing __doc__ (ans: None), executing it, assigning it to a variable, etc. Could anyone help me out? Thanks, Pijus From llam@AccordionNetworks.com Fri Mar 30 18:50:19 2001 From: llam@AccordionNetworks.com (Larry Lam) Date: Fri, 30 Mar 2001 10:50:19 -0800 Subject: [Tutor] Scripts Message-ID: <005C01D254FAD411BF8800B0D03E0AB632F81D@MICROPHONE> How can I call and receive phone calls thru a modem using python scripts? How to kill a telnet section with python? Thanks Larry P. Lam Accordion Networks 6170 Stevenson Blvd. Fremont, CA 94538 (510) 979-9035 x384 (510)979-9039 Fax From jcm@bigskytel.com Fri Mar 30 20:18:11 2001 From: jcm@bigskytel.com (David Porter) Date: Fri, 30 Mar 2001 13:18:11 -0700 Subject: [Tutor] how to read HyperText documentation? In-Reply-To: <200103301816.NAA29810@smtp3.fas.harvard.edu>; from virketis@fas.harvard.edu on Fri, Mar 30, 2001 at 01:24:39PM -0500 References: <200103301816.NAA29810@smtp3.fas.harvard.edu> Message-ID: <20010330131811.A1385@bigskytel.com> * Pijus Virketis <virketis@fas.harvard.edu>: > I am playing around with the HTML generator program, HyperText right now, > but I cannot get to its documentation. The author says that it's at > HyperText.HTML40.__doc__. Sure enough, if I import HyperText, and check > dir(HyperText), there is a __doc__ module there. But I do not know how to > get to the info inside. I tried printing __doc__ (ans: None), executing it, > assigning it to a variable, etc. Could anyone help me out? You're looking at HyperText.__doc__, not HyperText.HTML40.__doc__. import HyperText print HyperText.HTML40.__doc__ David From dyoo@hkn.eecs.berkeley.edu Fri Mar 30 22:58:02 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 30 Mar 2001 14:58:02 -0800 (PST) Subject: [Tutor] Timer? In-Reply-To: <20010330102131.A13498@harmony.cs.rit.edu> Message-ID: <Pine.LNX.4.21.0103301450320.8721-100000@hkn.eecs.berkeley.edu> On Fri, 30 Mar 2001, D-Man wrote: > On Thu, Mar 29, 2001 at 08:17:58PM -0800, Britt Green wrote: > | I was wondering how to make a timer in Python. Say every ten seconds, I want > | Python to print out a string of text. How might I do this? > | > | Britt > > > import time > > while 1 : > time.sleep( 10 ) # sleep (wait) for 10 seconds > print "Hello" > > > Various state, such as keeping track of how many iterations, etc, can > be added to this. If you want the program to continue to work (ie if > you have a gui) while this is printing 'hello' every ten seconds it > will need to be moved to a separate thread. By the way, Tkinter has an "after()" function that says that, after a certain period of time has passed, it should call back a function. For example: ### from Tkinter import * class BlinkingButton(Button): def __init__(self, master, **kwargs): Button.__init__(self, master, **kwargs) self.blinkerson = 1 self.blink() def blink(self): if self.blinkerson: self.flash() self.after(1000, self.blink) if __name__ == '__main__': root = Tk() BlinkingButton(root, text="Blinking Button!").pack() mainloop() ### creates a button that winks every second. The blink() function is responsible, then, for getting itself to blink after every second. If you're working with Tkinter, it possible to do some interesting stuff, even without threads. From dyoo@hkn.eecs.berkeley.edu Fri Mar 30 23:00:06 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 30 Mar 2001 15:00:06 -0800 (PST) Subject: [Tutor] how to read HyperText documentation? In-Reply-To: <200103301816.NAA29810@smtp3.fas.harvard.edu> Message-ID: <Pine.LNX.4.21.0103301458520.8721-100000@hkn.eecs.berkeley.edu> On Fri, 30 Mar 2001, Pijus Virketis wrote: > I am playing around with the HTML generator program, HyperText right now, > but I cannot get to its documentation. The author says that it's at > HyperText.HTML40.__doc__. Sure enough, if I import HyperText, and check > dir(HyperText), there is a __doc__ module there. But I do not know how to > get to the info inside. I tried printing __doc__ (ans: None), executing it, > assigning it to a variable, etc. Could anyone help me out? Try: ### import HyperText print HyperText.HTML40.__doc__ ### What was happening, I think, was that you were printing out the docstring for the whole HyperText module: print HyperText.__doc__ Hope this helps! From syrinx@simplecom.net Sat Mar 31 04:03:17 2001 From: syrinx@simplecom.net (Scott) Date: Fri, 30 Mar 2001 22:03:17 -0600 Subject: [Tutor] posting scripts Message-ID: <ehlactkosrfgq4l86fg4bivi55jfb3p13g@4ax.com> If I had a script that I wanted to get feedback on, would it be okay to post it here? How long of one could I get away with? I just don't want to annoy anyone x days in the future... TNX From dyoo@hkn.eecs.berkeley.edu Sat Mar 31 05:41:04 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 30 Mar 2001 21:41:04 -0800 (PST) Subject: [Tutor] posting scripts In-Reply-To: <ehlactkosrfgq4l86fg4bivi55jfb3p13g@4ax.com> Message-ID: <Pine.LNX.4.21.0103302133260.18723-100000@hkn.eecs.berkeley.edu> On Fri, 30 Mar 2001, Scott wrote: > If I had a script that I wanted to get feedback on, would it be okay > to post it here? How long of one could I get away with? I just don't > want to annoy anyone x days in the future... It's perfectly ok to post it up, as long as it isn't too long. *grin* Feel free to post it up! A "long" script would probably be more that 2 pages, just because many people like to look at code that fits on one screen. For long scripts, you can submit your script to Useless Python: http://www.lowerstandard.com/python/pythonsource.html and point people to the url where your script is located. Useless Python is set up so that you can share your scripts with others, so it's a good resource to use. In any event, don't worry about "annoying" us; we're here to help and learn. Good luck! From storage@lycos.es Sat Mar 31 14:37:00 2001 From: storage@lycos.es (storage@lycos.es) Date: Sat, 31 Mar 2001 09:37:00 -0500 Subject: [Tutor] REGALE DOMINIOS O REGISTRE EL SUYO Message-ID: <E14jMUn-0008Ts-00@mail.python.org> Si tiene una empresa en marcha, un proyecto o una idea registre su dominio en Internet AHORA, tal vez mañana sea demasiado tarde. Proteja su nombre en Internet. Si tiene ya dominio y ha de renovarlo proximamente transfiera el dominio por solo 20$ lo tendra un año renovado (esta operacion no afecta al hospedaje, solo al registrador del dominio) Si conoce a alguien en esta situacion y no sabe que regalarle regalele un dominio, es original y quedara bien. Vea toda la informacion referente al registro de dominios en http://ir-a.net/brand/ REGALE UN DOMINIO O REGISTRE EL SUYO Otros servicios: hospedaje, redireccion de dominio, ...etc ¿HAS DE RENOVAR EL REGISTRO DE TU DOMINIO? PRECIO ESPECIAL POR TRANSFERENCIA DE DOMINIO (20$ AÑO) PRECIO DE HOSTING IMBATIBLE -----------------------REMOVE------------------------------ SI NO QUIERE RECIBIR MAS MENSAJES DESDE ESTA DIRECCION VAYA AL LINK INDICADO Y SERA DADO DE BAJA INMEDIATAMENTE. DICHO LINK ES UN SERVICIO INDEPENDIENTE DEL ENVIO DE ESTE EMAIL ---------------------------------------------------------------------- dar de baja de la lista de distribucion - remove distribution list http://borrame.anexos.com RemovingNet. Cuentas gratuitas para el control de bajas. Free accounts for the control of "unsubscribes" RemovingNet nada tiene que ver con este email ni con su contenido RemovingNet nothing has to do with this email nor with contained his ---------------------------------------------------------------- IF YOU DON'T WANT TO RECEIVE MORE MESSAGES FROM US, PLEASE CLICK ON THE LINK BELOW. http://borrame.anexos.com YOUR EMAIL ADDRESS WILL BE REMOVED FROM OUR DATA BASE IMMEDIATELY. REMOVING.NET IS AN INDEPENDENT SERVICE -----------------------REMOVE------------------------------ From van@lindbergs.org Sat Mar 31 17:04:26 2001 From: van@lindbergs.org (VanL) Date: Sat, 31 Mar 2001 10:04:26 -0700 Subject: [Tutor] Timer? References: <Pine.LNX.4.21.0103301450320.8721-100000@hkn.eecs.berkeley.edu> Message-ID: <3AC60E1A.4D6A1EC2@lindbergs.org> > > ### > from Tkinter import * > > class BlinkingButton(Button): > def __init__(self, master, **kwargs): > Button.__init__(self, master, **kwargs) > self.blinkerson = 1 > self.blink() > > def blink(self): > if self.blinkerson: > self.flash() > self.after(1000, self.blink) > > if __name__ == '__main__': > root = Tk() > BlinkingButton(root, text="Blinking Button!").pack() > mainloop() > ### I was testing out what you said and this code didn't work for me. It created a button, but it didn't blink. Do you know why? Thanks, VanL From sheila@thinkspot.net Sat Mar 31 17:54:04 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 31 Mar 2001 09:54:04 -0800 Subject: [Tutor] Still confused about Python references/objects Message-ID: <5F0FF742F1D@kserver.org> Even now, there is a discussion going on in comp.lang.python on this same topic. Anyhow, I've been working with Python for a couple of months now, and reading some books and online docs, and have written a few successful scripts that I use on my website or for email management. And I THOUGHT I had figured out this Python reference stuff (with respect to objects and names that refer to them). <sigh> But I managed to confuse myself again this morning. I really like how it is not necessary to write a "swap" function in Python. The whole "swap" procedure can be accomplished in Python with a single assignment statement using tuples. I saw this type of example in Wesley Chun's _Core Python Programming_ book. However, just for illustration, I was trying to write a swap function. And, I thought that all parameters were passed by reference. So, when I ran the following interpreter session, I was really surprised to find that my swap function actually swapped nothing at all: Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.6 -- press F1 for help >>> x = 2 >>> y = 3 >>> print x, " ", y 2 3 >>> (y, x) = (x, y) >>> print x, " ", y 3 2 >>> def swap(a, b): (b, a) = (a, b) >>> swap(x, y) >>> print x, " ", y 3 2 >>> Could someone explain this to me? Why doesn't the swap function do anything? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From rick@niof.net Sat Mar 31 18:27:32 2001 From: rick@niof.net (Rick Pasotto) Date: Sat, 31 Mar 2001 13:27:32 -0500 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <5F0FF742F1D@kserver.org>; from sheila@thinkspot.net on Sat, Mar 31, 2001 at 09:54:04AM -0800 References: <5F0FF742F1D@kserver.org> Message-ID: <20010331132732.N26119@tc.niof.net> On Sat, Mar 31, 2001 at 09:54:04AM -0800, Sheila King wrote: > However, just for illustration, I was trying to write a swap function. And, I > thought that all parameters were passed by reference. So, when I ran the > following interpreter session, I was really surprised to find that my swap > function actually swapped nothing at all: > > Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.6 -- press F1 for help > >>> x = 2 > >>> y = 3 > >>> print x, " ", y > 2 3 > >>> (y, x) = (x, y) > >>> print x, " ", y > 3 2 > >>> def swap(a, b): > (b, a) = (a, b) > > >>> swap(x, y) > >>> print x, " ", y > 3 2 > >>> > > Could someone explain this to me? Why doesn't the swap function do anything? How about this: x and y are *names* given to the objects 3 and 2. Within your swap function these objects (3 and 2) have the additional names first of a and b and then of b and a. Outside your function the names of the objects have not changed. x and y are *not* the names of storage locations that can contain different values. They are the names of the values themselves. In python, when you write x = 2 you are saying that you want to refer to the value of 2 by the name x. When you then say x = x + 1 you are saying that from now on x is the name you will call the value 3 and unless the value 2 is also known by another name it (ie, the value 2) disappears. [Actually I think that, for performance reasons, small integers never *really* disappear, but conceptually they do.] -- "Disobedience is the true foundation of liberty. The obedient must be slaves." -- Henry David Thoreau Rick Pasotto email: rickp@telocity.com From tim.one@home.com Sat Mar 31 19:52:00 2001 From: tim.one@home.com (Tim Peters) Date: Sat, 31 Mar 2001 14:52:00 -0500 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <5F0FF742F1D@kserver.org> Message-ID: <LNBBLJKPBEHFEDALKOLCIEIAJJAA.tim.one@home.com> [Sheila King] > ... > However, just for illustration, I was trying to write a swap > function. And, I thought that all parameters were passed by reference. "by reference" isn't really a useful concept in Python. People bring that with them from other languages, and get into all sorts of trouble trying to force it to fit. Python is *simpler* than that. It's easier (in the end <wink>) to think of argument-passing in Python as being "pass by object": don't think of passing names, or pointers, or references, or even values, but think of passing objects directly. When you do f(x), f is passed the precise object to which the name "x" refers at the time. f doesn't see the *name* "x", nor does it get a copy of the value of the object x refers to, it gets the exact object x refers to at the time. The other half of the story is that a statement of the form x = y is *not* an operation on objects, it's an operation on namespaces, and all it means is "whatever object the name 'y' refers to at this moment, also give that object the name 'x' (and in the local namespace, provided 'x' hasn't been declared global)". Argument passing is exactly like x = y in all respects: the objects in the argument list are merely given names in the called function's local namespace. The names they're given are, of course, the function's formal argument names. > So, when I ran the following interpreter session, I was really > surprised to find that my swap function actually swapped nothing at all: Oh, but it did -- just not where you thought <wink>. > Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.6 -- press F1 for help > >>> x = 2 > >>> y = 3 > >>> print x, " ", y > 2 3 > >>> (y, x) = (x, y) > >>> print x, " ", y > 3 2 > >>> def swap(a, b): > (b, a) = (a, b) > > >>> swap(x, y) Calling "swap(x, y)" has two effects at the start: 1. Attaches the name 'a' in swap's local namespace to the object named by 'x' in the call (which is the integer object 3). 2. Attaches the name 'b' in swap's local namespace to the object named by 'y' in the call (which is the integer object 2). So the body of swap begins life with two local names, a and b, exactly as if the lines a = 3 b = 2 had appeared in its body. These have *nothing* to do with the names 'x' and 'y' in the caller anymore -- the names x and y don't live in swap's lcoal namespace, and assignments within swap can only affect swap's local namespace. So the (b, a) = (a, b) line does swap what the names "a" and "b" refer to in *swap's* local namespace, but, again, that has nothing to do with any other namespace, and in particular has nothing to do with the caller's namespace. Unless you engage in deep trickery, this is a reliable rule: a call to a function cannot change any bindings in the caller's namespace: if the local (wrt the caller) name 'x' was bound to an object O before a call, it will remain bound to O after the call, period. Now it's possible that O is an object of a mutable type, in which case the call may *mutate* O, but 'x' remains bound to (the mutated) O even then. it's-too-simple-to-fully-grasp-at-first<wink>-ly y'rs - tim From bsass@freenet.edmonton.ab.ca Sat Mar 31 20:25:04 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Sat, 31 Mar 2001 13:25:04 -0700 (MST) Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <5F0FF742F1D@kserver.org> Message-ID: <Pine.LNX.4.33.0103311306250.7534-100000@bms> On Sat, 31 Mar 2001, Sheila King wrote: <...> > Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.6 -- press F1 for help > >>> x = 2 > >>> y = 3 > >>> print x, " ", y > 2 3 > >>> (y, x) = (x, y) > >>> print x, " ", y > 3 2 > >>> def swap(a, b): > (b, a) = (a, b) You are assigning inside a function, which creates local variables... > >>> swap(x, y) > >>> print x, " ", y > 3 2 > >>> > > Could someone explain this to me? Why doesn't the swap function do anything? ...so "x" and "y" are not the same as "a" and "b", and neither "a" or "b" ever get out of the function to affect anything. - Bruce From cdwom@mpinet.net Sat Mar 31 20:52:35 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Sat, 31 Mar 2001 15:52:35 -0500 Subject: [Tutor] Text Editor focus() help Message-ID: <005d01c0ba24$856435e0$d8dc35d8@KellyJoW> I'm trying to get my text editor to open a document in a new toplevel widget if the current widget contains text. It works fine but the focus sometimes reverts back to the previous window (and then sometimes it doesn't). How can I make sure that the new window always receives the focus? Here is my code: (its 142 lines long. I hope this doesn't offend anyone... I don't think it will after reading the posting scripts thread, but it still seems a bit edgy. If This is too long please tell me, and if you notice any other errors, please point them out to me too :) Thanks Corey from Tkinter import * from ScrolledText import * import tkMessageBox from tkFileDialog import * import MDI import fileinput import string editorList = [] root = None def die(): sys.exit(0) def about(): tkMessageBox.showinfo("PythonPadTk", "PythonPadTk v0.0\n" "Based on Tkeditor 1.0 from:\n" "For Teach Yourself Python in 24 Hours") class statusBar(Frame): def __init__(self, master): Frame.__init__(self, master) self.label = Label(self, bd=1, relief=SUNKEN, anchor=W) self.label.pack(fill=X) def set(self, format, *args): self.label.config(text=format % args) self.label.update_idletasks() def clear(self): self.label.config(text="") self.label.update_idletasks() class editor: def __init__(self, rt): if rt == None: self.window = Tk() else: self.window = Toplevel(rt) self.window.title("PythonPadTk - Untitled") self.bar = Menu(self.window) self.fileName = None self.filem = Menu(self.bar) self.filem.add_command(label="New window", underline=0, command=newEditor) self.filem.add_command(label="Open...", underline=0, command=self.openFile) self.filem.add_command(label="Save", underline=0, command=self.saveFile) self.filem.add_command(label="Save As...", underline=5, command=self.saveAsFile) self.filem.add_command(label="Close", underline=0, command=self.close) self.filem.add_separator() self.filem.add_command(label="Exit", underline=0, command=die) self.helpm = Menu(self.bar) self.helpm.add_command(label="About", underline=0, command=about) self.bar.add_cascade(label="File", underline=0, menu=self.filem) self.bar.add_cascade(label="Help", underline=0, menu=self.helpm) self.window.config(menu=self.bar) self.f = Frame(self.window,width=512) self.f.pack(side=TOP, expand=1, fill=BOTH) self.sbf = Frame(self.window,width=512) self.sbf.pack(side=BOTTOM, expand=0, fill=X) self.status = statusBar(self.sbf) self.status.pack(side=LEFT, fill=X, expand=1) self.st = ScrolledText(self.f,background="white",font="System") self.st.pack(side=LEFT, fill=BOTH, expand=1) self.statusCol = statusBar(self.sbf) self.statusCol.pack(side=RIGHT) self.statusCol.set("Col: ?") self.statusLine = statusBar(self.sbf) self.statusLine.pack(side=RIGHT) self.statusLine.set("Ln: ?") self.st.bind('<KeyRelease>', self.setLineCol) self.st.bind('<ButtonRelease>', self.setLineCol) self.st.after_idle(self.setLineCol) def setFilename(self, fileName): self.fileName = fileName self.saved = 1 def setLineCol(self, event=None): line, column = string.split(self.st.index(INSERT), '.') self.statusLine.set("Ln: "+ line) self.statusCol.set("Col: "+ column) def close(self): self.window.destroy() def openFile(self): pl = END oname = askopenfilename(filetypes=[("Text files", "*.txt")]) if len(self.st.get(1.0,END)) == 1: if oname: for line in fileinput.input(oname): self.st.insert(pl,line) self.window.title("PythonPadTk - "+oname) else: if oname: newEditor() editorList[len(editorList)-1].window.focus() for line in fileinput.input(oname): editorList[len(editorList)-1].st.insert(pl,line) editorList[len(editorList)-1].window.title("PythonPadTk - "+oname) editorList[len(editorList)-1].window.focus() def saveAsFile(self): sname = asksaveasfilename() if sname: ofp = open(sname,"w") ofp.write(self.st.get(1.0,END + "-1c")) ofp.flush() ofp.close() self.setFilename(sname) self.saved = 1 self.window.title("PythonPadTk - "+sname) def saveFile(self): if not self.fileName: self.saveAsFile() else: ofp = open(self.fileName,"w") ofp.write(self.st.get(1.0,END + "-1c")) ofp.flush() ofp.close() def newEditor(): global root editorList.append(editor(root)) if __name__ == "__main__": root = None editorList.append(editor(root)) root = editorList[0].window root.mainloop() From Aaron.Mathews@Gentner.COM Sat Mar 31 17:21:36 2001 From: Aaron.Mathews@Gentner.COM (Aaron Mathews) Date: Sat, 31 Mar 2001 10:21:36 -0700 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: <200103301436.JAA23470@scott.zenplex.com>; from scott@zenplex.com on Fri, Mar 30, 2001 at 09:38:49AM -0500 References: <200103301436.JAA23470@scott.zenplex.com> Message-ID: <20010331102136.D4184@gandalf> On Fri, Mar 30, 2001 at 09:38:49AM -0500, Scott Ralph Comboni wrote: > Does anyone now if there is a bugtracking tool like bugzilla written in > Python? Not that I know of. Bugzilla is one on a *very* short list of open source bugtracking systems. I personally would love to see bugzilla reimplemented in python, it would be a heck of a lot easier to customize (which I unfortunately have had to do during the last few weeks). Modifying squirrely perl code is not exactly my idea of fun. But then again, bugzilla works better than any of the alternatives I've seen, so that's the way it goes. Regards, -- Aaron Mathews work: Aaron.Mathews@Gentner.COM - http://gentner.com/ play: Aaronm@Hobbiton.ORG - http://pukka.dyndns.org/ From aichele@mindspring.com Sat Mar 31 07:03:34 2001 From: aichele@mindspring.com (Steve A.) Date: Fri, 30 Mar 2001 23:03:34 -0800 Subject: [Tutor] installing python 2.0 on redhat 7.0 Message-ID: <000b01c0b9b0$b4aea160$7001a8c0@sagga> This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C0B96D.A5C1F6E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello. =20 Seems that to install python 2.0 on redhat 7 I'll need to reinstall = glibc.. well, basically, considering all the file dependencies,=20 it's just not worth it. I'm wondering if anyone has installed python = 2.0 or 2.1 on redhat 7, and if there are any RPMS out there to make it a relatively painless process. Otherwise it looks like I'm going to = have to go back to 6.2. argh! -Steve ------=_NextPart_000_0008_01C0B96D.A5C1F6E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hello. </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Seems that to install python 2.0 on = redhat 7 =20 I'll need to reinstall glibc.. well, basically, considering all the file = dependencies, </FONT></DIV> <DIV><FONT face=3DArial size=3D2>it's just not worth it. I'm = wondering if=20 anyone has installed python 2.0 or 2.1 on redhat 7, and if there are any = RPMS=20 out there to make</FONT></DIV> <DIV><FONT face=3DArial size=3D2>it a relatively painless process. = Otherwise=20 it looks like I'm going to have to go back to 6.2. = argh!</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-Steve</FONT></DIV></BODY></HTML> ------=_NextPart_000_0008_01C0B96D.A5C1F6E0--