From dis_gus_ted@my-deja.com Thu Feb 1 08:05:25 2001 From: dis_gus_ted@my-deja.com (First Name Last Name) Date: Thu, 1 Feb 2001 00:05:25 -0800 Subject: [Tutor] Newbie question re: user interaction Message-ID: <200102010805.AAA10776@mail14.bigmailbox.com> Hello, I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? 10 INPUT "What is your name?" N$ 20 PRINT "Hello, " N$ "!" This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! Thanks very much for any help, Gus Hungerford. ------------------------------------------------------------ --== Sent via Deja.com ==-- http://www.deja.com/ From conways5@earthlink.net Thu Feb 1 03:30:09 2001 From: conways5@earthlink.net (The Conways) Date: Wed, 31 Jan 2001 19:30:09 -0800 Subject: [Tutor] Path problems python 2.0 Message-ID: <011801c08bff$49b08380$25dbaec7@kitchen> To set the path in Win98k, I used SET PYTHONPATH=C:\PYTHON20\MYPYTHON in the autoexec.bat. It worked and I am able to use import prog.py. Next I tried to execute commands from the MS-DOS command prompt. I used SET PATH=C:\PYTHON20;%PATH% in the autoexec.bat. At the C prompt I typed in: python hello.py, I received the following error message from dos: C:\PYTHON20\PYTHON.EXE: can't open file 'hello.py. Next I tried typing python from the C prompt and it did start the PYTHON command prompt. By the way Alan Gauld's book, "Learning to Program Using Python" is excellent for beginners. Now for a Linux question. Python 1.52 came with our Mandrake 7.2 installation. So I am also learning some linux as well as python. My question is where do you keep your py scripts in Linux, the file system is so organized that I am not really sure where to put things. From bsass@freenet.edmonton.ab.ca Thu Feb 1 18:22:49 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Thu, 1 Feb 2001 11:22:49 -0700 (MST) Subject: [Tutor] NEWBIE!! pipes In-Reply-To: <50.10cfb61b.27a9e306@aol.com> Message-ID: On Wed, 31 Jan 2001 AquaRock7@aol.com wrote: > What are pipes? The docs barely touched this subject, it assumed you already > knew what they are... From context I am gathering that it is a connection to > the kernel? (maybe?) How can I utilize this? A "pipe" is a connection between two programs, from the stdout of one to the stdin of another. On a unix command line you would write it as: prog1 | prog2 | prog3 Which would pipe the output of prog1 to the input prog2, etc. > 1 more quickie: > >if __name__ == '__main__': > > main() > > what is the pourpose if the above code? It runs the sub main() (duh :) but, > why not just main() wihtout the if? what is the conditional testing for? > and what are the variables __main__ and __name__? i dont believe they are > defined in the program, so just what are they? and, what does putting "__" > around a variable actually DO besides look cool ? Ya, cool, until you try to read it done in a proportional font and can't tell how many underscores are present. anyways... When Python is executing the mainline of a program __name__ has the value "__main__", so, the above snippet would only execute the main() routine if the code was being executed as part of the mainline of a program. i.e., doing "python snippet" would execute main(), doing "import snippet" from within a Python program would not. It tends to be used it like this... ----- module: snip2 class C1: ... class C2: ... def f1: .... def main(): # class and function test routine if __name__ == "__main__": main() ----- When I want to test what I'm woring on I do "^C^C" to execute the buffer, __name__ == "__main__" and the test code is run; when a prg imports the finished module the test code is ignored. The prog doing the importing could also do a "snip2.main()" to run the test code. HTH later, Bruce From kalle@gnupung.net Thu Feb 1 18:51:36 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 1 Feb 2001 19:51:36 +0100 Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500 References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: <20010201195136.A463@apone.network.loc> --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Seelinger, Bruce: > Another question from someone totally new to Python. Is there an equivale= nt > in Python to a sub-routine, (e.g. gosub and return). I want to create a A function. [snip] > best) way to do this is with modules? A function works but the values > obtained within the function do not appear to be valid outside of that > function. I guess I am looking for the best approach to create the No. That's a feature. Global variables are often a bad idea and make programs more difficult to understand, especially when they grow larger. Use class instance methods and variables or plain old return values. Note: If you really, really want, use the "global" statement: >>> a =3D 0 >>> def f(val): =2E.. global a =2E.. a =3D val =2E..=20 >>> print a 0 >>> f(12) >>> print a 12 >>>=20 But don't blame me if you don't understand your own programs three months from now... I suggest you read http://www.crosswinds.net/~agauld/ http://www.ibiblio.org/obp/thinkCSpy/ http://www.python.org/doc/current/tut/ Especially the parts about functions, modules, classes and object oriented programming. 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 --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 iD8DBQE6ebA4dNeA1787sd0RAhDcAKCSRsGjb4wy5SxHxbU/bxw4lnyedQCgybTz UTMtlqPmdF7dsKRe2TDy6Rg= =Sj6q -----END PGP SIGNATURE----- --Dxnq1zWXvFF0Q93v-- From deirdre@deirdre.net Thu Feb 1 17:54:04 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Feb 2001 09:54:04 -0800 (PST) Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: On Wed, 31 Jan 2001, Seelinger, Bruce wrote: > Another question from someone totally new to Python. Is there an > equivalent in Python to a sub-routine, (e.g. gosub and return). There are functions. > I want to create a modular program with sub-routines to perform > distinct tasks wihin the program for organizational and debugging > purposes, etc. Is the only (or best) way to do this is with modules? No. As I said, there are also functions. > A function works but the values obtained within the function do not > appear to be valid outside of that function. I guess I am looking for > the best approach to create the subroutines for execution from the > main flow of the program. Good coding design says that that's the way it should be. Functions should only change what's inside them, not stuff that may have Unintended Consequences (tm). Clearly, you learned Basic first and early versions of Basic (sorry, I haven't used the language in 26 years...) didn't have local scoping as that was difficult to implement and its advantages were not yet appreciated. I believe Pascal was the first widely-used language to use local scoping. _Deirdre From deirdre@deirdre.net Thu Feb 1 17:56:55 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Feb 2001 09:56:55 -0800 (PST) Subject: [Tutor] NEWBIE!! pipes In-Reply-To: <50.10cfb61b.27a9e306@aol.com> Message-ID: On Wed, 31 Jan 2001 AquaRock7@aol.com wrote: > What are pipes? The docs barely touched this subject, it assumed you > already knew what they are... From context I am gathering that it is > a connection to the kernel? (maybe?) How can I utilize this? A pipe connects the output of one Unix process to the input of the next one. Sort of like "send this data through this pipe to here." It has nothing to do with the kernel per se and isn't generally used within a program. > 1 more quickie: > >if __name__ == '__main__': > > main() > > what is the pourpose if the above code? It runs the sub main() (duh > :) but, why not just main() wihtout the if? what is the conditional > testing for? and what are the variables __main__ and __name__? i > dont believe they are defined in the program, so just what are they? > and, what does putting "__" around a variable actually DO besides > look cool ? This means that if the file is invoked directly from the command line, it knows what to do. Otherwise, if well-designed and all in functions, how's it going to know which one to call? The __ around the variable means that it's a built-in function or variable (as in built-in to Python). _Deirdre From deirdre@deirdre.net Thu Feb 1 18:06:28 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Feb 2001 10:06:28 -0800 (PST) Subject: [Tutor] square root In-Reply-To: <3A787FD0.4CD22F54@wxs.nl> Message-ID: On Wed, 31 Jan 2001, W.W. van den Broek wrote: > How do you use the > square root as operator > in python? > Dumb question, but > thanks anyway, import math math.sqrt(25) Or... from math import sqrt a = sqrt(25) _Deirdre From arcege@shore.net Thu Feb 1 18:15:20 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 1 Feb 2001 13:15:20 -0500 (EST) Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> from "Seelinger, Bruce" at Jan 31, 2001 05:12:29 PM Message-ID: <200102011815.NAA11489@northshore.shore.net> > > This message is in MIME format. Since your mail reader does not understand > this format, some or all of this message may not be legible. > > ------_=_NextPart_001_01C08BD2.E6AD3D40 > Content-Type: text/plain; > charset="iso-8859-1" > > Hello, > > Another question from someone totally new to Python. Is there an equivalent > in Python to a sub-routine, (e.g. gosub and return). I want to create a > modular program with sub-routines to perform distinct tasks wihin the > program for organizational and debugging purposes, etc. Is the only (or > best) way to do this is with modules? A function works but the values > obtained within the function do not appear to be valid outside of that > function. I guess I am looking for the best approach to create the > subroutines for execution from the main flow of the program. There sure are. You would either use the "def" statement or the "lambda" expression to create a subroutine/procedure/function. >>> def WhatsMyLine(name, message): ... print name, 'said', repr(message) ... >>> WhatsMyLine('Arcege', "Spam, Spam, Eggs and Spam") Arcege said 'Spam, Spam, Eggs and Spam' >>> is_odd = lambda n: (n % 2) == 1 >>> is_odd(3) 1 >>> is_odd(4), is_odd(5) (0, 1) >>> I would suggest that you read the Python tutorial; it could help you a lot with your questions. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Thu Feb 1 18:29:01 2001 From: arcege@shore.net (Michael P. Reilly) Date: Thu, 1 Feb 2001 13:29:01 -0500 (EST) Subject: [Tutor] NEWBIE!! pipes In-Reply-To: <50.10cfb61b.27a9e306@aol.com> from "AquaRock7@aol.com" at Jan 31, 2001 04:52:06 PM Message-ID: <200102011829.NAA16195@northshore.shore.net> > What are pipes? The docs barely touched this subject, it assumed you already > knew what they are... From context I am gathering that it is a connection to > the kernel? (maybe?) How can I utilize this? Pipes are a feature of the operating system, not of Python; and then, mostly in POSIX operating systems. They are often used to connect the output of one process to the input of another. For example on MS-DOG, it is common to run `type autoexec.bat | more' to pause listing the file after every screenful, the "|" is the pipe character. Refer to a lot of shell scripting or UNIX system programming books for different ways to utilize this fairly powerful construct. > 1 more quickie: > >if __name__ == '__main__': > > main() > > what is the pourpose if the above code? It runs the sub main() (duh :) but, > why not just main() wihtout the if? what is the conditional testing for? > and what are the variables __main__ and __name__? i dont believe they are > defined in the program, so just what are they? and, what does putting "__" > around a variable actually DO besides look cool ? This is explained in the Python FAQ 4.10 "How do I find out whether I am running as a script?" Each module has a variable called "__name__". If variable contains the name "__main__", then the module is what was called from the command line (the "script"), instead of imported from another module. $ cat foo.py if __name__ == '__main__': print 'script' else: print 'imported' $ python foo.py script $ python >>> import foo imported >>> Most often it is used to test a module meant to be imported, so only if you execute it directly, it runs the testing code. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From bsass@freenet.edmonton.ab.ca Thu Feb 1 18:34:13 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Thu, 1 Feb 2001 11:34:13 -0700 (MST) Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: On Wed, 31 Jan 2001, Seelinger, Bruce wrote: > Another question from someone totally new to Python. Is there an equivalent > in Python to a sub-routine, (e.g. gosub and return). I want to create a function - subroutine - procedure... they are all the same basic idea > modular program with sub-routines to perform distinct tasks wihin the > program for organizational and debugging purposes, etc. Is the only (or > best) way to do this is with modules? A function works but the values > obtained within the function do not appear to be valid outside of that You should send along an example... it is probably just a problem with Python's scope rules, or maybe that the code is passing a reference when you are thinking value, or maybe you are expecting a default parameter's value to be evaluated everytime the function is used when it is actually only evaluated once... hard to say without seeing any code. > function. I guess I am looking for the best approach to create the > subroutines for execution from the main flow of the program. later, Bruce From deirdre@deirdre.net Thu Feb 1 19:15:35 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Feb 2001 11:15:35 -0800 (PST) Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDF@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: As this is really a tutor question, I'm cutting the extra parts and re-posting the meat to the Tutor list (list mom's prerogative): (And yes, I'd rather responses went to the list; others are struggling with the same kinds of things and NOT posting...) On Thu, 1 Feb 2001, Seelinger, Bruce wrote: > I wanted to use values obtained in subroutines or functions as you are > allowed in DCL. For example, one subroutine determines the hardware > type of unit based on data imported from a file. Once that subroutine > determines the hardware type, it is assigned to a variable (hw_type) > and is used by other subroutines for purposes unique to that hardware > type. I think the underlying issue is the my logic and design will > need to be modified to adhere to Python's rules. In calling a function, you can pass one or more parameters to it. Unlike may other languages, you can also return multiple parameters. def readFile(fname): ... do some stuff... hw_type = (something from the file) hw_info = (something else from the file) return hw_type, hw_info def main(): hw_type, hw_info = readFile("foo") There's also more complex structures; see: http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000 _Deirdre From kalle@gnupung.net Thu Feb 1 19:52:05 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 1 Feb 2001 20:52:05 +0100 Subject: [Tutor] NEWBIE!! pipes In-Reply-To: <50.10cfb61b.27a9e306@aol.com>; from AquaRock7@aol.com on Wed, Jan 31, 2001 at 04:52:06PM -0500 References: <50.10cfb61b.27a9e306@aol.com> Message-ID: <20010201205205.B463@apone.network.loc> --Yylu36WmvOXNoKYn Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez AquaRock7@aol.com: > What are pipes? The docs barely touched this subject, it assumed you alr= eady=20 > knew what they are... From context I am gathering that it is a connectio= n to=20 > the kernel? (maybe?) How can I utilize this? It is much like a file, but it's connected to another program. The name is actually pretty telling, your program holds one end of the pipe and the other program holds the other. If you put something in, it comes out in the other end, and vice versa. Computer pipes are one-way though, either you have a write pipe or a read pipe (I think?). Anyway, they're really cool to have in a shell: ps ax | grep netscape | grep -v grep | awk '{ print $1 }' is a common command on UNIX workstations, it finds the process id of netscape, to be able to kill it when it's sucking all the CPU again. In python, the most common way to use pipes is the os.popen* family of functions. They return pipes to/from a process. Artificial example: >>> import os >>> inpipe =3D os.popen("ls") >>> outpipe =3D os.popen("lpr", "w") >>> outpipe.write(inpipe.read()) >>> should print the contents of the current directory to your printer. Better examples for windows are left for others to figure out. > 1 more quickie: > >if __name__ =3D=3D '__main__': > > main() >=20 > what is the pourpose if the above code? It runs the sub main() (duh :) b= ut,=20 > why not just main() wihtout the if? what is the conditional testing for?= =20 > and what are the variables __main__ and __name__? i dont believe they ar= e=20 > defined in the program, so just what are they? and, what does putting "_= _"=20 > around a variable actually DO besides look cool ? Good questions! Variables with "__"s around them are system variables, often automatically defined by the system. Every module has a __name__, and when it is run directly from command line, this is "__main__". >>> import cgi >>> cgi.__name__ 'cgi' >>> print __name__ __main__ >>>=20 Thus if __name__ =3D=3D '__main__': main() only runs main() if the file is run, as opposed to imported from another module. This enables modules to work both as libraries and programs at the same time. Great, huh? 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 --Yylu36WmvOXNoKYn 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 iD8DBQE6eb5ldNeA1787sd0RAuoaAKCwtRdr/rNm+c/7K2bBg7yTh/Q/TQCeIgkP UVp6rNv78hCuE5Ata03Ng1g= =pjlL -----END PGP SIGNATURE----- --Yylu36WmvOXNoKYn-- From kalle@gnupung.net Thu Feb 1 19:55:09 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 1 Feb 2001 20:55:09 +0100 Subject: [Tutor] square root In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>; from vdbroekw@wxs.nl on Wed, Jan 31, 2001 at 10:12:48PM +0100 References: <20010130215307.C2537EECC@mail.python.org> <3A787FD0.4CD22F54@wxs.nl> Message-ID: <20010201205509.C463@apone.network.loc> --QRj9sO5tAVLaXnSD Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez W.W. van den Broek: > How do you use the > square root as operator > in python? There is no square root operator in python. You'll have to use the math.sqrt() function. 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 --QRj9sO5tAVLaXnSD 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 iD8DBQE6eb8ddNeA1787sd0RAuipAKCyt+zBoeiGvwOc1Qoa6LN5y4mlJwCgz4QG 2oDQJ8I8zwSuUgViBFdxP+s= =YK4m -----END PGP SIGNATURE----- --QRj9sO5tAVLaXnSD-- From dsh8290@rit.edu Thu Feb 1 21:03:48 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 1 Feb 2001 16:03:48 -0500 Subject: [Tutor] square root In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>; from vdbroekw@wxs.nl on Wed, Jan 31, 2001 at 10:12:48PM +0100 References: <20010130215307.C2537EECC@mail.python.org> <3A787FD0.4CD22F54@wxs.nl> Message-ID: <20010201160348.A5654@harmony.cs.rit.edu> There is no square root /operator/ in python. (AFAIK) There is a square root function instead. from math import sqrt print sqrt( 49 ) You can use it just like any other function. I will return the square root (as a floating point number). HTH, -D On Wed, Jan 31, 2001 at 10:12:48PM +0100, W.W. van den Broek wrote: | How do you use the | square root as operator | in python? | Dumb question, but | thanks anyway, | walter | -- | W.W. van den Broek | e-mail: | vandenbroek@psyd.azr.nl | AZR-Dijkzigt fax: | 010-4633217 | afdeling psychiatrie | tel: 010-4639222 | Postbus 2040 e-mail | vdbroekw@wxs.nl (thuis) | 3000 CA Rotterdam | homepage: | http://home.planet.nl/~vdbroekw | | _______________________________________________ | Tutor maillist - Tutor@python.org | http://mail.python.org/mailman/listinfo/tutor From kevinoconnor1@netscapeonline.co.uk Thu Feb 1 21:16:19 2001 From: kevinoconnor1@netscapeonline.co.uk (kevinoconnor1) Date: Thu, 01 Feb 2001 21:16:19 +0000 Subject: [Tutor] tutor me please Message-ID: <3A79D222.B9FD4C42@netscapeonline.co.uk> Hi im new and want to know the ins and outs of all the pythan programming. Before you try and reply, reply to a different address because it is more safe!!if you get the jist! email me : Freespirt@breathe.com Cheers From randrews@planhouse.com Thu Feb 1 21:28:16 2001 From: randrews@planhouse.com (Rob Andrews) Date: Thu, 1 Feb 2001 15:28:16 -0600 Subject: [Tutor] Newbie question re: user interaction References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <002c01c08c95$e5effd20$dc00a8c0@Planhouse5> name=raw_input("What's your name? ") print "Hello, " + name + "!" Something like this should do it. Rob ----- Original Message ----- From: "First Name Last Name" To: Sent: Thursday, February 01, 2001 2:05 AM Subject: [Tutor] Newbie question re: user interaction > Hello, > I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. > > Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. > > Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" > > This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! > > Thanks very much for any help, Gus Hungerford. > > > > ------------------------------------------------------------ > --== Sent via Deja.com ==-- > http://www.deja.com/ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From deirdre@deirdre.net Thu Feb 1 21:32:41 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 1 Feb 2001 13:32:41 -0800 (PST) Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: On Thu, 1 Feb 2001, First Name Last Name wrote: > Anyway, what I'm writing to ask about is, how do I do the equivalent > of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" n = raw_input("What is your name?") print "Hello, %s!" % n The syntax of the two languages' input and print is different, but the basic concept is the same. > This is a staggeringly simple piece of code and I instinctively feel > that a well-designed language like Python must have a simple and > elegant way of replicating it. However, all I've managed to gather > from the manual is that if I do something horribly complicated with > the cmd module then I might be able to do something that vaguely > mimics the code above. Please tell me I'm wrong! I think you'll find that a lot more is the same than you might think. It's the details that are different. The %s means "put a string here, I'll tell you what it is later." The % later in the line means "OK, here's the list of stuff to put in." _Deirdre From dsh8290@rit.edu Thu Feb 1 21:53:27 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 1 Feb 2001 16:53:27 -0500 Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800 References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <20010201165327.B5654@harmony.cs.rit.edu> N = raw_input( "What is your name? " ) print N :-) (though I would use a variable like "name" instead of N) -D On Thu, Feb 01, 2001 at 12:05:25AM -0800, First Name Last Name wrote: | Hello, | I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. | | Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. | | Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? | | 10 INPUT "What is your name?" N$ | 20 PRINT "Hello, " N$ "!" | | This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! | | Thanks very much for any help, Gus Hungerford. | | | | ------------------------------------------------------------ | --== Sent via Deja.com ==-- | http://www.deja.com/ | | | | _______________________________________________ | Tutor maillist - Tutor@python.org | http://mail.python.org/mailman/listinfo/tutor From sparling@uclick.com Thu Feb 1 21:54:24 2001 From: sparling@uclick.com (Douglas Sparling) Date: Thu, 1 Feb 2001 15:54:24 -0600 Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <000401c08c99$8afa0560$460110ac@uclick.com> >Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? > >10 INPUT "What is your name?" N$ >20 PRINT "Hello, " N$ "!" name = raw_input("What is your name? ") print "Hello, " + name + "!" From martok@mattsmail.com Thu Feb 1 22:12:09 2001 From: martok@mattsmail.com (Matthias Hager) Date: Thu, 1 Feb 2001 14:12:09 -0800 Subject: [Tutor] Newbie question re: user interaction Message-ID: <200102011412.AA123666752@mail.mattsmail.com> It's been so long since I've worked with any basic. But This should get the effect you're looking for. $N = input("What is your name? ") print "Hello, ", $N, "!\n" The python book I'm using, as pathetic as it may be, says that much. But when I learned Perl my book didn't tell me how to do that. Hope that's what you're looking for. Matthias -- Programming isn't cool, it's awesome. %%%################?????????###################^^^ martok@mattsmail.com http://mymymatthias.tripod.com/ %%%################????????####################^^^ -- Like my email address? Get your own for FREE at http://firstname.com Get you@JohnsMail.com or you@AlexsMail.com or pick from 500 more! From dsh8290@rit.edu Thu Feb 1 22:18:14 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 1 Feb 2001 17:18:14 -0500 Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500 References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: <20010201171814.C5654@harmony.cs.rit.edu> Except for some minor philosophical issues, subroutine is function is method is procedure is subprogram Different communities have different names for the same concept. Functions are what you want here. The problem you are running into is Python's scope and namespace rules. Ex: >>> def mutate( ) : ... """ this function will give a new value for s """ ... s = s + "Hello World" ... >>> s = "Foo " >>> mutate( ) >>> print s Foo >>> What happened here? The value didn't change. There are 2 reasons for that. First, the function body has a local namespace. Those names don't exist outside of the function. Assignment, in Python, is different than in most languages. In, say, C/C++ assignment will modify the value of the memory that the variable name refers to (is bound to). In Python, assignment is simply a rebinding. Everything in Python is a reference. If a name doesn't yet exist, the "assignment" will create the name, *in the local namespace*. Ok, knowing this, I'll try my above example again. >>> def mutate( ) : ... global s ... s = s + "Hello World" ... >>> s = "Foo " >>> mutate( ) >>> print s Foo Hello World >>> This is closer to what you are looking for, I think. The 'global' keyword notifies the interpreter that you want to use a variable from outside the local namespace. This isn't necessary for reading a variable, but to assign to it (rebind it) it is necessary. Without the global statement, I would have created a new binding in the function's local namespace, and the effects would not be visible outside of the function. There is another issue to consider when trying to modify variables. Some variables are immutable, while other are mutable. Immutable variables can't have their /value/ changed, but can still be rebound to a new object (value). Strings, integers, and tuples are some of the immutable types in python. Lists and classes are mutable. An example: >>> def mutate( s ) : ... s = s + "Hello World" ... >>> a_string = "Foo " >>> mutate( a_string ) >>> print a_string Foo >>> The argument 's' was rebound /inside/ the function to point to a new string whose value was "Foo Hello World". The a_string variable is still bound to the original string whose value is still "Foo". Now I'll try with a list, since lists are mutable. >>> def mutate( l ) : ... """ try mutating a list """ ... l = l + [ 3 , 4 , 5 ] ... >>> a_list = [ 1 , 2 ] >>> mutate( a_list ) >>> print a_list [1, 2] >>> The problem here is the namespace the new list is bound in. The operator "+" on a list doesn't modify the list, but instead returns a new list that is the concatenation of the operands. >>> def mutate( l ) : ... l += [ 3 , 4 , 5 ] ... >>> a_list = [ 1 , 2 ] >>> mutate( a_list ) >>> print a_list [1, 2, 3, 4, 5] >>> Version 2.0 of the interpreter added augmented assignment. For immutable objects, the value isn't changed and the new object is bound to the left hand side. (It is just a shorthand notation) For mutable objects it will modify the object, /and/ return a refernce to the object. The return is necessary otherwise your identifier won't refer to any objects anymore. In older versions as well as newer versions of the interpreter, the following will also work: >>> def mutate( l ) : ... l.extend( [ 3 , 4 , 5 ] ) ... >>> a_list = [ 1 , 2 ] >>> mutate( a_list ) >>> print a_list [1, 2, 3, 4, 5] >>> What kind of background are you coming from? If I remember correctly, gosub is from BASIC (but I haven't done any BASIC programming). If you can provide some examples of what you are trying to do (the python code you have that isn't working right) we can help you to see how python's semantics are working and how to modify it to give you the semantics you want. You can start out using stand-alone functions, but I much prefer using classes for (most) of my work. (there are situations where a stand-alone function is a better choice though) Simply put, a class is a set of data and a set of functions that operate on that data. You can create multiple instances of a class and each will have its own set of that data. HTH, -D On Wed, Jan 31, 2001 at 05:12:29PM -0500, Seelinger, Bruce wrote: | Hello, | | Another question from someone totally new to Python. Is there an equivalent | in Python to a sub-routine, (e.g. gosub and return). I want to create a | modular program with sub-routines to perform distinct tasks wihin the | program for organizational and debugging purposes, etc. Is the only (or | best) way to do this is with modules? A function works but the values | obtained within the function do not appear to be valid outside of that | function. I guess I am looking for the best approach to create the | subroutines for execution from the main flow of the program. | | Thanks for any assistance! | | Regards, | | Bruce Seelinger From DOUGS@oceanic.com Fri Feb 2 01:55:40 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Thu, 1 Feb 2001 15:55:40 -1000 Subject: [Tutor] Newbie question re: user interaction Message-ID: <8457258D741DD411BD3D0050DA62365907A5AF@huina.oceanic.com> [Gus Hungerford asked] > Anyway, what I'm writing to ask about is, how do I do the > equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" Look at the raw_input function. The reference example (below) is almost what you need. You'll probably want this: answer = raw_input('What is your name? ') print answer HTH -Doug- >From the 'Python Library Reference': raw_input ([prompt]) If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example: >>> s = raw_input('--> ') --> Monty Python's Flying Circus >>> s "Monty Python's Flying Circus" If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features. From moshez@zadka.site.co.il Fri Feb 2 01:55:31 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Fri, 2 Feb 2001 03:55:31 +0200 (IST) Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com> References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <20010202015531.D6228A840@darjeeling.zadka.site.co.il> On Thu, 1 Feb 2001, "First Name Last Name" wrote: > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" n = raw_input("what is your name?") print "hello, %s!" % n -- Moshe Zadka This is a signature anti-virus. Please stop the spread of signature viruses! Fingerprint: 4BD1 7705 EEC0 260A 7F21 4817 C7FC A636 46D0 1BD6 From moshez@zadka.site.co.il Fri Feb 2 01:56:03 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Fri, 2 Feb 2001 03:56:03 +0200 (IST) Subject: [Tutor] square root In-Reply-To: <3A787FD0.4CD22F54@wxs.nl> References: <3A787FD0.4CD22F54@wxs.nl>, <20010130215307.C2537EECC@mail.python.org> Message-ID: <20010202015603.EE36CA840@darjeeling.zadka.site.co.il> On Wed, 31 Jan 2001, "W.W. van den Broek" wrote: > How do you use the > square root as operator > in python? import math print math.sqrt(2) -- Moshe Zadka This is a signature anti-virus. Please stop the spread of signature viruses! Fingerprint: 4BD1 7705 EEC0 260A 7F21 4817 C7FC A636 46D0 1BD6 From jcm@bigskytel.com Fri Feb 2 02:14:32 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 1 Feb 2001 19:14:32 -0700 Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800 References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <20010201191432.A8192@bigskytel.com> * First Name Last Name : <...> > Anyway, I understand enough of Python to look up the bits I don't remember > in the manual, write simple functions, &c. The part in my manual (O'Reilly > 'Learning Python') about classes is complete gibberish to me, but I'm sure > that will change in time. I had similar troubles with classes too. The good thing is, that you don't need to know them to use Python. I'm sure that eventually their benefits will interest you in learning them, but you don't have to yet. > Anyway, what I'm writing to ask about is, how do I do the equivalent of the > following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" N = raw_input("What is your name?") print "Hello, %s!" % N David From sparling@uclick.com Fri Feb 2 03:02:50 2001 From: sparling@uclick.com (Doug Sparling) Date: Thu, 01 Feb 2001 19:02:50 -0800 Subject: [Tutor] test Message-ID: <981082970.3a7a235ad0d46@www.electricwebmail.com> Sorry, I haven't seen a previous post come through, so I wanted to make a test...... From lgwb@home.com Fri Feb 2 03:20:23 2001 From: lgwb@home.com (Michael Schmitt) Date: Thu, 1 Feb 2001 21:20:23 -0600 Subject: [Tutor] Newbie question re: user interaction References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <002501c08cc7$14fe13f0$0a0a0a0a@mntp1.il.home.com> Name = raw_input("What is your name\n") print "Hello", Name simple enough? Ya, I agree, it seems as input is well hidden in most Python doc/books. Michael Schmitt ----- Original Message ----- From: "First Name Last Name" To: Sent: Thursday, February 01, 2001 2:05 AM Subject: [Tutor] Newbie question re: user interaction > Hello, > I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. > > Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. > > Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" > > This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! > > Thanks very much for any help, Gus Hungerford. > > > > ------------------------------------------------------------ > --== Sent via Deja.com ==-- > http://www.deja.com/ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From tescoil@irtc.net Fri Feb 2 00:38:02 2001 From: tescoil@irtc.net (Tesla Coil) Date: Thu, 01 Feb 2001 18:38:02 -0600 Subject: [Tutor] Newbie question re: user interaction References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <3A7A016A.823E7D92@irtc.net> On 1 Feb 2001, First Name Last Name wrote: > Anyway, what I'm writing to ask about is, how do I do the > equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" > > This is a staggeringly simple piece of code and I > instinctively feel that a well-designed language > like Python must have a simple and elegant way > of replicating it N = raw_input('what is your name? ') print 'Hello,', N, '!' From rob@jam.rr.com Thu Feb 1 23:49:59 2001 From: rob@jam.rr.com (R. A.) Date: Thu, 01 Feb 2001 17:49:59 -0600 Subject: [Tutor] Newbie question re: user interaction References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <3A79F627.6D55E769@jam.rr.com> I sent this earlier, but it didn't seem to make it to the list. name=raw_input("What is your name? ") print "Hello, " + name + "!" Something like this should do the trick. Rob First Name Last Name wrote: > > Hello, > I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. > > Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. > > Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" > > This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! > > Thanks very much for any help, Gus Hungerford. > > ------------------------------------------------------------ > --== Sent via Deja.com ==-- > http://www.deja.com/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Visit the Useless Python Repository! http://www.lowerstandard.com/python/pythonsource.html From babyboy@oninet.pt Thu Feb 1 23:54:59 2001 From: babyboy@oninet.pt (wilson edgar pinto) Date: Thu, 1 Feb 2001 23:54:59 -0000 Subject: [Tutor] Newbie question re: user interaction References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <002401c08caa$63de0ec0$320d3ad5@x0q0w3> yes Gus, is much more simple than that just try this name = raw_input("hello what's your name? ") print "nice to meet you", name in other words, raw_input, print whatever you write between parenthesis as a prompt and and then ssaves the value and because, if you assign it to a variable in this case "name", you can reuse it after and you can use INPUT that lets you deal with numbers, c'os raw_input is for strings hope that helped ----- Original Message ----- From: "First Name Last Name" To: Sent: Thursday, February 01, 2001 8:05 AM Subject: [Tutor] Newbie question re: user interaction > Hello, > I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week. I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page. > > Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c. The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time. > > Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python? > > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" > > This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it. However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above. Please tell me I'm wrong! > > Thanks very much for any help, Gus Hungerford. > > > > ------------------------------------------------------------ > --== Sent via Deja.com ==-- > http://www.deja.com/ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From rob@jam.rr.com Fri Feb 2 00:06:55 2001 From: rob@jam.rr.com (R. A.) Date: Thu, 01 Feb 2001 18:06:55 -0600 Subject: [Tutor] We're famous! Message-ID: <3A79FA1F.E44688AD@jam.rr.com> I have not been this elated in recent memory, group. The O'Reilly Network has written what seems to be a kind article on Useless Python, which I call a success for the Tutor list. You nifty people have started something nice, and I thank you for allowing me to maintain it. The following URL says it all: http://www.oreillynet.com/pub/a/python/2001/01/31/pythonnews.html Rob Andrews -- Visit the Useless Python Repository! http://www.lowerstandard.com/python/pythonsource.html From dsh8290@rit.edu Fri Feb 2 00:15:47 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 1 Feb 2001 19:15:47 -0500 Subject: [Tutor] Word count help In-Reply-To: <001b01c08a3c$0761e1a0$f9230b3e@oemcomputer>; from facelle@tiscalinet.it on Mon, Jan 29, 2001 at 10:39:28PM +0100 References: <001b01c08a3c$0761e1a0$f9230b3e@oemcomputer> Message-ID: <20010201191547.D6419@harmony.cs.rit.edu> I have looked through the code you posted, and I think I know why it is so slow. You use lists a lot in your code, and use function calls such as list.count(). AFAIK list.count() will traverse through the entire list every time it is called. When the list gets to be large, this will take a long time. To speed this up, I would recommend using a dictionary to hold all the words and their counts. Dictionary lookups are fast since they use a hashing function to find the key. In this dictionary, I would use the word as the key, and have the associated value be the number of occurences. (I posted a perl script I wrote for class last quarter, but I think a moderator dropped the message) I have now translated that perl script to python. I use more pythonic techniques, and also use more punctuation marks for delimiting words (the result is that python does more work because it finds more words). (In the perl script I made my own regex with the most common chars, in the python script I use the predefined constants in the string module). For timing, I first prepared a file to count (the bash manpage): $ man bash > man_bash $ cp man_bash dup $ cat dup >> man_bash (3 times) $ rm dup The file size is now 1,211KB as reported by Windows Explorer. The file has 24552 lines in it. I'm using a PII 400 (I might be a little off on the clock speed, it's not my personal machinge) with Win2k and cygwin. I ran the interpreter from the bash shell. The python interpreter is compiled for windows, the perl one came with cygwin (compiled for cygwin). I ran time perl count.pl < man_bash > /dev/null and time python count.py < man_bash > /dev/null to get a rough idea how long the scripts take to run. My results: Perl: real 0m9.233s user 0m8.522s sys 0m0.090s Python: real 0m19.779s user 0m0.010s sys 0m0.010s Just kind of interesting, the first time I timed it, I used the wrong filename (a file that doesn't exist). Perl took longer to report the error than python. Perl: bash: man_bashrc: No such file or directory real 0m0.050s user 0m0.030s sys 0m0.020s Python: bash: man_bashrc: No such file or directory real 0m0.010s user 0m0.000s sys 0m0.010s My entire script (except for the print statements) could be placed inside a function that takes a filename as an argument, and returns the dictionary of words if you wanted to use it as part of a larger system. I hope this helps you to learn more. If you have any questions, don't hesitate to ask. -D Here is the script that I used: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import sys import string import re # initialize the counters linecount = 0 charcount = 0 wordcount = 0 # this is where I will store the total count of each word words = { } # iterate over each line on stdin for line in sys.stdin.readlines() : linecount += 1 charcount += len( line ) # remove leading and trailing whitespace line = string.strip( line ) # split the string into a list of words # a word is delimited by whitespace or punctuation #"[.,:;?! \t\n]+" , # this is the regex used in my perl version for word in re.split( "[" + string.whitespace + string.punctuation + "]+" , line ) : # make the word lower case word = string.lower( word ) # check to make sure the string is considered a word if re.match( "^[" + string.lowercase + "]+$" , word ) : wordcount += 1 # if the word has been found before, increment its count # otherwise initialize its count to 1 if words.has_key( word ) : words[ word ] += 1 else : words[ word ] = 1 # Now print out the results of the count: print print "Number of lines:" , linecount print "Total word count:" , wordcount print "Total character count:" , charcount print # print each word and its count in sorted order sorted_word_list = words.keys() sorted_word_list.sort() for word in sorted_word_list : print word , ":" , words[ word ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The script's output from the man_bash file I used (identical to the perl version's, except for the extra carriage returns that result from Windows) looks like: Number of lines: 24552 Total word count: 116000 Total character count: 1239660 a : 3236 abbreviates : 12 abe : 4 ability : 4 able : 40 abled : 4 ables : 20 abling : 4 abort : 8 about : 32 above : 196 absence : 4 absent : 4 absolute : 8 PS. I recently learned that all Usenet posts are automatically copyrighted by the poster. In light of this, I give explicit permission to use, copy, distribute, and mutilate my sample code to your heart's desire. :-) From jcm@bigskytel.com Fri Feb 2 00:29:55 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 1 Feb 2001 17:29:55 -0700 Subject: [Tutor] NEWBIE!! pipes In-Reply-To: <50.10cfb61b.27a9e306@aol.com>; from AquaRock7@aol.com on Wed, Jan 31, 2001 at 04:52:06PM -0500 References: <50.10cfb61b.27a9e306@aol.com> Message-ID: <20010201172955.A6810@bigskytel.com> * AquaRock7@aol.com : > What are pipes? The docs barely touched this subject, it assumed you > already knew what they are... From context I am gathering that it is a > connection to the kernel? (maybe?) How can I utilize this? http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=pipes I haven't done anything with pipes yet. > 1 more quickie: > >if __name__ == '__main__': > > main() > > what is the pourpose if the above code? It runs the sub main() (duh :) but, > why not just main() wihtout the if? what is the conditional testing for? > and what are the variables __main__ and __name__? i dont believe they are > defined in the program, so just what are they? and, what does putting "__" > around a variable actually DO besides look cool ? Each module has a __name__ attribute. The directly executed file (not imported) has the __name__ of "__main__". Even an interpretter session has the name of "__main__": >>> __name__ '__main__' >>> import os >>> os.__name__ 'os' Basically, the purpose of the above code is to make python do different things when the file is run as a script and when it is imported as a module. If it is being run as a script, execute main(). As for the question about __X__ type names, I think it is merely like that for __name__ to distinquish it from your variables with the added bonus of not stealing a valuable keyword from us, name. __X__ type names are more significant when you deal with classes, where they are hooks used for operator overloading. David From ccurrie@lcc.net Fri Feb 2 00:48:03 2001 From: ccurrie@lcc.net (Cameron) Date: Thu, 1 Feb 2001 18:48:03 -0600 Subject: [Tutor] Compiling Python Scripts References: <20010201170408.E3C9CF5D9@mail.python.org> Message-ID: <000501c08cb1$cda1b1c0$0101a8c0@ccurrie> Hi, I want to compile some of my Python scripts into executable programs to distribute to some friends who don't have the Python interpreter... is there any way to do this? I was unable to find the answer in the documentation. Thanks From jcm@bigskytel.com Fri Feb 2 00:55:58 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 1 Feb 2001 17:55:58 -0700 Subject: [Tutor] Equivalent of a Subroutine in Python? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500 References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: <20010201175558.A7581@bigskytel.com> * Seelinger, Bruce : > Another question from someone totally new to Python. Is there an equivalent > in Python to a sub-routine, (e.g. gosub and return). I want to create a > modular program with sub-routines to perform distinct tasks wihin the > program for organizational and debugging purposes, etc. Is the only (or > best) way to do this is with modules? What about functions? According to http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=subroutine "A function is often very similar to a subroutine, the main difference being that it is called chiefly for its return value, rather than for any side effects." > A function works but the values obtained within the function do not appear > to be valid outside of that function. That is because they are local to the function's namespace. If you want them to be global, then you must declare them so: def fun(): global x x = 11 fun() print x Or you could use a standard function with return value: def fun2(): return 11 x = fun2() print x David From kalle@gnupung.net Fri Feb 2 01:28:51 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 2 Feb 2001 02:28:51 +0100 Subject: [Tutor] Newbie question re: user interaction In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800 References: <200102010805.AAA10776@mail14.bigmailbox.com> Message-ID: <20010202022851.A1457@apone.network.loc> --+HP7ph2BbKc20aGI Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez First Name Last Name: > Anyway, what I'm writing to ask about is, how do I do the equivalent of > the following BASIC function in Python? >=20 > 10 INPUT "What is your name?" N$ > 20 PRINT "Hello, " N$ "!" n =3D raw_input("What is your name?") print "Hello,", n Note that there's no space in the "Hello," string. The print statement adds one space between each comma separated argument: >>> print "a", "b", "c" a b c >>> Also, a good idea is to check out the built in functions, there are quite a few nice tools there: http://www.python.org/doc/current/lib/built-in-funcs.html And indeed, the library reference is your friend: http://www.python.org/doc/current/lib/ > Please tell me I'm wrong! You're wrong! HTH, Kalle P.S. I might add that local time is 02:28 (AM). I really should go to bed. --=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 --+HP7ph2BbKc20aGI 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 iD8DBQE6eg1TdNeA1787sd0RAu98AJ9u+vayBvFAgQqt+RAYXW60tm26QQCgu+wN sw8UyttOcEBNDV0UX8hiay4= =Fj7O -----END PGP SIGNATURE----- --+HP7ph2BbKc20aGI-- From toodles@yifan.net Fri Feb 2 01:21:28 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Fri, 2 Feb 2001 09:21:28 +0800 Subject: [Tutor] square root In-Reply-To: <3A787FD0.4CD22F54@wxs.nl> Message-ID: There's no operator for squareroot (unless I've been misleading myself for this long). Use the power rule of x**(1/y). Here's the relavent rules: x**y == x to the power of y, x**(1/y) == x to the root of y, x**(z/y) == x to the root of y - all raised to the power of z, So x**(1/2) == the square root of x I don't think it was a dumb question, but then, I'm a newbie script kiddie! =) Andrew Wilkins > -----Original Message----- > From: tutor-admin@python.org > [mailto:tutor-admin@python.org]On Behalf Of > W.W. van den Broek > Sent: Thursday, 1 February 2001 5:13 > To: tutor@python.org > Subject: [Tutor] square root > > > How do you use the > square root as operator > in python? > Dumb question, but > thanks anyway, > walter > -- > W.W. van den Broek > e-mail: > vandenbroek@psyd.azr.nl > AZR-Dijkzigt fax: > 010-4633217 > afdeling psychiatrie > tel: 010-4639222 > Postbus 2040 e-mail > vdbroekw@wxs.nl (thuis) > 3000 CA Rotterdam > homepage: > http://home.planet.nl/~vdbroekw > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From bsass@freenet.edmonton.ab.ca Fri Feb 2 06:30:52 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Thu, 1 Feb 2001 23:30:52 -0700 (MST) Subject: [Tutor] Path problems python 2.0 In-Reply-To: <011801c08bff$49b08380$25dbaec7@kitchen> Message-ID: On Wed, 31 Jan 2001, The Conways wrote: > Now for a Linux question. Python 1.52 came with our Mandrake 7.2 > installation. So I am also learning some linux as well as python. My > question is where do you keep your py scripts in Linux, the file system is > so organized that I am not really sure where to put things. Generally, stuff the package manager does not know about should go into /usr/local or /opt (depending on whether the package is setup to install into the usual unix filesystem structure or into its own directory, respectively), everything under /usr should be the result of installing an .rpm. Your Mandrake-Python maintainer probably has a dir set aside for local modules, it is /usr/local/lib/site-python on my Debian box. Checking your PYTHONPATH while the interpreter is running will tell you all the locations Python will look for modules. If you are wondering about where to put executables so everyone can get at them... /usr/local/bin Maybe do, "echo $PATH", to make sure /usr/local/bin is in your PATH. later, Bruce From NHYTRO@compuserve.com Fri Feb 2 06:56:52 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Fri, 2 Feb 2001 01:56:52 -0500 Subject: [Tutor] Reading and outputting HTML files Message-ID: <200102020157_MC2-C3F6-C82A@compuserve.com> Hi guys! I have coded a CGI script that creates HTML files, strange thing is, when= reading a HTML file, one created by the script or otherwise, I just get a= very garbled page returned to the browser. Any clues? can someone help? this has been bugging me for 3 days now Cheers Sharriff P.S. did I mention that Python rocks? From salim@nstp.com.my Fri Feb 2 07:38:23 2001 From: salim@nstp.com.my (Salim) Date: Fri, 02 Feb 2001 15:38:23 +0800 Subject: [Tutor] square root In-Reply-To: References: <3A787FD0.4CD22F54@wxs.nl> Message-ID: <5.0.2.1.2.20010202153712.00a5fb70@nstp.com.my> Please make a correction: x**1/2==the square root of x please note there is no bracket... tq At 09:21 AM 2/2/01 +0800, you wrote: >There's no operator for squareroot (unless I've been misleading myself >for this long). > >Use the power rule of x**(1/y). Here's the relavent rules: > >x**y == x to the power of y, >x**(1/y) == x to the root of y, >x**(z/y) == x to the root of y - all raised to the power of z, > >So x**(1/2) == the square root of x > >I don't think it was a dumb question, but then, I'm a newbie script >kiddie! =) > >Andrew Wilkins > > > -----Original Message----- > > From: tutor-admin@python.org > > [mailto:tutor-admin@python.org]On Behalf Of > > W.W. van den Broek > > Sent: Thursday, 1 February 2001 5:13 > > To: tutor@python.org > > Subject: [Tutor] square root > > > > > > How do you use the > > square root as operator > > in python? > > Dumb question, but > > thanks anyway, > > walter > > -- > > W.W. van den Broek > > e-mail: > > vandenbroek@psyd.azr.nl > > AZR-Dijkzigt fax: > > 010-4633217 > > afdeling psychiatrie > > tel: 010-4639222 > > Postbus 2040 e-mail > > vdbroekw@wxs.nl (thuis) > > 3000 CA Rotterdam > > homepage: > > http://home.planet.nl/~vdbroekw > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From deirdre@deirdre.net Fri Feb 2 08:41:07 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 2 Feb 2001 00:41:07 -0800 (PST) Subject: [Tutor] Compiling Python Scripts In-Reply-To: <000501c08cb1$cda1b1c0$0101a8c0@ccurrie> Message-ID: On Thu, 1 Feb 2001, Cameron wrote: > I want to compile some of my Python scripts into executable programs > to distribute to some friends who don't have the Python interpreter... > is there any way to do this? I was unable to find the answer in the > documentation. The answer is, in part, dependent upon the platform -- which you didn't specify. _Deirdre From jcm@bigskytel.com Fri Feb 2 10:07:39 2001 From: jcm@bigskytel.com (David Porter) Date: Fri, 2 Feb 2001 03:07:39 -0700 Subject: [Tutor] Reading and outputting HTML files In-Reply-To: <200102020157_MC2-C3F6-C82A@compuserve.com>; from NHYTRO@compuserve.com on Fri, Feb 02, 2001 at 01:56:52AM -0500 References: <200102020157_MC2-C3F6-C82A@compuserve.com> Message-ID: <20010202030739.A10507@bigskytel.com> * Sharriff Aina : > I have coded a CGI script that creates HTML files, strange thing is, when > reading a HTML file, one created by the script or otherwise, I just get a > very garbled page returned to the browser. You seem to be saying above that your browser is broken ("created by the script or otherwise..."). Could you clarify you message? Also posting example code and errors helps greatly. David From christophe.cuny@ants.co.uk Fri Feb 2 11:16:46 2001 From: christophe.cuny@ants.co.uk (Cuny, Christophe (ANTS)) Date: Fri, 2 Feb 2001 11:16:46 -0000 Subject: [Tutor] Newbie questions with an anmbitious tweak! Message-ID: <29897BB9AE72D411A89B0008C773175E4B74FF@BHISHMA> Hello Tutor list. First of all, thank you for existing. We newbies appreciate the work that you guys put in supporting us. I am new to programming (almost) and new to Python. At first sight, I thought Python looked a lot easier than other languages. Whilst this is still valid, I also realised that I would have some serious issues doing the following: 1) Creating Stand-alone exes for 32 bit Windows. 2) Create a GUI for small apps I have in mind. So can I start with a basic question. In tutorials, I get referred to "using a text editor such as notepad...". But using Python for windows I saw that the "built-in" editor has full syntax highlighting. So the question is: do I actually need another editor or are the tutorials referring to old versions of Python? I also notice that I have problems relating to what "components" or "modules" are available and what they do. Is there an IDE for Python (windows) that has a proper browser-like utility for seeing the modules (and perhaps their related help files or whatever) or is there no standard? From my version of Python, I now it is possible to search for modules but I have to know the name and Python seems to look only in the "system path" (?). Generally, if I want to use modules from other people, must they be in a specific sub-directory of Python or should I be ok accessing them from any place were they may have been unpacked on my hard drive? Finally, is there an editor (for Python in Windows) that would be able either to refer to a library of commands or/and to complete command words as they are part-typed? I also have a question on GUIs. I have read a bit about Tk but to the newbie, constructing a user interface, for an application with menus and windows, using what seems to be another language is daunting, especially since trying to get to grips with core Python is enough for the newbie. It may be a question of "patience my friend" but can I ask what the best and most seamless approach would be to create such an interface and actively link it to Python scripts? Has anyone ever developed a kind of RAD tool for Python, that would also integrate GUIs? Or rather than using an external language, is there such a thing as a Python module/extension that would include this capability? And if you think this is a long email, be aware that I have other huge question marks hanging over COM access, about which I know so little, and which would also be useful...guess I'll save that one till later huh? Thank you for your help. I realise I am diving straight in with ambitious targets, but that's what it's all about and your help will be greatly appreciated. Thank you Christophe *************************************************************************** This email message contains confidential information for the above addressee only. If you are not the intended addressee you must not disclose or use the information in any manner whatsoever. Any opinion or views contained in this email message are those of the sender, do not represent those of the Company in any way and reliance should not be placed upon its contents. Unless otherwise stated this email message is not intended to be contractually binding. Where an Agreement exists between our respective companies and there is conflict between the contents of this email message and the Agreement then the terms of that Agreement shall prevail. Abbey National Treasury Services plc. Registered in England. Registered Office: Abbey House, Baker Street, London NW1 6XL. Company Registration No: 2338548. Regulated by the SFA *************************************************************************** From Lindsay.Davies@moonshine.co.uk Fri Feb 2 13:16:41 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Fri, 2 Feb 2001 13:16:41 +0000 Subject: [Tutor] Reading and outputting HTML files In-Reply-To: <200102020157_MC2-C3F6-C82A@compuserve.com> References: <200102020157_MC2-C3F6-C82A@compuserve.com> Message-ID: On 2/2/01, Sharriff Aina wrote about '[Tutor] Reading and outputting HTML files': >I have coded a CGI script that creates HTML files, strange thing is, when >reading a HTML file, one created by the script or otherwise, I just get a >very garbled page returned to the browser. Any clues? can someone help? >this has been bugging me for 3 days now You'll need to give us more information about the problem - what exactly do you get when you request a page? The problem could be any number of things, so until there's more detail, there's not much I can suggest other than: is your server configured correctly, are you outputting the appropriate headers, have you checked the script offline? Best wishes, Lindsay From bseelinger@neteffectcorp.com Fri Feb 2 15:52:14 2001 From: bseelinger@neteffectcorp.com (Seelinger, Bruce) Date: Fri, 2 Feb 2001 10:52:14 -0500 Subject: [Tutor] String as a Variable? Message-ID: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.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. ------_=_NextPart_001_01C08D30.1CF02260 Content-Type: text/plain; charset="iso-8859-1" Another newbie question... Is there a way to have a string represent a variable. For eaxample, I have a the following: serial_number = '3' print 'ip_address_serial_' + serial_number ip_address_serial_3 Now I want to use the string ip_address_serial_3 to pull the value assigned to the variable of the same name. How can I represent the string as a variable? Thanks in advance. ------_=_NextPart_001_01C08D30.1CF02260 Content-Type: text/html; charset="iso-8859-1" String as a Variable?

Another newbie question...

Is there a way to have a string represent a variable.

For eaxample, I have a the following:

<snip>

serial_number = '3'
print 'ip_address_serial_' + serial_number
ip_address_serial_3

Now I want to use the string ip_address_serial_3 to pull
the value assigned to the variable of the same name.

How can I represent the string as a variable?

Thanks in advance.

------_=_NextPart_001_01C08D30.1CF02260-- From abreu@penguinpowered.com Fri Feb 2 16:09:15 2001 From: abreu@penguinpowered.com (Jose Alberto Abreu) Date: Fri, 02 Feb 2001 10:09:15 -0600 Subject: [Tutor] Compiling Python Scripts References: Message-ID: <3A7ADBAB.62AE374@penguinpowered.com> Deirdre Saoirse wrote: > > On Thu, 1 Feb 2001, Cameron wrote: > > > I want to compile some of my Python scripts into executable programs > > to distribute to some friends who don't have the Python interpreter... > > is there any way to do this? I was unable to find the answer in the > > documentation. > > The answer is, in part, dependent upon the platform -- which you didn't > specify. > > _Deirdre OK, I have the same question, so I'll specify the platform: Windows I already can cheerfully distribute my programs to my Linux using friends, because practically all distributions install Python by default (most of the times 1.5.2). But in all honesty you cannot ask your grandmother to download Python and go through the installation motions just so that she can run the whizbang shopping list manager(TM) that you made for her... It would be a lot easier if there was a way to incorporate the interpreter, your program, and all required modules in a self-extracting .exe That way granny would only need to doubleclick on the icon on her windows desktop to run her whizbang shopping list manager(TM) Probably this would require some closed source program like InstallShield, but hopefully our resourceful and wise elders would have already come to a Free(TM) solution. ---- Disclaimers: I do not make programs for my grandmother, I was just trying to make a point. However Whizbang Shopping List Manager is (C) and (TM) Jose Alberto Abreu 2001. Free, of course is (C) and (TM) Richard Stallman 1984. From dsh8290@rit.edu Fri Feb 2 16:23:03 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 2 Feb 2001 11:23:03 -0500 Subject: [Tutor] String as a Variable? In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Fri, Feb 02, 2001 at 10:52:14AM -0500 References: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.com> Message-ID: <20010202112302.B8120@harmony.cs.rit.edu> On Fri, Feb 02, 2001 at 10:52:14AM -0500, Seelinger, Bruce wrote: | Another newbie question... | | Is there a way to have a string represent a variable. | | For eaxample, I have a the following: | | | | serial_number = '3' | print 'ip_address_serial_' + serial_number | ip_address_serial_3 | | Now I want to use the string ip_address_serial_3 to pull | the value assigned to the variable of the same name. | | How can I represent the string as a variable? | You can do this using exec, but it is not recommended. exec is a fairly slow statement, and it can have ugly side effects. For example, suppose you end up with a name that conflicts with a local or even worse a global variable in your program? The recommended technique is to use a dictionary instead. You can have a dict, say ip_address_serials, and use the serial_number's as keys. ip_address_serials = { } serial_number = find_serial_number( ) ip_address_serials[ serial_number ] = \ "whatever value you want associated with it" for serial_number in ip_address_serials.keys() : print "ip_address_serial is:", serial_number | Thanks in advance. | HTH, -D From johnnyflynn@hotmail.com Fri Feb 2 16:23:14 2001 From: johnnyflynn@hotmail.com (John Flynn) Date: Fri, 02 Feb 2001 11:23:14 -0500 Subject: [Tutor] New to all of this Message-ID: Hi there everyone. I am wondering if anyone out there knows where I might be able to find some source code for a simple (very simple) and small text editor done completely in Python. I would like to be able to refrence this code to help learn. The things that I would need (I am totally new to all of this:)) would be something simple that would draw it's own window (not Microsoft's dumb default one) and take the text that is typped in and save it as .txt, and be able to open .txt files. That is about all, nothing more than the one that comes with Windows. I just want to use it as a tool to help learn the different actions associated with opening files, saving files, drawing a window and possibly (A LONG WAY DOWN THE ROAD) be able to write my own (Open Source Of Course!, Hey I'm a poet) text editor. Any help would be greatly appreciated. Thanks,John Flynn _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From abreu@penguinpowered.com Fri Feb 2 16:39:55 2001 From: abreu@penguinpowered.com (Jose Alberto Abreu) Date: Fri, 02 Feb 2001 10:39:55 -0600 Subject: [Tutor] Newbie questions with an anmbitious tweak! References: <29897BB9AE72D411A89B0008C773175E4B74FF@BHISHMA> Message-ID: <3A7AE2DB.2C475D7D@penguinpowered.com> "Cuny, Christophe (ANTS)" wrote: > First of all, thank you for existing. We newbies appreciate the work that > you guys put in supporting us. We support each other... Although the List Moms put on a gargantuan ammount of patience and wisdom with the rest of us (and we all love them for that!), you are expected to answer your fellow newbie questions as your knowledge of python grows... > So can I start with a basic question. In tutorials, I get referred to "using > a text editor such as notepad...". But using Python for windows I saw that > the "built-in" editor has full syntax highlighting. So the question is: do I > actually need another editor or are the tutorials referring to old versions > of Python? Its based on your preference, actually. Some people like to use incredibly complex (yet infinetly configurable) text editors dating back to the stone age. Some prefer to use the newer Integrated Developement Enviroments like IDLE. By the way check out Boa Constructor: http://sourceforge.net/projects/boa-constructor Its still green, but its gonna be awesome. > I also have a question on GUIs. I have read a bit about Tk but to the > newbie, constructing a user interface, for an application with menus and > windows, using what seems to be another language is daunting, especially > since trying to get to grips with core Python is enough for the newbie. It > may be a question of "patience my friend" It is : ) But dont worry, you will with time see Tkinter (and later WxPython) as your friend. > but can I ask what the best and > most seamless approach would be to create such an interface and actively > link it to Python scripts? Has anyone ever developed a kind of RAD tool for > Python, that would also integrate GUIs? Or rather than using an external > language, is there such a thing as a Python module/extension that would > include this capability? Boa Constructor and other proyects are aiming to do this in the near future. Also the people at ActiveState are developing a plugin for Microsoft's Visual Studio to code in Python or Perl, but I would be extremely leery of using Visual Studio for anything. > Thank you for your help. I realise I am diving straight in with ambitious > targets, but that's what it's all about and your help will be greatly > appreciated. Its ok to be ambitious, just remember that even Olympic runners learned to walk the same way we all did. ----- Jose Alberto Abreu - abreu@penguinpowered.com From mr804@users.757.org Fri Feb 2 17:07:08 2001 From: mr804@users.757.org (Mr 804) Date: Fri, 2 Feb 2001 12:07:08 -0500 (EST) Subject: [Tutor] First real program Message-ID: Hello, I'm trying to write a small python script to do some checks on a unix password file. I've run into a stubling block. I think I don't understand list 100%. I've included my code with commends on the problem part. ****************************************** import sys import string import re ### open files read it in 1 line at a time print "Loading the password file." try: f = open('/etc/passwd','r') s = f.readlines() f.close() print "loaded." print "" except IOError: print "can't open the password file. Quiting." sys.exit() ### How many elements do we got? t = len(s) print "There are %d lines." % t ## sort it s.sort() # Clean the file up. Don't need no white space before or after # also convert everything to lower case. list = [] name = [] for i in s: i = string.lower(string.rstrip(string.strip(i))) list.append(i) name.append(string.splitfields(i,":")) ^-- This part should make everything lower case, strip white space. name[] should be a list of NAMES, but I don't think I'm doing that correctly? I want the user name and no othe fields after the first : . ? if I did print name[0] it should print the first name in the password file. but it's just printing the while line. From clickron@webtv.net Fri Feb 2 17:50:30 2001 From: clickron@webtv.net (clickron@webtv.net) Date: Fri, 2 Feb 2001 12:50:30 -0500 (EST) Subject: [Tutor] opening programs Message-ID: <18403-3A7AF366-573@storefull-164.iap.bryant.webtv.net> I have windows 98 ie5.0 and downloaded python2.0. To open a program (hello.py) while in idle I click file/open/documents/hello/open is there a different or quicker way to do this? I've tried typing, python hello.py, in idle and command but I just get the error message. I really new to this and would appreciate any help. Ron From Lindsay.Davies@moonshine.co.uk Fri Feb 2 18:39:11 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Fri, 2 Feb 2001 18:39:11 +0000 Subject: [Tutor] String as a Variable? Message-ID: --============_-1230983297==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Why not use a dictionary? snv = {'sn_1' : 123, 'sn_2' : 234, 'sn_3' : 345} serial_number = '3' try: print snv['sn_' + serial_number] except KeyError, missing_key: print "The serial number '%s' is missing." % serial_number Best wishes, Lindsay On 2/2/01, Seelinger, Bruce wrote about '[Tutor] String as a Variable?': >Another newbie question... > >Is there a way to have a string represent a variable. > >For eaxample, I have a the following: > > > >serial_number = '3' >print 'ip_address_serial_' + serial_number >ip_address_serial_3 > >Now I want to use the string ip_address_serial_3 to pull >the value assigned to the variable of the same name. > >How can I represent the string as a variable? > >Thanks in advance. --============_-1230983297==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] String as a Variable?
Why not use a dictionary?

snv = {'sn_1' : 123, 'sn_2' : 234, 'sn_3' : 345}
serial_number =
'3'

try:
    print snv[
'sn_' + serial_number]
except KeyError, missing_key:
        print "The serial number '%s' is missing." % serial_number


Best wishes,

Lindsay


On 2/2/01, Seelinger, Bruce wrote about '[Tutor] String as a Variable?':
Another newbie question...

Is there a way to have a string represent a variable.

For eaxample, I have a the following:

<snip>
serial_number = '3'
print 'ip_address_serial_' + serial_number
ip_address_serial_3

Now I want to use the string ip_address_serial_3 to pull
the value assigned to the variable of the same name.

How can I represent the string as a variable?

Thanks in advance.

--============_-1230983297==_ma============-- From randrews@planhouse.com Fri Feb 2 18:45:23 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 2 Feb 2001 12:45:23 -0600 Subject: [Tutor] opening programs References: <18403-3A7AF366-573@storefull-164.iap.bryant.webtv.net> Message-ID: <004001c08d48$4de9bee0$dc00a8c0@Planhouse5> As long as your hello.py file is saved in a directory (folder) that Python knows to look in, you should be able to type >>>import hello.py in Idle to run the program. Hope this helps, Rob Andrews ----- Original Message ----- From: To: Sent: Friday, February 02, 2001 11:50 AM Subject: [Tutor] opening programs > I have windows 98 ie5.0 and downloaded python2.0. To open a program > (hello.py) while in idle I click file/open/documents/hello/open > is there a different or quicker way to do this? > > I've tried typing, python hello.py, in idle and command but I just get > the error message. I really new to this and would appreciate any help. > > Ron > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From curtis.larsen@Covance.Com Fri Feb 2 18:49:56 2001 From: curtis.larsen@Covance.Com (Curtis Larsen) Date: Fri, 02 Feb 2001 12:49:56 -0600 Subject: [Tutor] List Dup-Elim Method? Message-ID: Is there an easy way to eliminate duplicate elements in a list? (A list method I missed, maybe?) Thanks! Curtis ----------------------------------------------------- Confidentiality Notice: This e-mail transmission may contain confidential or legally privileged information that is intended only for the individual or entity named in the e-mail address. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or reliance upon the contents of this e-mail is strictly prohibited. If you have received this e-mail transmission in error, please reply to the sender, so that we can arrange for proper delivery, and then please delete the message from your inbox. Thank you. From shaleh@valinux.com Fri Feb 2 18:59:46 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 02 Feb 2001 10:59:46 -0800 (PST) Subject: [Tutor] List Dup-Elim Method? In-Reply-To: Message-ID: On 02-Feb-2001 Curtis Larsen wrote: > Is there an easy way to eliminate duplicate elements in a list? > (A list method I missed, maybe?) > no, either do: if element not in list: list.append(element) or write a function to return a list with the cruft removed. From shaleh@valinux.com Fri Feb 2 19:00:39 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 02 Feb 2001 11:00:39 -0800 (PST) Subject: [Tutor] List Dup-Elim Method? In-Reply-To: Message-ID: On 02-Feb-2001 Curtis Larsen wrote: > Is there an easy way to eliminate duplicate elements in a list? > (A list method I missed, maybe?) > or maybe you should use a hash? hash[key] = 1 hash will only have one instance of the key and hash.keys() returns the list. From deirdre@deirdre.net Fri Feb 2 19:12:07 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 2 Feb 2001 11:12:07 -0800 (PST) Subject: [Tutor] Compiling Python Scripts In-Reply-To: <3A7ADBAB.62AE374@penguinpowered.com> Message-ID: OK, I'm not a Windows user, but I distinctly recall that there WAS a way of doing it -- it wasn't compiled, it was globbing the whole thing together. I *think* what you're looking for is at: http://starship.python.net/crew/gmcm/standalones.html Afaik, it's only Windows and Linux and not other OSes; I will probably look into working on the MacOS (9 and X) support for this. On Fri, 2 Feb 2001, Jose Alberto Abreu wrote: > Deirdre Saoirse wrote: > > > > On Thu, 1 Feb 2001, Cameron wrote: > > > > > I want to compile some of my Python scripts into executable programs > > > to distribute to some friends who don't have the Python interpreter... > > > is there any way to do this? I was unable to find the answer in the > > > documentation. > > > > The answer is, in part, dependent upon the platform -- which you didn't > > specify. > > OK, I have the same question, so I'll specify the platform: Windows > > I already can cheerfully distribute my programs to my Linux using > friends, because practically all distributions install Python by default > (most of the times 1.5.2). > But in all honesty you cannot ask your grandmother to download Python > and go through the installation motions just so that she can run the > whizbang shopping list manager(TM) that you made for her... > > It would be a lot easier if there was a way to incorporate the > interpreter, your program, and all required modules in a > self-extracting .exe That way granny would only need to doubleclick on > the icon on her windows desktop to run her whizbang shopping list > manager(TM) > > Probably this would require some closed source program like > InstallShield, but hopefully our resourceful and wise elders would have > already come to a Free(TM) solution. From randrews@planhouse.com Fri Feb 2 21:00:14 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 2 Feb 2001 15:00:14 -0600 Subject: [Tutor] List Dup-Elim Method? References: Message-ID: <002e01c08d5b$24bbc640$dc00a8c0@Planhouse5> I'm working on a similar problem, but more complicated and involving a zillion real world variables. I haven't fully worked it out yet, but here are some thoughts that might help you out. If the list isn't 200,000 items long or something, you can try a brute force approach. For each item of the list, compare the item to each other item, deleting duplicates as you go, then drop a copy of that item into a new list. Or, do the same thing, but instead of deleting the dupes as you go, move them into a *dupes* list, and copy the first item into a new list. if mylist[0:1] == mylist[1:2]: mylist[1:2] = [] This code compares an item in a list to the item next to it. If the two items are equivalent, the second item is essentially removed. Hope this helps a bit, Rob Andrews > Is there an easy way to eliminate duplicate elements in a list? > (A list method I missed, maybe?) > > > Thanks! > Curtis > From tuckerg@acm.org Sat Feb 3 01:51:34 2001 From: tuckerg@acm.org (Gregory Tucker) Date: Sat, 3 Feb 2001 10:51:34 +0900 Subject: [Tutor] Reading from a GUI In-Reply-To: <000401c08659$4387f9d0$0300000a@budgester> Message-ID: Hi, I think we would all save a lot of time if there were a clear answer to your question. I can only throw in a couple observations. 1. There is actually a book called "Python and Tkinter Programming". From this standpoint, this is the most well-documented. Check out your favorite bookstore for more information. 2. There are a few pages that discuss this: http://www.python.org/doc/FAQ.html http://wxpython.org/ http://www.wxwindows.org/ http://www.scriptics.com/ 3. Personally, I haven't done enough GUI programming in EITHER environment to answer the question. 4. In many cases the better question is "What is the best way to build active web pages in Python?" You can develop CGI scripts for simpler stuff. You can use Zope for more sophisticated environments, but with a higher learning curve. I am looking for a way to get out of the (painfully) sessionless nature CGI without the overhead of Zope. PSP (a Python version of PHP?) may offer an alternative. Regardless, an HTML interface is too limiting for some applications that could be done better with WxPython or Tkinter. It looks like WxPython is is easier to use and more powerful in general. And it looks like the cross-platform support is good enough for most developers. When I am ready to tackle GUI programming under Python, even though I own the above book, I will probably look first into WxPython. But I would appreciate feedback on this as well. Regards, Greg --- Gregory Tucker Tokyo, Japan mailto:tuckerg@acm.org These opinions are my own. > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Budgester > Sent: Thursday, January 25, 2001 7:59 AM > To: 'D-Man' > Subject: RE: [Tutor] Reading from a GUI > > > > > >D-Man Wrote : > > > >What is meant by "escape code" can differ by useage. For example, in > >Eiffel you would use "%N" as the excape code for a newline. \012 is > >the octal value of the character. 0xA is the hexadeciaml value and 10 > >is the decimal value. In C/C++/Java/Perl and Python \n is used as the > >escape for a newline, but with the proper conversion you can use any > >of these. > > They are the escape code I was looking for. > > >To "read from" a GUI you need to check the docs of the gui you are > >using. In GTK, for example, there is a funciton get_text in the > >Gtk.Text widget (or some similar name). The function returns a string > >object. > > I'm currently using Tkinter, but from reading this list it seems like the > most popular Toolkit is GTK, what is the general preference for python, > i.e. best documentation, ease of use, samples etc < I'm not > trying to start > a holy war here, just peoples experiences ;-) > > > > >import string > > > >my_str = text_widget.get_text() > >modified_str = string.replace( my_str, "\n" , "
" ) > >print my_str > >pirnt modified_str > > pretty much exactly the code I was after. > > >HTH, > > Loads thanks > > I'll let you know how it goes. > > >-D > > Budgester > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From DOUGS@oceanic.com Sat Feb 3 01:58:31 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Fri, 2 Feb 2001 15:58:31 -1000 Subject: [Tutor] List Dup-Elim Method? Message-ID: <8457258D741DD411BD3D0050DA62365907A5B6@huina.oceanic.com> I think the Python idiom I've seen for this uses a dictionary as a temporary holder. The dictionary needs unique keys so the following will leave a list without duplicates: theDict = {} theList = [1, 2, 4, 6, 21, 3, 8, 5, 3, 8] for element in theList: theDict[element] = None theList = theDict.keys() -Doug- > -----Original Message----- > From: Curtis Larsen [mailto:curtis.larsen@Covance.Com] > Sent: Friday, February 02, 2001 8:50 AM > To: tutor@python.org > Subject: [Tutor] List Dup-Elim Method? > > > Is there an easy way to eliminate duplicate elements in a list? > (A list method I missed, maybe?) > > > Thanks! > Curtis > > > > ----------------------------------------------------- > Confidentiality Notice: This e-mail transmission > may contain confidential or legally privileged > information that is intended only for the individual > or entity named in the e-mail address. If you are not > the intended recipient, you are hereby notified that > any disclosure, copying, distribution, or reliance > upon the contents of this e-mail is strictly prohibited. > > If you have received this e-mail transmission in error, > please reply to the sender, so that we can arrange > for proper delivery, and then please delete the message > from your inbox. Thank you. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From AquaRock7@aol.com Sat Feb 3 03:34:01 2001 From: AquaRock7@aol.com (AquaRock7@aol.com) Date: Fri, 2 Feb 2001 22:34:01 EST Subject: [Tutor] RE: user interaction Message-ID: --part1_c9.ce89898.27acd629_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit The python equivalent of INPUT in BASIC is raw_input() and input(). Use it : inputstr = raw_input("What is your name? ") # this is for text entry print inputstr inputnum = input("What is your age?") # for numbers only - text raises error print age There ya go! ~D --part1_c9.ce89898.27acd629_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit The python equivalent of INPUT in BASIC is raw_input() and input().  Use it
like this:



inputstr = raw_input("What is your name? ") # this is for text entry
print inputstr

inputnum = input("What is your age?") # for numbers only - text raises error
print age

There ya go!

~D
--part1_c9.ce89898.27acd629_boundary-- From ccurrie@lcc.net Sat Feb 3 04:25:56 2001 From: ccurrie@lcc.net (Cameron) Date: Fri, 2 Feb 2001 22:25:56 -0600 Subject: [Tutor] Compiling Python Scripts References: <20010202170118.A071DF031@mail.python.org> Message-ID: <001801c08d99$68ac2a00$0101a8c0@ccurrie> Ah, that had slipped my mind completely. I'd like to know the process for compiling my scripts on Windows platforms. Knowing the process on Linux would be great as well, but I give priority to Windows as more of my friends use it. Also, does anyone know of a free web hosting service that allows you to use your own Python CGI scripts, and that also has FTP access? I have gone through tons of search engine results and have yet to find a satisfying service. > Deirdre Saoirse wrote: > > > > On Thu, 1 Feb 2001, Cameron wrote: > > > > > I want to compile some of my Python scripts into executable programs > > > to distribute to some friends who don't have the Python interpreter... > > > is there any way to do this? I was unable to find the answer in the > > > documentation. > > > > The answer is, in part, dependent upon the platform -- which you didn't > > specify. > > > > _Deirdre From jcm@bigskytel.com Thu Feb 1 06:02:32 2001 From: jcm@bigskytel.com (David Porter) Date: Wed, 31 Jan 2001 23:02:32 -0700 Subject: [Tutor] os.popen: writing to In-Reply-To: <001301c08b7a$ab8a1c40$2c829e89@poseidon>; from jpl@global.co.za on Wed, Jan 31, 2001 at 01:40:54PM +0200 References: <001301c08b7a$ab8a1c40$2c829e89@poseidon> Message-ID: <20010131230231.A3732@bigskytel.com> * James Lockley : <...> > i now want to go to the next step and get rid of the batch files... i need > to open a pipe to a command and then write the command arguments to it. <...> > (this in a dos window works fine: D:\Work\Current>c:\abaqus\5.8-14\abaqus.exe post) How about: import os os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') David From deirdre@deirdre.net Sat Feb 3 05:19:47 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 2 Feb 2001 21:19:47 -0800 (PST) Subject: [Tutor] Compiling Python Scripts In-Reply-To: <001801c08d99$68ac2a00$0101a8c0@ccurrie> Message-ID: On Fri, 2 Feb 2001, Cameron wrote: > Ah, that had slipped my mind completely. I'd like to know the process > for compiling my scripts on Windows platforms. Knowing the process on > Linux would be great as well, but I give priority to Windows as more > of my friends use it. See the other reference. I'm somewhat at a loss as are many regulars in that we do a lot of Unix, but not Windows. I spend my day time on Linux and night time on MacOS X. > Also, does anyone know of a free web hosting service that allows you > to use your own Python CGI scripts, and that also has FTP access? I > have gone through tons of search engine results and have yet to find a > satisfying service. I don't know of a free one; for deirdre.net I use he.net which has a really excellent value package (imho): http://www.he.net/spaceservices.html I've been with them for two years. I've taken a tour of their colo space and it's *quite* impressive. No affiliation, yada yada yada, just been there > 2 years and happy. I mean, how many places give you crontab access? _Deirdre From sheila@thinkspot.net Sat Feb 3 05:27:43 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 02 Feb 2001 21:27:43 -0800 Subject: [Tutor] Compiling Python Scripts In-Reply-To: <001801c08d99$68ac2a00$0101a8c0@ccurrie> References: <20010202170118.A071DF031@mail.python.org> <001801c08d99$68ac2a00$0101a8c0@ccurrie> Message-ID: <20010203052807.9846BF16D@mail.python.org> On Fri, 2 Feb 2001 22:25:56 -0600, "Cameron" wrote about [Tutor] Compiling Python Scripts: :Also, does anyone know of a free web hosting service that allows you to use :your own Python CGI scripts, and that also has FTP access? I have gone :through tons of search engine results and have yet to find a satisfying :service. Man, I would be seriously interested in that! Right now, I have an account at free.prohosting.com, but they only allow Perl scripts. You can write and install your own, but only Perl, so far as I can tell. And I don't really write Perl. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From trainlist@yahoo.com Sat Feb 3 06:39:43 2001 From: trainlist@yahoo.com (trainlist@yahoo.com) Date: Fri, 02 Feb 2001 22:39:43 -0800 Subject: [Tutor] List of Buyers for Training Services & Products Message-ID: Hi, Recently you had talked to us about some of the courseware materials we carry for the needs of your customers. I thought you might also be interested in a proprietary list of buyers for training related services and products we have developed in house. Our list is comprehensive and includes tons of prospects you can reach right now to market your services and products to. I'd be happy to answer any questions you may have. Feel free to e-mail me with your inquiries, or call 780-998-4066. We also have lists for Human Resources Departments, Personnel contacts, etc. Best Regard D. Adams From deirdre@deirdre.net Sat Feb 3 09:15:32 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 3 Feb 2001 01:15:32 -0800 (PST) Subject: Ugh! Re: [Tutor] List of Buyers for Training Services & Products In-Reply-To: Message-ID: Sorry about the spammer. Abuse has been contacted; his email address has been blacklisted on the list and he's been unsubscribed. We'll now return you to your regular list.... _Deirdre (listmom) From tim.one@home.com Sat Feb 3 09:43:14 2001 From: tim.one@home.com (Tim Peters) Date: Sat, 3 Feb 2001 04:43:14 -0500 Subject: [Tutor] List Dup-Elim Method? In-Reply-To: <002e01c08d5b$24bbc640$dc00a8c0@Planhouse5> Message-ID: If the elements of a list are hashable, the method using a dict will be by far the fastest if the list is large. If the elements are not hashable (for example, a list of lists), but can be sorted, still much quicker than brute force (yet still much slower than using a temporary dict!) is this: def dupfree(x): """Remove all duplicates from list x, in place. The elements of x must enjoy a total ordering. """ n = len(x) if n > 1: x.sort() last = x[0] i = avail = 1 while i < n: if x[i] != last: x[avail] = last = x[i] avail += 1 i += 1 del x[avail:] That requires Python 2.0, because of the "+=" thingies. Example: >>> x = [[1, 2], [3, 4]] >>> x *= 10 >>> x [[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]] >>> dupfree(x) >>> x [[1, 2], [3, 4]] >>> How does it work? Sorting the list brings all the equal elements next to each other. (Note: Many sorting routines don't work very quickly when there are lots of equal elements, but Python's does. I know that because I wrote Python's list.sort() .) After all the equal elements are adjacent, it just marches across the list once, keeping track of when the list element at index i *changes*. When it does, it moves that not-seen-before element toward the front of the list, and moves on skipping over the chunk of elements equal to *it*. Finally, it gets rid of the list positions no longer needed (the "del" stmt). Of course there's nothing to do if the list doesn't have at least two elements to start, so it checks for that first. It *has* to avoid going into the main body if the list is empty, because then "last = x[0]" would blow up. Since it has to check for that anyway, it doesn't cost any more to make sure there are at least two things in the list. This isn't an easy algorithm -- the steps are delicate. If you can use the dict method instead, do so! what-you-can-assume-constrains-what-you-can-do-ly y'rs - tim From clickron@webtv.net Sat Feb 3 15:11:08 2001 From: clickron@webtv.net (clickron@webtv.net) Date: Sat, 3 Feb 2001 10:11:08 -0500 (EST) Subject: [Tutor] opening programs Message-ID: <3275-3A7C1F8C-5610@storefull-168.iap.bryant.webtv.net> >As long as your hello.py file is saved in a >directory (folder) that Python knows to >look in, you should be able to type >>>import hello.py >in Idle to run the program. >Hope this helps, >Rob Andrews I'm afraid that doesn't work. Do I have to learn dos so I can set the path? If there is an easy tutorial on how to do this let me know please I'm really getting discouraged. Ron From gcs@agentsinside.com Sat Feb 3 15:45:09 2001 From: gcs@agentsinside.com (GCS) Date: Sat, 3 Feb 2001 16:45:09 +0100 Subject: [Tutor] Newbie, get array from the url field Message-ID: <20010203164509.A11570@esparrall.udg.es> Hello, I would like to do a form handling. The URL looks like this: http://somewhere/somedir/somescript.py?variable[]=value1&variable[]=value2 How can I get the value1 and value2 in an array? If there would be only one 'variable[]', then list=cgi.SvFormContentDict() if list.has_key("gcs"): text=list["gcs"] enough. But I get problems because of there are more than values ofcourse. Thanks all the replies in advance, GCS Ps: Is the list really no searchable? From AquaRock7@aol.com Sat Feb 3 18:47:55 2001 From: AquaRock7@aol.com (AquaRock7@aol.com) Date: Sat, 3 Feb 2001 13:47:55 EST Subject: [Tutor] Re: opening programs Message-ID: <55.10b44c49.27adac5b@aol.com> --part1_55.10b44c49.27adac5b_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I am assuming you rin Windows -- you mentioned DOS. Go to your C:\ directory. There should be a file called "AUTOEXEC.BAT". Open it with Notepad. Mine looks like this: @C:\PROGRA~1\NORTON~1\NAVDX.EXE /Startup @Echo Off Set Blaster= A220 I5 D1 PATH=%PATH%;"C:\Python";"C:\qb45" The first line is for my anti-virus software -- calls startup scan. The secnod line tells DOS not to display what it is doing on the screen, only display what you tell it to display (using the DOS print command). The third is my sound card settings. The fourth is the path variable, thats what we are intrested in. Add the following line to your path statement: "C:\yourPythonDirectory" (w/o the quotes). Now my path statement looks like this: for example, your path statement could be: PATH=%PATH%;"C:\Python". Now, when you type python at the command prompt, you should get the interpreter prompt ">>>". If you do not have a path statement, create one. Put it on the lowest possible line but above a line that says "win" (if there is a line called win - if not just do it on the last line.) If you do not have an AUTOEXEC.BAT file, don't worry, just create one. Now, in order to run your program, change to the directory where the program is located. Do this by typing "cd\" at the dos prompt. Now you are at the root directory (C:\>). Now type "cd python\prog" or whatever directory the program is located. Now your prompt should look something like this: "C:\Python\pyprog>" Now type "python hello.py" to run the program. (FYI what dos says is open hello.py with the program python (the interpreter).) Tell me if that didnt work. ~Dustin --part1_55.10b44c49.27adac5b_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit      I am assuming you rin Windows -- you mentioned DOS.
      Go to your C:\ directory.  There should be a file called
"AUTOEXEC.BAT".  Open it with Notepad.  Mine looks like this:

@C:\PROGRA~1\NORTON~1\NAVDX.EXE /Startup
@Echo Off
Set Blaster= A220 I5 D1
PATH=%PATH%;"C:\Python";"C:\qb45"

      The first line is for my anti-virus software -- calls startup scan.  
The secnod line tells DOS not to display what it is doing on the screen, only
display what you tell it to display (using the DOS print command).  The third
is my sound card settings.  The fourth is the path variable, thats what we
are intrested in.
      Add the following line to your path statement:  
"C:\yourPythonDirectory" (w/o the quotes).  Now my path statement looks like
this:  for example, your path statement could be:  PATH=%PATH%;"C:\Python".  
Now, when you type python at the command prompt, you should get the
interpreter prompt ">>>".
      If you do not have a path statement, create one.  Put it on the lowest
possible line but above a line that says "win" (if there is a line called win
- if not just do it on the last line.)
      If you do not have an AUTOEXEC.BAT file, don't worry, just create one.
      Now, in order to run your program, change to the directory where the
program is located.  Do this by typing "cd\" at the dos prompt.  Now you are
at the root directory (C:\>).  Now type "cd python\prog" or whatever
directory the program is located.  Now your prompt should look something like
this: "C:\Python\pyprog>"  Now type "python hello.py" to run the program.  
(FYI what dos says is open hello.py with the program python (the
interpreter).)
      Tell me if that didnt work.
~Dustin
--part1_55.10b44c49.27adac5b_boundary-- From wheelege@tsn.cc Sun Feb 4 01:07:27 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sun, 4 Feb 2001 12:07:27 +1100 Subject: [Tutor] opening programs References: <3275-3A7C1F8C-5610@storefull-168.iap.bryant.webtv.net> Message-ID: <007f01c08e46$d79205e0$a410fea9@glen> If all your trying to do is run a script, you can do it within the environment your working (i.e IDLE, Activestate Activepython) if your writing them as text files then saving then as *.py files then you can still open them in these programs then choose 'Run Script' from one of the menus. I missed all the previous messages on this, so if I am totally unhelpful - sorry :) Glen. ----- Original Message ----- From: To: Sent: Sunday, February 04, 2001 2:11 AM Subject: [Tutor] opening programs > >As long as your hello.py file is saved in a >directory (folder) that > Python knows to >look in, you should be able to type > >>>import hello.py > >in Idle to run the program. > >Hope this helps, > >Rob Andrews > > I'm afraid that doesn't work. Do I have to learn dos so I can set the > path? If there is an easy tutorial on how to do this let me know please > I'm really getting discouraged. > > Ron > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From wheelege@tsn.cc Sun Feb 4 12:28:31 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sun, 4 Feb 2001 23:28:31 +1100 Subject: [Tutor] Tkinter - Destroying windows, destroying widgets Message-ID: <001801c08ea5$fcbf08e0$a410fea9@glen> This is a multi-part message in MIME format. ------=_NextPart_000_0015_01C08F02.2F800700 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hey all, I was just writing up a little tkinter app (a game, actually) and I = have hit a wall. My predicament, is that I want to destroy an object = (right word?) but I want to do it in a function...for example in this = code : from Tkinter import * def die(): l.destroy() ## here is the problem - root.l.destroy() does not work = either - I think since variables are local in functions it doesn't have = any clue as to the existence of the label "l" print 'yo' =20 raw_input("hi") root =3D Tk() root.title('jim') l =3D Label(root, text=3D'hi im root').pack() second =3D Toplevel(root) b =3D Button(root, text=3D'yo', command=3Ddie).pack() mainloop() No matter how hard I try I cannot kill the label "l" using the button, = and have it do other things as well. Say I wanted to destroy a widget = in a different window?? That label is in the same toplevel. I just = know there is a way to say something akin to "In the widget 'root' is a = widget 'l' - kill it" but for the life of me I cannot find it. You = can't pass a widget as an argument using lambda, either - I tried tho :) I've looked in John Grayson's book and the python docs but I can't = find anything. Help! Thanks, Glen. ------=_NextPart_000_0015_01C08F02.2F800700 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hey all,
 
  I was just writing up a little tkinter app (a game, = actually) and I=20 have hit a wall.  My predicament, is that I want to destroy an = object=20 (right word?) but I want to do it in a function...for example in this = code=20 :
 
from Tkinter import *
 
def die():
    l.destroy() ## here is the problem = -=20 root.l.destroy() does not work either - I think since variables are = local in=20 functions it doesn't have any clue as to the existence of the label=20 "l"
    print 'yo'    =20
    raw_input("hi")
 
root =3D Tk()
root.title('jim')
l =3D Label(root, text=3D'hi = im=20 root').pack()
second =3D Toplevel(root)
b =3D Button(root, = text=3D'yo',=20 command=3Ddie).pack()
 
mainloop()
 
  No matter how hard I try I cannot kill the label "l" using = the=20 button, and have it do other things as well.  Say I wanted to = destroy=20 a widget in a different window??  That label is in the same = toplevel. =20 I just know there is a way to say something akin to "In the widget = 'root' is a=20 widget 'l' - kill it" but for the life of me I cannot find it.  You = can't=20 pass a widget as an argument using lambda, either - I tried tho :)
  I've looked in John Grayson's book and the python docs but I = can't=20 find anything.  Help!
 
  Thanks,
  Glen.
------=_NextPart_000_0015_01C08F02.2F800700-- From rick@niof.net Sun Feb 4 13:13:14 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 4 Feb 2001 08:13:14 -0500 Subject: [Tutor] Tkinter - Destroying windows, destroying widgets In-Reply-To: <001801c08ea5$fcbf08e0$a410fea9@glen>; from wheelege@tsn.cc on Sun, Feb 04, 2001 at 11:28:31PM +1100 References: <001801c08ea5$fcbf08e0$a410fea9@glen> Message-ID: <20010204081314.B29265@tc.niof.net> One of the advantages of using classes to deal with TKinter is that you in effect get 'global' variables for free. If within a class you do self.second = Toplevel(root) then your destroy function can say self.second.destroy() since 'self' is always passed as the first argument to all methods (functions within a class). On Sun, Feb 04, 2001 at 11:28:31PM +1100, Glen Wheeler wrote: > Hey all, > > I was just writing up a little tkinter app (a game, actually) and I > have hit a wall. My predicament, is that I want to destroy an object > (right word?) but I want to do it in a function...for example in this > code : > > from Tkinter import * > > def die(): l.destroy() ## here is the problem - root.l.destroy() does > not work either - I think since variables are local in functions it > doesn't have any clue as to the existence of the label "l" > print 'yo' > raw_input("hi") > > root = Tk() > root.title('jim') > l = Label(root, text='hi im root').pack() > second = Toplevel(root) > b = Button(root, text='yo', command=die).pack() > > mainloop() > > No matter how hard I try I cannot kill the label "l" using the button, > and have it do other things as well. Say I wanted to destroy a widget > in a different window?? That label is in the same toplevel. I just > know there is a way to say something akin to "In the widget 'root' is > a widget 'l' - kill it" but for the life of me I cannot find it. You > can't pass a widget as an argument using lambda, either - I tried tho > :) > > I've looked in John Grayson's book and the python docs but I can't > find anything. Help! > > Thanks, Glen. -- "Good intentions will always be pleaded for every assumption of authority. It is hardly too strong to say that the constitution was made to guard the people against the dangers of good intentions. There are men in all ages who mean to govern well, but they mean to govern. They promise to be good masters, but they mean to be masters." -- Noah Webster Rick Pasotto email: rickp@telocity.com From arcege@shore.net Sun Feb 4 14:00:36 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 4 Feb 2001 09:00:36 -0500 (EST) Subject: [Tutor] Tkinter - Destroying windows, destroying widgets In-Reply-To: <001801c08ea5$fcbf08e0$a410fea9@glen> from "Glen Wheeler" at Feb 04, 2001 11:28:31 PM Message-ID: <200102041400.JAA11646@northshore.shore.net> > > This is a multi-part message in MIME format. > > ------=_NextPart_000_0015_01C08F02.2F800700 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > Hey all, > > I was just writing up a little tkinter app (a game, actually) and I = > have hit a wall. My predicament, is that I want to destroy an object = > (right word?) but I want to do it in a function...for example in this = > code : > > from Tkinter import * > > def die(): > l.destroy() ## here is the problem - root.l.destroy() does not work = > either - I think since variables are local in functions it doesn't have = > any clue as to the existence of the label "l" > print 'yo' =20 > raw_input("hi") > > root =3D Tk() > root.title('jim') > l =3D Label(root, text=3D'hi im root').pack() > second =3D Toplevel(root) > b =3D Button(root, text=3D'yo', command=3Ddie).pack() > > mainloop() > > No matter how hard I try I cannot kill the label "l" using the button, = > and have it do other things as well. Say I wanted to destroy a widget = > in a different window?? That label is in the same toplevel. I just = > know there is a way to say something akin to "In the widget 'root' is a = > widget 'l' - kill it" but for the life of me I cannot find it. You = > can't pass a widget as an argument using lambda, either - I tried tho :) > I've looked in John Grayson's book and the python docs but I can't = > find anything. Help! You have the right idea, but if you print "l", it is set to None, not to an object. That is because the pack() method returns None. You will want to use: l = Label(root, text = 'hi im root') l.pack() I would suggest however, creating a class (often a subclass of Frame) to represent what you want, setting attributes for the widgets that you wish to access later: class SpamEggs(Frame): def __init__(self, master=None, labeltxt='', buttontxt=''): Frame.__init__(self, master) self.l = Label(self, text=labeltxt) self.b = Button(self, text=buttontxt, command=self.die) self.l.pack() self.b.pack() def die(self): if self.l: self.l.destroy() self.l = None # so we do not destroy it twice root = Tk() SpamEggs(root, 'hi im root', 'yo').pack() root.mainloop() Good luck, -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From clickron@webtv.net Sun Feb 4 19:01:01 2001 From: clickron@webtv.net (clickron@webtv.net) Date: Sun, 4 Feb 2001 14:01:01 -0500 (EST) Subject: [Tutor] opening programs Message-ID: <3294-3A7DA6ED-1134@storefull-168.iap.bryant.webtv.net> Thanks everybody. I think I'll just keep doing things like I have been until I'm a little more comfortable with changing the path. I'm kind of afraid to go in there and mess around when I'm not that sure of myself. Thanks again, Ron From amsterdamn_2000@yahoo.com Sun Feb 4 19:11:03 2001 From: amsterdamn_2000@yahoo.com (Dan Zalewski) Date: Sun, 4 Feb 2001 11:11:03 -0800 (PST) Subject: [Tutor] intro to python Message-ID: <20010204191103.66268.qmail@web11502.mail.yahoo.com> --0-1299095577-981313863=:65740 Content-Type: text/plain; charset=us-ascii I know absolutely nothing about python. I was wondering if you could tell me of a good book that might help me to learn the language and maybe a website with some tutorials and stuff/ thankyou -Dan --------------------------------- Do You Yahoo!? - Get personalized email addresses from Yahoo! Mail Personal Address - only $35 a year! --0-1299095577-981313863=:65740 Content-Type: text/html; charset=us-ascii I know absolutely nothing about python. I was wondering if you could tell me of a good book that might help me to learn the language and maybe a website with some tutorials and stuff/ thankyou

-Dan



Do You Yahoo!?
- Get personalized email addresses from Yahoo! Mail Personal Address - only $35 a year! --0-1299095577-981313863=:65740-- From tim@johnsons-web.com Sun Feb 4 21:40:38 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 4 Feb 2001 12:40:38 -0900 Subject: [Tutor] intro to python References: <20010204191103.66268.qmail@web11502.mail.yahoo.com> Message-ID: <01020412434204.01088@shecom> On Sun, 04 Feb 2001, Dan Zalewski wrote: > >%_I know absolutely nothing about python. I was wondering if you could tell me of a good book that might help me to learn the language and maybe a website with some tutorials and stuff/ thankyou www.python.org for distributions. A fine tutorial by Guido is linked from the opening page, I believe. As a newbie myself, I am currently working from : "Teach Yourself Python in 24 Hours" by Van Langingham. I expect you'll see some more book recommendations from other list members, and I'm looking forward to their comments as well. Regards -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From tim@johnsons-web.com Sun Feb 4 21:54:40 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 4 Feb 2001 12:54:40 -0900 Subject: [Tutor] How do I iterate through object attributes References: <20010204191103.66268.qmail@web11502.mail.yahoo.com> Message-ID: <01020413003105.01088@shecom> Newbie question here: I would like to be able to iterate through a function's attributes and return values for them: Code is below: def f(): "f() doc string" z = 720 x = 840 f_dir = dir(f) print "f() attributes:",f_dir f_attr = f_dir[0] print "first attribute:", f_attr print f.__doc__ for attr in f_dir: print attr #print f.attr #This Code generates AttributeError To restate: How may I reference the value for one member of the attribute list of a function without the literal name of that attribute. I hope I'm phrasing this question properly. TIA -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From scarblac@pino.selwerd.nl Sun Feb 4 22:35:17 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 4 Feb 2001 23:35:17 +0100 Subject: [Tutor] How do I iterate through object attributes In-Reply-To: <01020413003105.01088@shecom>; from tim@johnsons-web.com on Sun, Feb 04, 2001 at 12:54:40PM -0900 References: <20010204191103.66268.qmail@web11502.mail.yahoo.com> <01020413003105.01088@shecom> Message-ID: <20010204233517.A26679@pino.selwerd.nl> On Sun, Feb 04, 2001 at 12:54:40PM -0900, Tim Johnson wrote: > Newbie question here: > I would like to be able to iterate through a function's attributes and return > values for them: Code is below: > def f(): > "f() doc string" > z = 720 > x = 840 > f_dir = dir(f) > print "f() attributes:",f_dir > f_attr = f_dir[0] > print "first attribute:", f_attr > print f.__doc__ > for attr in f_dir: > print attr > #print f.attr #This Code generates AttributeError > > To restate: How may I reference the value for one member of > the attribute list of a function without the literal name of that attribute. print getattr(f, attr) -- Remco Gerlich From wheelege@tsn.cc Mon Feb 5 06:09:16 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 5 Feb 2001 17:09:16 +1100 Subject: [Tutor] Tkinter - Destroying windows, destroying widgets References: <200102041400.JAA11646@northshore.shore.net> Message-ID: <001501c08f3a$2c132060$a410fea9@glen> Thanks alot Mike and Rick - yet again the secret key to all my problems lies in classes :) I already had to convert almost everything into classes - seems as though I've got to do the lot. Thanks alot, Glen (busily converting python code) ----- Original Message ----- From: Michael P. Reilly To: Glen Wheeler Cc: Sent: Monday, February 05, 2001 1:00 AM Subject: Re: [Tutor] Tkinter - Destroying windows, destroying widgets > > > > This is a multi-part message in MIME format. > > > > ------=_NextPart_000_0015_01C08F02.2F800700 > > Content-Type: text/plain; > > charset="iso-8859-1" > > Content-Transfer-Encoding: quoted-printable > > > > Hey all, > > > > I was just writing up a little tkinter app (a game, actually) and I = > > have hit a wall. My predicament, is that I want to destroy an object = > > (right word?) but I want to do it in a function...for example in this = > > code : > > > > from Tkinter import * > > > > def die(): > > l.destroy() ## here is the problem - root.l.destroy() does not work = > > either - I think since variables are local in functions it doesn't have = > > any clue as to the existence of the label "l" > > print 'yo' =20 > > raw_input("hi") > > > > root =3D Tk() > > root.title('jim') > > l =3D Label(root, text=3D'hi im root').pack() > > second =3D Toplevel(root) > > b =3D Button(root, text=3D'yo', command=3Ddie).pack() > > > > mainloop() > > > > No matter how hard I try I cannot kill the label "l" using the button, = > > and have it do other things as well. Say I wanted to destroy a widget = > > in a different window?? That label is in the same toplevel. I just = > > know there is a way to say something akin to "In the widget 'root' is a = > > widget 'l' - kill it" but for the life of me I cannot find it. You = > > can't pass a widget as an argument using lambda, either - I tried tho :) > > I've looked in John Grayson's book and the python docs but I can't = > > find anything. Help! > > You have the right idea, but if you print "l", it is set to None, not > to an object. That is because the pack() method returns None. You > will want to use: > l = Label(root, text = 'hi im root') > l.pack() > > I would suggest however, creating a class (often a subclass of Frame) > to represent what you want, setting attributes for the widgets that you > wish to access later: > > class SpamEggs(Frame): > def __init__(self, master=None, labeltxt='', buttontxt=''): > Frame.__init__(self, master) > self.l = Label(self, text=labeltxt) > self.b = Button(self, text=buttontxt, command=self.die) > self.l.pack() > self.b.pack() > def die(self): > if self.l: > self.l.destroy() > self.l = None # so we do not destroy it twice > > root = Tk() > SpamEggs(root, 'hi im root', 'yo').pack() > root.mainloop() > > Good luck, > -Arcege > > -- > ------------------------------------------------------------------------ > | Michael P. Reilly, Release Manager | Email: arcege@shore.net | > | Salem, Mass. USA 01970 | | > ------------------------------------------------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From brian@www.coolnamehere.com Mon Feb 5 07:34:13 2001 From: brian@www.coolnamehere.com (brian) Date: Sun, 4 Feb 2001 23:34:13 -0800 Subject: [Tutor] Python Baby Steps Tutorial Message-ID: <20010204233413.B15656@www.coolnamehere.com> Hi All, I made a very simple tutorial for getting started with Python. The link is currently: http://www.coolnamehere.com/z/programming/python/pythontut.asp Its focus is on using Python in Windows, just because I'm too lazy to detail using RPM's or compiling Python from code. Mainly, it's just a warmup for the "real" tutorials out there. It was originally written for my Dad, who had only worked with QBASIC in some distant past. Give it a go-over and let me know what I can polish up! Thanks, Brian Wisti -- ------------------------------------------------------------------------------- Brian Wisti brian@coolnamehere.com http://www.coolnamehere.com From NHYTRO@compuserve.com Mon Feb 5 07:55:45 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Mon, 5 Feb 2001 02:55:45 -0500 Subject: [Tutor] Reading and outputting HTML Message-ID: <200102050255_MC2-C447-B895@compuserve.com> Sorry for taking so long to post my script. Below is the code I used, please excuse its " roughness", I=B4m a 3 Weel old newbie: #!C:/Python/python.exe -u print "Content-Type: text/html\n\n" import cgi import webbrowser # # form =3D cgi.FieldStorage() print "saving html to file..." htmlfile =3D open("./webpages/tester.html", "w") htmlfile.write(form["editarea"].value) test =3D htmlfile.read() print "test file output..." print test webbrowser.open("./webpages/tester.html") I would like to display the generated HTML , but the page Displays garble= d on the SERVER!!?? I just can=B4t get my code to edit, store and re-displa= y HTML files :-( Thanks for your anticipated help! Sharriff Message text written by INTERNET:tutor@python.org >* Sharriff Aina : > I have coded a CGI script that creates HTML files, strange thing is, wh= en > reading a HTML file, one created by the script or otherwise, I just get= a > very garbled page returned to the browser. = You seem to be saying above that your browser is broken ("created by the script or otherwise..."). Could you clarify you message? Also posting example code and errors helps greatly.< From rob@jam.rr.com Mon Feb 5 12:31:24 2001 From: rob@jam.rr.com (R. A.) Date: Mon, 05 Feb 2001 06:31:24 -0600 Subject: [Tutor] Python Baby Steps Tutorial References: <20010204233413.B15656@www.coolnamehere.com> Message-ID: <3A7E9D1C.7CA4072@jam.rr.com> Groovy. I added a link to your tutorial from the Useless links page, so hopefully you'll be graced with a bit more feedback. Rob brian wrote: > > Hi All, > > I made a very simple tutorial for getting started with Python. The link is currently: > > http://www.coolnamehere.com/z/programming/python/pythontut.asp > > Its focus is on using Python in Windows, just because I'm too lazy to detail using RPM's or compiling Python from code. Mainly, it's just a warmup for the "real" tutorials out there. It was originally written for my Dad, who had only worked with QBASIC in some distant past. > > Give it a go-over and let me know what I can polish up! > > Thanks, > Brian Wisti > > -- > ------------------------------------------------------------------------------- > Brian Wisti > brian@coolnamehere.com > http://www.coolnamehere.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Visit the Useless Python Repository! http://www.lowerstandard.com/python/pythonsource.html From arcege@shore.net Mon Feb 5 12:45:14 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Feb 2001 07:45:14 -0500 (EST) Subject: [Tutor] Reading and outputting HTML In-Reply-To: <200102050255_MC2-C447-B895@compuserve.com> from "Sharriff Aina" at Feb 05, 2001 02:55:45 AM Message-ID: <200102051245.HAA24165@northshore.shore.net> > #!C:/Python/python.exe -u > > print "Content-Type: text/html\n\n" > > import cgi > import webbrowser > # > # > form =3D cgi.FieldStorage() > print "saving html to file..." > htmlfile =3D open("./webpages/tester.html", "w") > htmlfile.write(form["editarea"].value) > test =3D htmlfile.read() > print "test file output..." > print test > > webbrowser.open("./webpages/tester.html") > > > > I would like to display the generated HTML , but the page Displays garble= > d > on the SERVER!!?? I just can=B4t get my code to edit, store and re-displa= > y > HTML files :-( Looking at the code, the "blaring" errors are that you: a) Reading to a file that is only openned for writting; change the openning option from 'w' to 'w+', for "read and write". b) Should be reading an empty string from htmlfile since you haven't moved the file pointer back to the beginning of the file. With every file, there is a pointer where you are looking, writing to the file moves it. Reading would pick up where it left off, in this case at the end of the file. You want to use the "seek" method to move the file pointer to the beginning. htmlfile = open("./webpages/tester.html", "w+") htmlfile.write(form["editarea"].value) htmlfile.seek(0) test = htmlfile.read() c) You are attempting to open a browser (client) session from a web server. There is already a browser open (which submitted your form); you should be using that, by writing to stdout. You are already doing that with the print statements. Since you want to tell the browser to open another file, you would want to send a redirection HTTP response. Change the first print to: print 'Location: /tester.html' print This assumes that \webpages\ is your DocumentRoot setting in your web server software. Good luck, -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From christian.folini@unifr.ch Mon Feb 5 14:31:41 2001 From: christian.folini@unifr.ch (christian folini) Date: Mon, 5 Feb 2001 15:31:41 +0100 Subject: [Tutor] how to check for stdin? In-Reply-To: <200102051245.HAA24165@northshore.shore.net>; from arcege@shore.net on Mon, Feb 05, 2001 at 13:45:14 +0100 References: <200102050255_MC2-C447-B895@compuserve.com> <200102051245.HAA24165@northshore.shore.net> Message-ID: <20010205153141.E1442@histoirepc19> Hi there, I would like to check for STDIN in a script. Now there is no problem with sys.stdin, if there really is STDIN, but as soon as no STDIN is present, python stops and wait for me to enter some input. How can i check if there actually _is_ STDIN before i attempt to read it? christian P.S. sorry, if this has been asked before, i did not find anything in the web about it. From arcege@shore.net Mon Feb 5 15:45:30 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Feb 2001 10:45:30 -0500 (EST) Subject: [Tutor] how to check for stdin? In-Reply-To: <20010205153141.E1442@histoirepc19> from "christian folini" at Feb 05, 2001 03:31:41 PM Message-ID: <200102051545.KAA22130@northshore.shore.net> > Hi there, > > I would like to check for STDIN in a script. Now there is no > problem with sys.stdin, if there really is STDIN, but as soon > as no STDIN is present, python stops and wait for me to enter > some input. > > How can i check if there actually _is_ STDIN before i attempt to > read it? > > christian > > P.S. sorry, if this has been asked before, i did not find anything > in the web about it. I doubt that you could check on windoze, but in a UNIX environment there is knowledge of whether a open file is attached to a terminal or not. A method called "isatty()" returns true if associated with a terminal. $ cat eggs.py import sys if not sys.stdin.istty(): # redirected from file or pipe stdin_data = sys.stdin.read() else: stdin_data = 'not read from stdin' print `stdin_data` $ echo toast | python eggs.py 'toast\012' $ python eggs.py 'not read from stdin' $ -Arcege PS: I don't think it has been asked in years actually. ;) -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From bobhicks@adelphia.net Mon Feb 5 17:16:28 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Mon, 05 Feb 2001 12:16:28 -0500 Subject: [Tutor] FW: Ways to learn Python In-Reply-To: Message-ID: ---------- From: Robert L Hicks Date: Mon, 05 Feb 2001 12:15:29 -0500 To: Subject: Ways to learn Python http://www.crosswinds.net/~agauld/ http://www.python.org/doc/ "Learning to program using Python" by A. Gauld "Python and Tkinter Programming" by John Grayson "Learning Python" by Lutz & Ascher The python site has mutliple tutorials... - Bob From brian@coolnamehere.com Mon Feb 5 18:07:55 2001 From: brian@coolnamehere.com (brian) Date: Mon, 5 Feb 2001 10:07:55 -0800 (PST) Subject: [Tutor] Python Baby Steps Tutorial In-Reply-To: <3A7E9D1C.7CA4072@jam.rr.com> References: <20010204233413.B15656@www.coolnamehere.com> <3A7E9D1C.7CA4072@jam.rr.com> Message-ID: <14974.60411.636636.10461@www.coolnamehere.com> Thanks! Now you are a _source_ of elation, too! :) Brian Wisti R. A. writes: > Groovy. I added a link to your tutorial from the Useless links page, so > hopefully you'll be graced with a bit more feedback. > > Rob > From curtis.larsen@Covance.Com Mon Feb 5 19:15:23 2001 From: curtis.larsen@Covance.Com (Curtis Larsen) Date: Mon, 05 Feb 2001 13:15:23 -0600 Subject: [Tutor] List Dup-Elim Method? Message-ID: Tim - Thanks! This helps a lot. I've used the dictionary method before (with great success), but the when you have lists within lists (sometimes within lists) it takes more time to set it up the dictionary stuff than it would to do something like this. Thanks again! Curtis >>> "Tim Peters" 02/03/2001 3:43:14 AM >>> If the elements of a list are hashable, the method using a dict will be by far the fastest if the list is large. If the elements are not hashable (for example, a list of lists), but can be sorted, still much quicker than brute force (yet still much slower than using a temporary dict!) is this: def dupfree(x): """Remove all duplicates from list x, in place. The elements of x must enjoy a total ordering. """ n = len(x) if n > 1: x.sort() last = x[0] i = avail = 1 while i < n: if x[i] != last: x[avail] = last = x[i] avail += 1 i += 1 del x[avail:] That requires Python 2.0, because of the "+=" thingies. Example: >>> x = [[1, 2], [3, 4]] >>> x *= 10 >>> x [[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]] >>> dupfree(x) >>> x [[1, 2], [3, 4]] >>> How does it work? Sorting the list brings all the equal elements next to each other. (Note: Many sorting routines don't work very quickly when there are lots of equal elements, but Python's does. I know that because I wrote Python's list.sort() .) After all the equal elements are adjacent, it just marches across the list once, keeping track of when the list element at index i *changes*. When it does, it moves that not-seen-before element toward the front of the list, and moves on skipping over the chunk of elements equal to *it*. Finally, it gets rid of the list positions no longer needed (the "del" stmt). Of course there's nothing to do if the list doesn't have at least two elements to start, so it checks for that first. It *has* to avoid going into the main body if the list is empty, because then "last = x[0]" would blow up. Since it has to check for that anyway, it doesn't cost any more to make sure there are at least two things in the list. This isn't an easy algorithm -- the steps are delicate. If you can use the dict method instead, do so! what-you-can-assume-constrains-what-you-can-do-ly y'rs - tim _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ----------------------------------------------------- Confidentiality Notice: This e-mail transmission may contain confidential or legally privileged information that is intended only for the individual or entity named in the e-mail address. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or reliance upon the contents of this e-mail is strictly prohibited. If you have received this e-mail transmission in error, please reply to the sender, so that we can arrange for proper delivery, and then please delete the message from your inbox. Thank you. From pablo@universodigital.net Mon Feb 5 19:37:32 2001 From: pablo@universodigital.net (Pablo Mateo =?iso-8859-1?Q?V=E1zquez?=) Date: Mon, 05 Feb 2001 20:37:32 +0100 Subject: [Tutor] Cookies?? Message-ID: <3A7F00FC.8251E33D@universodigital.net> Hi, my problem is: How to read the Cookie in a cgi program? I write: c.load(os.environ["HTTP_COOKIE"]) And I get the follow error: def __getitem__(self, key): return self.data[key] KeyError: HTTP_COOKIE The cookie was written in a previous cgi program: c=Cookie.Cookie() c["login"]=log_encrip c["login"]["path"]=pass_encrip c["login"]["expires"]=fecha_expira c.output(header="Cookie:") ... ... print "Content-type: text/html" print c print Can you said to me what is the problem? Thanks. From vdbroekw@wxs.nl Mon Feb 5 20:28:28 2001 From: vdbroekw@wxs.nl (W.W. van den Broek) Date: Mon, 05 Feb 2001 21:28:28 +0100 Subject: [Tutor] idle 0.6 References: <20010205170158.3F998ED42@mail.python.org> Message-ID: <3A7F0CEC.F9EED0DE@wxs.nl> Hi all, I've installed python 2.0 from the cdrom that came with the wonderfull book core python programming, in 1.5.3 i used idle, with 2.0 there is an error when trying to start idle, on python.org there is mentioning of a new version idle0.6 to be used with python2.0, but i cannot find it, from where can i download it?? Thanks, walter -- W.W. van den Broek e-mail: vandenbroek@psyd.azr.nl AZR-Dijkzigt fax: 010-4633217 afdeling psychiatrie tel: 010-4639222 Postbus 2040 e-mail vdbroekw@wxs.nl (thuis) 3000 CA Rotterdam homepage: http://home.planet.nl/~vdbroekw From uygar_t@yahoo.com Mon Feb 5 21:29:25 2001 From: uygar_t@yahoo.com (uygar teomete) Date: Mon, 5 Feb 2001 13:29:25 -0800 (PST) Subject: [Tutor] python interpreter Message-ID: <20010205212925.14544.qmail@web4701.mail.yahoo.com> --0-2003238937-981408565=:13775 Content-Type: text/plain; charset=us-ascii I just downloaded Python 2.0 from www.python.org made a self-test, "import test. self_test" or somethin like that. My test_socket seems to be not working, and 24 other test_something could not be found. I am a newbie. should I uninstall and download again? Thanks for your patience.. --------------------------------- Do You Yahoo!? - Get personalized email addresses from Yahoo! Mail Personal Address - only $35 a year! --0-2003238937-981408565=:13775 Content-Type: text/html; charset=us-ascii I just downloaded Python 2.0 from www.python.org  made a self-test, "import test. self_test" or somethin like that. My test_socket seems to be not working, and 24 other test_something could not be found. I am a newbie. should I uninstall and download again? Thanks for your patience..



Do You Yahoo!?
- Get personalized email addresses from Yahoo! Mail Personal Address - only $35 a year! --0-2003238937-981408565=:13775-- From Lindsay.Davies@moonshine.co.uk Mon Feb 5 21:38:20 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Mon, 5 Feb 2001 21:38:20 +0000 Subject: [Tutor] Cookies?? In-Reply-To: <3A7F00FC.8251E33D@universodigital.net> References: <3A7F00FC.8251E33D@universodigital.net> Message-ID: Take a look at Guido's examples here... http://www.python.org/doc/essays/ppt/sd99east/sld057.htm Best wishes, Lindsay At 8:37 PM +0100 2/5/01, Pablo Mateo Vázquez wrote: >Hi, my problem is: > >How to read the Cookie in a cgi program? > >I write: > c.load(os.environ["HTTP_COOKIE"]) > >And I get the follow error: > > def __getitem__(self, key): return self.data[key] > KeyError: HTTP_COOKIE > >The cookie was written in a previous cgi program: > c=Cookie.Cookie() > c["login"]=log_encrip > c["login"]["path"]=pass_encrip > c["login"]["expires"]=fecha_expira > c.output(header="Cookie:") >... >... >print "Content-type: text/html" >print c >print > > >Can you said to me what is the problem? > > >Thanks. > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From tim.one@home.com Mon Feb 5 21:41:04 2001 From: tim.one@home.com (Tim Peters) Date: Mon, 5 Feb 2001 16:41:04 -0500 Subject: [Tutor] python interpreter In-Reply-To: <20010205212925.14544.qmail@web4701.mail.yahoo.com> Message-ID: [uygar teomete] > I just downloaded Python 2.0 from www.python.org made a self-test, > "import test. self_test" or somethin like that. My test_socket seems > to be not working, You didn't say which operating system you're using, but if you're running some flavor of Windows then test_socket will fail unless you have an active internet connection open at the time you run it. That's just the way it works on Windows. > and 24 other test_something could not be found. Sounds about right, again assuming you're running some flavor of Windows. For example, test test_fork1 skipped -- os.fork not defined -- skipping test_fork1 is normal on Windows. Windows doesn't support os.fork, so it simply can't run the test there. Anything that says "test_xxx skipped" at the end is nothing to worry about. Things to worry about say something like "test_xxx failed" instead. From tim@johnsons-web.com Tue Feb 6 02:15:31 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 5 Feb 2001 17:15:31 -0900 Subject: [Tutor] Interpreter Conflicts with os.access References: Message-ID: <01020517240801.02709@shecom> Hi: Confused Newbie Here: Am using Python on RH 6.0. Have both python1.5 and python2.0 When I invoke python 1.5, I receive an AttributeError when calling os.access. When I invoke python 2.0, os.access is processed correctly. Sure enough, there is no function named "access" in /usr/lib/python1.5/access.py That's no suprise, but when I look at /usr/local/lib/python2.0/os.py I can't find the subroutine there either. As a newbie, I'm confused: Could someone explain this discrepancy to me and let me know what I am doing incorrectly. Thanks -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From arcege@shore.net Tue Feb 6 02:45:58 2001 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Feb 2001 21:45:58 -0500 (EST) Subject: [Tutor] Interpreter Conflicts with os.access In-Reply-To: <01020517240801.02709@shecom> from "Tim Johnson" at Feb 05, 2001 05:15:31 PM Message-ID: <200102060245.VAA26633@northshore.shore.net> > > Hi: > Confused Newbie Here: > Am using Python on RH 6.0. > Have both python1.5 and python2.0 > When I invoke python 1.5, I receive an AttributeError > when calling os.access. > > When I invoke python 2.0, os.access is processed correctly. > Sure enough, there is no function named "access" in /usr/lib/python1.5/access.py > That's no suprise, but when I look at /usr/local/lib/python2.0/os.py > I can't find the subroutine there either. > > As a newbie, I'm confused: Could someone explain this discrepancy to me > and let me know what I am doing incorrectly. This function and most of the others in the os module (running on a UNIX/POSIX system) come from the "posix" built-in module. $ python Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import os >>> import posix >>> os.access is posix.access 1 >>> About the only difference is that this is RedHat 7. You might like to read the os.py module to see how this is accomplished. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From johnp@reportlab.com Tue Feb 6 11:42:09 2001 From: johnp@reportlab.com (John Precedo) Date: Tue, 6 Feb 2001 11:42:09 -0000 Subject: [Tutor] Clearing the screen? In-Reply-To: Message-ID: Hi everyone! I've been working with Python for a few months now, and I'm beginning to get quite good at it. Well, one of my friends has asked me a question, and it's bugging the hell out of me that I can't answer it! Maybe one of you kind folks could help? Right, say you have a program that does nothing fancy, just prints output to STDIO. The output is nothing fancy either -just text. But, you want to make each run distinct - you don't want junk from one run cluttering up the screen on the next run and confusing you. Is there any simple way of clearing the screen? Something like the old Basic CLS command? (And yes, I know you could probably do it using Tkinter - but I'm not going there for something so simple!) Anyway, thanks in advance for any help. From wheelege@tsn.cc Tue Feb 6 12:17:57 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Tue, 6 Feb 2001 23:17:57 +1100 Subject: [Tutor] Clearing the screen? References: Message-ID: <001701c09036$d77b7540$a410fea9@glen> Don't know if this is the answer your looking for - but you could say print a whole bunch of empty line...like say pirnt "\n" * 50 It sorta clears the screen :) ----- Original Message ----- From: John Precedo To: python-tutor mailing list Sent: Tuesday, February 06, 2001 10:42 PM Subject: [Tutor] Clearing the screen? > Hi everyone! > > I've been working with Python for a few months now, and I'm > beginning to get quite good at it. Well, one of my friends > has asked me a question, and it's bugging the hell out of me > that I can't answer it! Maybe one of you kind folks could > help? > > Right, say you have a program that does nothing fancy, just > prints output to STDIO. The output is nothing fancy > either -just text. But, you want to make each run distinct - > you don't want junk from one run cluttering up the screen on > the next run and confusing you. > > Is there any simple way of clearing the screen? Something > like the old Basic CLS command? > > (And yes, I know you could probably do it using Tkinter - > but I'm not going there for something so simple!) > > Anyway, thanks in advance for any help. > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From christian.folini@unifr.ch Tue Feb 6 10:00:55 2001 From: christian.folini@unifr.ch (christian folini) Date: Tue, 6 Feb 2001 11:00:55 +0100 Subject: [Tutor] how to check for stdin? In-Reply-To: <200102051545.KAA22130@northshore.shore.net>; from arcege@shore.net on Mon, Feb 05, 2001 at 16:45:30 +0100 References: <20010205153141.E1442@histoirepc19> <200102051545.KAA22130@northshore.shore.net> Message-ID: <20010206110055.C381@histoirepc19> On 2001.02.05 16:45:30 +0100 Michael P. Reilly wrote: > I doubt that you could check on windoze, but in a UNIX environment > there is knowledge of whether a open file is attached to a terminal or > not. A method called "isatty()" returns true if associated with a > terminal. thank you for that hint. Happy enough my script need not run under windows... And it works. cool. however, there was a typo on the second line, your prg should read: $ cat eggs.py import sys if not sys.stdin.isatty(): # redirected from file or pipe stdin_data = sys.stdin.read() else: stdin_data = 'not read from stdin' print `stdin_data` cheers, christian From alan.gauld@freenet.co.uk Tue Feb 6 10:11:39 2001 From: alan.gauld@freenet.co.uk (Alan Gauld) Date: Tue, 06 Feb 2001 10:11:39 +0000 Subject: [Tutor] Re opening programs Message-ID: <3.0.1.32.20010206101139.0191123c@mail.freenet.co.uk> > I have windows 98 ie5.0 and downloaded python2.0. To open a program > (hello.py) while in idle I click file/open/documents/hello/open > is there a different or quicker way to do this? To run the program or to edit it? To run the program type: python hello.py from an MS DOS command promt(aka DOS box) or just double click it from windows explorer(aka My computer). Alternatively right click in explorer and select open. You may find that it runs then closes again too quicvkly to vbe usefult in which case try adding the line: raw_input("Hit enter to exit") at the end. [BTW, I love the contradiction in that, oh so common, phrase :-) ] To edit it in IDLE right click in explorer and select edit, it will start IDLE with your program loaded in an editor window. There is a command line option to IDLE too, I think its /e thius: python idle.py /e hello.py But thats a bit messy IMHO... HTH, Alan G (Catching up on several days tutor messages) From dsh8290@rit.edu Tue Feb 6 18:19:15 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 6 Feb 2001 13:19:15 -0500 Subject: [Tutor] Clearing the screen? In-Reply-To: <001701c09036$d77b7540$a410fea9@glen>; from wheelege@tsn.cc on Tue, Feb 06, 2001 at 11:17:57PM +1100 References: <001701c09036$d77b7540$a410fea9@glen> Message-ID: <20010206131914.A1814@harmony.cs.rit.edu> On Tue, Feb 06, 2001 at 11:17:57PM +1100, Glen Wheeler wrote: | Don't know if this is the answer your looking for - but you could say | print a whole bunch of empty line...like say | | pirnt "\n" * 50 | | It sorta clears the screen :) | I was going to suggest a similar thing. If the script will be running on a *nix system you could take a look at the ncurses module. Reading your message again, it could be that you will run the interpreter more than once on the command line (as opposed to a loop in your program). If that's the case, you could have the script run with a shell/batch script. ex: cls C:\python\python.exe myscript.py or #!/bin/sh clear ./myscript.py | | ----- Original Message ----- | From: John Precedo | To: python-tutor mailing list | Sent: Tuesday, February 06, 2001 10:42 PM | Subject: [Tutor] Clearing the screen? | | | > Hi everyone! | > | > Right, say you have a program that does nothing fancy, just | > prints output to STDIO. The output is nothing fancy | > either -just text. But, you want to make each run distinct - | > you don't want junk from one run cluttering up the screen on | > the next run and confusing you. | > | > Is there any simple way of clearing the screen? Something | > like the old Basic CLS command? -D From jpl@global.co.za Tue Feb 6 19:09:19 2001 From: jpl@global.co.za (James Lockley) Date: Tue, 6 Feb 2001 21:09:19 +0200 Subject: [Tutor] Clearing the screen? References: <001701c09036$d77b7540$a410fea9@glen> Message-ID: <001f01c09070$4e5a6de0$2c829e89@poseidon> you can also backspace what ever you had written to screen previously import time for x in range(10): print x,3*'\b', time.sleep(0.5) # just lets it happen at more vsible speed there is also another backslashed command for clearing the line but am afraid it has slipped my mind cheers james ----- Original Message ----- From: "Glen Wheeler" To: Sent: Tuesday, February 06, 2001 2:17 PM Subject: Re: [Tutor] Clearing the screen? > Don't know if this is the answer your looking for - but you could say > print a whole bunch of empty line...like say > > pirnt "\n" * 50 > > It sorta clears the screen :) > > > ----- Original Message ----- > From: John Precedo > To: python-tutor mailing list > Sent: Tuesday, February 06, 2001 10:42 PM > Subject: [Tutor] Clearing the screen? > > > > Hi everyone! > > > > I've been working with Python for a few months now, and I'm > > beginning to get quite good at it. Well, one of my friends > > has asked me a question, and it's bugging the hell out of me > > that I can't answer it! Maybe one of you kind folks could > > help? > > > > Right, say you have a program that does nothing fancy, just > > prints output to STDIO. The output is nothing fancy > > either -just text. But, you want to make each run distinct - > > you don't want junk from one run cluttering up the screen on > > the next run and confusing you. > > > > Is there any simple way of clearing the screen? Something > > like the old Basic CLS command? > > > > (And yes, I know you could probably do it using Tkinter - > > but I'm not going there for something so simple!) > > > > Anyway, thanks in advance for any help. > > > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > From s349929@student.uq.edu.au Tue Feb 6 22:49:31 2001 From: s349929@student.uq.edu.au (Suzanne Little) Date: Wed, 7 Feb 2001 08:49:31 +1000 (GMT+1000) Subject: [Tutor] XML parsing Message-ID: Hi, I doing some work with xml at the moment and I was hoping that someone could give me some pointers. Currently I'm reading the file in, chopping up the string using re.compile('<') and re.split() and then looking at each 'tag' that's in the result list to find the information I'm looking for using regular expressions. This works but it can't be the only way to extract information from an xml document. I've looked at the xml.parsers.expat and the xml.sax modules including the HOWTO but I'm don't really understand what they are capable of or when to use them. Which module should I be using to do this? Are there any examples of this sort of scanning-of-xml-documents-for-information available for me to look at? Thanks for any and all help, Suzanne BTW the useless Python archive is excellent! -------------------------------------------------------------------------- "Contrariwise," continued Tweedledee, "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -Lewis Carroll -------------------------------------------------------------------------- From lumbricus@gmx.net Tue Feb 6 22:56:19 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Tue, 6 Feb 2001 23:56:19 +0100 (MET) Subject: [Tutor] Clearing the screen? References: <001701c09036$d77b7540$a410fea9@glen> Message-ID: <2447.981500179@www24.gmx.net> > Don't know if this is the answer your looking for - but you could say > print a whole bunch of empty line...like say > > pirnt "\n" * 50 50 ??? my screen has 25 lines. > It sorta clears the screen :) the curses module has got a clear screen function or do system('/usr/bin/clear') from the os module greeetz Jö! -- Sent through GMX FreeMail - http://www.gmx.net From AquaRock7@aol.com Tue Feb 6 23:30:36 2001 From: AquaRock7@aol.com (AquaRock7@aol.com) Date: Tue, 6 Feb 2001 18:30:36 EST Subject: [Tutor] BaseHTTPServer module Message-ID: <8b.207c3c9.27b1e31c@aol.com> --part1_8b.207c3c9.27b1e31c_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit A newbie question on the included module BaseHTTPServer: What is the root directory? that I put the pages for it to display? thanks, ~Dustin --part1_8b.207c3c9.27b1e31c_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit A newbie question on the included module BaseHTTPServer:
What is the root directory? that I put the pages for it to display?
thanks, ~Dustin
--part1_8b.207c3c9.27b1e31c_boundary-- From lumbricus@gmx.net Wed Feb 7 00:07:04 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Wed, 7 Feb 2001 01:07:04 +0100 (MET) Subject: [Tutor] BaseHTTPServer module References: <8b.207c3c9.27b1e31c@aol.com> Message-ID: <20474.981504424@www21.gmx.net> --part1_8b.207c3c9.27b1e31c_boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit > A newbie question on the included module BaseHTTPServer: > What is the root directory? that I put the pages for it to display? > thanks, ~Dustin > /home/httpd/html/ take care that this dir is not owned by root (but usually by nobody) :-) greetz jö! -- Sent through GMX FreeMail - http://www.gmx.net --part1_8b.207c3c9.27b1e31c_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit A newbie question on the included module BaseHTTPServer:
What is the root directory? that I put the pages for it to display?
thanks, ~Dustin
--part1_8b.207c3c9.27b1e31c_boundary-- _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From arcege@shore.net Wed Feb 7 00:27:02 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 6 Feb 2001 19:27:02 -0500 (EST) Subject: [Tutor] BaseHTTPServer module In-Reply-To: <8b.207c3c9.27b1e31c@aol.com> from "AquaRock7@aol.com" at Feb 06, 2001 06:30:36 PM Message-ID: <200102070027.TAA07680@northshore.shore.net> > A newbie question on the included module BaseHTTPServer: > What is the root directory? that I put the pages for it to display? > thanks, ~Dustin The BaseHTTPServer doesn't serve files, it is just a framework for creating a server. You want to be looking at SimpleHTTPServer. The default root directory is the program's current directory; but you can change that by overriding the "translate_path" method of the SimpleHTTPRequestHandler class. Before you call the server process (or just the server instance's "serve_forever" method), you would want to change to the directory containing your HTML files. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dyoo@hkn.eecs.berkeley.edu Wed Feb 7 06:04:30 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 6 Feb 2001 22:04:30 -0800 (PST) Subject: [Tutor] XML parsing In-Reply-To: Message-ID: On Wed, 7 Feb 2001, Suzanne Little wrote: > Which module should I be using to do this? Are there any examples of > this sort of scanning-of-xml-documents-for-information available for > me to look at? As a side project, I'm beginning to study the expat parser; it's pretty neat. Here's a small example that uses Expat: ### class MyXMLParser2: def __init__(self): self.parser = expat.ParserCreate() self.parser.StartElementHandler = self.StartElementHandler self.parser.EndElementHandler = self.EndElementHandler self.parser.CharacterDataHandler = self.CharacterDataHandler def feed(self, str): self.parser.Parse(str) def StartElementHandler(self, name, attributes): print "Starting: ", name, attributes def EndElementHandler(self, name): print "Ending: ", name def CharacterDataHandler(self, data): print "Character data:", data def test(): p = MyXMLParser2() p.feed(""" bbagginsBilbo Baggins """) if __name__ == '__main__': test() ### The idea is that whenever we let our parser look at something, it will "call back" functions whenever it sees something that interests us. For example, as soon as the parser sees: it realizes that it sees the start of a new tag, so that's when the StartElementHandler callback executes. Similar things happen when it sees an end tag or character data. Try playing around with the program above, and it should make things more clear. There's some documentation about Expat here: http://python.org/doc/current/lib/module-xml.parsers.expat.html but it is, admittedly, a little terse. If I find anything more accessible, I'll post to the list again. Good luck! From sthickey@juno.com Thu Feb 8 06:20:42 2001 From: sthickey@juno.com (Stevenson M Hickey) Date: Wed, 7 Feb 2001 22:20:42 -0800 Subject: [Tutor] Basic Question Message-ID: <20010207.222043.-296151.0.sthickey@juno.com> Hi! I am a new subscriber and I am just learning about Python. I have a MSc in Mathematical Computer Science and very little experience in programming. Lately I have wanted to do some database structures that would not be easy or even possible with MsAccess and so I started looking around. I was recommended to Python as an easy language to learn and an efficient language to program in. I am wondering if anyone knows how to command the Jet DataBase engine of Microsoft with Python scripts? More directly, I am looking for some amplification of the Tutorial in the form of some simple scripts that will make windows parse ascii texts in various ways. In particular, I would like to be able to scan several files and combine them at will or take several lines from one and put it in another, etc. Common CShell stuff. I am running Windows 98 on a 400 MHz Pentium 2 with 60 Mb Ram. I guess, before I get too deep into this kind of a problem, I need to get some practice doing the utmost simple API calls. I would appreciate any help anyone can give. My home email address is sthickey@juno.com Sincerely with Honor, Stevenson Hickey From lakicsv@usa.net Thu Feb 8 07:10:02 2001 From: lakicsv@usa.net (Viktor Lakics) Date: Thu, 8 Feb 2001 07:10:02 +0000 Subject: [Tutor] Format strings for variables - how? Message-ID: <20010208071002.A5389@Diogenes.co.uk> Hi dear Tutors, Sorry for the basic question, I am just a starter in Python... a=1 b=3 print "%0.2f" %(a/b) The above code gives me 0.00 as a result, while I wanted to get 0.33... Interestingly enough, if use print "%0.2f" %(0.3333333) I get 0.33 as a result... Can someone explain this to me? What should I use in the example with the variables to get the display format what I want? Viktor From jcm@bigskytel.com Thu Feb 8 07:28:39 2001 From: jcm@bigskytel.com (David Porter) Date: Thu, 8 Feb 2001 00:28:39 -0700 Subject: [Tutor] Format strings for variables - how? In-Reply-To: <20010208071002.A5389@Diogenes.co.uk>; from lakicsv@usa.net on Thu, Feb 08, 2001 at 07:10:02AM +0000 References: <20010208071002.A5389@Diogenes.co.uk> Message-ID: <20010208002839.A15627@bigskytel.com> * Viktor Lakics : > Hi dear Tutors, > > Sorry for the basic question, I am just a starter in Python... This is what tutor is for! > a=1 > b=3 > print "%0.2f" %(a/b) > > The above code gives me 0.00 as a result, while I wanted to get > 0.33... The reason is that the numbers you are dividing are not floats. Because of that, you are doing integer division. >>> a = 1.0 >>> b = 3 print "%0.2f" %(a/b) gives 0.33. You must add a decimal point to one (or more) of the numbers. David From kalle@gnupung.net Thu Feb 8 08:11:29 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 8 Feb 2001 09:11:29 +0100 Subject: [Tutor] Integer division (Was: Re: Format strings for variables - how?) In-Reply-To: <20010208002839.A15627@bigskytel.com>; from jcm@bigskytel.com on Thu, Feb 08, 2001 at 12:28:39AM -0700 References: <20010208071002.A5389@Diogenes.co.uk> <20010208002839.A15627@bigskytel.com> Message-ID: <20010208091129.A435@apone.network.loc> --wac7ysb48OaltWcw Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez David Porter: > * Viktor Lakics : > > a=3D1 > > b=3D3 > > print "%0.2f" %(a/b) > >=20 > > The above code gives me 0.00 as a result, while I wanted to get > > 0.33... >=20 > The reason is that the numbers you are dividing are not floats. Because of > that, you are doing integer division. >=20 > >>> a =3D 1.0 > >>> b =3D 3 > print "%0.2f" %(a/b) >=20 > gives 0.33. You must add a decimal point to one (or more) of the numbers. Now, you might (should, I think) wonder: Why? Basically, I think there are two reasons python has integer division. 1) C has truncating integer division. Python is implemented in C. Some of the initial target users for Python were C programmers. 2) There is no way to handle division of two integers that everybody likes. Some want truncating integer division (chopping off the remainder), some wa= nt conversion to float (which loses exact representation), some want rational math (resource intensive), some want the Spanish Inquisition... 3) It would break a lot of existing code if it was changed tomorrow. =20 Three reasons. The way it works today is perhaps not the most obvious for a newcomer to programming or one with experience in languages using different solutions, but when you get used to it, it's at least as good as any of the alternatives, IMHO. 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 --wac7ysb48OaltWcw 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 iD8DBQE6glSxdNeA1787sd0RAtwIAKCm23fTcd0RfspzKeirl1DU2n5nngCgtA0J ohI2o2GolV00BvYPjBEuKW8= =v/gD -----END PGP SIGNATURE----- --wac7ysb48OaltWcw-- From Lindsay.Davies@moonshine.co.uk Thu Feb 8 08:48:11 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Thu, 8 Feb 2001 08:48:11 +0000 Subject: [Tutor] Format strings for variables - how? In-Reply-To: <20010208002839.A15627@bigskytel.com> References: <20010208071002.A5389@Diogenes.co.uk> <20010208002839.A15627@bigskytel.com> Message-ID: --============_-1230500353==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" On 8/2/01, David Porter wrote about 'Re: [Tutor] Format strings for variables - how?': > > a=1 >> b=3 >> print "%0.2f" %(a/b) >> >> The above code gives me 0.00 as a result, while I wanted to get >> 0.33... > >The reason is that the numbers you are dividing are not floats. Because of >that, you are doing integer division. > >>>> a = 1.0 >>>> b = 3 >print "%0.2f" %(a/b) > >gives 0.33. You must add a decimal point to one (or more) of the numbers. ...or alternatively make the variable type explicit... a = float(1) b = float(3) print "%0.2f" %(a/b) Best wishes, Lindsay --============_-1230500353==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] Format strings for variables - how?
On 8/2/01, David Porter wrote about 'Re: [Tutor] Format strings for variables - how?':
> a=1
> b=3
> print "%0.2f" %(a/b)
>
> The above code gives me 0.00 as a result, while I wanted to get
> 0.33...
The reason is that the numbers you are dividing are not floats. Because of
that, you are doing integer division.

>>> a = 1.0
>>> b = 3
print "%0.2f" %(a/b)
gives 0.33. You must add a decimal point to one (or more) of the numbers.

...or alternatively make the variable type explicit...

a = float(1)
b = float(3)
print "%0.2f" %(a/b)


Best wishes,

Lindsay
--============_-1230500353==_ma============-- From lakicsv@usa.net Thu Feb 8 10:06:55 2001 From: lakicsv@usa.net (Viktor Lakics) Date: 8 Feb 2001 10:06:55 GMT Subject: [Re: [Tutor] Format strings for variables - how?] Message-ID: <20010208100655.8327.qmail@aw163.netaddress.usa.net> Thanks Lindsay and David, > ...or alternatively make the variable type explicit... > = > a =3D float(1) > b =3D float(3) > print "%0.2f" %(a/b) That is what I was after! I knew that if I do 1.0/3 I get a floating poin= t no as a result. My problem was, that how to define my variable in a way that= if such division happens (eg. number from user input), then I want to see th= e fp number... Thanks Viktor ----Viktor Lakics---- Through the Internet: lakicsv@usa.net ____________________________________________________________________ Get free email and a permanent address at http://www.amexmail.com/?A=3D1 From rob@jam.rr.com Thu Feb 8 12:38:37 2001 From: rob@jam.rr.com (R. A.) Date: Thu, 08 Feb 2001 06:38:37 -0600 Subject: [Tutor] Basic Question References: <20010207.222043.-296151.0.sthickey@juno.com> Message-ID: <3A82934D.EB68C0DC@jam.rr.com> I'm a newbie, so what you're up to is a bit beyond my level. However, you may find some of the other documentation that came with your Python installation useful, such as the String Services section of the Python Library Reference. Also, my website has links to sites with information on how to do a healthy assortment of tasks, as well as links to source code repositories such as the Vaults of Parnassas. Here's my links page URL: http://www.lowerstandard.com/python/pythonlinks.html The archives for this list, as well as the archive of comp.lang.python (searchable at deja.com), may also provide some excellent info for you. Hope this helps a bit, Rob Andrews Stevenson M Hickey wrote: > > Hi! > > I am a new subscriber and I am just learning about Python. I have a MSc > in Mathematical Computer Science and very little experience in > programming. Lately I have wanted to do some database structures that > would not be easy or even possible with MsAccess and so I started looking > around. > > I was recommended to Python as an easy language to learn and an efficient > language to program in. I am wondering if anyone knows how to command > the Jet DataBase engine of Microsoft with Python scripts? > > More directly, I am looking for some amplification of the Tutorial in the > form of some simple scripts that will make windows parse ascii texts in > various ways. In particular, I would like to be able to scan several > files and combine them at will or take several lines from one and put it > in another, etc. Common CShell stuff. I am running Windows 98 on a 400 > MHz Pentium 2 with 60 Mb Ram. > > I guess, before I get too deep into this kind of a problem, I need to get > some practice doing the utmost simple API calls. > > I would appreciate any help anyone can give. > > My home email address is sthickey@juno.com > > Sincerely with Honor, > > Stevenson Hickey > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Visit the Useless Python Repository! http://www.lowerstandard.com/python/pythonsource.html From NHYTRO@compuserve.com Thu Feb 8 15:44:37 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Thu, 8 Feb 2001 10:44:37 -0500 Subject: [Tutor] CGI question Message-ID: <200102081044_MC2-C4BB-B411@compuserve.com> I=B4m not sure if this question belongs here, here goes: I=B4m going to generate from a Database with a Python CGI script a lot o= f HTML output, how can I output the content to the client in smaller chunks= ? I=B4ve heard of a "CHUNK" command somewher but I do=B4nt know where or h= ow to implement this command. Any ideas? Best regards Sharriff From porterh@m-net.arbornet.org Thu Feb 8 16:20:54 2001 From: porterh@m-net.arbornet.org (Henry) Date: Thu, 8 Feb 2001 11:20:54 -0500 (EST) Subject: [Tutor] input() and raw_input() Message-ID: I'm taking a number as input from the user and attempting to do a comparison on it: selection = raw_input('Enter number: ') if selection < 3: print 'Invalid number' else: print 'OK number' The comparison works using input() but doesn't when using raw_input() -- it always drops to the 'else:'. I was trying to use raw_input() because it was recommended in the documentation as a safer way to get user input. What exactly is raw_input() doing to the input? Can I still do my comparison using raw_input()? Are there some general rules on when to use input() vs. raw_input()? Thanks for any help. From info@fotoasia.com Fri Feb 9 00:35:51 2001 From: info@fotoasia.com (Farah Cowan) Date: Fri, 9 Feb 2001 00:35:51 -0000 Subject: [Tutor] 30,000 Exclusive Images of Asia Message-ID: <200102081634.f18GYm806386@roam2.singnet.com.sg> Dear Sirs, Here's how you can have access to more than 30,000 exclusive images of Asia in 4 easy steps: Step One: Go to www.FotoAsia.com Step Two: Browse or search for images by keywords Step Three: Pay through credit cards via secure transactions Step Four: Download the image/s ....and voila! you are done. If you are targeting the Asian market, we can offer you royalty-free Asian images for your creative and publishing needs at competitive prices, from as low as US$30.00. Need a catalog? Just go to www.FotoAsia.com and download our FREE e-Catalogs and browse at your own convenience. Can't find an image you need? Send us an e-mail sales@FotoAsia.com and we will be glad to do a FREE search for you! Thank you. Ms Farah Cowan Chief Marketing Officer FotoAsia Pte Ltd 11 Kallang Place #02-08 Singapore 339155 Tel: 65-398-1373 Fax: 65-398-1393 www.FotoAsia.com sales@FotoAsia.com FotoAsia - T h e h e a r t a n d S o u l o f A s i a Removal ********** We have reason to believe that this mail would be of interest to you. If not, please accept our apologies for the intrusion. Kindly reply to this email info@FotoAsia.com with "REMOVE" in subject heading and you will not receive any further mailings from us. Thank you. From rick@niof.net Thu Feb 8 16:39:28 2001 From: rick@niof.net (Rick Pasotto) Date: Thu, 8 Feb 2001 11:39:28 -0500 Subject: [Tutor] input() and raw_input() In-Reply-To: ; from porterh@m-net.arbornet.org on Thu, Feb 08, 2001 at 11:20:54AM -0500 References: Message-ID: <20010208113928.C358@tc.niof.net> On Thu, Feb 08, 2001 at 11:20:54AM -0500, Henry wrote: > I'm taking a number as input from the user and attempting to do a > comparison on it: > > selection = raw_input('Enter number: ') > if selection < 3: > print 'Invalid number' > else: > print 'OK number' > > The comparison works using input() but doesn't when using > raw_input() -- it always drops to the 'else:'. > I was trying to use raw_input() because it was recommended in the > documentation as a safer way to get user input. What exactly is > raw_input() doing to the input? Nothing. That's why it's called *raw*_input(). And that's where your problem lies. raw_input() returns a string which you are then comparing to a number. You need to convert 'selection' to a numeric variable. -- "Moderation in temper is always a virtue; but moderation in principle is always a vice." -- Thomas Paine, _The Rights of Man_ (1791) Rick Pasotto email: rickp@telocity.com From johnp@reportlab.com Thu Feb 8 17:02:57 2001 From: johnp@reportlab.com (John Precedo) Date: Thu, 8 Feb 2001 17:02:57 -0000 Subject: [Tutor] input() and raw_input() In-Reply-To: Message-ID: Henry [porterh@m-net.arbornet.org] asked: > I'm taking a number as input from the user and > attempting to do a comparison on it: > > selection = raw_input('Enter number: ') > if selection < 3: > print 'Invalid number' > else: > print 'OK number' > > The comparison works using input() but doesn't when using > raw_input() -- it always drops to the 'else:'. I see your problem. Have a look at this snippet: >>> x = input ("give me a number: ") give me a number: 10 >>> print x 10 >>> print type(x) >>> y = raw_input("give me another number: ") give me another number: 20 >>> print y 20 >>> print type(y) >>> z = int(y) >>> print z 20 >>> print type(z) >>> So, input is returning an integer, but raw input is returning a string. You could do this to fix it - replace the first line with these two: selection = raw_input('Enter number: ') selection = int(selection) The 'int' bit converts your string into an integer so you can do tests on it. It _should_ work. -- John Precedo (johnp@reportlab.com) Junior Developer, Reportlab, Inc From dyoo@hkn.eecs.berkeley.edu Thu Feb 8 17:17:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 8 Feb 2001 09:17:36 -0800 (PST) Subject: [Tutor] input() and raw_input() In-Reply-To: Message-ID: On Thu, 8 Feb 2001, Henry wrote: > I'm taking a number as input from the user and attempting to do a > comparison on it: > > selection = raw_input('Enter number: ') > if selection < 3: > print 'Invalid number' > else: > print 'OK number' > > The comparison works using input() but doesn't when using > raw_input() -- it always drops to the 'else:'. > I was trying to use raw_input() because it was recommended in the > documentation as a safer way to get user input. What exactly is > raw_input() doing to the input? Can I still do my comparison using > raw_input()? Are there some general rules on when to use > input() vs. raw_input()? About input(): We can think of input() as if we were directly entering something in the interpreter prompt --- Python will try to evaluate whatever you type, into something appropriate. So if we type 42 in response to an input(), Python will return back an integer. However, if we tried something like: hello (unquoted), it will break unless a 'hello' variable had been defined in our program previously. If it helps, you can think of input() as a pure text substitution into the program. Given the file: mynum = input("Number? ") whatever we type will replace the 'input("Number? ")'. (This isn't quite what Python does, but it's close.) raw_input(), on the other hand, will always return back strings. The problem that you're running into is that strings need to be squeezed into integer form before you do the numerical comparison: if int(selection) < 3: is one possible way to fix it. Another way is this: selection = int(raw_input('Enter number: ')) which is nicer if you want to always think of selection as a number. By the way, the reason it doesn't like selection < 3 is because string-to-string comparison is also available to us. If both the left side and right sides are strings, like this: 'hello' < 'world' then Python will do an alphabetic comparison. However, because the left side of your comparison uses a string and your right side a number, Python gets very confused... *grin* So it just stops until you make the types match up. Hope this helps! From robert.groenewegen@zonnet.nl Thu Feb 8 17:22:21 2001 From: robert.groenewegen@zonnet.nl (Robert Groenewegen) Date: Thu, 8 Feb 2001 18:22:21 +0100 Subject: [Tutor] Copy of list Message-ID: <3A82E3DD.18478.19A6449@localhost> Dear all, I filled a list with very informative data (for me, anyway 8-)). Before processing (like eliminating the duplicates) I wanted to save the list. I used: mySavedList = myList That doesn't work. I understand the problem. The copy is not the data but the reference. This can be checked with id(mySavedList) which is the same as id(myList). I presume, I have to do an explicit copy ('deep copy' is the correct name??). Does anyknow the correct function of method to do the trick? Greetings, Robert From shaleh@valinux.com Thu Feb 8 17:44:54 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 08 Feb 2001 09:44:54 -0800 (PST) Subject: [Tutor] Copy of list In-Reply-To: <3A82E3DD.18478.19A6449@localhost> Message-ID: > > That doesn't work. I understand the problem. The copy is not the data but the > reference. This > can be checked with id(mySavedList) which is the same as id(myList). I > presume, I have to do > an explicit copy ('deep copy' is the correct name??). > > Does anyknow the correct function of method to do the trick? > >>> import copy >>> dir(copy) ['Error', '_EmptyClass', '__builtins__', '__doc__', '__file__', '__name__', '_copy_atomic', '_copy_dict', '_copy_dispatch', '_copy_inst', '_copy_list', '_copy_tuple', '_deepcopy_atomic', '_deepcopy_dict', '_deepcopy_dispatch', '_deepcopy_inst', '_deepcopy_list', '_deepcopy_tuple', '_keep_alive', '_test', 'copy', 'deepcopy', 'error'] what you want is copy.deepcopy(). From alan.gauld@bt.com Thu Feb 8 17:58:32 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 8 Feb 2001 17:58:32 -0000 Subject: [Tutor] Format strings for variables - how? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D57B@mbtlipnt02.btlabs.bt.co.uk> > a=1 > b=3 > print "%0.2f" %(a/b) 0.00 > print "%0.2f" %(0.3333333) 0.33 That's because a and b are integers(aka whole numbers) so Python gives a whole number back ie. 0! Try making either a or b a fraction/floating point/real number(choose your term :-) thus: >>> a = 1.0 >>> b = 3 >>> print "%0.2f" % a/b 0.33 This is explained in more detail in my tutorial on the simple equences page. Alan g. http://www.crosswinds.net/~agauld/ From dsh8290@rit.edu Thu Feb 8 23:28:56 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 8 Feb 2001 18:28:56 -0500 Subject: [Tutor] input() and raw_input() In-Reply-To: ; from porterh@m-net.arbornet.org on Thu, Feb 08, 2001 at 11:20:54AM -0500 References: Message-ID: <20010208182856.B15013@harmony.cs.rit.edu> All the responses given are good, but there is one thing they failed to mention -- exceptions. You may not want to bother with them now, but as you become more experienced you will need to deal with them or your programs will be very unstable. Here is an example (when prompted for a number, I will enter invalid data) : >>> x = int( raw_input( "Enter a number: " ) ) Enter a number: invalid input Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): invalid input >>> valid_input = 0 # we haven't gotten valid input yet >>> while not valid_input : ... try : ... x = int( raw_input( "Enter an integer: " ) ) ... valid_input = 1 ... except ValueError , err : ... print "'%s' is not a valid integer." % ... err.args[0].split(": ")[1] ... print "The user entered %d" % x Enter an integer: asdf 'asdf' is not a valid integer. Enter an integer: ;lkj ';lkj' is not a valid integer. Enter an integer: 13 The user entered 13 If the int() function doesn't get a string that can be converted to an integer, it throws a "ValueError" exception. If you put the call to int() in a try-except block, you can catch the ValueError exception and do something about it. If you don't catch it, your program will terminate immediately. In the except block, I did a little "magic" to put a nice looking error message together. The key point I wanted to make is use try-except once you understand the basics. HTH, -D From dyoo@hkn.eecs.berkeley.edu Fri Feb 9 09:14:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Feb 2001 01:14:11 -0800 (PST) Subject: [Tutor] CGI question In-Reply-To: <200102081044_MC2-C4BB-B411@compuserve.com> Message-ID: On Thu, 8 Feb 2001, Sharriff Aina wrote: > I=B4m going to generate from a Database with a Python CGI script a lot > of HTML output, how can I output the content to the client in smaller > chunks? I=B4ve heard of a "CHUNK" command somewher but I do=B4nt know > where or how to implement this command. Any ideas? Hmm... I'm not quite sure what you mean by a "chunk". You should be able to do regular printing to the brower without having to worry about breaking something into small bits. Perhaps "CHUNK" has to do with your database instead? It reminds me of an SQL data type; is this what you mean? From mbouhaid@mailandnews.com Fri Feb 9 18:50:26 2001 From: mbouhaid@mailandnews.com (Mario BouHaidar) Date: Fri, 9 Feb 2001 10:50:26 -0800 Subject: [Tutor] (no subject) Message-ID: <000a01c092c9$35c94ac0$88f858cb@orbital> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C09286.1C1735D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ------=_NextPart_000_0007_01C09286.1C1735D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
------=_NextPart_000_0007_01C09286.1C1735D0-- From Christopher Bemis" This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C0928F.3980E0E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am a complete newbie when it comes to programming. I have been = learning Python with "Sam's teach yourself Python in 24 hours". Here's = my question....When I type the helloworld.py program in Notepad and then = try to run it from Command Line, I get a flash of something that looks = like a DOS window, is this supposed to be the program?=20 ------=_NextPart_000_000E_01C0928F.3980E0E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am a complete newbie when it comes to = programming. I have been learning Python with "Sam's teach yourself = Python in 24=20 hours". Here's my question....When I type the helloworld.py program in = Notepad=20 and then try to run it from Command Line, I get a flash of something = that looks=20 like a DOS window, is this supposed to be the = program? 
 
------=_NextPart_000_000E_01C0928F.3980E0E0-- From shaleh@valinux.com Fri Feb 9 17:39:27 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 09 Feb 2001 09:39:27 -0800 (PST) Subject: [Tutor] Newbie In-Reply-To: <001101c092b9$238508a0$1008683f@laser151> Message-ID: On 09-Feb-2001 Christopher Bemis wrote: > I am a complete newbie when it comes to programming. I have been learning > Python with "Sam's teach yourself Python in 24 hours". Here's my > question....When I type the helloworld.py program in Notepad and then try to > run it from Command Line, I get a flash of something that looks like a DOS > window, is this supposed to be the program? > yep. What happens is it launches a DOS window, runs the app, then the app quits and the window goes with it. What you need to do is add a 'Press enter to finish' section at the end of the app. I bet if you read just a little further they explain this. Just add a line: raw_input('Hit enter to exit') From kalle@gnupung.net Fri Feb 9 17:59:02 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 9 Feb 2001 18:59:02 +0100 Subject: [Tutor] Basic Question In-Reply-To: <20010207.222043.-296151.0.sthickey@juno.com>; from sthickey@juno.com on Wed, Feb 07, 2001 at 10:20:42PM -0800 References: <20010207.222043.-296151.0.sthickey@juno.com> Message-ID: <20010209185901.A1052@father> --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sorry for taking long to answer. Sez Stevenson M Hickey: > I was recommended to Python as an easy language to learn and an efficient > language to program in. I am wondering if anyone knows how to command > the Jet DataBase engine of Microsoft with Python scripts?=20 I don't know much about Windows programming, but I hear that ODBC is the favored way to access databases. If this is true, I think mxODBC is a good bet. http://www.lemburg.com/files/python/mxODBC.html More information on database access with python can be found on: http://www.python.org/topics/database/ > More directly, I am looking for some amplification of the Tutorial in the > form of some simple scripts that will make windows parse ascii texts in > various ways. In particular, I would like to be able to scan several > files and combine them at will or take several lines from one and put it > in another, etc. Common CShell stuff. I am running Windows 98 on a 400 > MHz Pentium 2 with 60 Mb Ram. =20 >=20 > I guess, before I get too deep into this kind of a problem, I need to get > some practice doing the utmost simple API calls.=20 A few documentation pages that you might want to take a look at: http://www.python.org/doc/current/lib/builtin.html http://www.python.org/doc/current/lib/module-string.html http://www.python.org/doc/current/lib/module-re.html http://www.python.org/doc/current/lib/module-fileinput.html 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 --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 iD8DBQE6hC/ldNeA1787sd0RAh6TAJ0SwOvxo8q8tGrVzmqwWC6YtmS/NgCdHneb h07/FM/OgPggoCzkU4UMYnI= =sMHV -----END PGP SIGNATURE----- --tKW2IUtsqtDRztdT-- From randrews@planhouse.com Fri Feb 9 17:53:07 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 09 Feb 2001 11:53:07 -0600 Subject: [Tutor] Newbie References: <001101c092b9$238508a0$1008683f@laser151> Message-ID: <3A842E83.5C1EC582@planhouse.com> When this happens, it is likely that your program runs, possibly without error. However, your program may not be telling the window to remain open for you to read the output. There are a number of things you can do to work this out. 1) Run your script from within IDLE. Once IDLE is open, import your script at the prompt, like this: >>> import helloworld # if your script is helloworld.py 2) Add a line that forces the program to wait for your okay to close, such as the following: print "hello, world" raw_input("Press Enter to exit the program. >") Then you will have to press a key to end the script, and in Win95/98 you will then have to type EXIT at the command prompt to close the "DOS" window, if this is how you are running the script. Hope this helps ya, Rob Andrews http://www.lowerstandard.com/python/pythonsource.html > Christopher Bemis wrote: > > I am a complete newbie when it comes to programming. I have been > learning Python with "Sam's teach yourself Python in 24 hours". Here's > my question....When I type the helloworld.py program in Notepad and > then try to run it from Command Line, I get a flash of something that > looks like a DOS window, is this supposed to be the program? > From sparling@uclick.com Fri Feb 9 19:02:38 2001 From: sparling@uclick.com (Doug Sparling) Date: Fri, 9 Feb 2001 13:02:38 -0600 Subject: [Tutor] Newbie In-Reply-To: <001101c092b9$238508a0$1008683f@laser151> Message-ID: <000801c092ca$df7e0140$460110ac@doug> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C09298.94E39140 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I am a complete newbie when it comes to programming. I have been learning Python with "Sam's teach yourself Python in 24 hours". Here's my question....When I type the helloworld.py program in Notepad and then try to run it from Command Line, I get a flash of something that looks like a DOS window, is this supposed to be the program? [Douglas Sparling] It works fine for me at the DOS command prompt. What you describe sounds like you're clicking the filename in windows explorer. ------=_NextPart_000_0009_01C09298.94E39140 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 I am a complete newbie when it comes = to=20 programming. I have been learning Python with "Sam's teach yourself = Python in 24=20 hours". Here's my question....When I type the helloworld.py program in = Notepad=20 and then try to run it from Command Line, I get a flash of something = that looks=20 like a DOS window, is this supposed to be the program? 
 
[Douglas=20 Sparling]  
It = works fine for me=20 at the DOS command prompt. What you describe sounds like you're clicking = the=20 filename in windows explorer.
------=_NextPart_000_0009_01C09298.94E39140-- From michaelbaker@operamail.com Fri Feb 9 21:38:35 2001 From: michaelbaker@operamail.com (michaelbaker@operamail.com) Date: Fri, 09 Feb 2001 13:38:35 -0800 Subject: [Tutor] create and fill a list with exec? In-Reply-To: Message-ID: <4.3.2.7.1.20010209132308.00b8f2a0@operamail.com> how can I create an empty list and then fill it with stuff at the time of creation or without calling it explicitly by name later? >>> dir() ['__builtins__', '__doc__', '__name__'] >>> a=[1,2,3,4,5] >>> for b in a: exec 'buffer%s=[]' %b >>> dir() ['__builtins__', '__doc__', '__name__', 'a', 'b', 'buffer1', 'buffer2', 'buffer3', 'buffer4', 'buffer5'] I want to do someting like this: >>> a=[1,2,3,4,5] >>> for b in a: exec 'buffer%s=[], buffer%s.append(b)' %b this doesn't work. I could fill these lists later, but I'm not sure how to do that either: >>> for c in dir(): for d in range(len(a)+1): if c=='buffer%s' %d: c.append(d) Traceback (innermost last): File "", line 4, in ? c.append(d) AttributeError: append how can I make this work??? thanks tutors From michaelbaker@operamail.com Sat Feb 10 05:24:04 2001 From: michaelbaker@operamail.com (michaelbaker@operamail.com) Date: Fri, 09 Feb 2001 21:24:04 -0800 Subject: [Tutor] simple math but I can't quite get it In-Reply-To: Message-ID: <4.3.2.7.1.20010209212108.00a86f00@operamail.com> for a list of integers a=[23,45,65,27,98] how can I get the sum total of all integers in this list? I just can't qutie make it on this one :( thanks From dyoo@hkn.eecs.berkeley.edu Sat Feb 10 07:03:19 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Feb 2001 23:03:19 -0800 (PST) Subject: [Tutor] simple math but I can't quite get it In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com> Message-ID: On Fri, 9 Feb 2001 michaelbaker@operamail.com wrote: > for a list of integers > a=[23,45,65,27,98] > how can I get the sum total of all integers in this list? > > I just can't qutie make it on this one :( > thanks Hello! There are several approaches to this. If we know that 'a' will always contain 5 numbers, we can go with the direct route: sum = a[0] + a[1] + a[2] + a[3] + a[4] So instead, I'll interpret your question as: "How do I add up any list of numbers together?" One thing we can do keep a running total. We can look at each number in turn, and add it to our running total, until we run out of numbers to look at. In Python, it looks like this: ### sum = 0 for x in a: sum = sum + x ### This is probably one of the simpler, straightforward ways of adding those numbers up. Whenever you use lists, you'll probably make a lot of use of for loops. There are other ways of adding numbers; one of these ways is the "functional" approach: ### >>> def add(x, y): return x + y ... >>> sum = reduce(add, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) >>> sum 55 ### This, too, tells Python to: "Reduce all those list elements into a single thing, by using the add() function repeatedly." It might be a little weird because we're feeding the add() function itself into the reduce() function, but it's not too hard once you play with it. Here's another example of using reduce to find the product of all numbers in a list: ### >>> def mul(x, y): return x * y ... >>> product = reduce(mul, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) >>> product 3628800 ### Anyway, hope this helps! From wmperry@swbell.net Sat Feb 10 07:04:22 2001 From: wmperry@swbell.net (William Perry) Date: Sat, 10 Feb 2001 01:04:22 -0600 Subject: [Tutor] simple math but I can't quite get it In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com> References: <4.3.2.7.1.20010209212108.00a86f00@operamail.com> Message-ID: <200102100104220250.0BC53C7A@mail.swbell.net> Is this what you meant? ================ def addum(): ans=a[0] lst=a[1:] for i in lst: x=i+ans print x ================ *********** REPLY SEPARATOR *********** On 2/9/01 at 9:24 PM michaelbaker@operamail.com wrote: >for a list of integers >a=[23,45,65,27,98] >how can I get the sum total of all integers in this list? > >I just can't qutie make it on this one :( >thanks > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Sat Feb 10 07:08:30 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Feb 2001 23:08:30 -0800 (PST) Subject: [Tutor] Newbie In-Reply-To: <000801c092ca$df7e0140$460110ac@doug> Message-ID: On Fri, 9 Feb 2001, Doug Sparling wrote: > I am a complete newbie when it comes to programming. I have been learning > Python with "Sam's teach yourself Python in 24 hours". Here's my > question....When I type the helloworld.py program in Notepad and then try to > run it from Command Line, I get a flash of something that looks like a DOS > window, is this supposed to be the program? Sounds like your program is running, but then closing too quickly. Try adding this at the end of your program: raw_input("Please press ENTER to finish.") This will force your program to wait until you press enter, and will let you see what's happening. You might want to try out IDLE, which is an environment that lets you experiment more freely with Python programming. IDLE should already be installed in your computer: search your Start Menu under the Python group. Good luck! From dyoo@hkn.eecs.berkeley.edu Sat Feb 10 07:36:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 9 Feb 2001 23:36:05 -0800 (PST) Subject: [Tutor] create and fill a list with exec? In-Reply-To: <4.3.2.7.1.20010209132308.00b8f2a0@operamail.com> Message-ID: On Fri, 9 Feb 2001 michaelbaker@operamail.com wrote: > how can I create an empty list and then fill it with stuff at the time of > creation or without calling it explicitly by name later? > >>> dir() > ['__builtins__', '__doc__', '__name__'] > >>> a=[1,2,3,4,5] > >>> for b in a: > exec 'buffer%s=[]' %b As a note, if you're beginning to learn the language, I'd recommend against using exec() --- there's probably an easier way to do what you're doing. It looks like you're making several lists (buffer1, buffer2, buffer3, buffer4, and buffer5). It might be better to make a list of those buffers instead: ### >>> mybuffers = [] >>> for i in range(5): ... mybuffers.append([]) ... >>> mybuffers [[], [], [], [], []] ### Now we can treat buffer1 as mybuffers[0], buffer2 as mybuffers[1], etc. This is nice because we can now pass off all the buffers with a single name, "mybuffers". Lists are really nice, and using them will allow you to avoid tricky exec() stuff. Alan Gauld explains them pretty nicely in his tutorial here: http://www.crosswinds.net/~agauld/ Good luck! From arcege@shore.net Sat Feb 10 13:53:53 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sat, 10 Feb 2001 08:53:53 -0500 (EST) Subject: [Tutor] simple math but I can't quite get it In-Reply-To: from "Danny Yoo" at Feb 09, 2001 11:03:19 PM Message-ID: <200102101353.IAA01817@northshore.shore.net> > There are other ways of adding numbers; one of these ways is the > "functional" approach: > > ### > >>> def add(x, y): return x + y > ... > >>> sum = reduce(add, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) > >>> sum > 55 > ### > > This, too, tells Python to: "Reduce all those list elements into a single > thing, by using the add() function repeatedly." It might be a little > weird because we're feeding the add() function itself into the reduce() > function, but it's not too hard once you play with it. > > Here's another example of using reduce to find the product of all numbers > in a list: > > ### > >>> def mul(x, y): return x * y > ... > >>> product = reduce(mul, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) > >>> product > 3628800 > ### These functions are also built in to the operator module. >>> l = range(1, 11) >>> l [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> import operator >>> reduce(operator.add, l) 55 >>> reduce(operator.mul, l) 3628800 >>> Most all the Python operators have function analogs in the `operator' module. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From charlie@webmind.com Sat Feb 10 23:13:54 2001 From: charlie@webmind.com (Charlie Derr) Date: Sat, 10 Feb 2001 18:13:54 -0500 Subject: [Tutor] simple math but I can't quite get it In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com> Message-ID: >>> total = 0 >>> for j in range(0,len(a)): ... total+=a[j] >>> print total hth, ~c ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ michaelbaker@operamail.com ~ Sent: Saturday, February 10, 2001 12:24 AM ~ To: tutor@python.org ~ Subject: [Tutor] simple math but I can't quite get it ~ ~ ~ for a list of integers ~ a=[23,45,65,27,98] ~ how can I get the sum total of all integers in this list? ~ ~ I just can't qutie make it on this one :( ~ thanks ~ ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor From wheelege@tsn.cc Sun Feb 11 07:41:43 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sun, 11 Feb 2001 18:41:43 +1100 Subject: [Tutor] Raiobutton question Message-ID: <000001c093fe$1dc06c20$d0755cca@glen> This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0945A.47551660 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi. Here is some code.. from Tkinter import * var =3D IntVar() ##def die(x): ## print 'dead' ## print x =20 root =3D Tk() for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), = ('Stupid', 15)]: Radiobutton(root, text=3Dtext, value=3Dvalue, = variable=3Dvar).pack(anchor=3DW) ##b =3D Button(root, text=3D'lets go', command=3D ## lambda x=3Dx:die(x))] var.set(60) mainloop() I don't know why I get this error Traceback (most recent call last): File "c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, = in RunScript exec codeObject in __main__.__dict__ File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in ? var =3D IntVar() File "c:\python20\lib\lib-tk\Tkinter.py", line 231, in __init__ Variable.__init__(self, master) File "c:\python20\lib\lib-tk\Tkinter.py", line 172, in __init__ self._tk =3D master.tk AttributeError: 'None' object has no attribute 'tk' >>> Exception exceptions.AttributeError: "'IntVar' instance has no = attribute '_tk'" in ignored Upon execution. It is almost verbatim from J Grayson's book. Also, = I'd like to know how to fix errors such as these if they come up in the = future - this is the first time I have seen one like this. Thanks, Glen. ------=_NextPart_000_0009_01C0945A.47551660 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hi.  Here is some code..
 

from Tkinter import *
 
var =3D IntVar()
 
##def die(x):
##    print = 'dead'
##   =20 print x
 
   
root =3D Tk()
 
for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),=20 ('Stupid', 15)]:
    Radiobutton(root, text=3Dtext, = value=3Dvalue,=20 variable=3Dvar).pack(anchor=3DW)
##b =3D Button(root, text=3D'lets = go',=20 command=3D
##         &nb= sp;=20 lambda x=3Dx:die(x))]
var.set(60)
 
mainloop()
  I don't know why I get this error
 
Traceback (most recent call last):
  File=20 "c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, in=20 RunScript
    exec codeObject in = __main__.__dict__
 =20 File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in=20 ?
    var =3D IntVar()
  File=20 "c:\python20\lib\lib-tk\Tkinter.py", line 231, in = __init__
   =20 Variable.__init__(self, master)
  File=20 "c:\python20\lib\lib-tk\Tkinter.py", line 172, in = __init__
   =20 self._tk =3D master.tk
AttributeError: 'None' object has no attribute = 'tk'
>>> Exception exceptions.AttributeError: "'IntVar' = instance has=20 no attribute '_tk'" in <method Variable.__del__ of IntVar instance at = 014E6DBC> ignored
  Upon execution.  It is almost verbatim from J Grayson's = book.  Also, I'd like to know how to fix errors such as these if = they come=20 up in the future - this is the first time I have seen one like = this.
 
  Thanks,
  Glen.
------=_NextPart_000_0009_01C0945A.47551660-- From dyoo@hkn.eecs.berkeley.edu Sun Feb 11 11:58:48 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 11 Feb 2001 03:58:48 -0800 (PST) Subject: [Tutor] getopt options In-Reply-To: <3A864B3D.FC5F3BBD@early.com> Message-ID: On Sun, 11 Feb 2001, Tom Connor wrote: > I'm trying to find a tutorial for getopt. But most things seem to refer > to Unix or some other source not suitable for my current level of > understanding. I find the Python documentation pretty cryptic. Does > anyone have suggestions where I should go to improve my understanding of > getopt and it's options? Good evening; you're probably looking at the reference material for the getopt module here: http://python.org/doc/current/lib/module-getopt.html [note: this message is very long, and will look at the very last example in some detail. Apologies in advance.] Could you tell us where the reference material starts sounding funny? We can help interpret the examples on the bottom. Let's take a look at the very last example that the reference manual brings up. I'll simplify the example so we don't look at the "long" argument stuff. We'll be looking at variations of this: ### opts, args = getopt.getopt(sys.argv[1:], "ho:") ### getopt() will return two lists: "opts' will cotain all the option name-value pairs that we're looking for, while the "args" will contain anything that it doesn't know about. When we use getopt(), we need to tell it what options we're paying attention to. Let's take a look at the second argument to that getopt() call: "ho:" This means that our program will expect to see at most 2 types of "short" one-character things. For example, we could pass the following arguments: -h -h -oOutput -h -o Output -oRabbit which should be all legal. That colon in front of the 'o' means that we expect it to take in an additional argument, so getopt will suck the very next word in front of any "-o"'s. If we try to use the '-o' option without something in front, getopt() will respond with an error. That's the theory, at least. *grin* Let's put it into practice. Interpreter time. ### ## Case 1 >>> getopt(['-h', '-o', 'Object'], 'ho:') ([('-h', ''), ('-o', 'Object')], []) ### In this case, we've probably sent getopt the following command line: some_program_name -h -o Object Python will automagically parse out the arguments as the list sys.argv. We see that getopt returns back to us a tuple of two things. The first contains all the options. The options themselves have an interesting structure: each "option" is a 2-tuple: [('-h', ''), ('-o', 'Object')] But why doesn't it do this instead: [-h, ('-o', 'Object')] ? Isn't this more efficient? The reason getopt does it with 2-tuples always is because it's a matter of consistency. When we write programs to figure out what options have turned on, it's easy if we can expect getopt to return something with a very uniform structure. If we look later at the code: ### for o, a in opts: ### we expect to place the option name in 'o' and the argument value in 'a'; we wouldn't be able to do this unless we were absolutely sure that every element is a 2-tuple; otherwise, it wouldn't be able to unpack the tuple properly. Let's take a look at another call: ### ## Case 2 >>> getopt(['-o=Object'], 'ho:') ([('-o', '=Object')], []) ### Here, we see that the options are optional; even though we expect to see '-h' or '-o', nothing in getopt will break if we leave one of the options off alone. However, getopt is equipped to recognize when an option is incomplete. That's the next case: ### ## Case 3 >>> getopt(['-o'], 'ho:') Traceback (innermost last): # [edited for brevity] getopt.error: option -o requires argument ### Here, since '-o' needs to have something in front, getopt() will ultimately fail and complain with an exception. This error reporting is actually useful, though, because we can use exception handling to respond appropriately to these situations. This message is too long already, so I won't talk about exception handling for now. Here's a tricky case: ### ## Case 4 >>> getopt(['-homer'], 'ho:') ([('-h', ''), ('-o', 'mer')], []) ### What's going on? The trick is that, in UNIX tradition, when we put something like: -homer we really mean: -h -o -m -e -r as shorthand... That is, unless -o is an option that sucks the next word as its argument value. Since we've defined -o as such, that's why 'mer' becomes the argument to '-o'. We can see this more clearly with another example: ### >>> getopt(['-abc'], 'abcd') ([('-a', ''), ('-b', ''), ('-c', '')], []) ### Finally, here's a wacky case: ## Case 5 >>> getopt(['-h', 'radish', '-o=Object'], 'ho:') ([('-h', '')], ['radish', '-o=Object']) ### What's happening? You might be wondering, why didn't '-o=Object' get parsed out into: (-o, Object) ?? The reason is because all options need to come _before_ anything that looks like a regular argument (like a filename). So: ['-h', '-o=Object', 'radish'] would have worked normally. Options can be irritating that way, but that's how they're defined: as soon as getopt starts to see arguments that don't look like options, it will disregard the rest and stop parsing. If you have any questions, please feel free to ask; it's much too quiet in this mailing list. *grin* From dyoo@hkn.eecs.berkeley.edu Sun Feb 11 12:09:55 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 11 Feb 2001 04:09:55 -0800 (PST) Subject: [Tutor] Raiobutton question In-Reply-To: <000001c093fe$1dc06c20$d0755cca@glen> Message-ID: On Sun, 11 Feb 2001, Glen Wheeler wrote: > var = IntVar() [some code omitted] > root = Tk() > I don't know why I get this error > Traceback (most recent call last): [cut] > AttributeError: 'None' object has no attribute 'tk' > It is almost verbatim from J Grayson's book. The problem is that when we construct an InvVar(), Tk expects us to have a root window already set up. The line: root = Tkinter.Tk() initializes _tk to something that all other widgets will depend on. So, when we do something like: ### root = Tkinter.Tk() button = Tkinter.Button() ### in the background, the Button() knows that it should connect up with root, because the _tk variable's initialized. Going back to your program, the IntVar definition is a bit too early; IntVar doesn't know where to attach to until we either make a root window. Try putting it after your Tk() call, and you should be ok. > Also, I'd like to know how to fix errors such as these if they come up > in the future - this is the first time I have seen one like this. To tell the truth, I have no clue what an InvVar is. But if you ever see something that says "_Tk is undefined", it's probably because a Tk() instance hasn't been built yet. (Someday, I shall have to take a look at "Python and Tkinter Programming", and really understand what's happening... *grin*) Good luck! From arcege@shore.net Sun Feb 11 15:15:19 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 11 Feb 2001 10:15:19 -0500 (EST) Subject: [Tutor] Raiobutton question In-Reply-To: from "Danny Yoo" at Feb 11, 2001 04:09:55 AM Message-ID: <200102111515.KAA09747@northshore.shore.net> > The problem is that when we construct an InvVar(), Tk expects us to have a > root window already set up. The line: > > root = Tkinter.Tk() > > initializes _tk to something that all other widgets will depend > on. So, when we do something like: > > ### > root = Tkinter.Tk() > button = Tkinter.Button() > ### > > in the background, the Button() knows that it should connect up with root, > because the _tk variable's initialized. > > > Going back to your program, the IntVar definition is a bit too early; > IntVar doesn't know where to attach to until we either make a root window. > Try putting it after your Tk() call, and you should be ok. The reason is a little more subtle than this. All _widgets_ will implicitly create a new Tk() instance if None is set (and if Tkinter. _support_default_root is true). However the Variable classes (of which IntVar is a subclass) are not widgets, and do not have this behavior. So where just python -c 'import Tkinter; Tkinter.Button()' creating a widget with no Tk would work, but creating a variable before a widget won't python -c 'import Tkinter; Tkinter.IntVar()' The Button initialization detects that there is no _default_root and creates a Tk instance (which sets _default_root); but IntVar does nothing like this, and expects _default_root to be set already. Glen, Grayson's "Python and Tkinter Programming" example that I assume you are using (pp. 37-38) does not set "root = Tk()" at all, but uses the root in the Radiobutton call. This is confusing, and Grayson does not really explain the Variable classes well at all. Unfortunately, a lot of the Tkinter documentation does not do this part of Tkinter justice either. > To tell the truth, I have no clue what an InvVar is. But if you ever see > something that says "_Tk is undefined", it's probably because a Tk() > instance hasn't been built yet. Tkinter is written on top of Tcl/Tk, which has its own variables and functions, so there are such classes as Variable, and its subclasses, and CallWhapper so Tk can use Python functions and map Tcl variables to Python names. Much of this is handled for you in Tkinter itself, but for "shared" variables like Radiobutton instances required a new form of object. > (Someday, I shall have to take a look at "Python and Tkinter Programming", > and really understand what's happening... *grin*) It's a very good book, I recommend getting it. I would suggest reading Fredrik Lundh's not-as-complete "An Introduction to Tkinter" as well -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From georg.simon@bnmsp.de Sun Feb 11 17:35:36 2001 From: georg.simon@bnmsp.de (Georg Simon) Date: Sun, 11 Feb 2001 18:35:36 +0100 Subject: [Tutor] Fonts for Canvas text items ? Message-ID: <3A86CD81.755FCE8F@bnmsp.de> Python 2.0 and Windows 98 To find out how to change the font for a text item on a Canvas, I tried the following code. But the only effect I get is on the size of the font. The larger size appears in the first three lines, the tiny size in the last line. How can I get different fonts, different thickness, different size ? Georg Simon from Tkinter import * Wurzel=Tk() Leinwand = Canvas(Wurzel) Leinwand.create_text(50,50,text="Helvetica",font="Helvetica") Leinwand.create_text(50,100,text="NewCourier",font="NewCourier") Leinwand.create_text(50,150,text="bold",font="bold") Leinwand.create_text(50,200,text="no font") Leinwand.pack() Wurzel.mainloop() From tim@johnsons-web.com Sun Feb 11 18:10:12 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 11 Feb 2001 09:10:12 -0900 Subject: [Tutor] Textbook Recommendation References: <000001c093fe$1dc06c20$d0755cca@glen> Message-ID: <01021109135704.05012@shecom> Hello All: I'm learning Python, and at the same time, creating an online course in the language for a local school district. I would welcome recommendations on a textbook: I have about 6 books on Python: The two I am considering are: 1)Learning Python in 24 hours 2)Learning Python Any and all opinions would be welcome. TIA -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From rob@jam.rr.com Sun Feb 11 18:22:05 2001 From: rob@jam.rr.com (R. A.) Date: Sun, 11 Feb 2001 12:22:05 -0600 Subject: [Tutor] Textbook Recommendation References: <000001c093fe$1dc06c20$d0755cca@glen> <01021109135704.05012@shecom> Message-ID: <3A86D84D.848F94B6@jam.rr.com> Each of the two books you mention seem fine. You should also consider Alan Gauld's *Learning to Program Using Python*. I've been through the material on his site, which I found to be of high quality, and my understanding is that the book is excellent. If I purchase another introductory Python book, it's the one I figure I'll spend my money on, especially if the intended purpose is to use the material to teach programming to young people. Rob Andrews Tim Johnson wrote: > > Hello All: > I'm learning Python, and at the same time, creating an online course in > the language for a local school district. > I would welcome recommendations on a textbook: > I have about 6 books on Python: The two I am considering are: > 1)Learning Python in 24 hours > 2)Learning Python > > Any and all opinions would be welcome. > TIA > -- > Tim Johnson > ----------- > "Of all manifestations of power, > restraint impresses the most." > -Thucydides > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Visit the Useless Python Repository! http://www.lowerstandard.com/python/pythonsource.html From arcege@shore.net Sun Feb 11 18:35:44 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 11 Feb 2001 13:35:44 -0500 (EST) Subject: [Tutor] Fonts for Canvas text items ? In-Reply-To: <3A86CD81.755FCE8F@bnmsp.de> from "Georg Simon" at Feb 11, 2001 06:35:36 PM Message-ID: <200102111835.NAA01957@northshore.shore.net> > Python 2.0 and Windows 98 > > To find out how to change the font for a text item on a Canvas, I tried > the following code. But the only effect I get is on the size of the > font. The larger size appears in the first three lines, the tiny size in > the last line. > > How can I get different fonts, different thickness, different size ? I don't know about Win98, but you can get the list of fonts with Python 2.0 (#3, Dec 18 2000, 02:47:55) [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import tkFont >>> tkFont.families() ('fangsong ti', 'fixed', 'clearlyu alternate glyphs', 'charter', 'lucidatypewriter', 'lucidabright', 'times', 'lucidux sans', 'open look glyph', 'song ti', 'zapf dingbats', 'avantgarde', 'helvetica', 'open look cursor', 'newspaper', 'mincho', 'clearlyu ligature', 'lucidux mono', 'clearlyu pua', 'palatino', 'courier', 'clearlyu', 'lucida', 'utopia', 'clean', 'nil', 'terminal', 'zapf chancery', 'cursor', 'symbol', 'gothic', 'bookman', 'lucidux serif', 'new century schoolbook', 'clearlyu arabic extra') >>> root = tkFont.Tkinter.Tk() >>> f = tkFont.Font(root, ('courier', 10, tkFont.NORMAL)) >>> tkFont.Tkinter.Label(root, text='hi', font=f).pack() You should be able to set fonts with Font instances. -Arcege PS: Your example worked fine on my systems. > > from Tkinter import * > > Wurzel=Tk() > > Leinwand = Canvas(Wurzel) > > Leinwand.create_text(50,50,text="Helvetica",font="Helvetica") > Leinwand.create_text(50,100,text="NewCourier",font="NewCourier") > Leinwand.create_text(50,150,text="bold",font="bold") > Leinwand.create_text(50,200,text="no font") > > Leinwand.pack() > > Wurzel.mainloop() -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From arcege@shore.net Sun Feb 11 18:44:49 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sun, 11 Feb 2001 13:44:49 -0500 (EST) Subject: [Tutor] Textbook Recommendation In-Reply-To: <01021109135704.05012@shecom> from "Tim Johnson" at Feb 11, 2001 09:10:12 AM Message-ID: <200102111844.NAA02650@northshore.shore.net> > I'm learning Python, and at the same time, creating an online course in > the language for a local school district. > I would welcome recommendations on a textbook: > I have about 6 books on Python: The two I am considering are: > 1)Learning Python in 24 hours > 2)Learning Python > > Any and all opinions would be welcome. If you are interested in teaching Python, then I suggest that you look into CP4E ("Computer Programming for Everybody"), which is a project now on hold, and the EDU SIG ("Python in Education"). Resources: * CP4E: * EDU-SIG: Both books are good. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From b_hitesh@hotmail.com Sun Feb 11 19:32:46 2001 From: b_hitesh@hotmail.com (Hitesh N Brahmbhatt) Date: Sun, 11 Feb 2001 11:32:46 -0800 Subject: [Tutor] How to compile "odbchelper.py" app used in "diveintopython" book ? Message-ID: <3A86E8DE.6C64ECA0@hotmail.com> Hi, When I compile this file, it gives me an SyntaxError on for statement. In the Python documentation I have the for loop is always used as follows : for i in list: while the "odbchelper.py" uses it as [(%s=%s) % (k, params[k]) for k in params.keys()] So, I tried to put the ":" at the end of the for statement but it doesn't help. Can you tell me what is wrong ? I am pasting the whole prgram and the output below: def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()]) if __name__ == "__main__": myParams = {"server":"mpilgrim", \ "database":"master", \ "uid":"sa", \ "pwd":"secret" \ } print buildConnectionString(myParams) output of "python odbchelper.py" : File "odbchelper.py", line 5 return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()]) ^ SyntaxError: invalid syntax Thanks, Hitesh From dyoo@hkn.eecs.berkeley.edu Sun Feb 11 21:46:53 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 11 Feb 2001 13:46:53 -0800 (PST) Subject: [Tutor] How to compile "odbchelper.py" app used in "diveintopython" book ? In-Reply-To: <3A86E8DE.6C64ECA0@hotmail.com> Message-ID: On Sun, 11 Feb 2001, Hitesh N Brahmbhatt wrote: > print buildConnectionString(myParams) > > output of "python odbchelper.py" : > > File "odbchelper.py", line 5 > return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()]) > ^ > SyntaxError: invalid syntax Do you have Python 2.0? It looks like odbchelper.py was written using the "list comprehensions" feature within Python 2.0. One equivalent way of writing that in Python 1.52 format is: ### from string import join return join(map(lambda k: "%s=%s" % (k, params[k]), params.keys()), ';') ### But it might just be cleaner to write your own function to break that complicated statement down: ### def makeNameValuePairs(dict): result = [] for key, value in dict.items(): result.append("%s=%s" % (key, value)) return result ### Then the statement above will look like this: return join(makeNameValuePairs(params), ';') which is definitely much cleaner to read. Hope this helps! From wsryu@fas.harvard.edu Mon Feb 12 02:51:04 2001 From: wsryu@fas.harvard.edu (William Ryu) Date: Sun, 11 Feb 2001 21:51:04 -0500 Subject: [Tutor] Get IP address? Message-ID: <4.3.2.7.2.20010211215019.00ba3ba0@pop.fas.harvard.edu> Is there a function to get the IP address of your machine? Thanks, -w From dyoo@hkn.eecs.berkeley.edu Mon Feb 12 05:58:22 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 11 Feb 2001 21:58:22 -0800 (PST) Subject: [Tutor] Get IP address? In-Reply-To: <4.3.2.7.2.20010211215019.00ba3ba0@pop.fas.harvard.edu> Message-ID: On Sun, 11 Feb 2001, William Ryu wrote: > Is there a function to get the IP address of your machine? According to: http://python.org/doc/current/lib/module-socket.html you can do this with the socket module: from socket import gethostbyname, gethostname print gethostbyname(gethostname()) From wheelege@tsn.cc Mon Feb 12 08:01:08 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 12 Feb 2001 19:01:08 +1100 Subject: [Tutor] Raiobutton question References: <200102111515.KAA09747@northshore.shore.net> Message-ID: <004001c094c9$f56750a0$a3755cca@glen> Thanks alot for the help - I understand why that wasn't working. Also, the reason I had the root = Tk() in there is because Grayson explains he expects that (among other header stuff) at the beginning of all his examples (note he says beginning, and not 3rd in line, like I had it). However, my real problem is still rearing it's ugly head. Almost the same code as before : from Tkinter import * root = Tk() x = IntVar() def die(x): print 'dead' print x for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), ('Stupid', 15)]: Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W) b = Button(root, text='lets go', command= lambda x=x:die(x)).pack() x.set(60) ## meant to select a radio button as default however does not work mainloop() Except this one makes a button that is meant to print 'dead' and also the value of x. This doesn't happen, instead it prints the name given to x upon its creation. It appears that x is not changed by the radio buttons, or maybe it isn't even recognised (wrong namespace? nah cos then the radiobuttons would throw an exception....right?). I know this is an easy problem - they are the ones I have the most trouble with. It seems I can always work my way through the big ugly hard things...just not the easy ones. Thanks again, Glen. From gibbs05@flash.net Mon Feb 12 10:59:21 2001 From: gibbs05@flash.net (Harry Kattz) Date: Mon, 12 Feb 2001 04:59:21 -0600 Subject: [Tutor] Raiobutton question References: <200102111515.KAA09747@northshore.shore.net> <004001c094c9$f56750a0$a3755cca@glen> Message-ID: <026c01c094e2$e5fc2280$e7de3040@gibbs05> Greetings Glen & All, Since I'm awake and struggling to learn Tkinter also, I've decided to jump in. I tried your code in PythonWin and the value of x is indeed being set by the radiobutton. The values stored in the TK variables can be retrieved using their 'get' method, so the following modification to the die function should fix your output. def die(x) print 'dead' print x.get() I think you can find this in the top paragraph on page 152 of 'Python and Tkinter Programming' by Grayson. Your code set the radiobutton's default just fine when I tried it, so I can't help you with that one. ;-) Good luck Harry > Thanks alot for the help - I understand why that wasn't working. Also, > the reason I had the root = Tk() in there is because Grayson explains he > expects that (among other header stuff) at the beginning of all his examples > (note he says beginning, and not 3rd in line, like I had it). > However, my real problem is still rearing it's ugly head. Almost the same > code as before : > > from Tkinter import * > > root = Tk() > > x = IntVar() > > def die(x): > print 'dead' > print x > > for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), ('Stupid', > 15)]: > Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W) > b = Button(root, text='lets go', command= > lambda x=x:die(x)).pack() > > x.set(60) ## meant to select a radio button as default however does not > work > > mainloop() > > Except this one makes a button that is meant to print 'dead' and also the > value of x. This doesn't happen, instead it prints the name given to x upon > its creation. It appears that x is not changed by the radio buttons, or > maybe it isn't even recognised (wrong namespace? nah cos then the > radiobuttons would throw an exception....right?). > I know this is an easy problem - they are the ones I have the most trouble > with. It seems I can always work my way through the big ugly hard > things...just not the easy ones. > > Thanks again, > Glen. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From wheelege@tsn.cc Mon Feb 12 10:59:52 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 12 Feb 2001 21:59:52 +1100 Subject: [Tutor] Raiobutton question References: <200102111515.KAA09747@northshore.shore.net> <004001c094c9$f56750a0$a3755cca@glen> <026c01c094e2$e5fc2280$e7de3040@gibbs05> Message-ID: <002901c094e2$eda7f0e0$b8755cca@glen> Thanks, it seems I need more reading on the different methods of the variable classes. Python docs, here I come! The default setting doesn't really matter...not yet anyway :) Glen. ----- Original Message ----- From: Harry Kattz To: Glen Wheeler Cc: Sent: Monday, February 12, 2001 9:59 PM Subject: Re: [Tutor] Raiobutton question > Greetings Glen & All, > > Since I'm awake and struggling to learn Tkinter also, I've decided to jump > in. > > I tried your code in PythonWin and the value of x is indeed being set by the > radiobutton. > > The values stored in the TK variables can be retrieved using their 'get' > method, so the following modification to the die function should fix your > output. > > def die(x) > print 'dead' > print x.get() > > I think you can find this in the top paragraph on page 152 of 'Python and > Tkinter Programming' by Grayson. > > Your code set the radiobutton's default just fine when I tried it, so I > can't help you with that one. ;-) > > Good luck > Harry > > > Thanks alot for the help - I understand why that wasn't working. Also, > > the reason I had the root = Tk() in there is because Grayson explains he > > expects that (among other header stuff) at the beginning of all his > examples > > (note he says beginning, and not 3rd in line, like I had it). > > However, my real problem is still rearing it's ugly head. Almost the > same > > code as before : > > > > from Tkinter import * > > > > root = Tk() > > > > x = IntVar() > > > > def die(x): > > print 'dead' > > print x > > > > for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), > ('Stupid', > > 15)]: > > Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W) > > b = Button(root, text='lets go', command= > > lambda x=x:die(x)).pack() > > > > x.set(60) ## meant to select a radio button as default however does not > > work > > > > mainloop() > > > > Except this one makes a button that is meant to print 'dead' and also > the > > value of x. This doesn't happen, instead it prints the name given to x > upon > > its creation. It appears that x is not changed by the radio buttons, or > > maybe it isn't even recognised (wrong namespace? nah cos then the > > radiobuttons would throw an exception....right?). > > I know this is an easy problem - they are the ones I have the most > trouble > > with. It seems I can always work my way through the big ugly hard > > things...just not the easy ones. > > > > Thanks again, > > Glen. > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > From Greg.Furmanek@hit.cendant.com Mon Feb 12 16:57:09 2001 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Mon, 12 Feb 2001 11:57:09 -0500 Subject: [Tutor] initialization of classes. Message-ID: Here is a Problem: I am trying to pass a class to another class and initialize the passed class if it is not passed when the main class is initialized. This is the piece of code and error I get. Thanks for help. #============ Code Start ============================== class connection: def __init__ \ (self, \ l_acc_stat = "", \ l_user_info = c_user_info(), \ l_tun_type = "", \ l_acc_info = c_acct_info(), \ l_net_info = c_network_info()): self.account_status = l_acc_stat self.user = l_user_info self.Class = "" # not used self.Tunnel_Type = l_tun_type self.acct_info = l_acc_info self.network_info = l_net_info def load_account_status(self, acc_stat): self.account_status = acc_stat def load_user_info(self, l_user_info): self.user = l_user_info class c_user_info: def __init__(self): self.User_Name = "" self.User_Full_Name = "" self.User_Group = user_group #============ Code End ============================== #============ Error Start ============================= => dsv.py 20010120.dat Traceback (most recent call last): File "dsv.py", line 46, in ? class connection: File "dsv.py", line 49, in connection def __init__ \ NameError: There is no variable named 'c_user_info' #============ Error End ============================== Grzegorz Furmanek Furmanek.Greg@hit.cendant.com ---------------------------------------------------------- Three Mile Island '79 Chernobyl '86 Windows '00 (1900) "The sender believes that this E-mail and any attachments were free of any virus, worm, Trojan horse, and/or malicious code when sent. This message and its attachments could have been infected during transmission. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective and remedial action about viruses and other defects. The sender's employer is not liable for any loss or damage arising in any way from this message or its attachments." From ibraheem@micromuse.com Mon Feb 12 17:18:49 2001 From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed) Date: Mon, 12 Feb 2001 17:18:49 +0000 Subject: [Tutor] initialization of classes. In-Reply-To: ; from Greg.Furmanek@hit.cendant.com on Mon, Feb 12, 2001 at 11:57:09AM -0500 References: Message-ID: <20010212171849.A19742@micromuse.com> Hi, On Mon, Feb 12, 2001 at 11:57:09AM -0500, Furmanek, Greg wrote: > Here is a Problem: > > I am trying to pass a class to another class and > initialize the passed class if it is not passed > when the main class is initialized. > > This is the piece of code and error I get. > > Thanks for help. > > #============ Code Start ============================== > > class connection: > > > def __init__ \ > (self, \ > l_acc_stat = "", \ > l_user_info = c_user_info(), \ c_user_info is not defined at this point - move the definition of c_user_info above (i.e. before ) the definition of connection. You will probably then find that "user_group" (and the other undefined functions)are not well....defined. > l_tun_type = "", \ > l_acc_info = c_acct_info(), \ > l_net_info = c_network_info()): > > self.account_status = l_acc_stat > self.user = l_user_info > self.Class = "" # not used > self.Tunnel_Type = l_tun_type > self.acct_info = l_acc_info > self.network_info = l_net_info > > > def load_account_status(self, acc_stat): > self.account_status = acc_stat > > > def load_user_info(self, l_user_info): > self.user = l_user_info > > class c_user_info: > > > def __init__(self): > self.User_Name = "" > self.User_Full_Name = "" > self.User_Group = user_group Kindest regards, --ibs. -- -------------------------------------------------------------------------------- -- Ibraheem Umaru-Mohammed -- -- Email:ium@micromuse.com -- -- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA -- -- http://www.micromuse.com -- -------------------------------------------------------------------------------- From scarpenter@innerx.net Mon Feb 12 17:27:22 2001 From: scarpenter@innerx.net (scarpenter@innerx.net) Date: Mon, 12 Feb 2001 12:27:22 -0500 Subject: [Tutor] New Online Auction Site for Brand Name Tools, Hardware, Home Improvement Products Message-ID: --=200102121225= Content-Type: text/html;charset=US-ASCII http://www

http://www.hardwareusa.net

Stop paying outrageous retail prices for the products you need to keep your home beautiful.

Hardware USA, a leading home center, is excited to invite you to visit our new website and auction store. Visit us now and save big money on superior products from such trusted brand names as Black & Decker, DeWalt and Makita.

Never before has saving money on top quality power tools, hardware, electrical and plumbing supplies, lawn and garden equipment and automotive care products been easier or more fun!

Shop conveniently from your home or office and save big at the new Hardware USA website and auction store!

Be sure to check out our unbeatable selection of interior and exterior paint too!

100% CUSTOMER SATISFACTION GUARANTEED.

http://www.hardwareusa.net

 

--=200102121225=-- From alan.gauld@bt.com Mon Feb 12 17:21:43 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Feb 2001 17:21:43 -0000 Subject: [Tutor] Textbook Recommendation Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D590@mbtlipnt02.btlabs.bt.co.uk> > I'm learning Python, and at the same time, creating an > online course in the language for a local school district. > I would welcome recommendations on a textbook: First you need to tell us a it more: What if any programming/computer skills do the students have already? > The two I am considering are: > 1)Learning Python in 24 hours Aimed at beginners with litle or no previous experience. Good for an intro to GUI programming (and Mayan calanders!) > 2)Learning Python Only really suitable if they have a programming background already. Or if you are ready/able to do a lot of additional work filling in the gaps. I could suggest my book but I've done enough self promotion recently :-) Both of the above are good intros they just serve different audiences. Since I don't know what the other 4 books you have are I'll just add the following to your list: Core Python - Wesley Chun Quick Python - ??? Manning Press I've browsed both and they look good and have had good reader reviews. Alan g. From alan.gauld@bt.com Mon Feb 12 17:23:53 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Feb 2001 17:23:53 -0000 Subject: [Tutor] How to compile "odbchelper.py" app used in "diveintop ython" book ? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D591@mbtlipnt02.btlabs.bt.co.uk> > while the "odbchelper.py" uses it as > > [(%s=%s) % (k, params[k]) for k in params.keys()] This is new to Python 2.o Is that the version you are uusing? If not it won't work... Alan g From alan.gauld@bt.com Mon Feb 12 17:34:23 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 12 Feb 2001 17:34:23 -0000 Subject: [Tutor] initialization of classes. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D592@mbtlipnt02.btlabs.bt.co.uk> > Here is a Problem: > class connection: > def __init__ (... > l_user_info = c_user_info(), ... Tries to instantiate the class and assign the instance as the default value for the constructor. I suspect you really want: > l_user_info = c_user_info, ... And within the init method: # create an instance of whatever kind of # class was passed. l_user_instance = l_user_info() > class c_user_info: > def __init__(self): ... > #============ Error Start ============================= > => dsv.py 20010120.dat > Traceback (most recent call last): > File "dsv.py", line 46, in ? > class connection: > File "dsv.py", line 49, in connection > def __init__ \ > NameError: There is no variable named 'c_user_info' The NameError is because you haven't defined this class yet. Try reversing the order of your classes.... Alan G. From Greg.Furmanek@hit.cendant.com Mon Feb 12 17:41:27 2001 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Mon, 12 Feb 2001 12:41:27 -0500 Subject: [Tutor] initialization of classes. Message-ID: This worked. Thanks -> -----Original Message----- -> From: Ibraheem Umaru-Mohammed [mailto:ibraheem@micromuse.com] -> Sent: Monday, February 12, 2001 10:19 AM -> To: Furmanek, Greg -> Cc: 'tutor@python.org' -> Subject: Re: [Tutor] initialization of classes. -> -> -> Hi, -> -> -> On Mon, Feb 12, 2001 at 11:57:09AM -0500, Furmanek, Greg wrote: -> > Here is a Problem: -> > -> > I am trying to pass a class to another class and -> > initialize the passed class if it is not passed -> > when the main class is initialized. -> > -> > This is the piece of code and error I get. -> > -> > Thanks for help. -> > -> > #============ Code Start ============================== -> > -> > class connection: -> > -> > -> > def __init__ \ -> > (self, \ -> > l_acc_stat = "", \ -> > l_user_info = c_user_info(), \ -> -> c_user_info is not defined at this point - move the definition -> of c_user_info above (i.e. before ) the definition of connection. -> You will probably then find that "user_group" (and the other -> undefined -> functions)are not well....defined. -> -> > l_tun_type = "", \ -> > l_acc_info = c_acct_info(), \ -> > l_net_info = c_network_info()): -> > -> > self.account_status = l_acc_stat -> > self.user = l_user_info -> > self.Class = "" # not used -> > self.Tunnel_Type = l_tun_type -> > self.acct_info = l_acc_info -> > self.network_info = l_net_info -> > -> > -> > def load_account_status(self, acc_stat): -> > self.account_status = acc_stat -> > -> > -> > def load_user_info(self, l_user_info): -> > self.user = l_user_info -> > -> > class c_user_info: -> > -> > -> > def __init__(self): -> > self.User_Name = "" -> > self.User_Full_Name = "" -> > self.User_Group = user_group -> -> Kindest regards, -> -> --ibs. -> -> -- -> ------------------------------------------------------------- -> ------------------- -> -- Ibraheem Umaru-Mohammed -- -> -- Email:ium@micromuse.com -- -> -- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, -> London SW18 1DA -- -> -- http://www.micromuse.com -- -> ------------------------------------------------------------- -> ------------------- -> -> _______________________________________________ -> Tutor maillist - Tutor@python.org -> http://mail.python.org/mailman/listinfo/tutor -> "The sender believes that this E-mail and any attachments were free of any virus, worm, Trojan horse, and/or malicious code when sent. This message and its attachments could have been infected during transmission. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective and remedial action about viruses and other defects. The sender's employer is not liable for any loss or damage arising in any way from this message or its attachments." From alan.gauld@freenet.co.uk Tue Feb 13 07:42:25 2001 From: alan.gauld@freenet.co.uk (Alan Gauld) Date: Tue, 13 Feb 2001 07:42:25 +0000 Subject: [Tutor] New tutorial translations Message-ID: <3.0.1.32.20010213074225.006ffebc@mail.freenet.co.uk> I'm pleased to announce 2 new translations of my online tutorial: Portuguese by Wilson Pinto: http://www.crosswinds.net/~agauld/port/ And German by Bup Schaeffer: http://www.crosswinds.net/~agauld/german/ Neither is fully completed yet but they both have all of the "concepts" and "basics" topics done Italian and Chech/Slovak versions are in progress. Hope these help someone, my thanks to Wilson and Bup for their hard work, Alan G. From bkoyuncu@hotmail.com Tue Feb 13 14:48:55 2001 From: bkoyuncu@hotmail.com (burak koyuncu) Date: Tue, 13 Feb 2001 14:48:55 Subject: [Tutor] Help !!! Message-ID:
I am studying Computer Engineering. This semester I have to give my final thesis to graduate. My thesis topic is: "Web based tutorial about Python". As it can be understood from the topic, there would be a tutorial that would teach someone Python from web. But this is not at all. Also this project must include some sample programs with Python which would run on the linux platform and output will be shown.
Can someone show me some way? How can I do this project? Please..
Thank you for your interest.
Burki


Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

From dsh8290@rit.edu Tue Feb 13 16:24:10 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 13 Feb 2001 11:24:10 -0500 Subject: [Tutor] Help !!! In-Reply-To: ; from bkoyuncu@hotmail.com on Tue, Feb 13, 2001 at 02:48:55PM +0000 References: Message-ID: <20010213112410.C10906@harmony.cs.rit.edu> (HTML mail is bad -- it is very hard to read the message between all those <..> tags, if you can please set it to Plain Text only) There is the python tutorial on www.python.org. If you have specific questions (like How do I ...?, or Why won't .. work?) we can answer them. Your question is a bit too vague. What are your specific examples supposed to do? If you want to let people run the interpreter interactively through their web browser I would recommend looking at Jython. Jython is the interpreter implemented in Java instead of C. Python code run by jython has full access to all the Java libraries. You could create an applet that will run the interpreter in a user's browser. -D On Tue, Feb 13, 2001 at 02:48:55PM +0000, burak koyuncu wrote:
I am studying Computer Engineering. This semester I have to give my final thesis to graduate. My thesis topic is: "Web based tutorial about Python". As it can be understood from the topic, there would be a tutorial that would teach someone Python from web. But this is not at all. Also this project must include some sample programs with Python which would run on the linux platform and output will be shown.
Can someone show me some way? How can I do this project? Please..
Thank you for your interest.
Burki


Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From tim@johnsons-web.com Tue Feb 13 16:57:45 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Tue, 13 Feb 2001 07:57:45 -0900 Subject: [Tutor] Textbook Recommendation References: <5104D4DBC598D211B5FE0000F8FE7EB20751D590@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01021307585001.10772@shecom> Hello All: Just a quick note to thank all who made text book recommendations to me. All of the input was greatly appreciated. Thanks!! -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From bsass@freenet.edmonton.ab.ca Tue Feb 13 19:21:18 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Tue, 13 Feb 2001 12:21:18 -0700 (MST) Subject: [Tutor] Help !!! In-Reply-To: Message-ID: Hi, I've only seen a few 'help me with my homework' messages before, this is the best one so far. :) On Tue, 13 Feb 2001, burak koyuncu wrote: > I am studying Computer Engineering. This semester I have to give my final > thesis to graduate. My thesis topic is: "Web based tutorial about > Python". As it can be understood from the topic, there would be a > tutorial that would teach someone Python from web. But this is not at > all. Also this project must include some sample programs with Python > which would run on the linux platform and output will be shown. > Can someone show me some way? How can I do this project? Please.. Hmmm, it sounds like you could get away with a web document that describes Python. i.e., Show you have an understanding of both how to construct a website and the Python language - no real user interaction or coding required, just a canned presention. That seems pretty basic for a Computer Engineering course (but what do I know, I studied Chemistry and chuckled at the Engineering students who were lost without a table to look stuff up in :). Are you expected to generate the site dynamically using Python code, or is it as straight-forward as it appears? If this is more than a 'do a website and regurgitate some Python information' project... you could look at ILU ftp://parcftp.parc.xerox.com/pub/ilu/ilu.html and do a prototype tutorial server and client with a sample Python tutorial. - Bruce From randrews@planhouse.com Tue Feb 13 20:30:52 2001 From: randrews@planhouse.com (Rob Andrews) Date: Tue, 13 Feb 2001 14:30:52 -0600 Subject: [Tutor] simple server and client question Message-ID: <3A89997C.961498E9@planhouse.com> I hate to even ask this one, because it just doesn't *feel* specific enough, but my sad little plea will have to do. The mandate has come from above that I write a simple server and client in Python in preparation for a project in development. The server and client can do absolutely anything, and barely that, if I so choose, as they will not be used in the project (unless my code is brilliant enough to be useful for the project, I suppose, which is unlikely as it's a Java project). The important thing is that I understand how to write such things. So if anyone can recommend any good sources I can absorb and start tinkering, I'd be mighty appreciative. Rob Andrews p.s.: The Useless Python site has undergone a serious renovation involving a hand re-coding in XHTML this last weekend. Anyone who has submitted source code might want to take a peek and make sure I didn't mess up your entries in the process. From Lindsay.Davies@moonshine.co.uk Tue Feb 13 21:21:54 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Tue, 13 Feb 2001 21:21:54 +0000 Subject: [Tutor] simple server and client question In-Reply-To: <3A89997C.961498E9@planhouse.com> References: <3A89997C.961498E9@planhouse.com> Message-ID: Can't give you a definitive answer, but look at the documentation for the asyncore/asynchat[1] and SocketServer[2] modules. These should give you some good pointers. You might also want to look at Medusa[3] (where asyncore originated from) for some advanced examples. Best wishes, Lindsay 1. http://www.python.org/doc/current/lib/asyncore-example.html 2. http://www.python.org/doc/current/lib/module-SocketServer.html 3. http://www.nightmare.com/medusa/index.html On 13/2/01, Rob Andrews wrote about '[Tutor] simple server and client question': >I hate to even ask this one, because it just doesn't *feel* specific >enough, but my sad little plea will have to do. > >The mandate has come from above that I write a simple server and client >in Python in preparation for a project in development. The server and >client can do absolutely anything, and barely that, if I so choose, as >they will not be used in the project (unless my code is brilliant enough >to be useful for the project, I suppose, which is unlikely as it's a >Java project). The important thing is that I understand how to write >such things. > >So if anyone can recommend any good sources I can absorb and start >tinkering, I'd be mighty appreciative. > >Rob Andrews > >p.s.: The Useless Python site has undergone a serious renovation >involving a hand re-coding in XHTML this last weekend. Anyone who has >submitted source code might want to take a peek and make sure I didn't >mess up your entries in the process. > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor From randrews@planhouse.com Tue Feb 13 22:22:43 2001 From: randrews@planhouse.com (Rob Andrews) Date: Tue, 13 Feb 2001 16:22:43 -0600 Subject: [Tutor] simple server and client question References: <3A89997C.961498E9@planhouse.com> Message-ID: <003b01c0960b$7da2c5c0$dc00a8c0@Planhouse5> Thanks greatly. It's certainly more than I had already found. Now I just need to figure out what he means when he says "Do it with sockets, using non-buffered input/output if python easily makes the distinction in i/o." Rob ----- Original Message ----- From: "Lindsay Davies" To: Sent: Tuesday, February 13, 2001 3:21 PM Subject: Re: [Tutor] simple server and client question > Can't give you a definitive answer, but look at the documentation for > the asyncore/asynchat[1] and SocketServer[2] modules. These should > give you some good pointers. You might also want to look at Medusa[3] > (where asyncore originated from) for some advanced examples. > > Best wishes, > > Lindsay > > 1. http://www.python.org/doc/current/lib/asyncore-example.html > 2. http://www.python.org/doc/current/lib/module-SocketServer.html > 3. http://www.nightmare.com/medusa/index.html > > > On 13/2/01, Rob Andrews wrote about '[Tutor] simple server and client > question': > >I hate to even ask this one, because it just doesn't *feel* specific > >enough, but my sad little plea will have to do. > > > >The mandate has come from above that I write a simple server and client > >in Python in preparation for a project in development. The server and > >client can do absolutely anything, and barely that, if I so choose, as > >they will not be used in the project (unless my code is brilliant enough > >to be useful for the project, I suppose, which is unlikely as it's a > >Java project). The important thing is that I understand how to write > >such things. > > > >So if anyone can recommend any good sources I can absorb and start > >tinkering, I'd be mighty appreciative. > > > >Rob Andrews > > > >p.s.: The Useless Python site has undergone a serious renovation > >involving a hand re-coding in XHTML this last weekend. Anyone who has > >submitted source code might want to take a peek and make sure I didn't > >mess up your entries in the process. > > > >_______________________________________________ > >Tutor maillist - Tutor@python.org > >http://mail.python.org/mailman/listinfo/tutor > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From scarblac@pino.selwerd.nl Tue Feb 13 22:52:22 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 13 Feb 2001 23:52:22 +0100 Subject: [Tutor] simple server and client question In-Reply-To: <3A89997C.961498E9@planhouse.com>; from randrews@planhouse.com on Tue, Feb 13, 2001 at 02:30:52PM -0600 References: <3A89997C.961498E9@planhouse.com> Message-ID: <20010213235222.A4533@pino.selwerd.nl> On Tue, Feb 13, 2001 at 02:30:52PM -0600, Rob Andrews wrote: > I hate to even ask this one, because it just doesn't *feel* specific > enough, but my sad little plea will have to do. > > The mandate has come from above that I write a simple server and client > in Python in preparation for a project in development. The server and > client can do absolutely anything, and barely that, if I so choose, as > they will not be used in the project (unless my code is brilliant enough > to be useful for the project, I suppose, which is unlikely as it's a > Java project). The important thing is that I understand how to write > such things. > > So if anyone can recommend any good sources I can absorb and start > tinkering, I'd be mighty appreciative. If you get the source distribution of Python, there is quite some stuff in the Demo/ and Tools/ dirs, and the standard library of course. In Demo/sockets, there is a "hello world" style unix socket client and a socket server (unixclient.py and unixserver.py). Understand these first. Then there are sample implementations of all kinds of clients in that dir. Try to make a little server that listen for connections, and a client that can connect to it, so you can send text messages to the screen of the server. This is the lowest level. Now play with http. With the standard module BaseHTTPServer you can make a simple web server and run it. With urllib you can send requests to web servers. Try if you can get them to work together. This is high level. Now I don't know how the HTTP server actually works, maybe you need threads as well. Now the first thing I would think of to make as a test case is a chat server where multiple people can login and they all see each other's messages :). XML-RPC might be fun to look into as well - send complex datatype to another python program by turning it into xml and giving it to a web server. There's a good library for this at www.secretlabs.com, if I recall correctly. So, this is how I would approach it. -- Remco Gerlich From gibbs05@flash.net Tue Feb 13 22:57:50 2001 From: gibbs05@flash.net (Harry Kattz) Date: Tue, 13 Feb 2001 16:57:50 -0600 Subject: [Tutor] simple server and client question References: <3A89997C.961498E9@planhouse.com> Message-ID: <03b201c09610$6fe9a480$d6de3040@gibbs05> Greetings Rob & All, My suggestion for ginning up Python client / server fast would be XML-RPC using xmlrpclib.py by Fredrik Lundh over at PythonLabs. You can download it at http://www.pythonware.com/products/xmlrpc/ There are two good articles on Python and XML-RPC at the O'Reilly Network: http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html Using xmlrpclib.py you'll have a test client & server done in less than two hours and you'll probably have a small demo in your boss's area of interest done before the weekend. You'll probably want to check out Medusa and Zope while you're on this subject also. > I hate to even ask this one, because it just doesn't *feel* specific > enough, but my sad little plea will have to do. > > The mandate has come from above that I write a simple server and client > in Python in preparation for a project in development. The server and > client can do absolutely anything, and barely that, if I so choose, as > they will not be used in the project (unless my code is brilliant enough > to be useful for the project, I suppose, which is unlikely as it's a > Java project). The important thing is that I understand how to write > such things. How hooked are they on using Java for this? Do you know if they're going to use EJB or go with straight RMI? I spent five months working with two other programmers on a Java project using Swing and EJB that could have been done in only two months by one programmer using Python with Tkinter and XML-RPC. Make sure to tell 'those above' that the Java solution will be over five times as expensive. :-) > So if anyone can recommend any good sources I can absorb and start > tinkering, I'd be mighty appreciative. > > Rob Andrews Good luck Sam From bsass@freenet.edmonton.ab.ca Tue Feb 13 23:13:26 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Tue, 13 Feb 2001 16:13:26 -0700 (MST) Subject: [Tutor] simple server and client question In-Reply-To: <3A89997C.961498E9@planhouse.com> Message-ID: On Tue, 13 Feb 2001, Rob Andrews wrote: > I hate to even ask this one, because it just doesn't *feel* specific > enough, but my sad little plea will have to do. > > The mandate has come from above that I write a simple server and client > in Python in preparation for a project in development. The server and > client can do absolutely anything, and barely that, if I so choose, as > they will not be used in the project (unless my code is brilliant enough > to be useful for the project, I suppose, which is unlikely as it's a > Java project). The important thing is that I understand how to write > such things. > > So if anyone can recommend any good sources I can absorb and start > tinkering, I'd be mighty appreciative. Have a look at ftp://parcftp.parc.xerox.com/pub/ilu/ilu.html The scope is probably a little more than what you need, but it does run on lots of platforms and supports clients and servers done in a number of programming languages (python, c, c++, java,...), using a couple(few?) interface specification languages (corba's IDL, and ILU's ISL). An interesting read if nothing else. - Bruce From deirdre@deirdre.net Tue Feb 13 23:23:08 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 13 Feb 2001 15:23:08 -0800 (PST) Subject: [Tutor] simple server and client question In-Reply-To: <3A89997C.961498E9@planhouse.com> Message-ID: On Tue, 13 Feb 2001, Rob Andrews wrote: > The mandate has come from above that I write a simple server and > client in Python in preparation for a project in development. The > server and client can do absolutely anything, and barely that, if I so > choose, as they will not be used in the project (unless my code is > brilliant enough to be useful for the project, I suppose, which is > unlikely as it's a Java project). The important thing is that I > understand how to write such things. Well, without wrapping a big abstraction around it, sometimes it's just fun to play at the low level and see how these things work. Thus, I recommend at least trying a very little project at the low level socket modele WITHOUT a lot of abstraction, etc. Get your hands dirty. With all due respect, the prior suggestion for XML-RPC is SO overkill -- a web server just blats a file out to a port after adding some headers. Now, with that, you should be able to write a web server of your own; a mini web server that can run from inetd.conf (i.e. one that exits right after delivering a file) should be able to be written in a very few lines of code. Ok, here's a really stupid client/server pair, just for amusement and amazement. This is an adaptation of the examples found in the library docs. The server opens up an unprivileged port (> 1023), in this case, 30242, on the server localhost (aka 127.0.0.1). It waits for a client. The client, when connected, sends the phrase "foo." The server responds "bar." The client waits for the server. They repeat this two times, then the server closes the connection. Ready? Server code: import socket HOST = '' # Symbolic name meaning the local host PORT = 30242 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr count = 0 while 1: data = conn.recv(1024) if not data: break print "Data received:",data if data == 'foo': conn.send('bar') count = count + 1 else: conn.send('err') if count == 3: break print 'Closing connection to', addr s.close() client code: import socket HOST = '' # Symbolic name meaning the local host PORT = 30242 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) count = 0 while 1: count = count + 1 if count == 2: s.send('boo!') else: s.send('foo') data = s.recv(1024) if not data: break print data if count == 4: break print 'Closing connection.' s.close() _Deirdre From rob@jam.rr.com Wed Feb 14 00:09:05 2001 From: rob@jam.rr.com (R. A.) Date: Tue, 13 Feb 2001 18:09:05 -0600 Subject: [Tutor] simple server and client question References: Message-ID: <3A89CCA1.64DF9087@jam.rr.com> Sweet! I didn't expect such a wealth of replies so quickly, and now I have a good deal of stuff to play with this evening. Deirdre, is there any way I could talk you into allowing me to post the client & server code to Useless Python? Rob Deirdre Saoirse wrote: > > On Tue, 13 Feb 2001, Rob Andrews wrote: > > > The mandate has come from above that I write a simple server and > > client in Python in preparation for a project in development. The > > server and client can do absolutely anything, and barely that, if I so > > choose, as they will not be used in the project (unless my code is > > brilliant enough to be useful for the project, I suppose, which is > > unlikely as it's a Java project). The important thing is that I > > understand how to write such things. > > Well, without wrapping a big abstraction around it, sometimes it's just > fun to play at the low level and see how these things work. Thus, I > recommend at least trying a very little project at the low level socket > modele WITHOUT a lot of abstraction, etc. Get your hands dirty. > > With all due respect, the prior suggestion for XML-RPC is SO overkill -- > a web server just blats a file out to a port after adding some headers. > > Now, with that, you should be able to write a web server of your own; a > mini web server that can run from inetd.conf (i.e. one that exits right > after delivering a file) should be able to be written in a very few lines > of code. > > Ok, here's a really stupid client/server pair, just for amusement and > amazement. This is an adaptation of the examples found in the library > docs. > > The server opens up an unprivileged port (> 1023), in this case, 30242, on > the server localhost (aka 127.0.0.1). It waits for a client. The client, > when connected, sends the phrase "foo." The server responds "bar." The > client waits for the server. They repeat this two times, then the server > closes the connection. > > Ready? > > Server code: > > import socket > HOST = '' # Symbolic name meaning the local host > PORT = 30242 # Arbitrary non-privileged port > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((HOST, PORT)) > s.listen(1) > conn, addr = s.accept() > print 'Connected by', addr > count = 0 > while 1: > data = conn.recv(1024) > if not data: break > print "Data received:",data > if data == 'foo': > conn.send('bar') > count = count + 1 > else: > conn.send('err') > > if count == 3: > break > > print 'Closing connection to', addr s.close() > > client code: > > import socket > HOST = '' # Symbolic name meaning the local host > PORT = 30242 # Arbitrary non-privileged port > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) > count = 0 > while 1: > count = count + 1 > if count == 2: > s.send('boo!') > else: > s.send('foo') > data = s.recv(1024) > if not data: break > print data > > if count == 4: > break > > print 'Closing connection.' s.close() > > _Deirdre > > _______________________________________________ > 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 deirdre@deirdre.net Wed Feb 14 00:07:46 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 13 Feb 2001 16:07:46 -0800 (PST) Subject: [Tutor] simple server and client question In-Reply-To: <3A89CCA1.64DF9087@jam.rr.com> Message-ID: On Tue, 13 Feb 2001, R. A. wrote: > Deirdre, is there any way I could talk you into allowing me to post the > client & server code to Useless Python? Sure, I don't have a problem with that. :) This was the kind of futzing around I did before writing my (still unpublished) APOP server. Now that I've solved the security issue, I may yet wrap it up. _Deirdre From chris@collegewafer.com Wed Feb 14 09:38:23 2001 From: chris@collegewafer.com (Chris Baker) Date: Wed, 14 Feb 2001 04:38:23 -0500 Subject: [Tutor] Hi, Need 6"-8" Wafer Special! Si, SOI, ZnO, MEMS & More! Message-ID: <200102140938.DAA07936@ionet.net> Hi, Let CollegeWafer.com take care of your wafer needs! Save time and $$$ It= 's a=20 FREE service to you! Visit http://www.collegewafer.com or call 800-713-9375, Fax 888-832-0340 = or email=20 chris@collegewafer.com We have AIN, Fused Silica, Pyrex, GaN, SiC, ZnO of course Si, SOI, Ultra-= Thin=20 Si, Ge, InP, ZnSe, ZnO, ZnS, GaP, Infrared and so much more, including: Custom orders for Prime wafers, Test wafers, or Coin Roll wafers.=20 5" N<100> 5-10 ohm-cm. 24-25.9mils 5" N <100> 10-20 ohm-cm. 24-26mils=20 5" P<100> 5-10 ohm-cm. 24-25.9mils=20 5" P<100> 10-20 ohm-cm. 24-25.9mils 6" N<100> 1-5 ohm-cm. 25-27.9mils=20 6" N<100> 10-20 ohm-cm. 585-725=B5m =20 6" N<100> 10-20 ohm-cm. >650=B5m =20 6" N<100> 20-30 ohm-cm. 625-725=B5m 6" N<100> 20-30 ohm-cm. 25-27.5mils 6" P<100> 1-10 ohm-cm. 625-725=B5m=20 6" P<100> 10-20 ohm-cm. 625-725=B5m=20 6" P<100> 2-15 ohm-cm. 625-725=B5m=20 6" P<100> >30 ohm-cm. 25-27.5mils=20 8" P<100> 1-10 ohm-cm. 675-775=B5m=20 8" P<100> 10-20 ohm-cm. 675-775=B5m=20 8" P<100> 10-20 ohm-cm. 700-750=B5m=20 8" P<100> 10-20 ohm-cm. 700-750=B5m=20 12" P <100> 1-100 ohm-cm.750-800=B5m=20 Polishing and Reclaim: We can polish test and prime wafers at better than SEMI standard spe= cifications. Need Wafer inspection services? Test your wafers for type, resistivity, thickness, TI= R, STIR,=20 TTV, FPD and cleanliness analysis. How about: Cleaning, Lapping, Etching, Edge round, graphic printouts (2D &= 3D),=20 Certificate of Conformance, Certificate of Analysis, Polishing, = Reclaim=20 Services, Laser-cutting and Oxide Services=20 Ask about In-House Oxide Services:=20 Thermally grown oxide for 2"-8" wafers ranging in thickness from 500-100,= 000=20 Angstroms. http://www.collegewafer.com/contact_us/Remove/remove.html 11ada22 From wheelege@tsn.cc Wed Feb 14 10:55:57 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Wed, 14 Feb 2001 21:55:57 +1100 Subject: [Tutor] Rather vague questions.... (Tkinter) Message-ID: <00b201c09674$b6770500$90755cca@glen> This is a multi-part message in MIME format. ------=_NextPart_000_00AF_01C096D0.E9474560 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I have gotten this error, while running a little python program I am = creating as a project. Here is the error : Traceback (most recent call last): File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball = game.py", line 264, in gogamego Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the = reassigning of the ball's coords File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords self.tk.splitlist( TclError: invalid command name ".22703164" It's an error which pops up in the interactive window every time the = program quits. It could have something to do with the thread still = running and thus losing all the objects it was referencing - but I don't = know enough about the error messages to tell if this is the case. Sometimes (damn intermittent errors) the main thread of the program = quits (I think...I should probably trap the exit() call...) for no = reason. I am hoping that it has something to do with this error. It = seems the faster I make the thread run the sooner it quits, and I can = almost get it to quit every single time I run it at a fast speed (with a = 0.0025 second delay between each iteration) it breaks every time. When = it does this, it shows a different error to the one above, it shows this = one : Traceback (most recent call last): File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball = game.py", line 265, in gogamego Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) ## the = reassigning of the ball's coords File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords self.tk.splitlist( ValueError: invalid literal for float(): expected I'm running an Athlon 600mhz system, 256mb ram and windows 98. I know = threads aren't all that great in windows...but I seriously need them. = The program will be an arkanoid type game (use a paddle to bounce a ball = and smash blocks) when I'm finished. Which will be a long time :) I'd rather not post the code because it is in super early newbie alpha = stage and not worth showing to my Mum :) But of course I will if I have = to. Thanks, Glen. ------=_NextPart_000_00AF_01C096D0.E9474560 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hi all,
 
  I have gotten this error, while running a little python = program I am=20 creating as a project.  Here is the error :
 
Traceback (most recent call last):
  File=20 "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball game.py", = line=20 264, in gogamego
    Screen.coords(ballphys, Ball.x1, = Ball.y1,=20 Ball.x2, Ball.y2) #the reassigning of the ball's coords
  File=20 "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in = coords
   =20 self.tk.splitlist(
TclError: invalid command name ".22703164"
 
  It's an error which pops up in the interactive window every = time the=20 program quits.  It could have something to do with the thread still = running=20 and thus losing all the objects it was referencing - but I don't know = enough=20 about the error messages to tell if this is the case.
  Sometimes (damn intermittent errors) the main thread of the = program=20 quits (I think...I should probably trap the exit() call...) for no = reason. =20 I am hoping that it has something to do with this error.  It seems = the=20 faster I make the thread run the sooner it quits, and I can almost get = it to=20 quit every single time I run it at a fast speed (with a 0.0025 second = delay=20 between each iteration) it breaks every time.  When it does this, = it shows=20 a different error to the one above, it shows this one :
 
Traceback (most recent call last):
  File=20 "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball game.py", = line=20 265, in gogamego
    Screen.coords(ballphys, Ball.x1, = Ball.y1,=20 Ball.x2, Ball.y2) ## the reassigning of the ball's coords
  File = "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in = coords
   =20 self.tk.splitlist(
ValueError: invalid literal for float():=20 expected
  I'm running an Athlon 600mhz system, 256mb ram and windows = 98. =20 I know threads aren't all that great in windows...but I seriously need=20 them.  The program will be an arkanoid type game (use a paddle to = bounce a=20 ball and smash blocks) when I'm finished.  Which will be a long = time=20 :)
  I'd rather not post the code because it is in super early = newbie=20 alpha stage and not worth showing to my Mum :)  But of course I = will if I=20 have to.
 
  Thanks,
  Glen.
------=_NextPart_000_00AF_01C096D0.E9474560-- From arcege@shore.net Wed Feb 14 12:32:31 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 14 Feb 2001 07:32:31 -0500 (EST) Subject: [Tutor] Rather vague questions.... (Tkinter) In-Reply-To: <00b201c09674$b6770500$90755cca@glen> from "Glen Wheeler" at Feb 14, 2001 09:55:57 PM Message-ID: <200102141232.HAA18438@northshore.shore.net> > Hi all, > > I have gotten this error, while running a little python program I am = > creating as a project. Here is the error : > > Traceback (most recent call last): > File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball = > game.py", line 264, in gogamego > Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the = > reassigning of the ball's coords > File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords > self.tk.splitlist( > TclError: invalid command name ".22703164" > > It's an error which pops up in the interactive window every time the = > program quits. It could have something to do with the thread still = > running and thus losing all the objects it was referencing - but I don't = > know enough about the error messages to tell if this is the case. > Sometimes (damn intermittent errors) the main thread of the program = > quits (I think...I should probably trap the exit() call...) for no = > reason. I am hoping that it has something to do with this error. It = > seems the faster I make the thread run the sooner it quits, and I can = > almost get it to quit every single time I run it at a fast speed (with a = > 0.0025 second delay between each iteration) it breaks every time. When = > it does this, it shows a different error to the one above, it shows this = > one : Yes, without the code there is only so much we can do to help you, but here are some things to thing about. First, Tkinter will only work "well" if it is running in the main (first) thread. You can delegate other functionality to the additional peer threads, but you'll run into problems (likely the ones you've seen). You might want to do some searches in the archives at www.python.org/search. Second, it is often not necessary to have separate threads. Most things that will need to be done are just at specific intervals (updating non-player "enemies", etc.). Those can be done with the after() and after_idle() methods instead of using threads. Threads lead to complications with data integrity, indefinate postponement and deadlock, to name just a few issues involved. Please make sure that you NEED threads before you think to use them; you'll find that your programming needs to much more complex. But even if you think you need threads, make sure that Tkinter is in the main thread. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From wheelege@tsn.cc Wed Feb 14 21:02:25 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Thu, 15 Feb 2001 08:02:25 +1100 Subject: [Tutor] Rather vague questions.... (Tkinter) References: <200102141232.HAA18438@northshore.shore.net> Message-ID: <002f01c096c9$6fa5bea0$e5755cca@glen> Thanks for the quick reply. I've now got : Traceback (most recent call last): File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball game.py", line 266, in gogamego Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) ## the reassigning of the ball's coords File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords self.tk.splitlist( TclError: invalid command name ".21933052" Nutted out. That was the exception occuring if the main thread unexpectedly quit (ie no break command or natural end), and I found the error that made it occur. I replaced another thread I had (now I onyl have one thread) which created other things for you to play with, and replaced it with a whole load of event bindings. Seems to work better now. However, the other error I was getting seems to have run off from my program. I cannot recreate it. That was a problem because it would only occur at high speeds, and would crash the whole thing. Maybe it was to do with my computer not being restarted in a long long time. Whatever it was, be sure I'll post it again (along with some code, if it looks nicer by then) because I will not have any idea how it came about. I really do need at least one thread, but I think I can do other minor operations not with threads. I've read a bit about them, and the docs are not hugely confident in their stability (hey who would be). I think I'm going to have to do some more fiddling with little baby thread applications - I strongly suspect the reason I was getting the error about float() was because a floating point variable used in the same while loops as that command was confused with an integer - but I'm not sure. I hope that isn't true because if it is I have no idea how to fix it. Thanks again, Glen. ----- Original Message ----- From: Michael P. Reilly To: Glen Wheeler Cc: Sent: Wednesday, February 14, 2001 11:32 PM Subject: Re: [Tutor] Rather vague questions.... (Tkinter) > > Hi all, > > > > I have gotten this error, while running a little python program I am = > > creating as a project. Here is the error : > > > > Traceback (most recent call last): > > File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball = > > game.py", line 264, in gogamego > > Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the = > > reassigning of the ball's coords > > File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords > > self.tk.splitlist( > > TclError: invalid command name ".22703164" > > > > It's an error which pops up in the interactive window every time the = > > program quits. It could have something to do with the thread still = > > running and thus losing all the objects it was referencing - but I don't = > > know enough about the error messages to tell if this is the case. > > Sometimes (damn intermittent errors) the main thread of the program = > > quits (I think...I should probably trap the exit() call...) for no = > > reason. I am hoping that it has something to do with this error. It = > > seems the faster I make the thread run the sooner it quits, and I can = > > almost get it to quit every single time I run it at a fast speed (with a = > > 0.0025 second delay between each iteration) it breaks every time. When = > > it does this, it shows a different error to the one above, it shows this = > > one : > > Yes, without the code there is only so much we can do to help you, but > here are some things to thing about. > > First, Tkinter will only work "well" if it is running in the main > (first) thread. You can delegate other functionality to the additional > peer threads, but you'll run into problems (likely the ones you've > seen). You might want to do some searches in the archives at > www.python.org/search. > > Second, it is often not necessary to have separate threads. Most > things that will need to be done are just at specific intervals > (updating non-player "enemies", etc.). Those can be done with the > after() and after_idle() methods instead of using threads. > > Threads lead to complications with data integrity, indefinate > postponement and deadlock, to name just a few issues involved. Please > make sure that you NEED threads before you think to use them; you'll > find that your programming needs to much more complex. > > But even if you think you need threads, make sure that Tkinter is in > the main thread. > > -Arcege > > -- > ------------------------------------------------------------------------ > | Michael P. Reilly, Release Manager | Email: arcege@shore.net | > | Salem, Mass. USA 01970 | | > ------------------------------------------------------------------------ From Christopher Bemis" This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C096A2.65F50A40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am learning Python with"Learn Python in 24 hours", and am getting = quite a good grasp of the programming aspect....However here's my = problem........With all the sample progs that I've written I've used = Notepad as my editor....I save them as text as script.py.....but when I = try to run them I can't. I've tried Start/Run/.....py and I get a flash = of a DOS box. I try command prompt and it won't go at all.....I'm = running Win98Se....Is my DOS file path screwed up or is there something = else I need....I have Python2.0....or maybe I need a new DOS = prompt....how do I get one? Help Please =20 The Great One ------=_NextPart_000_000E_01C096A2.65F50A40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am = learning=20 Python with"Learn Python in 24 hours", and am getting quite a good grasp = of the=20 programming aspect....However here's my problem........With all the = sample progs=20 that I've written I've used Notepad as my editor....I save them as text = as=20 script.py.....but when I try to run them I can't. I've tried=20 Start/Run/.....py and I get a flash of a DOS box. I try command = prompt and=20 it won't go at all.....I'm running Win98Se....Is my DOS file path = screwed up or=20 is there something else I need....I have Python2.0....or maybe I need a = new DOS=20 prompt....how do I get one? Help = Please  
The = Great=20 One
------=_NextPart_000_000E_01C096A2.65F50A40-- From kalle@gnupung.net Wed Feb 14 22:04:34 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 14 Feb 2001 23:04:34 +0100 Subject: [Tutor] Running the programs In-Reply-To: <001101c096cc$50871a20$1008683f@laser151>; from laser151@tvn.net on Wed, Feb 14, 2001 at 04:23:00PM -0500 References: <001101c096cc$50871a20$1008683f@laser151> Message-ID: <20010214230434.D1361@apone.network.loc> --Qrgsu6vtpU/OV/zm Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Christopher Bemis: [flashing dos-box problem] What was wrong with the answers you recieved last time you asked? http://mail.python.org/pipermail/tutor/2001-February/003502.html http://mail.python.org/pipermail/tutor/2001-February/003504.html http://mail.python.org/pipermail/tutor/2001-February/003505.html http://mail.python.org/pipermail/tutor/2001-February/003510.html 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 --Qrgsu6vtpU/OV/zm 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 iD8DBQE6iwDydNeA1787sd0RAvYFAKCjqE0OFcKxAJEGJK4H9s2p2zRGdQCgk4yv q01Z6jGg4MpXWbhurpt0sfM= =Q/hB -----END PGP SIGNATURE----- --Qrgsu6vtpU/OV/zm-- From randrews@planhouse.com Wed Feb 14 21:59:19 2001 From: randrews@planhouse.com (Rob Andrews) Date: Wed, 14 Feb 2001 15:59:19 -0600 Subject: [Tutor] Running the programs References: <001101c096cc$50871a20$1008683f@laser151> Message-ID: <000e01c096d1$6414f440$dc00a8c0@Planhouse5> Try opening a command prompt (DOS prompt, if you like), and changing to your Python directory. Then type something along these lines: C:\Python20> python helloworld.py Substitute the name of your script for 'helloworld', of course. And you can also run your script from within IDLE by typing: >>> import helloworld Does this help a bit? Rob Andrews ----- Original Message ----- From: Christopher Bemis To: tutor@python.org Sent: Wednesday, February 14, 2001 3:23 PM Subject: [Tutor] Running the programs I am learning Python with"Learn Python in 24 hours", and am getting quite a good grasp of the programming aspect....However here's my problem........With all the sample progs that I've written I've used Notepad as my editor....I save them as text as script.py.....but when I try to run them I can't. I've tried Start/Run/.....py and I get a flash of a DOS box. I try command prompt and it won't go at all.....I'm running Win98Se....Is my DOS file path screwed up or is there something else I need....I have Python2.0....or maybe I need a new DOS prompt....how do I get one? Help Please The Great One From arcege@shore.net Wed Feb 14 22:06:04 2001 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 14 Feb 2001 17:06:04 -0500 (EST) Subject: [Tutor] Running the programs In-Reply-To: <001101c096cc$50871a20$1008683f@laser151> from "Christopher Bemis" at Feb 14, 2001 04:23:00 PM Message-ID: <200102142206.RAA25590@northshore.shore.net> > I am learning Python with"Learn Python in 24 hours", and am getting = > quite a good grasp of the programming aspect....However here's my = > problem........With all the sample progs that I've written I've used = > Notepad as my editor....I save them as text as script.py.....but when I = > try to run them I can't. I've tried Start/Run/.....py and I get a flash = > of a DOS box. I try command prompt and it won't go at all.....I'm = > running Win98Se....Is my DOS file path screwed up or is there something = > else I need....I have Python2.0....or maybe I need a new DOS = > prompt....how do I get one? Help Please =20 In hour 2 (pp. 24-27), the author shows you how to run scripts/programs. >From the MS-DOS prompt, you type "python script.py" and look at the output in that box. -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From dsh8290@rit.edu Wed Feb 14 22:10:26 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 14 Feb 2001 17:10:26 -0500 Subject: [Tutor] Running the programs In-Reply-To: <001101c096cc$50871a20$1008683f@laser151>; from laser151@tvn.net on Wed, Feb 14, 2001 at 04:23:00PM -0500 References: <001101c096cc$50871a20$1008683f@laser151> Message-ID: <20010214171026.B17793@harmony.cs.rit.edu> On Wed, Feb 14, 2001 at 04:23:00PM -0500, Christopher Bemis wrote: | | I am learning Python with"Learn Python in 24 hours", and am getting | quite a good grasp of the programming aspect....However here's my | problem........With all the sample progs that I've written I've used | Notepad as my editor....I save them as text as script.py.....but when | I try to run them I can't. I've tried Start/Run/.....py and I get a | flash of a DOS box. I try command prompt and it won't go at | all.....I'm running Win98Se....Is my DOS file path screwed up or is | there something else I need....I have Python2.0....or maybe I need a | new DOS prompt....how do I get one? Help Please | People having trouble figuring out how to run scripts make me feel old -- they must not have used MS-DOS before the days of MS Windows came about. (Don't feel so bad, lots of people have this problem) By default, Windows will close the DOS box when the app is done. One workaround is to put the following line at the end of your program. Then it won't be done until you say it is ;-). raw_input( "Press enter to quit." ) Since you get a flash when you try Start->Run that means Windows has the association correct to run a .py file. (Unless you get a weird error in the DOS box, but you can't see it anyways...) There are a few things you can do if you want to run scripts from the commandline. a) Add c:\python20 (or whatever it is) to your PATH environment variable. This can be done in several ways : 1) type set PATH %PATH%;c:\python20 when you start up a DOS box 2) append set PATH %PATH%;c:\python20 to the end of your c:\autoexec.bat, then reboot ;-) This will put python in the path for all DOS boxes you open b) Type the full path to python every time you run it ( C:\myprog> c:\python20\python myscript.py ) =p c) Add a script (batch file) to a directory that is in the path, this script will run python with the full path and pass it any arguments you give -------- python.bat -------- c:\python20\python %1 %2 %3 %4 %5 %6 %7 %8 %9 My preference is (c). Actually, I use the bash shell provided by cygwin (I really prefer Linux, but ...) and put similar scripts in ~/bin. Bash is a much more powerful, convenient, and useful shell than DOS provides. (FYI an example script : ----------- ~/bin/python ------------- #!/bin/bash //c/python20/python $* As for your editor, notepad works but lacks the many conveniences of a "real" editor. I like gvim the best (www.vim.org) but it takes a while to learn all of the commands. There are other editors (and IDEs) for windows. I would strongly recommend finding one that you like. Some of the features I really like include : o autoindenting (and convenient re-indenting) o syntax highlighting o text wrapping (for long blocks of comments) o regex search and replace o rapid cursor movement HTH, -D BTW I'm not trying to start a flame war here about shells and editors, just providing some FYI From Christopher Peet" Message-ID: <011401c096e5$5123ed00$0200a8c0@horus> For me this is the easiest thing to do. Start IDLE and do a Control+n to open a new window. Type all your code in this new window and when you're ready to run it, save it to temp.py - and then making sure focus is still on the second window hit Control+F5. This will run the code in main IDLE window. Making changes is easy, edit your code and type ALT f(ile) s(ave) to save it again and rerun it with Control+F5. Very fast and you still have IDLE color coding your text so you'll know right away if your syntax it botched! You'll never go back to using notepad after you get used to this setup.. Cheers, Christopher Peet ----- Original Message ----- From: "Christopher Bemis" To: Sent: Wednesday, February 14, 2001 1:23 PM Subject: [Tutor] Running the programs I am learning Python with"Learn Python in 24 hours", and am getting quite a good grasp of the programming aspect....However here's my problem........With all the sample progs that I've written I've used Notepad as my editor....I save them as text as script.py.....but when I try to run them I can't. I've tried Start/Run/.....py and I get a flash of a DOS box. I try command prompt and it won't go at all.....I'm running Win98Se....Is my DOS file path screwed up or is there something else I need....I have Python2.0....or maybe I need a new DOS prompt....how do I get one? Help Please The Great One From darrell@brogdon.net Thu Feb 15 03:59:42 2001 From: darrell@brogdon.net (Darrell Brogdon) Date: Wed, 14 Feb 2001 22:59:42 -0500 Subject: [Tutor] building a tuple Message-ID: <3A8B542E.6020202@brogdon.net> I'm curious as to how to build a tuple out of data that I'm getting from a database result set. Can anyone point me in the right direction? Thanks -- Darrell Brogdon http://darrell.brogdon.net From darrell@brogdon.net Thu Feb 15 04:48:59 2001 From: darrell@brogdon.net (Darrell Brogdon) Date: Wed, 14 Feb 2001 23:48:59 -0500 Subject: [Tutor] building a tuple References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com> Message-ID: <3A8B5FBB.9000803@brogdon.net> Ok, so for example, I'm getting the following data: Field Name Value ------------------------ fname John lname Doe address 123 Any St. city Anytown Now I know I can manually build a tuple out of this data with the following: my_tuple { "fname" : "John", "lname" : "Doe", "address" : "123 Any St." "city" : "Anytown" } But obviously with this data coming from the database I wouldn't know what the values are. I've figured out how to get the data out of the database for the most part. Now its just a matter of how to get that data into a tuple. I think partly I'm confusing myself with my knowledge of PHP where you can pretty much get away with anything. :) -Darrell R. A. wrote: > Can you provide a little more info? Info on tuples themselves may be > found in all the standard tutorials. Do you have to interact with the > database itself, or just with a data table? > > Rob > > Darrell Brogdon wrote: > >> I'm curious as to how to build a tuple out of data that I'm getting from a database result set. Can anyone point me in the right direction? >> >> Thanks >> >> -- >> Darrell Brogdon >> http://darrell.brogdon.net >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor > -- Darrell Brogdon http://darrell.brogdon.net From Lindsay.Davies@moonshine.co.uk Thu Feb 15 08:15:54 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Thu, 15 Feb 2001 08:15:54 +0000 Subject: [Tutor] building a tuple In-Reply-To: <3A8B5FBB.9000803@brogdon.net> References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com> <3A8B5FBB.9000803@brogdon.net> Message-ID: Darrell - I think I see where some of the confusion is coming from. The code snippet below shows you building a dictionary (AKA hash or associative array), NOT a tuple, which is an immutable array. If you are asking how do you build a dictionary from the result of a database query, then that is a different question from how to build a tuple. The answer to dictionary-building does depend on the module you are using to access the database. For example, both the MySQLdb.py and PgSQL.py modules allow you to retrieve a dictionary (or dictionary-like object) from a *.fetchall() call for example. There is devil in the detail though, so perhaps you need to supply more information, like the database and DB API module you are using to access it. Best wishes, Lindsay On 14/2/01, Darrell Brogdon wrote about 'Re: [Tutor] building a tuple': >Ok, so for example, I'm getting the following data: > >Field Name Value >------------------------ >fname John >lname Doe >address 123 Any St. >city Anytown > >Now I know I can manually build a tuple out of this data with the following: > > my_tuple { > "fname" : "John", > "lname" : "Doe", > "address" : "123 Any St." > "city" : "Anytown" > } > >But obviously with this data coming from the database I wouldn't >know what the values are. I've figured out how to get the data out >of the database for the most part. Now its just a matter of how to >get that data into a tuple. > >I think partly I'm confusing myself with my knowledge of PHP where >you can pretty much get away with anything. :) > From wheelege@tsn.cc Thu Feb 15 08:21:26 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Thu, 15 Feb 2001 19:21:26 +1100 Subject: [Tutor] Running the programs References: <001101c096cc$50871a20$1008683f@laser151> <20010214171026.B17793@harmony.cs.rit.edu> Message-ID: <007a01c09728$4ac6c340$8f755cca@glen> As Kalle said, this has been asked many times before. Can you not receive tutor mail back? From rsmith@ffs.cc Thu Feb 15 13:23:17 2001 From: rsmith@ffs.cc (Ryan Smith) Date: Thu, 15 Feb 2001 08:23:17 -0500 Subject: [Tutor] i want to learn to hack Message-ID: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> how do i hack? -Ryan From Lindsay.Davies@moonshine.co.uk Thu Feb 15 13:43:34 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Thu, 15 Feb 2001 13:43:34 +0000 Subject: [Tutor] i want to learn to hack In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> Message-ID: On 15/2/01, Ryan Smith wrote about '[Tutor] i want to learn to hack': >how do i hack? Hacking[1] or cracking[2]? In the latter case, this isn't the right list. If you want to learn to program, and be creative and constructive in your programming, then of course, Python's a good starting point. Best wishes, Lindsay --courtesy of everything2.com-- [1] The art of programming that uses both accepted design principles, kluges, and software/hardware fixes (whichever is inappropriate) to get the job done. It is frequently confused with cracking. [2] The act of breaking into a computer system; what a cracker does. Contrary to widespread myth, this does not usually involve some mysterious leap of hackerly brilliance, but rather persistence and the dogged repetition of a handful of fairly well-known tricks that exploit common weaknesses in the security of target systems. Accordingly, most crackers are only mediocre hackers. From scarblac@pino.selwerd.nl Thu Feb 15 13:52:38 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 15 Feb 2001 14:52:38 +0100 Subject: [Tutor] i want to learn to hack In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>; from rsmith@ffs.cc on Thu, Feb 15, 2001 at 08:23:17AM -0500 References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> Message-ID: <20010215145238.A7487@pino.selwerd.nl> On Thu, Feb 15, 2001 at 08:23:17AM -0500, Ryan Smith wrote: > how do i hack? That depends on what you mean. If you mean breaking into computers, that is called "cracking", is not the subject of this list, and is a sad thing for kids who have nothing better to do. No help from us there. The first two meanings of the verb 'hack' that the Jargon File gives: 1.n Originally, a quick job that produces what is needed, but not well. 2.n An incredibly good, and perhaps very time-consuming piece of work that produces exactly what is needed. In general, it's a style of programming, very informal, but very fanatical. A lot of the best open source software came into being because someone started programming something cool, and continued for a few nights. Hacking is fun. As a start, I'd say you read - ESR's "How to become a Hacker FAQ" at http://www.tuxedo.org/~esr/faqs/hacker-howto.html Or maybe you read that and then came here. - If you're not a programmer yet, I suggest you start with Alan Gauld's online book http://www.crosswinds.net/~agauld/ to learn programming, using Python. This list is for beginning Python programmers, to ask questions. So if you have any problems with that part, you're welcome to ask here :). -- Remco Gerlich From dsh8290@rit.edu Thu Feb 15 14:20:13 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 15 Feb 2001 09:20:13 -0500 Subject: [Tutor] i want to learn to hack In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>; from rsmith@ffs.cc on Thu, Feb 15, 2001 at 08:23:17AM -0500 References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> Message-ID: <20010215092013.B132@harmony.cs.rit.edu> On Thu, Feb 15, 2001 at 08:23:17AM -0500, Ryan Smith wrote: | how do i hack? | | -Ryan | Is this a new e-mail address, or are you not the same Ryan on the gimpwin-users list? I'll assume that you intend the good definition of 'hack'. What do you want to accomplish from your hacking? This list is very helpful at explaining various programming concepts and how they apply to python, but you must have some questions first. For example, to start with you could write the canonical "Hello World" program. In python that would be: -------------------- print "Hello World" -------------------- If you wanted to print it 10 times, you could ------------------------------ for i in range( 10 ) : print "Hello World" ------------------------------ Have you taken a look at the tutorial on www.python.org? It's a rather good tutorial, but I think it expects a basic knowledge of programming and computer operation. Alan Gauld also has a nice book (so I've heard) and I think there is quite a bit of useful information on his web site (I haven't been there, but other people say it is good, check the list archives for a url). Enjoy learning python! The gimp even has a plugin module so you can script it in python. -D From lumbricus@gmx.net Thu Feb 15 17:09:32 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Thu, 15 Feb 2001 18:09:32 +0100 (MET) Subject: [Tutor] i want to learn to hack References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer> Message-ID: <26883.982256972@www37.gmx.net> > how do i hack? > > -Ryan > > _______________________________________________ youre running windoze - right? fire up a dos prompt and type format c: hit return and get an os. ;-> read the dox. write progs. -jö -- Sent through GMX FreeMail - http://www.gmx.net From dbrogdon@valinux.com Thu Feb 15 18:44:06 2001 From: dbrogdon@valinux.com (Darrell Brogdon) Date: Thu, 15 Feb 2001 13:44:06 -0500 Subject: [Tutor] building a tuple References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com> <3A8B5FBB.9000803@brogdon.net> Message-ID: <3A8C2376.3030605@valinux.com> Well, I found that I could instead create a list and append to it using the extend() method and then convert the list into a tuple where I can work from there. You're right about my confusion. Here again, the line can be blurry sometimes in PHP. :) Anyway, thanks for the help and sorry for the vague post. When you're learning sometimes you don't quite know how to phrase your question. Lindsay Davies wrote: > Darrell - > > I think I see where some of the confusion is coming from. The code > snippet below shows you building a dictionary (AKA hash or associative > array), NOT a tuple, which is an immutable array. > > If you are asking how do you build a dictionary from the result of a > database query, then that is a different question from how to build a > tuple. > > The answer to dictionary-building does depend on the module you are > using to access the database. For example, both the MySQLdb.py and > PgSQL.py modules allow you to retrieve a dictionary (or dictionary-like > object) from a *.fetchall() call for example. There is devil in the > detail though, so perhaps you need to supply more information, like the > database and DB API module you are using to access it. > > Best wishes, > > Lindsay > > > > On 14/2/01, Darrell Brogdon wrote about 'Re: [Tutor] building a tuple': > >> Ok, so for example, I'm getting the following data: >> >> Field Name Value >> ------------------------ >> fname John >> lname Doe >> address 123 Any St. >> city Anytown >> >> Now I know I can manually build a tuple out of this data with the >> following: >> >> my_tuple { >> "fname" : "John", >> "lname" : "Doe", >> "address" : "123 Any St." >> "city" : "Anytown" >> } >> >> But obviously with this data coming from the database I wouldn't know >> what the values are. I've figured out how to get the data out of the >> database for the most part. Now its just a matter of how to get that >> data into a tuple. >> >> I think partly I'm confusing myself with my knowledge of PHP where you >> can pretty much get away with anything. :) >> > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Darrell Brogdon http://darrell.brogdon.net Web Developer - SourceForge http://sourceforge.net VA Linux Systems, Inc. http://www.valinux.com From tim@johnsons-web.com Thu Feb 15 20:43:19 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Thu, 15 Feb 2001 11:43:19 -0900 Subject: [Tutor] Need Python Images References: Message-ID: <01021511445503.01167@shecom> Hi: I'm doing an online class on Programming using python. I'd appreciate being pointed towards images (preferably gifs) displaying python. They will help to dress up the content -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From randrews@planhouse.com Thu Feb 15 20:55:00 2001 From: randrews@planhouse.com (Rob Andrews) Date: Thu, 15 Feb 2001 14:55:00 -0600 Subject: [Tutor] Need Python Images References: <01021511445503.01167@shecom> Message-ID: <001801c09791$90c5ad20$9600a8c0@Planhouse5> The "Python Powered" logo may be found at: http://www.python.org/psa/Logo.html I've been intending to whip up some snazzy Python pics in Photoshop lately, but haven't been able to fit it into my copious free time lately. What's your deadline? Rob ----- Original Message ----- > Hi: > I'm doing an online class on Programming using python. > I'd appreciate being pointed towards images (preferably gifs) displaying python. > They will help to dress up the content > -- > Tim Johnson > ----------- > "Of all manifestations of power, > restraint impresses the most." > -Thucydides From pythoperson@yahoo.com Thu Feb 15 21:02:43 2001 From: pythoperson@yahoo.com (folklore hopeful) Date: Thu, 15 Feb 2001 13:02:43 -0800 (PST) Subject: [Tutor] Python copyright question? Message-ID: <20010215210243.673.qmail@web12402.mail.yahoo.com> Hello everyone, I have made quite a few handy python/tkinter programs that the professors at my college would like to distribute to students in their classes. Since downloading and installing python is a lot to ask of all the students, and since not all the students would have home computers, we are trying to come up with an alternate solution. So far, we were thinking of distributing a cd-rom with python installed on it and the scripts for the programs I have written. This way, students could use them either on their home computers OR on the college's comptuers (which don't take kindly to installations but will run CD-ROMs). Would this sort of copying be legal? Thanks, - pythoperson __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ From Christopher Bemis" This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C0976F.7768E120 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable It worked! I can run the programs! I feel like a lumberjack!!! Thank you = all for your suggestions on running my programs, they all helped to some = degree.... The Great One ------=_NextPart_000_000A_01C0976F.7768E120 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
It = worked! I can=20 run the programs! I feel like a lumberjack!!! Thank you all for your = suggestions=20 on running my programs, they all helped to some = degree....
The = Great=20 One
------=_NextPart_000_000A_01C0976F.7768E120-- From shaleh@valinux.com Thu Feb 15 22:23:37 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 15 Feb 2001 14:23:37 -0800 Subject: [Tutor] question about glob.glob() implementation Message-ID: <20010215142337.E11714@valinux.com> glob.glob() has a section like: if not has_magic(basename): result = [] for dirname in list: if basename or os.path.isdir(dirname): name = os.path.join(dirname, basename) if os.path.exists(name): result.append(name) else: For every iteration of the for loop, basename is tested, yet its value never changes. Am I missing something here or is this wasteful like i think it is? From dsh8290@rit.edu Thu Feb 15 23:57:00 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 15 Feb 2001 18:57:00 -0500 Subject: [Tutor] Python copyright question? In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com>; from pythoperson@yahoo.com on Thu, Feb 15, 2001 at 01:02:43PM -0800 References: <20010215210243.673.qmail@web12402.mail.yahoo.com> Message-ID: <20010215185659.A1668@harmony.cs.rit.edu> On Thu, Feb 15, 2001 at 01:02:43PM -0800, folklore hopeful wrote: | Hello everyone, | | I have made quite a few handy python/tkinter programs | that the professors at my college would like to | distribute to students in their classes. Since | downloading and installing python is a lot to ask of | all the students, and since not all the students would | have home computers, we are trying to come up with an | alternate solution. So far, we were thinking of | distributing a cd-rom with python installed on it and | the scripts for the programs I have written. This | way, students could use them either on their home | computers OR on the college's comptuers (which don't | take kindly to installations but will run CD-ROMs). | Would this sort of copying be legal? | | Thanks, | | - pythoperson | I think it would be legal to copy the interpreter like that. But I'm not a lawyer, so don't quote me. The license is freely available, and the interpreter is freely available as well. It would probably be simpler for you to just install python on the school's computers. (That is, get the appropriate authority's permission and have them set up by the proper admin) You should probably ask on python-list since there are people with a better understanding of the license. Programs such as py2exe and Gordon McMillan's installer allow you to package the interpreter with your program into an installer (for Windows) so I don't think there is any problems with redistributing the interpreter. HTH, -D From scarblac@pino.selwerd.nl Fri Feb 16 00:20:51 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Fri, 16 Feb 2001 01:20:51 +0100 Subject: [Tutor] Python copyright question? In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com>; from pythoperson@yahoo.com on Thu, Feb 15, 2001 at 01:02:43PM -0800 References: <20010215210243.673.qmail@web12402.mail.yahoo.com> Message-ID: <20010216012051.A279@pino.selwerd.nl> On Thu, Feb 15, 2001 at 01:02:43PM -0800, folklore hopeful wrote: > I have made quite a few handy python/tkinter programs > that the professors at my college would like to > distribute to students in their classes. Since > downloading and installing python is a lot to ask of > all the students, and since not all the students would > have home computers, we are trying to come up with an > alternate solution. So far, we were thinking of > distributing a cd-rom with python installed on it and > the scripts for the programs I have written. This > way, students could use them either on their home > computers OR on the college's comptuers (which don't > take kindly to installations but will run CD-ROMs). > Would this sort of copying be legal? Certainly. Quoting from the Python 1.6 license which was basically carried to 2.0, you as individual or organization using Python 1.6 are the Licensee, and "2. Subject to the terms and conditions of this License Agreement, CNRI hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, anayze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python 1.6 alone or in any derivative version, ..." [provided that the copyright notice is retained]. Well, *read the exact license yourself*. You are allowed to do absolutely anything with the code, as long as you list any changes to the original in some way, and CNRI/BeOpen/etc has no obligations to you whatsoever. -- Remco Gerlich From tim_one@email.msn.com Fri Feb 16 00:22:31 2001 From: tim_one@email.msn.com (Tim Peters) Date: Thu, 15 Feb 2001 19:22:31 -0500 Subject: [Tutor] Python copyright question? In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com> Message-ID: [folklore hopeful] Cool handle! > ... > So far, we were thinking of distributing a cd-rom with > python installed on it and the scripts for the programs > I have written. This way, students could use them either > on their home computers OR on the college's comptuers > (which don't take kindly to installations but will run > CD-ROMs). Would this sort of copying be legal? You didn't say which version of Python you're using. Each version comes with a license. Read the license -- it's good practice for the Real World . All Python licenses to date allow you to make copies and do distribution without asking for permission, or even telling us, unless you're using the ActiveState distribution. More details have to be gotten from the specific license for the specific version of Python you're using. While this is certainly not legal advice, just between us nobody has ever gotten in any trouble for doing anything with Python, and that's the way we like it. share-and-enjoy-but-read-the-darn-license-first-ly y'rs - tim From joejava@dragoncat.net Fri Feb 16 00:39:07 2001 From: joejava@dragoncat.net (Joel Ricker) Date: Thu, 15 Feb 2001 19:39:07 -0500 Subject: [Tutor] Automating Web Browsing References: <20010215210243.673.qmail@web12402.mail.yahoo.com> <20010216012051.A279@pino.selwerd.nl> Message-ID: <00aa01c097b0$ea52b120$a0a2d6d1@ceo> In my idle time -- when I have some anyway -- my diversion of choice has been the Hollywood Stock Exchange. For those not familiar with it, it is a simulation where you buy and sell stocks on actual movies. Alot like the real stock market it takes a little shrewness and research to make money and all around quite fun. My problem is that now that my portfolio has grown quite a bit, I'm having trouble keeping up with it. The number of stocks I have to buy and sell on a given day has increased to the point where it takes too much time to even play. [How this relates to Python] What I would like to do is automate my buying and selling, which amounts to logging in to the site, going to the buy/sell section, filling out a form with the Movies stock symbol, pressing buy, and pressing the confirm button, and then repeat. What modules can I use to accomplish this? In searching around for information I ran across a mention of LWP::UserAgent for Perl and it sounds kind of what I'm looking for -- except it uses Perl. Any ideas? Thanks Joel From tescoil@irtc.net Fri Feb 16 03:45:13 2001 From: tescoil@irtc.net (Tesla Coil) Date: Thu, 15 Feb 2001 21:45:13 -0600 Subject: [Tutor] Need Python Images References: <01021511445503.01167@shecom> Message-ID: <3A8CA249.27D0DAB6@irtc.net> On 15 Feb 2001, Tim Johnson wrote: > I'm doing an online class on Programming using python. > I'd appreciate being pointed towards images (preferably > gifs) displaying python. They will help to dress up the > content There's two or three images in http://www.python.org/pics/ I'm not certain are used in any html page on the site--like kick_camels_butt.gif and pythondo.gif. I took pythonHi.gif, did various snazzy stuff with it--not all extant and none of it published on the web, but easy enough to whip up again if you'd want 'em in email attachments ... or if R.A. decides to add a gallery for collecting Python propaganda images. ;) From britt_green@hotmail.com Fri Feb 16 04:38:58 2001 From: britt_green@hotmail.com (Britt Green) Date: Thu, 15 Feb 2001 20:38:58 -0800 Subject: [Tutor] Errr...Capitalizing Words Message-ID: Hello, I'm kind of stuck on something seemingly trivial, and I'm hoping someone can help me out. Say I have a block of text, all in lower case: this is some sample text. its all in lower case. there are no capitals in this block of text. you get the idea, and now i'm just typing to make a lot of text. What I want to do with Python is take the first letter of each sentance and capitalize it. By looking into the string library I've found the string.capitalize() function. This only seems to work if you know the word you're trying to use. Then string.capwords() will capitalize each word instead of just the first one. Can anyone point me in the right direction for 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 darrell@brogdon.net Fri Feb 16 06:41:01 2001 From: darrell@brogdon.net (Darrell Brogdon) Date: Fri, 16 Feb 2001 01:41:01 -0500 Subject: [Tutor] xmlrpclib docs/examples Message-ID: <3A8CCB7D.4020801@brogdon.net> Does anyone know where I can find *good* (see: any) documentation on xmlrpclib as well as some examples of how to use it? I've been playing around with it as a side project but the code isn't really documented all that well and what little info I find elsewhere really doesn't indicate how to use it. -- Darrell Brogdon http://darrell.brogdon.net From bsass@freenet.edmonton.ab.ca Fri Feb 16 08:19:31 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 16 Feb 2001 01:19:31 -0700 (MST) Subject: [Tutor] question about glob.glob() implementation In-Reply-To: <20010215142337.E11714@valinux.com> Message-ID: On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote: > glob.glob() has a section like: > > if not has_magic(basename): > result = [] > for dirname in list: > if basename or os.path.isdir(dirname): > name = os.path.join(dirname, basename) > if os.path.exists(name): > result.append(name) > else: > > For every iteration of the for loop, basename is tested, yet its value never > changes. Am I missing something here or is this wasteful like i think it is? Hmmm, it looks like a dual purpose routine. If basename is an empty string, result ends up with the paths to the dirs in list that exist (i.e., where can I look?). If basename has a value, result ends up with the paths that end in basename (i.e., is it there?). I think you're missing the logic of the for loop. If basename is "true", the action is always performed on dirname; if it is "false", the action is only performed when dirname is a dir. If dirname is a dir, the action is always performed; if dirname is not a dir the action is performed if basename is true. Since neither basename or os.path.isdir(dirname) alone can determine what to do it is necessary to test both for each value taken on by dirname. Check out the truth table; b is the basename term, d is the os.path.isdir(dirname) term, action is what happens. b d action - - ------ 0 0 skip 0 1 do 1 0 do 1 1 do Since it can't be simplified, both terms are necessary. - Bruce From bsass@freenet.edmonton.ab.ca Fri Feb 16 08:51:13 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 16 Feb 2001 01:51:13 -0700 (MST) Subject: [Tutor] Errr...Capitalizing Words In-Reply-To: Message-ID: > What I want to do with Python is take the first letter of each sentance and > capitalize it. By looking into the string library I've found the > string.capitalize() function. This only seems to work if you know the word > you're trying to use. Then string.capwords() will capitalize each word > instead of just the first one. > > Can anyone point me in the right direction for this? string.capitalize(a_sentence) works, once you split the text into sentences. - Bruce From bxuef@freemail.sx.cn Fri Feb 16 08:57:01 2001 From: bxuef@freemail.sx.cn (bxuef@freemail.sx.cn) Date: Fri, 16 Feb 2001 16:57:01 +0800 (CST) Subject: [Tutor] need help Message-ID: Hi, everyone, Please help me to make a webpage username and password authentication program. I started learning Python mainly for this function but right now I still can not do the job. I typed >s = raw_input("please enter your password: ") >if raw_input=="password" print "authenticated" #go to another page. I described this in human language, could help me right a simple example for me? This is not my homework and I am a newbie down-to-earth, so please kindly help me. thanks. ----------------------------------------------------------- »¶Ó­Ê¹ÓÃɽÎ÷µçÐÅÃâ·Ñµç×ÓÓʼþϵͳ ¡£ ÈçÓÐÎÊÌ⣬ÇëÓë webmaster@freemail.sx.cn ÁªÏµ¡£ ллÄúµÄʹÓã¡ From Lindsay.Davies@moonshine.co.uk Fri Feb 16 09:05:42 2001 From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies) Date: Fri, 16 Feb 2001 09:05:42 +0000 Subject: [Tutor] Errr...Capitalizing Words In-Reply-To: References: Message-ID: --============_-1229808104==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Well, here's a quick line that will do it for you... import string,re s = '''this is some sample text. its all in lower case. there are no capitals in this block of text. you get the idea, and now i'm just typing to make a lot of text.''' s = re.sub("(\.\s*|^\s*)(\w)", (lambda x: x.group(1) +\ string.upper(x.group(2))), s) This matches appropriate characters with a regular expression, and then capitalizes them. Best wishes, Lindsay On 15/2/01, Britt Green wrote about '[Tutor] Errr...Capitalizing Words': >Hello, > >I'm kind of stuck on something seemingly trivial, and I'm hoping >someone can help me out. Say I have a block of text, all in lower >case: > >this is some sample text. its all in lower case. there are no >capitals in this block of text. you get the idea, and now i'm just >typing to make a lot of text. > >What I want to do with Python is take the first letter of each >sentance and capitalize it. By looking into the string library I've >found the string.capitalize() function. This only seems to work if >you know the word you're trying to use. Then string.capwords() will >capitalize each word instead of just the first one. > >Can anyone point me in the right direction for 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 > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor --============_-1229808104==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] Errr...Capitalizing Words
Well, here's a quick line that will do it for you...

import string,re
s = '''this is some sample text. its all in lower case. there are no capitals in this block of text. you get the idea, and now i'm just typing to make a lot of text.'''

s = re.sub("(\.\s*|^\s*)(\w)", (lambda x: x.group(1) +\
    string.upper(x.group(2))), s)

This matches appropriate characters with a regular expression, and then capitalizes them.

Best wishes,

Lindsay


On 15/2/01, Britt Green wrote about '[Tutor] Errr...Capitalizing Words':
Hello,

I'm kind of stuck on something seemingly trivial, and I'm hoping someone can help me out. Say I have a block of text, all in lower case:

this is some sample text. its all in lower case. there are no capitals in this block of text. you get the idea, and now i'm just typing to make a lot of text.

What I want to do with Python is take the first letter of each sentance and capitalize it. By looking into the string library I've found the string.capitalize() function. This only seems to work if you know the word you're trying to use. Then string.capwords() will capitalize each word instead of just the first one.

Can anyone point me in the right direction for 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


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

--============_-1229808104==_ma============-- From NHYTRO@compuserve.com Fri Feb 16 09:22:37 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Fri, 16 Feb 2001 04:22:37 -0500 Subject: [Tutor] Errr...Capitalizing Words Message-ID: <200102160422_MC2-C5D1-B20E@compuserve.com> Hi Britt! In this case I would store the text in a variable then loop a function that contains a "Regular expression" over it.. The exprssion sorts out th= e first words in a sentences and capitilizes it. Hope that helps somehow Sharriff Message text written by INTERNET:tutor@python.org >Message: 13 From: "Britt Green" To: tutor@python.org Date: Thu, 15 Feb 2001 20:38:58 -0800 Subject: [Tutor] Errr...Capitalizing Words Hello, I'm kind of stuck on something seemingly trivial, and I'm hoping someone can = help me out. Say I have a block of text, all in lower case: this is some sample text. its all in lower case. there are no capitals in= = this block of text. you get the idea, and now i'm just typing to make a l= ot of text. What I want to do with Python is take the first letter of each sentance a= nd capitalize it. By looking into the string library I've found the = string.capitalize() function. This only seems to work if you know the wor= d = you're trying to use. Then string.capwords() will capitalize each word = instead of just the first one. Can anyone point me in the right direction for this? Thanks, Britt< From ibraheem@micromuse.com Fri Feb 16 09:31:33 2001 From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed) Date: Fri, 16 Feb 2001 09:31:33 +0000 Subject: [Tutor] need help In-Reply-To: ; from bxuef@freemail.sx.cn on Fri, Feb 16, 2001 at 04:57:01PM +0800 References: Message-ID: <20010216093133.A7216@micromuse.com> Hi, On Fri, Feb 16, 2001 at 04:57:01PM +0800, bxuef@freemail.sx.cn wrote: > Hi, everyone, > Please help me to make a webpage username and password authentication p= rogram. > I started learning Python mainly for this function but right now I stil= l can not do the job. > I typed=20 > >s =3D raw_input("please enter your password: ") > >if raw_input=3D=3D"password" > print "authenticated" > #go to another page. >=20 I think what you meant to write is something like this: >>>def test(): ... s =3D raw_input("please enter your password: ") ... if s =3D=3D "password": ... print "authenticated" ... else: ... print "authentication failure" >>> test() please enter your password: password authenticated >>> test() please enter your password: boo authentication failure >>> basically I think you meant to compare "s" and not "raw_input". kindest regards, --ibs. =09 =09 > I described this in human language, could help me right a simple exampl= e for me? > This is not my homework and I am a newbie down-to-earth, so please kind= ly help me. > thanks. >=20 >=20 > ----------------------------------------------------------- > =BB=B6=D3=AD=CA=B9=D3=C3=C9=BD=CE=F7=B5=E7=D0=C5=C3=E2=B7=D1=B5=E7=D7=D3= =D3=CA=BC=FE=CF=B5=CD=B3 =A1=A3 > =C8=E7=D3=D0=CE=CA=CC=E2=A3=AC=C7=EB=D3=EB webmaster@freemail.sx.cn =C1=AA=CF=B5=A1=A3 > =D0=BB=D0=BB=C4=FA=B5=C4=CA=B9=D3=C3=A3=A1 >=20 >=20 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor >=20 --=20 -------------------------------------------------------------------------= ------- -- Ibraheem Umaru-Mohammed -- -- Email:ium@micromuse.com -- -- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA = -- -- http://www.micromuse.com -- -------------------------------------------------------------------------= ------- From jcm@bigskytel.com Fri Feb 16 09:40:37 2001 From: jcm@bigskytel.com (David Porter) Date: Fri, 16 Feb 2001 02:40:37 -0700 Subject: [Tutor] xmlrpclib docs/examples In-Reply-To: <3A8CCB7D.4020801@brogdon.net>; from darrell@brogdon.net on Fri, Feb 16, 2001 at 01:41:01AM -0500 References: <3A8CCB7D.4020801@brogdon.net> Message-ID: <20010216024037.A20435@bigskytel.com> * Darrell Brogdon : > Does anyone know where I can find *good* (see: any) documentation on > xmlrpclib as well as some examples of how to use it? <..> Here are some to get you started: XML-RPC in Python: http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html XML-RPC: It Works Both Ways: http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html XML-RPC HOWTO: http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html I should read these too... David From amoreira@mercury.ubi.pt Fri Feb 16 10:19:56 2001 From: amoreira@mercury.ubi.pt (Jose Amoreira) Date: Fri, 16 Feb 2001 10:19:56 +0000 Subject: [Tutor] off-topic? (dos box) Message-ID: <3A8CFECB.A0F47DF6@mercury.ubi.pt> I'm sorry if this is somewhat offtopic, but anyway... At home, I usually run idle, but sometimes I'd prefer to run the interpreter in a dos box. The problem is that I loose all the facilities provided by readline, like command recall and editing. At work, I use a linux pc, and install python from sources, with the readline option; but in windows I don't have the make utility, so I install precompiled binaries. Replacing windows with an operating system is not an option because the majority (my wife and kids) voted against it, go figure... So my question is: Is there any way of running the python interpreter in a command line shell, with readline (or something similar) in windows? If so, could you tell me how to do it, please? Many thanks, Ze amoreira@mercury.ubi.pt From dyoo@hkn.eecs.berkeley.edu Fri Feb 16 11:05:34 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 16 Feb 2001 03:05:34 -0800 (PST) Subject: [Tutor] Errr...Capitalizing Words In-Reply-To: Message-ID: On Fri, 16 Feb 2001, Lindsay Davies wrote: > s = re.sub("(\.\s*|^\s*)(\w)", (lambda x: x.group(1) +\ As a safety tip: it's safer to make the regular expression an explicit "raw" string, because it's only coincidence that '\s' doesn't match up as a special character: s = re.sub(r"(\.\s*| ... From randrews@planhouse.com Fri Feb 16 14:13:13 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 16 Feb 2001 08:13:13 -0600 Subject: [Tutor] Need Python Images References: <01021511445503.01167@shecom> <3A8CA249.27D0DAB6@irtc.net> Message-ID: <000f01c09822$9bc28360$9600a8c0@Planhouse5> It's a tempting idea, actually, since I'm working on some of my own. We'd just have to make sure people who submit images know how to make them *small-ish* for the web. Anything else Useless we should add to the site? ;-> Rob ----- Original Message ----- From: "Tesla Coil" > On 15 Feb 2001, Tim Johnson wrote: or if R.A. decides > to add a gallery for collecting Python propaganda images. ;) > From dsh8290@rit.edu Fri Feb 16 15:44:02 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 16 Feb 2001 10:44:02 -0500 Subject: [Tutor] question about glob.glob() implementation In-Reply-To: ; from bsass@freenet.edmonton.ab.ca on Fri, Feb 16, 2001 at 01:19:31AM -0700 References: <20010215142337.E11714@valinux.com> Message-ID: <20010216104402.F2913@harmony.cs.rit.edu> On Fri, Feb 16, 2001 at 01:19:31AM -0700, Bruce Sass wrote: | On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote: [snip] | | b d action | - - ------ | 0 0 skip | 0 1 do | 1 0 do | 1 1 do | | Since it can't be simplified, both terms are necessary. | Couldn't it be reduced to if (not b) and (not d) : skip else : do or if b or d : do else : skip ? I don't know if that would make any improvement, but ... -D From dsh8290@rit.edu Fri Feb 16 15:51:04 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 16 Feb 2001 10:51:04 -0500 Subject: [Tutor] off-topic? (dos box) In-Reply-To: <3A8CFECB.A0F47DF6@mercury.ubi.pt>; from amoreira@mercury.ubi.pt on Fri, Feb 16, 2001 at 10:19:56AM +0000 References: <3A8CFECB.A0F47DF6@mercury.ubi.pt> Message-ID: <20010216105104.G2913@harmony.cs.rit.edu> On Fri, Feb 16, 2001 at 10:19:56AM +0000, Jose Amoreira wrote: | I'm sorry if this is somewhat offtopic, but anyway... | At home, I usually run idle, but sometimes I'd prefer to run the | interpreter in a dos box. The problem is that I loose all the facilities | provided by readline, like command recall and editing. At work, I use a | linux pc, and install python from sources, with the readline option; but | in windows I don't have the make utility, so I install precompiled | binaries. Replacing windows with an operating system is not an option | because the majority (my wife and kids) voted against it, go figure... | So my question is: | Is there any way of running the python interpreter in a command line | shell, with readline (or something similar) in windows? If so, could you | tell me how to do it, please? | The Python 2.0 binaries I installed on this Win2k machine have command history and editing (no ^U though) if run from a DOS box. If I run it from bash it doens't =p. Jython doesn't (because Java doesn't have readline =p). You could probably build from source like it was a unix machine after installing cygwin. You'll probably want cygwin anyways since you are familiar with Linux. http://sources.redhat.com HTH, -D From darrell@brogdon.net Fri Feb 16 16:09:38 2001 From: darrell@brogdon.net (Darrell Brogdon) Date: Fri, 16 Feb 2001 11:09:38 -0500 Subject: [Tutor] xmlrpclib docs/examples References: <3A8CCB7D.4020801@brogdon.net> <20010216024037.A20435@bigskytel.com> Message-ID: <3A8D50C2.1060002@brogdon.net> Thanks for the links David. The third is new to me so I will definately have a look. I Found "XML-RPC: It Works Both Ways" to be helpful but the problem I have is that when I try to add additional methods to the class and call them with my client I get errors back saying something to the effect of "...expected 1 argument, got 3" which is really confusing because the methods I've created have no arguments. David Porter wrote: > * Darrell Brogdon : > > >> Does anyone know where I can find *good* (see: any) documentation on >> xmlrpclib as well as some examples of how to use it? > > <..> > > Here are some to get you started: > > XML-RPC in Python: > http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html > > XML-RPC: It Works Both Ways: > http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html > > XML-RPC HOWTO: > http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html > > > I should read these too... > > David > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Darrell Brogdon http://darrell.brogdon.net From shaleh@valinux.com Fri Feb 16 16:15:39 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Fri, 16 Feb 2001 08:15:39 -0800 (PST) Subject: [Tutor] question about glob.glob() implementation In-Reply-To: Message-ID: On 16-Feb-2001 Bruce Sass wrote: > On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote: > >> glob.glob() has a section like: >> >> if not has_magic(basename): >> result = [] >> for dirname in list: >> if basename or os.path.isdir(dirname): >> name = os.path.join(dirname, basename) >> if os.path.exists(name): >> result.append(name) >> else: >> >> For every iteration of the for loop, basename is tested, yet its value never >> changes. Am I missing something here or is this wasteful like i think it >> is? > > Hmmm, it looks like a dual purpose routine. If basename is an empty > string, result ends up with the paths to the dirs in list that exist > (i.e., where can I look?). If basename has a value, result ends up > with the paths that end in basename (i.e., is it there?). > Could use a comment then. What it looks like it is doing is making sure it is not using an empty basename string. And since the basename value never changes the check seems superfluous. I still feel this could be better coded, although I am struggling to find the answer. Thanks for the help. From gibbs05@flash.net Fri Feb 16 16:58:58 2001 From: gibbs05@flash.net (Harry Kattz) Date: Fri, 16 Feb 2001 10:58:58 -0600 Subject: [Tutor] xmlrpclib docs/examples References: <3A8CCB7D.4020801@brogdon.net> <20010216024037.A20435@bigskytel.com> <3A8D50C2.1060002@brogdon.net> Message-ID: <017d01c09839$dde05bc0$e9ef3040@gibbs05> Greetings Darrell & All, Your call method is probably passing two additional arguments: method & params. At least that's what it's supposed to do. :-) Try changing the method definitions you created to something like the following: def YourMethod(self, method, anyparams): # your code See what happens from there... Good luck, Sam > Thanks for the links David. The third is new to me so I will definately > have a look. I Found "XML-RPC: It Works Both Ways" to be helpful but > the problem I have is that when I try to add additional methods to the > class and call them with my client I get errors back saying something to > the effect of "...expected 1 argument, got 3" which is really confusing > because the methods I've created have no arguments. > > David Porter wrote: > > > * Darrell Brogdon : > > > > > >> Does anyone know where I can find *good* (see: any) documentation on > >> xmlrpclib as well as some examples of how to use it? > > > > <..> > > > > Here are some to get you started: > > > > XML-RPC in Python: > > http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html > > > > XML-RPC: It Works Both Ways: > > http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html > > > > XML-RPC HOWTO: > > http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html > > > > > > I should read these too... > > > > David > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > -- > Darrell Brogdon > http://darrell.brogdon.net From mr804@users.757.org Fri Feb 16 18:17:32 2001 From: mr804@users.757.org (Mr 804) Date: Fri, 16 Feb 2001 13:17:32 -0500 (EST) Subject: [Tutor] reading stdin? In-Reply-To: Message-ID: how do I read stdin? From dsh8290@rit.edu Fri Feb 16 18:30:00 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 16 Feb 2001 13:30:00 -0500 Subject: [Tutor] reading stdin? In-Reply-To: ; from mr804@users.757.org on Fri, Feb 16, 2001 at 01:17:32PM -0500 References: Message-ID: <20010216133000.A3862@harmony.cs.rit.edu> On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote: | | how do I read stdin? | >>> data = raw_input( "Please give me some data: " ) Please give me some data: Hello World >>> type( data ) >>> print data Hello World >>> raw_input is good if you want random stuff or text stuff, if you want other stuff, input can be helpful >>> data = input( "Enter some data: " ) Enter some data: 2 >>> type( data ) >>> print data 2 >>> However, be careful how you use input() : >>> data = input( "Enter some data: " ) Enter some data: foo Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: There is no variable named 'foo' >>> >>> i = 2 >>> data = input( "Enter some data: " ) Enter some data: lambda x : x + i >>> type( data ) >>> print data at 007A8574> >>> print data( 3 ) 5 >>> input won't always do what you want, if the user inputs bad stuff. You can use raw_input, then convert the string how you want to. Ex: >>> try : ... data = int( raw_input( "Enter a number: " ) ) ... except ValueError , err : ... print "You didn't enter a valid number" ... Enter a number: 3 >>> print data 3 >>> >>> try : ... data = int( raw_input( "Enter a number: " ) ) ... except ValueError , err : ... print "You didn't enter a valid number" ... Enter a number: asdf You didn't enter a valid number >>> If you have more questions, just ask. HTH, -D From kalle@gnupung.net Fri Feb 16 19:52:12 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 16 Feb 2001 20:52:12 +0100 Subject: [Tutor] reading stdin? In-Reply-To: <20010216133000.A3862@harmony.cs.rit.edu>; from dsh8290@rit.edu on Fri, Feb 16, 2001 at 01:30:00PM -0500 References: <20010216133000.A3862@harmony.cs.rit.edu> Message-ID: <20010216205212.A926@apone.network.loc> --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez D-Man: > On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote: > |=20 > | how do I read stdin? > |=20 [snip great introduction to input/raw_input] If you want to read from standard input in a more low-level way, perhaps better suited for redirected input and that kind of stuff, use sys.stdin. import sys # get input s =3D sys.stdin.read() # do stuff sys.{stdin|stdout|stderr} are ordinary file objects. This makes it easy to use standard input/output as defaults, e.g. if no input/output files are specified on the command line: # crude example import sys if len(sys.argv) =3D=3D 1: outfile =3D sys.stdout infile =3D sys.stdin elif len(sys.argv) =3D=3D 2: outfile =3D open(sys.argv[1]) infile =3D sys.stdin else: outfile =3D open(sys.argv[1]) infile =3D open(sys.argv[2]) 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 --1yeeQ81UyVL57Vl7 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 iD8DBQE6jYTsdNeA1787sd0RAsbmAKCPalN1+ULLJGql/BIT1e5R8tY7fwCgqZlO /U7UlVZLhKK+CmI+WDyx6Gg= =GPzc -----END PGP SIGNATURE----- --1yeeQ81UyVL57Vl7-- From bsass@freenet.edmonton.ab.ca Fri Feb 16 20:47:58 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 16 Feb 2001 13:47:58 -0700 (MST) Subject: [Tutor] question about glob.glob() implementation In-Reply-To: <20010216104402.F2913@harmony.cs.rit.edu> Message-ID: On Fri, 16 Feb 2001, D-Man wrote: > On Fri, Feb 16, 2001 at 01:19:31AM -0700, Bruce Sass wrote: > | On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote: > [snip] > > | > | b d action > | - - ------ > | 0 0 skip > | 0 1 do > | 1 0 do > | 1 1 do > | > | Since it can't be simplified, both terms are necessary. > | > > Couldn't it be reduced to > > if (not b) and (not d) : > skip > else : > do Ya, but it is not a reduction or simplification. You could rewrite as... if not ((not b) and (not d)): do else: skip simply by reversing the sense of the test; applying a couple of the "rules of replacement" (I'll use Boolean algebra syntax, 'cause it's shorter)[1]... (b'*d')' ---------> b''+d'' -------> b+d DeMorgan Double Negation So, it is the same logically, but requires 4 operators instead of 1. > or > > if b or d : > do > else : > skip This is what is there already; "else: skip" == "", right. - Bruce [1] Boolean Algebra words others --------------- ----- ------ + or v, | * and & ' not ~ A couple of replacement rules, expressed in yet another logic system (just to confuse you ;)... DeMorgan's Theorem: ~(P&Q)::~Pv~Q Double Negation: P::~~P From dsh8290@rit.edu Fri Feb 16 20:57:45 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 16 Feb 2001 15:57:45 -0500 Subject: [Tutor] question about glob.glob() implementation In-Reply-To: ; from bsass@freenet.edmonton.ab.ca on Fri, Feb 16, 2001 at 01:47:58PM -0700 References: <20010216104402.F2913@harmony.cs.rit.edu> Message-ID: <20010216155744.A4932@harmony.cs.rit.edu> On Fri, Feb 16, 2001 at 01:47:58PM -0700, Bruce Sass wrote: | On Fri, 16 Feb 2001, D-Man wrote: [snip] | > Couldn't it be reduced to | > [snip] | Ya, but it is not a reduction or simplification. [snip] | > if b or d : | > do | > else : | > skip | | This is what is there already; "else: skip" == "", right. I just took another look and it is what is there already. I guess I didn't look closely enough at the original. -D From abreu@penguinpowered.com Sat Feb 17 09:39:33 2001 From: abreu@penguinpowered.com (Jose Alberto Abreu) Date: Sat, 17 Feb 2001 03:39:33 -0600 Subject: [Tutor] anybody tried PMZ for cgi? Message-ID: <3A8E46D5.1C2F8F98@penguinpowered.com> Has anybody tried Poor Man's Zope? I stumbled upon it on sourceforge and would like to try it, anybody has any comments about it? From m_r_quick@yahoo.co.uk Sat Feb 17 11:47:04 2001 From: m_r_quick@yahoo.co.uk (Martyn Quick) Date: Sat, 17 Feb 2001 11:47:04 +0000 Subject: [Tutor] Turning some Tkinter stuff into classes Message-ID: <3A8E64B8.E1183007@yahoo.co.uk> I have the following code which *seems* to work ok: -------------------------------- from Tkinter import * class Popup: def __init__(self,master): self.win = Toplevel(master) def popup(): newwin = Popup(root) class PopupButton: def __init(self,master): self.button = Button(master,text="New!",command=popup) self.button.pack() root = Tk() button = PopupButton(root) root.mainloop() -------------------------------- The problem is that the definition of "popup" is stylistically horrible (I think - I'm still rather new to Object Oriented Programming) since it has to refer to the fixed object root, but I'm using it within the class PopupButton, so could theoretically create another object with no reference to root using this class. My attempt to create a better definition inside the class definition was as follows: --------------------------- from Tkinter import * class Popup: def __init__(self,master): self.win = Toplevel(master) class PopupButton: def __init__(self,master): self.button=Button(master,text="New!",command=self.popup(master)) self.button.pack() def popup(self,master): self.newwin = Popup(master) root = Tk() button = PopupButton(root) root.mainloop() ---------------------------------------- Of course, the above didn't work - I got the new popup window immediately and the button didn't do anything. Other attempts to do a similar thing (deleting the master reference in the various bits of the popup command) produced syntax errors. Any suggestions to correct what it is wrong in my second attempt? Thanks, Martyn _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From W.W.vandenBroek Sat Feb 17 12:58:03 2001 From: W.W.vandenBroek (W.W.vandenBroek) Date: Sat, 17 Feb 2001 13:58:03 +0100 Subject: [Tutor] Re: hacking In-Reply-To: References: Message-ID: <01021713580303.02006@vdbroekw> > Message: 1 > Date: Thu, 15 Feb 2001 18:09:32 +0100 (MET) > To: > Cc: tutor@python.org > Cc: tutor@python.org > Subject: Re: [Tutor] i want to learn to hack > From: =?ISO-8859-1?Q?J=F6rg_W=F6lke?= > > > how do i hack? > > > > -Ryan > > > > _______________________________________________ > > youre running windoze - right? > fire up a dos prompt and type format c: > hit return and get an os. ;-> > read the dox. > write progs. > -jö Or much better read the book: "The Cathedral & The Bazaar" by Eric S. Raymond. He will teach you how to "hack" Bye walter -- W.W. van den Broek e-mail: vandenbroek@psyd.azr.nl AZR-Dijkzigt fax: 010-4633217 afdeling psychiatrie tel: 010-4639222 Postbus 2040 e-mail vdbroekw@wxs.nl (thuis) 3000 CA Rotterdam homepage: http://home.planet.nl/~vdbroekw From arcege@shore.net Sat Feb 17 13:05:06 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sat, 17 Feb 2001 08:05:06 -0500 (EST) Subject: [Tutor] Turning some Tkinter stuff into classes In-Reply-To: <3A8E64B8.E1183007@yahoo.co.uk> from "Martyn Quick" at Feb 17, 2001 11:47:04 AM Message-ID: <200102171305.IAA01125@northshore.shore.net> > > I have the following code which *seems* to work ok: > > -------------------------------- > from Tkinter import * > > class Popup: > def __init__(self,master): > self.win = Toplevel(master) > > def popup(): > newwin = Popup(root) > > class PopupButton: > def __init(self,master): > self.button = Button(master,text="New!",command=popup) > self.button.pack() > > root = Tk() > button = PopupButton(root) > > root.mainloop() > -------------------------------- > > The problem is that the definition of "popup" is stylistically horrible > (I think - I'm still rather new to Object Oriented Programming) since it > has to refer to the fixed object root, but I'm using it within the class > PopupButton, so could theoretically create another object with no > reference to root using this class. My attempt to create a better > definition inside the class definition was as follows: > > --------------------------- > from Tkinter import * > > class Popup: > def __init__(self,master): > self.win = Toplevel(master) > > class PopupButton: > def __init__(self,master): > self.button=Button(master,text="New!",command=self.popup(master)) > self.button.pack() > > def popup(self,master): > self.newwin = Popup(master) > > root = Tk() > button = PopupButton(root) > > root.mainloop() > ---------------------------------------- > > Of course, the above didn't work - I got the new popup window > immediately and the button didn't do anything. Other attempts to do a > similar thing (deleting the master reference in the various bits of the > popup command) produced syntax errors. > > Any suggestions to correct what it is wrong in my second attempt? Hi there, You are calling a function when the Button is created, not passing which function to call at a later point. class PopupButton: def __init__(self,master): # store the master widget for the popup self.master = master # pass the method self.button=Button(master,text="New!",command=self.popup) self.button.pack() # pass only the class instance, self def popup(self): # get master from the member stored in __init__ self.newwin = Popup(self.master) Good luck, -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Manager | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From lumbricus@gmx.net Sat Feb 17 16:20:07 2001 From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=) Date: Sat, 17 Feb 2001 17:20:07 +0100 (MET) Subject: [Tutor] reading stdin? References: <20010216133000.A3862@harmony.cs.rit.edu> Message-ID: <862.982426807@www27.gmx.net> > On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote: > | > | how do I read stdin? > | > > >>> data = raw_input( "Please give me some data: " ) > Please give me some data: Hello World > >>> type( data ) > > >>> print data > Hello World > >>> > > > raw_input is good if you want random stuff or text stuff, > if you want other stuff, input can be helpful > > >>> data = input( "Enter some data: " ) > Enter some data: 2 > >>> type( data ) > > >>> print data > 2 > >>> > > > However, be careful how you use input() : > > >>> data = input( "Enter some data: " ) > Enter some data: foo > Traceback (most recent call last): > File "", line 1, in ? > File "", line 0, in ? > NameError: There is no variable named 'foo' > >>> > > >>> i = 2 > >>> data = input( "Enter some data: " ) > Enter some data: lambda x : x + i > >>> type( data ) > > >>> print data > at 007A8574> > >>> print data( 3 ) > 5 > >>> > > > input won't always do what you want, if the user inputs bad stuff. > You can use raw_input, then convert the string how you want to. Ex: > > >>> try : > ... data = int( raw_input( "Enter a number: " ) ) > ... except ValueError , err : > ... print "You didn't enter a valid number" > ... excuse me if that's a silly question: why not just try: data = input("Enter number: ") except: "wrong" which would trap all errors? greets jö! > > > If you have more questions, just ask. > > HTH, > -D > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Sent through GMX FreeMail - http://www.gmx.net From dsh8290@rit.edu Sat Feb 17 16:37:10 2001 From: dsh8290@rit.edu (D-Man) Date: Sat, 17 Feb 2001 11:37:10 -0500 Subject: [Tutor] reading stdin? In-Reply-To: <862.982426807@www27.gmx.net>; from lumbricus@gmx.net on Sat, Feb 17, 2001 at 05:20:07PM +0100 References: <20010216133000.A3862@harmony.cs.rit.edu> <862.982426807@www27.gmx.net> Message-ID: <20010217113710.A8457@harmony.cs.rit.edu> On Sat, Feb 17, 2001 at 05:20:07PM +0100, J=F6rg W=F6lke wrote: [snip] | > >>> try : | > ... data =3D int( raw_input( "Enter a number: " ) ) | > ... except ValueError , err : | > ... print "You didn't enter a valid number" | > ... |=20 | excuse me if that's a silly question: | why not just It's a perfectly good question. | try: | data =3D input("Enter number: ") | except: | "wrong" |=20 | which would trap all errors? This is exactly why you don't want to use a universal except clause -- do you really want to catch KeyBoardError, OutOfMemoryError, SystemExit and ComputerExplodingError? Using a universal except will work if you never get one of these kind of errors, but if you do get one, the program won't behave as expected. It is generally good to be as explicit as you can in what exceptions you want to catch and handle. I didn't do it here, but in an earlier post (see archives) I used the exception to tell the user what exactly they entered that wasn't a valid number. By explicitly catching certain exceptions, you can use their data to improve the error handling. -D From DOUGS@oceanic.com Sat Feb 17 17:43:27 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sat, 17 Feb 2001 07:43:27 -1000 Subject: [Tutor] reading stdin? Message-ID: <8457258D741DD411BD3D0050DA62365907A624@huina.oceanic.com> [D-Man wrote:] > On Sat, Feb 17, 2001 at 05:20:07PM +0100, J=F6rg W=F6lke wrote: > [snip] > | > >>> try : > | > ... data =3D int( raw_input( "Enter a number: " ) ) > | > ... except ValueError , err : > | > ... print "You didn't enter a valid number" > | > ... > |=20 > | excuse me if that's a silly question: > | why not just >=20 > It's a perfectly good question. >=20 > | try: > | data =3D input("Enter number: ") > | except: > | "wrong" > |=20 > | which would trap all errors? >=20 > This is exactly why you don't want to use a universal except clause = -- > do you really want to catch KeyBoardError, OutOfMemoryError, > SystemExit and ComputerExplodingError? Using a universal except will > work if you never get one of these kind of errors, but if you do get > one, the program won't behave as expected. It is generally good to = be > as explicit as you can in what exceptions you want to catch and > handle. I didn't do it here, but in an earlier post (see archives) I > used the exception to tell the user what exactly they entered that > wasn't a valid number. By explicitly catching certain exceptions, = you > can use their data to improve the error handling. In addition, please note the difference between 'raw_input' and = 'input'. The use of 'input' is generally unsafe. Using 'raw_input' is almost = always what you want in this scenario of getting data from a user. -Doug- From dyoo@hkn.eecs.berkeley.edu Sun Feb 18 00:34:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 17 Feb 2001 16:34:33 -0800 (PST) Subject: [Tutor] reading stdin? In-Reply-To: <8457258D741DD411BD3D0050DA62365907A624@huina.oceanic.com> Message-ID: On Sat, 17 Feb 2001, Doug Stanfield wrote: > > | > ... data = int( raw_input( "Enter a number: " ) ) > > | why not just > > | data = input("Enter number: ") > In addition, please note the difference between 'raw_input' and > 'input'. The use of 'input' is generally unsafe. Using 'raw_input' is > almost always what you want in this scenario of getting data from a > user. Clarification on what it means to be unsafe: sometimes, when we write programs, we need to imagine a "worst case" scenario. (Not that our users are malevolant, but it's quite possible for them to make typing mistakes). For example, with the following program: ### try: myint = input("Enter a number: ") except: print "Error!" ### What happens when the user enters this at our prompt? : open('really-important-file-would-be-clobbered-muhahaha', 'w') This is evil, but it works. *grin* input() is really powerful... sometimes TOO powerful. input() will accept any Python expression, and this includes the file-opening functions. Hope this helps! From britt_green@hotmail.com Sun Feb 18 01:37:10 2001 From: britt_green@hotmail.com (Britt Green) Date: Sat, 17 Feb 2001 17:37:10 -0800 Subject: [Tutor] A Better Way to Write This? Message-ID: Hello all, I have a tiny program that asks a user to enter a color choice. There are four valid choices for the user to enter. I have a function that checks to see if the user entered one of the valid choices. A snippet from it looks like this: if choice == ("black") or choice == ("white") or choice == ("green") or choice == ("blue"): return 1 else: return 0 While this works, it seems ugly. What would happen, for example, if there were ten or twenty correct colors? So I'm wondering if there is a better way to write 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 gko@gko.net Sun Feb 18 01:57:51 2001 From: gko@gko.net (Georges Ko) Date: 18 Feb 2001 09:57:51 +0800 Subject: [Tutor] A Better Way to Write This? In-Reply-To: References: Message-ID: "Britt Green" wrote: > if choice == ("black") or choice == ("white") or choice == > ("green") or choice == ("blue"): > return 1 > else: > return 0 > > While this works, it seems ugly. What would happen, for example, if > there were ten or twenty correct colors? > > So I'm wondering if there is a better way to write this? Use: return choice in ['black', 'white', 'green', 'blue'] instead. Because this list may be used somewhere else, it would be better to put it in a variable so that when you add a color, you won't have to mess with parts of the code that use it. acceptable_colors = ['black', 'white', 'green', 'blue'] . . . return choice in acceptable_colors -- Georges Ko (Taipei, Taiwan) 2001-02-18 gko@gko.net / ICQ: 8719684 From tim.one@home.com Sun Feb 18 03:18:51 2001 From: tim.one@home.com (Tim Peters) Date: Sat, 17 Feb 2001 22:18:51 -0500 Subject: [Tutor] A Better Way to Write This? In-Reply-To: Message-ID: [Britt Green] > I have a tiny program that asks a user to enter a color choice. There are > four valid choices for the user to enter. I have a function that > checks to see if the user entered one of the valid choices. A snippet > from it looks like this: > > if choice == ("black") or choice == ("white") or \ > choice == ("green") or choice == ("blue"): > return 1 > else: > return 0 > > While this works, it seems ugly. Here are two easy steps: 1. The parentheses aren't needed, so: if choice == "black" or choice == "white" or \ choice == "green" or choice == "blue": return 1 else: return 0 2. What value does choice == "black" yield? Well, 1 if it's black, 0 if it's not. Same for the rest of them. So this does the same thing: return choice == "black" or choice == "white" or \ choice == "green" or choice == "blue" That is, the if/else isn't needed either. > What would happen, for example, if there were ten or twenty > correct colors? It would get *very* ugly . And what if there were hundreds? Thousands? > So I'm wondering if there is a better way to write this? There are three ways you're more likely to see this written, two using lists or tuples, and one using dicts. 1. _VALID_COLORS = ["black", "white", "green", "blue"] def is_valid_color(choice): for valid in _VALID_COLORS: if choice == valid: return 1 return 0 This scales to any number of colors, of course. If there are many of them, it's helpful to sort the list of colors, most popular color first. That way you'll usually get out of the loop more quickly. 2. Actually the same as #1: def is_valid_color(choice): return choice in _VALID_COLORS People who come to Python from languages like C are likely to use #1, not realizing that Python has the higher-level "in" operator that searches over a list (or tuple, or any other sequence) for them. #2 is easy to recommend, but you can do a lot better in *speed* if there are thousands, or hundreds of thousands(! it can happen) of "good" choices. Like so: 3. _VALID_COLOR_DICT = {} for choice in _VALID_COLORS: _VALID_COLOR_DICT[choice] = 1 # value irrelevant def is_valid_color(choice): return _VALID_COLOR_DICT.has_key(choice) Unlike searching for something in a list, dict lookup goes very fast even if the number of good choices is huge. dicts are way cool. But they take a little more effort to set up. Just for fun, here's a reasonably quick method you'll almost never see (note that this uses string methods, which were new in Python 2.0): 4. _VALID_COLORS = " black white green blue " def is_valid_color(choice): return _VALID_COLORS.find(" " + choice + " ") >= 0 So, lots of choices. If you want to learn only one, learn #3, because it remains quick and just as easy no matter how large the set of choices grows. From bxuef@freemail.sx.cn Sun Feb 18 13:54:50 2001 From: bxuef@freemail.sx.cn (bxuef@freemail.sx.cn) Date: Sun, 18 Feb 2001 21:54:50 +0800 (CST) Subject: [Tutor] not a good tutorial, in my view Message-ID: Hi, everyone, It appears the Python 2.0 tutorial are not written for beginners without programming background. The language is claimed to be a desktop program for everyone but the tutorial is already hard to read. I am currently learning Python through the tutorial but I think it just neglected the programming level of the general readship. There are several questions that I hope to seek answer from the veterans of Python programming: 1. I typed: >>>"doesn\t" # and it produced the following result: >>>'doesn\011' >>> 'yes\'he said' "yes'he said" >>>>>> "\"yes,\" he said" '"yes," he said' what is the use of this slash? 2. What is the use of 'strip' here? >>> string.strip('str') + 'ing' 'string' and why this does not work: >>> string.strip('str') 'ing' SyntaxError: invalid syntax It is explained in the tutorial, but I can not understand. 3. In the tutorial 3.1.3. Why there is the unicode part. what's the use of unicode in programming? I input this but why it did not produce the desired result? >>> u'Hello\\u0020World !' u'Hello\\u0020World !' The desired result should be >>>u'Hello World !' Under what conditions will the Interpreter shows the second prompt(...)? In the turtorial, it reads "for continuation lines it prompts with the second prompt...". I am a little frustrated by the tutorial, can anyone show me some links to the easier tutorial (for instance, Alan's)? Or hopefuly there will be a beginner's version of the tutorial. Thank you very much! Best wishes. -------bxuef ----------------------------------------------------------- »¶Ó­Ê¹ÓÃɽÎ÷µçÐÅÃâ·Ñµç×ÓÓʼþϵͳ ¡£ ÈçÓÐÎÊÌ⣬ÇëÓë webmaster@freemail.sx.cn ÁªÏµ¡£ ллÄúµÄʹÓã¡ From scarblac@pino.selwerd.nl Sun Feb 18 14:30:18 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 18 Feb 2001 15:30:18 +0100 Subject: [Tutor] not a good tutorial, in my view In-Reply-To: ; from bxuef@freemail.sx.cn on Sun, Feb 18, 2001 at 09:54:50PM +0800 References: Message-ID: <20010218153018.A4193@pino.selwerd.nl> On Sun, Feb 18, 2001 at 09:54:50PM +0800, bxuef@freemail.sx.cn wrote: > It appears the Python 2.0 tutorial are not written for beginners without > programming background. I agree. Try Alan Gauld's webpage instead, at http://www.crosswinds.net/~agauld (there are a few others, on www.python.org go to Documentation, then look for "Introductions", and "Introductions for non-programmers"). > 1. I typed: If you write down a string, the \ is used to "escape" things. For instance, if a string is enclosed between " ", you need a way to have a " inside the string - you write it \". Similarly, there are some special characters that you can't simply write down. A newline is spelled as \n, a tab is spelled \t. \011 is the same thing as \t, in another representation. > >>>"doesn\t" > # and it produced the following result: > >>>'doesn\011' See above. The \t you typed shows as \011 in the interpreter's representation. The string is "doesn" followed by a tab character. > >>> 'yes\'he said' > "yes'he said" > >>>>>> "\"yes,\" he said" > '"yes," he said' > what is the use of this slash? If you don't use the slash, Python thinks the ' means the end of the string. Same for " in the second example. > 2. What is the use of 'strip' here? > >>> string.strip('str') + 'ing' > 'string' string.strip removes whitespace from the begin and end of a string. Try this alternative: >>> string.strip(" str \n")+'ing' (the \n is a newline, it also counts as whitespace) > and why this does not work: > >>> string.strip('str') 'ing' > SyntaxError: invalid syntax > It is explained in the tutorial, but I can not understand. You have first a call to a function (string.strip) and then a string ('ing'). Python doesn't know what to do with that, this is not what Python looks like. If you want to add them together, you can do so with +. > 3. In the tutorial 3.1.3. Why there is the unicode part. > what's the use of unicode in programming? Standard ASCII has only 127 different characters. That is not enough to represent text in all the world's languages, by far. Unicode is newer, and it has over 60,000 different codes. But moving programs like Python to Unicode is a slow and complicated process, and I propose you ignore it totally for now. > I input this but why it did not produce the desired result? > >>> u'Hello\\u0020World !' > u'Hello\\u0020World !' One backslash too many. \\ inside a string means simply \. > The desired result should be > >>>u'Hello World !' > Under what conditions will the Interpreter shows the second prompt(...)? > In the turtorial, it reads "for continuation lines it prompts with the > second prompt...". If the command you started to enter isn't done yet. For instance, when you still have a ( open without an ), or when you're writing a block of code, for instance after an if: statement: >>> if 2 > 1: ... print "whee" ... It writes ... because you can still enter lines that belong to the 'if' statement. > I am a little frustrated by the tutorial, can anyone show me some links to > the easier tutorial (for instance, Alan's)? Or hopefuly there will be a > beginner's version of the tutorial. See above. -- Remco Gerlich From tim@johnsons-web.com Sun Feb 18 18:09:45 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 18 Feb 2001 09:09:45 -0900 Subject: [Tutor] not a good tutorial, in my view References: <20010218153018.A4193@pino.selwerd.nl> Message-ID: <01021809113504.02173@shecom> Hello On Sun, 18 Feb 2001, you wrote: > I agree. Try Alan Gauld's webpage instead, at > http://www.crosswinds.net/~agauld (there are a few others, on www.python.org > go to Documentation, then look for "Introductions", and "Introductions for > non-programmers"). I'll add a ditto to that. I just got his good bood also, and it is great. I'm modeling a class on Python programming around it -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From rha2077@netzero.net Sun Feb 18 20:33:27 2001 From: rha2077@netzero.net (Ron) Date: Sun, 18 Feb 2001 15:33:27 -0500 Subject: [Tutor] not a good tutorail Message-ID: <000701c099ea$0e5c4960$80c545d1@computer> This is a multi-part message in MIME format. ------=_NextPart_000_0004_01C099C0.23B970A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm working my way through HOW TO THINK LIKE A COMPUTER SCIENTIST and I = think it's pretty good. I haven't found one tutorial that I'm completely = happy with, but then I'm a newbie and have a lot to learn. Oh, here's the link if you want to take a look. http://www.ibiblio.org/obp/thinkCSpy/ ------=_NextPart_000_0004_01C099C0.23B970A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I'm working my way through HOW TO THINK LIKE A = COMPUTER=20 SCIENTIST and I think it's pretty good. I haven't found one tutorial = that I'm=20 completely happy with, but then I'm a newbie and have a lot to=20 learn.
 
Oh, here's the link if you want to take a = look.
 
http://www.ibiblio.org/obp= /thinkCSpy/
------=_NextPart_000_0004_01C099C0.23B970A0-- Shop online without a credit card http://www.rocketcash.com RocketCash, a NetZero subsidiary From tim@johnsons-web.com Sun Feb 18 23:18:34 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 18 Feb 2001 14:18:34 -0900 Subject: [Tutor] Python Access to Computer speaker References: <000701c099ea$0e5c4960$80c545d1@computer> Message-ID: <01021814195505.02173@shecom> Hi : Does Python have a function to access for the computer speaker for frequency and duration? .....like the the "C" sound() function. TIA -- Tim Johnson ----------- "Of all manifestations of power, restraint impresses the most." -Thucydides From kalle@gnupung.net Mon Feb 19 00:13:10 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 19 Feb 2001 01:13:10 +0100 Subject: [Tutor] Python Access to Computer speaker In-Reply-To: <01021814195505.02173@shecom>; from tim@johnsons-web.com on Sun, Feb 18, 2001 at 02:18:34PM -0900 References: <000701c099ea$0e5c4960$80c545d1@computer> <01021814195505.02173@shecom> Message-ID: <20010219011310.A2379@apone.network.loc> --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Tim Johnson: > Hi : > Does Python have a function to access for the computer > speaker for frequency and duration? No, not generally. On Windows NT, there is winsound.Beep(), but there is no support on other platforms. On GNU/Linux, you could use the 'beep' program by Johnathan Nightingale: http://www.johnath.com/beep/. You'll have to use it through os.system, or wrap it in a python module. > .....like the the "C" sound() function. What library? Platform? Just curious. Peace, Kalle (from Sweden) --=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 --PEIAKu/WMn1b1Hv9 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 iD8DBQE6kGUWdNeA1787sd0RAkSiAJ9BYHLigWErMjQ+ktr2jQ71JbnCrACgiEDk UNocLZDVLv9o/8b4u0bmv48= =PDqM -----END PGP SIGNATURE----- --PEIAKu/WMn1b1Hv9-- From dyoo@hkn.eecs.berkeley.edu Mon Feb 19 00:19:08 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 18 Feb 2001 16:19:08 -0800 (PST) Subject: [Tutor] not a good tutorial, in my view In-Reply-To: Message-ID: On Sun, 18 Feb 2001 bxuef@freemail.sx.cn wrote: > It appears the Python 2.0 tutorial are not written for beginners > without programming background. In one sense, the tutorial's is a "good" one because it is specifically tailored for people who have previous programming experience. For those who haven't programmed before though, it stinks. *grin* Take a look at the Introductions section of python.org: it has tutorials that are targeted toward newcomers: http://python.org/doc/Intros.html > 1. I typed: > > >>>"doesn\t" > # and it produced the following result: > >>>'doesn\011' > >>> 'yes\'he said' > "yes'he said" > >>>>>> "\"yes,\" he said" > '"yes," he said' > what is the use of this slash? Let's see what happens when we don't put the slash. ### >>> ""yes, " he said" File "", line 1 ""yes, " he said" ^ SyntaxError: invalid syntax ### Strings in Python are surrounded by pairs of quotation marks. For example: "hello world" "how to solve it" "harry potter" The tricky part is when we want to put quotation marks within a string. When we tried: ""yes", he said" we wanted Python to understand that we wanted quotes around "yes". However, here's that Python sees, piece by piece: " : Ok, we have an opening quote, so I'm reading a string. " : There's the closing quote. We must mean the empty string. yes : What does yes mean? It's outside quotes, and I don't know what to do! And that's the problem; how can we put quotes within a string? The solution that Python chooses is to make a character that's special; whenever Python sees it during string reading, it'll escape out of it's regular set of rules. For example, when we feed it: "\"" here's what Python's thinking: " : ok, opening quote mark \ : Oh! This is an escape character. That means I should do something special to the next thing I see. " : Ah, ok, so I won't close off the string yet. I'll just add the literal quote character to our string. Let's go back to our normal set of rules. " : Closing quote and we end up with the string that contains one quotation mark. > 2. What is the use of 'strip' here? > >>> string.strip('str') + 'ing' > 'string' > and why this does not work: > >>> string.strip('str') 'ing' > SyntaxError: invalid syntax > It is explained in the tutorial, but I can not understand. Ah. Really subtle point; you don't need to worry about this for a while. This is what they mean: Whenever we put two strings together like this: ### >>> "this is" "two literal strings" 'this istwo literal strings' ### Python can see that both are obviously strings, so it'll put them together automatically. However, when we do: ### >>> string.strip('str') 'ing' File "", line 1 string.strip('str') 'ing' ^ SyntaxError: invalid syntax ### The idea is that Python has no clue if string.strip() will return a string or not, so it'll go bonkers again. What we need to do is convince Python that we really want it to put strings together: ### >>> string.strip('str') + 'ing' 'string' ### Adding a '+' in the middle of those two tells Python to try adding the result of string.strip() with 'ing', in any way possible. > 3. In the tutorial 3.1.3. Why there is the unicode part. what's the > use of unicode in programming? Unicode's important for people who plan to write multilingual programs; that is, programs that need to deal with more than english text. Since the tutorials tailored to professional programmers, that's why it talks about this issue. To tell the truth, I don't know Unicode either. *grin* Good luck to you! From dyoo@hkn.eecs.berkeley.edu Mon Feb 19 00:25:12 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 18 Feb 2001 16:25:12 -0800 (PST) Subject: [Tutor] Python Access to Computer speaker In-Reply-To: <01021814195505.02173@shecom> Message-ID: On Sun, 18 Feb 2001, Tim Johnson wrote: > Does Python have a function to access for the computer > speaker for frequency and duration? > .....like the the "C" sound() function. I'll assume that you're working on a Windows system for the moment. There's a module called winsound that'll let you do this: http://www.python.org/doc/current/lib/module-winsound.html In it, there's a function called Beep(), and it does take in frequency and duration. However, I have to admit that I have no experience with it. Perhaps someone else on tutor's played around with it? Good luck! From kalle@gnupung.net Mon Feb 19 01:16:46 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 19 Feb 2001 02:16:46 +0100 Subject: [Tutor] Python Access to Computer speaker In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Sun, Feb 18, 2001 at 04:25:12PM -0800 References: <01021814195505.02173@shecom> Message-ID: <20010219021646.C2379@apone.network.loc> --dkEUBIird37B8yKS Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sez Danny Yoo: > On Sun, 18 Feb 2001, Tim Johnson wrote: >=20 > > Does Python have a function to access for the computer > > speaker for frequency and duration? > > .....like the the "C" sound() function. >=20 > I'll assume that you're working on a Windows system for the moment. =20 > There's a module called winsound that'll let you do this: >=20 > http://www.python.org/doc/current/lib/module-winsound.html >=20 > In it, there's a function called Beep(), and it does take in frequency and > duration. However, I have to admit that I have no experience with it. = =20 > Perhaps someone else on tutor's played around with it? I haven't used it myself, but from reading comp.lang.python I have learned that this doesn't work as advertised on Win95/98/ME systems. On those systems, it plays the windows bell sound, regardless of the parameters. 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 --dkEUBIird37B8yKS 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 iD8DBQE6kHP+dNeA1787sd0RAg/ZAKCn9WmLWNZmO/CmVZ7z5xiPEEC35wCghXXA LCq8wW7dlht3xnt1tia3XdA= =C1I6 -----END PGP SIGNATURE----- --dkEUBIird37B8yKS-- From tim.one@home.com Mon Feb 19 02:06:38 2001 From: tim.one@home.com (Tim Peters) Date: Sun, 18 Feb 2001 21:06:38 -0500 Subject: [Tutor] Python Access to Computer speaker In-Reply-To: Message-ID: [Tim Johnson] > Does Python have a function to access for the computer > speaker for frequency and duration? > .....like the the "C" sound() function. [Danny Yoo] > I'll assume that you're working on a Windows system for the moment. > There's a module called winsound that'll let you do this: > > http://www.python.org/doc/current/lib/module-winsound.html > > In it, there's a function called Beep(), and it does take in frequency > and duration. This is a case where you really need to use the development docs: http://python.sourceforge.net/devel-docs/lib/module-winsound.html They point out that-- alas --Beep()'s arguments are ignored except under Windows NT and 2000. Under 95 and 98, Windows doesn't supply anything "that works". Unsure about Windows ME. Note that standard C doesn't have a "sound" function -- that must be specific to some particular vendor-extended C you used. no-good-news-here!-ly y'rs - tim From sandy@mnic.net Mon Feb 19 06:49:58 2001 From: sandy@mnic.net (Sandy Oppegard) Date: Mon, 19 Feb 2001 00:49:58 -0600 Subject: [Tutor] sign me up! Message-ID: <000a01c09a40$30a862a0$0100007f@ic.mankato.mn.us> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C09A0D.E24B1E40 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable ------=_NextPart_000_0007_01C09A0D.E24B1E40 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
 
------=_NextPart_000_0007_01C09A0D.E24B1E40-- From tim.one@home.com Mon Feb 19 07:21:06 2001 From: tim.one@home.com (Tim Peters) Date: Mon, 19 Feb 2001 02:21:06 -0500 Subject: [Tutor] Python Access to Computer speaker In-Reply-To: Message-ID: [Tim (this Tim -- that's me) bemoaned] > This is a case where you really need to use the development docs: > > http://python.sourceforge.net/devel-docs/lib/module-winsound.html > > They point out that-- alas --Beep()'s arguments are ignored except under > Windows NT and 2000. Under 95 and 98, Windows doesn't supply > anything "that works". Unsure about Windows ME. > > ... > > no-good-news-here!-ly y'rs - tim OK, I confess I got really irritated with this. What good is having a computer if you can't play stupid one-voice tunes on it laboriously poking each note in by hand ? So I added Win9X support for winsound.Beep(), and that will be released in Python 2.1. Here's the heart of the Win9X code. This is educational, because it demonstrates why you want to stick with coding in Python just as long as you can : static PyObject * sound_beep(PyObject *self, PyObject *args) { int freq; int dur; if (!PyArg_ParseTuple(args, "ii:Beep", &freq, &dur)) return NULL; if (freq < 37 || freq > 32767) { PyErr_SetString(PyExc_ValueError, "frequency must be in 37 thru 32767"); return NULL; } /* On NT and 2000, the SDK Beep() function does the whole job. * But while Beep() exists before NT, it ignores its arguments and * plays the system default sound. Sheesh ... * The Win9X code is mondo bizarre. I (Tim) pieced it together from * crap all over the web. The original IBM PC used some particular * pieces of hardware (Intel 8255 and 8254 chips) hardwired to * particular port addresses and running at particular clock speeds, * and the poor sound card folks have been forced to emulate that in * all particulars ever since. But NT and 2000 don't support port * manipulation, Don't know about WinME; guessing it's like 98. */ if (whichOS == WinNT2000) { BOOL ok; Py_BEGIN_ALLOW_THREADS ok = Beep(freq, dur); Py_END_ALLOW_THREADS if (!ok) { PyErr_SetString(PyExc_RuntimeError,"Failed to beep"); return NULL; } } else if (whichOS == Win9X) { int speaker_state; /* Force timer into oscillator mode via timer control port. */ _outp(0x43, 0xb6); /* Compute ratio of ancient hardcoded timer frequency to * frequency we want. Then feed that ratio (lowest byte * first) into timer data port. */ freq = 1193180 / freq; _outp(0x42, freq & 0xff); _outp(0x42, (freq >> 8) & 0xff); /* Get speaker control state. */ speaker_state = _inp(0x61); /* Turn the speaker on (bit 1) * and drive speaker from timer (bit 0). */ _outp(0x61, speaker_state | 0x3); /* Let it blast in peace for the duration. */ Py_BEGIN_ALLOW_THREADS Sleep(dur); Py_END_ALLOW_THREADS /* Restore speaker control to original state. */ _outp(0x61, speaker_state); } else { assert(!"winsound's whichOS has insane value"); } Py_INCREF(Py_None); return Py_None; } you-can-like-python-as-a-first-language-but-you-won't-truly-love- it-until-you've-suffered-with-everything-else-ly y'rs - tim From abreu@penguinpowered.com Mon Feb 19 16:39:11 2001 From: abreu@penguinpowered.com (Jose Alberto Abreu) Date: Mon, 19 Feb 2001 10:39:11 -0600 Subject: [Tutor] Has anyone tried PMZ Message-ID: <3A914C2F.85F95CEB@penguinpowered.com> I found the "Poor Man's Zope" proyect in sourceforge, and it looks like something I would like to try... http://pmz.sourceforge.net/ Looks easy to learn and powerful, but has anyone tried it yet? Any comments? Thanks in advance to the List Moms for their infinite wisdom... From alan.gauld@bt.com Mon Feb 19 17:43:37 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 19 Feb 2001 17:43:37 -0000 Subject: [Tutor] Python Access to Computer speaker Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5A9@mbtlipnt02.btlabs.bt.co.uk> > Does Python have a function to access for the computer > speaker for frequency and duration? Sound is a very platform specific thing. > .....like the the "C" sound() function. Not all C compilers have a sound() function. Python provides several sound modules for different platforms. I think theres a winsound module that might do and I think there's a set of sound APIs in Mark Hammond's winall wrapper of the MFC clsses. Alan G. From dhhoward@hotmail.com Mon Feb 19 20:10:37 2001 From: dhhoward@hotmail.com (Dan Howard) Date: Mon, 19 Feb 2001 15:10:37 -0500 Subject: [Tutor] Serial Port Access - Help!! References: Message-ID: I've been quite excited about the power and ease of use of Pthon and have been continuing my learning... However I have a need to access a serial port ( I'm an avid Ham Radio nut and would like to control my various radios using a Python set of routines). I have found this to be a challenge that seems out of what I thought was a design philosophy of Python - ie ease of learning and use. I have yet to successfully get access to the serial port. I've tried to use various 'downloads' referenced in the Python books - but no doubt due to my noice skills - I have not been successful in getting any of them to work. I'm trying this from a Windows 98 system. I sure would welcome some advice as to an easy approach to using a serial port Thanks Dan ( VA3MA) > From bobhicks@adelphia.net Mon Feb 19 23:55:55 2001 From: bobhicks@adelphia.net (Robert L Hicks) Date: Mon, 19 Feb 2001 18:55:55 -0500 Subject: [Tutor] PMZ Message-ID: I have *tried* it but unsuccessfully so far...I just need to tweak the = pmz.py file to reflect my environment but I am kinda clueless on the = paths that pmz.py wants. A better place to post would be the newsgroup... - Bob= From tim@johnsons-web.com Tue Feb 20 03:50:26 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Mon, 19 Feb 2001 18:50:26 -0900 Subject: [Tutor] Button, Button, How do I put the Button References: Message-ID: <01021918550700.01148@shecom> Hello All: Below is some code that is meant to hold two buttons and a text window. I don't know quite how to place the buttons Two Questions: 1)How do I place the buttons side by side, instead of one above the other? 2)Where is documentation relevant to my questions. BTW: Thanks to all for all the input on my question on sound() Code to follow ################################################################ from Tkinter import * from ScrolledText import * import sys def die(event): sys.exit(0) def test(event): pass root = Tk() text_frame = Frame(root) text_frame.pack(expand=1,fill=BOTH) # build the "quit" button q_button = Button(text_frame,width=25) q_button["text"] = "Quit" q_button.bind("