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: 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: 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
Just=20 reverse the assignment line
 
 
temperature =3D input("What is the = temperature of the=20 spam?")
 
    ~c
-----Original Message-----
From: = tutor-admin@python.org=20 [mailto:tutor-admin@python.org]On Behalf Of Katharine=20 Stoner
Sent: Wednesday, February 28, 2001 6:55 = PM
To:=20 python tutor
Subject: [Tutor] what's wrong with this=20 code

What's wrong with this code?  I=20 don't understand. Please help.
 
input("What is the temperature of the = spam?") =3D=20 temperature
 
    if temperature = >=20 50:
        print "The salad is = properly=20 cooked."
   =20 else:
        print "Cook the = salad some=20 more."
 
-Cameron=20 Stoner
------=_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
What's wrong with this code?  I=20 don't understand. Please help.
 
input("What is the temperature of the = spam?") =3D=20 temperature
 
    if temperature >=20 50:
        print "The salad is = properly=20 cooked."
   =20 else:
        print "Cook the = salad some=20 more."
 
-Cameron = Stoner
------=_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: > 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
Hi,
 
day =3D input("On a scale of 1 to 10, = how was your=20 day?")
if day =3D=3D (fine):
#used double equals to make=20
    fine =3D "The salad is properly=20 cooked."
    print fine
else:
    = print=20 "Cook the salad some more."
 

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.
 
-Cameron = Stoner
------=_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: Message-ID: 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) > > > > > >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: 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
Hi,
 
day =3D input("On a scale of 1 to 10, = how was your=20 day?")
 
if day =3D=3D fine:
#used double = equals to=20 make    
    print "The salad is = properly=20 cooked."
else:
    print "Cook the salad some=20 more."
 
 
------=_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: 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: 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: 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 : > 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: 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: Message-ID: > > 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: 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: Message-ID: 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: Message-ID: 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 "", 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: 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: 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 , 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 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: Message-ID: 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: 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: References: <3439F4C6B44@kserver.org> Message-ID: <3994B4748A4@kserver.org> On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse 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: On Thu, 1 Mar 2001, Sheila King wrote: > On Thu, 1 Mar 2001 23:13:57 -0800 (PST), Deirdre Saoirse > 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: 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: 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: 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 >>> x.wm_iconmask =20 ### 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" To: 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: > 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: Message-ID: 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 > To: Sheila King > cc: > 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 > To: Deirdre Saoirse > Cc: > 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 > 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 > To: Sheila King > cc: > 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 >> >> 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 > 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 > To: Arthur Watts > cc: "'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 > 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 > To: "INTERNET: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 > 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 > 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 > To: Sharriff Aina > cc: "INTERNET: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 > >>>> x.wm_iconmask =20 > > ### > > > 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 > 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" > To: > Subject: Re: [Tutor] Database connectivity > Date: Fri, 2 Mar 2001 09:45:07 -0600 > > ----- Original Message ----- > From: "GCS" > To: > 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 > 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: > >> 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: 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 > > To: Sheila King > > cc: > > 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 > > To: Deirdre Saoirse > > Cc: > > 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 > > 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 > > To: Sheila King > > cc: > > 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 > >> > >> 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 > > 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 > > To: Arthur Watts > > cc: "'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 > > 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 > > To: "INTERNET: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 > > 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 > > 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 > > To: Sharriff Aina > > cc: "INTERNET: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 > > > >>>> x.wm_iconmask =20 > > > > ### > > > > > > 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 > > 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" > > To: > > Subject: Re: [Tutor] Database connectivity > > Date: Fri, 2 Mar 2001 09:45:07 -0600 > > > > ----- Original Message ----- > > From: "GCS" > > To: > > 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 > > 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: > > > >> 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
I'm a python newbie and I = have been going=20 through Mr. Gauld's book and have a question.
 
Following an exercise to understand = loops, the=20 following came about:
 
