From Laszlo Janos" Hi all, I should write some script, witch log into a telnet server and make changes in a lot of records. There are about 400 records I should modify. I can call a modificator application witch wants me to send keystrokes but I aim to automate it. Have you got any idea, or do you know any example? thanxxx, jlaszlo --------------------------------------------------------------------- http://www.netposta.net NetPosta, E-m@il ingyen! From arcege@shore.net Fri Jul 2 13:54:21 1999 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 2 Jul 1999 08:54:21 -0400 (EDT) Subject: [Tutor] telnet app In-Reply-To: <19990702095442.21740.qmail@netposta.net> from Laszlo Janos at "Jul 2, 99 09:54:42 am" Message-ID: <199907021254.IAA16727@northshore.shore.net> > Hi all, > > I should write some script, witch log into a telnet server and make changes in > a lot of records. There are about 400 records I should modify. I can call a > modificator application witch wants me to send keystrokes but I aim to automate > it. Have you got any idea, or do you know any example? > You will want to either use the expect feature in the standard module telnetlib, or download one of the Expect extension (which can give a little more control) from the Python website (http://www.python.org/). Expect is a Tcl extension (UNIX, but there is a NT port out there) which allows control over a application (often one that requires a terminal to work). Some Python extensions emulate Expect, some use the Expect/C library directly (without Tcl). -Arcege From Stephen_Gilbert@npd.com Fri Jul 2 20:11:49 1999 From: Stephen_Gilbert@npd.com (Stephen_Gilbert@npd.com) Date: Fri, 2 Jul 1999 15:11:49 -0400 Subject: [Tutor] newbie problems Message-ID: --openmail-part-024eb95c-00000001 Content-Type: multipart/alternative; boundary=openmail-part-024eb95c-00000002 --openmail-part-024eb95c-00000002 Content-Type: text/plain; charset=ISO-8859-1; name="BDY.RTF" Content-Disposition: inline; filename="BDY.RTF" Content-Transfer-Encoding: quoted-printable Help! I'm trying to write a simple script to: open 2 files one new file for writing, one existing file to read from, =20 read a line at a time and write it to the new file, if the first 3 bytes of the line is "+++" =20 then I want to take 5 bytes starting at position 15 and append it to the end of each line. I have done this type of processing on many different platforms in the past, but now I need to do it using Python on Unix. =20 I have figured out how to open the files and how to read each line into a string variable. However I can't figure out how to parse the variable and concatenate the new string to write out to the new file. Any help would be greatly appreciated. TIA Steve --openmail-part-024eb95c-00000002 Content-Type: application/rtf; name="BDY.RTF" Content-Disposition: attachment; filename="BDY.RTF" Content-Transfer-Encoding: base64 e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZGVmZjBcZGVmbGFuZzEwMzN7XGZvbnR0Ymwge1xm MFxmc3dpc3NcZmNoYXJzZXQwIEFyaWFsO319DQpcdWMxXHBhcmRcdWxub25lXGYwXGZzMjAg SGVscCFccGFyDQpccGFyDQpJJ20gdHJ5aW5nIHRvIHdyaXRlIGEgc2ltcGxlIHNjcmlwdCB0 bzpccGFyDQpccGFyDQpcdGFiIG9wZW4gMiBmaWxlcyBvbmUgbmV3IGZpbGUgZm9yIHdyaXRp bmcsIG9uZSBleGlzdGluZyBmaWxlIHRvIHJlYWQgZnJvbSwgXHBhcg0KXHRhYiByZWFkIGEg bGluZSBhdCBhIHRpbWUgYW5kIHdyaXRlIGl0IHRvIHRoZSBuZXcgZmlsZSxccGFyDQpcdGFi IGlmIHRoZSBmaXJzdCAzIGJ5dGVzIG9mIHRoZSBsaW5lIGlzICIrKysiIFxwYXINClx0YWIg dGhlbiBJIHdhbnQgdG8gdGFrZSA1IGJ5dGVzIHN0YXJ0aW5nIGF0IHBvc2l0aW9uIDE1IGFu ZCBhcHBlbmQgaXQgdG8gdGhlIGVuZCBvZiBlYWNoIGxpbmUuXHBhcg0KXHBhcg0KSSBoYXZl IGRvbmUgdGhpcyB0eXBlIG9mIHByb2Nlc3Npbmcgb24gbWFueSBkaWZmZXJlbnQgcGxhdGZv cm1zIGluIHRoZSBwYXN0LCBidXQgbm93IEkgbmVlZCB0byBkbyBpdCB1c2luZyBQeXRob24g b24gVW5peC4gXHBhcg0KSSBoYXZlIGZpZ3VyZWQgb3V0IGhvdyB0byBvcGVuIHRoZSBmaWxl cyBhbmQgaG93IHRvIHJlYWQgZWFjaCBsaW5lIGludG8gYSBzdHJpbmcgdmFyaWFibGUuIEhv d2V2ZXIgSSBjYW4ndCBmaWd1cmUgb3V0IGhvdyB0byBwYXJzZSB0aGUgdmFyaWFibGUgYW5k IGNvbmNhdGVuYXRlIHRoZSBuZXcgc3RyaW5nIHRvIHdyaXRlIG91dCB0byB0aGUgbmV3IGZp bGUuIEFueSBoZWxwIHdvdWxkIGJlIGdyZWF0bHkgYXBwcmVjaWF0ZWQuXHBhcg0KXHBhcg0K VElBXHBhcg0KXHBhcg0KU3RldmVccGFyDQp9DQoA --openmail-part-024eb95c-00000002-- --openmail-part-024eb95c-00000001 Content-Type: application/ms-tnef; name="WINMAIL.DAT" Content-Disposition: attachment; filename="WINMAIL.DAT" Content-Transfer-Encoding: base64 eJ8+Ij97AQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcACQAAAElQTS5O b3RlAKoCAQ2ABAACAAAAAgACAAEDkAYADAAAAAEAAAADABcAAQAAABwAAQOQBgAMAAAAAQAA AAMANgAAAAAAOgABBIABABAAAABuZXdiaWUgcHJvYmxlbXMA/gUBA5AGABAAAAABAAAAQAA5 AICNr8y+xL4BQwUBA5AGACQAAAABAAAACwArjwsgBgAAAAAAwAAAAAAAAEYAAAAABYgAAAAA AACKAgEDkAYAJAAAAAEAAAALACyPCyAGAAAAAADAAAAAAAAARgAAAAAAiAAAAAAAAIYCAQOQ BgAsAAAAAQAAAB4ALY8IIAYAAAAAAMAAAAAAAABGAAAAADiFAAABAAAAAQAAAAAAAADOAgED kAYALAAAAAEAAAAeAC6PCCAGAAAAAADAAAAAAAAARgAAAAA3hQAAAQAAAAEAAAAAAAAAzgIB A5AGACwAAAABAAAAHgAvjwggBgAAAAAAwAAAAAAAAEYAAAAANoUAAAEAAAABAAAAAAAAAM4C AQOQBgAkAAAAAQAAAAMAMI8IIAYAAAAAAMAAAAAAAABGAAAAABiFAAAAAAAAlAIBA5AGACQA AAABAAAAAwAxjwggBgAAAAAAwAAAAAAAAEYAAAAAEYUAAAAAAACOAgEDkAYAJAAAAAEAAAAD ADKPCCAGAAAAAADAAAAAAAAARgAAAAAQhQAAAAAAAI4CAQOQBgAkAAAAAQAAAAsAM48IIAYA AAAAAMAAAAAAAABGAAAAAA6FAAAAAAAAlQIBA5AGACQAAAABAAAAAwA0jwggBgAAAAAAwAAA AAAAAEYAAAAAAYUAAAAAAACBAgEDkAYAJAAAAAEAAAALADWPCCAGAAAAAADAAAAAAAAARgAA AAAGhQAAAAAAAI8CAQOQBgAsAAAAAQAAAB4ANo8IIAYAAAAAAMAAAAAAAABGAAAAAFSFAAAB AAAABAAAADguNQCRAwEDkAYAJAAAAAEAAAADADePCCAGAAAAAADAAAAAAAAARgAAAABShQAA 8BMAANgDAQOQBgAMAAAAAQAAAAMA3j+vbwAAPwIBA5AGAAwAAAABAAAACwACAAEAAAAPAAED kAYAIAAAAAEAAAAeAHAAAQAAABAAAABuZXdiaWUgcHJvYmxlbXMAngYBA5AGABQAAAABAAAA HgA9AAEAAAABAAAAAAAAAF4AAQOQBgAgAAAAAQAAAAIBCzABAAAAEAAAAAdj44SvL9MRvdEA wE9v5IteCAEDkAYAKAAAAAEAAAACAXEAAQAAABYAAAABvsS+zGmE42ODL68R073RAMBPb+SL AACMDAEDkAYADAAAAAEAAAADAIAQ/////5AEAQkABAACAAAAAAAAAAEDkAYADAAAAAEAAAAL ACMAAAAAAC8AAQOQBgAMAAAAAQAAAAsAKQAAAAAANQABBJAGADgCAAABAAAAEwAAAB4AATAB AAAAEwAAACd0dXRvckBweXRob24ub3JnJwAAAgH/DwEAAAA/AAAAAAAAAIErH6S+oxAZnW4A 3QEPVAIAAAEAdHV0b3JAcHl0aG9uLm9yZwBTTVRQAHR1dG9yQHB5dGhvbi5vcmcAAAMAFQwB AAAAAwAAMAAAAAAeAAIwAQAAAAUAAABTTVRQAAAAAB4AGgwBAAAAEQAAAFN0ZXBoZW4gR2ls YmVydAAAAAAAAgEZDAEAAABAAAAAAAAAAI1VTNDsPBHOgf8IAAmxA3oBAAAACwAAAAAAAAAx HUdpbGJlcnQeMh1TdGVwaGVuHjUdbnkeNh1zeW5kAAMAcToAAAAACwBAOgAABgADAAA5AAAA AAIBCzABAAAAFgAAAFNNVFA6VFVUT1JAUFlUSE9OLk9SRwAAAAIB+Q8BAAAAPwAAAAAAAACB Kx+kvqMQGZ1uAN0BD1QCAAABEHR1dG9yQHB5dGhvbi5vcmcAU01UUAB0dXRvckBweXRob24u b3JnAAADAP4PBgAAAB4AAzABAAAAEQAAAHR1dG9yQHB5dGhvbi5vcmcAAAAAAwD/XwAAAAAD AP1fAQAAAB4A9l8BAAAAEQAAAHR1dG9yQHB5dGhvbi5vcmcAAAAAAgH3XwEAAAA/AAAAAAAA AIErH6S+oxAZnW4A3QEPVAIAAAEAdHV0b3JAcHl0aG9uLm9yZwBTTVRQAHR1dG9yQHB5dGhv bi5vcmcAAAsADw4AAASAn3s= --openmail-part-024eb95c-00000001-- From ivanlan@callware.com Fri Jul 2 20:37:00 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Fri, 02 Jul 1999 13:37:00 -0600 Subject: [Tutor] newbie problems References: Message-ID: <377D14DC.60F68CD3@callware.com> Hi Steve-- Stephen_Gilbert@npd.com wrote: > > Help! > > I'm trying to write a simple script to: > > open 2 files one new file for writing, one existing file to read > from, > read a line at a time and write it to the new file, > if the first 3 bytes of the line is "+++" > then I want to take 5 bytes starting at position 15 and append it > to the end of each line. > > I have done this type of processing on many different platforms in the > past, but now I need to do it using Python on Unix. > I have figured out how to open the files and how to read each line into > a string variable. However I can't figure out how to parse the variable > and concatenate the new string to write out to the new file. Any help > would be greatly appreciated. > > TIA > > Steve > This is the sort of thing Python is *really* good at. Assume s contains your whole line: plus = s[:3] # Grab first three bytes; you can also write this as s[0:3] if plus == '+++': appnd = s[15:20] newline = s + appnd outfile.write(newline) else: # do whatever you need to do if the first three chars aren't +++ Alternatively, you can dispense with the temporary variables: if s[:3] == '+++': outfile.write(s + s[15:20]) and speed it up with a slight penalty in readability. Look at the docs for slicing at www.python.org. -ly y'rs, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 ---------------------------------------------- From joe@strout.net Fri Jul 2 20:40:55 1999 From: joe@strout.net (Joseph J. Strout) Date: Fri, 2 Jul 1999 12:40:55 -0700 Subject: [Tutor] newbie problems In-Reply-To: Message-ID: At 12:11 PM -0700 07/02/99, Stephen_Gilbert@npd.com wrote: >a string variable. However I can't figure out how to parse the variable >and concatenate the new string to write out to the new file. You need to read about basic string operations. Try this page of the tutorial: http://www.python.org/doc/tut/node5.html (or, if you're really interested in learning Python, try the entire tutorial -- it's well-written and not all that long). E.g., to see if the first three bytes of the line is "+++" just do if myline[:3] == "+++": Simple, no? And, to contatenate bytes 15-20 to the end of the line, do: myline = myline + myline[15:20] Even simpler! That's Python for you... Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' From sessile@in-gen.net Sun Jul 4 18:11:21 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Sun, 04 Jul 1999 13:11:21 -0400 Subject: [Tutor] Accessing C library (*.a) functions from Python Message-ID: <3.0.6.32.19990704131121.007aca10@mail.in-gen.net> Hello all, This is my first attempt at a Python extension... I would like to be able to use Python rather than C to access the functions contained within a library file named "ttslib.a". From the "tts" documentation, I know that the "tts" functions can be used within a C program by #defining "ttsdef.h" (which defines a number of return codes) and then linking "ttslib.a" into the program. No source code is available on the "ttslib" side of things (it's part of a proprietary system) though all of the "tts" functions are documented. After reading the Extending and Embedding Tutorial, I do not see how to tie Python into an existing API without access to source (and given my current level of understanding, probably couldn't do it even if I had the source :-/ ). Advice please? Am I missing a basic concept here? I can forward additional "tts" documentation, including an example C program that uses some of the "libtts.a" functions, to anyone willing to help. -- E-Mail: sessile@in-gen.net "I don't want the world... I just want your half." -- TMBG (Anna Ng) From 010.Werkstudent@MCHF.SIEMENS.DE Mon Jul 5 11:36:12 1999 From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010) Date: Mon, 5 Jul 1999 12:36:12 +0200 Subject: [Tutor] (no subject) Message-ID: <809AE76DB183D111BE1300005A40E070CA53ED@mail.mchf.siemens.de> Greetings, the thread module allows one to start a new thread with "thread.start_new_thread(routine-name, (tuple))", but what does it do under internall? I want to execute a method by passing it in a similar manner, with its tuple of arguments, e.g. "doit(routine-name, (tuple))". How do I get my python interpreter to believe me. What is the sequence of "routine-name" and tuple that my python interpreter needs from me, complete with parenthesis, or none, etc. etc.? thanks David Ungemach From arcege@shore.net Mon Jul 5 14:54:12 1999 From: arcege@shore.net (Michael P. Reilly) Date: Mon, 5 Jul 1999 09:54:12 -0400 (EDT) Subject: [Tutor] (no subject) In-Reply-To: <809AE76DB183D111BE1300005A40E070CA53ED@mail.mchf.siemens.de> from Werkstudent 010 at "Jul 5, 99 12:36:12 pm" Message-ID: <199907051354.JAA13931@northshore.shore.net> [Charset iso-8859-1 unsupported, filtering to ASCII...] > > Greetings, > > the thread module allows one to start a new thread with "thread.start_new_thread(routine-name, (tuple))", > but what does it do under internall? I want to execute a method by passing it in a similar manner, with its tuple of arguments, e.g. "doit(routine-name, (tuple))". How do I get my python interpreter to believe me. What is the sequence of "routine-name" and tuple that my python interpreter needs from me, complete with parenthesis, or none, etc. etc.? > > thanks David, Python has a function to call functions in the fashion you want, called "apply". The format is: retvalue = apply(function, args[, keywds]) The function must be a function object or bound method, args must be a tuple, and the optional keywds should be a dictionary. >>> def foo(a, b=1, *c, **d): ... print a, b, c, d ... >>> foo(1) >>> apply(foo, (1,)) 1 1 () {} >>> foo(1, 2, 3) 1 2 (3,) {} >>> apply(foo, (1, 2, 3)) 1 2 (3,) {} >>> foo(1, b=2, c=3) 1 2 () {'c': 3} >>> apply(foo, (1,) {'b': 2, 'c': 3}) 1 2 () {'c': 3} >>> The start_new_thread() function is similar, but must start differently because of how threads are started. I suggest reading the source if you are really interested (Modules/threadmodule.c), but it is not important for what it seems you need. :) For more information, read: Python Language Reference, section 5.3.4: "Calls" http://www.python.org/doc/current/ref/calls.html Python Language Reference, section 7.5: "Function definitions" http://www.python.org/doc/current/ref/function.html Python Library Reference, section 2.3 "Built-in Functions: apply" http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-181 -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ From 010.Werkstudent@MCHF.SIEMENS.DE Mon Jul 5 15:03:04 1999 From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010) Date: Mon, 5 Jul 1999 16:03:04 +0200 Subject: AW: [Tutor] (no subject) Message-ID: <809AE76DB183D111BE1300005A40E070CA53EE@mail.mchf.siemens.de> -----Ursprüngliche Nachricht----- Von: Michael P. Reilly [mailto:arcege@shore.net] Gesendet am: Montag, 5. Juli 1999 15:54 An: Werkstudent 010 Cc: tutor@python.org Betreff: Re: [Tutor] (no subject) [Charset iso-8859-1 unsupported, filtering to ASCII...] > > Greetings, > > the thread module allows one to start a new thread with "thread.start_new_thread(routine-name, (tuple))", > but what does it do under internall? I want to execute a method by passing it in a similar manner, with its tuple of arguments, e.g. "doit(routine-name, (tuple))". How do I get my python interpreter to believe me. What is the sequence of "routine-name" and tuple that my python interpreter needs from me, complete with parenthesis, or none, etc. etc.? > > thanks David, Python has a function to call functions in the fashion you want, called "apply". The format is: retvalue = apply(function, args[, keywds]) The function must be a function object or bound method, args must be a tuple, and the optional keywds should be a dictionary. >>> def foo(a, b=1, *c, **d): ... print a, b, c, d ... >>> foo(1) >>> apply(foo, (1,)) 1 1 () {} >>> foo(1, 2, 3) 1 2 (3,) {} >>> apply(foo, (1, 2, 3)) 1 2 (3,) {} >>> foo(1, b=2, c=3) 1 2 () {'c': 3} >>> apply(foo, (1,) {'b': 2, 'c': 3}) 1 2 () {'c': 3} >>> The start_new_thread() function is similar, but must start differently because of how threads are started. I suggest reading the source if you are really interested (Modules/threadmodule.c), but it is not important for what it seems you need. :) For more information, read: Python Language Reference, section 5.3.4: "Calls" http://www.python.org/doc/current/ref/calls.html Python Language Reference, section 7.5: "Function definitions" http://www.python.org/doc/current/ref/function.html Python Library Reference, section 2.3 "Built-in Functions: apply" http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-181 -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor From 010.Werkstudent@MCHF.SIEMENS.DE Mon Jul 5 15:05:42 1999 From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010) Date: Mon, 5 Jul 1999 16:05:42 +0200 Subject: AW: [Tutor] (no subject) Message-ID: <809AE76DB183D111BE1300005A40E070CA53EF@mail.mchf.siemens.de> Thanks Michael, I believe, that which had stumped me, was my use of doulbe instead of single quotes when trying to pass my argument tuple. It resulted in each letter of a string being considered a seperate argument, and my called routines screamed about too many arguments, until it occured to me, to use skinny quotes. Thanks again, David Ungemach -----Ursprüngliche Nachricht----- Von: Michael P. Reilly [mailto:arcege@shore.net] Gesendet am: Montag, 5. Juli 1999 15:54 An: Werkstudent 010 Cc: tutor@python.org Betreff: Re: [Tutor] (no subject) [Charset iso-8859-1 unsupported, filtering to ASCII...] > > Greetings, > > the thread module allows one to start a new thread with "thread.start_new_thread(routine-name, (tuple))", > but what does it do under internall? I want to execute a method by passing it in a similar manner, with its tuple of arguments, e.g. "doit(routine-name, (tuple))". How do I get my python interpreter to believe me. What is the sequence of "routine-name" and tuple that my python interpreter needs from me, complete with parenthesis, or none, etc. etc.? > > thanks David, Python has a function to call functions in the fashion you want, called "apply". The format is: retvalue = apply(function, args[, keywds]) The function must be a function object or bound method, args must be a tuple, and the optional keywds should be a dictionary. >>> def foo(a, b=1, *c, **d): ... print a, b, c, d ... >>> foo(1) >>> apply(foo, (1,)) 1 1 () {} >>> foo(1, 2, 3) 1 2 (3,) {} >>> apply(foo, (1, 2, 3)) 1 2 (3,) {} >>> foo(1, b=2, c=3) 1 2 () {'c': 3} >>> apply(foo, (1,) {'b': 2, 'c': 3}) 1 2 () {'c': 3} >>> The start_new_thread() function is similar, but must start differently because of how threads are started. I suggest reading the source if you are really interested (Modules/threadmodule.c), but it is not important for what it seems you need. :) For more information, read: Python Language Reference, section 5.3.4: "Calls" http://www.python.org/doc/current/ref/calls.html Python Language Reference, section 7.5: "Function definitions" http://www.python.org/doc/current/ref/function.html Python Library Reference, section 2.3 "Built-in Functions: apply" http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-181 -Arcege -- ------------------------------------------------------------------------ | Michael P. Reilly, Release Engineer | Email: arcege@shore.net | | Salem, Mass. USA 01970 | | ------------------------------------------------------------------------ _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor From Chris.Reay@pareto-partners.com.au Mon Jul 5 06:07:30 1999 From: Chris.Reay@pareto-partners.com.au (Chris Reay) Date: Mon, 5 Jul 1999 06:07:30 +0100 Subject: [Tutor] Clipboard utilities for Windows NT4? Message-ID: <55A01F6715D2D211BE8D00600856C4FE062B45@ozntsyd1.ppsydney> Greetings Do there exist for Python utilities for copying and pasting to and from the Windows NT4.0 clipboard? I've had an unsuccesful look through the documentation. Thanks Chris chris.reay@pareto-partners.com.au From Stephen_Gilbert@npd.com Tue Jul 6 13:46:39 1999 From: Stephen_Gilbert@npd.com (Stephen_Gilbert@npd.com) Date: Tue, 6 Jul 1999 08:46:39 -0400 Subject: [Tutor] newbie problems Message-ID: --openmail-part-0251345a-00000001 Content-Type: multipart/alternative; boundary=openmail-part-0251345a-00000002 --openmail-part-0251345a-00000002 Content-Type: text/plain; charset=ISO-8859-1; name="BDY.RTF" Content-Disposition: inline; filename="BDY.RTF" Content-Transfer-Encoding: quoted-printable Thanks Guys. That was just the ticket! The tutorial looks quite helpful.= Thanks Again! Steve =2D----Original Message----- From: joe [mailto:joe@strout.net] Sent: Friday, July 02, 1999 3:41 PM To: Stephen Gilbert; tutor Cc: joe Subject: Re: [Tutor] newbie problems At 12:11 PM -0700 07/02/99, Stephen_Gilbert@npd.com wrote: >a string variable. However I can't figure out how to parse the variable= >and concatenate the new string to write out to the new file. You need to read about basic string operations. Try this page of the tutorial: http://www.python.org/doc/tut/node5.html (or, if you're really interested in learning Python, try the entire tutorial -- it's well-written and not all that long). E.g., to see if the first three bytes of the line is "+++" just do if myline[:3] =3D=3D "+++": Simple, no? And, to contatenate bytes 15-20 to the end of the line, do:= myline =3D myline + myline[15:20] Even simpler! That's Python for you... Cheers, =2D- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' --openmail-part-0251345a-00000002 Content-Type: application/rtf; name="BDY.RTF" Content-Disposition: attachment; filename="BDY.RTF" Content-Transfer-Encoding: base64 e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYw XGZzd2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmls XGZjaGFyc2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5l dzt9fQ0Ke1xjb2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1 NTt9DQpcdWMxXHBhcmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwXGNmMCBUaGFua3MgR3V5 cy4gVGhhdCB3YXMganVzdCB0aGUgdGlja2V0ISBUaGUgdHV0b3JpYWwgbG9va3MgcXVpdGUg aGVscGZ1bC4gXHBhcg0KXHBhcg0KVGhhbmtzIEFnYWluIVxwYXINClxwYXINClN0ZXZlXHBh cg0KXHBhcg0KLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS1ccGFyDQpGcm9tOiBqb2UgW21h aWx0bzpqb2VAc3Ryb3V0Lm5ldF1ccGFyDQpTZW50OiBGcmlkYXksIEp1bHkgMDIsIDE5OTkg Mzo0MSBQTVxwYXINClRvOiBTdGVwaGVuIEdpbGJlcnQ7IHR1dG9yXHBhcg0KQ2M6IGpvZVxw YXINClN1YmplY3Q6IFJlOiBbVHV0b3JdIG5ld2JpZSBwcm9ibGVtc1xwYXINClxwYXINClxw YXINCkF0IDEyOjExIFBNIC0wNzAwIDA3LzAyLzk5LCBTdGVwaGVuX0dpbGJlcnRAbnBkLmNv bSB3cm90ZTpccGFyDQpccGFyDQo+YSBzdHJpbmcgdmFyaWFibGUuIEhvd2V2ZXIgSSBjYW4n dCBmaWd1cmUgb3V0IGhvdyB0byBwYXJzZSB0aGUgdmFyaWFibGVccGFyDQo+YW5kIGNvbmNh dGVuYXRlIHRoZSBuZXcgc3RyaW5nIHRvIHdyaXRlIG91dCB0byB0aGUgbmV3IGZpbGUuXHBh cg0KXHBhcg0KWW91IG5lZWQgdG8gcmVhZCBhYm91dCBiYXNpYyBzdHJpbmcgb3BlcmF0aW9u cy4gIFRyeSB0aGlzIHBhZ2Ugb2YgdGhlIHR1dG9yaWFsOlxwYXINClxwYXINClx0YWIgICAg aHR0cDovL3d3dy5weXRob24ub3JnL2RvYy90dXQvbm9kZTUuaHRtbFxwYXINClxwYXINCihv ciwgaWYgeW91J3JlIHJlYWxseSBpbnRlcmVzdGVkIGluIGxlYXJuaW5nIFB5dGhvbiwgdHJ5 IHRoZSBlbnRpcmVccGFyDQp0dXRvcmlhbCAtLSBpdCdzIHdlbGwtd3JpdHRlbiBhbmQgbm90 IGFsbCB0aGF0IGxvbmcpLlxwYXINClxwYXINCkUuZy4sIHRvIHNlZSBpZiB0aGUgZmlyc3Qg dGhyZWUgYnl0ZXMgb2YgdGhlIGxpbmUgaXMgIisrKyIganVzdCBkb1xwYXINClxwYXINClx0 YWIgaWYgbXlsaW5lWzozXSA9PSAiKysrIjpccGFyDQpccGFyDQpTaW1wbGUsIG5vPyAgQW5k LCB0byBjb250YXRlbmF0ZSBieXRlcyAxNS0yMCB0byB0aGUgZW5kIG9mIHRoZSBsaW5lLCBk bzpccGFyDQpccGFyDQpcdGFiIG15bGluZSA9IG15bGluZSArIG15bGluZVsxNToyMF1ccGFy DQpccGFyDQpFdmVuIHNpbXBsZXIhICBUaGF0J3MgUHl0aG9uIGZvciB5b3UuLi5ccGFyDQpc cGFyDQpDaGVlcnMsXHBhcg0KLS0gSm9lXHBhcg0KLC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS5ccGFyDQp8ICAg IEpvc2VwaCBKLiBTdHJvdXQgICAgICAgICAgIEJpb2NvbXB1dGluZyAtLSBUaGUgU2FsayBJ bnN0aXR1dGUgfFxwYXINCnwgICAgam9lQHN0cm91dC5uZXQgICAgICAgICAgICAgaHR0cDov L3d3dy5zdHJvdXQubmV0ICAgICAgICAgICAgICB8XHBhcg0KYC0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSdccGFy DQp9 --openmail-part-0251345a-00000002-- --openmail-part-0251345a-00000001 Content-Type: application/ms-tnef; name="WINMAIL.DAT" Content-Disposition: attachment; filename="WINMAIL.DAT" Content-Transfer-Encoding: base64 eJ8+IsefAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcACQAAAElQTS5O b3RlAKoCAQ2ABAACAAAAAgACAAEDkAYADAAAAAEAAAADABcAAQAAABwAAQOQBgAMAAAAAQAA AAMANgAAAAAAOgABBIABACAAAABSRTogUmU6IFtUdXRvcl0gbmV3YmllIHByb2JsZW1zAPYK AQOQBgAQAAAAAQAAAEAAOQAgRuu0rce+AbIEAQOQBgAMAAAAAQAAAAMA3j+vbwAAPwIBA5AG ABQAAAABAAAAHgBCEAEAAAABAAAAAAAAAHMAAQOQBgAkAAAAAQAAAAIBMQABAAAAEQAAAEgw MDAwNWQxMDMwMjA3ODQAAAAAsQMBA5AGAAwAAAABAAAACwACAAEAAAAPAAEDkAYADAAAAAEA AAALACsAAAAAADcAAQOQBgAMAAAAAQAAAAMALgAAAAAAMgABA5AGACgAAAABAAAAAgFxAAEA AAAWAAAAAb7HrbSbVsE+UDOeEdO90QDAT2/kiwAA4wsBA5AGACwAAAABAAAAHgBwAAEAAAAc AAAAUmU6IFtUdXRvcl0gbmV3YmllIHByb2JsZW1zALEKAQOQBgAYAAAAAQAAAB4APQABAAAA BQAAAFJFOiAAAAAAUwEBA5AGACQAAAABAAAACwAAgAsgBgAAAAAAwAAAAAAAAEYAAAAABYgA AAAAAABQAgEDkAYAJAAAAAEAAAALAAGACyAGAAAAAADAAAAAAAAARgAAAAAAiAAAAAAAAEwC AQOQBgAsAAAAAQAAAB4AAoAIIAYAAAAAAMAAAAAAAABGAAAAADiFAAABAAAAAQAAAAAAAACU AgEDkAYALAAAAAEAAAAeAAOACCAGAAAAAADAAAAAAAAARgAAAAA3hQAAAQAAAAEAAAAAAAAA lAIBA5AGACwAAAABAAAAHgAEgAggBgAAAAAAwAAAAAAAAEYAAAAANoUAAAEAAAABAAAAAAAA AJQCAQOQBgAkAAAAAQAAAAMABYAIIAYAAAAAAMAAAAAAAABGAAAAABiFAAAAAAAAWgIBA5AG ACQAAAABAAAAAwAGgAggBgAAAAAAwAAAAAAAAEYAAAAAEYUAAAAAAABUAgEDkAYAJAAAAAEA AAADAAeACCAGAAAAAADAAAAAAAAARgAAAAAQhQAAAAAAAFQCAQOQBgAkAAAAAQAAAAsACIAI IAYAAAAAAMAAAAAAAABGAAAAAA6FAAAAAAAAWwIBA5AGACQAAAABAAAAAwAJgAggBgAAAAAA wAAAAAAAAEYAAAAAAYUAAAAAAABHAgEDkAYAJAAAAAEAAAALAAqACCAGAAAAAADAAAAAAAAA RgAAAAAGhQAAAAAAAFUCAQOQBgAsAAAAAQAAAB4AC4AIIAYAAAAAAMAAAAAAAABGAAAAAFSF AAABAAAABAAAADguNQBXAwEDkAYAJAAAAAEAAAADAAyACCAGAAAAAADAAAAAAAAARgAAAABS hQAA8BMAAJ4DAQOQBgAgAAAAAQAAAAIBCzABAAAAEAAAAEw+wVaeM9MRvdEAwE9v5IshCAED kAYADAAAAAEAAAADAIAQ/////5AEAQkABAACAAAAAAAAAAEDkAYADAAAAAEAAAALACMAAAAA AC8AAQOQBgAMAAAAAQAAAAsAKQAAAAAANQABBJAGAGABAAABAAAADwAAAB4AATABAAAACAAA ACd0dXRvcicAAgH/DwEAAAA0AAAAAAAAAIErH6S+oxAZnW4A3QEPVAIAAAAAdHV0b3IAU01U UAB0dXRvckBweXRob24ub3JnAAMAFQwBAAAAAwAAMAAAAAAeAAIwAQAAAAUAAABTTVRQAAAA AB4AGgwBAAAAEQAAAFN0ZXBoZW4gR2lsYmVydAAAAAAAAgEZDAEAAABAAAAAAAAAAI1VTNDs PBHOgf8IAAmxA3oBAAAACwAAAAAAAAAxHUdpbGJlcnQeMh1TdGVwaGVuHjUdbnkeNh1zeW5k AAMAADkAAAAAAwD+DwYAAAACAQswAQAAABYAAABTTVRQOlRVVE9SQFBZVEhPTi5PUkcAAAAe AAMwAQAAABEAAAB0dXRvckBweXRob24ub3JnAAAAAAMAcToAAAAAAwD9XwEAAAALAA8OAAAE gAsAQDoBAAYA9T4= --openmail-part-0251345a-00000001-- From michael@mediamanager.com.sg Wed Jul 7 08:35:19 1999 From: michael@mediamanager.com.sg (Michael Ang) Date: Wed, 07 Jul 1999 15:35:19 +0800 Subject: [Tutor] Apache, CGI configuration Message-ID: <4.1.19990707152513.0093bc90@po.mediamanager.com.sg> Hi, I'm having problem running cgi in one of my Linux-Apache server, I follow exactly what needed to be done given in this site (http://starship.skyport.net/crew/davem/cgifaq/faqw.cgi?req=index). The web server always respond as <<<< The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, michael@kids.monja.com.sg and inform them of the time the error occurred, and anything you might have done that may have caused the error. Premature end of script headers: /usr/local/apache/share/cgi-bin/Hello.py >>> (Hello.py is also taken from the help site) Is it neccessary to set PYTHONPATH in Linux and how and where should I set it. Anything that I've missed out? Thanks in advance Michael From deirdre@deirdre.net Wed Jul 7 00:59:51 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 6 Jul 1999 16:59:51 -0700 (PDT) Subject: [Tutor] Apache, CGI configuration In-Reply-To: <4.1.19990707152513.0093bc90@po.mediamanager.com.sg> Message-ID: I was having problems with CGIs too. I actually found Internet Programming With Python a better resource. In my case, I was also sending mail with the CGI and set its debug level to 1; the chatter from the mail server gave exactly the error below. You might try running your CGI from the command line and see what you get. :) On Wed, 7 Jul 1999, Michael Ang wrote: > Hi, > I'm having problem running cgi in one of my Linux-Apache server, I follow > exactly what needed to be done given in this site > (http://starship.skyport.net/crew/davem/cgifaq/faqw.cgi?req=index). The web > server always respond as > <<<< > The server encountered an internal error or misconfiguration and was unable > to complete your request. > > Please contact the server administrator, michael@kids.monja.com.sg and > inform them of the time the error occurred, and anything you might have > done that may have caused the error. > > Premature end of script headers: /usr/local/apache/share/cgi-bin/Hello.py > >>> > (Hello.py is also taken from the help site) > > Is it neccessary to set PYTHONPATH in Linux and how and where should I set it. > Anything that I've missed out? > > Thanks in advance > > Michael > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > -- _Deirdre * http://www.linuxcabal.org * http://www.deirdre.net "I have a simple rule in life: If I don't understand something, it must be bad." & "If you want more than 4 gig of memory, get a *real* CPU." -- Linus Torvalds, speaking at BALUG (www.balug.org) From steve@estel.uindy.edu Wed Jul 7 14:31:58 1999 From: steve@estel.uindy.edu (Steve Spicklemire) Date: Wed, 7 Jul 1999 08:31:58 -0500 (EST) Subject: [Tutor] Apache, CGI configuration In-Reply-To: <4.1.19990707152513.0093bc90@po.mediamanager.com.sg> (message from Michael Ang on Wed, 07 Jul 1999 15:35:19 +0800) Message-ID: <199907071331.IAA08387@estel.uindy.edu> Hi Michael, Have you looked at the apach error_log file for clues? More than likely this is a problem with the 'Content-Type' header. If possible, try to run your cgi-script stand-alone and see that it produces the correct header. If that doesn't work... maybe post the code? -steve >>>>> "Michael" == Michael Ang writes: Michael> Hi, I'm having problem running cgi in one of my Michael> Linux-Apache server, I follow exactly what needed to be Michael> done given in this site Michael> (http://starship.skyport.net/crew/davem/cgifaq/faqw.cgi?req=index). The Michael> web server always respond as <<<< The server encountered Michael> an internal error or misconfiguration and was unable to Michael> complete your request. Michael> Please contact the server administrator, Michael> michael@kids.monja.com.sg and inform them of the time the Michael> error occurred, and anything you might have done that may Michael> have caused the error. Michael> Premature end of script headers: Michael> /usr/local/apache/share/cgi-bin/Hello.py >>>> Michael> (Hello.py is also taken from the help site) Michael> Is it neccessary to set PYTHONPATH in Linux and how and Michael> where should I set it. Anything that I've missed out? Michael> Thanks in advance Michael> Michael Michael> _______________________________________________ Tutor Michael> maillist - Tutor@python.org Michael> http://www.python.org/mailman/listinfo/tutor From jdemarchis@stny.rr.com Wed Jul 7 16:49:15 1999 From: jdemarchis@stny.rr.com (John De Marchis) Date: Wed, 7 Jul 1999 11:49:15 -0400 Subject: [Tutor] how to Message-ID: <000701bec890$449342e0$992c5e18@oemcomputer.stny.rr.com> This is a multi-part message in MIME format. ------=_NextPart_000_0004_01BEC86E.BD36DE40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Once u write your program how do u run it and what does it run on, do u = have to buy python b/c i dont know if it works b/c i downloaded it from = this websit and it is called Python 1.5.2. peace, Tyler ------=_NextPart_000_0004_01BEC86E.BD36DE40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Once u write your program how do u run it and what = does it run=20 on, do u have to buy python b/c i dont know if it works b/c i downloaded = it from=20 this websit and it is called Python 1.5.2.
 
          &nbs= p;            = ;            =             &= nbsp;       =20 peace,
          &nbs= p;            = ;            =             &= nbsp;       =20 Tyler
------=_NextPart_000_0004_01BEC86E.BD36DE40-- From a.mueller@icrf.icnet.uk Wed Jul 7 19:15:24 1999 From: a.mueller@icrf.icnet.uk (Arne Mueller) Date: Wed, 07 Jul 1999 19:15:24 +0100 Subject: [Tutor] stupid question allowed ;-) ? Message-ID: <3783993C.3B189654@icrf.icnet.uk> Hi All, I now stupid question are allowed in this group - so I don't hesitate to ask ... I'm using the cPickle module to store a large set of objects in binary format into a file. All that happens on an SGI R10000 machine (64 bit). I transfered the pickled object to my 32 bit linux box unpickled it and got the values I expected ;-) . Sometimes live is easy ... . However, does that mean the numbers in python (e.g. integers) are not different on these machines, there's the same maximum integer for 64 and 32 bit platforms? How does the binary storing and loading work, is the 64 bit integer truncated to 32 bit? Is it python specific or an os specific behaviour? In a C program all that could be different, can it? Hm, maybe you've some ideas about all that. For me it's realy fine, so I can do all the nasty calculations on the big SGI and the nice bit at home on a tiny little laptop (thanks to all pickles!). greetings, Arne From deirdre@deirdre.net Wed Jul 7 10:09:37 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 7 Jul 1999 02:09:37 -0700 (PDT) Subject: [Tutor] San Francisco Python Group: BayPIGgies In-Reply-To: Message-ID: On Wed, 19 May 1999, Deirdre Saoirse wrote: > Sorry for the short notice, but we just decided to do this yesterday. :) Wow, this JUST got into my inbox. Talk about lag! Those of you in the bay area will be happy to know that we now have a domain: baypiggies.org. I should have the web site up today, but it probably will take 2-3 days for it to propagate everywhere. We will be meeting on the 3rd wednesdays as we found twice a month was too ambitious for our social calendars. :) -- _Deirdre * http://www.linuxcabal.org * http://www.deirdre.net "I have a simple rule in life: If I don't understand something, it must be bad." & "If you want more than 4 gig of memory, get a *real* CPU." -- Linus Torvalds, speaking at BALUG (www.balug.org) From stalnaker@acm.org Thu Jul 8 20:13:24 1999 From: stalnaker@acm.org (Max M. Stalnaker) Date: Thu, 08 Jul 1999 12:13:24 -0700 Subject: [Tutor] RE: How to References: <199907080614.CAA28561@python.org> Message-ID: <3784F854.4E6419C4@acm.org> If you execute python1-5.2.exe, you get an install process. This installs python. Once you get it installed, type python myprogram.py. If all your environment variables and paths are set, you should get a positive result. The 1.5.2 is the current version number of python, which is in continual development. You do not have to buy anything. It runs on a lot of platforms. If you are on ms windows, you also have to install winall.exe which installs a lot of stuff so it work well with windows. From deirdre@deirdre.net Thu Jul 8 10:42:54 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 8 Jul 1999 02:42:54 -0700 (PDT) Subject: [Tutor] Guido to speak at BayPIGgies Message-ID: Due to a fortuitous delay of email about the first BayPIGgies meeting, Guido van Rossum noticed that he'd be in town for our next meeting. :) As a result, he's agreed to do a Q-and-A session about Python. Where: LinuxCabal (probably spilling over into the coffeenet), San Francisco CA. See http//www.baypiggies.org for details When: July 21, 8 pm. If you're in the area for that or our August meeting (halfway in between LinuxWorldExpo and the O'Reilly Python conference), we'd love to have you there. -- _Deirdre * http://www.linuxcabal.org * http://www.deirdre.net "I have a simple rule in life: If I don't understand something, it must be bad." & "If you want more than 4 gig of memory, get a *real* CPU." -- Linus Torvalds, speaking at BALUG (www.balug.org) From gerrit.sere@lin.vlaanderen.be Fri Jul 9 08:31:29 1999 From: gerrit.sere@lin.vlaanderen.be (=?iso-8859-1?Q?Ser=E9?= Gerrit) Date: Fri, 09 Jul 1999 09:31:29 +0200 Subject: [Tutor] Is this the way Message-ID: <3785A551.7077B56C@lin.vlaanderen.be> This is a multi-part message in MIME format. --------------70FECA572E9A03DBE01E7939 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Like most of you, I'm very new to Python. A few weeks ago I bought the book "Learning Python". Now I wrote a little program "Network monitor" (350 lines). I took some code from Mike Kershaw(thank you Mike) The program works with Tkinter and threads. After some time the program check some servers in a network if they are still a live (with ping). Is somebody wants to look at the code? With all those classes I'm not sure if this is the way of doing. Classes are new and difficult to me. Is there a place where you can look how to work the right way with classes ? Examples, technical information ... Regards, Yerry --------------70FECA572E9A03DBE01E7939 Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Gerrit seré Content-Disposition: attachment; filename="vcard.vcf" begin: vcard fn: Gerrit seré n: seré;Gerrit org: test email;internet: gerrit.sere@lin.vlaanderen.be x-mozilla-cpt: ;0 x-mozilla-html: FALSE version: 2.1 end: vcard --------------70FECA572E9A03DBE01E7939-- From vlad@redline.ru Tue Jul 13 11:16:09 1999 From: vlad@redline.ru (Vladimir Nevzorov) Date: Tue, 13 Jul 1999 14:16:09 +0400 (MSD) Subject: [Tutor] question Message-ID: Hello! Is python module for Postgres database existing? If yes, where can I find it? Thanks! Best regards, Vladimir Nevzorov, Redline tech.dept. vlad@redline.ru, (7-095) 291-6132 From kjhagen@mmm.com Thu Jul 15 16:00:18 1999 From: kjhagen@mmm.com (kjhagen@mmm.com) Date: Thu, 15 Jul 1999 10:00:18 -0500 Subject: [Tutor] Just getting started in Python Message-ID: <862567AF.00518818.00@em-stpmta-01.mmm.com> I verified that the interpreter works by doing the following: >>> 12*12 144 >>> import string >>> string.split ("hello world") ['hello', 'world'] >>> This all works fine in both the python shell and command line windows. I start working my way though the "Learning Python" book and when asked to run a module file on page 13, I get the following error message at the NT command prompt line. "The name specified is not recongnized as an internal or external command, operable program or batch file" I typed my "spam.py" file in as follows, using WordPad. I saved the file "spam.py" as a text file. import sys print sys.argv Why am I not able to get this simple progam to run at the "C:\misc\book" prompt in NT4.0? Thanks, Ken Hagen kjhagen@mmm.com From ivanlan@callware.com Thu Jul 15 16:15:10 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Thu, 15 Jul 1999 09:15:10 -0600 Subject: [Tutor] Just getting started in Python References: <862567AF.00518818.00@em-stpmta-01.mmm.com> Message-ID: <378DFAFE.3C36895F@callware.com> Hi All-- kjhagen@mmm.com wrote: > > I verified that the interpreter works by doing the following: > > >>> 12*12 > 144 > >>> import string > >>> string.split ("hello world") > ['hello', 'world'] > >>> > > This all works fine in both the python shell and command line windows. I > start working my way though the "Learning Python" book and when asked to > run a module file on page 13, I get the following error message at the NT > command prompt line. > > "The name specified is not recongnized as an internal or external command, > operable program or batch file" > > I typed my "spam.py" file in as follows, using WordPad. I saved the file > "spam.py" as a text file. > > import sys > print sys.argv > > Why am I not able to get this simple progam to run at the "C:\misc\book" > prompt in NT4.0? > The short answer is that NT and Windows are stupid. The slightly longer answer is that you must, on Win$, type 'python spam.py' and hit return. That will get you by until you find time for one of the longer answers. The much longer answer is that you have to make NT aware of the association between the .py suffix and the python.exe file, and even after that you have to jump through some hoops. Another short answer is to install pythonwin, which will make the file associations for you. -ly y'rs, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 ---------------------------------------------- From phil@philh.org Thu Jul 15 16:40:03 1999 From: phil@philh.org (Phil Harris) Date: Thu, 15 Jul 1999 16:40:03 +0100 Subject: [Tutor] Just getting started in Python References: <862567AF.00518818.00@em-stpmta-01.mmm.com> <378DFAFE.3C36895F@callware.com> Message-ID: <005c01beced8$4e910fe0$5c773fc1@media1> No hoops; Just go to a command line and type: assoc .py 'path to your python interpreter' Simple HTH Phil phil@philh.org ----- Original Message ----- From: Ivan Van Laningham To: Sent: Thursday, July 15, 1999 4:15 PM Subject: Re: [Tutor] Just getting started in Python > Hi All-- > > kjhagen@mmm.com wrote: > > > > I verified that the interpreter works by doing the following: > > > > >>> 12*12 > > 144 > > >>> import string > > >>> string.split ("hello world") > > ['hello', 'world'] > > >>> > > > > This all works fine in both the python shell and command line windows. I > > start working my way though the "Learning Python" book and when asked to > > run a module file on page 13, I get the following error message at the NT > > command prompt line. > > > > "The name specified is not recongnized as an internal or external command, > > operable program or batch file" > > > > I typed my "spam.py" file in as follows, using WordPad. I saved the file > > "spam.py" as a text file. > > > > import sys > > print sys.argv > > > > Why am I not able to get this simple progam to run at the "C:\misc\book" > > prompt in NT4.0? > > > > The short answer is that NT and Windows are stupid. The slightly longer > answer is that you must, on Win$, type 'python spam.py' and hit return. > That will get you by until you find time for one of the longer answers. > > The much longer answer is that you have to make NT aware of the > association between the .py suffix and the python.exe file, and even > after that you have to jump through some hoops. > > Another short answer is to install pythonwin, which will make the file > associations for you. > > -ly y'rs, > Ivan > ---------------------------------------------- > Ivan Van Laningham > Callware Technologies, Inc. > ivanlan@callware.com > ivanlan@home.com > http://www.pauahtun.org > See also: > http://www.foretec.com/python/workshops/1998-11/proceedings.html > Army Signal Corps: Cu Chi, Class of '70 > ---------------------------------------------- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor From spiderman@nasachem.com Fri Jul 16 00:13:45 1999 From: spiderman@nasachem.com (R Parker) Date: Thu, 15 Jul 1999 18:13:45 -0500 Subject: [Tutor] Dumb question Message-ID: <378E6B29.E3231720@ghg.net> I was wondering How do you make EXE files in python??? From stalnaker@acm.org Fri Jul 16 06:29:19 1999 From: stalnaker@acm.org (Max M. Stalnaker) Date: Thu, 15 Jul 1999 22:29:19 -0700 Subject: [Tutor] Re: Dumb question References: <199907160506.BAA07750@python.org> Message-ID: <378EC32F.D7517800@acm.org> > Subject: [Tutor] Dumb question > Date: Thu, 15 Jul 1999 18:13:45 -0500 > From: R Parker > To: tutor@python.org > > I was wondering How do you make EXE files in python??? You need the source, a c compiler, and a tool set that comes with source, called freeze. Download the source and look in tools/freeze and look at the doc, including the html. There is said to be NO significant performance advantage. There are a number of disadvantages, especially on win platforms. On win, expect that getting your program into a single executable for transfer to another computer will be a significant task. But see the cgipython project. > > > ------------------------------------------------------------------------ > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor -- Max M. Stalnaker stalnaker@acm.org Astar Computer Consulting: Networking and Custom Accounting Software From MANOR73537@aol.com Sun Jul 18 06:50:40 1999 From: MANOR73537@aol.com (MANOR73537@aol.com) Date: Sun, 18 Jul 1999 01:50:40 EDT Subject: [Tutor] how do i write a simple telnet client? Message-ID: how do i write a simple telnet client? i have tried import telnetlib open(grex.cyberspace.org and read_very_eager(grex.cyberspace.org From rmasse@cnri.reston.va.us (Roger E. Masse) Mon Jul 19 16:27:28 1999 From: rmasse@cnri.reston.va.us (Roger E. Masse) (Roger Masse) Date: Mon, 19 Jul 1999 11:27:28 -0400 (EDT) Subject: [Tutor] I want to learn to hack Message-ID: <14227.17376.361340.434400@nobot.cnri.reston.va.us> From tlovett@juno.com Mon Jul 19 17:38:15 1999 From: tlovett@juno.com (William H Lovett) Date: Mon, 19 Jul 1999 11:38:15 -0500 Subject: [Tutor] Other languages for learning to program with Python Message-ID: <19990719.113815.-287561.1.TLovett@juno.com> I' m interested in programming in Python, but am extremely new (only programmed in Basic and QBasic in High School -not very heavily, either). There are several colleges in my area that teach classes, but always in other languages, like VB, C++, and Cobol. I have bought both O'Reilly programming books, but would like to know an experienced programmers opinion: Should I just try to learn on my own from the books, or resort to learning something like C before Python, to get an understanding of programming basics again? My ultimate goal is to make a little statistical analysis package for my field. From ivanlan@callware.com Mon Jul 19 17:16:14 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Mon, 19 Jul 1999 10:16:14 -0600 Subject: [Tutor] Other languages for learning to program with Python References: <19990719.113815.-287561.1.TLovett@juno.com> Message-ID: <37934F4E.8CF86322@callware.com> Hi All-- William H Lovett wrote: > > I' m interested in programming in Python, but am extremely new (only > programmed in Basic and QBasic in High School -not very heavily, either). > There are several colleges in my area that teach classes, but always in > other languages, like VB, C++, and Cobol. I have bought both O'Reilly > programming books, but would like to know an experienced programmers > opinion: Should I just try to learn on my own from the books, or resort > to learning something like C before Python, to get an understanding of > programming basics again? My ultimate goal is to make a little > statistical analysis package for my field. > By all means, learn Python first. Many on this list, as well as the main list, feel that Python is the ideal first language; I think that the major problem with learning Python first is that when you are required to learn C or C++ later on, you will be so spoiled by Python that you will be resistant to learning the baroque ins and outs of C++, and you will be unhappy with the clumsiness of C (although you should be satisfied with its power). Since you have some programming experience, then I think the place to start is _Learning Python_; the authors' style is chatty, witty and informal, not unlike the main newsgroup/mailing list. You should be warned, however, that coming to a Python list and asking if Python is a good first language is a little like going to the head of the Slavic Languages department and asking if you should learn Russian or Swahili, as both could be useful in your chosen field. Guess which answer you're going to get? ;-) (I actually did that, BTW) Blatant Self-Promotion (BSP): if you're not in a hurry, you could wait for _Teach Yourself Python in 24 Hours_, forthcoming from SAMS, written by yours truly. Possibly this year. -ly y'rs, Ivan;-) ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 ---------------------------------------------- From deirdre@deirdre.net Mon Jul 19 17:52:13 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 19 Jul 1999 09:52:13 -0700 (PDT) Subject: [Tutor] Other languages for learning to program with Python In-Reply-To: <19990719.113815.-287561.1.TLovett@juno.com> Message-ID: On Mon, 19 Jul 1999, William H Lovett wrote: > other languages, like VB, C++, and Cobol. I have bought both O'Reilly > programming books, but would like to know an experienced programmers > opinion: Should I just try to learn on my own from the books, or > resort to learning something like C before Python, to get an > understanding of programming basics again? My ultimate goal is to > make a little statistical analysis package for my field. I think you'll be a LOT less frustrated if you start it in Python. If you want to take classes, I'd recommend taking classes in C/C++. But it'll only highlight how much easier Python is. :) -- _Deirdre * http://www.linuxcabal.org * http://www.deirdre.net "I have a simple rule in life: If I don't understand something, it must be bad." & "If you want more than 4 gig of memory, get a *real* CPU." -- Linus Torvalds, speaking at BALUG (www.balug.org) From tim_one@email.msn.com Tue Jul 20 07:31:55 1999 From: tim_one@email.msn.com (Tim Peters) Date: Tue, 20 Jul 1999 02:31:55 -0400 Subject: [Tutor] I want to learn to hack In-Reply-To: <14227.17376.361340.434400@nobot.cnri.reston.va.us> Message-ID: <001501bed279$8fc0b700$139e2299@tim> So, little Roger, you want to learn how to hack? You came to the right place! First walk down the hall and pick up a copy of Python from Guido. He'll have you cracking bank accounts in no time . the-psa-is-the-richest-organization-on-earth-ly y'rs - tim From jwiscav@hotmail.com Thu Jul 22 16:16:08 1999 From: jwiscav@hotmail.com (Joshua Wiscaver) Date: Thu, 22 Jul 1999 15:16:08 GMT Subject: [Tutor] (no subject) Message-ID: <19990722151608.76937.qmail@hotmail.com> Hello, I am completely new to Python, so please bear with me. My question is this: Whenever I try to run one of the .py files that came with the program, it runs then immediately the window closes. I looked for the "Close window on exit" box, but found none. Can you tell me how to keep the window from closing after teh program runs? If I can't see the output, then there is no reason to even try to learn. ~PEACE~ Joshua _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com From jwiscav@hotmail.com Thu Jul 22 16:16:39 1999 From: jwiscav@hotmail.com (Joshua Wiscaver) Date: Thu, 22 Jul 1999 15:16:39 GMT Subject: [Tutor] PIF Message-ID: <19990722151639.3040.qmail@hotmail.com> Hello, I am completely new to Python, so please bear with me. My question is this: Whenever I try to run one of the .py files that came with the program, it runs then immediately the window closes. I looked for the "Close window on exit" box, but found none. Can you tell me how to keep the window from closing after the program runs? If I can't see the output, then there is no reason to even try to learn. ~PEACE~ Joshua _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com From 010.Werkstudent@MCHF.SIEMENS.DE Thu Jul 22 20:25:49 1999 From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010) Date: Thu, 22 Jul 1999 21:25:49 +0200 Subject: AW: [Tutor] PIF Message-ID: <809AE76DB183D111BE1300005A40E070CA5403@mail.mchf.siemens.de> Hail Monty, who art a heathen, you´re right! many files go pffffft! Do a grep on files that have a "main". Try them. Many of the other files are not applications, but more like utilties. Otherwise, write a wrapper that imports the files you want to look at, and then does a sleep(100). This snooze is still no assurance that you´ve generated GUI output. $PEACE$ and good luck David Ungemach -----Ursprüngliche Nachricht----- Von: Joshua Wiscaver [mailto:jwiscav@hotmail.com] Gesendet am: Donnerstag, 22. Juli 1999 17:17 An: tutor@python.org Betreff: [Tutor] PIF Hello, I am completely new to Python, so please bear with me. My question is this: Whenever I try to run one of the .py files that came with the program, it runs then immediately the window closes. I looked for the "Close window on exit" box, but found none. Can you tell me how to keep the window from closing after the program runs? If I can't see the output, then there is no reason to even try to learn. ~PEACE~ Joshua _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor From andyquake@hotmail.com Thu Jul 22 22:30:56 1999 From: andyquake@hotmail.com (Andy Quake) Date: Thu, 22 Jul 1999 16:30:56 CDT Subject: [Tutor] (no subject) Message-ID: <19990722213057.6207.qmail@hotmail.com> can you please send me a tutorial that defines all the terms...like strings and stuff cause i don't know what all these terms mean and it's very confusing to me. _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com From deirdre@deirdre.net Thu Jul 22 22:42:33 1999 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 22 Jul 1999 14:42:33 -0700 (PDT) Subject: [Tutor] PIF In-Reply-To: <19990722151639.3040.qmail@hotmail.com> Message-ID: On Thu, 22 Jul 1999, Joshua Wiscaver wrote: > I am completely new to Python, so please bear with me. My question is this: > Whenever I try to run one of the .py files that came with the program, it > runs then immediately the window closes. I looked for the "Close window on > exit" box, but found none. Can you tell me how to keep the window from > closing after the program runs? If I can't see the output, then there is no > reason to even try to learn. What OS are you using? How are you invoking the code? -- _Deirdre * http://www.linuxcabal.net * http://www.deirdre.net Indeed, when I design my killer language, the identifiers "foo" and "bar" will be reserved words, never used, and not even mentioned in the reference manual. Any program using one will simply dump core without comment. Multitudes will rejoice. -- Tim Peters From ivanlan@callware.com Thu Jul 22 22:55:17 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Thu, 22 Jul 1999 15:55:17 -0600 Subject: [Tutor] (no subject) References: <19990722213057.6207.qmail@hotmail.com> Message-ID: <37979345.4D2D3E44@callware.com> Hi All-- Andy Quake wrote: > > can you please send me a tutorial that defines all the terms...like strings > and stuff cause i don't know what all these terms mean and it's very > confusing to me. > Andy, if you managed to find the tutor mailing list, you must have gone to www.python.org, where there is a wealth of documentation, including a tutorial, about Python. If you really need a basic, rock-bottom intro to programming, not just Python, then you have two choices: a) Wait for _Teach Yourself Python in 24 Hours_, possibly out at the end of this year; b) Go to http://www.amazon.com and buy _Teach Yourself Beginning Programming in 24 Hours_. Good luck, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 ---------------------------------------------- From fractalyze@iname.com Sat Jul 24 07:02:31 1999 From: fractalyze@iname.com (fractalyze@iname.com) Date: Sat, 24 Jul 1999 00:02:31 -0600 Subject: [Tutor] PIF Message-ID: <199907240605.BAA07760@hortus.ots.ac.cr> hey there josh - i had the same problem. if you are running python on win9x or something similar, you may want to try one of the following: a) open up a dos prompt b) at the dos prompt, type (without the quotes): "python the-py- file-you-want-to-run" when you do this, the error messages stay in the dos shell after python closes. i have made a win95(x?) file extension/association that does the same thing...check out my message at: http://x43.deja.com/[ST_rn=ps]/getdoc.xp?AN=503531232.1&CON TEXT=932745 826.1292763289&hitnum=0 (i'm not sure that link is going to work) if it doesn't, try this: go to http://www.deja.com go to power search search for: Subject: extension Author: Isidor Forum: comp.lang.python NOTE TO ANYONE ELSE READING THIS: i tried finding my message in the python-list "archives" at the python site, but it wasn't there. in fact, there are several (lots?) of messages missing from the archive. anyone know why? QUESTION: i have several newbie-related posts (i am a newbie) that i sent to comp.lang.python (tips/tools, not questions). is it ok/advisable/reasonable to cross-post them here? (E.g., reposting the message about win95(9x/NT?) file extensions/associations.) i hope that helps! take care isidor From jcosby@wolfenet.com Sun Jul 25 21:15:31 1999 From: jcosby@wolfenet.com (Jon Cosby) Date: Sun, 25 Jul 1999 13:15:31 -0700 Subject: [Tutor] Hex strings Message-ID: <000501bed6da$9595f540$781c9fce@wolfenet.com> How do you go about manipulating these hexadecimal strings, for example, adding two numbers base 16? Jon Cosby E-mail: jcosby@wolfenet.com Web Site: http://www.wolfenet.com/~jcosby/ From ivanlan@callware.com Sun Jul 25 21:27:17 1999 From: ivanlan@callware.com (Ivan Van Laningham) Date: Sun, 25 Jul 1999 14:27:17 -0600 Subject: [Tutor] Hex strings References: <000501bed6da$9595f540$781c9fce@wolfenet.com> Message-ID: <379B7325.9ECEB210@callware.com> Hi All-- Jon Cosby wrote: > > How do you go about manipulating these hexadecimal strings, for example, > adding two numbers base 16? > n = string.atoi("0xFFFF",16) n = n + 0xFFFF print n The optional second argument to string.atoi() is the base from which you wish to convert. Once strings are converted to integers, they're just computer numbers; you only have to worry about the radix (base) when you want to read them in or print them out. By default, atoi() and print assume you want to read and see them in decimal. -ly y'rs, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan@callware.com ivanlan@home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 ---------------------------------------------- From Emile van Sebille" Message-ID: <018301bed6df$f735c5a0$01ffffc0@direcpc.com> Hi Jon, >>> c = 0x20 >>> d = 0x30 >>> c+d 80 >>> '%0x' % (c+d) '50' Emile van Sebille emile@fenx.com ------------------- ----- Original Message ----- From: Jon Cosby To: Python Tutor Sent: Sunday, July 25, 1999 1:15 PM Subject: [Tutor] Hex strings > How do you go about manipulating these hexadecimal strings, for example, > adding two numbers base 16? > > Jon Cosby > > E-mail: jcosby@wolfenet.com > Web Site: http://www.wolfenet.com/~jcosby/ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > > > From Emile van Sebille" Message-ID: <018301bed6df$f735c5a0$01ffffc0@direcpc.com> Hi Jon, >>> c = 0x20 >>> d = 0x30 >>> c+d 80 >>> '%0x' % (c+d) '50' Emile van Sebille emile@fenx.com ------------------- ----- Original Message ----- From: Jon Cosby To: Python Tutor Sent: Sunday, July 25, 1999 1:15 PM Subject: [Tutor] Hex strings > How do you go about manipulating these hexadecimal strings, for example, > adding two numbers base 16? > > Jon Cosby > > E-mail: jcosby@wolfenet.com > Web Site: http://www.wolfenet.com/~jcosby/ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > > > From jwiscav@hotmail.com Mon Jul 26 01:59:26 1999 From: jwiscav@hotmail.com (Joshua Wiscaver) Date: Mon, 26 Jul 1999 00:59:26 GMT Subject: [Tutor] Re: Tutor digest, Vol 1 #85 - 1 msg Message-ID: <19990726005927.34028.qmail@hotmail.com> isidor, thanks for responding... After thinking about this a little more, i realised that python should allow you to edit a .py file straight from the console. So, I simply did an edit filename.py and saw the code. Of course, I still haven't been able to see the output, but i wll try your suggestion. thanks... joshua ----Original Message Follows---- From: tutor-admin@python.org Reply-To: tutor@python.org To: tutor@python.org Subject: Tutor digest, Vol 1 #85 - 1 msg Date: Sun, 25 Jul 1999 01:02:19 -0400 (EDT) MIME-Version: 1.0 From alan.gauld@bt.com Mon Jul 26 11:27:16 1999 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 26 Jul 1999 11:27:16 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E0A80@mbtlipnt02.btlabs.bt.co.uk> > can you please send me a tutorial that defines all the > terms...like strings > and stuff cause i don't know what all these terms mean and it's very > confusing to me. Take a look at the 2 'Python for non programmer' tutorials under documentation at the python web site. http://www.python.org/doc/Intros.html If that's still not enough then look at my (in progress) 'Programming for beginners' tutorial which uses Pytthon, Tcl and BASIC. It goes into more detail on the terminology than either of the other 2. Specifically the Data page might help you. http://members.xoom.com/alan_gauld/tutor/tutindex.htm Alan G. From chris@frostnet.advicom.net Mon Jul 26 15:34:13 1999 From: chris@frostnet.advicom.net (Chris Frost) Date: Mon, 26 Jul 1999 09:34:13 -0500 Subject: [Tutor] Getting current path Message-ID: <19990726093413.C5334@pooh.frostnet.net> --2/5bycvrmDh4d1IB Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable How can you find the current directory you are presently in? I'd like to output to whatever directory a program is called from, and then load it back reason being. thanks! --=20 Chris Frost | -------------+------------------------------------------ Public PGP Key: Email chris@frostnet.advicom.net with the subject "retrieve pgp key" or visit --2/5bycvrmDh4d1IB Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use MessageID: cmhcn2QRojoxlxcbk6WVRDievvZrxSss iQA/AwUBN5xj0+EzIlbKpewXEQIHTgCg/fP7/rWyr6lmRusIJygNNscv6X0An1e1 9KntB39xm+PKk3Ar2N5ilNIG =+GIx -----END PGP SIGNATURE----- --2/5bycvrmDh4d1IB-- From ajs@ix.netcom.com Mon Jul 26 16:02:32 1999 From: ajs@ix.netcom.com (Art Siegel) Date: Mon, 26 Jul 1999 11:02:32 -0400 Subject: [Tutor] Re: Inheritance and *args and **kw Message-ID: <001f01bed777$e49e1d00$cb0101c0@seigel.eico.com> I create a class with only *args constructors which are handled in the class' def __init__. I inherit from the class and try to add **kw args in the sub-classes def __init__. But in creating an instance of the the sub-class the kw dictionary is now an element of a tuple passed as a single argument, rather than a tuple of *args and a dictionary of *kw. I think the above is probably inconherent. If anybody can see what I am driving at, help is appreciated. I will try to follow up with a snippet to clarify my issue From chris@frostnet.advicom.net Mon Jul 26 16:10:29 1999 From: chris@frostnet.advicom.net (Chris Frost) Date: Mon, 26 Jul 1999 10:10:29 -0500 Subject: [Tutor] Getting current path In-Reply-To: <027101bed777$bea33680$01ffffc0@direcpc.com>; from Emile van Sebille on Mon, Jul 26, 1999 at 08:01:30AM -0700 References: <19990726093413.C5334@pooh.frostnet.net> <027101bed777$bea33680$01ffffc0@direcpc.com> Message-ID: <19990726101029.A5832@pooh.frostnet.net> --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable On Mon, Jul 26, 1999 at 08:01:30AM -0700, Emile van Sebille wrote: > Hi Chris, >=20 > >>> import os > >>> os.getcwd() > 'D:\\Program Files\\Python\\Tools\\idle' >=20 > HTH Yes, thanks! How could I tell if the user simply entered a filename, or if they gave the entire path (assuming unix if that helps)? thanks again, --=20 Chris Frost | -------------+------------------------------------------ Public PGP Key: Email chris@frostnet.advicom.net with the subject "retrieve pgp key" or visit --LQksG6bCIzRHxTLp Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use MessageID: EAj7Vkdi3hAwVZx4b2UkfWbAJ2PH4gFX iQA/AwUBN5xsVOEzIlbKpewXEQLNYQCfZpiylyjpDG7quQQd6fr9/ftTL70AoJ0C HnSe0hL6RqLTz/j0hlN/Y2fg =puey -----END PGP SIGNATURE----- --LQksG6bCIzRHxTLp-- From ajs@ix.netcom.com Mon Jul 26 17:16:18 1999 From: ajs@ix.netcom.com (Art Siegel) Date: Mon, 26 Jul 1999 12:16:18 -0400 Subject: [Tutor] Inheritance and *args Message-ID: <000d01bed782$331cd340$9377fea9@seigel.eico.com> This is a multi-part message in MIME format. ------=_NextPart_000_000A_01BED760.AA2D99A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable class Position: def __init__(self, *args): if args: self.x=3Dargs[0] self.y=3Dargs[1] self.z=3Dargs[2] print self.x,self.y,self.z class Point(Position): def __init__(self,*args): Position.__init__(self,args) Point(1,2,3) Result: Traceback (innermost last): ... self.y=3Dargs[1] IndexError: tuple index out of range Apparently because the arguments to Point(1,2,3) is read in as a single = element tuple, whose single element is the 3 element tuple (1,2,3). Whereas Position(1,2,3) is processed as a three element tuple, with = elements 1,2,3. Is there a straightforward approach to accomplish above inheritance?? ------=_NextPart_000_000A_01BED760.AA2D99A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
class Position:
 def = __init__(self,=20 *args):
  if args:
   = self.x=3Dargs[0]
  =20 self.y=3Dargs[1]
   self.z=3Dargs[2]
  print=20 self.x,self.y,self.z
 