for i in range(2, = 13):
    for j=20 in range(1, 13):
        if i =3D=3D 2 = and j =3D=3D=20 1:
            print=20 "---------------------------------- "
    =    =20     print "This table is the",i,"multiple=20 table"
            print = "---------------------------------- "
    =    =20 print "%d x %d =3D %d" % (j, i, j * i)
    if i =3D=3D = 12:
        break
    = print=20 "---------------------------------- "
    print "This = table is=20 the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Which works fine.
 
However, when I add user input to let = the range be=20 dependant on this input like this:
 
multiplier =3D input("Which mulitplier = value do you=20 want to use? ")
for i in range(2, multiplier + = 1):
    for=20 j in range(1, multiplier + 1):
        = if i =3D=3D=20 2 and j =3D=3D 1:
        =     print=20 "---------------------------------- "
    =    =20     print "This table is the",i,"multiple=20 table"
            print = "---------------------------------- "
    =    =20 print "%d x %d =3D %d" % (j, i, j * i)
    if i =3D=3D = multiplier:
        = break
   =20 print "---------------------------------- "
    print = "This=20 table is the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Using any input just returns to a = prompt in=20 'idle'.
 
Any help will be = appreciated.
 
Thanks,
------=_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: > 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: 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 " without the quotes, = where is python20 in this case. Then just type "python " 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
 
  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).
  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 :)
  You change directories by typing "dir <dirname>" = without the=20 quotes, where <dirname> is python20 in this case.
  Then just type "python <scriptname>" to run the = script. =20 Don't forget the .py at the end of the filename :)
 
  Cya,
  Glen.
 
 
 
----- Original Message -----
From:=20 Marty = Pitts=20
Sent: Saturday, March 03, 2001 = 6:52=20 AM
Subject: [Tutor] Loops and User = Input

I'm a python newbie and I = have been=20 going through Mr. Gauld's book and have a question.
 
Following an exercise to understand = loops, the=20 following came about:
 
for i in range(2, = 13):
    for=20 j in range(1, 13):
        if i = =3D=3D 2 and j =3D=3D=20 1:
            print=20 "---------------------------------- "
    =    =20     print "This table is the",i,"multiple=20 table"
            = print=20 "---------------------------------- "
    =    =20 print "%d x %d =3D %d" % (j, i, j * i)
    if i = =3D=3D=20 12:
        = break
    print=20 "---------------------------------- "
    print = "This table=20 is the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Which works fine.
 
However, when I add user input to let = the range=20 be dependant on this input like this:
 
multiplier =3D input("Which = mulitplier value do you=20 want to use? ")
for i in range(2, multiplier + = 1):
   =20 for j in range(1, multiplier + 1):
    =     if=20 i =3D=3D 2 and j =3D=3D 1:
        =    =20 print "---------------------------------- "
   =20         print "This table is = the",i,"multiple=20 table"
            = print=20 "---------------------------------- "
    =    =20 print "%d x %d =3D %d" % (j, i, j * i)
    if i = =3D=3D=20 multiplier:
       =20 break
    print "----------------------------------=20 "
    print "This table is the",i + 1 ,"multiple=20 table"
    print "---------------------------------- = "
 
Using any input just returns to a = prompt in=20 'idle'.
 
Any help will be = appreciated.
 
Thanks,
------=_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: 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: 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" 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" 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" To: 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: 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: 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) ### 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: 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: 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: >From: Jörg Wölke >To: "Britt Green" >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) >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 " without the quotes, = where is python20 in this case. Then just type "python " 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
Much to my embarrassment, this script = works for me=20 if I run it at the command prompt and not in idle.
 
Though my primary platform is linux and = not=20 windows. 
 
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.
 
Thanks for the comments.
----- Original Message -----
From:=20 Glen = Wheeler
Sent: Friday, March 02, 2001 = 1:32=20 PM
Subject: Re: [Tutor] Loops and = User=20 Input

 
  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).
  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 :)
  You change directories by typing "dir <dirname>" = without the=20 quotes, where <dirname> is python20 in this case.
  Then just type "python <scriptname>" to run the=20 script.  Don't forget the .py at the end of the filename :)
 
  Cya,
  Glen.
 
 
 
----- Original Message -----
From:=20 Marty = Pitts=20
Sent: Saturday, March 03, = 2001 6:52=20 AM
Subject: [Tutor] Loops and = User=20 Input

I'm a python newbie and I = have been=20 going through Mr. Gauld's book and have a question.
 
Following an exercise to understand = loops, the=20 following came about:
 
for i in range(2, = 13):
   =20 for j in range(1, 13):
        if i = =3D=3D 2=20 and j =3D=3D 1:
        =    =20 print "---------------------------------- "
   =20         print "This table is = the",i,"multiple=20 table"
            = print=20 "---------------------------------- "
   =20     print "%d x %d =3D %d" % (j, i, j *=20 i)
    if i =3D=3D 12:
   =20     break
    print=20 "---------------------------------- "
    print = "This=20 table is the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Which works fine.
 
However, when I add user input to = let the range=20 be dependant on this input like this:
 
multiplier =3D input("Which = mulitplier value do=20 you want to use? ")
for i in range(2, multiplier +=20 1):
    for j in range(1, multiplier +=20 1):
        if i =3D=3D 2 and j = =3D=3D=20 1:
            print = "---------------------------------- "
   =20         print "This table is = the",i,"multiple=20 table"
            = print=20 "---------------------------------- "
   =20     print "%d x %d =3D %d" % (j, i, j *=20 i)
    if i =3D=3D = multiplier:
   =20     break
    print=20 "---------------------------------- "
    print = "This=20 table is the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Using any input just returns to a = prompt in=20 'idle'.
 
Any help will be = appreciated.
 
Thanks,
------=_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 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-- 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: 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: 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: Message-ID: 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: Message-ID: 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 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) >>> 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 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) : :>>> 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) >>> 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 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) : :>>> 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: > Hello: > I need to be able to test the type of a variable: > Consider the following code: > # code begins > >>> str = 'hello' > >>> type(str) > > >>> 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(mysillywalk) >>> 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: 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: 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: On Sat, 3 Mar 2001, Tim Johnson wrote: > Consider the following code: > # code begins > >>> str = 'hello' > >>> type(str) > > >>> 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) == "" 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: 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 To: Danny Yoo 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: 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: 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: 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 . 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: Message-ID: <03a501c0a483$ea891fa0$0300a8c0@arthur> 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 "", 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 "", 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: 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) 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: > >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) > Similarly, >>> types.TypeType >>> x = None >>> for i in range(5): ... x = type(x) ... print x ... >>> 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
Hi all,
 
Does anyone know of a good scource on = how to design=20 programs before you start programming?
 
-Cameron = Stoner
------=_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: 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: > (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) == "" > > 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: <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 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) > > ### > > 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: 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"
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-- 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: 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: 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
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
------=_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" 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-- 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

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...
 
------------------------------------------------------------= ---
Sent: Sunday, March 04, 2001 3:21 PM
Subject: Re: [Tutor] software design

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...
 
Jay D.
------------------------------------------------------------= ---
----- Original Message -----
From:=20 alan.gauld@bt.com
To: kstoner@netins.net ; tutor@python.org=20
Sent: Sunday, March 04, 2001 = 12:12=20 PM
Subject: RE: [Tutor] software=20 design

Does anyone know of a good = scource on how=20 to design programs before you start programming?  
 
Short answer is no. I have a chapter in my = book=20 called "Designing a solution"
but even it is really just some things to = think=20 about. Its really hard to describe
the creative processes involved in = converting an idea=20 to an algorithm and hence
to a program. There are a few books on = Problem=20 Solving that try to do thast
but none do it well=20 IMHO.
 