class Point(Position):
 def=20 __init__(self,*args):
  = Position.__init__(self,args)
Point(1,2,3)
 
Result:

Traceback (innermost = last):
     =20 ...
    self.y=3Dargs[1]
IndexError: tuple index = out of=20 range
Apparently because the arguments to = Point(1,2,3)=20 is read in as a single element tuple, whose single element is the 3 = element=20 tuple (1,2,3).
 
Whereas Position(1,2,3) is processed as a three = element tuple,=20 with elements 1,2,3.
 
Is there a straightforward approach to accomplish = above=20 inheritance??
 
------=_NextPart_000_000A_01BED760.AA2D99A0-- From steve@acer.spvi.com Mon Jul 26 18:22:05 1999 From: steve@acer.spvi.com (Steve Spicklemire) Date: Mon, 26 Jul 1999 12:22:05 -0500 (EST) Subject: [Tutor] Inheritance and *args In-Reply-To: <000d01bed782$331cd340$9377fea9@seigel.eico.com> (ajs@ix.netcom.com) Message-ID: <199907261722.MAA29534@acer.spvi.com> Art, Try this: ---------------------------------------------------------------------- class Position: def __init__(self, *args): if args: self.x=args[0] self.y=args[1] self.z=args[2] print self.x,self.y,self.z class Point(Position): def __init__(self,*args): apply(Position.__init__,([self] + list(args))) Point(1,2,3) ---------------------------------------------------------------------- -steve From joe@strout.net Mon Jul 26 18:24:13 1999 From: joe@strout.net (Joseph J. Strout) Date: Mon, 26 Jul 1999 10:24:13 -0700 Subject: [Tutor] Inheritance and *args In-Reply-To: <000d01bed782$331cd340$9377fea9@seigel.eico.com> Message-ID: --============_-1279112630==_ma============ Content-Type: text/plain; charset="us-ascii" At 9:16 AM -0700 07/26/99, Art Siegel wrote: > self.y=args[1] >IndexError: tuple index out of range >Apparently because the arguments to Point(1,2,3) is read in as a single >element tuple, whose single element is the 3 element tuple (1,2,3). Yep. >Whereas Position(1,2,3) is processed as a three element tuple, with >elements 1,2,3. Yep again. >Is there a straightforward approach to accomplish above inheritance?? Yep^3. Well, reasonably straightforward -- slightly complicated by having an additional parameter ('self'): apply(Position.__init__, (self,) + args) In cases where you have a list or tuple of arguments, but you need to pass them to a function as separate arguments rather than a single object, you use 'apply'. Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' --============_-1279112630==_ma============ Content-Type: text/enriched; charset="us-ascii" At 9:16 AM -0700 07/26/99, Art Siegel wrote: self.y=args[1] IndexError: tuple index out of range Apparently because the arguments to Point(1,2,3) is read in as a single element tuple, whose single element is the 3 element tuple (1,2,3). Yep. Whereas Position(1,2,3) is processed as a three element tuple, with elements 1,2,3. Yep again. Is there a straightforward approach to accomplish above inheritance?? Yep^3. Well, reasonably straightforward -- slightly complicated by having an additional parameter ('self'): apply(Position.__init__, (self,) + args) In cases where you have a list or tuple of arguments, but you need to pass them to a function as separate arguments rather than a single object, you use 'apply'. Cheers, -- Joe ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------' --============_-1279112630==_ma============-- From b4705021@im.ntu.edu.tw Tue Jul 27 09:08:22 1999 From: b4705021@im.ntu.edu.tw (Daniel Gau) Date: Tue, 27 Jul 1999 16:08:22 +0800 (CST) Subject: [Tutor] Re: Tutor digest, Vol 1 #87 - 7 msgs In-Reply-To: <199907270506.BAA01322@python.org> Message-ID: On Tue, 27 Jul 1999 tutor-admin@python.org wrote: > > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the web, visit > http://www.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-request@python.org > You can reach the person managing the list at > tutor-admin@python.org > > When replying, please edit your Subject line so it is more specific than > "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. RE: (no subject) (alan.gauld@bt.com) > 2. Getting current path (Chris Frost) > 3. Re: Inheritance and *args and **kw (Art Siegel) > 4. Re: Getting current path (Chris Frost) > 5. Inheritance and *args (Art Siegel) > 6. Re: Inheritance and *args (Steve Spicklemire) > 7. Re: Inheritance and *args (Joseph J. Strout) > > --__--__-- > > Message: 1 > From: alan.gauld@bt.com > To: andyquake@hotmail.com, tutor@python.org > Subject: RE: [Tutor] (no subject) > Date: Mon, 26 Jul 1999 11:27:16 +0100 > > > can you please send me a tutorial that defines all the > > terms...like strings > > and stuff cause i don't know what all these terms mean and it's very > > confusing to me. > > Take a look at the 2 'Python for non programmer' tutorials under > documentation at the python web site. > > http://www.python.org/doc/Intros.html > > If that's still not enough then look at my (in progress) > 'Programming for beginners' tutorial which uses Pytthon, > Tcl and BASIC. It goes into more detail on the terminology > than either of the other 2. > > Specifically the Data page might help you. > > http://members.xoom.com/alan_gauld/tutor/tutindex.htm > > Alan G. > > --__--__-- > > Message: 2 > Date: Mon, 26 Jul 1999 09:34:13 -0500 > From: Chris Frost > To: tutor@python.org > protocol="application/pgp-signature" > Subject: [Tutor] Getting current path > > > --2/5bycvrmDh4d1IB > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: quoted-printable > > How can you find the current directory you are presently in? I'd like to > output to whatever directory a program is called from, and then load it > back reason being. > > thanks! > --=20 > Chris Frost | > -------------+------------------------------------------ > Public PGP Key: > Email chris@frostnet.advicom.net with the subject "retrieve pgp key" > or visit > > --2/5bycvrmDh4d1IB > Content-Type: application/pgp-signature > > -----BEGIN PGP SIGNATURE----- > Version: PGPfreeware 5.0i for non-commercial use > MessageID: cmhcn2QRojoxlxcbk6WVRDievvZrxSss > > iQA/AwUBN5xj0+EzIlbKpewXEQIHTgCg/fP7/rWyr6lmRusIJygNNscv6X0An1e1 > 9KntB39xm+PKk3Ar2N5ilNIG > =+GIx > -----END PGP SIGNATURE----- > > --2/5bycvrmDh4d1IB-- > > --__--__-- > > Message: 3 > From: "Art Siegel" > To: "Python Tutor" > Date: Mon, 26 Jul 1999 11:02:32 -0400 > charset="iso-8859-1" > Subject: [Tutor] Re: Inheritance and *args and **kw > > I create a class with only *args constructors which are handled in the > class' def __init__. > > I inherit from the class and try to add **kw args in the sub-classes def > __init__. > > But in creating an instance of the the sub-class the kw dictionary is now an > element of a tuple passed as a single argument, rather than a tuple of *args > and a dictionary of *kw. > > I think the above is probably inconherent. If anybody can see what I am > driving at, help is appreciated. > > I will try to follow up with a snippet to clarify my issue > > > > > > --__--__-- > > Message: 4 > Date: Mon, 26 Jul 1999 10:10:29 -0500 > From: Chris Frost > To: Emile van Sebille > Cc: tutor@python.org > Subject: Re: [Tutor] Getting current path > protocol="application/pgp-signature" > > > --LQksG6bCIzRHxTLp > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: quoted-printable > > On Mon, Jul 26, 1999 at 08:01:30AM -0700, Emile van Sebille wrote: > > Hi Chris, > >=20 > > >>> import os > > >>> os.getcwd() > > 'D:\\Program Files\\Python\\Tools\\idle' > >=20 > > HTH > Yes, thanks! > > How could I tell if the user simply entered a filename, or if they gave > the entire path (assuming unix if that helps)? > > thanks again, > --=20 > Chris Frost | > -------------+------------------------------------------ > Public PGP Key: > Email chris@frostnet.advicom.net with the subject "retrieve pgp key" > or visit > > --LQksG6bCIzRHxTLp > Content-Type: application/pgp-signature > > -----BEGIN PGP SIGNATURE----- > Version: PGPfreeware 5.0i for non-commercial use > MessageID: EAj7Vkdi3hAwVZx4b2UkfWbAJ2PH4gFX > > iQA/AwUBN5xsVOEzIlbKpewXEQLNYQCfZpiylyjpDG7quQQd6fr9/ftTL70AoJ0C > HnSe0hL6RqLTz/j0hlN/Y2fg > =puey > -----END PGP SIGNATURE----- > > --LQksG6bCIzRHxTLp-- > > --__--__-- > > Message: 5 > From: "Art Siegel" > To: "Python Tutor" > Date: Mon, 26 Jul 1999 12:16:18 -0400 > boundary="----=_NextPart_000_000A_01BED760.AA2D99A0" > Subject: [Tutor] Inheritance and *args > > This is a multi-part message in MIME format. > > ------=_NextPart_000_000A_01BED760.AA2D99A0 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > class Position: > def __init__(self, *args): > if args: > self.x=3Dargs[0] > self.y=3Dargs[1] > self.z=3Dargs[2] > print self.x,self.y,self.z > > class Point(Position): > def __init__(self,*args): > Position.__init__(self,args) > > Point(1,2,3) > > Result: > > Traceback (innermost last): > ... > self.y=3Dargs[1] > IndexError: tuple index out of range > > Apparently because the arguments to Point(1,2,3) is read in as a single = > element tuple, whose single element is the 3 element tuple (1,2,3). > > Whereas Position(1,2,3) is processed as a three element tuple, with = > elements 1,2,3. > > Is there a straightforward approach to accomplish above inheritance?? > > > ------=_NextPart_000_000A_01BED760.AA2D99A0 > Content-Type: text/html; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > > > > > http-equiv=3DContent-Type> > > > >
class Position:
 def = > __init__(self,=20 > *args):
  if args:
   = > self.x=3Dargs[0]
  =20 > self.y=3Dargs[1]
   self.z=3Dargs[2]
  print=20 > self.x,self.y,self.z
>
 
>
class Point(Position):
 def=20 > __init__(self,*args):
  = > Position.__init__(self,args)
>
Point(1,2,3)
>
 
>
Result:
>

Traceback (innermost = > last):
>
     =20 > ...
    self.y=3Dargs[1]
IndexError: tuple index = > out of=20 > range
>
Apparently because the arguments to = > Point(1,2,3)=20 > is read in as a single element tuple, whose single element is the 3 = > element=20 > tuple (1,2,3).
>
 
>
Whereas Position(1,2,3) is processed as a three = > element tuple,=20 > with elements 1,2,3.
>
 
>
Is there a straightforward approach to accomplish = > above=20 > inheritance??
>
 
> > ------=_NextPart_000_000A_01BED760.AA2D99A0-- > > > --__--__-- > > Message: 6 > Date: Mon, 26 Jul 1999 12:22:05 -0500 (EST) > From: Steve Spicklemire > To: ajs@ix.netcom.com > CC: tutor@python.org > (ajs@ix.netcom.com) > Subject: Re: [Tutor] Inheritance and *args > > > Art, > > Try this: > > ---------------------------------------------------------------------- > > class Position: > def __init__(self, *args): > if args: > self.x=args[0] > self.y=args[1] > self.z=args[2] > print self.x,self.y,self.z > > class Point(Position): > def __init__(self,*args): > apply(Position.__init__,([self] + list(args))) > > Point(1,2,3) > > ---------------------------------------------------------------------- > > -steve > > --__--__-- > > Message: 7 > Date: Mon, 26 Jul 1999 10:24:13 -0700 > To: "Art Siegel" , "Python Tutor" > From: "Joseph J. Strout" > Subject: Re: [Tutor] Inheritance and *args > > --============_-1279112630==_ma============ > Content-Type: text/plain; charset="us-ascii" > > At 9:16 AM -0700 07/26/99, Art Siegel wrote: > > > self.y=args[1] > >IndexError: tuple index out of range > >Apparently because the arguments to Point(1,2,3) is read in as a single > >element tuple, whose single element is the 3 element tuple (1,2,3). > > Yep. > > >Whereas Position(1,2,3) is processed as a three element tuple, with > >elements 1,2,3. > > Yep again. > > >Is there a straightforward approach to accomplish above inheritance?? > > Yep^3. Well, reasonably straightforward -- slightly complicated by having > an additional parameter ('self'): > > apply(Position.__init__, (self,) + args) > > In cases where you have a list or tuple of arguments, but you need to pass > them to a function as separate arguments rather than a single object, you > use 'apply'. > > Cheers, > -- Joe > ,------------------------------------------------------------------. > | Joseph J. Strout Biocomputing -- The Salk Institute | > | joe@strout.net http://www.strout.net | > `------------------------------------------------------------------' > --============_-1279112630==_ma============ > Content-Type: text/enriched; charset="us-ascii" > > At 9:16 AM -0700 07/26/99, Art Siegel wrote: > > > self.y=args[1] > > IndexError: tuple index out of range > > Apparently because the arguments to Point(1,2,3) is read in as a single > element tuple, whose single element is the 3 element tuple (1,2,3). > > > > Yep. > > > Whereas Position(1,2,3) is processed as a three element tuple, > with elements 1,2,3. > > > > Yep again. > > > Is there a straightforward approach to accomplish above > inheritance?? > > > > Yep^3. Well, reasonably straightforward -- slightly complicated by > having an additional parameter ('self'): > > > apply(Position.__init__, (self,) + args) > > > In cases where you have a list or tuple of arguments, but you need to > pass them to a function as separate arguments rather than a single > object, you use 'apply'. > > > Cheers, > > -- Joe > > ,------------------------------------------------------------------. > > | Joseph J. Strout Biocomputing -- The Salk Institute | > > | joe@strout.net http://www.strout.net | > > `------------------------------------------------------------------' > > --============_-1279112630==_ma============-- > > > > --__--__-- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > > > End of Tutor Digest > ------------------------------------------------------------------- -- Daniel Gau -- -- webmaster of Linux Notes -- -- http://www.linux.org.tw/~plateau/linux_notes/index.htm -- -- webmaster of TwLUG -- -- http://www.linux.org.tw -- -- ICQ 30932232 -- ------------------------------------------------------------------- From wongcc8@yahoo.com Wed Jul 28 13:36:44 1999 From: wongcc8@yahoo.com (martin martin) Date: Wed, 28 Jul 1999 05:36:44 -0700 (PDT) Subject: [Tutor] A beginner's question Message-ID: <19990728123644.9271.rocketmail@web204.mail.yahoo.com> To dear --- : Can I know what should I know before I learn how to program .As you know , i'm a real real beginner .Or should I start with basic understanding .For example : if I want to create a program that could make the monitor screen upside-down or something else ,what should i start from the beginning ?....Thank you for answering my question...... _____________________________________________________________ Do You Yahoo!? Free instant messaging and more at http://messenger.yahoo.com From Garyf618@cs.com Wed Jul 28 21:04:16 1999 From: Garyf618@cs.com (Garyf618@cs.com) Date: Wed, 28 Jul 1999 16:04:16 EDT Subject: [Tutor] (no subject) Message-ID: <1c92293f.24d0bc40@cs.com> who do u make games using python? From sessile@in-gen.net Thu Jul 29 00:38:00 1999 From: sessile@in-gen.net (sessile@in-gen.net) Date: Wed, 28 Jul 1999 19:38:00 -0400 Subject: [Tutor] Accessing C library (".a") functions from Python? Message-ID: <3.0.6.32.19990728193800.007c79b0@mail.in-gen.net> My relevent programming experience: some Python, negligible C/C++. I have a library file named "libtts.a" containing a bunch of functions that I would like to make accessible through Python. I know that a C program can access the functions by name (eg., "tts_get_int") if I compile the program with a link to the library (and obey the function's requirements as spelled out in the "tts" documentation). I have read the Extending and Embedding Tutorial, but still don't see how to get started. I take it that I'm missing some basic concepts here... what information can I provide to make advising me easier (or at least possible)? -- E-Mail: sessile@in-gen.net "I don't want the world... I just want your half." -- TMBG (Anna Ng) From eroubinc@u.washington.edu Thu Jul 29 04:34:11 1999 From: eroubinc@u.washington.edu (Evgeny Roubinchtein) Date: Wed, 28 Jul 1999 20:34:11 -0700 (PDT) Subject: [Tutor] popen()ed file object hangs on close() -- why? Message-ID: So, I have written a very simple script to filter the output of a command. Right now it is just the ping command, but I think I can add more. The problem is the script hangs. I realize that the ping command is still writing data when I try to close the pipe. If I knew it's PID, I could try killing it, but I how do I get its PID? (short of an equivalent of 'ps ax | grep ping' ) Here is the script: It hangs under both Linux and FreeBSD, in case that matters. I know I am doing sthg stupid, I just wish I knew what... Any help is greatly appreciated ---%<----- #! /usr/local/bin/python import re, os, string, sys ping = '/bin/ping' host = '127.0.0.1' ping_re = r'\s+time=(?P\d+\.\d*)\s+ms' class CommandPipe: def __init__(self, command, command_options, command_args, regexp): self.prog = string.join((command, command_options, command_args), ' ') self.re_obj = re.compile(regexp) self.line = '' def run(self): command_pipe = os.popen(self.prog) maxcount = 5 # this can be adjusted for i in range(maxcount): line = command_pipe.readline() if not line: break line = string.strip(line) m = self.re_obj.search(line) if m: for group in m.groups(): print group, print # a blank line sys.stdout.flush() command_pipe.close() # the script hangs here return class PingPipe(CommandPipe): def __init__(self, command=ping, command_options='', command_args=host, regexp=ping_re): CommandPipe.__init__(self, command, command_options, command_args, regexp) def test(): p = PingPipe() p.run() if __name__=='__main__': test() sys.exit(0) -- Evgeny Roubinchtein, eroubinc@u.washington.edu ................... SDD: Scratch Disk and Die From DOUGS@oceanic.com Thu Jul 29 04:57:23 1999 From: DOUGS@oceanic.com (Doug Stanfield) Date: Wed, 28 Jul 1999 17:57:23 -1000 Subject: [Tutor] popen()ed file object hangs on close() -- why? Message-ID: <5650A1190E4FD111BC7E0000F8034D26A0EF11@huina.oceanic.com> I don't know what platform you're on but I'd do something like (untested code): class PingPipe(CommandPipe): def __init__(self, command=ping, command_options='-c 1', command_args=host, regexp=ping_re): CommandPipe.__init__(self, command, command_options, command_args, regexp) Notice the command_options='-c 1'. This limits you to one ping and if thats not what you're trying to do, adjust the number. Apologies in advance for the probable line length mangling of my mailer. -Doug- > -----Original Message----- > From: Evgeny Roubinchtein [mailto:eroubinc@u.washington.edu] > Sent: Wednesday, July 28, 1999 5:34 PM > To: tutor@python.org > Subject: [Tutor] popen()ed file object hangs on close() -- why? > > > So, I have written a very simple script to filter the output > of a command. > Right now it is just the ping command, but I think I can add more. The > problem is the script hangs. I realize that the ping command is > still writing data when I try to close the pipe. If I knew > it's PID, I > could try killing it, but I how do I get its PID? (short of an > equivalent of 'ps ax | grep ping' ) Here is the script: > It hangs under both Linux and FreeBSD, in case that matters. > > I know I am doing sthg stupid, I just wish I knew what... > > Any help is greatly appreciated > > ---%<----- > > #! /usr/local/bin/python > > import re, os, string, sys > > ping = '/bin/ping' > host = '127.0.0.1' > ping_re = r'\s+time=(?P\d+\.\d*)\s+ms' > > class CommandPipe: > def __init__(self, command, command_options, > command_args, regexp): > self.prog = string.join((command, command_options, > command_args), ' ') > self.re_obj = re.compile(regexp) > self.line = '' > def run(self): > command_pipe = os.popen(self.prog) > maxcount = 5 # this can be adjusted > for i in range(maxcount): > line = command_pipe.readline() > if not line: > break > line = string.strip(line) > m = self.re_obj.search(line) > if m: > for group in m.groups(): > print group, > print # a blank line > sys.stdout.flush() > command_pipe.close() # the script hangs here > return > > > > class PingPipe(CommandPipe): > def __init__(self, command=ping, command_options='', > command_args=host, > regexp=ping_re): > CommandPipe.__init__(self, command, command_options, > command_args, > regexp) > > def test(): > p = PingPipe() > p.run() > > > if __name__=='__main__': > test() > sys.exit(0) > > > > -- > Evgeny Roubinchtein, eroubinc@u.washington.edu > ................... > SDD: Scratch Disk and Die > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From eroubinc@u.washington.edu Thu Jul 29 05:43:48 1999 From: eroubinc@u.washington.edu (Evgeny Roubinchtein) Date: Wed, 28 Jul 1999 21:43:48 -0700 (PDT) Subject: [Tutor] popen()ed file object hangs on close() -- why? In-Reply-To: <5650A1190E4FD111BC7E0000F8034D26A0EF11@huina.oceanic.com> Message-ID: Adjusting the number after the '-c ' in the command_options works beautifully. Also, I no longer need the maxcount variable in CommandPipe.run(): maxcount = 5 # this can be adjusted for i in range(maxcount): can be replaced with while 1: Thank you (and to think the '-c ' option was actually in the ping(1) man page :) Evgeny. On Wed, 28 Jul 1999, Doug Stanfield wrote: >I don't know what platform you're on but I'd do something like (untested >code): > >class PingPipe(CommandPipe): > def __init__(self, command=ping, command_options='-c 1', >command_args=host, regexp=ping_re): > CommandPipe.__init__(self, command, command_options, command_args, >regexp) > >Notice the command_options='-c 1'. This limits you to one ping and if thats >not what you're trying to do, adjust the number. > >Apologies in advance for the probable line length mangling of my mailer. > >-Doug- >> -----Original Message----- >> From: Evgeny Roubinchtein [mailto:eroubinc@u.washington.edu] >> Sent: Wednesday, July 28, 1999 5:34 PM >> To: tutor@python.org >> Subject: [Tutor] popen()ed file object hangs on close() -- why? >> >> >> So, I have written a very simple script to filter the output >> of a command. >> Right now it is just the ping command, but I think I can add more. The >> problem is the script hangs. I realize that the ping command is >> still writing data when I try to close the pipe. If I knew >> it's PID, I >> could try killing it, but I how do I get its PID? (short of an >> equivalent of 'ps ax | grep ping' ) Here is the script: >> It hangs under both Linux and FreeBSD, in case that matters. >> >> I know I am doing sthg stupid, I just wish I knew what... >> >> Any help is greatly appreciated >> >> ---%<----- >> >> #! /usr/local/bin/python >> >> import re, os, string, sys >> >> ping = '/bin/ping' >> host = '127.0.0.1' >> ping_re = r'\s+time=(?P\d+\.\d*)\s+ms' >> >> class CommandPipe: >> def __init__(self, command, command_options, >> command_args, regexp): >> self.prog = string.join((command, command_options, >> command_args), ' ') >> self.re_obj = re.compile(regexp) >> self.line = '' >> def run(self): >> command_pipe = os.popen(self.prog) >> maxcount = 5 # this can be adjusted >> for i in range(maxcount): >> line = command_pipe.readline() >> if not line: >> break >> line = string.strip(line) >> m = self.re_obj.search(line) >> if m: >> for group in m.groups(): >> print group, >> print # a blank line >> sys.stdout.flush() >> command_pipe.close() # the script hangs here >> return >> >> >> >> class PingPipe(CommandPipe): >> def __init__(self, command=ping, command_options='', >> command_args=host, >> regexp=ping_re): >> CommandPipe.__init__(self, command, command_options, >> command_args, >> regexp) >> >> def test(): >> p = PingPipe() >> p.run() >> >> >> if __name__=='__main__': >> test() >> sys.exit(0) >> >> >> >> -- >> Evgeny Roubinchtein, eroubinc@u.washington.edu >> ................... >> SDD: Scratch Disk and Die >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://www.python.org/mailman/listinfo/tutor >> > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://www.python.org/mailman/listinfo/tutor > > From samus@feudalkingdoms.tzo.org Mon Jul 19 03:54:31 1999 From: samus@feudalkingdoms.tzo.org (samus) Date: Sun, 18 Jul 1999 22:54:31 -0400 Subject: [Tutor] Is Python suitable for my project? In-Reply-To: <3973A34A.2578.47AD0@localhost> Message-ID: >Now I'm planning to develop a new version from scratch. I like >Visual Basic because it is easy to program with and you can get >what you want fast. But with my application I got to the limits of >this programming environment. I had to use thousands of nasty >tricks to overcome them, and that resulted in a loss of productivity >and made the code harder to debug, modify and maintain. Modularity is key to large projects. In the case of OOP its a mater of keeping your objects as independent of each other as possible. Generic is good. Then you inherit from those or write specialized wrappers to do the special case stuff. >programming, but I have never undertaken a serious project with >this paradigm. I come from the old structured-programming school... Get aquainted with it. Once you get into it its hard to think of writing software any other way. >To use any of the languages I already know for my project would >require too much time. The application I need to develop doesn't >need any low-level code, so using Pascal or C would be a waste of >power. C++ is just a modified version of C. This time I would like to >try the real object-oriented programming. Python springs to mind, >and I've been reading the introductory course and so far I like what >I've seen. I think it is a good compromise between programming >power and productivity. I have so far enjoyed Python best for automating tasks like system administration and acting as a support or glue language. If you plan on sticking to windows then I would suggest learning about how to do COM objects. VB is a decent enough way to start to get a feel of how it works. The MSDN help sections give nice overviews. Though I hate that html help interface. I'm not sure that I reccomend doing a whole application on windows in Python yet. The graphical part will take longer than VB b/c there isn't really any RAD tool for gui design with Python. WxPython so far seems to be the best gui toolkit for python. Its cross platform with a native look in each supported platform. It also doesn't take the least common denominator of the platforms it actually will add what is missing to each platform to make things as even as possible. There is an MFC wrapper that comes with the win32 python distrobution. The editor Pythonwin serves as an IDE and an example of how to do it. So what I would probably do in your shoes is design out my app with object oriented principles as much as possible and then use the language that is easiest for me (in my case VB for others C++ on the backside and VB on the front). I would think of the app as more of a toolkit that has a pretty face. All the while keeping in mind about how you can embed a scripting language (Python) in to it to automate repetive tasks. On win32 if you use COM you can easily embed any scripting language ala VBA by the use of the active scripting control. The debugging pretty much blows but its real easy to setup the interface between your program and a script. You can find info about it on MS's website by searching for VBScript. I've found this method to be an excellent way of extending my apps and to easily allow me to switch out the way things work in the program. This would be handy if your dad has a friend that would like the program but he does things slightly different. Anyway sorry to ramble. I hope I didn't come off as being an MSZombie. My first preference is Linux but at work the market has so far demanded windows. I have had to appease the bill collectors with a job working with MS tools while secretly at night plotting world domination through free software. ;-) -Sam