Going down a level there are a few that = describe ways=20 of documenting
solutions using various notations. But that = doesn't=20 help you actually come
up with a design, just how ton write your = thoughts=20 down...
 
Alan=20 G.
------=_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: 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: 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: 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
From:=20 alan.gauld@bt.com
Sent: Sunday, March 04, 2001 = 9:16=20 AM
Subject: RE: [Tutor] Loops and = User=20 Input

HI,=20 Glad to see you are working thru' the book. Your example looks fine=20
to=20 me and the fact that you have elaborated on the version on the book=20
is=20 excellent. That's by far the best way to learn.
 
Just=20 in case you haven't seen it there is an errata page = at:
 
http://www.cro= sswinds.net/~agauld/book/errata.htm
 
And=20 there are direct mail links to me there too.
 
    Thanks, I appreciate the = pointer.
 
But=20 I can't see any immediate problems in your code other than the ones=20
Danny Yoo pointed out with strangeness = using low=20 multipliers.
 
However I couldn't help adding a few = "thought=20 provoking" comments :-)
 
multiplier =3D input("Which = mulitplier value do=20 you want to use? ")
for i in range(2, multiplier +=20 1):
    for j in range(1, multiplier + = 1):
 
Are you sure you want this? If you use a = multiplier=20 of say 20 you will get
all of the tables from 2 to 20=20 times.
BUT they will also have all the elements = from 1 to=20 20!
I=20 suspect you want to make the second range be (1,13) to get the 1 to = 12=20 values?
 
    I noticed this.  = I am=20 thinking about modifying the input for the user to be able to have = choice=20 for both variables.
 
Just a thought.
 
      &nb= sp; =20 if i =3D=3D 2 and j =3D=3D 1:
    =    =20     print "----------------------------------=20 "
            print = "This=20 table is the",i,"multiple table"
    =    =20     print "---------------------------------- " 
 
So this only prints for the first time round = since i is=20 only 2 once.
Assuming you want the caption for every table I = think you only=20
need to check for=20 j=3D=3D1? 
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.
 
      &nb= sp; =20 print "%d x %d =3D %d" % (j, i, j * i)
    if i = =3D=3D=20 multiplier:
        break
 
Oooh! Now I never wrote about break=20 :-)
Where did you find that=20 trick?
Yours is not the only book on Python = that I own.=20 :-) However, I find it a good one for my=20 pace.
But it will throw you out of the loop one = iteration=20 before I think you want to?
After all, you used multiplier+1 in the = initial=20 range. This will somewhat deeat the
purpose of that won't=20 it?
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.
    print=20 "---------------------------------- "
    print = "This=20 table is the",i + 1 ,"multiple table"
    print=20 "---------------------------------- "
 
Using any input just returns to a = prompt in=20 'idle'.
 
Don't understand why that is tho'...
 
Alan G.
Thanks for your=20 critique. If you spot any errors in = my=20 reasonings above, please feel free to point them=20 out.
 
Regards,
 
Marty.
------=_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: 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: Message-ID: 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: 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
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.
 
TIA,

Jay D
------=_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"
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-- 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: Message-ID: 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: > 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 (, ) on the widget, but the classes bindings would still be there. How I've removed them is: master.unbind_class("Text", "") master.unbind_class("Text", "") master.unbind_class("Text", "") 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 -- ------------------------------------------------------------------------ | 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: > 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
Alan Gauld wrote:
 
This works best if you are checkjing for type several
times since = the=20 import overhead only gets called once.
 
> >     type(mystr) =3D=3D type("")
 
This is better if you only do it once since the extra
function = call is=20 probably faster than importing the
type module.
 
______
 
Am I misunderstanding something?
 
If you enter:  "import type" and hit return, are you not = adding=20 only a pointer to the file 'type.py'?
 
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.
 
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!
 
So what's the Overhead for this?
 
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. 
 
Stevenson Hickey
 
 
----__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: Message-ID: <01030508034900.01151@shecom> Hi Michael: On Mon, 05 Mar 2001, Michael P. Reilly wrote: > > 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 (, ) on the > widget, but the classes bindings would still be there. > > How I've removed them is: > master.unbind_class("Text", "") > master.unbind_class("Text", "") > master.unbind_class("Text", "") > 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: 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: > Hi Michael: > On Mon, 05 Mar 2001, Michael P. Reilly wrote: > > > > > 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 (, ) on the > > widget, but the classes bindings would still be there. > > > > How I've removed them is: > > master.unbind_class("Text", "") > > master.unbind_class("Text", "") > > master.unbind_class("Text", "") > > 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"
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-- 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: 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: 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: Message-ID: 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: References: 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: 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: ; from arcege@shore.net on Mon, Mar 05, 2001 at 07:59:41AM -0500 References: <20010305131709.A7316@pino.selwerd.nl> 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: <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: 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: ; from Sascharrer@aol.com on Sun, Mar 04, 2001 at 01:38:25AM -0500 References: 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: 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: ; from britt_green@hotmail.com on Mon, Mar 05, 2001 at 03:43:00AM -0800 References: 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: <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" To: 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: ; from arcege@shore.net on Mon, Mar 05, 2001 at 07:06:31AM -0500 References: <01030409325106.04879@shecom> 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"
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-- 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 To: Remco Gerlich 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: [, ] 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: > > [, 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: > > [, 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: 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: > > [, 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, > [, 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: > > [, 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: 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: 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 CAN Admin 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: 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 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: 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: Message-ID: 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: 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: 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: 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: 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: 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: 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: >Message: 11 >Date: Tue, 6 Mar 2001 21:19:31 -0800 (PST) >From: Daniel Yoo >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: >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: ; from britt_green@hotmail.com on Tue, Mar 06, 2001 at 11:13:10PM -0800 References: Message-ID: <20010307010710.A392@bigskytel.com> * 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 #--- 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: ; from britt_green@hotmail.com on Tue, Mar 06, 2001 at 11:13:10PM -0800 References: 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: ; from gruschow2@hotmail.com on Wed, Mar 07, 2001 at 12:46:23AM -0600 References: 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: Message-ID: 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: 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: from Britt Green at "Mar 6, 2001 11:13:10 pm" Message-ID: > > >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
What is a data flow model?
 
-Cameron = Stoner
------=_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"
Hi there!
 
How can I change the small Tk icon in = the upper=20 left corner of a frame (made by tkinter)?
 
Thanks for your help
 
------=_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 //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', '/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: .call('winico', 'setwindow', ._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
Greetings J=F6rg & All,
 
Currently this is possible for some people but not = for=20 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=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 = http://ftp.bj-ig.de/pub/tcltk/  I=20 think the latest version is winico31.zip
 
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.
 
You can use the standard Tcl load command to = get around=20 this like so:
    % load <path to where you put=20 it>//winico03.dll
 
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.
 
From there you'd use notation something like this, = though I've=20 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=20 it:
    Tk.call('load', '<path to = where you put=20 it>/winico03.dll')
 
I've tried this and it gives me the same page = fault. =20 Others have claimed to get it to work though.
 
If you're able to successfully load it, something = like this=20 could set the icon:
    <Your main window=20 name>.call('winico', 'setwindow', <Your main window name>._w,=20 Icon)
where you've already loaded an image into = Icon.
 
Well, good luck if you try this anyone.  If = someone finds=20 a way to fix the page faults, please let me know.
 
 
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.
 
I'm going to be patient and wait...
 
 
Good luck,
Sam
 
Hi there!
 
How can I change the small Tk icon in = the upper=20 left corner of a frame (made by tkinter)?
 
Thanks for your help
 
------=_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: 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: 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: 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("