From dis_gus_ted@my-deja.com  Thu Feb  1 08:05:25 2001
From: dis_gus_ted@my-deja.com (First Name Last Name)
Date: Thu, 1 Feb 2001 00:05:25 -0800
Subject: [Tutor] Newbie question re: user interaction
Message-ID: <200102010805.AAA10776@mail14.bigmailbox.com>

Hello,
    I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week.  I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page.

Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c.  The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time.

Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python?

10 INPUT "What is your name?" N$
20 PRINT "Hello, " N$ "!"

This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it.  However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above.  Please tell me I'm wrong!

Thanks very much for any help, Gus Hungerford.



------------------------------------------------------------
--== Sent via Deja.com ==--
http://www.deja.com/




From conways5@earthlink.net  Thu Feb  1 03:30:09 2001
From: conways5@earthlink.net (The Conways)
Date: Wed, 31 Jan 2001 19:30:09 -0800
Subject: [Tutor] Path problems python 2.0
Message-ID: <011801c08bff$49b08380$25dbaec7@kitchen>

To set the path in Win98k, I used SET PYTHONPATH=C:\PYTHON20\MYPYTHON in the
autoexec.bat.
It worked and I am able to use import prog.py.

Next I tried to execute commands from the MS-DOS command prompt.  I used
SET PATH=C:\PYTHON20;%PATH% in the autoexec.bat.  At the C prompt I typed
in:
python hello.py, I received the following error message from dos:
C:\PYTHON20\PYTHON.EXE:  can't open file 'hello.py.
Next I tried typing python from the C prompt and it did start the PYTHON
command prompt.

By the way Alan Gauld's book, "Learning to Program Using Python" is
excellent for beginners.

Now for a Linux question.  Python 1.52 came with our Mandrake 7.2
installation.  So I am also learning some linux as well as python.  My
question is where do you keep your py scripts in Linux, the file system is
so organized that I am not really sure where to put things.



From bsass@freenet.edmonton.ab.ca  Thu Feb  1 18:22:49 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 1 Feb 2001 11:22:49 -0700 (MST)
Subject: [Tutor] NEWBIE!! pipes
In-Reply-To: <50.10cfb61b.27a9e306@aol.com>
Message-ID: <Pine.A41.3.95.1010201104820.17122A-100000@fn2.freenet.edmonton.ab.ca>

On Wed, 31 Jan 2001 AquaRock7@aol.com wrote:
> What are pipes?  The docs barely touched this subject, it assumed you already 
> knew what they are...  From context I am gathering that it is a connection to 
> the kernel?  (maybe?)  How can I utilize this?

A "pipe" is a connection between two programs, from the stdout of one to
the stdin of another.  On a unix command line you would write it as:
	prog1 | prog2 | prog3

Which would pipe the output of prog1 to the input prog2, etc.

> 1 more quickie:
> >if __name__ == '__main__':
> >     main()
> 
> what is the pourpose if the above code?  It runs the sub main() (duh :) but, 
> why not just main() wihtout the if?  what is the conditional testing for?  
> and what are the variables __main__ and __name__?  i dont believe they are 
> defined in the program, so just what are they?  and, what does putting "__" 
> around a variable actually DO besides look cool ?

Ya, cool, until you try to read it done in a proportional font and can't
tell how many underscores are present.  anyways...

When Python is executing the mainline of a program __name__ has the
value "__main__", so, the above snippet would only execute the main()
routine if the code was being executed as part of the mainline of a
program.  i.e., doing "python snippet" would execute main(), doing
"import snippet" from within a Python program would not.  It tends to
be used it like this...

----- module: snip2
class C1:
    ...

class C2:
    ...

def f1:
    ....

def main():
    # class and function test routine

if __name__ == "__main__":
    main()
-----

When I want to test what I'm woring on I do "^C^C" to execute the
buffer, __name__ == "__main__" and the test code is run; when a prg
imports the finished module the test code is ignored.  The prog doing
the importing could also do a "snip2.main()" to run the test code.

HTH


later,

	Bruce



From kalle@gnupung.net  Thu Feb  1 18:51:36 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 1 Feb 2001 19:51:36 +0100
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500
References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <20010201195136.A463@apone.network.loc>

--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Seelinger, Bruce:
> Another question from someone totally new to Python. Is there an equivale=
nt
> in Python to a sub-routine, (e.g. gosub and return).  I want to create a

A function.

[snip]
> best) way to do this is with modules?  A function works but the values
> obtained within the function do not appear to be valid outside of that
> function.  I guess I am looking for the best approach to create the

No.  That's a feature.  Global variables are often a bad idea and make
programs more difficult to understand, especially when they grow larger.
Use class instance methods and variables or plain old return values.

Note:  If you really, really want, use the "global" statement:
>>> a =3D 0
>>> def f(val):
=2E..     global a
=2E..     a =3D val
=2E..=20
>>> print a
0
>>> f(12)
>>> print a
12
>>>=20

But don't blame me if you don't understand your own programs three months
from now... <wink>

I suggest you read
http://www.crosswinds.net/~agauld/
http://www.ibiblio.org/obp/thinkCSpy/
http://www.python.org/doc/current/tut/

Especially the parts about functions, modules, classes and object oriented
programming.

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--Dxnq1zWXvFF0Q93v
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6ebA4dNeA1787sd0RAhDcAKCSRsGjb4wy5SxHxbU/bxw4lnyedQCgybTz
UTMtlqPmdF7dsKRe2TDy6Rg=
=Sj6q
-----END PGP SIGNATURE-----

--Dxnq1zWXvFF0Q93v--


From deirdre@deirdre.net  Thu Feb  1 17:54:04 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 1 Feb 2001 09:54:04 -0800 (PST)
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <Pine.LNX.4.31.0102010951040.31938-100000@emperor.deirdre.org>

On Wed, 31 Jan 2001, Seelinger, Bruce wrote:

> Another question from someone totally new to Python. Is there an
> equivalent in Python to a sub-routine, (e.g. gosub and return).

There are functions.

> I want to create a modular program with sub-routines to perform
> distinct tasks wihin the program for organizational and debugging
> purposes, etc.  Is the only (or best) way to do this is with modules?

No. As I said, there are also functions.

> A function works but the values obtained within the function do not
> appear to be valid outside of that function.  I guess I am looking for
> the best approach to create the subroutines for execution from the
> main flow of the program.

Good coding design says that that's the way it should be. Functions should
only change what's inside them, not stuff that may have Unintended
Consequences (tm).

Clearly, you learned Basic first and early versions of Basic (sorry, I
haven't used the language in 26 years...) didn't have local scoping as
that was difficult to implement and its advantages were not yet
appreciated. I believe Pascal was the first widely-used language to use
local scoping.

_Deirdre



From deirdre@deirdre.net  Thu Feb  1 17:56:55 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 1 Feb 2001 09:56:55 -0800 (PST)
Subject: [Tutor] NEWBIE!! pipes
In-Reply-To: <50.10cfb61b.27a9e306@aol.com>
Message-ID: <Pine.LNX.4.31.0102010954330.31938-100000@emperor.deirdre.org>

On Wed, 31 Jan 2001 AquaRock7@aol.com wrote:

> What are pipes?  The docs barely touched this subject, it assumed you
> already knew what they are...  From context I am gathering that it is
> a connection to the kernel?  (maybe?)  How can I utilize this?

A pipe connects the output of one Unix process to the input of the next
one. Sort of like "send this data through this pipe to here."

It has nothing to do with the kernel per se and isn't generally used
within a program.

> 1 more quickie:
> >if __name__ == '__main__':
> >     main()
>
> what is the pourpose if the above code?  It runs the sub main() (duh
> :) but, why not just main() wihtout the if?  what is the conditional
> testing for?  and what are the variables __main__ and __name__?  i
> dont believe they are defined in the program, so just what are they?
> and, what does putting "__"  around a variable actually DO besides
> look cool ?

This means that if the file is invoked directly from the command line, it
knows what to do. Otherwise, if well-designed and all in functions, how's
it going to know which one to call?

The __ around the variable means that it's a built-in function or variable
(as in built-in to Python).

_Deirdre




From deirdre@deirdre.net  Thu Feb  1 18:06:28 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 1 Feb 2001 10:06:28 -0800 (PST)
Subject: [Tutor] square root
In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>
Message-ID: <Pine.LNX.4.31.0102011005540.31938-100000@emperor.deirdre.org>

On Wed, 31 Jan 2001, W.W. van den Broek wrote:

> How do you use the
> square root as operator
> in python?
> Dumb question, but
> thanks anyway,

import math
math.sqrt(25)

Or...
from math import sqrt
a = sqrt(25)

_Deirdre




From arcege@shore.net  Thu Feb  1 18:15:20 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 1 Feb 2001 13:15:20 -0500 (EST)
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com> from "Seelinger, Bruce" at Jan 31, 2001 05:12:29 PM
Message-ID: <200102011815.NAA11489@northshore.shore.net>

> 
> This message is in MIME format. Since your mail reader does not understand
> this format, some or all of this message may not be legible.
> 
> ------_=_NextPart_001_01C08BD2.E6AD3D40
> Content-Type: text/plain;
> 	charset="iso-8859-1"
> 
> Hello,
> 
> Another question from someone totally new to Python. Is there an equivalent
> in Python to a sub-routine, (e.g. gosub and return).  I want to create a
> modular program with sub-routines to perform distinct tasks wihin the
> program for organizational and debugging purposes, etc.  Is the only (or
> best) way to do this is with modules?  A function works but the values
> obtained within the function do not appear to be valid outside of that
> function.  I guess I am looking for the best approach to create the
> subroutines for execution from the main flow of the program.

There sure are.  You would either use the "def" statement or the
"lambda" expression to create a subroutine/procedure/function.

>>> def WhatsMyLine(name, message):
...   print name, 'said', repr(message)
...
>>> WhatsMyLine('Arcege', "Spam, Spam, Eggs and Spam")
Arcege said 'Spam, Spam, Eggs and Spam'
>>> is_odd = lambda n: (n % 2) == 1
>>> is_odd(3)
1
>>> is_odd(4), is_odd(5)
(0, 1)
>>>

I would suggest that you read the Python tutorial; it could help you a
lot with your questions.
<URL: http://www.python.org/doc/current/tut/tut.html>

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From arcege@shore.net  Thu Feb  1 18:29:01 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 1 Feb 2001 13:29:01 -0500 (EST)
Subject: [Tutor] NEWBIE!! pipes
In-Reply-To: <50.10cfb61b.27a9e306@aol.com> from "AquaRock7@aol.com" at Jan 31, 2001 04:52:06 PM
Message-ID: <200102011829.NAA16195@northshore.shore.net>

> What are pipes?  The docs barely touched this subject, it assumed you already 
> knew what they are...  From context I am gathering that it is a connection to 
> the kernel?  (maybe?)  How can I utilize this?

Pipes are a feature of the operating system, not of Python; and then,
mostly in POSIX operating systems.  They are often used to connect the
output of one process to the input of another.  For example on MS-DOG,
it is common to run `type autoexec.bat | more' to pause listing the
file after every screenful, the "|" is the pipe character.  Refer to a
lot of shell scripting or UNIX system programming books for different
ways to utilize this fairly powerful construct.

> 1 more quickie:
> >if __name__ == '__main__':
> >     main()
> 
> what is the pourpose if the above code?  It runs the sub main() (duh :) but, 
> why not just main() wihtout the if?  what is the conditional testing for?  
> and what are the variables __main__ and __name__?  i dont believe they are 
> defined in the program, so just what are they?  and, what does putting "__" 
> around a variable actually DO besides look cool ?

This is explained in the Python FAQ 4.10 "How do I find out whether I
am running as a script?"  Each module has a variable called
"__name__".  If variable contains the name "__main__", then the module
is what was called from the command line (the "script"), instead of
imported from another module.

$ cat foo.py
if __name__ == '__main__':
    print 'script'
else:
    print 'imported'
$ python foo.py
script
$ python
>>> import foo
imported
>>>

Most often it is used to test a module meant to be imported, so only if
you execute it directly, it runs the testing code.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From bsass@freenet.edmonton.ab.ca  Thu Feb  1 18:34:13 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 1 Feb 2001 11:34:13 -0700 (MST)
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <Pine.A41.3.95.1010201112335.17122B-100000@fn2.freenet.edmonton.ab.ca>

On Wed, 31 Jan 2001, Seelinger, Bruce wrote:
> Another question from someone totally new to Python. Is there an equivalent
> in Python to a sub-routine, (e.g. gosub and return).  I want to create a

function - subroutine - procedure... they are all the same basic idea

> modular program with sub-routines to perform distinct tasks wihin the
> program for organizational and debugging purposes, etc.  Is the only (or
> best) way to do this is with modules?  A function works but the values
> obtained within the function do not appear to be valid outside of that

You should send along an example... it is probably just a problem with
Python's scope rules, or maybe that the code is passing a reference when
you are thinking value, or maybe you are expecting a default parameter's
value to be evaluated everytime the function is used when it is actually
only evaluated once... hard to say without seeing any code. 

> function.  I guess I am looking for the best approach to create the
> subroutines for execution from the main flow of the program.


later,

	Bruce



From deirdre@deirdre.net  Thu Feb  1 19:15:35 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 1 Feb 2001 11:15:35 -0800 (PST)
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDF@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <Pine.LNX.4.31.0102011100120.31938-100000@emperor.deirdre.org>

As this is really a tutor question, I'm cutting the extra parts and
re-posting the meat to the Tutor list (list mom's prerogative):

(And yes, I'd rather responses went to the list; others are struggling
with the same kinds of things and NOT posting...)

On Thu, 1 Feb 2001, Seelinger, Bruce wrote:

> I wanted to use values obtained in subroutines or functions as you are
> allowed in DCL.  For example, one subroutine determines the hardware
> type of unit based on data imported from a file.  Once that subroutine
> determines the hardware type, it is assigned to a variable (hw_type)
> and is used by other subroutines for purposes unique to that hardware
> type.  I think the underlying issue is the my logic and design will
> need to be modified to adhere to Python's rules.

In calling a function, you can pass one or more parameters to it. Unlike
may other languages, you can also return multiple parameters.

def readFile(fname):
	... do some stuff...
	hw_type = (something from the file)
	hw_info = (something else from the file)
	return hw_type, hw_info

def main():
	hw_type, hw_info = readFile("foo")

There's also more complex structures; see:
http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000

_Deirdre




From kalle@gnupung.net  Thu Feb  1 19:52:05 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 1 Feb 2001 20:52:05 +0100
Subject: [Tutor] NEWBIE!! pipes
In-Reply-To: <50.10cfb61b.27a9e306@aol.com>; from AquaRock7@aol.com on Wed, Jan 31, 2001 at 04:52:06PM -0500
References: <50.10cfb61b.27a9e306@aol.com>
Message-ID: <20010201205205.B463@apone.network.loc>

--Yylu36WmvOXNoKYn
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez AquaRock7@aol.com:
> What are pipes?  The docs barely touched this subject, it assumed you alr=
eady=20
> knew what they are...  From context I am gathering that it is a connectio=
n to=20
> the kernel?  (maybe?)  How can I utilize this?

It is much like a file, but it's connected to another program.  The name is
actually pretty telling, your program holds one end of the pipe and the
other program holds the other.  If you put something in, it comes out in the
other end, and vice versa.  Computer pipes are one-way though, either you
have a write pipe or a read pipe (I think?).
Anyway, they're really cool to have in a shell:
ps ax | grep netscape | grep -v grep | awk '{ print $1 }'
is a common command on UNIX workstations, it finds the process id of
netscape, to be able to kill it when it's sucking all the CPU again.

In python, the most common way to use pipes is the os.popen* family of
functions.  They return pipes to/from a process.
Artificial example:
>>> import os
>>> inpipe =3D os.popen("ls")
>>> outpipe =3D os.popen("lpr", "w")
>>> outpipe.write(inpipe.read())
>>>
should print the contents of the current directory to your printer.
Better examples for windows are left for others to figure out.

> 1 more quickie:
> >if __name__ =3D=3D '__main__':
> >     main()
>=20
> what is the pourpose if the above code?  It runs the sub main() (duh :) b=
ut,=20
> why not just main() wihtout the if?  what is the conditional testing for?=
 =20
> and what are the variables __main__ and __name__?  i dont believe they ar=
e=20
> defined in the program, so just what are they?  and, what does putting "_=
_"=20
> around a variable actually DO besides look cool ?

Good questions!  Variables with "__"s around them are system variables,
often automatically defined by the system.  Every module has a __name__, and
when it is run directly from command line, this is "__main__".
>>> import cgi
>>> cgi.__name__
'cgi'
>>> print __name__
__main__
>>>=20

Thus
if __name__ =3D=3D '__main__':
    main()

only runs main() if the file is run, as opposed to imported from another
module.  This enables modules to work both as libraries and programs at the
same time.  Great, huh?

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--Yylu36WmvOXNoKYn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6eb5ldNeA1787sd0RAuoaAKCwtRdr/rNm+c/7K2bBg7yTh/Q/TQCeIgkP
UVp6rNv78hCuE5Ata03Ng1g=
=pjlL
-----END PGP SIGNATURE-----

--Yylu36WmvOXNoKYn--


From kalle@gnupung.net  Thu Feb  1 19:55:09 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 1 Feb 2001 20:55:09 +0100
Subject: [Tutor] square root
In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>; from vdbroekw@wxs.nl on Wed, Jan 31, 2001 at 10:12:48PM +0100
References: <20010130215307.C2537EECC@mail.python.org> <3A787FD0.4CD22F54@wxs.nl>
Message-ID: <20010201205509.C463@apone.network.loc>

--QRj9sO5tAVLaXnSD
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez W.W. van den Broek:
> How do you use the
> square root as operator
> in python?

There is no square root operator in python.  You'll have to use the
math.sqrt() function.

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--QRj9sO5tAVLaXnSD
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6eb8ddNeA1787sd0RAuipAKCyt+zBoeiGvwOc1Qoa6LN5y4mlJwCgz4QG
2oDQJ8I8zwSuUgViBFdxP+s=
=YK4m
-----END PGP SIGNATURE-----

--QRj9sO5tAVLaXnSD--


From dsh8290@rit.edu  Thu Feb  1 21:03:48 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 1 Feb 2001 16:03:48 -0500
Subject: [Tutor] square root
In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>; from vdbroekw@wxs.nl on Wed, Jan 31, 2001 at 10:12:48PM +0100
References: <20010130215307.C2537EECC@mail.python.org> <3A787FD0.4CD22F54@wxs.nl>
Message-ID: <20010201160348.A5654@harmony.cs.rit.edu>

There is no square root /operator/ in python.  (AFAIK)  There is a
square root function instead.

from math import sqrt
print sqrt( 49 )


You can use it just like any other function.  I will return the square
root (as a floating point number).

HTH,
-D

On Wed, Jan 31, 2001 at 10:12:48PM +0100, W.W. van den Broek wrote:
| How do you use the
| square root as operator
| in python?
| Dumb question, but
| thanks anyway,
| walter
| -- 
| W.W. van den Broek
| e-mail:	
| vandenbroek@psyd.azr.nl
| AZR-Dijkzigt		fax:	
| 010-4633217
| afdeling psychiatrie
| tel:		010-4639222
| Postbus 2040		e-mail	
| vdbroekw@wxs.nl (thuis)
| 3000 CA Rotterdam
| homepage:
| http://home.planet.nl/~vdbroekw
| 
| _______________________________________________
| Tutor maillist  -  Tutor@python.org
| http://mail.python.org/mailman/listinfo/tutor


From kevinoconnor1@netscapeonline.co.uk  Thu Feb  1 21:16:19 2001
From: kevinoconnor1@netscapeonline.co.uk (kevinoconnor1)
Date: Thu, 01 Feb 2001 21:16:19 +0000
Subject: [Tutor] tutor me please
Message-ID: <3A79D222.B9FD4C42@netscapeonline.co.uk>


Hi im new and want to know the  ins and outs of all the pythan
programming. Before you try and reply, reply to a different address
because it is more safe!!if you get the jist!
email me : Freespirt@breathe.com

  Cheers



From randrews@planhouse.com  Thu Feb  1 21:28:16 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 1 Feb 2001 15:28:16 -0600
Subject: [Tutor] Newbie question re: user interaction
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <002c01c08c95$e5effd20$dc00a8c0@Planhouse5>

name=raw_input("What's your name? ")
print "Hello, " + name + "!"

Something like this should do it.

Rob

----- Original Message -----
From: "First Name Last Name" <dis_gus_ted@my-deja.com>
To: <tutor@python.org>
Sent: Thursday, February 01, 2001 2:05 AM
Subject: [Tutor] Newbie question re: user interaction


> Hello,
>     I'm a clueless newbie who has been self-teaching Python (and
programming) for approximately one week.  I have made my stab at immortality
by writing a random-name generator and submitting it to the Useless Python
Scripts page.
>
> Anyway, I understand enough of Python to look up the bits I don't remember
in the manual, write simple functions, &c.  The part in my manual (O'Reilly
'Learning Python') about classes is complete gibberish to me, but I'm sure
that will change in time.
>
> Anyway, what I'm writing to ask about is, how do I do the equivalent of
the following BASIC function in Python?
>
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"
>
> This is a staggeringly simple piece of code and I instinctively feel that
a well-designed language like Python must have a simple and elegant way of
replicating it.  However, all I've managed to gather from the manual is that
if I do something horribly complicated with the cmd module then I might be
able to do something that vaguely mimics the code above.  Please tell me I'm
wrong!
>
> Thanks very much for any help, Gus Hungerford.
>
>
>
> ------------------------------------------------------------
> --== Sent via Deja.com ==--
> http://www.deja.com/
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From deirdre@deirdre.net  Thu Feb  1 21:32:41 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 1 Feb 2001 13:32:41 -0800 (PST)
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <Pine.LNX.4.31.0102011328210.9150-100000@emperor.deirdre.org>

On Thu, 1 Feb 2001, First Name Last Name wrote:

> Anyway, what I'm writing to ask about is, how do I do the equivalent
> of the following BASIC function in Python?
>
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"

n = raw_input("What is your name?")
print "Hello, %s!" % n

The syntax of the two languages' input and print is different, but the
basic concept is the same.

> This is a staggeringly simple piece of code and I instinctively feel
> that a well-designed language like Python must have a simple and
> elegant way of replicating it.  However, all I've managed to gather
> from the manual is that if I do something horribly complicated with
> the cmd module then I might be able to do something that vaguely
> mimics the code above.  Please tell me I'm wrong!

I think you'll find that a lot more is the same than you might think. It's
the details that are different.

The %s means "put a string here, I'll tell you what it is later." The %
later in the line means "OK, here's the list of stuff to put in."

_Deirdre




From dsh8290@rit.edu  Thu Feb  1 21:53:27 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 1 Feb 2001 16:53:27 -0500
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <20010201165327.B5654@harmony.cs.rit.edu>

N = raw_input( "What is your name? " )
print N

:-)

(though I would use a variable like "name" instead of N)

-D


On Thu, Feb 01, 2001 at 12:05:25AM -0800, First Name Last Name wrote:
| Hello,
|     I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week.  I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page.
| 
| Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c.  The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time.
| 
| Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python?
| 
| 10 INPUT "What is your name?" N$
| 20 PRINT "Hello, " N$ "!"
| 
| This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it.  However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above.  Please tell me I'm wrong!
| 
| Thanks very much for any help, Gus Hungerford.
| 
| 
| 
| ------------------------------------------------------------
| --== Sent via Deja.com ==--
| http://www.deja.com/
| 
| 
| 
| _______________________________________________
| Tutor maillist  -  Tutor@python.org
| http://mail.python.org/mailman/listinfo/tutor


From sparling@uclick.com  Thu Feb  1 21:54:24 2001
From: sparling@uclick.com (Douglas Sparling)
Date: Thu, 1 Feb 2001 15:54:24 -0600
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <000401c08c99$8afa0560$460110ac@uclick.com>

>Anyway, what I'm writing to ask about is, how do I do the equivalent of the
following BASIC function in Python?
>
>10 INPUT "What is your name?" N$
>20 PRINT "Hello, " N$ "!"


name = raw_input("What is your name? ")
print "Hello, " +  name + "!"




From martok@mattsmail.com  Thu Feb  1 22:12:09 2001
From: martok@mattsmail.com (Matthias Hager)
Date: Thu,  1 Feb 2001 14:12:09 -0800
Subject: [Tutor] Newbie question re: user interaction
Message-ID: <200102011412.AA123666752@mail.mattsmail.com>

It's been so long since I've worked with any basic. But This should get the effect you're looking for.

$N = input("What is your name? ")
print "Hello, ", $N, "!\n"

The python book I'm using, as pathetic as it may be, says that much. But when I learned Perl my book didn't tell me how to do that. Hope that's what you're looking for.


Matthias

--
Programming isn't cool, it's awesome.

%%%################?????????###################^^^
                                          
          martok@mattsmail.com              
      http://mymymatthias.tripod.com/       
                                            
%%%################????????####################^^^         


--



Like my email address? Get your own for FREE at http://firstname.com 
Get you@JohnsMail.com or you@AlexsMail.com or pick from 500 more! 



From dsh8290@rit.edu  Thu Feb  1 22:18:14 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 1 Feb 2001 17:18:14 -0500
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500
References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <20010201171814.C5654@harmony.cs.rit.edu>

Except for some minor philosophical issues,

subroutine is function is method is procedure is subprogram

Different communities have different names for the same concept.
Functions are what you want here.  The problem you are running into is
Python's scope and namespace rules.

Ex:

>>> def mutate( ) :
...     """ this function will give a new value for s """
...     s = s + "Hello World"
...
>>> s = "Foo "
>>> mutate( )
>>> print s
Foo
>>>

What happened here?  The value didn't change.  There are 2 reasons for
that.  First, the function body has a local namespace.  Those names
don't exist outside of the function.  Assignment, in Python, is
different than in most languages.  In, say, C/C++ assignment will
modify the value of the memory that the variable name refers to (is
bound to).  In Python, assignment is simply a rebinding.  Everything
in Python is a reference.  If a name doesn't yet exist, the
"assignment" will create the name, *in the local namespace*.  Ok,
knowing this, I'll try my above example again.

>>> def mutate( ) :
...     global s
...     s = s + "Hello World"
...
>>> s = "Foo "
>>> mutate( )
>>> print s
Foo Hello World
>>>


This is closer to what you are looking for, I think.  The 'global'
keyword notifies the interpreter that you want to use a variable from
outside the local namespace.  This isn't necessary for reading a
variable, but to assign to it (rebind it) it is necessary.  Without
the global statement, I would have created a new binding in the
function's local namespace, and the effects would not be visible
outside of the function.


There is another issue to consider when trying to modify variables.
Some variables are immutable, while other are mutable.  Immutable
variables can't have their /value/ changed, but can still be rebound
to a new object (value).  Strings, integers, and tuples are some of
the immutable types in python.  Lists and classes are mutable.  An
example:

>>> def mutate( s ) :
...     s = s + "Hello World"
...
>>> a_string = "Foo "
>>> mutate( a_string )
>>> print a_string
Foo
>>>

The argument 's' was rebound /inside/ the function to point to a new
string whose value was "Foo Hello World".  The a_string variable is
still bound to the original string whose value is still "Foo".

Now I'll try with a list, since lists are mutable.

>>> def mutate( l ) :
...     """ try mutating a list """
...     l = l + [ 3 , 4 , 5 ]
...
>>> a_list = [ 1 , 2 ]
>>> mutate( a_list )
>>> print a_list
[1, 2]
>>>

The problem here is the namespace the new list is bound in.  The
operator "+" on a list doesn't modify the list, but instead returns a
new list that is the concatenation of the operands.

>>> def mutate( l ) :
...     l += [ 3 , 4 , 5 ]
...
>>> a_list = [ 1 , 2 ]
>>> mutate( a_list )
>>> print a_list
[1, 2, 3, 4, 5]
>>>

Version 2.0 of the interpreter added augmented assignment.  For
immutable objects, the value isn't changed and the new object is bound
to the left hand side.  (It is just a shorthand notation)  For mutable
objects it will modify the object, /and/ return a refernce to the
object.  The return is necessary otherwise your identifier won't refer
to any objects anymore.

In older versions as well as newer versions of the interpreter, the
following will also work:

>>> def mutate( l ) :
...     l.extend( [ 3 , 4 , 5 ] )
...
>>> a_list = [ 1 , 2 ]
>>> mutate( a_list )
>>> print a_list
[1, 2, 3, 4, 5]
>>>


What kind of background are you coming from?  If I remember correctly,
gosub is from BASIC (but I haven't done any BASIC programming).

If you can provide some examples of what you are trying to do (the
python code you have that isn't working right) we can help you to see
how python's semantics are working and how to modify it to give you
the semantics you want.


You can start out using stand-alone functions, but I much prefer using
classes for (most) of my work.  (there are situations where a
stand-alone function is a better choice though)  Simply put, a class
is a set of data and a set of functions that operate on that data.
You can create multiple instances of a class and each will have its
own set of that data.

HTH,
-D


On Wed, Jan 31, 2001 at 05:12:29PM -0500, Seelinger, Bruce wrote:
| Hello,
| 
| Another question from someone totally new to Python. Is there an equivalent
| in Python to a sub-routine, (e.g. gosub and return).  I want to create a
| modular program with sub-routines to perform distinct tasks wihin the
| program for organizational and debugging purposes, etc.  Is the only (or
| best) way to do this is with modules?  A function works but the values
| obtained within the function do not appear to be valid outside of that
| function.  I guess I am looking for the best approach to create the
| subroutines for execution from the main flow of the program.
| 
| Thanks for any assistance!
| 
| Regards,
| 
| Bruce Seelinger


From DOUGS@oceanic.com  Fri Feb  2 01:55:40 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Thu, 1 Feb 2001 15:55:40 -1000
Subject: [Tutor] Newbie question re: user interaction
Message-ID: <8457258D741DD411BD3D0050DA62365907A5AF@huina.oceanic.com>

[Gus Hungerford asked] 
> Anyway, what I'm writing to ask about is, how do I do the 
> equivalent of the following BASIC function in Python?
> 
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"

Look at the raw_input function.  The reference example (below) is almost
what you need.  You'll probably want this:

answer = raw_input('What is your name? ')
print answer

HTH
-Doug-

>From the 'Python Library Reference':

raw_input ([prompt]) 
If the prompt argument is present, it is written to standard output without
a trailing newline. The function then reads a line from input, converts it
to a string (stripping a trailing newline), and returns that. When EOF is
read, EOFError is raised. Example: 

>>> s = raw_input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"

If the readline module was loaded, then raw_input() will use it to provide
elaborate line editing and history features. 


From moshez@zadka.site.co.il  Fri Feb  2 01:55:31 2001
From: moshez@zadka.site.co.il (Moshe Zadka)
Date: Fri,  2 Feb 2001 03:55:31 +0200 (IST)
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <20010202015531.D6228A840@darjeeling.zadka.site.co.il>

On Thu, 1 Feb 2001, "First Name Last Name" <dis_gus_ted@my-deja.com> wrote:

> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"

n = raw_input("what is your name?")
print "hello, %s!" % n
-- 
Moshe Zadka <sig@zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!
Fingerprint: 4BD1 7705 EEC0 260A 7F21  4817 C7FC A636 46D0 1BD6


From moshez@zadka.site.co.il  Fri Feb  2 01:56:03 2001
From: moshez@zadka.site.co.il (Moshe Zadka)
Date: Fri,  2 Feb 2001 03:56:03 +0200 (IST)
Subject: [Tutor] square root
In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>
References: <3A787FD0.4CD22F54@wxs.nl>, <20010130215307.C2537EECC@mail.python.org>
Message-ID: <20010202015603.EE36CA840@darjeeling.zadka.site.co.il>

On Wed, 31 Jan 2001, "W.W. van den Broek" <vdbroekw@wxs.nl> wrote:

> How do you use the
> square root as operator
> in python?

import math
print math.sqrt(2)
-- 
Moshe Zadka <sig@zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!
Fingerprint: 4BD1 7705 EEC0 260A 7F21  4817 C7FC A636 46D0 1BD6


From jcm@bigskytel.com  Fri Feb  2 02:14:32 2001
From: jcm@bigskytel.com (David Porter)
Date: Thu, 1 Feb 2001 19:14:32 -0700
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <20010201191432.A8192@bigskytel.com>

* First Name Last Name <dis_gus_ted@my-deja.com>:
<...>
> Anyway, I understand enough of Python to look up the bits I don't remember
> in the manual, write simple functions, &c.  The part in my manual (O'Reilly
> 'Learning Python') about classes is complete gibberish to me, but I'm sure
> that will change in time.

I had similar troubles with classes too. The good thing is, that you don't
need to know them to use Python. I'm sure that eventually their benefits
will interest you in learning them, but you don't have to yet.

> Anyway, what I'm writing to ask about is, how do I do the equivalent of the
> following BASIC function in Python?
> 
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"

N = raw_input("What is your name?")
print "Hello, %s!" % N


David


From sparling@uclick.com  Fri Feb  2 03:02:50 2001
From: sparling@uclick.com (Doug Sparling)
Date: Thu, 01 Feb 2001 19:02:50 -0800
Subject: [Tutor] test
Message-ID: <981082970.3a7a235ad0d46@www.electricwebmail.com>

Sorry, I haven't seen a previous post come through, so I wanted to make a test......  


From lgwb@home.com  Fri Feb  2 03:20:23 2001
From: lgwb@home.com (Michael Schmitt)
Date: Thu, 1 Feb 2001 21:20:23 -0600
Subject: [Tutor] Newbie question re: user interaction
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <002501c08cc7$14fe13f0$0a0a0a0a@mntp1.il.home.com>

Name = raw_input("What is your name\n")
print "Hello", Name

simple enough?  Ya, I agree, it seems as input is well hidden in most Python
doc/books.

Michael Schmitt

----- Original Message -----
From: "First Name Last Name" <dis_gus_ted@my-deja.com>
To: <tutor@python.org>
Sent: Thursday, February 01, 2001 2:05 AM
Subject: [Tutor] Newbie question re: user interaction


> Hello,
>     I'm a clueless newbie who has been self-teaching Python (and
programming) for approximately one week.  I have made my stab at immortality
by writing a random-name generator and submitting it to the Useless Python
Scripts page.
>
> Anyway, I understand enough of Python to look up the bits I don't remember
in the manual, write simple functions, &c.  The part in my manual (O'Reilly
'Learning Python') about classes is complete gibberish to me, but I'm sure
that will change in time.
>
> Anyway, what I'm writing to ask about is, how do I do the equivalent of
the following BASIC function in Python?
>
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"
>
> This is a staggeringly simple piece of code and I instinctively feel that
a well-designed language like Python must have a simple and elegant way of
replicating it.  However, all I've managed to gather from the manual is that
if I do something horribly complicated with the cmd module then I might be
able to do something that vaguely mimics the code above.  Please tell me I'm
wrong!
>
> Thanks very much for any help, Gus Hungerford.
>
>
>
> ------------------------------------------------------------
> --== Sent via Deja.com ==--
> http://www.deja.com/
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From tescoil@irtc.net  Fri Feb  2 00:38:02 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Thu, 01 Feb 2001 18:38:02 -0600
Subject: [Tutor] Newbie question re: user interaction
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <3A7A016A.823E7D92@irtc.net>

On 1 Feb 2001, First Name Last Name wrote:
> Anyway, what I'm writing to ask about is, how do I do the
> equivalent of the following BASIC function in Python?
>
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"
>
> This is a staggeringly simple piece of code and I
> instinctively feel that a well-designed language
> like Python must have a simple and elegant way
> of replicating it

N = raw_input('what is your name? ')
print 'Hello,', N, '!'








From rob@jam.rr.com  Thu Feb  1 23:49:59 2001
From: rob@jam.rr.com (R. A.)
Date: Thu, 01 Feb 2001 17:49:59 -0600
Subject: [Tutor] Newbie question re: user interaction
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <3A79F627.6D55E769@jam.rr.com>

I sent this earlier, but it didn't seem to make it to the list.

name=raw_input("What is your name? ")
print "Hello, " + name + "!"

Something like this should do the trick.

Rob

First Name Last Name wrote:
> 
> Hello,
>     I'm a clueless newbie who has been self-teaching Python (and programming) for approximately one week.  I have made my stab at immortality by writing a random-name generator and submitting it to the Useless Python Scripts page.
> 
> Anyway, I understand enough of Python to look up the bits I don't remember in the manual, write simple functions, &c.  The part in my manual (O'Reilly 'Learning Python') about classes is complete gibberish to me, but I'm sure that will change in time.
> 
> Anyway, what I'm writing to ask about is, how do I do the equivalent of the following BASIC function in Python?
> 
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"
> 
> This is a staggeringly simple piece of code and I instinctively feel that a well-designed language like Python must have a simple and elegant way of replicating it.  However, all I've managed to gather from the manual is that if I do something horribly complicated with the cmd module then I might be able to do something that vaguely mimics the code above.  Please tell me I'm wrong!
> 
> Thanks very much for any help, Gus Hungerford.
> 
> ------------------------------------------------------------
> --== Sent via Deja.com ==--
> http://www.deja.com/
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Visit the Useless Python Repository!
http://www.lowerstandard.com/python/pythonsource.html


From babyboy@oninet.pt  Thu Feb  1 23:54:59 2001
From: babyboy@oninet.pt (wilson edgar pinto)
Date: Thu, 1 Feb 2001 23:54:59 -0000
Subject: [Tutor] Newbie question re: user interaction
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <002401c08caa$63de0ec0$320d3ad5@x0q0w3>

yes Gus, is much  more simple than that
just try  this

name = raw_input("hello what's your name? ")
print "nice to meet you", name

 in other words, raw_input, print whatever you write between parenthesis as
a prompt and and then ssaves the value and because, if you assign it to a
variable in this case "name", you can reuse it after

and you can use INPUT that lets you deal with numbers, c'os raw_input is for
strings

hope that helped
----- Original Message -----
From: "First Name Last Name" <dis_gus_ted@my-deja.com>
To: <tutor@python.org>
Sent: Thursday, February 01, 2001 8:05 AM
Subject: [Tutor] Newbie question re: user interaction


> Hello,
>     I'm a clueless newbie who has been self-teaching Python (and
programming) for approximately one week.  I have made my stab at immortality
by writing a random-name generator and submitting it to the Useless Python
Scripts page.
>
> Anyway, I understand enough of Python to look up the bits I don't remember
in the manual, write simple functions, &c.  The part in my manual (O'Reilly
'Learning Python') about classes is complete gibberish to me, but I'm sure
that will change in time.
>
> Anyway, what I'm writing to ask about is, how do I do the equivalent of
the following BASIC function in Python?
>
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"
>
> This is a staggeringly simple piece of code and I instinctively feel that
a well-designed language like Python must have a simple and elegant way of
replicating it.  However, all I've managed to gather from the manual is that
if I do something horribly complicated with the cmd module then I might be
able to do something that vaguely mimics the code above.  Please tell me I'm
wrong!
>
> Thanks very much for any help, Gus Hungerford.
>
>
>
> ------------------------------------------------------------
> --== Sent via Deja.com ==--
> http://www.deja.com/
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From rob@jam.rr.com  Fri Feb  2 00:06:55 2001
From: rob@jam.rr.com (R. A.)
Date: Thu, 01 Feb 2001 18:06:55 -0600
Subject: [Tutor] We're famous!
Message-ID: <3A79FA1F.E44688AD@jam.rr.com>

I have not been this elated in recent memory, group.  The O'Reilly
Network has written what seems to be a kind article on Useless Python,
which I call a success for the Tutor list.  You nifty people have
started something nice, and I thank you for allowing me to maintain it. 
The following URL says it all:

http://www.oreillynet.com/pub/a/python/2001/01/31/pythonnews.html

Rob Andrews
-- 
Visit the Useless Python Repository!
http://www.lowerstandard.com/python/pythonsource.html


From dsh8290@rit.edu  Fri Feb  2 00:15:47 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 1 Feb 2001 19:15:47 -0500
Subject: [Tutor] Word count help
In-Reply-To: <001b01c08a3c$0761e1a0$f9230b3e@oemcomputer>; from facelle@tiscalinet.it on Mon, Jan 29, 2001 at 10:39:28PM +0100
References: <001b01c08a3c$0761e1a0$f9230b3e@oemcomputer>
Message-ID: <20010201191547.D6419@harmony.cs.rit.edu>

I have looked through the code you posted, and I think I know why it
is so slow.  You use lists a lot in your code, and use function calls
such as list.count().  AFAIK list.count() will traverse through the
entire list every time it is called.  When the list gets to be large,
this will take a long time.

To speed this up, I would recommend using a dictionary to hold all the
words and their counts.  Dictionary lookups are fast since they use a
hashing function to find the key.

In this dictionary, I would use the word as the key, and have the
associated value be the number of occurences.

(I posted a perl script I wrote for class last quarter, but I think a
moderator dropped the message)

I have now translated that perl script to python.  I use more pythonic
techniques, and also use more punctuation marks for delimiting words
(the result is that python does more work because it finds more
words).  (In the perl script I made my own regex with the most common
chars, in the python script I use the predefined constants in the
string module).


For timing, I first prepared a file to count (the bash manpage):

$ man bash > man_bash
$ cp man_bash dup
$ cat dup >> man_bash
(3 times)
$ rm dup

The file size is now 1,211KB as reported by Windows Explorer.  The
file has 24552 lines in it.  I'm using a PII 400 (I might be a little
off on the clock speed, it's not my personal machinge) with Win2k and
cygwin.  I ran the interpreter from the bash shell.  The python
interpreter is compiled for windows, the perl one came with cygwin
(compiled for cygwin). 

I ran 

time perl count.pl < man_bash > /dev/null
and
time python count.py < man_bash > /dev/null

to get a rough idea how long the scripts take to run.

My results:

Perl:
real    0m9.233s
user    0m8.522s
sys     0m0.090s

Python:
real    0m19.779s
user    0m0.010s
sys     0m0.010s


Just kind of interesting, the first time I timed it, I used the wrong
filename (a file that doesn't exist).  Perl took longer to report the
error than python.

Perl:
bash: man_bashrc: No such file or directory
real    0m0.050s
user    0m0.030s
sys     0m0.020s

Python:
bash: man_bashrc: No such file or directory
real    0m0.010s
user    0m0.000s
sys     0m0.010s



My entire script (except for the print statements) could be placed
inside a function that takes a filename as an argument, and returns
the dictionary of words if you wanted to use it as part of a larger
system.


I hope this helps you to learn more.  If you have any questions, don't
hesitate to ask.

-D


Here is the script that I used:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import sys
import string
import re

# initialize the counters
linecount = 0
charcount = 0
wordcount = 0
# this is where I will store the total count of each word
words     = { }


# iterate over each line on stdin
for line in sys.stdin.readlines() :
    linecount += 1
    charcount += len( line )

    # remove leading and trailing whitespace
    line = string.strip( line ) 

    # split the string into a list of words
    # a word is delimited by whitespace or punctuation
            #"[.,:;?! \t\n]+" , # this is the regex used in my perl version
    for word in re.split(
            "[" + string.whitespace + string.punctuation + "]+" ,
            line ) :

        # make the word lower case
        word = string.lower( word )

        # check to make sure the string is considered a word
        if re.match( "^[" + string.lowercase + "]+$" , word ) :
            wordcount += 1

            # if the word has been found before, increment its count
            # otherwise initialize its count to 1
            if words.has_key( word ) :
                words[ word ] += 1
            else :
                words[ word ] = 1

        
# Now print out the results of the count:
print
print "Number of lines:" , linecount
print "Total word count:" , wordcount
print "Total character count:" , charcount
print

# print each word and its count in sorted order
sorted_word_list = words.keys()
sorted_word_list.sort()

for word in sorted_word_list :
    print word , ":" , words[ word ]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The script's output from the man_bash file I used (identical to the
perl version's, except for the extra carriage returns that result from
Windows) looks like:

Number of lines: 24552
Total word count: 116000
Total character count: 1239660

a : 3236
abbreviates : 12
abe : 4
ability : 4
able : 40
abled : 4
ables : 20
abling : 4
abort : 8
about : 32
above : 196
absence : 4
absent : 4
absolute : 8


PS.  I recently learned that all Usenet posts are automatically
     copyrighted by the poster.  In light of this, I give explicit
     permission to use, copy, distribute, and mutilate my sample code
     to your heart's desire.  :-)


From jcm@bigskytel.com  Fri Feb  2 00:29:55 2001
From: jcm@bigskytel.com (David Porter)
Date: Thu, 1 Feb 2001 17:29:55 -0700
Subject: [Tutor] NEWBIE!! pipes
In-Reply-To: <50.10cfb61b.27a9e306@aol.com>; from AquaRock7@aol.com on Wed, Jan 31, 2001 at 04:52:06PM -0500
References: <50.10cfb61b.27a9e306@aol.com>
Message-ID: <20010201172955.A6810@bigskytel.com>

* AquaRock7@aol.com <AquaRock7@aol.com>:

> What are pipes?  The docs barely touched this subject, it assumed you
> already knew what they are...  From context I am gathering that it is a
> connection to the kernel?  (maybe?) How can I utilize this?

http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=pipes

I haven't done anything with pipes yet.

> 1 more quickie:
> >if __name__ == '__main__':
> >     main()
> 
> what is the pourpose if the above code?  It runs the sub main() (duh :) but, 
> why not just main() wihtout the if?  what is the conditional testing for?  
> and what are the variables __main__ and __name__?  i dont believe they are 
> defined in the program, so just what are they?  and, what does putting "__" 
> around a variable actually DO besides look cool ?

Each module has a __name__ attribute. The directly executed file (not
imported) has the __name__ of "__main__". Even an interpretter session has
the name of "__main__":

>>> __name__
'__main__'
>>> import os
>>> os.__name__
'os'

Basically, the purpose of the above code is to make python do different
things when the file is run as a script and when it is imported as a
module. If it is being run as a script, execute main().

As for the question about __X__ type names, I think it is merely like that
for __name__ to distinquish it from your variables with the added bonus of
not stealing a valuable keyword from us, name. __X__ type names are more
significant when you deal with classes, where they are hooks used for
operator overloading.


David


From ccurrie@lcc.net  Fri Feb  2 00:48:03 2001
From: ccurrie@lcc.net (Cameron)
Date: Thu, 1 Feb 2001 18:48:03 -0600
Subject: [Tutor] Compiling Python Scripts
References: <20010201170408.E3C9CF5D9@mail.python.org>
Message-ID: <000501c08cb1$cda1b1c0$0101a8c0@ccurrie>

Hi,

I want to compile some of my Python scripts into executable programs to
distribute to some
friends who don't have the Python interpreter... is there any way to do
this? I was unable to
find the answer in the documentation.

Thanks



From jcm@bigskytel.com  Fri Feb  2 00:55:58 2001
From: jcm@bigskytel.com (David Porter)
Date: Thu, 1 Feb 2001 17:55:58 -0700
Subject: [Tutor] Equivalent of a Subroutine in Python?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Wed, Jan 31, 2001 at 05:12:29PM -0500
References: <958398973B4A0343A904C2A4157EDEA54FDCDE@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <20010201175558.A7581@bigskytel.com>

* Seelinger, Bruce <bseelinger@neteffectcorp.com>:

> Another question from someone totally new to Python. Is there an equivalent
> in Python to a sub-routine, (e.g. gosub and return).  I want to create a
> modular program with sub-routines to perform distinct tasks wihin the
> program for organizational and debugging purposes, etc.  Is the only (or
> best) way to do this is with modules?  

What about functions?

According to http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=subroutine 

"A function is often very similar to a subroutine, the main difference
being that it is called chiefly for its return value, rather than for any
side effects."

> A function works but the values obtained within the function do not appear
> to be valid outside of that function.  

That is because they are local to the function's namespace. If you want them
to be global, then you must declare them so:

def fun():
    global x
    x = 11    

fun()    
print x


Or you could use a standard function with return value:

def fun2():
    return 11

x = fun2()
print x


David


From kalle@gnupung.net  Fri Feb  2 01:28:51 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 2 Feb 2001 02:28:51 +0100
Subject: [Tutor] Newbie question re: user interaction
In-Reply-To: <200102010805.AAA10776@mail14.bigmailbox.com>; from dis_gus_ted@my-deja.com on Thu, Feb 01, 2001 at 12:05:25AM -0800
References: <200102010805.AAA10776@mail14.bigmailbox.com>
Message-ID: <20010202022851.A1457@apone.network.loc>

--+HP7ph2BbKc20aGI
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez First Name Last Name:
> Anyway, what I'm writing to ask about is, how do I do the equivalent of
> the following BASIC function in Python?
>=20
> 10 INPUT "What is your name?" N$
> 20 PRINT "Hello, " N$ "!"

n =3D raw_input("What is your name?")
print "Hello,", n

Note that there's no space in the "Hello," string.  The print statement adds
one space between each comma separated argument:
>>> print "a", "b", "c"
a b c
>>>

Also, a good idea is to check out the built in functions, there are quite a
few nice tools there:
http://www.python.org/doc/current/lib/built-in-funcs.html
And indeed, the library reference is your friend:
http://www.python.org/doc/current/lib/

> Please tell me I'm wrong!

You're wrong! <wink>

HTH,
  Kalle

P.S.  I might add that local time is 02:28 (AM).  I really should go to bed.
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--+HP7ph2BbKc20aGI
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6eg1TdNeA1787sd0RAu98AJ9u+vayBvFAgQqt+RAYXW60tm26QQCgu+wN
sw8UyttOcEBNDV0UX8hiay4=
=Fj7O
-----END PGP SIGNATURE-----

--+HP7ph2BbKc20aGI--


From toodles@yifan.net  Fri Feb  2 01:21:28 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Fri, 2 Feb 2001 09:21:28 +0800
Subject: [Tutor] square root
In-Reply-To: <3A787FD0.4CD22F54@wxs.nl>
Message-ID: <MABBIFAJGJIHIKKDOGHOAEBHCDAA.toodles@yifan.net>

There's no operator for squareroot (unless I've been misleading myself
for this long).

Use the power rule of x**(1/y). Here's the relavent rules:

x**y == x to the power of y,
x**(1/y) == x to the root of y,
x**(z/y) == x to the root of y - all raised to the power of z,

So x**(1/2) == the square root of x

I don't think it was a dumb question, but then, I'm a newbie script
kiddie! =)

Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org
> [mailto:tutor-admin@python.org]On Behalf Of
> W.W. van den Broek
> Sent: Thursday, 1 February 2001 5:13
> To: tutor@python.org
> Subject: [Tutor] square root
>
>
> How do you use the
> square root as operator
> in python?
> Dumb question, but
> thanks anyway,
> walter
> --
> W.W. van den Broek
> e-mail:
> vandenbroek@psyd.azr.nl
> AZR-Dijkzigt		fax:
> 010-4633217
> afdeling psychiatrie
> tel:		010-4639222
> Postbus 2040		e-mail
> vdbroekw@wxs.nl (thuis)
> 3000 CA Rotterdam
> homepage:
> http://home.planet.nl/~vdbroekw
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From bsass@freenet.edmonton.ab.ca  Fri Feb  2 06:30:52 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 1 Feb 2001 23:30:52 -0700 (MST)
Subject: [Tutor] Path problems python 2.0
In-Reply-To: <011801c08bff$49b08380$25dbaec7@kitchen>
Message-ID: <Pine.A41.3.95.1010201231630.75790B-100000@fn2.freenet.edmonton.ab.ca>

On Wed, 31 Jan 2001, The Conways wrote:
> Now for a Linux question.  Python 1.52 came with our Mandrake 7.2
> installation.  So I am also learning some linux as well as python.  My
> question is where do you keep your py scripts in Linux, the file system is
> so organized that I am not really sure where to put things.

Generally, stuff the package manager does not know about should go into
/usr/local or /opt (depending on whether the package is setup to
install into the usual unix filesystem structure or into its own
directory, respectively), everything under /usr should be the result of
installing an .rpm.

Your Mandrake-Python maintainer probably has a dir set aside for local
modules, it is /usr/local/lib/site-python on my Debian box.  Checking
your PYTHONPATH while the interpreter is running will tell you all the
locations Python will look for modules.

If you are wondering about where to put executables so everyone can get
at them... /usr/local/bin
Maybe do, "echo $PATH", to make sure /usr/local/bin is in your PATH.


later,

	Bruce



From NHYTRO@compuserve.com  Fri Feb  2 06:56:52 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 2 Feb 2001 01:56:52 -0500
Subject: [Tutor] Reading and outputting  HTML files
Message-ID: <200102020157_MC2-C3F6-C82A@compuserve.com>

Hi guys!

I have coded a CGI script that creates HTML files, strange thing is, when=

reading a HTML file, one created by the script or otherwise, I just get a=

very garbled page returned to the browser. Any clues? can someone help?
this has been bugging me for 3 days now


Cheers


Sharriff

P.S. did I mention that Python rocks?


From salim@nstp.com.my  Fri Feb  2 07:38:23 2001
From: salim@nstp.com.my (Salim)
Date: Fri, 02 Feb 2001 15:38:23 +0800
Subject: [Tutor] square root
In-Reply-To: <MABBIFAJGJIHIKKDOGHOAEBHCDAA.toodles@yifan.net>
References: <3A787FD0.4CD22F54@wxs.nl>
Message-ID: <5.0.2.1.2.20010202153712.00a5fb70@nstp.com.my>

Please make a correction:
x**1/2==the square root of x

please note there is no bracket...

tq


At 09:21 AM 2/2/01 +0800, you wrote:
>There's no operator for squareroot (unless I've been misleading myself
>for this long).
>
>Use the power rule of x**(1/y). Here's the relavent rules:
>
>x**y == x to the power of y,
>x**(1/y) == x to the root of y,
>x**(z/y) == x to the root of y - all raised to the power of z,
>
>So x**(1/2) == the square root of x
>
>I don't think it was a dumb question, but then, I'm a newbie script
>kiddie! =)
>
>Andrew Wilkins
>
> > -----Original Message-----
> > From: tutor-admin@python.org
> > [mailto:tutor-admin@python.org]On Behalf Of
> > W.W. van den Broek
> > Sent: Thursday, 1 February 2001 5:13
> > To: tutor@python.org
> > Subject: [Tutor] square root
> >
> >
> > How do you use the
> > square root as operator
> > in python?
> > Dumb question, but
> > thanks anyway,
> > walter
> > --
> > W.W. van den Broek
> > e-mail:
> > vandenbroek@psyd.azr.nl
> > AZR-Dijkzigt          fax:
> > 010-4633217
> > afdeling psychiatrie
> > tel:          010-4639222
> > Postbus 2040          e-mail
> > vdbroekw@wxs.nl (thuis)
> > 3000 CA Rotterdam
> > homepage:
> > http://home.planet.nl/~vdbroekw
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From deirdre@deirdre.net  Fri Feb  2 08:41:07 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Fri, 2 Feb 2001 00:41:07 -0800 (PST)
Subject: [Tutor] Compiling Python Scripts
In-Reply-To: <000501c08cb1$cda1b1c0$0101a8c0@ccurrie>
Message-ID: <Pine.LNX.4.31.0102020037020.13368-100000@emperor.deirdre.org>

On Thu, 1 Feb 2001, Cameron wrote:

> I want to compile some of my Python scripts into executable programs
> to distribute to some friends who don't have the Python interpreter...
> is there any way to do this? I was unable to find the answer in the
> documentation.

The answer is, in part, dependent upon the platform -- which you didn't
specify.

_Deirdre




From jcm@bigskytel.com  Fri Feb  2 10:07:39 2001
From: jcm@bigskytel.com (David Porter)
Date: Fri, 2 Feb 2001 03:07:39 -0700
Subject: [Tutor] Reading and outputting  HTML files
In-Reply-To: <200102020157_MC2-C3F6-C82A@compuserve.com>; from NHYTRO@compuserve.com on Fri, Feb 02, 2001 at 01:56:52AM -0500
References: <200102020157_MC2-C3F6-C82A@compuserve.com>
Message-ID: <20010202030739.A10507@bigskytel.com>

* Sharriff Aina <NHYTRO@compuserve.com>:

> I have coded a CGI script that creates HTML files, strange thing is, when
> reading a HTML file, one created by the script or otherwise, I just get a
> very garbled page returned to the browser. 

You seem to be saying above that your browser is broken ("created by the
script or otherwise..."). Could you clarify you message? Also posting
example code and errors helps greatly.


David


From christophe.cuny@ants.co.uk  Fri Feb  2 11:16:46 2001
From: christophe.cuny@ants.co.uk (Cuny, Christophe (ANTS))
Date: Fri, 2 Feb 2001 11:16:46 -0000
Subject: [Tutor] Newbie questions with an anmbitious tweak!
Message-ID: <29897BB9AE72D411A89B0008C773175E4B74FF@BHISHMA>

Hello Tutor list.

First of all, thank you for existing. We newbies appreciate the work that
you guys put in supporting us.

I am new to programming (almost) and new to Python. At first sight, I
thought Python looked a lot easier than other languages. Whilst this is
still valid, I also realised that I would have some serious issues doing the
following:

1)	Creating Stand-alone exes for 32 bit Windows.
2)	Create a GUI for small apps I have in mind. 

So can I start with a basic question. In tutorials, I get referred to "using
a text editor such as notepad...". But using Python for windows I saw that
the "built-in" editor has full syntax highlighting. So the question is: do I
actually need another editor or are the tutorials referring to old versions
of Python?

I also notice that I have problems relating to what "components" or
"modules" are available and what they do.  Is there an IDE for Python
(windows) that has a proper browser-like utility for seeing the modules (and
perhaps their related help files or whatever) or is there no standard? From
my version of Python, I now it is possible to search for modules but I have
to know the name and Python seems to look only in the "system path" (?).

Generally, if I want to use modules from other people, must they be in a
specific sub-directory of Python or should I be ok accessing them from any
place were they may have been unpacked on my hard drive? Finally, is there
an editor (for Python in Windows) that would be able either to refer to a
library of commands or/and to complete command words as they are part-typed?

I also have a question on GUIs. I have read a bit about Tk but to the
newbie, constructing a user interface, for an application with menus and
windows, using what seems to be another language is daunting, especially
since trying to get to grips with core Python is enough for the newbie. It
may be a question of "patience my friend" but can I ask what the best and
most seamless approach would be to create such an interface and actively
link it to Python scripts? Has anyone ever developed a kind of RAD tool for
Python, that would also integrate GUIs? Or rather than using an external
language, is there such a thing as a Python module/extension that would
include this capability?

And if you think this is a long email, be aware that I have other huge
question marks hanging over COM access, about which I know so little, and
which would also be useful...guess I'll save that one till later huh?

Thank you for your help. I realise I am diving straight in with ambitious
targets, but that's what it's all about and your help will be greatly
appreciated.

Thank you

Christophe



***************************************************************************
This email message contains confidential information for the above addressee only.  If you are not the intended addressee you must not disclose or use the information in any manner whatsoever.

Any opinion or views contained in this email message are those of the sender, do not represent those of the Company in any way and reliance should not be placed upon its contents.

Unless otherwise stated this email message is not intended to be contractually binding.  Where an Agreement exists between our respective companies and there is conflict between the contents of this email message and the Agreement then the terms of that Agreement shall prevail.

Abbey National Treasury Services plc. Registered in England. Registered Office:  Abbey House, Baker Street, London NW1 6XL.  Company Registration No: 2338548.  Regulated by the SFA
***************************************************************************


From Lindsay.Davies@moonshine.co.uk  Fri Feb  2 13:16:41 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Fri, 2 Feb 2001 13:16:41 +0000
Subject: [Tutor] Reading and outputting  HTML files
In-Reply-To: <200102020157_MC2-C3F6-C82A@compuserve.com>
References: <200102020157_MC2-C3F6-C82A@compuserve.com>
Message-ID: <a0501040eb6a063115769@[195.102.186.233]>

On 2/2/01, Sharriff Aina wrote about '[Tutor] Reading and outputting 
HTML files':
>I have coded a CGI script that creates HTML files, strange thing is, when
>reading a HTML file, one created by the script or otherwise, I just get a
>very garbled page returned to the browser. Any clues? can someone help?
>this has been bugging me for 3 days now

You'll need to give us more information about the problem - what 
exactly do you get when you request a page? The problem could be any 
number of things, so until there's more detail, there's not much I 
can suggest other than: is your server configured correctly, are you 
outputting the appropriate headers, have you checked the script 
offline?

Best wishes,

Lindsay


From bseelinger@neteffectcorp.com  Fri Feb  2 15:52:14 2001
From: bseelinger@neteffectcorp.com (Seelinger, Bruce)
Date: Fri, 2 Feb 2001 10:52:14 -0500
Subject: [Tutor] String as a Variable?
Message-ID: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.com>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C08D30.1CF02260
Content-Type: text/plain;
	charset="iso-8859-1"

Another newbie question...

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

For eaxample, I have a the following:

<snip>

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

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

How can I represent the string as a variable?

Thanks in advance.




------_=_NextPart_001_01C08D30.1CF02260
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2652.35">
<TITLE>String as a Variable?</TITLE>
</HEAD>
<BODY>

<P><FONT FACE="Times New Roman">Another newbie question...<BR>
<BR>
Is there a way to have a string represent a variable.<BR>
<BR>
For eaxample, I have a the following:<BR>
<BR>
&lt;snip&gt;<BR>
<BR>
serial_number = '3'<BR>
print 'ip_address_serial_' + serial_number<BR>
ip_address_serial_3<BR>
<BR>
Now I want to use the string ip_address_serial_3 to pull<BR>
the value assigned to the variable of the same name.<BR>
<BR>
How can I represent the string as a variable?<BR>
<BR>
Thanks in advance.<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C08D30.1CF02260--


From abreu@penguinpowered.com  Fri Feb  2 16:09:15 2001
From: abreu@penguinpowered.com (Jose Alberto Abreu)
Date: Fri, 02 Feb 2001 10:09:15 -0600
Subject: [Tutor] Compiling Python Scripts
References: <Pine.LNX.4.31.0102020037020.13368-100000@emperor.deirdre.org>
Message-ID: <3A7ADBAB.62AE374@penguinpowered.com>

Deirdre Saoirse wrote:
> 
> On Thu, 1 Feb 2001, Cameron wrote:
> 
> > I want to compile some of my Python scripts into executable programs
> > to distribute to some friends who don't have the Python interpreter...
> > is there any way to do this? I was unable to find the answer in the
> > documentation.
> 
> The answer is, in part, dependent upon the platform -- which you didn't
> specify.
> 
> _Deirdre

OK, I have the same question, so I'll specify the platform: Windows

I already can cheerfully distribute my programs to my Linux using
friends, because practically all distributions install Python by default
(most of the times 1.5.2).
But in all honesty you cannot ask your grandmother to download Python
and go through the installation motions just so that she can run the
whizbang shopping list manager(TM) that you made for her...

It would be a lot easier if there was a way to incorporate the
interpreter, your program, and all required modules in a self-extracting
.exe 
That way granny would only need to doubleclick on the icon on her
windows desktop to run her whizbang shopping list manager(TM)

Probably this would require some closed source program like
InstallShield, but hopefully our resourceful and wise elders would have
already come to a Free(TM) solution.

----
Disclaimers: I do not make programs for my grandmother, I was just
trying to make a point. However Whizbang Shopping List Manager is (C)
and (TM) Jose Alberto Abreu 2001.  Free, of course is (C) and (TM)
Richard Stallman 1984.


From dsh8290@rit.edu  Fri Feb  2 16:23:03 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 2 Feb 2001 11:23:03 -0500
Subject: [Tutor] String as a Variable?
In-Reply-To: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.com>; from bseelinger@neteffectcorp.com on Fri, Feb 02, 2001 at 10:52:14AM -0500
References: <958398973B4A0343A904C2A4157EDEA54FDCE2@ATLEXC01.neteffect.neteffectcorp.com>
Message-ID: <20010202112302.B8120@harmony.cs.rit.edu>

On Fri, Feb 02, 2001 at 10:52:14AM -0500, Seelinger, Bruce wrote:
| Another newbie question...
| 
| Is there a way to have a string represent a variable.
| 
| For eaxample, I have a the following:
| 
| <snip>
| 
| serial_number = '3'
| print 'ip_address_serial_' + serial_number
| ip_address_serial_3
| 
| Now I want to use the string ip_address_serial_3 to pull
| the value assigned to the variable of the same name.
| 
| How can I represent the string as a variable?
| 

You can do this using exec, but it is not recommended.  exec is a
fairly slow statement, and it can have ugly side effects.  For
example, suppose you end up with a name that conflicts with a local or
even worse a global variable in your program?

The recommended technique is to use a dictionary instead.  You can
have a dict, say ip_address_serials, and use the serial_number's as
keys.

ip_address_serials = { }
serial_number = find_serial_number( )
ip_address_serials[ serial_number ] = \
	"whatever value you want associated with it"

for serial_number in ip_address_serials.keys() :
	print "ip_address_serial is:", serial_number

| Thanks in advance.
| 

HTH,
-D



From johnnyflynn@hotmail.com  Fri Feb  2 16:23:14 2001
From: johnnyflynn@hotmail.com (John Flynn)
Date: Fri, 02 Feb 2001 11:23:14 -0500
Subject: [Tutor] New to all of this
Message-ID: <F124oo9tjxqxPs68K8r00003572@hotmail.com>

        Hi there everyone. I am wondering if anyone out there knows where I 
might be able to find some source code for a simple (very simple) and small 
text editor done completely in Python. I would like to be able to refrence 
this code to help learn. The things that I would need (I am totally new to 
all of this:)) would be something simple that would draw it's own window 
(not Microsoft's dumb default one) and take the text that is typped in and 
save it as .txt, and be able to open .txt files. That is about all, nothing 
more than the one that comes with Windows. I just want to use it as a tool 
to help learn the different actions associated with opening files, saving 
files, drawing a window and possibly (A LONG WAY DOWN THE ROAD) be able to 
write my own (Open Source Of Course!, Hey I'm a poet) text editor. Any help 
would be greatly appreciated.

Thanks,John Flynn
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From abreu@penguinpowered.com  Fri Feb  2 16:39:55 2001
From: abreu@penguinpowered.com (Jose Alberto Abreu)
Date: Fri, 02 Feb 2001 10:39:55 -0600
Subject: [Tutor] Newbie questions with an anmbitious tweak!
References: <29897BB9AE72D411A89B0008C773175E4B74FF@BHISHMA>
Message-ID: <3A7AE2DB.2C475D7D@penguinpowered.com>

"Cuny, Christophe (ANTS)" wrote:

> First of all, thank you for existing. We newbies appreciate the work that
> you guys put in supporting us.

We support each other... Although the List Moms put on a gargantuan
ammount of patience and wisdom with the rest of us (and we all love them
for that!), you are expected to answer your fellow newbie questions as
your knowledge of python grows...
  
> So can I start with a basic question. In tutorials, I get referred to "using
> a text editor such as notepad...". But using Python for windows I saw that
> the "built-in" editor has full syntax highlighting. So the question is: do I
> actually need another editor or are the tutorials referring to old versions
> of Python?

Its based on your preference, actually. Some people like to use
incredibly complex (yet infinetly configurable) text editors dating back
to the stone age. Some prefer to use the newer Integrated Developement
Enviroments like IDLE.
By the way check out Boa Constructor:
http://sourceforge.net/projects/boa-constructor
Its still green, but its gonna be awesome.
 
> I also have a question on GUIs. I have read a bit about Tk but to the
> newbie, constructing a user interface, for an application with menus and
> windows, using what seems to be another language is daunting, especially
> since trying to get to grips with core Python is enough for the newbie. It
> may be a question of "patience my friend" 

It is : )
But dont worry, you will with time see Tkinter (and later WxPython) as
your friend.

> but can I ask what the best and
> most seamless approach would be to create such an interface and actively
> link it to Python scripts? Has anyone ever developed a kind of RAD tool for
> Python, that would also integrate GUIs? Or rather than using an external
> language, is there such a thing as a Python module/extension that would
> include this capability?

Boa Constructor and other proyects are aiming to do this in the near
future. Also the people at ActiveState are developing a plugin for
Microsoft's Visual Studio to code in Python or Perl, but I would be
extremely leery of using Visual Studio for anything.
 
> Thank you for your help. I realise I am diving straight in with ambitious
> targets, but that's what it's all about and your help will be greatly
> appreciated.

Its ok to be ambitious, just remember that even Olympic runners learned
to walk the same way we all did.


-----
Jose Alberto Abreu  -   abreu@penguinpowered.com


From mr804@users.757.org  Fri Feb  2 17:07:08 2001
From: mr804@users.757.org (Mr 804)
Date: Fri, 2 Feb 2001 12:07:08 -0500 (EST)
Subject: [Tutor] First real program
Message-ID: <Pine.BSO.4.21.0102021202510.12443-100000@users.757.org>

Hello,

  I'm trying to write a small python script to do some checks
on a unix password file. I've run into a stubling block. I think I don't
understand list 100%. I've included my code with commends on the problem
part.

******************************************
import sys
import string
import re

### open files read it in 1 line at a time 

print "Loading the password file."
try:
	f = open('/etc/passwd','r')
	s = f.readlines()
	f.close()
	print "loaded."
	print ""
except IOError:
	print "can't open the password file. Quiting."
	sys.exit()
### How many elements do we got?
t = len(s) 
print "There are %d lines." % t
## sort it
s.sort()
# Clean the file up. Don't need no white space before or after
# also convert everything to lower case.

list = []
name = []

for i in s:
	i = string.lower(string.rstrip(string.strip(i)))
	list.append(i)
	name.append(string.splitfields(i,":"))
^--

  This part should make everything lower case, strip white space. 
   name[] should be a list of NAMES, but I don't think I'm doing that
  correctly? I want the user name and no othe fields after the first
  : . ? if I did print name[0] it should print the first name in the
  password file. but it's just printing the while line.



	



From clickron@webtv.net  Fri Feb  2 17:50:30 2001
From: clickron@webtv.net (clickron@webtv.net)
Date: Fri, 2 Feb 2001 12:50:30 -0500 (EST)
Subject: [Tutor] opening programs
Message-ID: <18403-3A7AF366-573@storefull-164.iap.bryant.webtv.net>

I have windows 98 ie5.0 and downloaded python2.0. To open a program
(hello.py) while in idle I click file/open/documents/hello/open
is there a different or quicker way to do this? 

I've tried typing, python hello.py, in idle and command but I just get
the error message. I really new to this and would appreciate any help. 

 Ron



From Lindsay.Davies@moonshine.co.uk  Fri Feb  2 18:39:11 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Fri, 2 Feb 2001 18:39:11 +0000
Subject: [Tutor] String as a Variable?
Message-ID: <a0501041cb6a0af3f40e3@[195.102.186.233]>

--============_-1230983297==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

Why not use a dictionary?

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

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


Best wishes,

Lindsay


On 2/2/01, Seelinger, Bruce wrote about '[Tutor] String as a Variable?':
>Another newbie question...
>
>Is there a way to have a string represent a variable.
>
>For eaxample, I have a the following:
>
><snip>
>
>serial_number = '3'
>print 'ip_address_serial_' + serial_number
>ip_address_serial_3
>
>Now I want to use the string ip_address_serial_3 to pull
>the value assigned to the variable of the same name.
>
>How can I represent the string as a variable?
>
>Thanks in advance.

--============_-1230983297==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
 --></style><title>Re: [Tutor] String as a
Variable?</title></head><body>
<div>Why not use a dictionary?</div>
<div><br></div>
<div><font color="#000000">snv = {</font><font
color="#007F00">'sn_1'</font><font color="#000000"> :
123,</font><font color="#007F00"> 'sn_2'</font><font color="#000000">
: 234,</font><font color="#007F00"> 'sn_3'</font><font
color="#000000"> : 345}<br>
serial_number =</font><font color="#007F00"> '3'</font></div>
<div><font color="#000000"><br>
<b>try</b>:<br>
<b><x-tab>&nbsp;&nbsp;&nbsp; </x-tab>print</b> snv[</font><font
color="#007F00">'sn_'</font><font color="#000000"> +
serial_number]<br>
<b>except</b> KeyError, missing_key:</font></div>
<div><font
color="#000000"><b><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>print</b></font><font color="#007F00"> &quot;The serial number
'%s' is missing.&quot;</font><font color="#000000"> %
serial_number</font></div>
<div><br></div>
<div><br></div>
<div>Best wishes,</div>
<div><br></div>
<div>Lindsay</div>
<div><br></div>
<div><br></div>
<div>On 2/2/01, Seelinger, Bruce wrote about '[Tutor] String as a
Variable?':</div>
<blockquote type="cite" cite>Another newbie question...<br>
<br>
Is there a way to have a string represent a variable.<br>
<br>
For eaxample, I have a the following:<br>
<br>
&lt;snip&gt;<br>
</blockquote>
<blockquote type="cite" cite>serial_number = '3'<br>
print 'ip_address_serial_' + serial_number<br>
ip_address_serial_3<br>
<br>
Now I want to use the string ip_address_serial_3 to pull<br>
the value assigned to the variable of the same name.</blockquote>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite>How can I represent the string as a
variable?</blockquote>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite>Thanks in advance.</blockquote>
<div><br></div>
</body>
</html>
--============_-1230983297==_ma============--


From randrews@planhouse.com  Fri Feb  2 18:45:23 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 2 Feb 2001 12:45:23 -0600
Subject: [Tutor] opening programs
References: <18403-3A7AF366-573@storefull-164.iap.bryant.webtv.net>
Message-ID: <004001c08d48$4de9bee0$dc00a8c0@Planhouse5>

As long as your hello.py file is saved in a directory (folder) that Python
knows to look in, you should be able to type

>>>import hello.py

in Idle to run the program.

Hope this helps,
Rob Andrews

----- Original Message -----
From: <clickron@webtv.net>
To: <tutor@python.org>
Sent: Friday, February 02, 2001 11:50 AM
Subject: [Tutor] opening programs


> I have windows 98 ie5.0 and downloaded python2.0. To open a program
> (hello.py) while in idle I click file/open/documents/hello/open
> is there a different or quicker way to do this?
>
> I've tried typing, python hello.py, in idle and command but I just get
> the error message. I really new to this and would appreciate any help.
>
>  Ron
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From curtis.larsen@Covance.Com  Fri Feb  2 18:49:56 2001
From: curtis.larsen@Covance.Com (Curtis Larsen)
Date: Fri, 02 Feb 2001 12:49:56 -0600
Subject: [Tutor] List Dup-Elim Method?
Message-ID: <sa7aad1a.004@madmail.truax.covance.com>

Is there an easy way to eliminate duplicate elements in a list?
(A list method I missed, maybe?)


Thanks!
Curtis
 


-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.


From shaleh@valinux.com  Fri Feb  2 18:59:46 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 02 Feb 2001 10:59:46 -0800 (PST)
Subject: [Tutor] List Dup-Elim Method?
In-Reply-To: <sa7aad1a.004@madmail.truax.covance.com>
Message-ID: <XFMail.20010202105946.shaleh@valinux.com>

On 02-Feb-2001 Curtis Larsen wrote:
> Is there an easy way to eliminate duplicate elements in a list?
> (A list method I missed, maybe?)
>

no, either do:

if element not in list:
        list.append(element)

or write a function to return a list with the cruft removed. 


From shaleh@valinux.com  Fri Feb  2 19:00:39 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 02 Feb 2001 11:00:39 -0800 (PST)
Subject: [Tutor] List Dup-Elim Method?
In-Reply-To: <sa7aad1a.004@madmail.truax.covance.com>
Message-ID: <XFMail.20010202110039.shaleh@valinux.com>

On 02-Feb-2001 Curtis Larsen wrote:
> Is there an easy way to eliminate duplicate elements in a list?
> (A list method I missed, maybe?)
> 

or maybe you should use a hash?

hash[key] = 1

hash will only have one instance of the key and hash.keys() returns the list.


From deirdre@deirdre.net  Fri Feb  2 19:12:07 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Fri, 2 Feb 2001 11:12:07 -0800 (PST)
Subject: [Tutor] Compiling Python Scripts
In-Reply-To: <3A7ADBAB.62AE374@penguinpowered.com>
Message-ID: <Pine.LNX.4.31.0102021109420.17591-100000@emperor.deirdre.org>

OK, I'm not a Windows user, but I distinctly recall that there WAS a way
of doing it -- it wasn't compiled, it was globbing the whole thing
together.

I *think* what you're looking for is at:

http://starship.python.net/crew/gmcm/standalones.html

Afaik, it's only Windows and Linux and not other OSes; I will probably
look into working on the MacOS (9 and X) support for this.

On Fri, 2 Feb 2001, Jose Alberto Abreu wrote:

> Deirdre Saoirse wrote:
> >
> > On Thu, 1 Feb 2001, Cameron wrote:
> >
> > > I want to compile some of my Python scripts into executable programs
> > > to distribute to some friends who don't have the Python interpreter...
> > > is there any way to do this? I was unable to find the answer in the
> > > documentation.
> >
> > The answer is, in part, dependent upon the platform -- which you didn't
> > specify.
>
> OK, I have the same question, so I'll specify the platform: Windows
>
> I already can cheerfully distribute my programs to my Linux using
> friends, because practically all distributions install Python by default
> (most of the times 1.5.2).
> But in all honesty you cannot ask your grandmother to download Python
> and go through the installation motions just so that she can run the
> whizbang shopping list manager(TM) that you made for her...
>
> It would be a lot easier if there was a way to incorporate the
> interpreter, your program, and all required modules in a
> self-extracting .exe That way granny would only need to doubleclick on
> the icon on her windows desktop to run her whizbang shopping list
> manager(TM)
>
> Probably this would require some closed source program like
> InstallShield, but hopefully our resourceful and wise elders would have
> already come to a Free(TM) solution.



From randrews@planhouse.com  Fri Feb  2 21:00:14 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 2 Feb 2001 15:00:14 -0600
Subject: [Tutor] List Dup-Elim Method?
References: <sa7aad1a.004@madmail.truax.covance.com>
Message-ID: <002e01c08d5b$24bbc640$dc00a8c0@Planhouse5>

I'm working on a similar problem, but more complicated and involving a
zillion real world variables.  I haven't fully worked it out yet, but here
are some thoughts that might help you out.

If the list isn't 200,000 items long or something, you can try a brute force
approach.  For each item of the list, compare the item to each other item,
deleting duplicates as you go, then drop a copy of that item into a new
list.

Or, do the same thing, but instead of deleting the dupes as you go, move
them into a *dupes* list, and copy the first item into a new list.

if mylist[0:1] == mylist[1:2]:
    mylist[1:2] = []

This code compares an item in a list to the item next to it.  If the two
items are equivalent, the second item is essentially removed.

Hope this helps a bit,
Rob Andrews

> Is there an easy way to eliminate duplicate elements in a list?
> (A list method I missed, maybe?)
>
>
> Thanks!
> Curtis
>




From tuckerg@acm.org  Sat Feb  3 01:51:34 2001
From: tuckerg@acm.org (Gregory Tucker)
Date: Sat, 3 Feb 2001 10:51:34 +0900
Subject: [Tutor] Reading from a GUI
In-Reply-To: <000401c08659$4387f9d0$0300000a@budgester>
Message-ID: <NIEOLFMNKKMFANJFMKBAMEMDDCAA.tuckerg@acm.org>

Hi,

I think we would all save a lot of time if there were a clear answer to your
question. I can only throw in a couple observations.

1. There is actually a book called "Python and Tkinter Programming". From
this standpoint, this is the most well-documented. Check out your favorite
bookstore for more information.

2. There are a few pages that discuss this:

http://www.python.org/doc/FAQ.html
http://wxpython.org/
http://www.wxwindows.org/
http://www.scriptics.com/

3. Personally, I haven't done enough GUI programming in EITHER environment
to answer the question.

4. In many cases the better question is "What is the best way to build
active web pages in Python?" You can develop CGI scripts for simpler stuff.
You can use Zope for more sophisticated environments, but with a higher
learning curve. I am looking for a way to get out of the (painfully)
sessionless nature CGI without the overhead of Zope. PSP (a Python version
of PHP?) may offer an alternative. Regardless, an HTML interface is too
limiting for some applications that could be done better with WxPython or
Tkinter.

It looks like WxPython is is easier to use and more powerful in general. And
it looks like the cross-platform support is good enough for most developers.
When I am ready to tackle GUI programming under Python, even though I own
the above book, I will probably look first into WxPython.

But I would appreciate feedback on this as well.

Regards,
Greg




---
  Gregory Tucker
  Tokyo, Japan
  mailto:tuckerg@acm.org

  These opinions are my own.

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Budgester
> Sent: Thursday, January 25, 2001 7:59 AM
> To: 'D-Man'
> Subject: RE: [Tutor] Reading from a GUI
>
>
>
>
> >D-Man Wrote :
> >
> >What is meant by "escape code" can differ by useage.  For example, in
> >Eiffel you would use "%N" as the excape code for a newline.  \012 is
> >the octal value of the character.  0xA is the hexadeciaml value and 10
> >is the decimal value.  In C/C++/Java/Perl and Python \n is used as the
> >escape for a newline, but with the proper conversion you can use any
> >of these.
>
> They are the escape code I was looking for.
>
> >To "read from" a GUI you need to check the docs of the gui you are
> >using.  In GTK, for example, there is a funciton get_text in the
> >Gtk.Text widget (or some similar name).  The function returns a string
> >object.
>
> I'm currently using Tkinter, but from reading this list it seems like the
> most popular Toolkit is GTK, what is the general preference for python,
> i.e. best documentation, ease of use, samples etc < I'm not
> trying to start
> a holy war here, just peoples experiences ;-) >
>
>
> >import string
> >
> >my_str = text_widget.get_text()
> >modified_str = string.replace( my_str, "\n" , "<br>" )
> >print my_str
> >pirnt modified_str
>
> pretty much exactly the code I was after.
>
> >HTH,
>
> Loads thanks
>
> I'll let you know how it goes.
>
> >-D
>
> Budgester
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From DOUGS@oceanic.com  Sat Feb  3 01:58:31 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Fri, 2 Feb 2001 15:58:31 -1000
Subject: [Tutor] List Dup-Elim Method?
Message-ID: <8457258D741DD411BD3D0050DA62365907A5B6@huina.oceanic.com>

I think the Python idiom I've seen for this uses a dictionary as a temporary
holder.  The dictionary needs unique keys so the following will leave a list
without duplicates:

theDict = {}
theList = [1, 2, 4, 6, 21, 3, 8, 5, 3, 8]
for element in theList:
    theDict[element] = None
theList = theDict.keys()

-Doug-

> -----Original Message-----
> From: Curtis Larsen [mailto:curtis.larsen@Covance.Com]
> Sent: Friday, February 02, 2001 8:50 AM
> To: tutor@python.org
> Subject: [Tutor] List Dup-Elim Method?
> 
> 
> Is there an easy way to eliminate duplicate elements in a list?
> (A list method I missed, maybe?)
> 
> 
> Thanks!
> Curtis
>  
> 
> 
> -----------------------------------------------------
> Confidentiality Notice: This e-mail transmission 
> may contain confidential or legally privileged 
> information that is intended only for the individual 
> or entity named in the e-mail address. If you are not 
> the intended recipient, you are hereby notified that 
> any disclosure, copying, distribution, or reliance 
> upon the contents of this e-mail is strictly prohibited. 
> 
> If you have received this e-mail transmission in error, 
> please reply to the sender, so that we can arrange 
> for proper delivery, and then please delete the message 
> from your inbox. Thank you.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From AquaRock7@aol.com  Sat Feb  3 03:34:01 2001
From: AquaRock7@aol.com (AquaRock7@aol.com)
Date: Fri, 2 Feb 2001 22:34:01 EST
Subject: [Tutor] RE: user interaction
Message-ID: <c9.ce89898.27acd629@aol.com>

--part1_c9.ce89898.27acd629_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

The python equivalent of INPUT in BASIC is raw_input() and input().  Use it 
:


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

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

There ya go!

~D

--part1_c9.ce89898.27acd629_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2>The python equivalent of INPUT in BASIC is raw_input() and input(). &nbsp;Use it 
<BR>like this</BLOCKQUOTE>:</FONT><FONT  COLOR="#000000" SIZE=3 FAMILY="SANSSERIF" FACE="Arial" LANG="0">
<BR>
<BR>
<BR>inputstr = raw_input("What is your name? ") # this is for text entry
<BR>print inputstr
<BR>
<BR>inputnum = input("What is your age?") # for numbers only - text raises error
<BR>print age
<BR>
<BR>There ya go!
<BR>
<BR>~D</FONT></HTML>

--part1_c9.ce89898.27acd629_boundary--


From ccurrie@lcc.net  Sat Feb  3 04:25:56 2001
From: ccurrie@lcc.net (Cameron)
Date: Fri, 2 Feb 2001 22:25:56 -0600
Subject: [Tutor] Compiling Python Scripts
References: <20010202170118.A071DF031@mail.python.org>
Message-ID: <001801c08d99$68ac2a00$0101a8c0@ccurrie>

Ah, that had slipped my mind completely. I'd like to know the process for
compiling my scripts on Windows platforms. Knowing the process on Linux
would be great as well, but I give priority to Windows as more of my friends
use it.

Also, does anyone know of a free web hosting service that allows you to use
your own Python CGI scripts, and that also has FTP access? I have gone
through tons of search engine results and have yet to find a satisfying
service.

> Deirdre Saoirse wrote:
> >
> > On Thu, 1 Feb 2001, Cameron wrote:
> >
> > > I want to compile some of my Python scripts into executable programs
> > > to distribute to some friends who don't have the Python interpreter...
> > > is there any way to do this? I was unable to find the answer in the
> > > documentation.
> >
> > The answer is, in part, dependent upon the platform -- which you didn't
> > specify.
> >
> > _Deirdre




From jcm@bigskytel.com  Thu Feb  1 06:02:32 2001
From: jcm@bigskytel.com (David Porter)
Date: Wed, 31 Jan 2001 23:02:32 -0700
Subject: [Tutor] os.popen: writing  to
In-Reply-To: <001301c08b7a$ab8a1c40$2c829e89@poseidon>; from jpl@global.co.za on Wed, Jan 31, 2001 at 01:40:54PM +0200
References: <001301c08b7a$ab8a1c40$2c829e89@poseidon>
Message-ID: <20010131230231.A3732@bigskytel.com>

* James Lockley <jpl@global.co.za>:
<...>
> i now want to go to the next step and get rid of the batch files... i need
> to open a pipe to a command and then write the command arguments to it.
<...>
> (this in a dos window works fine: D:\Work\Current>c:\abaqus\5.8-14\abaqus.exe post)

How about:

import os
os.system('c:\\abaqus\\5.8-14\\abaqus.exe post')


David


From deirdre@deirdre.net  Sat Feb  3 05:19:47 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Fri, 2 Feb 2001 21:19:47 -0800 (PST)
Subject: [Tutor] Compiling Python Scripts
In-Reply-To: <001801c08d99$68ac2a00$0101a8c0@ccurrie>
Message-ID: <Pine.LNX.4.31.0102022116250.22028-100000@emperor.deirdre.org>

On Fri, 2 Feb 2001, Cameron wrote:

> Ah, that had slipped my mind completely. I'd like to know the process
> for compiling my scripts on Windows platforms. Knowing the process on
> Linux would be great as well, but I give priority to Windows as more
> of my friends use it.

See the other reference.

I'm somewhat at a loss as are many regulars in that we do a lot of Unix,
but not Windows. I spend my day time on Linux and night time on MacOS X.

> Also, does anyone know of a free web hosting service that allows you
> to use your own Python CGI scripts, and that also has FTP access? I
> have gone through tons of search engine results and have yet to find a
> satisfying service.

I don't know of a free one; for deirdre.net I use he.net which has a
really excellent value package (imho):
http://www.he.net/spaceservices.html

I've been with them for two years. I've taken a tour of their colo space
and it's *quite* impressive.

No affiliation, yada yada yada, just been there > 2 years and happy. I
mean, how many places give you crontab access?

_Deirdre



From sheila@thinkspot.net  Sat Feb  3 05:27:43 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 02 Feb 2001 21:27:43 -0800
Subject: [Tutor] Compiling Python Scripts
In-Reply-To: <001801c08d99$68ac2a00$0101a8c0@ccurrie>
References: <20010202170118.A071DF031@mail.python.org> <001801c08d99$68ac2a00$0101a8c0@ccurrie>
Message-ID: <20010203052807.9846BF16D@mail.python.org>

On Fri, 2 Feb 2001 22:25:56 -0600, "Cameron" <ccurrie@lcc.net>  wrote about
[Tutor] Compiling Python Scripts:

:Also, does anyone know of a free web hosting service that allows you to use
:your own Python CGI scripts, and that also has FTP access? I have gone
:through tons of search engine results and have yet to find a satisfying
:service.

Man, I would be seriously interested in that! Right now, I have an account at
free.prohosting.com, but they only allow Perl scripts. You can write and
install your own, but only Perl, so far as I can tell. And I don't really
write Perl.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From trainlist@yahoo.com  Sat Feb  3 06:39:43 2001
From: trainlist@yahoo.com (trainlist@yahoo.com)
Date: Fri, 02 Feb 2001 22:39:43 -0800
Subject: [Tutor] List of Buyers for Training Services & Products
Message-ID: <E14OwMJ-0007Vf-01@mail2.uniserve.com>

Hi,

Recently you had talked to us about some of the courseware materials we carry for the 
needs of your customers.  I thought you might also be interested in a proprietary list
of buyers for training related services and products we have developed in house.  
Our list is comprehensive and includes tons of prospects you can reach right now to market
your services and products to.  I'd be happy to answer any questions you may have.
Feel free to e-mail me with your inquiries, or call 780-998-4066.

We also have lists for Human Resources Departments, Personnel contacts, etc.


Best Regard

D. Adams



From deirdre@deirdre.net  Sat Feb  3 09:15:32 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Sat, 3 Feb 2001 01:15:32 -0800 (PST)
Subject: Ugh! Re: [Tutor] List of Buyers for Training Services & Products
In-Reply-To: <E14OwMJ-0007Vf-01@mail2.uniserve.com>
Message-ID: <Pine.LNX.4.31.0102030114420.22028-100000@emperor.deirdre.org>

Sorry about the spammer. Abuse has been contacted; his email address has
been blacklisted on the list and he's been unsubscribed.

We'll now return you to your regular list....

_Deirdre (listmom)




From tim.one@home.com  Sat Feb  3 09:43:14 2001
From: tim.one@home.com (Tim Peters)
Date: Sat, 3 Feb 2001 04:43:14 -0500
Subject: [Tutor] List Dup-Elim Method?
In-Reply-To: <002e01c08d5b$24bbc640$dc00a8c0@Planhouse5>
Message-ID: <LNBBLJKPBEHFEDALKOLCKEDMINAA.tim.one@home.com>

If the elements of a list are hashable, the method using a dict will be by
far the fastest if the list is large.

If the elements are not hashable (for example, a list of lists), but can be
sorted, still much quicker than brute force (yet still much slower than
using a temporary dict!) is this:

def dupfree(x):
    """Remove all duplicates from list x, in place.

    The elements of x must enjoy a total ordering.
    """

    n = len(x)
    if n > 1:
        x.sort()
        last = x[0]
        i = avail = 1
        while i < n:
            if x[i] != last:
                x[avail] = last = x[i]
                avail += 1
            i += 1
        del x[avail:]

That requires Python 2.0, because of the "+=" thingies.

Example:

>>> x = [[1, 2], [3, 4]]
>>> x *= 10
>>> x
[[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4],
 [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4],
 [1, 2], [3, 4], [1, 2], [3, 4]]
>>> dupfree(x)
>>> x
[[1, 2], [3, 4]]
>>>

How does it work?  Sorting the list brings all the equal elements next to
each other.  (Note:  Many sorting routines don't work very quickly when
there are lots of equal elements, but Python's does.  I know that because I
wrote Python's list.sort() <wink>.)

After all the equal elements are adjacent, it just marches across the list
once, keeping track of when the list element at index i *changes*.  When it
does, it moves that not-seen-before element toward the front of the list,
and moves on skipping over the chunk of elements equal to *it*.  Finally, it
gets rid of the list positions no longer needed (the "del" stmt).

Of course there's nothing to do if the list doesn't have at least two
elements to start, so it checks for that first.  It *has* to avoid going
into the main body if the list is empty, because then "last = x[0]" would
blow up.  Since it has to check for that anyway, it doesn't cost any more to
make sure there are at least two things in the list.

This isn't an easy algorithm -- the steps are delicate.  If you can use the
dict method instead, do so!

what-you-can-assume-constrains-what-you-can-do-ly y'rs  - tim



From clickron@webtv.net  Sat Feb  3 15:11:08 2001
From: clickron@webtv.net (clickron@webtv.net)
Date: Sat, 3 Feb 2001 10:11:08 -0500 (EST)
Subject: [Tutor] opening programs
Message-ID: <3275-3A7C1F8C-5610@storefull-168.iap.bryant.webtv.net>

>As long as your hello.py file is saved in a >directory (folder) that
Python knows to >look in, you should be able to type 
>>>import hello.py 
>in Idle to run the program. 
>Hope this helps, 
>Rob Andrews

I'm afraid that doesn't work. Do I have to learn dos so I can set the
path? If there is an easy tutorial on how to do this let me know please
I'm really getting discouraged.

Ron



From gcs@agentsinside.com  Sat Feb  3 15:45:09 2001
From: gcs@agentsinside.com (GCS)
Date: Sat, 3 Feb 2001 16:45:09 +0100
Subject: [Tutor] Newbie, get array from the url field
Message-ID: <20010203164509.A11570@esparrall.udg.es>

Hello,

 I would like to do a form handling. The URL looks like this:
http://somewhere/somedir/somescript.py?variable[]=value1&variable[]=value2

How can I get the value1 and value2 in an array? If there would be only one
'variable[]', then
list=cgi.SvFormContentDict()
if list.has_key("gcs"):
        text=list["gcs"]

enough. But I get problems because of there are more than values ofcourse.

Thanks all the replies in advance,
				GCS
Ps: Is the list really no searchable?


From AquaRock7@aol.com  Sat Feb  3 18:47:55 2001
From: AquaRock7@aol.com (AquaRock7@aol.com)
Date: Sat, 3 Feb 2001 13:47:55 EST
Subject: [Tutor] Re: opening programs
Message-ID: <55.10b44c49.27adac5b@aol.com>

--part1_55.10b44c49.27adac5b_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

       I am assuming you rin Windows -- you mentioned DOS.
       Go to your C:\ directory.  There should be a file called 
"AUTOEXEC.BAT".  Open it with Notepad.  Mine looks like this:

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

       The first line is for my anti-virus software -- calls startup scan.  
The secnod line tells DOS not to display what it is doing on the screen, only 
display what you tell it to display (using the DOS print command).  The third 
is my sound card settings.  The fourth is the path variable, thats what we 
are intrested in.
       Add the following line to your path statement:  
"C:\yourPythonDirectory" (w/o the quotes).  Now my path statement looks like 
this:  for example, your path statement could be:  PATH=%PATH%;"C:\Python".  
Now, when you type python at the command prompt, you should get the 
interpreter prompt ">>>".
       If you do not have a path statement, create one.  Put it on the lowest 
possible line but above a line that says "win" (if there is a line called win 
- if not just do it on the last line.)
       If you do not have an AUTOEXEC.BAT file, don't worry, just create one.
       Now, in order to run your program, change to the directory where the 
program is located.  Do this by typing "cd\" at the dos prompt.  Now you are 
at the root directory (C:\>).  Now type "cd python\prog" or whatever 
directory the program is located.  Now your prompt should look something like 
this: "C:\Python\pyprog>"  Now type "python hello.py" to run the program.  
(FYI what dos says is open hello.py with the program python (the 
interpreter).)
       Tell me if that didnt work.
~Dustin

--part1_55.10b44c49.27adac5b_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I am assuming you rin Windows -- you mentioned DOS.
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Go to your C:\ directory. &nbsp;There should be a file called 
<BR>"AUTOEXEC.BAT". &nbsp;Open it with Notepad. &nbsp;Mine looks like this:
<BR>
<BR>@C:\PROGRA~1\NORTON~1\NAVDX.EXE /Startup
<BR>@Echo Off
<BR>Set Blaster= A220 I5 D1
<BR>PATH=%PATH%;"C:\Python";"C:\qb45"
<BR>
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The first line is for my anti-virus software -- calls startup scan. &nbsp;
<BR>The secnod line tells DOS not to display what it is doing on the screen, only 
<BR>display what you tell it to display (using the DOS print command). &nbsp;The third 
<BR>is my sound card settings. &nbsp;The fourth is the path variable, thats what we 
<BR>are intrested in.
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add the following line to your path statement: &nbsp;
<BR>"C:\yourPythonDirectory" (w/o the quotes). &nbsp;Now my path statement looks like 
<BR>this: &nbsp;for example, your path statement could be: &nbsp;PATH=%PATH%;"C:\Python". &nbsp;
<BR>Now, when you type python at the command prompt, you should get the 
<BR>interpreter prompt "&gt;&gt;&gt;".
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If you do not have a path statement, create one. &nbsp;Put it on the lowest 
<BR>possible line but above a line that says "win" (if there is a line called win 
<BR>- if not just do it on the last line.)
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If you do not have an AUTOEXEC.BAT file, don't worry, just create one.
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Now, in order to run your program, change to the directory where the 
<BR>program is located. &nbsp;Do this by typing "cd\" at the dos prompt. &nbsp;Now you are 
<BR>at the root directory (C:\&gt;). &nbsp;Now type "cd python\prog" or whatever 
<BR>directory the program is located. &nbsp;Now your prompt should look something like 
<BR>this: "C:\Python\pyprog&gt;" &nbsp;Now type "python hello.py" to run the program. &nbsp;
<BR>(FYI what dos says is open hello.py with the program python (the 
<BR>interpreter).)
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tell me if that didnt work.
<BR>~Dustin</FONT></HTML>

--part1_55.10b44c49.27adac5b_boundary--


From wheelege@tsn.cc  Sun Feb  4 01:07:27 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Sun, 4 Feb 2001 12:07:27 +1100
Subject: [Tutor] opening programs
References: <3275-3A7C1F8C-5610@storefull-168.iap.bryant.webtv.net>
Message-ID: <007f01c08e46$d79205e0$a410fea9@glen>

  If all your trying to do is run a script, you can do it within the
environment your working (i.e IDLE, Activestate Activepython) if your
writing them as text files then saving then as *.py files then you can still
open them in these programs then choose 'Run Script' from one of the menus.
  I missed all the previous messages on this, so if I am totally unhelpful -
sorry :)

  Glen.


----- Original Message -----
From: <clickron@webtv.net>
To: <tutor@python.org>
Sent: Sunday, February 04, 2001 2:11 AM
Subject: [Tutor] opening programs


> >As long as your hello.py file is saved in a >directory (folder) that
> Python knows to >look in, you should be able to type
> >>>import hello.py
> >in Idle to run the program.
> >Hope this helps,
> >Rob Andrews
>
> I'm afraid that doesn't work. Do I have to learn dos so I can set the
> path? If there is an easy tutorial on how to do this let me know please
> I'm really getting discouraged.
>
> Ron
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From wheelege@tsn.cc  Sun Feb  4 12:28:31 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Sun, 4 Feb 2001 23:28:31 +1100
Subject: [Tutor] Tkinter - Destroying windows, destroying widgets
Message-ID: <001801c08ea5$fcbf08e0$a410fea9@glen>

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C08F02.2F800700
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hey all,

  I was just writing up a little tkinter app (a game, actually) and I =
have hit a wall.  My predicament, is that I want to destroy an object =
(right word?) but I want to do it in a function...for example in this =
code :

from Tkinter import *

def die():
    l.destroy() ## here is the problem - root.l.destroy() does not work =
either - I think since variables are local in functions it doesn't have =
any clue as to the existence of the label "l"
    print 'yo'    =20
    raw_input("hi")

root =3D Tk()
root.title('jim')
l =3D Label(root, text=3D'hi im root').pack()
second =3D Toplevel(root)
b =3D Button(root, text=3D'yo', command=3Ddie).pack()

mainloop()

  No matter how hard I try I cannot kill the label "l" using the button, =
and have it do other things as well.  Say I wanted to destroy a widget =
in a different window??  That label is in the same toplevel.  I just =
know there is a way to say something akin to "In the widget 'root' is a =
widget 'l' - kill it" but for the life of me I cannot find it.  You =
can't pass a widget as an argument using lambda, either - I tried tho :)
  I've looked in John Grayson's book and the python docs but I can't =
find anything.  Help!

  Thanks,
  Glen.

------=_NextPart_000_0015_01C08F02.2F800700
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hey all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I was just writing up a little tkinter app (a game, =
actually) and I=20
have hit a wall.&nbsp; My predicament, is that I want to destroy an =
object=20
(right word?) but I want to do it in a function...for example in this =
code=20
:</DIV>
<DIV>&nbsp;</DIV>
<DIV>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>def die():<BR>&nbsp;&nbsp;&nbsp; l.destroy() ## here is the problem =
-=20
root.l.destroy() does not work either - I think since variables are =
local in=20
functions it doesn't have any clue as to the existence of the label=20
"l"<BR>&nbsp;&nbsp;&nbsp; print 'yo'&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; raw_input("hi")</DIV>
<DIV>&nbsp;</DIV>
<DIV>root =3D Tk()<BR>root.title('jim')<BR>l =3D Label(root, text=3D'hi =
im=20
root').pack()<BR>second =3D Toplevel(root)<BR>b =3D Button(root, =
text=3D'yo',=20
command=3Ddie).pack()</DIV>
<DIV>&nbsp;</DIV>
<DIV>mainloop()</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; No matter how hard I try I cannot kill the label "l" using =
the=20
button, and have it do other things as well.&nbsp; Say I wanted&nbsp;to =
destroy=20
a widget in a different window??&nbsp; That label is in the same =
toplevel.&nbsp;=20
I just know there is a way to say something akin to "In the widget =
'root' is a=20
widget 'l' - kill it" but for the life of me I cannot find it.&nbsp; You =
can't=20
pass a widget as an argument using lambda, either - I tried tho :)</DIV>
<DIV>&nbsp; I've looked in John Grayson's book and the python docs but I =
can't=20
find anything.&nbsp; Help!</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0015_01C08F02.2F800700--



From rick@niof.net  Sun Feb  4 13:13:14 2001
From: rick@niof.net (Rick Pasotto)
Date: Sun, 4 Feb 2001 08:13:14 -0500
Subject: [Tutor] Tkinter - Destroying windows, destroying widgets
In-Reply-To: <001801c08ea5$fcbf08e0$a410fea9@glen>; from wheelege@tsn.cc on Sun, Feb 04, 2001 at 11:28:31PM +1100
References: <001801c08ea5$fcbf08e0$a410fea9@glen>
Message-ID: <20010204081314.B29265@tc.niof.net>

One of the advantages of using classes to deal with TKinter is that you
in effect get 'global' variables for free. If within a class you do

self.second = Toplevel(root)

then your destroy function can say

self.second.destroy()

since 'self' is always passed as the first argument to all methods
(functions within a class).

On Sun, Feb 04, 2001 at 11:28:31PM +1100, Glen Wheeler wrote:
> Hey all,
> 
> I was just writing up a little tkinter app (a game, actually) and I
> have hit a wall.  My predicament, is that I want to destroy an object
> (right word?) but I want to do it in a function...for example in this
> code :
> 
> from Tkinter import *
> 
> def die(): l.destroy() ## here is the problem - root.l.destroy() does
> not work either - I think since variables are local in functions it
> doesn't have any clue as to the existence of the label "l"
>     print 'yo'     
>     raw_input("hi")
> 
> root = Tk()
> root.title('jim')
> l = Label(root, text='hi im root').pack()
> second = Toplevel(root)
> b = Button(root, text='yo', command=die).pack()
> 
> mainloop()
> 
> No matter how hard I try I cannot kill the label "l" using the button,
> and have it do other things as well.  Say I wanted to destroy a widget
> in a different window??  That label is in the same toplevel.  I just
> know there is a way to say something akin to "In the widget 'root' is
> a widget 'l' - kill it" but for the life of me I cannot find it.  You
> can't pass a widget as an argument using lambda, either - I tried tho
> :)
>
> I've looked in John Grayson's book and the python docs but I can't
> find anything.  Help!
> 
>   Thanks, Glen.

-- 
"Good intentions will always be pleaded for every assumption of
authority.  It is hardly too strong to say that the constitution was
made to guard the people against the dangers of good intentions. There
are men in all ages who mean to govern well, but they mean to govern.
They promise to be good masters, but they mean to be masters."
		-- Noah Webster
		   Rick Pasotto email: rickp@telocity.com


From arcege@shore.net  Sun Feb  4 14:00:36 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sun, 4 Feb 2001 09:00:36 -0500 (EST)
Subject: [Tutor] Tkinter - Destroying windows, destroying widgets
In-Reply-To: <001801c08ea5$fcbf08e0$a410fea9@glen> from "Glen Wheeler" at Feb 04, 2001 11:28:31 PM
Message-ID: <200102041400.JAA11646@northshore.shore.net>

> 
> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_0015_01C08F02.2F800700
> Content-Type: text/plain;
> 	charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
>   Hey all,
> 
>   I was just writing up a little tkinter app (a game, actually) and I =
> have hit a wall.  My predicament, is that I want to destroy an object =
> (right word?) but I want to do it in a function...for example in this =
> code :
> 
> from Tkinter import *
> 
> def die():
>     l.destroy() ## here is the problem - root.l.destroy() does not work =
> either - I think since variables are local in functions it doesn't have =
> any clue as to the existence of the label "l"
>     print 'yo'    =20
>     raw_input("hi")
> 
> root =3D Tk()
> root.title('jim')
> l =3D Label(root, text=3D'hi im root').pack()
> second =3D Toplevel(root)
> b =3D Button(root, text=3D'yo', command=3Ddie).pack()
> 
> mainloop()
> 
>   No matter how hard I try I cannot kill the label "l" using the button, =
> and have it do other things as well.  Say I wanted to destroy a widget =
> in a different window??  That label is in the same toplevel.  I just =
> know there is a way to say something akin to "In the widget 'root' is a =
> widget 'l' - kill it" but for the life of me I cannot find it.  You =
> can't pass a widget as an argument using lambda, either - I tried tho :)
>   I've looked in John Grayson's book and the python docs but I can't =
> find anything.  Help!

You have the right idea, but if you print "l", it is set to None, not
to an object.  That is because the pack() method returns None.  You
will want to use:
  l = Label(root, text = 'hi im root')
  l.pack()

I would suggest however, creating a class (often a subclass of Frame)
to represent what you want, setting attributes for the widgets that you
wish to access later:

  class SpamEggs(Frame):
    def __init__(self, master=None, labeltxt='', buttontxt=''):
      Frame.__init__(self, master)
      self.l = Label(self, text=labeltxt)
      self.b = Button(self, text=buttontxt, command=self.die)
      self.l.pack()
      self.b.pack()
    def die(self):
      if self.l:
        self.l.destroy()
      self.l = None # so we do not destroy it twice

  root = Tk()
  SpamEggs(root, 'hi im root', 'yo').pack()
  root.mainloop()

Good luck,
  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From clickron@webtv.net  Sun Feb  4 19:01:01 2001
From: clickron@webtv.net (clickron@webtv.net)
Date: Sun, 4 Feb 2001 14:01:01 -0500 (EST)
Subject: [Tutor] opening programs
Message-ID: <3294-3A7DA6ED-1134@storefull-168.iap.bryant.webtv.net>

Thanks everybody. I think I'll just keep doing things like I have been
until I'm a little more comfortable with changing the path. I'm kind of
afraid to go in there and mess around when I'm not that sure of myself.

Thanks again,

Ron



From amsterdamn_2000@yahoo.com  Sun Feb  4 19:11:03 2001
From: amsterdamn_2000@yahoo.com (Dan Zalewski)
Date: Sun, 4 Feb 2001 11:11:03 -0800 (PST)
Subject: [Tutor] intro to python
Message-ID: <20010204191103.66268.qmail@web11502.mail.yahoo.com>

--0-1299095577-981313863=:65740
Content-Type: text/plain; charset=us-ascii

I know absolutely nothing about python. I was wondering if you could tell me of a good book that might help me to learn the language and maybe a website with some tutorials and stuff/ thankyou

-Dan



---------------------------------
Do You Yahoo!?
- Get personalized email addresses from Yahoo! Mail Personal Address  - only $35 a year!
--0-1299095577-981313863=:65740
Content-Type: text/html; charset=us-ascii

I know absolutely nothing about python. I was wondering if you could tell me of a good book that might help me to learn the language and maybe a website with some tutorials and stuff/ thankyou<BR><BR><a href="http://www.angelfire.com/electronic/graphicsbizz/Danny.html">-Dan</a><br><p><br><hr size=1><b>Do You Yahoo!?</b><br>
- Get personalized email addresses from <a href=http://personal.mail.yahoo.com/>Yahoo! Mail Personal Address</a>  - only $35 
a year!
--0-1299095577-981313863=:65740--


From tim@johnsons-web.com  Sun Feb  4 21:40:38 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 4 Feb 2001 12:40:38 -0900
Subject: [Tutor] intro to python
References: <20010204191103.66268.qmail@web11502.mail.yahoo.com>
Message-ID: <01020412434204.01088@shecom>

On Sun, 04 Feb 2001, Dan Zalewski wrote:

> >%_I know absolutely nothing about python. I was wondering if you could tell
me of a good book that might help me to learn the language and maybe a website
with some tutorials and stuff/ thankyou

www.python.org for distributions.
A fine tutorial by Guido is linked from the opening page, I believe.
As a newbie myself, I am currently working from :
"Teach Yourself Python in 24 Hours" by Van Langingham.

I expect you'll see some more book recommendations from other list members, and

I'm looking forward to their comments as well.

Regards
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From tim@johnsons-web.com  Sun Feb  4 21:54:40 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 4 Feb 2001 12:54:40 -0900
Subject: [Tutor] How do I iterate through object attributes
References: <20010204191103.66268.qmail@web11502.mail.yahoo.com>
Message-ID: <01020413003105.01088@shecom>

Newbie question here:
I would like to be able to iterate through a function's attributes and return
values for them: Code is below:
def f():
	"f() doc string"
	z = 720
	x = 840
f_dir =  dir(f)
print "f() attributes:",f_dir
f_attr = f_dir[0]
print "first attribute:", f_attr
print f.__doc__
for attr in f_dir:
	print attr
	#print f.attr   #This Code generates AttributeError

To restate: How may I reference the value for one member of
the attribute list of a function without the literal name of that attribute.

I hope I'm phrasing this question properly.
TIA
 --
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From scarblac@pino.selwerd.nl  Sun Feb  4 22:35:17 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 4 Feb 2001 23:35:17 +0100
Subject: [Tutor] How do I iterate through object attributes
In-Reply-To: <01020413003105.01088@shecom>; from tim@johnsons-web.com on Sun, Feb 04, 2001 at 12:54:40PM -0900
References: <20010204191103.66268.qmail@web11502.mail.yahoo.com> <01020413003105.01088@shecom>
Message-ID: <20010204233517.A26679@pino.selwerd.nl>

On Sun, Feb 04, 2001 at 12:54:40PM -0900, Tim Johnson wrote:
> Newbie question here:
> I would like to be able to iterate through a function's attributes and return
> values for them: Code is below:
> def f():
> 	"f() doc string"
> 	z = 720
> 	x = 840
> f_dir =  dir(f)
> print "f() attributes:",f_dir
> f_attr = f_dir[0]
> print "first attribute:", f_attr
> print f.__doc__
> for attr in f_dir:
> 	print attr
> 	#print f.attr   #This Code generates AttributeError
> 
> To restate: How may I reference the value for one member of
> the attribute list of a function without the literal name of that attribute.

print getattr(f, attr)

-- 
Remco Gerlich


From wheelege@tsn.cc  Mon Feb  5 06:09:16 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 5 Feb 2001 17:09:16 +1100
Subject: [Tutor] Tkinter - Destroying windows, destroying widgets
References: <200102041400.JAA11646@northshore.shore.net>
Message-ID: <001501c08f3a$2c132060$a410fea9@glen>

  Thanks alot Mike and Rick - yet again the secret key to all my problems
lies in classes :)

  I already had to convert almost everything into classes - seems as though
I've got to do the lot.

  Thanks alot,
  Glen (busily converting python code)

----- Original Message -----
From: Michael P. Reilly <arcege@shore.net>
To: Glen Wheeler <wheelege@tsn.cc>
Cc: <tutor@python.org>
Sent: Monday, February 05, 2001 1:00 AM
Subject: Re: [Tutor] Tkinter - Destroying windows, destroying widgets


> >
> > This is a multi-part message in MIME format.
> >
> > ------=_NextPart_000_0015_01C08F02.2F800700
> > Content-Type: text/plain;
> > charset="iso-8859-1"
> > Content-Transfer-Encoding: quoted-printable
> >
> >   Hey all,
> >
> >   I was just writing up a little tkinter app (a game, actually) and I =
> > have hit a wall.  My predicament, is that I want to destroy an object =
> > (right word?) but I want to do it in a function...for example in this =
> > code :
> >
> > from Tkinter import *
> >
> > def die():
> >     l.destroy() ## here is the problem - root.l.destroy() does not work
=
> > either - I think since variables are local in functions it doesn't have
=
> > any clue as to the existence of the label "l"
> >     print 'yo'    =20
> >     raw_input("hi")
> >
> > root =3D Tk()
> > root.title('jim')
> > l =3D Label(root, text=3D'hi im root').pack()
> > second =3D Toplevel(root)
> > b =3D Button(root, text=3D'yo', command=3Ddie).pack()
> >
> > mainloop()
> >
> >   No matter how hard I try I cannot kill the label "l" using the button,
=
> > and have it do other things as well.  Say I wanted to destroy a widget =
> > in a different window??  That label is in the same toplevel.  I just =
> > know there is a way to say something akin to "In the widget 'root' is a
=
> > widget 'l' - kill it" but for the life of me I cannot find it.  You =
> > can't pass a widget as an argument using lambda, either - I tried tho :)
> >   I've looked in John Grayson's book and the python docs but I can't =
> > find anything.  Help!
>
> You have the right idea, but if you print "l", it is set to None, not
> to an object.  That is because the pack() method returns None.  You
> will want to use:
>   l = Label(root, text = 'hi im root')
>   l.pack()
>
> I would suggest however, creating a class (often a subclass of Frame)
> to represent what you want, setting attributes for the widgets that you
> wish to access later:
>
>   class SpamEggs(Frame):
>     def __init__(self, master=None, labeltxt='', buttontxt=''):
>       Frame.__init__(self, master)
>       self.l = Label(self, text=labeltxt)
>       self.b = Button(self, text=buttontxt, command=self.die)
>       self.l.pack()
>       self.b.pack()
>     def die(self):
>       if self.l:
>         self.l.destroy()
>       self.l = None # so we do not destroy it twice
>
>   root = Tk()
>   SpamEggs(root, 'hi im root', 'yo').pack()
>   root.mainloop()
>
> Good luck,
>   -Arcege
>
> --
> ------------------------------------------------------------------------
> | Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
> | Salem, Mass. USA  01970             |                                |
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From brian@www.coolnamehere.com  Mon Feb  5 07:34:13 2001
From: brian@www.coolnamehere.com (brian)
Date: Sun, 4 Feb 2001 23:34:13 -0800
Subject: [Tutor] Python Baby Steps Tutorial
Message-ID: <20010204233413.B15656@www.coolnamehere.com>

Hi All,

I made a very simple tutorial for getting started with Python.  The link is currently:

	http://www.coolnamehere.com/z/programming/python/pythontut.asp

Its focus is on using Python in Windows, just because I'm too lazy to detail using RPM's or compiling Python from code.  Mainly, it's just a warmup for the "real" tutorials out there.  It was originally written for my Dad, who had only worked with QBASIC in some distant past.

Give it a go-over and let me know what I can polish up!

Thanks,
Brian Wisti

-- 
-------------------------------------------------------------------------------
Brian Wisti
brian@coolnamehere.com
http://www.coolnamehere.com


From NHYTRO@compuserve.com  Mon Feb  5 07:55:45 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Mon, 5 Feb 2001 02:55:45 -0500
Subject: [Tutor] Reading and outputting HTML
Message-ID: <200102050255_MC2-C447-B895@compuserve.com>

Sorry for taking so long to post my script. Below is the code I used,
please excuse its " roughness", I=B4m a 3 Weel old newbie:



#!C:/Python/python.exe -u

print "Content-Type: text/html\n\n"

import cgi
import webbrowser
#
#
form =3D cgi.FieldStorage()
print "saving html to file..."
htmlfile =3D open("./webpages/tester.html", "w")
htmlfile.write(form["editarea"].value)
test =3D htmlfile.read()
print "test file output..."
print test

webbrowser.open("./webpages/tester.html")



I would like to display the generated HTML , but the page Displays garble=
d
on the SERVER!!?? I just can=B4t get my code to edit, store and re-displa=
y
HTML files :-(


Thanks for your anticipated help!

Sharriff

Message text written by INTERNET:tutor@python.org
>* Sharriff Aina <NHYTRO@compuserve.com>:

> I have coded a CGI script that creates HTML files, strange thing is, wh=
en
> reading a HTML file, one created by the script or otherwise, I just get=
 a
> very garbled page returned to the browser. =


You seem to be saying above that your browser is broken ("created by the
script or otherwise..."). Could you clarify you message? Also posting
example code and errors helps greatly.<



From rob@jam.rr.com  Mon Feb  5 12:31:24 2001
From: rob@jam.rr.com (R. A.)
Date: Mon, 05 Feb 2001 06:31:24 -0600
Subject: [Tutor] Python Baby Steps Tutorial
References: <20010204233413.B15656@www.coolnamehere.com>
Message-ID: <3A7E9D1C.7CA4072@jam.rr.com>

Groovy.  I added a link to your tutorial from the Useless links page, so
hopefully you'll be graced with a bit more feedback.

Rob

brian wrote:
> 
> Hi All,
> 
> I made a very simple tutorial for getting started with Python.  The link is currently:
> 
>         http://www.coolnamehere.com/z/programming/python/pythontut.asp
> 
> Its focus is on using Python in Windows, just because I'm too lazy to detail using RPM's or compiling Python from code.  Mainly, it's just a warmup for the "real" tutorials out there.  It was originally written for my Dad, who had only worked with QBASIC in some distant past.
> 
> Give it a go-over and let me know what I can polish up!
> 
> Thanks,
> Brian Wisti
> 
> --
> -------------------------------------------------------------------------------
> Brian Wisti
> brian@coolnamehere.com
> http://www.coolnamehere.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Visit the Useless Python Repository!
http://www.lowerstandard.com/python/pythonsource.html


From arcege@shore.net  Mon Feb  5 12:45:14 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Mon, 5 Feb 2001 07:45:14 -0500 (EST)
Subject: [Tutor] Reading and outputting HTML
In-Reply-To: <200102050255_MC2-C447-B895@compuserve.com> from "Sharriff Aina" at Feb 05, 2001 02:55:45 AM
Message-ID: <200102051245.HAA24165@northshore.shore.net>

> #!C:/Python/python.exe -u
> 
> print "Content-Type: text/html\n\n"
> 
> import cgi
> import webbrowser
> #
> #
> form =3D cgi.FieldStorage()
> print "saving html to file..."
> htmlfile =3D open("./webpages/tester.html", "w")
> htmlfile.write(form["editarea"].value)
> test =3D htmlfile.read()
> print "test file output..."
> print test
> 
> webbrowser.open("./webpages/tester.html")
> 
> 
> 
> I would like to display the generated HTML , but the page Displays garble=
> d
> on the SERVER!!?? I just can=B4t get my code to edit, store and re-displa=
> y
> HTML files :-(

Looking at the code, the "blaring" errors are that you:
a) Reading to a file that is only openned for writting; change the
   openning option from 'w' to 'w+', for "read and write".
b) Should be reading an empty string from htmlfile since you haven't
   moved the file pointer back to the beginning of the file.

   With every file, there is a pointer where you are looking, writing
   to the file moves it.  Reading would pick up where it left off, in
   this case at the end of the file.  You want to use the "seek" method
   to move the file pointer to the beginning.
 htmlfile = open("./webpages/tester.html", "w+")
 htmlfile.write(form["editarea"].value)
 htmlfile.seek(0)
 test = htmlfile.read()
c) You are attempting to open a browser (client) session from a web
   server.  There is already a browser open (which submitted your
   form); you should be using that, by writing to stdout.  You are
   already doing that with the print statements.

Since you want to tell the browser to open another file, you would want
to send a redirection HTTP response.  Change the first print to:
  print 'Location: /tester.html'
  print

This assumes that \webpages\ is your DocumentRoot setting in your web
server software.

Good luck,
  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From christian.folini@unifr.ch  Mon Feb  5 14:31:41 2001
From: christian.folini@unifr.ch (christian folini)
Date: Mon, 5 Feb 2001 15:31:41 +0100
Subject: [Tutor] how to check for stdin?
In-Reply-To: <200102051245.HAA24165@northshore.shore.net>; from arcege@shore.net on Mon, Feb 05, 2001 at 13:45:14 +0100
References: <200102050255_MC2-C447-B895@compuserve.com> <200102051245.HAA24165@northshore.shore.net>
Message-ID: <20010205153141.E1442@histoirepc19>

Hi there,

I would like to check for STDIN in a script. Now there is no
problem with sys.stdin, if there really is STDIN, but as soon
as no STDIN is present, python stops and wait for me to enter
some input. 

How can i check if there actually _is_ STDIN before i attempt to
read it?

christian

P.S. sorry, if this has been asked before, i did not find anything
in the web about it.


From arcege@shore.net  Mon Feb  5 15:45:30 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Mon, 5 Feb 2001 10:45:30 -0500 (EST)
Subject: [Tutor] how to check for stdin?
In-Reply-To: <20010205153141.E1442@histoirepc19> from "christian folini" at Feb 05, 2001 03:31:41 PM
Message-ID: <200102051545.KAA22130@northshore.shore.net>

> Hi there,
> 
> I would like to check for STDIN in a script. Now there is no
> problem with sys.stdin, if there really is STDIN, but as soon
> as no STDIN is present, python stops and wait for me to enter
> some input. 
> 
> How can i check if there actually _is_ STDIN before i attempt to
> read it?
> 
> christian
> 
> P.S. sorry, if this has been asked before, i did not find anything
> in the web about it.

I doubt that you could check on windoze, but in a UNIX environment
there is knowledge of whether a open file is attached to a terminal or
not.  A method called "isatty()" returns true if associated with a
terminal.

$ cat eggs.py
import sys
if not sys.stdin.istty(): # redirected from file or pipe
  stdin_data = sys.stdin.read()
else:
  stdin_data = 'not read from stdin'
print `stdin_data`

$ echo toast | python eggs.py
'toast\012'
$ python eggs.py
'not read from stdin'
$

  -Arcege

PS: I don't think it has been asked in years actually. ;)

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From bobhicks@adelphia.net  Mon Feb  5 17:16:28 2001
From: bobhicks@adelphia.net (Robert L Hicks)
Date: Mon, 05 Feb 2001 12:16:28 -0500
Subject: [Tutor] FW: Ways to learn Python
In-Reply-To: <B6A449E1.A04B%bobhicks@adelphia.net>
Message-ID: <B6A44A1C.A04C%bobhicks@adelphia.net>


----------
From: Robert L Hicks <bobhicks@adelphia.net>
Date: Mon, 05 Feb 2001 12:15:29 -0500
To: <amsterdamn_2000@yahoo.com>
Subject: Ways to learn Python

http://www.crosswinds.net/~agauld/
http://www.python.org/doc/

"Learning to program using Python" by A. Gauld
"Python and Tkinter Programming" by John Grayson
"Learning Python" by Lutz & Ascher

The python site has mutliple tutorials...

- Bob



From brian@coolnamehere.com  Mon Feb  5 18:07:55 2001
From: brian@coolnamehere.com (brian)
Date: Mon, 5 Feb 2001 10:07:55 -0800 (PST)
Subject: [Tutor] Python Baby Steps Tutorial
In-Reply-To: <3A7E9D1C.7CA4072@jam.rr.com>
References: <20010204233413.B15656@www.coolnamehere.com>
 <3A7E9D1C.7CA4072@jam.rr.com>
Message-ID: <14974.60411.636636.10461@www.coolnamehere.com>

Thanks!  Now you are a _source_ of elation, too! :)

Brian Wisti

R. A. writes:
 > Groovy.  I added a link to your tutorial from the Useless links page, so
 > hopefully you'll be graced with a bit more feedback.
 > 
 > Rob
 > 


From curtis.larsen@Covance.Com  Mon Feb  5 19:15:23 2001
From: curtis.larsen@Covance.Com (Curtis Larsen)
Date: Mon, 05 Feb 2001 13:15:23 -0600
Subject: [Tutor] List Dup-Elim Method?
Message-ID: <sa7ea78f.031@madmail.truax.covance.com>

Tim - 

Thanks!  This helps a lot.  I've used the dictionary method before
(with great success), but the when you have lists within lists
(sometimes within lists) it takes more time to set it up the dictionary
stuff than it would to do something like this.  Thanks again!

Curtis

>>> "Tim Peters" <tim.one@home.com> 02/03/2001 3:43:14 AM >>>
If the elements of a list are hashable, the method using a dict will be
by
far the fastest if the list is large.

If the elements are not hashable (for example, a list of lists), but
can be
sorted, still much quicker than brute force (yet still much slower
than
using a temporary dict!) is this:

def dupfree(x):
    """Remove all duplicates from list x, in place.

    The elements of x must enjoy a total ordering.
    """

    n = len(x)
    if n > 1:
        x.sort()
        last = x[0]
        i = avail = 1
        while i < n:
            if x[i] != last:
                x[avail] = last = x[i]
                avail += 1
            i += 1
        del x[avail:]

That requires Python 2.0, because of the "+=" thingies.

Example:

>>> x = [[1, 2], [3, 4]]
>>> x *= 10
>>> x
[[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4],
 [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4],
 [1, 2], [3, 4], [1, 2], [3, 4]]
>>> dupfree(x)
>>> x
[[1, 2], [3, 4]]
>>>

How does it work?  Sorting the list brings all the equal elements next
to
each other.  (Note:  Many sorting routines don't work very quickly
when
there are lots of equal elements, but Python's does.  I know that
because I
wrote Python's list.sort() <wink>.)

After all the equal elements are adjacent, it just marches across the
list
once, keeping track of when the list element at index i *changes*. 
When it
does, it moves that not-seen-before element toward the front of the
list,
and moves on skipping over the chunk of elements equal to *it*. 
Finally, it
gets rid of the list positions no longer needed (the "del" stmt).

Of course there's nothing to do if the list doesn't have at least two
elements to start, so it checks for that first.  It *has* to avoid
going
into the main body if the list is empty, because then "last = x[0]"
would
blow up.  Since it has to check for that anyway, it doesn't cost any
more to
make sure there are at least two things in the list.

This isn't an easy algorithm -- the steps are delicate.  If you can use
the
dict method instead, do so!

what-you-can-assume-constrains-what-you-can-do-ly y'rs  - tim


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


-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.


From pablo@universodigital.net  Mon Feb  5 19:37:32 2001
From: pablo@universodigital.net (Pablo Mateo =?iso-8859-1?Q?V=E1zquez?=)
Date: Mon, 05 Feb 2001 20:37:32 +0100
Subject: [Tutor] Cookies??
Message-ID: <3A7F00FC.8251E33D@universodigital.net>

Hi, my problem is:

How to read the Cookie in a cgi program? 

I write:
  c.load(os.environ["HTTP_COOKIE"])

And I get the follow error:

  def __getitem__(self, key): return self.data[key]
  KeyError: HTTP_COOKIE

The cookie was written in a previous cgi program:
   c=Cookie.Cookie()
   c["login"]=log_encrip
   c["login"]["path"]=pass_encrip
   c["login"]["expires"]=fecha_expira
   c.output(header="Cookie:") 
...
...
print "Content-type: text/html"
print c
print   


Can you said to me what is the problem?


Thanks.


From vdbroekw@wxs.nl  Mon Feb  5 20:28:28 2001
From: vdbroekw@wxs.nl (W.W. van den Broek)
Date: Mon, 05 Feb 2001 21:28:28 +0100
Subject: [Tutor] idle 0.6
References: <20010205170158.3F998ED42@mail.python.org>
Message-ID: <3A7F0CEC.F9EED0DE@wxs.nl>

Hi all,
I've installed python
2.0 from the cdrom that
came with the wonderfull
book core python
programming, in 1.5.3 i
used idle, with 2.0
there is an error when
trying to start idle, on
python.org there is
mentioning of a new
version idle0.6 to be
used with python2.0, but
i cannot find it, from
where can i download
it??
Thanks, walter
-- 
W.W. van den Broek
e-mail:	
vandenbroek@psyd.azr.nl
AZR-Dijkzigt		fax:	
010-4633217
afdeling psychiatrie
tel:		010-4639222
Postbus 2040		e-mail	
vdbroekw@wxs.nl (thuis)
3000 CA Rotterdam
homepage:
http://home.planet.nl/~vdbroekw


From uygar_t@yahoo.com  Mon Feb  5 21:29:25 2001
From: uygar_t@yahoo.com (uygar teomete)
Date: Mon, 5 Feb 2001 13:29:25 -0800 (PST)
Subject: [Tutor] python interpreter
Message-ID: <20010205212925.14544.qmail@web4701.mail.yahoo.com>

--0-2003238937-981408565=:13775
Content-Type: text/plain; charset=us-ascii

I just downloaded Python 2.0 from www.python.org  made a self-test, "import test. self_test" or somethin like that. My test_socket seems to be not working, and 24 other test_something could not be found. I am a newbie. should I uninstall and download again? Thanks for your patience..


---------------------------------
Do You Yahoo!?
- Get personalized email addresses from Yahoo! Mail Personal Address  - only $35 a year!
--0-2003238937-981408565=:13775
Content-Type: text/html; charset=us-ascii

I just downloaded Python 2.0 from <A href="http://www.python.org">www.python.org</A>&nbsp; made a self-test, "import test. self_test" or somethin like that. My test_socket seems to be not working, and 24 other test_something could not be found. I am a newbie. should I uninstall and download again? Thanks for your patience..<p><br><hr size=1><b>Do You Yahoo!?</b><br>
- Get personalized email addresses from <a href=http://personal.mail.yahoo.com/>Yahoo! Mail Personal Address</a>  - only $35 
a year!
--0-2003238937-981408565=:13775--


From Lindsay.Davies@moonshine.co.uk  Mon Feb  5 21:38:20 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Mon, 5 Feb 2001 21:38:20 +0000
Subject: [Tutor] Cookies??
In-Reply-To: <3A7F00FC.8251E33D@universodigital.net>
References: <3A7F00FC.8251E33D@universodigital.net>
Message-ID: <a05010412b6a4cdae2ef2@[195.102.186.233]>

Take a look at Guido's examples here...

http://www.python.org/doc/essays/ppt/sd99east/sld057.htm

Best wishes,

Lindsay



At 8:37 PM +0100 2/5/01, Pablo Mateo Vázquez wrote:
>Hi, my problem is:
>
>How to read the Cookie in a cgi program?
>
>I write:
>   c.load(os.environ["HTTP_COOKIE"])
>
>And I get the follow error:
>
>   def __getitem__(self, key): return self.data[key]
>   KeyError: HTTP_COOKIE
>
>The cookie was written in a previous cgi program:
>    c=Cookie.Cookie()
>    c["login"]=log_encrip
>    c["login"]["path"]=pass_encrip
>    c["login"]["expires"]=fecha_expira
>    c.output(header="Cookie:")
>...
>...
>print "Content-type: text/html"
>print c
>print  
>
>
>Can you said to me what is the problem?
>
>
>Thanks.
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From tim.one@home.com  Mon Feb  5 21:41:04 2001
From: tim.one@home.com (Tim Peters)
Date: Mon, 5 Feb 2001 16:41:04 -0500
Subject: [Tutor] python interpreter
In-Reply-To: <20010205212925.14544.qmail@web4701.mail.yahoo.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCAELJINAA.tim.one@home.com>

[uygar teomete]
> I just downloaded Python 2.0 from www.python.org  made a self-test,
> "import test. self_test" or somethin like that. My test_socket seems
> to be not working,

You didn't say which operating system you're using, but if you're running
some flavor of Windows then test_socket will fail unless you have an active
internet connection open at the time you run it.  That's just the way it
works on Windows.

> and 24 other test_something could not be found.

Sounds about right, again assuming you're running some flavor of Windows.
For example,

test test_fork1 skipped --  os.fork not defined -- skipping test_fork1

is normal on Windows.  Windows doesn't support os.fork, so it simply can't
run the test there.  Anything that says "test_xxx skipped" at the end is
nothing to worry about.  Things to worry about say something like "test_xxx
failed" instead.




From tim@johnsons-web.com  Tue Feb  6 02:15:31 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Mon, 5 Feb 2001 17:15:31 -0900
Subject: [Tutor] Interpreter Conflicts with os.access
References: <LNBBLJKPBEHFEDALKOLCAELJINAA.tim.one@home.com>
Message-ID: <01020517240801.02709@shecom>

Hi:
<duh>Confused Newbie Here:
	Am using Python on RH 6.0.
Have both python1.5 and python2.0
When I invoke python 1.5, I receive an AttributeError
when calling os.access.

When I invoke python 2.0, os.access is processed correctly.
Sure enough, there is no function named "access" in /usr/lib/python1.5/access.py
That's no suprise, but when I look at   /usr/local/lib/python2.0/os.py
I can't find the subroutine there either. 

As a newbie, I'm confused: Could someone explain this discrepancy to me
and let me know what I am doing incorrectly. </duh>

Thanks
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From arcege@shore.net  Tue Feb  6 02:45:58 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Mon, 5 Feb 2001 21:45:58 -0500 (EST)
Subject: [Tutor] Interpreter Conflicts with os.access
In-Reply-To: <01020517240801.02709@shecom> from "Tim Johnson" at Feb 05, 2001 05:15:31 PM
Message-ID: <200102060245.VAA26633@northshore.shore.net>

> 
> Hi:
> <duh>Confused Newbie Here:
> 	Am using Python on RH 6.0.
> Have both python1.5 and python2.0
> When I invoke python 1.5, I receive an AttributeError
> when calling os.access.
> 
> When I invoke python 2.0, os.access is processed correctly.
> Sure enough, there is no function named "access" in /usr/lib/python1.5/access.py
> That's no suprise, but when I look at   /usr/local/lib/python2.0/os.py
> I can't find the subroutine there either. 
> 
> As a newbie, I'm confused: Could someone explain this discrepancy to me
> and let me know what I am doing incorrectly. </duh>

This function and most of the others in the os module (running on a
UNIX/POSIX system) come from the "posix" built-in module.

$ python
Python 1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731 (experimental)] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os
>>> import posix
>>> os.access is posix.access
1
>>>

About the only difference is that this is RedHat 7.  You might like to
read the os.py module to see how this is accomplished.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From johnp@reportlab.com  Tue Feb  6 11:42:09 2001
From: johnp@reportlab.com (John Precedo)
Date: Tue, 6 Feb 2001 11:42:09 -0000
Subject: [Tutor] Clearing the screen?
In-Reply-To: <Pine.LNX.4.21.0101261309440.8103-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <GBEDIFFLINCAGNCJCLIFEEEPCBAA.johnp@reportlab.com>

Hi everyone!

I've been working with Python for a few months now, and I'm
beginning to get quite good at it. Well, one of my friends
has asked me a question, and it's bugging the hell out of me
that I can't answer it! Maybe one of you kind folks could
help?

Right, say you have a program that does nothing fancy, just
prints output to STDIO. The output is nothing fancy
either -just text. But, you want to make each run distinct -
you don't want junk from one run cluttering up the screen on
the next run and confusing you.

Is there any simple way of clearing the screen? Something
like the old Basic CLS command?

(And yes, I know you could probably do it using Tkinter -
but I'm not going there for something so simple!)

Anyway, thanks in advance for any help.




From wheelege@tsn.cc  Tue Feb  6 12:17:57 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 6 Feb 2001 23:17:57 +1100
Subject: [Tutor] Clearing the screen?
References: <GBEDIFFLINCAGNCJCLIFEEEPCBAA.johnp@reportlab.com>
Message-ID: <001701c09036$d77b7540$a410fea9@glen>

  Don't know if this is the answer your looking for - but you could say
print a whole bunch of empty line...like say

pirnt "\n" * 50

  It sorta clears the screen :)


----- Original Message -----
From: John Precedo <johnp@reportlab.com>
To: python-tutor mailing list <tutor@python.org>
Sent: Tuesday, February 06, 2001 10:42 PM
Subject: [Tutor] Clearing the screen?


> Hi everyone!
>
> I've been working with Python for a few months now, and I'm
> beginning to get quite good at it. Well, one of my friends
> has asked me a question, and it's bugging the hell out of me
> that I can't answer it! Maybe one of you kind folks could
> help?
>
> Right, say you have a program that does nothing fancy, just
> prints output to STDIO. The output is nothing fancy
> either -just text. But, you want to make each run distinct -
> you don't want junk from one run cluttering up the screen on
> the next run and confusing you.
>
> Is there any simple way of clearing the screen? Something
> like the old Basic CLS command?
>
> (And yes, I know you could probably do it using Tkinter -
> but I'm not going there for something so simple!)
>
> Anyway, thanks in advance for any help.
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From christian.folini@unifr.ch  Tue Feb  6 10:00:55 2001
From: christian.folini@unifr.ch (christian folini)
Date: Tue, 6 Feb 2001 11:00:55 +0100
Subject: [Tutor] how to check for stdin?
In-Reply-To: <200102051545.KAA22130@northshore.shore.net>; from arcege@shore.net on Mon, Feb 05, 2001 at 16:45:30 +0100
References: <20010205153141.E1442@histoirepc19> <200102051545.KAA22130@northshore.shore.net>
Message-ID: <20010206110055.C381@histoirepc19>

On 2001.02.05 16:45:30 +0100 Michael P. Reilly wrote:
> I doubt that you could check on windoze, but in a UNIX environment
> there is knowledge of whether a open file is attached to a terminal or
> not.  A method called "isatty()" returns true if associated with a
> terminal.

thank you for that hint. Happy enough my script need not run
under windows... And it works. cool.

however, there was a typo on the second line, your prg should read:

$ cat eggs.py
import sys
if not sys.stdin.isatty(): # redirected from file or pipe
  stdin_data = sys.stdin.read()
else:
  stdin_data = 'not read from stdin'
print `stdin_data`

cheers, christian


From alan.gauld@freenet.co.uk  Tue Feb  6 10:11:39 2001
From: alan.gauld@freenet.co.uk (Alan Gauld)
Date: Tue, 06 Feb 2001 10:11:39 +0000
Subject: [Tutor] Re opening programs
Message-ID: <3.0.1.32.20010206101139.0191123c@mail.freenet.co.uk>

> I have windows 98 ie5.0 and downloaded python2.0. To open a program
> (hello.py) while in idle I click file/open/documents/hello/open
> is there a different or quicker way to do this? 

To run the program or to edit it?

To run the program type:

python hello.py from an MS DOS command promt(aka DOS box)
or just double click it from windows explorer(aka My computer).

Alternatively right click in explorer and select open.

You may find that it runs then closes again too quicvkly to vbe usefult in
which case try adding the line:

raw_input("Hit enter to exit") at the end.

[BTW,  I love the contradiction in that, oh so common, phrase :-) ]

To edit it in IDLE right click in explorer and select edit, 
it will start IDLE with your program loaded in an editor window.

There is a command line option to IDLE too, I think its /e thius:

 python idle.py /e hello.py

But thats a bit messy IMHO...

HTH,

Alan G
(Catching up on several days tutor messages)



From dsh8290@rit.edu  Tue Feb  6 18:19:15 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 6 Feb 2001 13:19:15 -0500
Subject: [Tutor] Clearing the screen?
In-Reply-To: <001701c09036$d77b7540$a410fea9@glen>; from wheelege@tsn.cc on Tue, Feb 06, 2001 at 11:17:57PM +1100
References: <GBEDIFFLINCAGNCJCLIFEEEPCBAA.johnp@reportlab.com> <001701c09036$d77b7540$a410fea9@glen>
Message-ID: <20010206131914.A1814@harmony.cs.rit.edu>

On Tue, Feb 06, 2001 at 11:17:57PM +1100, Glen Wheeler wrote:
|   Don't know if this is the answer your looking for - but you could say
| print a whole bunch of empty line...like say
| 
| pirnt "\n" * 50
| 
|   It sorta clears the screen :)
| 

I was going to suggest a similar thing.

If the script will be running on a *nix system you could take a look
at the ncurses module.


Reading your message again, it could be that you will run the
interpreter more than once on the command line (as opposed to a loop
in your program).  If that's the case, you could have the script run
with a shell/batch script.  ex:

cls
C:\python\python.exe myscript.py

or

#!/bin/sh
clear
./myscript.py


| 
| ----- Original Message -----
| From: John Precedo <johnp@reportlab.com>
| To: python-tutor mailing list <tutor@python.org>
| Sent: Tuesday, February 06, 2001 10:42 PM
| Subject: [Tutor] Clearing the screen?
| 
| 
| > Hi everyone!
| >
| > Right, say you have a program that does nothing fancy, just
| > prints output to STDIO. The output is nothing fancy
| > either -just text. But, you want to make each run distinct -
| > you don't want junk from one run cluttering up the screen on
| > the next run and confusing you.
| >
| > Is there any simple way of clearing the screen? Something
| > like the old Basic CLS command?

-D


From jpl@global.co.za  Tue Feb  6 19:09:19 2001
From: jpl@global.co.za (James Lockley)
Date: Tue, 6 Feb 2001 21:09:19 +0200
Subject: [Tutor] Clearing the screen?
References: <GBEDIFFLINCAGNCJCLIFEEEPCBAA.johnp@reportlab.com> <001701c09036$d77b7540$a410fea9@glen>
Message-ID: <001f01c09070$4e5a6de0$2c829e89@poseidon>

you can also backspace what ever you had written to screen previously

import time
for x in range(10):
    print x,3*'\b',
    time.sleep(0.5)  # just lets it happen at more vsible speed

there is also another backslashed command for clearing the line but am
afraid it has slipped my mind

cheers
james



----- Original Message -----
From: "Glen Wheeler" <wheelege@tsn.cc>
To: <tutor@python.org>
Sent: Tuesday, February 06, 2001 2:17 PM
Subject: Re: [Tutor] Clearing the screen?


>   Don't know if this is the answer your looking for - but you could say
> print a whole bunch of empty line...like say
>
> pirnt "\n" * 50
>
>   It sorta clears the screen :)
>
>
> ----- Original Message -----
> From: John Precedo <johnp@reportlab.com>
> To: python-tutor mailing list <tutor@python.org>
> Sent: Tuesday, February 06, 2001 10:42 PM
> Subject: [Tutor] Clearing the screen?
>
>
> > Hi everyone!
> >
> > I've been working with Python for a few months now, and I'm
> > beginning to get quite good at it. Well, one of my friends
> > has asked me a question, and it's bugging the hell out of me
> > that I can't answer it! Maybe one of you kind folks could
> > help?
> >
> > Right, say you have a program that does nothing fancy, just
> > prints output to STDIO. The output is nothing fancy
> > either -just text. But, you want to make each run distinct -
> > you don't want junk from one run cluttering up the screen on
> > the next run and confusing you.
> >
> > Is there any simple way of clearing the screen? Something
> > like the old Basic CLS command?
> >
> > (And yes, I know you could probably do it using Tkinter -
> > but I'm not going there for something so simple!)
> >
> > Anyway, thanks in advance for any help.
> >
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>
>



From s349929@student.uq.edu.au  Tue Feb  6 22:49:31 2001
From: s349929@student.uq.edu.au (Suzanne Little)
Date: Wed, 7 Feb 2001 08:49:31 +1000 (GMT+1000)
Subject: [Tutor] XML parsing
Message-ID: <Pine.OSF.4.30.0102070840340.23514-100000@student.uq.edu.au>

Hi,

I doing some work with xml at the moment and I was hoping that someone
could give me some pointers. Currently I'm reading the file in, chopping
up the string using re.compile('<') and re.split() and then looking at each
'tag' that's in the result list to find the information I'm looking for
using regular expressions. This works but it can't be the only way to
extract information from an xml document. I've looked at the
xml.parsers.expat and the xml.sax modules including the HOWTO but I'm
don't really understand what they are capable of or when to use them.

Which module should I be using to do this? Are there any examples of this
sort of scanning-of-xml-documents-for-information available for me to look
at?

Thanks for any and all help,
Suzanne

BTW the useless Python archive is excellent!

--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------



From lumbricus@gmx.net  Tue Feb  6 22:56:19 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Tue, 6 Feb 2001 23:56:19 +0100 (MET)
Subject: [Tutor] Clearing the screen?
References: <001701c09036$d77b7540$a410fea9@glen>
Message-ID: <2447.981500179@www24.gmx.net>

>   Don't know if this is the answer your looking for - but you could say
> print a whole bunch of empty line...like say
> 
> pirnt "\n" * 50
50 ??? my screen has 25 lines.
>   It sorta clears the screen :)
the curses module has got a clear screen function
or do system('/usr/bin/clear') from the os module

greeetz Jö!

-- 
Sent through GMX FreeMail - http://www.gmx.net


From AquaRock7@aol.com  Tue Feb  6 23:30:36 2001
From: AquaRock7@aol.com (AquaRock7@aol.com)
Date: Tue, 6 Feb 2001 18:30:36 EST
Subject: [Tutor] BaseHTTPServer module
Message-ID: <8b.207c3c9.27b1e31c@aol.com>

--part1_8b.207c3c9.27b1e31c_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

A newbie question on the included module BaseHTTPServer:
What is the root directory? that I put the pages for it to display?
thanks, ~Dustin

--part1_8b.207c3c9.27b1e31c_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2>A newbie question on the included module BaseHTTPServer:
<BR>What is the root directory? that I put the pages for it to display?
<BR>thanks, ~Dustin</FONT></HTML>

--part1_8b.207c3c9.27b1e31c_boundary--


From lumbricus@gmx.net  Wed Feb  7 00:07:04 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Wed, 7 Feb 2001 01:07:04 +0100 (MET)
Subject: [Tutor] BaseHTTPServer module
References: <8b.207c3c9.27b1e31c@aol.com>
Message-ID: <20474.981504424@www21.gmx.net>


--part1_8b.207c3c9.27b1e31c_boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

> A newbie question on the included module BaseHTTPServer:
> What is the root directory? that I put the pages for it to display?
> thanks, ~Dustin
> 
/home/httpd/html/

take care that this dir is not owned by root
(but usually by nobody)
:-)
greetz jö!

-- 
Sent through GMX FreeMail - http://www.gmx.net
--part1_8b.207c3c9.27b1e31c_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2>A newbie question on the included module BaseHTTPServer:
<BR>What is the root directory? that I put the pages for it to display?
<BR>thanks, ~Dustin</FONT></HTML>

--part1_8b.207c3c9.27b1e31c_boundary--

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



From arcege@shore.net  Wed Feb  7 00:27:02 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Tue, 6 Feb 2001 19:27:02 -0500 (EST)
Subject: [Tutor] BaseHTTPServer module
In-Reply-To: <8b.207c3c9.27b1e31c@aol.com> from "AquaRock7@aol.com" at Feb 06, 2001 06:30:36 PM
Message-ID: <200102070027.TAA07680@northshore.shore.net>

> A newbie question on the included module BaseHTTPServer:
> What is the root directory? that I put the pages for it to display?
> thanks, ~Dustin

The BaseHTTPServer doesn't serve files, it is just a framework for
creating a server.  You want to be looking at SimpleHTTPServer.  The
default root directory is the program's current directory; but you can
change that by overriding the "translate_path" method of the
SimpleHTTPRequestHandler class.

Before you call the server process (or just the server instance's
"serve_forever" method), you would want to change to the directory
containing your HTML files.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From dyoo@hkn.eecs.berkeley.edu  Wed Feb  7 06:04:30 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 6 Feb 2001 22:04:30 -0800 (PST)
Subject: [Tutor] XML parsing
In-Reply-To: <Pine.OSF.4.30.0102070840340.23514-100000@student.uq.edu.au>
Message-ID: <Pine.LNX.4.21.0102062150170.1908-100000@c82114-a.pinol1.sfba.home.com>

On Wed, 7 Feb 2001, Suzanne Little wrote:

> Which module should I be using to do this? Are there any examples of
> this sort of scanning-of-xml-documents-for-information available for
> me to look at?

As a side project, I'm beginning to study the expat parser; it's pretty
neat.  Here's a small example that uses Expat:

###
class MyXMLParser2:
    def __init__(self):
        self.parser = expat.ParserCreate()
        self.parser.StartElementHandler = self.StartElementHandler
        self.parser.EndElementHandler = self.EndElementHandler
        self.parser.CharacterDataHandler = self.CharacterDataHandler

    def feed(self, str):
        self.parser.Parse(str)

    def StartElementHandler(self, name, attributes):
        print "Starting: ", name, attributes
        
    def EndElementHandler(self, name):
        print "Ending: ", name
        
    def CharacterDataHandler(self, data):
        print "Character data:", data

def test():
    p = MyXMLParser2()
    p.feed("""
<iq id='A0' type='get'><query
xmlns='jabber:iq:auth'><paragraph><username>bbaggins<boldface>Bilbo</boldface>
Baggins</username></paragraph></query></iq>
    """)

if __name__ == '__main__':
    test()
###

The idea is that whenever we let our parser look at something, it will
"call back" functions whenever it sees something that interests us.  For
example, as soon as the parser sees:

    <iq id='A0' type='get'>

it realizes that it sees the start of a new tag, so that's when the
StartElementHandler callback executes.  Similar things happen when it sees
an end tag or character data.  Try playing around with the program above,
and it should make things more clear.


There's some documentation about Expat here:

    http://python.org/doc/current/lib/module-xml.parsers.expat.html

but it is, admittedly, a little terse.  If I find anything more
accessible, I'll post to the list again.  Good luck!



From sthickey@juno.com  Thu Feb  8 06:20:42 2001
From: sthickey@juno.com (Stevenson M Hickey)
Date: Wed, 7 Feb 2001 22:20:42 -0800
Subject: [Tutor] Basic Question
Message-ID: <20010207.222043.-296151.0.sthickey@juno.com>

Hi!

I am a new subscriber and I am just learning about Python.  I have a MSc
in Mathematical Computer Science and very little experience in
programming.  Lately I have wanted to do some database structures that
would not be easy or even possible with MsAccess and so I started looking
around.

I was recommended to Python as an easy language to learn and an efficient
language to program in.  I am wondering if anyone knows how to command
the Jet DataBase engine of Microsoft with Python scripts? 

More directly, I am looking for some amplification of the Tutorial in the
form of some simple scripts that will make windows parse ascii texts in
various ways.  In particular, I would like to be able to scan several
files and combine them at will or take several lines from one and put it
in another, etc.  Common CShell stuff.  I am running Windows 98 on a 400
MHz Pentium 2 with 60 Mb Ram.  

I guess, before I get too deep into this kind of a problem, I need to get
some practice doing the utmost simple API calls. 

I would appreciate any help anyone can give.

My home email address is sthickey@juno.com

Sincerely with Honor,

Stevenson Hickey


From lakicsv@usa.net  Thu Feb  8 07:10:02 2001
From: lakicsv@usa.net (Viktor Lakics)
Date: Thu, 8 Feb 2001 07:10:02 +0000
Subject: [Tutor] Format strings for variables - how?
Message-ID: <20010208071002.A5389@Diogenes.co.uk>

Hi dear Tutors,

Sorry for the basic question, I am just a starter in Python...

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

The above code gives me 0.00 as a result, while I wanted to get
0.33...

Interestingly enough, if use

print "%0.2f" %(0.3333333)

I get 0.33 as a result...

Can someone explain this to me?
What should I use in the example with the variables to get the
display format what I want?

Viktor


From jcm@bigskytel.com  Thu Feb  8 07:28:39 2001
From: jcm@bigskytel.com (David Porter)
Date: Thu, 8 Feb 2001 00:28:39 -0700
Subject: [Tutor] Format strings for variables - how?
In-Reply-To: <20010208071002.A5389@Diogenes.co.uk>; from lakicsv@usa.net on Thu, Feb 08, 2001 at 07:10:02AM +0000
References: <20010208071002.A5389@Diogenes.co.uk>
Message-ID: <20010208002839.A15627@bigskytel.com>

* Viktor Lakics <lakicsv@usa.net>:
> Hi dear Tutors,
> 
> Sorry for the basic question, I am just a starter in Python...

This is what tutor is for!

> a=1
> b=3
> print "%0.2f" %(a/b)
> 
> The above code gives me 0.00 as a result, while I wanted to get
> 0.33...

The reason is that the numbers you are dividing are not floats. Because of
that, you are doing integer division.

>>> a = 1.0
>>> b = 3
print "%0.2f" %(a/b)

gives 0.33. You must add a decimal point to one (or more) of the numbers.


David


From kalle@gnupung.net  Thu Feb  8 08:11:29 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 8 Feb 2001 09:11:29 +0100
Subject: [Tutor] Integer division (Was: Re: Format strings for variables - how?)
In-Reply-To: <20010208002839.A15627@bigskytel.com>; from jcm@bigskytel.com on Thu, Feb 08, 2001 at 12:28:39AM -0700
References: <20010208071002.A5389@Diogenes.co.uk> <20010208002839.A15627@bigskytel.com>
Message-ID: <20010208091129.A435@apone.network.loc>

--wac7ysb48OaltWcw
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez David Porter:
> * Viktor Lakics <lakicsv@usa.net>:
> > a=3D1
> > b=3D3
> > print "%0.2f" %(a/b)
> >=20
> > The above code gives me 0.00 as a result, while I wanted to get
> > 0.33...
>=20
> The reason is that the numbers you are dividing are not floats. Because of
> that, you are doing integer division.
>=20
> >>> a =3D 1.0
> >>> b =3D 3
> print "%0.2f" %(a/b)
>=20
> gives 0.33. You must add a decimal point to one (or more) of the numbers.

Now, you might (should, I think) wonder:  Why?
Basically, I think there are two reasons python has integer division.

 1) C has truncating integer division.  Python is implemented in C.  Some of
the initial target users for Python were C programmers.

 2) There is no way to handle division of two integers that everybody likes.
Some want truncating integer division (chopping off the remainder), some wa=
nt
conversion to float (which loses exact representation), some want rational
math (resource intensive), some want the Spanish Inquisition...

 3) It would break a lot of existing code if it was changed tomorrow.
=20
Three reasons.

The way it works today is perhaps not the most obvious for a newcomer to
programming or one with experience in languages using different solutions,
but when you get used to it, it's at least as good as any of the
alternatives, IMHO.

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--wac7ysb48OaltWcw
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6glSxdNeA1787sd0RAtwIAKCm23fTcd0RfspzKeirl1DU2n5nngCgtA0J
ohI2o2GolV00BvYPjBEuKW8=
=v/gD
-----END PGP SIGNATURE-----

--wac7ysb48OaltWcw--


From Lindsay.Davies@moonshine.co.uk  Thu Feb  8 08:48:11 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Thu, 8 Feb 2001 08:48:11 +0000
Subject: [Tutor] Format strings for variables - how?
In-Reply-To: <20010208002839.A15627@bigskytel.com>
References: <20010208071002.A5389@Diogenes.co.uk>
 <20010208002839.A15627@bigskytel.com>
Message-ID: <a0501042bb6a80d43baa0@[195.102.186.233]>

--============_-1230500353==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

On 8/2/01, David Porter wrote about 'Re: [Tutor] Format strings for 
variables - how?':
>  > a=1
>>  b=3
>>  print "%0.2f" %(a/b)
>>
>>  The above code gives me 0.00 as a result, while I wanted to get
>>  0.33...
>
>The reason is that the numbers you are dividing are not floats. Because of
>that, you are doing integer division.
>
>>>>  a = 1.0
>>>>  b = 3
>print "%0.2f" %(a/b)
>
>gives 0.33. You must add a decimal point to one (or more) of the numbers.

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

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


Best wishes,

Lindsay
--============_-1230500353==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
 --></style><title>Re: [Tutor] Format strings for variables -
how?</title></head><body>
<div>On 8/2/01, David Porter wrote about 'Re: [Tutor] Format strings
for variables - how?':</div>
<blockquote type="cite" cite>&gt; a=1<br>
&gt; b=3<br>
&gt; print &quot;%0.2f&quot; %(a/b)<br>
&gt;<br>
&gt; The above code gives me 0.00 as a result, while I wanted to
get<br>
&gt; 0.33...<br>
</blockquote>
<blockquote type="cite" cite>The reason is that the numbers you are
dividing are not floats. Because of<br>
that, you are doing integer division.<br>
<br>
&gt;&gt;&gt; a = 1.0<br>
&gt;&gt;&gt; b = 3<br>
print &quot;%0.2f&quot; %(a/b)<br>
</blockquote>
<blockquote type="cite" cite>gives 0.33. You must add a decimal point
to one (or more) of the numbers.</blockquote>
<div><br></div>
<div>...or alternatively make the variable type explicit...</div>
<div><br></div>
<div><font color="#000000">a = float(1)<br>
b = float(3)</font></div>
<div><font color="#000000"><b>print</b></font><font color="#007F00">
&quot;%0.2f&quot;</font><font color="#000000"> %(a/b)</font></div>
<div><br></div>
<div><br></div>
<div>Best wishes,</div>
<div><br></div>
<div>Lindsay</div>
</body>
</html>
--============_-1230500353==_ma============--


From lakicsv@usa.net  Thu Feb  8 10:06:55 2001
From: lakicsv@usa.net (Viktor Lakics)
Date: 8 Feb 2001 10:06:55 GMT
Subject: [Re: [Tutor] Format strings for variables - how?]
Message-ID: <20010208100655.8327.qmail@aw163.netaddress.usa.net>

Thanks Lindsay and David,

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

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

That is what I was after! I knew that if I do 1.0/3 I get a floating poin=
t no
as a result. My problem was, that how to define my variable in a way that=
 if
such division happens (eg. number from user input), then I want to see th=
e fp
number...

Thanks Viktor


----Viktor Lakics----

Through the Internet:

  lakicsv@usa.net


____________________________________________________________________
Get free email and a permanent address at http://www.amexmail.com/?A=3D1


From rob@jam.rr.com  Thu Feb  8 12:38:37 2001
From: rob@jam.rr.com (R. A.)
Date: Thu, 08 Feb 2001 06:38:37 -0600
Subject: [Tutor] Basic Question
References: <20010207.222043.-296151.0.sthickey@juno.com>
Message-ID: <3A82934D.EB68C0DC@jam.rr.com>

I'm a newbie, so what you're up to is a bit beyond my level.  However,
you may find some of the other documentation that came with your Python
installation useful, such as the String Services section of the Python
Library Reference.  Also, my website has links to sites with information
on how to do a healthy assortment of tasks, as well as links to source
code repositories such as the Vaults of Parnassas.  Here's my links page
URL:

http://www.lowerstandard.com/python/pythonlinks.html

The archives for this list, as well as the archive of comp.lang.python
(searchable at deja.com), may also provide some excellent info for you.

Hope this helps a bit,
Rob Andrews

Stevenson M Hickey wrote:
> 
> Hi!
> 
> I am a new subscriber and I am just learning about Python.  I have a MSc
> in Mathematical Computer Science and very little experience in
> programming.  Lately I have wanted to do some database structures that
> would not be easy or even possible with MsAccess and so I started looking
> around.
> 
> I was recommended to Python as an easy language to learn and an efficient
> language to program in.  I am wondering if anyone knows how to command
> the Jet DataBase engine of Microsoft with Python scripts?
> 
> More directly, I am looking for some amplification of the Tutorial in the
> form of some simple scripts that will make windows parse ascii texts in
> various ways.  In particular, I would like to be able to scan several
> files and combine them at will or take several lines from one and put it
> in another, etc.  Common CShell stuff.  I am running Windows 98 on a 400
> MHz Pentium 2 with 60 Mb Ram.
> 
> I guess, before I get too deep into this kind of a problem, I need to get
> some practice doing the utmost simple API calls.
> 
> I would appreciate any help anyone can give.
> 
> My home email address is sthickey@juno.com
> 
> Sincerely with Honor,
> 
> Stevenson Hickey
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Visit the Useless Python Repository!
http://www.lowerstandard.com/python/pythonsource.html


From NHYTRO@compuserve.com  Thu Feb  8 15:44:37 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 8 Feb 2001 10:44:37 -0500
Subject: [Tutor] CGI question
Message-ID: <200102081044_MC2-C4BB-B411@compuserve.com>

I=B4m not sure if this question belongs here, here goes:

I=B4m going to generate from a Database with a Python CGI script  a lot o=
f
HTML output, how can I output the content to the client in smaller chunks=
?
I=B4ve heard of  a "CHUNK" command somewher but I do=B4nt know where or h=
ow to
implement this command. Any ideas?

Best regards


Sharriff


From porterh@m-net.arbornet.org  Thu Feb  8 16:20:54 2001
From: porterh@m-net.arbornet.org (Henry)
Date: Thu, 8 Feb 2001 11:20:54 -0500 (EST)
Subject: [Tutor] input() and raw_input()
Message-ID: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>

I'm taking a number as input from the user and attempting to do a
comparison on it:
 
selection = raw_input('Enter number: ')
if selection < 3:
	print 'Invalid number'
else:
	print 'OK number'

The comparison works using input() but doesn't when using
raw_input() -- it always drops to the 'else:'.  
I was trying to use raw_input() because it was recommended in the
documentation as a safer way to get user input.  What exactly is
raw_input() doing to the input?  Can I still do my comparison using
raw_input()?  Are there some general rules on when to use
input() vs. raw_input()?

Thanks for any help.




From info@fotoasia.com  Fri Feb  9 00:35:51 2001
From: info@fotoasia.com (Farah Cowan)
Date: Fri, 9 Feb 2001 00:35:51 -0000
Subject: [Tutor] 30,000 Exclusive Images of Asia
Message-ID: <200102081634.f18GYm806386@roam2.singnet.com.sg>

Dear Sirs,

Here's how you can have access to more than 30,000 exclusive images of Asia in 4 easy steps:

Step One: Go to www.FotoAsia.com
Step Two: Browse or search for images by keywords
Step Three: Pay through credit cards via secure transactions
Step Four: Download the image/s

....and voila! you are done.

If you are targeting the Asian market, we can offer you royalty-free Asian images for your creative and publishing needs at competitive prices, from as low as US$30.00.

Need a catalog? Just go to www.FotoAsia.com and download our FREE e-Catalogs and browse at your own convenience.

Can't find an image you need? Send us an e-mail sales@FotoAsia.com and we will be glad to do a FREE search for you!

Thank you.

Ms Farah Cowan
Chief Marketing Officer
FotoAsia Pte Ltd
11 Kallang Place #02-08
Singapore 339155
Tel: 65-398-1373
Fax: 65-398-1393
www.FotoAsia.com
sales@FotoAsia.com

FotoAsia - T h e h e a r t a n d S o u l o f A s i a


Removal
**********
We have reason to believe that this mail would be of interest to you. If not, please accept our apologies for the intrusion.
Kindly reply to this email info@FotoAsia.com with "REMOVE" in subject heading and you will not receive any further mailings from us. Thank you.










From rick@niof.net  Thu Feb  8 16:39:28 2001
From: rick@niof.net (Rick Pasotto)
Date: Thu, 8 Feb 2001 11:39:28 -0500
Subject: [Tutor] input() and raw_input()
In-Reply-To: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>; from porterh@m-net.arbornet.org on Thu, Feb 08, 2001 at 11:20:54AM -0500
References: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>
Message-ID: <20010208113928.C358@tc.niof.net>

On Thu, Feb 08, 2001 at 11:20:54AM -0500, Henry wrote:
> I'm taking a number as input from the user and attempting to do a
> comparison on it:
>  
> selection = raw_input('Enter number: ')
> if selection < 3:
> 	print 'Invalid number'
> else:
> 	print 'OK number'
> 
> The comparison works using input() but doesn't when using
> raw_input() -- it always drops to the 'else:'.  
> I was trying to use raw_input() because it was recommended in the
> documentation as a safer way to get user input.  What exactly is
> raw_input() doing to the input?

Nothing. That's why it's called *raw*_input(). And that's where your
problem lies. raw_input() returns a string which you are then comparing
to a number. You need to convert 'selection' to a numeric variable.

-- 
"Moderation in temper is always a virtue; but moderation in
 principle is always a vice."
		-- Thomas Paine, _The Rights of Man_ (1791)
		   Rick Pasotto email: rickp@telocity.com


From johnp@reportlab.com  Thu Feb  8 17:02:57 2001
From: johnp@reportlab.com (John Precedo)
Date: Thu, 8 Feb 2001 17:02:57 -0000
Subject: [Tutor] input() and raw_input()
In-Reply-To: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>
Message-ID: <GBEDIFFLINCAGNCJCLIFMEGDCBAA.johnp@reportlab.com>

Henry [porterh@m-net.arbornet.org] asked:
> I'm taking a number as input from the user and
> attempting to do a comparison on it:
>
> selection = raw_input('Enter number: ')
> if selection < 3:
> 	print 'Invalid number'
> else:
> 	print 'OK number'
>
> The comparison works using input() but doesn't when using
> raw_input() -- it always drops to the 'else:'.

I see your problem. Have a look at this snippet:

  >>> x = input ("give me a number: ")
  give me a number: 10
  >>> print x
  10
  >>> print type(x)
  <type 'int'>
  >>> y = raw_input("give me another number: ")
  give me another number: 20
  >>> print y
  20
  >>> print type(y)
  <type 'string'>
  >>> z = int(y)
  >>> print z
  20
  >>> print type(z)
  <type 'int'>
  >>>

So, input is returning an integer, but raw input is
returning a string.

You could do this to fix it - replace the first line with
these two:
  selection = raw_input('Enter number: ')
  selection = int(selection)

The 'int' bit converts your string into an integer so you
can do tests on it.

It _should_ work.

--
John Precedo   (johnp@reportlab.com)
Junior Developer,   Reportlab, Inc



From dyoo@hkn.eecs.berkeley.edu  Thu Feb  8 17:17:36 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 8 Feb 2001 09:17:36 -0800 (PST)
Subject: [Tutor] input() and raw_input()
In-Reply-To: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>
Message-ID: <Pine.LNX.4.21.0102080905001.3211-100000@c82114-a.pinol1.sfba.home.com>

On Thu, 8 Feb 2001, Henry wrote:

> I'm taking a number as input from the user and attempting to do a
> comparison on it:
>  
> selection = raw_input('Enter number: ')
> if selection < 3:
> 	print 'Invalid number'
> else:
> 	print 'OK number'
> 
> The comparison works using input() but doesn't when using
> raw_input() -- it always drops to the 'else:'.  
> I was trying to use raw_input() because it was recommended in the
> documentation as a safer way to get user input.  What exactly is
> raw_input() doing to the input?  Can I still do my comparison using
> raw_input()?  Are there some general rules on when to use
> input() vs. raw_input()?

About input():  We can think of input() as if we were directly entering
something in the interpreter prompt --- Python will try to evaluate
whatever you type, into something appropriate.  So if we type

    42

in response to an input(), Python will return back an integer.  However,
if we tried something like:

    hello

(unquoted), it will break unless a 'hello' variable had been defined in
our program previously.  If it helps, you can think of input() as a pure
text substitution into the program.  Given the file:

    mynum = input("Number? ")

whatever we type will replace the 'input("Number? ")'.  (This isn't quite
what Python does, but it's close.)


raw_input(), on the other hand, will always return back strings.  The
problem that you're running into is that strings need to be squeezed into
integer form before you do the numerical comparison:

    if int(selection) < 3:

is one possible way to fix it.

Another way is this:

    selection = int(raw_input('Enter number: '))

which is nicer if you want to always think of selection as a number.


By the way, the reason it doesn't like

    selection < 3

is because string-to-string comparison is also available to us.  If both
the left side and right sides are strings, like this:

    'hello' < 'world'

then Python will do an alphabetic comparison.  However, because the left
side of your comparison uses a string and your right side a number, Python
gets very confused... *grin*  So it just stops until you make the types
match up.

Hope this helps!



From robert.groenewegen@zonnet.nl  Thu Feb  8 17:22:21 2001
From: robert.groenewegen@zonnet.nl (Robert Groenewegen)
Date: Thu, 8 Feb 2001 18:22:21 +0100
Subject: [Tutor] Copy of list
Message-ID: <3A82E3DD.18478.19A6449@localhost>

Dear all,

I filled a list with very informative data (for me, anyway 8-)). Before processing (like eliminating 
the duplicates) I wanted to save the list.

I used:
	mySavedList = myList

That doesn't work. I understand the problem. The copy is not the data but the reference. This 
can be checked with id(mySavedList) which is the same as id(myList). I presume, I have to do 
an explicit copy ('deep copy' is the correct name??).

Does anyknow the correct function of method to do the trick?

Greetings,
Robert



From shaleh@valinux.com  Thu Feb  8 17:44:54 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Thu, 08 Feb 2001 09:44:54 -0800 (PST)
Subject: [Tutor] Copy of list
In-Reply-To: <3A82E3DD.18478.19A6449@localhost>
Message-ID: <XFMail.20010208094454.shaleh@valinux.com>

> 
> That doesn't work. I understand the problem. The copy is not the data but the
> reference. This 
> can be checked with id(mySavedList) which is the same as id(myList). I
> presume, I have to do 
> an explicit copy ('deep copy' is the correct name??).
> 
> Does anyknow the correct function of method to do the trick?
> 

>>> import copy
>>> dir(copy)
['Error', '_EmptyClass', '__builtins__', '__doc__', '__file__', '__name__',
'_copy_atomic', '_copy_dict', '_copy_dispatch', '_copy_inst', '_copy_list',
'_copy_tuple', '_deepcopy_atomic', '_deepcopy_dict', '_deepcopy_dispatch',
'_deepcopy_inst', '_deepcopy_list', '_deepcopy_tuple', '_keep_alive', '_test',
'copy', 'deepcopy', 'error']

what you want is copy.deepcopy().



From alan.gauld@bt.com  Thu Feb  8 17:58:32 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 8 Feb 2001 17:58:32 -0000
Subject: [Tutor] Format strings for variables - how?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D57B@mbtlipnt02.btlabs.bt.co.uk>

> a=1
> b=3
> print "%0.2f" %(a/b)
0.00
> print "%0.2f" %(0.3333333)
0.33

That's because a and b are integers(aka whole numbers) 
so Python gives a whole number back ie. 0!

Try making either a or b a fraction/floating point/real 
number(choose your term :-) thus:

>>> a = 1.0
>>> b = 3
>>> print "%0.2f" % a/b
0.33

This is explained in more detail in my tutorial on 
the simple equences page.

Alan g.
http://www.crosswinds.net/~agauld/



From dsh8290@rit.edu  Thu Feb  8 23:28:56 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 8 Feb 2001 18:28:56 -0500
Subject: [Tutor] input() and raw_input()
In-Reply-To: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>; from porterh@m-net.arbornet.org on Thu, Feb 08, 2001 at 11:20:54AM -0500
References: <Pine.BSF.4.21.0102081104330.94504-100000@m-net.arbornet.org>
Message-ID: <20010208182856.B15013@harmony.cs.rit.edu>

All the responses given are good, but there is one thing they failed
to mention -- exceptions.  You may not want to bother with them now,
but as you become more experienced you will need to deal with them or
your programs will be very unstable.

Here is an example (when prompted for a number, I will enter invalid
data) :

>>> x = int( raw_input( "Enter a number: " ) )
Enter a number: invalid input
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  ValueError: invalid literal for int(): invalid input

>>> valid_input = 0 # we haven't gotten valid input yet
>>> while not valid_input :
...     try :
...         x = int( raw_input( "Enter an integer: " ) )
...         valid_input = 1
...     except ValueError , err :
...         print "'%s' is not a valid integer." %
...                         err.args[0].split(": ")[1]
... print "The user entered %d" % x
Enter an integer: asdf
'asdf' is not a valid integer.
Enter an integer: ;lkj
';lkj' is not a valid integer.
Enter an integer: 13
The user entered 13


If the int() function doesn't get a string that can be converted to an
integer, it throws a "ValueError" exception.  If you put the call to
int() in a try-except block, you can catch the ValueError exception
and do something about it.  If you don't catch it, your program will
terminate immediately.  

In the except block, I did a little "magic" to put a nice looking
error message together.  The key point I wanted to make is use
try-except once you understand the basics.

HTH,
-D



From dyoo@hkn.eecs.berkeley.edu  Fri Feb  9 09:14:11 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 9 Feb 2001 01:14:11 -0800 (PST)
Subject: [Tutor] CGI question
In-Reply-To: <200102081044_MC2-C4BB-B411@compuserve.com>
Message-ID: <Pine.LNX.4.21.0102090112160.1775-100000@c82114-a.pinol1.sfba.home.com>

On Thu, 8 Feb 2001, Sharriff Aina wrote:

> I=B4m going to generate from a Database with a Python CGI script a lot
> of HTML output, how can I output the content to the client in smaller
> chunks? I=B4ve heard of a "CHUNK" command somewher but I do=B4nt know
> where or how to implement this command. Any ideas?

Hmm... I'm not quite sure what you mean by a "chunk".  You should be able
to do regular printing to the brower without having to worry about
breaking something into small bits.

Perhaps "CHUNK" has to do with your database instead?  It reminds me of an
SQL data type; is this what you mean?



From mbouhaid@mailandnews.com  Fri Feb  9 18:50:26 2001
From: mbouhaid@mailandnews.com (Mario BouHaidar)
Date: Fri, 9 Feb 2001 10:50:26 -0800
Subject: [Tutor] (no subject)
Message-ID: <000a01c092c9$35c94ac0$88f858cb@orbital>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C09286.1C1735D0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



------=_NextPart_000_0007_01C09286.1C1735D0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0007_01C09286.1C1735D0--



From Christopher Bemis" <laser151@tvn.net  Fri Feb  9 16:55:40 2001
From: Christopher Bemis" <laser151@tvn.net (Christopher Bemis)
Date: Fri, 9 Feb 2001 11:55:40 -0500
Subject: [Tutor] Newbie
Message-ID: <001101c092b9$238508a0$1008683f@laser151>

This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C0928F.3980E0E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am a complete newbie when it comes to programming. I have been =
learning Python with "Sam's teach yourself Python in 24 hours". Here's =
my question....When I type the helloworld.py program in Notepad and then =
try to run it from Command Line, I get a flash of something that looks =
like a DOS window, is this supposed to be the program?=20


------=_NextPart_000_000E_01C0928F.3980E0E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am a complete newbie when it comes to =

programming. I have been learning Python with "Sam's teach yourself =
Python in 24=20
hours". Here's my question....When I type the helloworld.py program in =
Notepad=20
and then try to run it from Command Line, I get a flash of something =
that looks=20
like a DOS window, is this supposed to be the =
program?&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_000E_01C0928F.3980E0E0--



From shaleh@valinux.com  Fri Feb  9 17:39:27 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 09 Feb 2001 09:39:27 -0800 (PST)
Subject: [Tutor] Newbie
In-Reply-To: <001101c092b9$238508a0$1008683f@laser151>
Message-ID: <XFMail.20010209093927.shaleh@valinux.com>

On 09-Feb-2001 Christopher Bemis wrote:
> I am a complete newbie when it comes to programming. I have been learning
> Python with "Sam's teach yourself Python in 24 hours". Here's my
> question....When I type the helloworld.py program in Notepad and then try to
> run it from Command Line, I get a flash of something that looks like a DOS
> window, is this supposed to be the program? 
> 

yep.  What happens is it launches a DOS window, runs the app, then the app
quits and the window goes with it.  What you need to do is add a 'Press enter
to finish' section at the end of the app.  I bet if you read just a little
further they explain this.

Just add a line:

raw_input('Hit enter to exit')



From kalle@gnupung.net  Fri Feb  9 17:59:02 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 9 Feb 2001 18:59:02 +0100
Subject: [Tutor] Basic Question
In-Reply-To: <20010207.222043.-296151.0.sthickey@juno.com>; from sthickey@juno.com on Wed, Feb 07, 2001 at 10:20:42PM -0800
References: <20010207.222043.-296151.0.sthickey@juno.com>
Message-ID: <20010209185901.A1052@father>

--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sorry for taking long to answer.

Sez Stevenson M Hickey:
> I was recommended to Python as an easy language to learn and an efficient
> language to program in.  I am wondering if anyone knows how to command
> the Jet DataBase engine of Microsoft with Python scripts?=20

I don't know much about Windows programming, but I hear that ODBC is the
favored way to access databases.  If this is true, I think mxODBC is a good
bet.  http://www.lemburg.com/files/python/mxODBC.html

More information on database access with python can be found on:
http://www.python.org/topics/database/

> More directly, I am looking for some amplification of the Tutorial in the
> form of some simple scripts that will make windows parse ascii texts in
> various ways.  In particular, I would like to be able to scan several
> files and combine them at will or take several lines from one and put it
> in another, etc.  Common CShell stuff.  I am running Windows 98 on a 400
> MHz Pentium 2 with 60 Mb Ram. =20
>=20
> I guess, before I get too deep into this kind of a problem, I need to get
> some practice doing the utmost simple API calls.=20

A few documentation pages that you might want to take a look at:
http://www.python.org/doc/current/lib/builtin.html
http://www.python.org/doc/current/lib/module-string.html
http://www.python.org/doc/current/lib/module-re.html
http://www.python.org/doc/current/lib/module-fileinput.html

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--tKW2IUtsqtDRztdT
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6hC/ldNeA1787sd0RAh6TAJ0SwOvxo8q8tGrVzmqwWC6YtmS/NgCdHneb
h07/FM/OgPggoCzkU4UMYnI=
=sMHV
-----END PGP SIGNATURE-----

--tKW2IUtsqtDRztdT--


From randrews@planhouse.com  Fri Feb  9 17:53:07 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 09 Feb 2001 11:53:07 -0600
Subject: [Tutor] Newbie
References: <001101c092b9$238508a0$1008683f@laser151>
Message-ID: <3A842E83.5C1EC582@planhouse.com>

When this happens, it is likely that your program runs, possibly without
error.  However, your program may not be telling the window to remain
open for you to read the output.  There are a number of things you can
do to work this out.

1) Run your script from within IDLE.  Once IDLE is open, import your
script at the prompt, like this:

>>> import helloworld # if your script is helloworld.py

2) Add a line that forces the program to wait for your okay to close,
such as the following:

	print "hello, world"

	raw_input("Press Enter to exit the program. >")

Then you will have to press a key to end the script, and in Win95/98 you
will then have to type EXIT at the command prompt to close the "DOS"
window, if this is how you are running the script.

Hope this helps ya,
Rob Andrews
http://www.lowerstandard.com/python/pythonsource.html

> Christopher Bemis wrote:
> 
> I am a complete newbie when it comes to programming. I have been
> learning Python with "Sam's teach yourself Python in 24 hours". Here's
> my question....When I type the helloworld.py program in Notepad and
> then try to run it from Command Line, I get a flash of something that
> looks like a DOS window, is this supposed to be the program?
>


From sparling@uclick.com  Fri Feb  9 19:02:38 2001
From: sparling@uclick.com (Doug Sparling)
Date: Fri, 9 Feb 2001 13:02:38 -0600
Subject: [Tutor] Newbie
In-Reply-To: <001101c092b9$238508a0$1008683f@laser151>
Message-ID: <000801c092ca$df7e0140$460110ac@doug>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C09298.94E39140
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

 I am a complete newbie when it comes to programming. I have been learning
Python with "Sam's teach yourself Python in 24 hours". Here's my
question....When I type the helloworld.py program in Notepad and then try to
run it from Command Line, I get a flash of something that looks like a DOS
window, is this supposed to be the program?

[Douglas Sparling]
It works fine for me at the DOS command prompt. What you describe sounds
like you're clicking the filename in windows explorer.

------=_NextPart_000_0009_01C09298.94E39140
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">


<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D510590019-09022001><FONT=20
color=3D#0000ff>&nbsp;</FONT></SPAN>I am a complete newbie when it comes =
to=20
programming. I have been learning Python with "Sam's teach yourself =
Python in 24=20
hours". Here's my question....When I type the helloworld.py program in =
Notepad=20
and then try to run it from Command Line, I get a flash of something =
that looks=20
like a DOS window, is this supposed to be the program?&nbsp;<BR><SPAN=20
class=3D510590019-09022001><FONT =
color=3D#0000ff>&nbsp;</FONT></SPAN><BR><SPAN=20
class=3D510590019-09022001><FONT color=3D#0000ff>[Douglas=20
Sparling]&nbsp;&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><SPAN class=3D510590019-09022001><FONT face=3DArial size=3D2>It =
works fine for me=20
at the DOS command prompt. What you describe sounds like you're clicking =
the=20
filename&nbsp;in windows explorer.</FONT></SPAN></DIV></BODY></HTML>

------=_NextPart_000_0009_01C09298.94E39140--



From michaelbaker@operamail.com  Fri Feb  9 21:38:35 2001
From: michaelbaker@operamail.com (michaelbaker@operamail.com)
Date: Fri, 09 Feb 2001 13:38:35 -0800
Subject: [Tutor] create and fill a list with exec?
In-Reply-To: <E14QuSb-0004D9-00@mail.python.org>
Message-ID: <4.3.2.7.1.20010209132308.00b8f2a0@operamail.com>

how can I create an empty list and then fill it with stuff at the time of 
creation or without calling it explicitly by name later?
 >>> dir()
['__builtins__', '__doc__', '__name__']
 >>> a=[1,2,3,4,5]
 >>> for b in a:
	exec 'buffer%s=[]' %b
	
 >>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'b', 'buffer1', 'buffer2', 
'buffer3', 'buffer4', 'buffer5']

I want to do someting like this:

 >>> a=[1,2,3,4,5]
 >>> for b in a:
	exec 'buffer%s=[], buffer%s.append(b)' %b

this doesn't work.

I could fill these lists later, but I'm not sure how to do that either:

 >>> for c in dir():
	for d in range(len(a)+1):
		if c=='buffer%s' %d:
			c.append(d)

			
Traceback (innermost last):
   File "<pyshell#27>", line 4, in ?
     c.append(d)
AttributeError: append

how can I make this work???
thanks tutors



From michaelbaker@operamail.com  Sat Feb 10 05:24:04 2001
From: michaelbaker@operamail.com (michaelbaker@operamail.com)
Date: Fri, 09 Feb 2001 21:24:04 -0800
Subject: [Tutor] simple math but I can't quite get it
In-Reply-To: <E14RGw6-0008K5-00@mail.python.org>
Message-ID: <4.3.2.7.1.20010209212108.00a86f00@operamail.com>

for a list of integers
a=[23,45,65,27,98]
how can I get the sum total of all integers in this list?

I just can't qutie make it on this one :(
thanks



From dyoo@hkn.eecs.berkeley.edu  Sat Feb 10 07:03:19 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 9 Feb 2001 23:03:19 -0800 (PST)
Subject: [Tutor] simple math but I can't quite get it
In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com>
Message-ID: <Pine.LNX.4.21.0102092135060.900-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 9 Feb 2001 michaelbaker@operamail.com wrote:

> for a list of integers
> a=[23,45,65,27,98]
> how can I get the sum total of all integers in this list?
> 
> I just can't qutie make it on this one :(
> thanks

Hello!  There are several approaches to this.

If we know that 'a' will always contain 5 numbers, we can go with the
direct route:

    sum = a[0] + a[1] + a[2] + a[3] + a[4]

So instead, I'll interpret your question as: "How do I add up any list of
numbers together?"

One thing we can do keep a running total.  We can look at each number in
turn, and add it to our running total, until we run out of numbers to look
at.  In Python, it looks like this:

###
    sum = 0
    for x in a:
        sum = sum + x
###

This is probably one of the simpler, straightforward ways of adding those
numbers up.  Whenever you use lists, you'll probably make a lot of use of
for loops.


There are other ways of adding numbers; one of these ways is the
"functional" approach:

###
>>> def add(x, y): return x + y
... 
>>> sum = reduce(add, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> sum
55
###

This, too, tells Python to: "Reduce all those list elements into a single
thing, by using the add() function repeatedly."  It might be a little
weird because we're feeding the add() function itself into the reduce()
function, but it's not too hard once you play with it.

Here's another example of using reduce to find the product of all numbers
in a list:

###
>>> def mul(x, y): return x * y
...
>>> product = reduce(mul, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> product
3628800
###

Anyway, hope this helps!



From wmperry@swbell.net  Sat Feb 10 07:04:22 2001
From: wmperry@swbell.net (William Perry)
Date: Sat, 10 Feb 2001 01:04:22 -0600
Subject: [Tutor] simple math but I can't quite get it
In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com>
References: <4.3.2.7.1.20010209212108.00a86f00@operamail.com>
Message-ID: <200102100104220250.0BC53C7A@mail.swbell.net>

Is this what you meant?

================

def addum():
	ans=a[0]
	lst=a[1:]
	for i in lst:
		x=i+ans
	print x
================

*********** REPLY SEPARATOR  ***********

On 2/9/01 at 9:24 PM michaelbaker@operamail.com wrote:

>for a list of integers
>a=[23,45,65,27,98]
>how can I get the sum total of all integers in this list?
>
>I just can't qutie make it on this one :(
>thanks
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor





From dyoo@hkn.eecs.berkeley.edu  Sat Feb 10 07:08:30 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 9 Feb 2001 23:08:30 -0800 (PST)
Subject: [Tutor] Newbie
In-Reply-To: <000801c092ca$df7e0140$460110ac@doug>
Message-ID: <Pine.LNX.4.21.0102092306300.900-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 9 Feb 2001, Doug Sparling wrote:

>  I am a complete newbie when it comes to programming. I have been learning
> Python with "Sam's teach yourself Python in 24 hours". Here's my
> question....When I type the helloworld.py program in Notepad and then try to
> run it from Command Line, I get a flash of something that looks like a DOS
> window, is this supposed to be the program?

Sounds like your program is running, but then closing too quickly.  Try
adding this at the end of your program:

    raw_input("Please press ENTER to finish.")

This will force your program to wait until you press enter, and will let
you see what's happening.

You might want to try out IDLE, which is an environment that lets you
experiment more freely with Python programming.  IDLE should already be
installed in your computer: search your Start Menu under the Python group.

Good luck!



From dyoo@hkn.eecs.berkeley.edu  Sat Feb 10 07:36:05 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 9 Feb 2001 23:36:05 -0800 (PST)
Subject: [Tutor] create and fill a list with exec?
In-Reply-To: <4.3.2.7.1.20010209132308.00b8f2a0@operamail.com>
Message-ID: <Pine.LNX.4.21.0102092327430.1746-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 9 Feb 2001 michaelbaker@operamail.com wrote:

> how can I create an empty list and then fill it with stuff at the time of 
> creation or without calling it explicitly by name later?
>  >>> dir()
> ['__builtins__', '__doc__', '__name__']
>  >>> a=[1,2,3,4,5]
>  >>> for b in a:
> 	exec 'buffer%s=[]' %b

As a note, if you're beginning to learn the language, I'd recommend
against using exec() --- there's probably an easier way to do what you're
doing.

It looks like you're making several lists (buffer1, buffer2, buffer3,
buffer4, and buffer5).  It might be better to make a list of those buffers
instead:

###
>>> mybuffers = []
>>> for i in range(5):
...     mybuffers.append([])
... 
>>> mybuffers
[[], [], [], [], []]
###

Now we can treat buffer1 as mybuffers[0], buffer2 as mybuffers[1], etc.  
This is nice because we can now pass off all the buffers with a single
name, "mybuffers".

Lists are really nice, and using them will allow you to avoid tricky
exec() stuff.  Alan Gauld explains them pretty nicely in his tutorial
here:

    http://www.crosswinds.net/~agauld/

Good luck!



From arcege@shore.net  Sat Feb 10 13:53:53 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sat, 10 Feb 2001 08:53:53 -0500 (EST)
Subject: [Tutor] simple math but I can't quite get it
In-Reply-To: <Pine.LNX.4.21.0102092135060.900-100000@c82114-a.pinol1.sfba.home.com> from "Danny Yoo" at Feb 09, 2001 11:03:19 PM
Message-ID: <200102101353.IAA01817@northshore.shore.net>

> There are other ways of adding numbers; one of these ways is the
> "functional" approach:
> 
> ###
> >>> def add(x, y): return x + y
> ... 
> >>> sum = reduce(add, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
> >>> sum
> 55
> ###
> 
> This, too, tells Python to: "Reduce all those list elements into a single
> thing, by using the add() function repeatedly."  It might be a little
> weird because we're feeding the add() function itself into the reduce()
> function, but it's not too hard once you play with it.
> 
> Here's another example of using reduce to find the product of all numbers
> in a list:
> 
> ###
> >>> def mul(x, y): return x * y
> ...
> >>> product = reduce(mul, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
> >>> product
> 3628800
> ###

These functions are also built in to the operator module.

>>> l = range(1, 11)
>>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> import operator
>>> reduce(operator.add, l)
55
>>> reduce(operator.mul, l)
3628800
>>>

Most all the Python operators have function analogs in the `operator'
module.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From charlie@webmind.com  Sat Feb 10 23:13:54 2001
From: charlie@webmind.com (Charlie Derr)
Date: Sat, 10 Feb 2001 18:13:54 -0500
Subject: [Tutor] simple math but I can't quite get it
In-Reply-To: <4.3.2.7.1.20010209212108.00a86f00@operamail.com>
Message-ID: <LOBBJCAMDNLNCGCCHGEIIENEJGAA.charlie@webmind.com>

>>> total = 0
>>> for j in range(0,len(a)):
...	  total+=a[j]

>>> print total


	hth,
		~c

~ -----Original Message-----
~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
~ michaelbaker@operamail.com
~ Sent: Saturday, February 10, 2001 12:24 AM
~ To: tutor@python.org
~ Subject: [Tutor] simple math but I can't quite get it
~ 
~ 
~ for a list of integers
~ a=[23,45,65,27,98]
~ how can I get the sum total of all integers in this list?
~ 
~ I just can't qutie make it on this one :(
~ thanks
~ 
~ 
~ _______________________________________________
~ Tutor maillist  -  Tutor@python.org
~ http://mail.python.org/mailman/listinfo/tutor


From wheelege@tsn.cc  Sun Feb 11 07:41:43 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Sun, 11 Feb 2001 18:41:43 +1100
Subject: [Tutor] Raiobutton question
Message-ID: <000001c093fe$1dc06c20$d0755cca@glen>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C0945A.47551660
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hi.  Here is some code..


from Tkinter import *

var =3D IntVar()

##def die(x):
##    print 'dead'
##    print x

   =20
root =3D Tk()

for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), =
('Stupid', 15)]:
    Radiobutton(root, text=3Dtext, value=3Dvalue, =
variable=3Dvar).pack(anchor=3DW)
##b =3D Button(root, text=3D'lets go', command=3D
##           lambda x=3Dx:die(x))]
var.set(60)

mainloop()

  I don't know why I get this error

Traceback (most recent call last):
  File "c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, =
in RunScript
    exec codeObject in __main__.__dict__
  File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in ?
    var =3D IntVar()
  File "c:\python20\lib\lib-tk\Tkinter.py", line 231, in __init__
    Variable.__init__(self, master)
  File "c:\python20\lib\lib-tk\Tkinter.py", line 172, in __init__
    self._tk =3D master.tk
AttributeError: 'None' object has no attribute 'tk'
>>> Exception exceptions.AttributeError: "'IntVar' instance has no =
attribute '_tk'" in <method Variable.__del__ of IntVar instance at =
014E6DBC> ignored

  Upon execution.  It is almost verbatim from J Grayson's book.  Also, =
I'd like to know how to fix errors such as these if they come up in the =
future - this is the first time I have seen one like this.

  Thanks,
  Glen.

------=_NextPart_000_0009_01C0945A.47551660
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hi.&nbsp; Here is some code..</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>var =3D IntVar()</DIV>
<DIV>&nbsp;</DIV>
<DIV>##def die(x):<BR>##&nbsp;&nbsp;&nbsp; print =
'dead'<BR>##&nbsp;&nbsp;&nbsp;=20
print x</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; <BR>root =3D Tk()</DIV>
<DIV>&nbsp;</DIV>
<DIV>for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),=20
('Stupid', 15)]:<BR>&nbsp;&nbsp;&nbsp; Radiobutton(root, text=3Dtext, =
value=3Dvalue,=20
variable=3Dvar).pack(anchor=3DW)<BR>##b =3D Button(root, text=3D'lets =
go',=20
command=3D<BR>##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
lambda x=3Dx:die(x))]<BR>var.set(60)</DIV>
<DIV>&nbsp;</DIV>
<DIV>mainloop()<BR></DIV>
<DIV>&nbsp; I don't know why I get this error</DIV>
<DIV>&nbsp;</DIV>
<DIV>Traceback (most recent call last):<BR>&nbsp; File=20
"c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, in=20
RunScript<BR>&nbsp;&nbsp;&nbsp; exec codeObject in =
__main__.__dict__<BR>&nbsp;=20
File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in=20
?<BR>&nbsp;&nbsp;&nbsp; var =3D IntVar()<BR>&nbsp; File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 231, in =
__init__<BR>&nbsp;&nbsp;&nbsp;=20
Variable.__init__(self, master)<BR>&nbsp; File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 172, in =
__init__<BR>&nbsp;&nbsp;&nbsp;=20
self._tk =3D master.tk<BR>AttributeError: 'None' object has no attribute =

'tk'<BR>&gt;&gt;&gt; Exception exceptions.AttributeError: "'IntVar' =
instance has=20
no attribute '_tk'" in &lt;method Variable.__del__ of IntVar instance at =

014E6DBC&gt; ignored<BR></DIV>
<DIV>&nbsp; Upon execution.&nbsp; It is almost verbatim from J Grayson's =

book.&nbsp; Also, I'd like to know how to fix errors such as these if =
they come=20
up in the future - this is the first time I have seen one like =
this.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0009_01C0945A.47551660--



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 11 11:58:48 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 11 Feb 2001 03:58:48 -0800 (PST)
Subject: [Tutor] getopt options
In-Reply-To: <3A864B3D.FC5F3BBD@early.com>
Message-ID: <Pine.LNX.4.21.0102110303190.703-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 11 Feb 2001, Tom Connor wrote:

> I'm trying to find a tutorial for getopt. But most things seem to refer
> to Unix or some other source not suitable for my current level of
> understanding.  I find the Python documentation pretty cryptic.  Does
> anyone have suggestions where I should go to improve my understanding of
> getopt and it's options?

Good evening; you're probably looking at the reference material for the
getopt module here:

    http://python.org/doc/current/lib/module-getopt.html

[note: this message is very long, and will look at the very last example
in some detail.  Apologies in advance.]

Could you tell us where the reference material starts sounding funny?  We
can help interpret the examples on the bottom.

Let's take a look at the very last example that the reference manual
brings up.  I'll simplify the example so we don't look at the "long"
argument stuff.  We'll be looking at variations of this:

###
    opts, args = getopt.getopt(sys.argv[1:], "ho:")
###

getopt() will return two lists: "opts' will cotain all the option
name-value pairs that we're looking for, while the "args" will contain
anything that it doesn't know about.  When we use getopt(), we need to
tell it what options we're paying attention to.

Let's take a look at the second argument to that getopt() call:

    "ho:"

This means that our program will expect to see at most 2 types of
"short" one-character things.  For example, we could pass the following
arguments:

    -h
    -h -oOutput
    -h -o Output
    -oRabbit

which should be all legal.  That colon in front of the 'o' means that we
expect it to take in an additional argument, so getopt will suck the very
next word in front of any "-o"'s.  If we try to use the '-o' option
without something in front, getopt() will respond with an error.  That's
the theory, at least.  *grin*  Let's put it into practice.


Interpreter time.

###
## Case 1
>>> getopt(['-h', '-o', 'Object'], 'ho:')
([('-h', ''), ('-o', 'Object')], [])
###

In this case, we've probably sent getopt the following command line:

    some_program_name -h -o Object

Python will automagically parse out the arguments as the list sys.argv.  
We see that getopt returns back to us a tuple of two things.  The first
contains all the options.  The options themselves have an interesting
structure: each "option" is a 2-tuple:

    [('-h', ''), ('-o', 'Object')]

But why doesn't it do this instead:

    [-h, ('-o', 'Object')]   ?

Isn't this more efficient?  The reason getopt does it with 2-tuples always
is because it's a matter of consistency.  When we write programs to figure
out what options have turned on, it's easy if we can expect getopt to
return something with a very uniform structure.  If we look later at the
code:

###
    for o, a in opts:
###

we expect to place the option name in 'o' and the argument value in 'a';
we wouldn't be able to do this unless we were absolutely sure that every
element is a 2-tuple; otherwise, it wouldn't be able to unpack the tuple
properly.


Let's take a look at another call:

###
## Case 2
>>> getopt(['-o=Object'], 'ho:')
([('-o', '=Object')], [])
###

Here, we see that the options are optional; even though we expect to see
'-h' or '-o', nothing in getopt will break if we leave one of the options
off alone.  However, getopt is equipped to recognize when an option is
incomplete.  That's the next case:


###
## Case 3
>>> getopt(['-o'], 'ho:')
Traceback (innermost last):
# [edited for brevity]
getopt.error: option -o requires argument
###

Here, since '-o' needs to have something in front, getopt() will
ultimately fail and complain with an exception.  This error reporting is
actually useful, though, because we can use exception handling to respond
appropriately to these situations.  This message is too long already, so I
won't talk about exception handling for now.



Here's a tricky case:
###
## Case 4
>>> getopt(['-homer'], 'ho:')
([('-h', ''), ('-o', 'mer')], [])
###

What's going on?  The trick is that, in UNIX tradition, when we put
something like:

    -homer

we really mean:

    -h -o -m -e -r

as shorthand...  That is, unless -o is an option that sucks the next word
as its argument value.  Since we've defined -o as such, that's why 'mer'
becomes the argument to '-o'.  We can see this more clearly with another
example:

###
>>> getopt(['-abc'], 'abcd')
([('-a', ''), ('-b', ''), ('-c', '')], [])
###



Finally, here's a wacky case:

## Case 5
>>> getopt(['-h', 'radish', '-o=Object'], 'ho:')
([('-h', '')], ['radish', '-o=Object'])
###

What's happening?  You might be wondering, why didn't '-o=Object' get
parsed out into:

    (-o, Object)   ?? 

The reason is because all options need to come _before_ anything that
looks like a regular argument (like a filename).  So: ['-h', '-o=Object',
'radish'] would have worked normally.  Options can be irritating that way,
but that's how they're defined: as soon as getopt starts to see arguments
that don't look like options, it will disregard the rest and stop parsing.

If you have any questions, please feel free to ask; it's much too quiet in
this mailing list.  *grin*



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 11 12:09:55 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 11 Feb 2001 04:09:55 -0800 (PST)
Subject: [Tutor] Raiobutton question
In-Reply-To: <000001c093fe$1dc06c20$d0755cca@glen>
Message-ID: <Pine.LNX.4.21.0102110400300.703-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 11 Feb 2001, Glen Wheeler wrote:

> var = IntVar()
[some code omitted]
> root = Tk()

>   I don't know why I get this error
> Traceback (most recent call last):
[cut]
> AttributeError: 'None' object has no attribute 'tk'

>   It is almost verbatim from J Grayson's book.  

The problem is that when we construct an InvVar(), Tk expects us to have a
root window already set up.  The line:

    root = Tkinter.Tk()

initializes _tk to something that all other widgets will depend
on.  So, when we do something like:

###
root = Tkinter.Tk()
button = Tkinter.Button()
###

in the background, the Button() knows that it should connect up with root,
because the _tk variable's initialized.


Going back to your program, the IntVar definition is a bit too early;
IntVar doesn't know where to attach to until we either make a root window.  
Try putting it after your Tk() call, and you should be ok.


> Also, I'd like to know how to fix errors such as these if they come up
> in the future - this is the first time I have seen one like this.

To tell the truth, I have no clue what an InvVar is.  But if you ever see
something that says "_Tk is undefined", it's probably because a Tk()
instance hasn't been built yet.

(Someday, I shall have to take a look at "Python and Tkinter Programming",
and really understand what's happening... *grin*)

Good luck!



From arcege@shore.net  Sun Feb 11 15:15:19 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sun, 11 Feb 2001 10:15:19 -0500 (EST)
Subject: [Tutor] Raiobutton question
In-Reply-To: <Pine.LNX.4.21.0102110400300.703-100000@c82114-a.pinol1.sfba.home.com> from "Danny Yoo" at Feb 11, 2001 04:09:55 AM
Message-ID: <200102111515.KAA09747@northshore.shore.net>

> The problem is that when we construct an InvVar(), Tk expects us to have a
> root window already set up.  The line:
> 
>     root = Tkinter.Tk()
> 
> initializes _tk to something that all other widgets will depend
> on.  So, when we do something like:
> 
> ###
> root = Tkinter.Tk()
> button = Tkinter.Button()
> ###
> 
> in the background, the Button() knows that it should connect up with root,
> because the _tk variable's initialized.
> 
> 
> Going back to your program, the IntVar definition is a bit too early;
> IntVar doesn't know where to attach to until we either make a root window.  
> Try putting it after your Tk() call, and you should be ok.

The reason is a little more subtle than this.  All _widgets_ will
implicitly create a new Tk() instance if None is set (and if Tkinter.
_support_default_root is true).  However the Variable classes (of
which IntVar is a subclass) are not widgets, and do not have this
behavior.

So where just
  python -c 'import Tkinter; Tkinter.Button()'
creating a widget with no Tk would work, but creating a variable before
a widget won't
  python -c 'import Tkinter; Tkinter.IntVar()'

The Button initialization detects that there is no _default_root
and creates a Tk instance (which sets _default_root);  but IntVar
does nothing like this, and expects _default_root to be set
already.

Glen, Grayson's "Python and Tkinter Programming" example that I assume
you are using (pp. 37-38) does not set "root = Tk()" at all, but uses
the root in the Radiobutton call.  This is confusing, and Grayson does
not really explain the Variable classes well at all.  Unfortunately, a
lot of the Tkinter documentation does not do this part of Tkinter
justice either.

> To tell the truth, I have no clue what an InvVar is.  But if you ever see
> something that says "_Tk is undefined", it's probably because a Tk()
> instance hasn't been built yet.

Tkinter is written on top of Tcl/Tk, which has its own variables and
functions, so there are such classes as Variable, and its subclasses,
and CallWhapper so Tk can use Python functions and map Tcl variables to
Python names.  Much of this is handled for you in Tkinter itself, but
for "shared" variables like Radiobutton instances required a new form
of object.

> (Someday, I shall have to take a look at "Python and Tkinter Programming",
> and really understand what's happening... *grin*)

It's a very good book, I recommend getting it.  I would suggest reading
Fredrik Lundh's not-as-complete "An Introduction to Tkinter" as well
  <URL: http:/www.pythonware.com/library/tkinter/introduction/>

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From georg.simon@bnmsp.de  Sun Feb 11 17:35:36 2001
From: georg.simon@bnmsp.de (Georg Simon)
Date: Sun, 11 Feb 2001 18:35:36 +0100
Subject: [Tutor] Fonts for Canvas text items ?
Message-ID: <3A86CD81.755FCE8F@bnmsp.de>

Python 2.0 and Windows 98

To find out how to change the font for a text item on a Canvas, I tried
the following code. But the only effect I get is on the size of the
font. The larger size appears in the first three lines, the tiny size in
the last line.

How can I get different fonts, different thickness, different size ?

Georg Simon


from Tkinter import *

Wurzel=Tk()

Leinwand = Canvas(Wurzel)

Leinwand.create_text(50,50,text="Helvetica",font="Helvetica")
Leinwand.create_text(50,100,text="NewCourier",font="NewCourier")
Leinwand.create_text(50,150,text="bold",font="bold")
Leinwand.create_text(50,200,text="no font")

Leinwand.pack()

Wurzel.mainloop()


From tim@johnsons-web.com  Sun Feb 11 18:10:12 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 11 Feb 2001 09:10:12 -0900
Subject: [Tutor] Textbook Recommendation
References: <000001c093fe$1dc06c20$d0755cca@glen>
Message-ID: <01021109135704.05012@shecom>

Hello All:
	I'm learning Python, and at the same time, creating an online course in
the language for a local school district.
I would welcome recommendations on a textbook:
I have about  6 books on Python: The two I am considering are:
1)Learning Python in 24 hours
2)Learning Python

Any and all opinions would be welcome.
TIA
 --
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From rob@jam.rr.com  Sun Feb 11 18:22:05 2001
From: rob@jam.rr.com (R. A.)
Date: Sun, 11 Feb 2001 12:22:05 -0600
Subject: [Tutor] Textbook Recommendation
References: <000001c093fe$1dc06c20$d0755cca@glen> <01021109135704.05012@shecom>
Message-ID: <3A86D84D.848F94B6@jam.rr.com>

Each of the two books you mention seem fine.  You should also consider
Alan Gauld's *Learning to Program Using Python*.  I've been through the
material on his site, which I found to be of high quality, and my
understanding is that the book is excellent.  If I purchase another
introductory Python book, it's the one I figure I'll spend my money on,
especially if the intended purpose is to use the material to teach
programming to young people.

Rob Andrews

Tim Johnson wrote:
> 
> Hello All:
>         I'm learning Python, and at the same time, creating an online course in
> the language for a local school district.
> I would welcome recommendations on a textbook:
> I have about  6 books on Python: The two I am considering are:
> 1)Learning Python in 24 hours
> 2)Learning Python
> 
> Any and all opinions would be welcome.
> TIA
>  --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Visit the Useless Python Repository!
http://www.lowerstandard.com/python/pythonsource.html


From arcege@shore.net  Sun Feb 11 18:35:44 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sun, 11 Feb 2001 13:35:44 -0500 (EST)
Subject: [Tutor] Fonts for Canvas text items ?
In-Reply-To: <3A86CD81.755FCE8F@bnmsp.de> from "Georg Simon" at Feb 11, 2001 06:35:36 PM
Message-ID: <200102111835.NAA01957@northshore.shore.net>

> Python 2.0 and Windows 98
> 
> To find out how to change the font for a text item on a Canvas, I tried
> the following code. But the only effect I get is on the size of the
> font. The larger size appears in the first three lines, the tiny size in
> the last line.
> 
> How can I get different fonts, different thickness, different size ?

I don't know about Win98, but you can get the list of fonts with
  Python 2.0 (#3, Dec 18 2000, 02:47:55)
  [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2
  Type "copyright", "credits" or "license" for more information.
  >>> import tkFont
  >>> tkFont.families()
  ('fangsong ti', 'fixed', 'clearlyu alternate glyphs', 'charter',
  'lucidatypewriter', 'lucidabright', 'times', 'lucidux sans',
  'open look glyph', 'song ti', 'zapf dingbats', 'avantgarde',
  'helvetica', 'open look cursor', 'newspaper', 'mincho',
  'clearlyu ligature', 'lucidux mono', 'clearlyu pua', 'palatino',
  'courier', 'clearlyu', 'lucida', 'utopia', 'clean', 'nil',
  'terminal', 'zapf chancery', 'cursor', 'symbol', 'gothic',
  'bookman', 'lucidux serif', 'new century schoolbook',
  'clearlyu arabic extra')
  >>> root = tkFont.Tkinter.Tk()
  >>> f = tkFont.Font(root, ('courier', 10, tkFont.NORMAL))
  >>> tkFont.Tkinter.Label(root, text='hi', font=f).pack()

You should be able to set fonts with Font instances.

  -Arcege

PS: Your example worked fine on my systems.

> 
> from Tkinter import *
> 
> Wurzel=Tk()
> 
> Leinwand = Canvas(Wurzel)
> 
> Leinwand.create_text(50,50,text="Helvetica",font="Helvetica")
> Leinwand.create_text(50,100,text="NewCourier",font="NewCourier")
> Leinwand.create_text(50,150,text="bold",font="bold")
> Leinwand.create_text(50,200,text="no font")
> 
> Leinwand.pack()
> 
> Wurzel.mainloop()

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From arcege@shore.net  Sun Feb 11 18:44:49 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sun, 11 Feb 2001 13:44:49 -0500 (EST)
Subject: [Tutor] Textbook Recommendation
In-Reply-To: <01021109135704.05012@shecom> from "Tim Johnson" at Feb 11, 2001 09:10:12 AM
Message-ID: <200102111844.NAA02650@northshore.shore.net>

> 	I'm learning Python, and at the same time, creating an online course in
> the language for a local school district.
> I would welcome recommendations on a textbook:
> I have about  6 books on Python: The two I am considering are:
> 1)Learning Python in 24 hours
> 2)Learning Python
> 
> Any and all opinions would be welcome.

If you are interested in teaching Python, then I suggest that you look
into CP4E ("Computer Programming for Everybody"), which is a project
now on hold, and the EDU SIG ("Python in Education").

Resources:
* CP4E: <URL: http://www.python.org/cp4e/>
* EDU-SIG: <URL: http://www.python.org/sigs/edu-sig/>

Both books are good.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From b_hitesh@hotmail.com  Sun Feb 11 19:32:46 2001
From: b_hitesh@hotmail.com (Hitesh N Brahmbhatt)
Date: Sun, 11 Feb 2001 11:32:46 -0800
Subject: [Tutor] How to compile "odbchelper.py" app used in "diveintopython" book ?
Message-ID: <3A86E8DE.6C64ECA0@hotmail.com>

Hi,

When I compile this file, it gives me an SyntaxError on
for statement. In the Python documentation I have the
for loop is always used as follows :

for i in list:

while the "odbchelper.py" uses it as

[(%s=%s) % (k, params[k]) for k in params.keys()]

So, I tried to put the ":" at the end of the for statement
but it doesn't help.

Can you tell me what is wrong ? I am pasting the whole prgram
and the output below:

def buildConnectionString(params):
    """Build a connection string from a dictionary of parameters.

    Returns string."""
    return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])

if __name__ == "__main__":
    myParams = {"server":"mpilgrim", \
                "database":"master", \
                "uid":"sa", \
                "pwd":"secret" \
                }
    print buildConnectionString(myParams)

output of "python odbchelper.py" :

  File "odbchelper.py", line 5
    return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])
                                                ^
SyntaxError: invalid syntax 

Thanks,

Hitesh


From dyoo@hkn.eecs.berkeley.edu  Sun Feb 11 21:46:53 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 11 Feb 2001 13:46:53 -0800 (PST)
Subject: [Tutor] How to compile "odbchelper.py" app used in "diveintopython"
 book ?
In-Reply-To: <3A86E8DE.6C64ECA0@hotmail.com>
Message-ID: <Pine.LNX.4.21.0102111337280.19272-100000@hkn.eecs.berkeley.edu>

On Sun, 11 Feb 2001, Hitesh N Brahmbhatt wrote:

>     print buildConnectionString(myParams)
> 
> output of "python odbchelper.py" :
> 
>   File "odbchelper.py", line 5
>     return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])
>                                                 ^
> SyntaxError: invalid syntax 

Do you have Python 2.0?  It looks like odbchelper.py was written using the
"list comprehensions" feature within Python 2.0.  One equivalent
way of writing that in Python 1.52 format is:

###
    from string import join
    return join(map(lambda k: "%s=%s" % (k, params[k]), params.keys()),
                ';')
###

But it might just be cleaner to write your own function to break that
complicated statement down:

###
def makeNameValuePairs(dict):
    result = []
    for key, value in dict.items():
          result.append("%s=%s" % (key, value))
    return result
###

Then the statement above will look like this:

    return join(makeNameValuePairs(params), ';')

which is definitely much cleaner to read.

Hope this helps!



From wsryu@fas.harvard.edu  Mon Feb 12 02:51:04 2001
From: wsryu@fas.harvard.edu (William Ryu)
Date: Sun, 11 Feb 2001 21:51:04 -0500
Subject: [Tutor] Get IP address?
Message-ID: <4.3.2.7.2.20010211215019.00ba3ba0@pop.fas.harvard.edu>

Is there a function to get the IP address of your machine?

Thanks,

-w



From dyoo@hkn.eecs.berkeley.edu  Mon Feb 12 05:58:22 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 11 Feb 2001 21:58:22 -0800 (PST)
Subject: [Tutor] Get IP address?
In-Reply-To: <4.3.2.7.2.20010211215019.00ba3ba0@pop.fas.harvard.edu>
Message-ID: <Pine.LNX.4.21.0102112156190.30259-100000@hkn.eecs.berkeley.edu>

On Sun, 11 Feb 2001, William Ryu wrote:

> Is there a function to get the IP address of your machine?

According to:

    http://python.org/doc/current/lib/module-socket.html

you can do this with the socket module:

    from socket import gethostbyname, gethostname
    print gethostbyname(gethostname())



From wheelege@tsn.cc  Mon Feb 12 08:01:08 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 12 Feb 2001 19:01:08 +1100
Subject: [Tutor] Raiobutton question
References: <200102111515.KAA09747@northshore.shore.net>
Message-ID: <004001c094c9$f56750a0$a3755cca@glen>

  Thanks alot for the help - I understand why that wasn't working.  Also,
the reason I had the root = Tk() in there is because Grayson explains he
expects that (among other header stuff) at the beginning of all his examples
(note he says beginning, and not 3rd in line, like I had it).
  However, my real problem is still rearing it's ugly head.  Almost the same
code as before :

from Tkinter import *

root = Tk()

x = IntVar()

def die(x):
    print 'dead'
    print x

for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), ('Stupid',
15)]:
    Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W)
b = Button(root, text='lets go', command=
           lambda x=x:die(x)).pack()

x.set(60)  ## meant to select a radio button as default however does not
work

mainloop()

  Except this one makes a button that is meant to print 'dead' and also the
value of x.  This doesn't happen, instead it prints the name given to x upon
its creation.  It appears that x is not changed by the radio buttons, or
maybe it isn't even recognised (wrong namespace?  nah cos then the
radiobuttons would throw an exception....right?).
  I know this is an easy problem - they are the ones I have the most trouble
with.  It seems I can always work my way through the big ugly hard
things...just not the easy ones.

  Thanks again,
  Glen.



From gibbs05@flash.net  Mon Feb 12 10:59:21 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Mon, 12 Feb 2001 04:59:21 -0600
Subject: [Tutor] Raiobutton question
References: <200102111515.KAA09747@northshore.shore.net> <004001c094c9$f56750a0$a3755cca@glen>
Message-ID: <026c01c094e2$e5fc2280$e7de3040@gibbs05>

Greetings Glen & All,

Since I'm awake and struggling to learn Tkinter also, I've decided to jump
in.

I tried your code in PythonWin and the value of x is indeed being set by the
radiobutton.

The values stored in the TK variables can be retrieved using their 'get'
method, so the following modification to the die function should fix your
output.

def die(x)
    print 'dead'
    print x.get()

I think you can find this in the top paragraph on page 152 of 'Python and
Tkinter Programming' by Grayson.

Your code set the radiobutton's default just fine when I tried it, so I
can't help you with that one. ;-)

Good luck
Harry

>   Thanks alot for the help - I understand why that wasn't working.  Also,
> the reason I had the root = Tk() in there is because Grayson explains he
> expects that (among other header stuff) at the beginning of all his
examples
> (note he says beginning, and not 3rd in line, like I had it).
>   However, my real problem is still rearing it's ugly head.  Almost the
same
> code as before :
>
> from Tkinter import *
>
> root = Tk()
>
> x = IntVar()
>
> def die(x):
>     print 'dead'
>     print x
>
> for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),
('Stupid',
> 15)]:
>     Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W)
> b = Button(root, text='lets go', command=
>            lambda x=x:die(x)).pack()
>
> x.set(60)  ## meant to select a radio button as default however does not
> work
>
> mainloop()
>
>   Except this one makes a button that is meant to print 'dead' and also
the
> value of x.  This doesn't happen, instead it prints the name given to x
upon
> its creation.  It appears that x is not changed by the radio buttons, or
> maybe it isn't even recognised (wrong namespace?  nah cos then the
> radiobuttons would throw an exception....right?).
>   I know this is an easy problem - they are the ones I have the most
trouble
> with.  It seems I can always work my way through the big ugly hard
> things...just not the easy ones.
>
>   Thanks again,
>   Glen.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From wheelege@tsn.cc  Mon Feb 12 10:59:52 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 12 Feb 2001 21:59:52 +1100
Subject: [Tutor] Raiobutton question
References: <200102111515.KAA09747@northshore.shore.net> <004001c094c9$f56750a0$a3755cca@glen> <026c01c094e2$e5fc2280$e7de3040@gibbs05>
Message-ID: <002901c094e2$eda7f0e0$b8755cca@glen>

  Thanks, it seems I need more reading on the different methods of the
variable classes.  Python docs, here I come!  The default setting doesn't
really matter...not yet anyway :)

  Glen.

----- Original Message -----
From: Harry Kattz <gibbs05@flash.net>
To: Glen Wheeler <wheelege@tsn.cc>
Cc: <tutor@python.org>
Sent: Monday, February 12, 2001 9:59 PM
Subject: Re: [Tutor] Raiobutton question


> Greetings Glen & All,
>
> Since I'm awake and struggling to learn Tkinter also, I've decided to jump
> in.
>
> I tried your code in PythonWin and the value of x is indeed being set by
the
> radiobutton.
>
> The values stored in the TK variables can be retrieved using their 'get'
> method, so the following modification to the die function should fix your
> output.
>
> def die(x)
>     print 'dead'
>     print x.get()
>
> I think you can find this in the top paragraph on page 152 of 'Python and
> Tkinter Programming' by Grayson.
>
> Your code set the radiobutton's default just fine when I tried it, so I
> can't help you with that one. ;-)
>
> Good luck
> Harry
>
> >   Thanks alot for the help - I understand why that wasn't working.
Also,
> > the reason I had the root = Tk() in there is because Grayson explains he
> > expects that (among other header stuff) at the beginning of all his
> examples
> > (note he says beginning, and not 3rd in line, like I had it).
> >   However, my real problem is still rearing it's ugly head.  Almost the
> same
> > code as before :
> >
> > from Tkinter import *
> >
> > root = Tk()
> >
> > x = IntVar()
> >
> > def die(x):
> >     print 'dead'
> >     print x
> >
> > for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),
> ('Stupid',
> > 15)]:
> >     Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W)
> > b = Button(root, text='lets go', command=
> >            lambda x=x:die(x)).pack()
> >
> > x.set(60)  ## meant to select a radio button as default however does not
> > work
> >
> > mainloop()
> >
> >   Except this one makes a button that is meant to print 'dead' and also
> the
> > value of x.  This doesn't happen, instead it prints the name given to x
> upon
> > its creation.  It appears that x is not changed by the radio buttons, or
> > maybe it isn't even recognised (wrong namespace?  nah cos then the
> > radiobuttons would throw an exception....right?).
> >   I know this is an easy problem - they are the ones I have the most
> trouble
> > with.  It seems I can always work my way through the big ugly hard
> > things...just not the easy ones.
> >
> >   Thanks again,
> >   Glen.
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>



From Greg.Furmanek@hit.cendant.com  Mon Feb 12 16:57:09 2001
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Mon, 12 Feb 2001 11:57:09 -0500
Subject: [Tutor] initialization of classes.
Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9CF4@hit-phx-mail-3.hfscorp.com>

Here is a Problem:

I am trying to pass a class to another class and 
initialize the passed class if it is not passed
when the main class is initialized.  

This is the piece of code and error I get.

Thanks for help.

#============  Code Start ==============================

class connection:


	def __init__ \
		(self, \
		l_acc_stat = "", \
		l_user_info = c_user_info(), \
		l_tun_type = "", \
		l_acc_info = c_acct_info(), \
		l_net_info = c_network_info()):

		self.account_status = l_acc_stat
		self.user = l_user_info
		self.Class = ""				# not used
		self.Tunnel_Type = l_tun_type
		self.acct_info = l_acc_info
		self.network_info = l_net_info


	def load_account_status(self, acc_stat):
		self.account_status = acc_stat


	def load_user_info(self, l_user_info):
		self.user = l_user_info

class c_user_info:


	def __init__(self):
		self.User_Name = ""
		self.User_Full_Name = ""
		self.User_Group = user_group 

#============  Code End   ==============================

#============  Error Start =============================
=> dsv.py 20010120.dat
Traceback (most recent call last):
  File "dsv.py", line 46, in ?
    class connection:
  File "dsv.py", line 49, in connection
    def __init__ \
NameError: There is no variable named 'c_user_info'

#============ Error End   ==============================

Grzegorz Furmanek
Furmanek.Greg@hit.cendant.com
----------------------------------------------------------
Three Mile Island '79   Chernobyl '86   Windows '00 (1900) 


"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent.  This message
and its attachments could have been infected during transmission.  By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects.  The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."


From ibraheem@micromuse.com  Mon Feb 12 17:18:49 2001
From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed)
Date: Mon, 12 Feb 2001 17:18:49 +0000
Subject: [Tutor] initialization of classes.
In-Reply-To: <E5468D0C0B2DD411AE52009027B0FA3F8D9CF4@hit-phx-mail-3.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Mon, Feb 12, 2001 at 11:57:09AM -0500
References: <E5468D0C0B2DD411AE52009027B0FA3F8D9CF4@hit-phx-mail-3.hfscorp.com>
Message-ID: <20010212171849.A19742@micromuse.com>

Hi,


On Mon, Feb 12, 2001 at 11:57:09AM -0500, Furmanek, Greg wrote:
> Here is a Problem:
> 
> I am trying to pass a class to another class and 
> initialize the passed class if it is not passed
> when the main class is initialized.  
> 
> This is the piece of code and error I get.
> 
> Thanks for help.
> 
> #============  Code Start ==============================
> 
> class connection:
> 
> 
> 	def __init__ \
> 		(self, \
> 		l_acc_stat = "", \
> 		l_user_info = c_user_info(), \

c_user_info is not defined at this point -  move the definition
of c_user_info above (i.e. before ) the definition of connection. 
You will probably then find that "user_group" (and the other undefined
functions)are not well....defined. 

> 		l_tun_type = "", \
> 		l_acc_info = c_acct_info(), \
> 		l_net_info = c_network_info()):
> 
> 		self.account_status = l_acc_stat
> 		self.user = l_user_info
> 		self.Class = ""				# not used
> 		self.Tunnel_Type = l_tun_type
> 		self.acct_info = l_acc_info
> 		self.network_info = l_net_info
> 
> 
> 	def load_account_status(self, acc_stat):
> 		self.account_status = acc_stat
> 
> 
> 	def load_user_info(self, l_user_info):
> 		self.user = l_user_info
> 
> class c_user_info:
> 
> 
> 	def __init__(self):
> 		self.User_Name = ""
> 		self.User_Full_Name = ""
> 		self.User_Group = user_group 

Kindest regards,

	--ibs.
	
-- 
--------------------------------------------------------------------------------
			--  Ibraheem Umaru-Mohammed  --
			--  Email:ium@micromuse.com  --
-- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA --
			--  http://www.micromuse.com --
--------------------------------------------------------------------------------


From scarpenter@innerx.net  Mon Feb 12 17:27:22 2001
From: scarpenter@innerx.net (scarpenter@innerx.net)
Date: Mon, 12 Feb 2001 12:27:22 -0500
Subject: [Tutor] New Online Auction Site for Brand Name Tools, Hardware, Home Improvement Products
Message-ID: <E14SMl0-0005dW-00@mail.python.org>

--=200102121225=
Content-Type: text/html;charset=US-ASCII

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./hardusatosend_files/filelist.xml">
<title>http://www</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Saveweb.com, Inc.</o:Author>
  <o:Template>Normal</o:Template>
  <o:LastAuthor>Saveweb.com, Inc.</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>15</o:TotalTime>
  <o:Created>2001-02-12T16:20:00Z</o:Created>
  <o:LastSaved>2001-02-12T16:20:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>126</o:Words>
  <o:Characters>722</o:Characters>
  <o:Company>Saveweb.com, Inc.</o:Company>
  <o:Lines>6</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>886</o:CharactersWithSpaces>
  <o:Version>9.2720</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>0</w:DisplayVerticalDrawingGridEvery>
  <w:UseMarginsForDrawingGridOrigin/>
  <w:Compatibility>
   <w:FootnoteLayoutLikeWW8/>
   <w:ShapeLayoutLikeWW8/>
   <w:AlignTablesRowByRow/>
   <w:ForgetLastTabAlignment/>
   <w:LayoutRawTableWidth/>
   <w:LayoutTableRowsApart/>
  </w:Compatibility>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
</head>

<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>

<div class=Section1>

<p class=MsoNormal><a href="http://www.hardwareusa.net/">http://www.hardwareusa.net</a>
</p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Stop
paying outrageous retail prices for the products you need to keep your home
beautiful. <span style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Hardware
USA, a leading home center, is excited to invite you to visit our new website and
auction store.&nbsp;Visit us now and save big money on superior products from
such trusted brand names as Black &amp; Decker, DeWalt and Makita. <span
style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Never
before has saving money on&nbsp;top quality power tools, hardware, electrical
and plumbing supplies, lawn and garden equipment and automotive care products
been easier or more fun! <span style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Shop
conveniently from your home or office and save big at the new Hardware USA
website and auction store!<span style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Be
sure to check out our unbeatable selection of interior and exterior paint too!<span
style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>100%
CUSTOMER SATISFACTION GUARANTEED.<span style='font-size:12.0pt'><o:p></o:p></span></p>

<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><a
href="http://www.hardwareusa.net/">http://www.hardwareusa.net</a></p>

<p class=MsoNormal><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>

</div>

</body>

</html>

--=200102121225=--



From alan.gauld@bt.com  Mon Feb 12 17:21:43 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 12 Feb 2001 17:21:43 -0000
Subject: [Tutor] Textbook Recommendation
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D590@mbtlipnt02.btlabs.bt.co.uk>

> 	I'm learning Python, and at the same time, creating an 
> online course in the language for a local school district.
> I would welcome recommendations on a textbook:

First you need to tell us a it more:

What if any programming/computer skills do the students 
have already?

> The two I am considering are:
> 1)Learning Python in 24 hours

Aimed at beginners with litle or no previous experience.
Good for an intro to GUI programming (and Mayan calanders!)

> 2)Learning Python

Only really suitable if they have a programming 
background already. Or if you are ready/able to do
a lot of additional work filling in the gaps.

I could suggest my book but I've done enough self 
promotion recently :-) Both of the above are good 
intros they just serve different audiences. Since 
I don't know what the other 4 books you have are 
I'll just add the following to your list:

Core Python - Wesley Chun
Quick Python - ??? Manning Press

I've browsed both and they look good and have had 
good reader reviews.

Alan g.


From alan.gauld@bt.com  Mon Feb 12 17:23:53 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 12 Feb 2001 17:23:53 -0000
Subject: [Tutor] How to compile "odbchelper.py" app used in
 "diveintop ython"        book ?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D591@mbtlipnt02.btlabs.bt.co.uk>

> while the "odbchelper.py" uses it as
> 
> [(%s=%s) % (k, params[k]) for k in params.keys()]

This is new to Python 2.o
Is that the version you are uusing? If not it won't work...

Alan g


From alan.gauld@bt.com  Mon Feb 12 17:34:23 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 12 Feb 2001 17:34:23 -0000
Subject: [Tutor] initialization of classes.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D592@mbtlipnt02.btlabs.bt.co.uk>

> Here is a Problem:

> class connection:
> 	def __init__ (...
> 		l_user_info = c_user_info(), ...

Tries to instantiate the class and assign the instance 
as the default value for the constructor. I suspect you 
really want:

> 		l_user_info = c_user_info, ...
And within the init method:
		# create an instance of whatever kind of 
		# class was passed.
              l_user_instance = l_user_info()

> class c_user_info:
> 	def __init__(self): ...

> #============  Error Start =============================
> => dsv.py 20010120.dat
> Traceback (most recent call last):
>   File "dsv.py", line 46, in ?
>     class connection:
>   File "dsv.py", line 49, in connection
>     def __init__ \
> NameError: There is no variable named 'c_user_info'

The NameError is because you haven't defined this 
class yet. Try reversing the order of your classes....

Alan G.


From Greg.Furmanek@hit.cendant.com  Mon Feb 12 17:41:27 2001
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Mon, 12 Feb 2001 12:41:27 -0500
Subject: [Tutor] initialization of classes.
Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9CF5@hit-phx-mail-3.hfscorp.com>

This worked.

Thanks

-> -----Original Message-----
-> From: Ibraheem Umaru-Mohammed [mailto:ibraheem@micromuse.com]
-> Sent: Monday, February 12, 2001 10:19 AM
-> To: Furmanek, Greg
-> Cc: 'tutor@python.org'
-> Subject: Re: [Tutor] initialization of classes.
-> 
-> 
-> Hi,
-> 
-> 
-> On Mon, Feb 12, 2001 at 11:57:09AM -0500, Furmanek, Greg wrote:
-> > Here is a Problem:
-> > 
-> > I am trying to pass a class to another class and 
-> > initialize the passed class if it is not passed
-> > when the main class is initialized.  
-> > 
-> > This is the piece of code and error I get.
-> > 
-> > Thanks for help.
-> > 
-> > #============  Code Start ==============================
-> > 
-> > class connection:
-> > 
-> > 
-> > 	def __init__ \
-> > 		(self, \
-> > 		l_acc_stat = "", \
-> > 		l_user_info = c_user_info(), \
-> 
-> c_user_info is not defined at this point -  move the definition
-> of c_user_info above (i.e. before ) the definition of connection. 
-> You will probably then find that "user_group" (and the other 
-> undefined
-> functions)are not well....defined. 
-> 
-> > 		l_tun_type = "", \
-> > 		l_acc_info = c_acct_info(), \
-> > 		l_net_info = c_network_info()):
-> > 
-> > 		self.account_status = l_acc_stat
-> > 		self.user = l_user_info
-> > 		self.Class = ""				# not used
-> > 		self.Tunnel_Type = l_tun_type
-> > 		self.acct_info = l_acc_info
-> > 		self.network_info = l_net_info
-> > 
-> > 
-> > 	def load_account_status(self, acc_stat):
-> > 		self.account_status = acc_stat
-> > 
-> > 
-> > 	def load_user_info(self, l_user_info):
-> > 		self.user = l_user_info
-> > 
-> > class c_user_info:
-> > 
-> > 
-> > 	def __init__(self):
-> > 		self.User_Name = ""
-> > 		self.User_Full_Name = ""
-> > 		self.User_Group = user_group 
-> 
-> Kindest regards,
-> 
-> 	--ibs.
-> 	
-> -- 
-> -------------------------------------------------------------
-> -------------------
-> 			--  Ibraheem Umaru-Mohammed  --
-> 			--  Email:ium@micromuse.com  --
-> -- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, 
-> London SW18 1DA --
-> 			--  http://www.micromuse.com --
-> -------------------------------------------------------------
-> -------------------
-> 
-> _______________________________________________
-> Tutor maillist  -  Tutor@python.org
-> http://mail.python.org/mailman/listinfo/tutor
-> 


"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent.  This message
and its attachments could have been infected during transmission.  By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects.  The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."


From alan.gauld@freenet.co.uk  Tue Feb 13 07:42:25 2001
From: alan.gauld@freenet.co.uk (Alan Gauld)
Date: Tue, 13 Feb 2001 07:42:25 +0000
Subject: [Tutor] New tutorial translations
Message-ID: <3.0.1.32.20010213074225.006ffebc@mail.freenet.co.uk>

I'm pleased to announce 2 new translations of my online tutorial:

Portuguese by Wilson Pinto:

http://www.crosswinds.net/~agauld/port/

And German by Bup Schaeffer:

http://www.crosswinds.net/~agauld/german/

Neither is fully completed yet but they both have all of 
the "concepts" and "basics" topics done

Italian and Chech/Slovak versions are in progress.

Hope these help someone, my thanks to Wilson and Bup for 
their hard work,

Alan G.




From bkoyuncu@hotmail.com  Tue Feb 13 14:48:55 2001
From: bkoyuncu@hotmail.com (burak koyuncu)
Date: Tue, 13 Feb 2001 14:48:55
Subject: [Tutor] Help !!!
Message-ID: <F28wfMGqDsi4IBP3gzC00010230@hotmail.com>

<html><div style='background-color:#cccc99'><DIV><FONT color=#990000 face="Verdana, Geneva, Arial, Sans-serif" size=2>I am studying Computer Engineering. This semester I have to give my final thesis to graduate. My thesis topic is: "Web based tutorial about Python". As it can be understood from the topic, there would be a tutorial that would teach someone Python from web. But this is not at all. Also this project must include some sample programs with Python which would run on the linux platform and output will be shown.</FONT></DIV>
<DIV><FONT color=#990000 face="Verdana, Geneva, Arial, Sans-serif" size=2>Can someone show me some way? How can I do this project? Please..<BR>Thank you for your interest.<BR>Burki </FONT></DIV></div><br clear=all><hr>Get Your Private, Free E-mail from MSN Hotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br></p></html>


From dsh8290@rit.edu  Tue Feb 13 16:24:10 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 13 Feb 2001 11:24:10 -0500
Subject: [Tutor] Help !!!
In-Reply-To: <F28wfMGqDsi4IBP3gzC00010230@hotmail.com>; from bkoyuncu@hotmail.com on Tue, Feb 13, 2001 at 02:48:55PM +0000
References: <F28wfMGqDsi4IBP3gzC00010230@hotmail.com>
Message-ID: <20010213112410.C10906@harmony.cs.rit.edu>

(HTML mail is bad -- it is very hard to read the message between all
those <..> tags, if you can please set it to Plain Text only)

There is the python tutorial on www.python.org.  If you have specific
questions (like How do I ...?, or Why won't .. work?) we can answer
them.  Your question is a bit too vague.  What are your specific
examples supposed to do?

If you want to let people run the interpreter interactively through
their web browser I would recommend looking at Jython.  Jython is the
interpreter implemented in Java instead of C.  Python code run by
jython has full access to all the Java libraries.  You could create an
applet that will run the interpreter in a user's browser.

-D


On Tue, Feb 13, 2001 at 02:48:55PM +0000, burak koyuncu wrote:

<html><div style='background-color:#cccc99'><DIV><FONT color=#990000 face="Verdana, Geneva, Arial, Sans-serif" size=2>I am studying Computer Engineering. This semester I have to give my final thesis to graduate. My thesis topic is: "Web based tutorial about Python". As it can be understood from the topic, there would be a tutorial that would teach someone Python from web. But this is not at all. Also this project must include some sample programs with Python which would run on the linux platform and output will be shown.</FONT></DIV>
<DIV><FONT color=#990000 face="Verdana, Geneva, Arial, Sans-serif" size=2>Can someone show me some way? How can I do this project? Please..<BR>Thank you for your interest.<BR>Burki </FONT></DIV></div><br clear=all><hr>Get Your Private, Free E-mail from MSN Hotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br></p></html>

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


From tim@johnsons-web.com  Tue Feb 13 16:57:45 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Tue, 13 Feb 2001 07:57:45 -0900
Subject: [Tutor] Textbook Recommendation
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D590@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <01021307585001.10772@shecom>

Hello All:
Just a quick note to thank all who made text book recommendations to me.
All of the input was greatly appreciated.
Thanks!!
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From bsass@freenet.edmonton.ab.ca  Tue Feb 13 19:21:18 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Tue, 13 Feb 2001 12:21:18 -0700 (MST)
Subject: [Tutor] Help !!!
In-Reply-To: <F28wfMGqDsi4IBP3gzC00010230@hotmail.com>
Message-ID: <Pine.LNX.4.33.0102131158570.14738-100000@bms>

Hi,

I've only seen a few 'help me with my homework' messages before,
this is the best one so far. :)

On Tue, 13 Feb 2001, burak koyuncu wrote:

> I am studying Computer Engineering. This semester I have to give my final
> thesis to graduate. My thesis topic is: "Web based tutorial about
> Python". As it can be understood from the topic, there would be a
> tutorial that would teach someone Python from web. But this is not at
> all. Also this project must include some sample programs with Python
> which would run on the linux platform and output will be shown.
> Can someone show me some way? How can I do this project? Please..

Hmmm, it sounds like you could get away with a web document that
describes Python.  i.e., Show you have an understanding of both how to
construct a website and the Python language - no real user interaction
or coding required, just a canned presention.

That seems pretty basic for a Computer Engineering course (but what do
I know, I studied Chemistry and chuckled at the Engineering students
who were lost without a table to look stuff up in :).  Are you
expected to generate the site dynamically using Python code, or is it
as straight-forward as it appears?

If this is more than a 'do a website and regurgitate some Python
information' project... you could look at ILU
	ftp://parcftp.parc.xerox.com/pub/ilu/ilu.html
and do a prototype tutorial server and client with a sample Python
tutorial.


- Bruce



From randrews@planhouse.com  Tue Feb 13 20:30:52 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 13 Feb 2001 14:30:52 -0600
Subject: [Tutor] simple server and client question
Message-ID: <3A89997C.961498E9@planhouse.com>

I hate to even ask this one, because it just doesn't *feel* specific
enough, but my sad little plea will have to do.

The mandate has come from above that I write a simple server and client
in Python in preparation for a project in development.  The server and
client can do absolutely anything, and barely that, if I so choose, as
they will not be used in the project (unless my code is brilliant enough
to be useful for the project, I suppose, which is unlikely as it's a
Java project).  The important thing is that I understand how to write
such things.

So if anyone can recommend any good sources I can absorb and start
tinkering, I'd be mighty appreciative.

Rob Andrews

p.s.: The Useless Python site has undergone a serious renovation
involving a hand re-coding in XHTML this last weekend.  Anyone who has
submitted source code might want to take a peek and make sure I didn't
mess up your entries in the process.


From Lindsay.Davies@moonshine.co.uk  Tue Feb 13 21:21:54 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Tue, 13 Feb 2001 21:21:54 +0000
Subject: [Tutor] simple server and client question
In-Reply-To: <3A89997C.961498E9@planhouse.com>
References: <3A89997C.961498E9@planhouse.com>
Message-ID: <a0501045cb6af51e43be2@[195.102.186.233]>

Can't give you a definitive answer, but look at the documentation for 
the asyncore/asynchat[1] and SocketServer[2] modules. These should 
give you some good pointers. You might also want to look at Medusa[3] 
(where asyncore originated from) for some advanced examples.

Best wishes,

Lindsay

1.	http://www.python.org/doc/current/lib/asyncore-example.html
2.	http://www.python.org/doc/current/lib/module-SocketServer.html
3.	http://www.nightmare.com/medusa/index.html


On 13/2/01, Rob Andrews wrote about '[Tutor] simple server and client 
question':
>I hate to even ask this one, because it just doesn't *feel* specific
>enough, but my sad little plea will have to do.
>
>The mandate has come from above that I write a simple server and client
>in Python in preparation for a project in development.  The server and
>client can do absolutely anything, and barely that, if I so choose, as
>they will not be used in the project (unless my code is brilliant enough
>to be useful for the project, I suppose, which is unlikely as it's a
>Java project).  The important thing is that I understand how to write
>such things.
>
>So if anyone can recommend any good sources I can absorb and start
>tinkering, I'd be mighty appreciative.
>
>Rob Andrews
>
>p.s.: The Useless Python site has undergone a serious renovation
>involving a hand re-coding in XHTML this last weekend.  Anyone who has
>submitted source code might want to take a peek and make sure I didn't
>mess up your entries in the process.
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From randrews@planhouse.com  Tue Feb 13 22:22:43 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 13 Feb 2001 16:22:43 -0600
Subject: [Tutor] simple server and client question
References: <3A89997C.961498E9@planhouse.com> <a0501045cb6af51e43be2@[195.102.186.233]>
Message-ID: <003b01c0960b$7da2c5c0$dc00a8c0@Planhouse5>

Thanks greatly.  It's certainly more than I had already found.  Now I just
need to figure out what he means when he says "Do it with sockets, using
non-buffered input/output if python easily makes the distinction in i/o."

Rob

----- Original Message -----
From: "Lindsay Davies" <Lindsay.Davies@moonshine.co.uk>
To: <tutor@python.org>
Sent: Tuesday, February 13, 2001 3:21 PM
Subject: Re: [Tutor] simple server and client question


> Can't give you a definitive answer, but look at the documentation for
> the asyncore/asynchat[1] and SocketServer[2] modules. These should
> give you some good pointers. You might also want to look at Medusa[3]
> (where asyncore originated from) for some advanced examples.
>
> Best wishes,
>
> Lindsay
>
> 1. http://www.python.org/doc/current/lib/asyncore-example.html
> 2. http://www.python.org/doc/current/lib/module-SocketServer.html
> 3. http://www.nightmare.com/medusa/index.html
>
>
> On 13/2/01, Rob Andrews wrote about '[Tutor] simple server and client
> question':
> >I hate to even ask this one, because it just doesn't *feel* specific
> >enough, but my sad little plea will have to do.
> >
> >The mandate has come from above that I write a simple server and client
> >in Python in preparation for a project in development.  The server and
> >client can do absolutely anything, and barely that, if I so choose, as
> >they will not be used in the project (unless my code is brilliant enough
> >to be useful for the project, I suppose, which is unlikely as it's a
> >Java project).  The important thing is that I understand how to write
> >such things.
> >
> >So if anyone can recommend any good sources I can absorb and start
> >tinkering, I'd be mighty appreciative.
> >
> >Rob Andrews
> >
> >p.s.: The Useless Python site has undergone a serious renovation
> >involving a hand re-coding in XHTML this last weekend.  Anyone who has
> >submitted source code might want to take a peek and make sure I didn't
> >mess up your entries in the process.
> >
> >_______________________________________________
> >Tutor maillist  -  Tutor@python.org
> >http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From scarblac@pino.selwerd.nl  Tue Feb 13 22:52:22 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 13 Feb 2001 23:52:22 +0100
Subject: [Tutor] simple server and client question
In-Reply-To: <3A89997C.961498E9@planhouse.com>; from randrews@planhouse.com on Tue, Feb 13, 2001 at 02:30:52PM -0600
References: <3A89997C.961498E9@planhouse.com>
Message-ID: <20010213235222.A4533@pino.selwerd.nl>

On Tue, Feb 13, 2001 at 02:30:52PM -0600, Rob Andrews wrote:
> I hate to even ask this one, because it just doesn't *feel* specific
> enough, but my sad little plea will have to do.
> 
> The mandate has come from above that I write a simple server and client
> in Python in preparation for a project in development.  The server and
> client can do absolutely anything, and barely that, if I so choose, as
> they will not be used in the project (unless my code is brilliant enough
> to be useful for the project, I suppose, which is unlikely as it's a
> Java project).  The important thing is that I understand how to write
> such things.
> 
> So if anyone can recommend any good sources I can absorb and start
> tinkering, I'd be mighty appreciative.

If you get the source distribution of Python, there is quite some stuff in
the Demo/ and Tools/ dirs, and the standard library of course. 

In Demo/sockets, there is a "hello world" style unix socket client and a
socket server (unixclient.py and unixserver.py). Understand these first.
Then there are sample implementations of all kinds of clients in that dir.
Try to make a little server that listen for connections, and a client that
can connect to it, so you can send text messages to the screen of the server.
This is the lowest level.

Now play with http. With the standard module BaseHTTPServer you can make a
simple web server and run it. With urllib you can send requests to web
servers. Try if you can get them to work together. This is high level.

Now I don't know how the HTTP server actually works, maybe you need threads
as well.

Now the first thing I would think of to make as a test case is a chat server
where multiple people can login and they all see each other's messages :).

XML-RPC might be fun to look into as well - send complex datatype to another
python program by turning it into xml and giving it to a web server. There's
a good library for this at www.secretlabs.com, if I recall correctly.

So, this is how I would approach it.

-- 
Remco Gerlich


From gibbs05@flash.net  Tue Feb 13 22:57:50 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Tue, 13 Feb 2001 16:57:50 -0600
Subject: [Tutor] simple server and client question
References: <3A89997C.961498E9@planhouse.com>
Message-ID: <03b201c09610$6fe9a480$d6de3040@gibbs05>

Greetings Rob & All,

My suggestion for ginning up Python client / server fast would be XML-RPC
using xmlrpclib.py by Fredrik Lundh over at PythonLabs.  You can download it
at http://www.pythonware.com/products/xmlrpc/

There are two good articles on Python and XML-RPC at the O'Reilly Network:
http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html
http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html

Using xmlrpclib.py you'll have a test client & server done in less than two
hours and you'll probably have a small demo in your boss's area of interest
done before the weekend.

You'll probably want to check out Medusa and Zope while you're on this
subject also.

> I hate to even ask this one, because it just doesn't *feel* specific
> enough, but my sad little plea will have to do.
>
> The mandate has come from above that I write a simple server and client
> in Python in preparation for a project in development.  The server and
> client can do absolutely anything, and barely that, if I so choose, as
> they will not be used in the project (unless my code is brilliant enough
> to be useful for the project, I suppose, which is unlikely as it's a
> Java project).  The important thing is that I understand how to write
> such things.

How hooked are they on using Java for this?  Do you know if they're going to
use EJB or go with straight RMI?

I spent five months working with two other programmers on a Java project
using Swing and EJB that could have been done in only two months by one
programmer using Python with Tkinter and XML-RPC.

Make sure to tell 'those above' that the Java solution will be over five
times as expensive. :-)

> So if anyone can recommend any good sources I can absorb and start
> tinkering, I'd be mighty appreciative.
>
> Rob Andrews


Good luck
Sam




From bsass@freenet.edmonton.ab.ca  Tue Feb 13 23:13:26 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Tue, 13 Feb 2001 16:13:26 -0700 (MST)
Subject: [Tutor] simple server and client question
In-Reply-To: <3A89997C.961498E9@planhouse.com>
Message-ID: <Pine.LNX.4.33.0102131601300.14775-100000@bms>

On Tue, 13 Feb 2001, Rob Andrews wrote:

> I hate to even ask this one, because it just doesn't *feel* specific
> enough, but my sad little plea will have to do.
>
> The mandate has come from above that I write a simple server and client
> in Python in preparation for a project in development.  The server and
> client can do absolutely anything, and barely that, if I so choose, as
> they will not be used in the project (unless my code is brilliant enough
> to be useful for the project, I suppose, which is unlikely as it's a
> Java project).  The important thing is that I understand how to write
> such things.
>
> So if anyone can recommend any good sources I can absorb and start
> tinkering, I'd be mighty appreciative.

Have a look at ftp://parcftp.parc.xerox.com/pub/ilu/ilu.html

The scope is probably a little more than what you need, but it does
run on lots of platforms and supports clients and servers done in a
number of programming languages (python, c, c++, java,...), using a
couple(few?) interface specification languages (corba's IDL, and
ILU's ISL).

An interesting read if nothing else.


- Bruce



From deirdre@deirdre.net  Tue Feb 13 23:23:08 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Tue, 13 Feb 2001 15:23:08 -0800 (PST)
Subject: [Tutor] simple server and client question
In-Reply-To: <3A89997C.961498E9@planhouse.com>
Message-ID: <Pine.LNX.4.31.0102131509450.28382-100000@emperor.deirdre.org>

On Tue, 13 Feb 2001, Rob Andrews wrote:

> The mandate has come from above that I write a simple server and
> client in Python in preparation for a project in development.  The
> server and client can do absolutely anything, and barely that, if I so
> choose, as they will not be used in the project (unless my code is
> brilliant enough to be useful for the project, I suppose, which is
> unlikely as it's a Java project).  The important thing is that I
> understand how to write such things.

Well, without wrapping a big abstraction around it, sometimes it's just
fun to play at the low level and see how these things work. Thus, I
recommend at least trying a very little project at the low level socket
modele WITHOUT a lot of abstraction, etc. Get your hands dirty.

With all due respect, the prior suggestion for XML-RPC is SO overkill --
a web server just blats a file out to a port after adding some headers.

Now, with that, you should be able to write a web server of your own; a
mini web server that can run from inetd.conf (i.e. one that exits right
after delivering a file) should be able to be written in a very few lines
of code.

Ok, here's a really stupid client/server pair, just for amusement and
amazement. This is an adaptation of the examples found in the library
docs.

The server opens up an unprivileged port (> 1023), in this case, 30242, on
the server localhost (aka 127.0.0.1). It waits for a client. The client,
when connected, sends the phrase "foo." The server responds "bar." The
client waits for the server. They repeat this two times, then the server
closes the connection.

Ready?

Server code:

import socket
HOST = '' # Symbolic name meaning the local host
PORT = 30242 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
count = 0
while 1:
	data = conn.recv(1024)
	if not data: break
	print "Data received:",data
	if data == 'foo':
		conn.send('bar')
		count = count + 1
	else:
		conn.send('err')

	if count == 3:
		break

print 'Closing connection to', addr s.close()

client code:

import socket
HOST = '' # Symbolic name meaning the local host
PORT = 30242 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
count = 0
while 1:
	count = count + 1
	if count == 2:
		s.send('boo!')
	else:
		s.send('foo')
	data = s.recv(1024)
	if not data: break
	print data

	if count == 4:
		break

print 'Closing connection.' s.close()

_Deirdre



From rob@jam.rr.com  Wed Feb 14 00:09:05 2001
From: rob@jam.rr.com (R. A.)
Date: Tue, 13 Feb 2001 18:09:05 -0600
Subject: [Tutor] simple server and client question
References: <Pine.LNX.4.31.0102131509450.28382-100000@emperor.deirdre.org>
Message-ID: <3A89CCA1.64DF9087@jam.rr.com>

Sweet!  I didn't expect such a wealth of replies so quickly, and now I
have a good deal of stuff to play with this evening.

Deirdre, is there any way I could talk you into allowing me to post the
client & server code to Useless Python?

Rob

Deirdre Saoirse wrote:
> 
> On Tue, 13 Feb 2001, Rob Andrews wrote:
> 
> > The mandate has come from above that I write a simple server and
> > client in Python in preparation for a project in development.  The
> > server and client can do absolutely anything, and barely that, if I so
> > choose, as they will not be used in the project (unless my code is
> > brilliant enough to be useful for the project, I suppose, which is
> > unlikely as it's a Java project).  The important thing is that I
> > understand how to write such things.
> 
> Well, without wrapping a big abstraction around it, sometimes it's just
> fun to play at the low level and see how these things work. Thus, I
> recommend at least trying a very little project at the low level socket
> modele WITHOUT a lot of abstraction, etc. Get your hands dirty.
> 
> With all due respect, the prior suggestion for XML-RPC is SO overkill --
> a web server just blats a file out to a port after adding some headers.
> 
> Now, with that, you should be able to write a web server of your own; a
> mini web server that can run from inetd.conf (i.e. one that exits right
> after delivering a file) should be able to be written in a very few lines
> of code.
> 
> Ok, here's a really stupid client/server pair, just for amusement and
> amazement. This is an adaptation of the examples found in the library
> docs.
> 
> The server opens up an unprivileged port (> 1023), in this case, 30242, on
> the server localhost (aka 127.0.0.1). It waits for a client. The client,
> when connected, sends the phrase "foo." The server responds "bar." The
> client waits for the server. They repeat this two times, then the server
> closes the connection.
> 
> Ready?
> 
> Server code:
> 
> import socket
> HOST = '' # Symbolic name meaning the local host
> PORT = 30242 # Arbitrary non-privileged port
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind((HOST, PORT))
> s.listen(1)
> conn, addr = s.accept()
> print 'Connected by', addr
> count = 0
> while 1:
>         data = conn.recv(1024)
>         if not data: break
>         print "Data received:",data
>         if data == 'foo':
>                 conn.send('bar')
>                 count = count + 1
>         else:
>                 conn.send('err')
> 
>         if count == 3:
>                 break
> 
> print 'Closing connection to', addr s.close()
> 
> client code:
> 
> import socket
> HOST = '' # Symbolic name meaning the local host
> PORT = 30242 # Arbitrary non-privileged port
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((HOST, PORT))
> count = 0
> while 1:
>         count = count + 1
>         if count == 2:
>                 s.send('boo!')
>         else:
>                 s.send('foo')
>         data = s.recv(1024)
>         if not data: break
>         print data
> 
>         if count == 4:
>                 break
> 
> print 'Closing connection.' s.close()
> 
> _Deirdre
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

The Useless Python Repository has received an XHTML face-lift!
http://www.lowerstandard.com/python/pythonsource.html


From deirdre@deirdre.net  Wed Feb 14 00:07:46 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Tue, 13 Feb 2001 16:07:46 -0800 (PST)
Subject: [Tutor] simple server and client question
In-Reply-To: <3A89CCA1.64DF9087@jam.rr.com>
Message-ID: <Pine.LNX.4.31.0102131606180.28382-100000@emperor.deirdre.org>

On Tue, 13 Feb 2001, R. A. wrote:

> Deirdre, is there any way I could talk you into allowing me to post the
> client & server code to Useless Python?

Sure, I don't have a problem with that. :)

This was the kind of futzing around I did before writing my (still
unpublished) APOP server. Now that I've solved the security issue, I may
yet wrap it up.

_Deirdre




From chris@collegewafer.com  Wed Feb 14 09:38:23 2001
From: chris@collegewafer.com (Chris Baker)
Date: Wed, 14 Feb 2001 04:38:23 -0500
Subject: [Tutor] Hi, Need 6"-8" Wafer Special! Si, SOI, ZnO, MEMS & More!
Message-ID: <200102140938.DAA07936@ionet.net>

Hi,

Let CollegeWafer.com take care of your wafer needs!  Save time and $$$ It=
's a=20
FREE service to you!

Visit http://www.collegewafer.com or call 800-713-9375, Fax 888-832-0340 =
or email=20
chris@collegewafer.com


We have AIN, Fused Silica, Pyrex, GaN, SiC, ZnO of course Si, SOI, Ultra-=
Thin=20
Si, Ge, InP, ZnSe, ZnO, ZnS, GaP, Infrared and so much more, including:

Custom orders for Prime wafers, Test wafers, or Coin Roll wafers.=20

5" N<100> 5-10 ohm-cm.   24-25.9mils
5" N <100> 10-20 ohm-cm. 24-26mils=20
5" P<100> 5-10 ohm-cm.   24-25.9mils=20
5" P<100> 10-20 ohm-cm.  24-25.9mils
6" N<100> 1-5 ohm-cm.    25-27.9mils=20
6" N<100> 10-20 ohm-cm.  585-725=B5m =20
6" N<100> 10-20 ohm-cm.  >650=B5m    =20
6" N<100> 20-30 ohm-cm.  625-725=B5m
6" N<100> 20-30 ohm-cm.  25-27.5mils
6" P<100> 1-10 ohm-cm.   625-725=B5m=20
6" P<100> 10-20 ohm-cm.  625-725=B5m=20
6" P<100> 2-15 ohm-cm.   625-725=B5m=20
6" P<100> >30 ohm-cm.    25-27.5mils=20
8" P<100> 1-10 ohm-cm.   675-775=B5m=20
8" P<100> 10-20 ohm-cm.  675-775=B5m=20
8" P<100> 10-20 ohm-cm.  700-750=B5m=20
8" P<100> 10-20 ohm-cm.  700-750=B5m=20
12" P <100> 1-100 ohm-cm.750-800=B5m=20

Polishing and Reclaim:
We can polish test and prime wafers at better      than SEMI standard spe=
cifications.

Need Wafer inspection services?
Test your wafers for type, resistivity,                     thickness, TI=
R, STIR,=20
TTV, FPD and cleanliness           analysis.

How about:
Cleaning, Lapping, Etching, Edge round,           graphic printouts (2D &=
 3D),=20
Certificate of      Conformance, Certificate of Analysis,     Polishing, =
Reclaim=20
Services, Laser-cutting and           Oxide Services=20

Ask about In-House Oxide Services:=20

Thermally grown oxide for 2"-8" wafers ranging in thickness from 500-100,=
000=20
Angstroms.

http://www.collegewafer.com/contact_us/Remove/remove.html



11ada22










From wheelege@tsn.cc  Wed Feb 14 10:55:57 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 14 Feb 2001 21:55:57 +1100
Subject: [Tutor] Rather vague questions....  (Tkinter)
Message-ID: <00b201c09674$b6770500$90755cca@glen>

This is a multi-part message in MIME format.

------=_NextPart_000_00AF_01C096D0.E9474560
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hi all,

  I have gotten this error, while running a little python program I am =
creating as a project.  Here is the error :

Traceback (most recent call last):
  File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball =
game.py", line 264, in gogamego
    Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the =
reassigning of the ball's coords
  File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
    self.tk.splitlist(
TclError: invalid command name ".22703164"

  It's an error which pops up in the interactive window every time the =
program quits.  It could have something to do with the thread still =
running and thus losing all the objects it was referencing - but I don't =
know enough about the error messages to tell if this is the case.
  Sometimes (damn intermittent errors) the main thread of the program =
quits (I think...I should probably trap the exit() call...) for no =
reason.  I am hoping that it has something to do with this error.  It =
seems the faster I make the thread run the sooner it quits, and I can =
almost get it to quit every single time I run it at a fast speed (with a =
0.0025 second delay between each iteration) it breaks every time.  When =
it does this, it shows a different error to the one above, it shows this =
one :

Traceback (most recent call last):
  File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball =
game.py", line 265, in gogamego
    Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) ## the =
reassigning of the ball's coords
  File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
    self.tk.splitlist(
ValueError: invalid literal for float(): expected

  I'm running an Athlon 600mhz system, 256mb ram and windows 98.  I know =
threads aren't all that great in windows...but I seriously need them.  =
The program will be an arkanoid type game (use a paddle to bounce a ball =
and smash blocks) when I'm finished.  Which will be a long time :)
  I'd rather not post the code because it is in super early newbie alpha =
stage and not worth showing to my Mum :)  But of course I will if I have =
to.

  Thanks,
  Glen.

------=_NextPart_000_00AF_01C096D0.E9474560
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I have gotten this error, while running a little python =
program I am=20
creating as a project.&nbsp; Here is the error :</DIV>
<DIV>&nbsp;</DIV>
<DIV>Traceback (most recent call last):<BR>&nbsp; File=20
"C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball game.py", =
line=20
264, in gogamego<BR>&nbsp;&nbsp;&nbsp; Screen.coords(ballphys, Ball.x1, =
Ball.y1,=20
Ball.x2, Ball.y2) #the reassigning of the ball's coords<BR>&nbsp; File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 1929, in =
coords<BR>&nbsp;&nbsp;&nbsp;=20
self.tk.splitlist(<BR>TclError: invalid command name ".22703164"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; It's an error which pops up in the interactive window every =
time the=20
program quits.&nbsp; It could have something to do with the thread still =
running=20
and thus losing all the objects it was referencing - but I don't know =
enough=20
about the error messages to tell if this is the case.</DIV>
<DIV>&nbsp; Sometimes (damn intermittent errors) the main thread of the =
program=20
quits (I think...I should probably trap the exit() call...) for no =
reason.&nbsp;=20
I am hoping that it has something to do with this error.&nbsp; It seems =
the=20
faster I make the thread run the sooner it quits, and I can almost get =
it to=20
quit every single time I run it at a fast speed (with a 0.0025 second =
delay=20
between each iteration) it breaks every time.&nbsp; When it does this, =
it shows=20
a different error to the one above, it shows this one :</DIV>
<DIV>&nbsp;</DIV>
<DIV>Traceback (most recent call last):<BR>&nbsp; File=20
"C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball game.py", =
line=20
265, in gogamego<BR>&nbsp;&nbsp;&nbsp; Screen.coords(ballphys, Ball.x1, =
Ball.y1,=20
Ball.x2, Ball.y2) ## the reassigning of the ball's coords<BR>&nbsp; File =

"c:\python20\lib\lib-tk\Tkinter.py", line 1929, in =
coords<BR>&nbsp;&nbsp;&nbsp;=20
self.tk.splitlist(<BR>ValueError: invalid literal for float():=20
expected<BR></DIV>
<DIV>&nbsp; I'm running an Athlon 600mhz system, 256mb ram and windows =
98.&nbsp;=20
I know threads aren't all that great in windows...but I seriously need=20
them.&nbsp; The program will be an arkanoid type game (use a paddle to =
bounce a=20
ball and smash blocks) when I'm finished.&nbsp; Which will be a long =
time=20
:)</DIV>
<DIV>&nbsp; I'd rather not post the code because it is in super early =
newbie=20
alpha stage and not worth showing to my Mum :)&nbsp; But of course I =
will if I=20
have to.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_00AF_01C096D0.E9474560--



From arcege@shore.net  Wed Feb 14 12:32:31 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Wed, 14 Feb 2001 07:32:31 -0500 (EST)
Subject: [Tutor] Rather vague questions....  (Tkinter)
In-Reply-To: <00b201c09674$b6770500$90755cca@glen> from "Glen Wheeler" at Feb 14, 2001 09:55:57 PM
Message-ID: <200102141232.HAA18438@northshore.shore.net>

>   Hi all,
> 
>   I have gotten this error, while running a little python program I am =
> creating as a project.  Here is the error :
> 
> Traceback (most recent call last):
>   File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball =
> game.py", line 264, in gogamego
>     Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the =
> reassigning of the ball's coords
>   File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
>     self.tk.splitlist(
> TclError: invalid command name ".22703164"
> 
>   It's an error which pops up in the interactive window every time the =
> program quits.  It could have something to do with the thread still =
> running and thus losing all the objects it was referencing - but I don't =
> know enough about the error messages to tell if this is the case.
>   Sometimes (damn intermittent errors) the main thread of the program =
> quits (I think...I should probably trap the exit() call...) for no =
> reason.  I am hoping that it has something to do with this error.  It =
> seems the faster I make the thread run the sooner it quits, and I can =
> almost get it to quit every single time I run it at a fast speed (with a =
> 0.0025 second delay between each iteration) it breaks every time.  When =
> it does this, it shows a different error to the one above, it shows this =
> one :

Yes, without the code there is only so much we can do to help you, but
here are some things to thing about.

First, Tkinter will only work "well" if it is running in the main
(first) thread.  You can delegate other functionality to the additional
peer threads, but you'll run into problems (likely the ones you've
seen).  You might want to do some searches in the archives at
www.python.org/search.

Second, it is often not necessary to have separate threads.  Most
things that will need to be done are just at specific intervals
(updating non-player "enemies", etc.).  Those can be done with the
after() and after_idle() methods instead of using threads.

Threads lead to complications with data integrity, indefinate
postponement and deadlock, to name just a few issues involved.  Please
make sure that you NEED threads before you think to use them; you'll
find that your programming needs to much more complex.

But even if you think you need threads, make sure that Tkinter is in
the main thread.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From wheelege@tsn.cc  Wed Feb 14 21:02:25 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 15 Feb 2001 08:02:25 +1100
Subject: [Tutor] Rather vague questions....  (Tkinter)
References: <200102141232.HAA18438@northshore.shore.net>
Message-ID: <002f01c096c9$6fa5bea0$e5755cca@glen>

  Thanks for the quick reply. I've now got :

Traceback (most recent call last):
  File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball
game.py", line 266, in gogamego
    Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) ## the
reassigning of the ball's coords
  File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
    self.tk.splitlist(
TclError: invalid command name ".21933052"

  Nutted out.  That was the exception  occuring if the main thread
unexpectedly quit (ie no break command or natural end), and I found the
error that made it occur.  I replaced another thread I had (now I onyl have
one thread) which created other things for you to play with, and replaced it
with a whole load of event bindings.  Seems to work better now.
  However, the other error I was getting seems to have run off from my
program.  I cannot recreate it.  That was a problem because it would only
occur at high speeds, and would crash the whole thing.  Maybe it was to do
with my computer not being restarted in a long long time.  Whatever it was,
be sure I'll post it again (along with some code, if it looks nicer by then)
because I will not have any idea how it came about.
  I really do need at least one thread, but I think I can do other minor
operations not with threads.  I've read a bit about them, and the docs are
not hugely confident in their stability (hey who would be).  I think I'm
going to have to do some more fiddling with little baby thread
applications - I strongly suspect the reason I was getting the error about
float() was because a floating point variable used in the same while loops
as that command was confused with an integer - but I'm not sure.  I hope
that isn't true because if it is I have no idea how to fix it.

  Thanks again,
  Glen.


----- Original Message -----
From: Michael P. Reilly <arcege@shore.net>
To: Glen Wheeler <wheelege@tsn.cc>
Cc: <tutor@python.org>
Sent: Wednesday, February 14, 2001 11:32 PM
Subject: Re: [Tutor] Rather vague questions.... (Tkinter)


> >   Hi all,
> >
> >   I have gotten this error, while running a little python program I am =
> > creating as a project.  Here is the error :
> >
> > Traceback (most recent call last):
> >   File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball =
> > game.py", line 264, in gogamego
> >     Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the =
> > reassigning of the ball's coords
> >   File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
> >     self.tk.splitlist(
> > TclError: invalid command name ".22703164"
> >
> >   It's an error which pops up in the interactive window every time the =
> > program quits.  It could have something to do with the thread still =
> > running and thus losing all the objects it was referencing - but I don't
=
> > know enough about the error messages to tell if this is the case.
> >   Sometimes (damn intermittent errors) the main thread of the program =
> > quits (I think...I should probably trap the exit() call...) for no =
> > reason.  I am hoping that it has something to do with this error.  It =
> > seems the faster I make the thread run the sooner it quits, and I can =
> > almost get it to quit every single time I run it at a fast speed (with a
=
> > 0.0025 second delay between each iteration) it breaks every time.  When
=
> > it does this, it shows a different error to the one above, it shows this
=
> > one :
>
> Yes, without the code there is only so much we can do to help you, but
> here are some things to thing about.
>
> First, Tkinter will only work "well" if it is running in the main
> (first) thread.  You can delegate other functionality to the additional
> peer threads, but you'll run into problems (likely the ones you've
> seen).  You might want to do some searches in the archives at
> www.python.org/search.
>
> Second, it is often not necessary to have separate threads.  Most
> things that will need to be done are just at specific intervals
> (updating non-player "enemies", etc.).  Those can be done with the
> after() and after_idle() methods instead of using threads.
>
> Threads lead to complications with data integrity, indefinate
> postponement and deadlock, to name just a few issues involved.  Please
> make sure that you NEED threads before you think to use them; you'll
> find that your programming needs to much more complex.
>
> But even if you think you need threads, make sure that Tkinter is in
> the main thread.
>
>   -Arcege
>
> --
> ------------------------------------------------------------------------
> | Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
> | Salem, Mass. USA  01970             |                                |
> ------------------------------------------------------------------------



From Christopher Bemis" <laser151@tvn.net  Wed Feb 14 21:23:00 2001
From: Christopher Bemis" <laser151@tvn.net (Christopher Bemis)
Date: Wed, 14 Feb 2001 16:23:00 -0500
Subject: [Tutor] Running the programs
Message-ID: <001101c096cc$50871a20$1008683f@laser151>

This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C096A2.65F50A40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am learning Python with"Learn Python in 24 hours", and am getting =
quite a good grasp of the programming aspect....However here's my =
problem........With all the sample progs that I've written I've used =
Notepad as my editor....I save them as text as script.py.....but when I =
try to run them I can't. I've tried Start/Run/.....py and I get a flash =
of a DOS box. I try command prompt and it won't go at all.....I'm =
running Win98Se....Is my DOS file path screwed up or is there something =
else I need....I have Python2.0....or maybe I need a new DOS =
prompt....how do I get one? Help Please =20
The Great One

------=_NextPart_000_000E_01C096A2.65F50A40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><STRONG><FONT face=3D"Californian FB" color=3D#800080 size=3D2>I am =
learning=20
Python with"Learn Python in 24 hours", and am getting quite a good grasp =
of the=20
programming aspect....However here's my problem........With all the =
sample progs=20
that I've written I've used Notepad as my editor....I save them as text =
as=20
script.py.....but when I try to run them I can't. I've tried=20
Start/Run/.....py&nbsp;and I get a flash of a DOS box. I try command =
prompt and=20
it won't go at all.....I'm running Win98Se....Is my DOS file path =
screwed up or=20
is there something else I need....I have Python2.0....or maybe I need a =
new DOS=20
prompt....how do I get one? Help =
Please&nbsp;&nbsp;</FONT></STRONG></DIV>
<DIV><STRONG><FONT face=3D"Californian FB" color=3D#800080 size=3D2>The =
Great=20
One</FONT></STRONG></DIV></BODY></HTML>

------=_NextPart_000_000E_01C096A2.65F50A40--



From kalle@gnupung.net  Wed Feb 14 22:04:34 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Wed, 14 Feb 2001 23:04:34 +0100
Subject: [Tutor] Running the programs
In-Reply-To: <001101c096cc$50871a20$1008683f@laser151>; from laser151@tvn.net on Wed, Feb 14, 2001 at 04:23:00PM -0500
References: <001101c096cc$50871a20$1008683f@laser151>
Message-ID: <20010214230434.D1361@apone.network.loc>

--Qrgsu6vtpU/OV/zm
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Christopher Bemis:
[flashing dos-box problem]

What was wrong with the answers you recieved last time you asked?
http://mail.python.org/pipermail/tutor/2001-February/003502.html
http://mail.python.org/pipermail/tutor/2001-February/003504.html
http://mail.python.org/pipermail/tutor/2001-February/003505.html
http://mail.python.org/pipermail/tutor/2001-February/003510.html

Peace,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--Qrgsu6vtpU/OV/zm
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6iwDydNeA1787sd0RAvYFAKCjqE0OFcKxAJEGJK4H9s2p2zRGdQCgk4yv
q01Z6jGg4MpXWbhurpt0sfM=
=Q/hB
-----END PGP SIGNATURE-----

--Qrgsu6vtpU/OV/zm--


From randrews@planhouse.com  Wed Feb 14 21:59:19 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 14 Feb 2001 15:59:19 -0600
Subject: [Tutor] Running the programs
References: <001101c096cc$50871a20$1008683f@laser151>
Message-ID: <000e01c096d1$6414f440$dc00a8c0@Planhouse5>

Try opening a command prompt (DOS prompt, if you like), and changing to your
Python directory.  Then type something along these lines:

C:\Python20> python helloworld.py

Substitute the name of your script for 'helloworld', of course.

And you can also run your script from within IDLE by typing:

>>> import helloworld

Does this help a bit?

Rob Andrews
----- Original Message -----
From: Christopher Bemis
To: tutor@python.org
Sent: Wednesday, February 14, 2001 3:23 PM
Subject: [Tutor] Running the programs


I am learning Python with"Learn Python in 24 hours", and am getting quite a
good grasp of the programming aspect....However here's my
problem........With all the sample progs that I've written I've used Notepad
as my editor....I save them as text as script.py.....but when I try to run
them I can't. I've tried Start/Run/.....py and I get a flash of a DOS box. I
try command prompt and it won't go at all.....I'm running Win98Se....Is my
DOS file path screwed up or is there something else I need....I have
Python2.0....or maybe I need a new DOS prompt....how do I get one? Help
Please
The Great One



From arcege@shore.net  Wed Feb 14 22:06:04 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Wed, 14 Feb 2001 17:06:04 -0500 (EST)
Subject: [Tutor] Running the programs
In-Reply-To: <001101c096cc$50871a20$1008683f@laser151> from "Christopher Bemis" at Feb 14, 2001 04:23:00 PM
Message-ID: <200102142206.RAA25590@northshore.shore.net>

> I am learning Python with"Learn Python in 24 hours", and am getting =
> quite a good grasp of the programming aspect....However here's my =
> problem........With all the sample progs that I've written I've used =
> Notepad as my editor....I save them as text as script.py.....but when I =
> try to run them I can't. I've tried Start/Run/.....py and I get a flash =
> of a DOS box. I try command prompt and it won't go at all.....I'm =
> running Win98Se....Is my DOS file path screwed up or is there something =
> else I need....I have Python2.0....or maybe I need a new DOS =
> prompt....how do I get one? Help Please =20

In hour 2 (pp. 24-27), the author shows you how to run
scripts/programs.
>From the MS-DOS prompt, you type "python script.py" and look at the
output in that box.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From dsh8290@rit.edu  Wed Feb 14 22:10:26 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 14 Feb 2001 17:10:26 -0500
Subject: [Tutor] Running the programs
In-Reply-To: <001101c096cc$50871a20$1008683f@laser151>; from laser151@tvn.net on Wed, Feb 14, 2001 at 04:23:00PM -0500
References: <001101c096cc$50871a20$1008683f@laser151>
Message-ID: <20010214171026.B17793@harmony.cs.rit.edu>

On Wed, Feb 14, 2001 at 04:23:00PM -0500, Christopher Bemis wrote:
| 
|    I am learning Python with"Learn Python in 24 hours", and am getting
|    quite a good grasp of the programming aspect....However here's my
|    problem........With all the sample progs that I've written I've used
|    Notepad as my editor....I save them as text as script.py.....but when
|    I try to run them I can't. I've tried Start/Run/.....py and I get a
|    flash of a DOS box. I try command prompt and it won't go at
|    all.....I'm running Win98Se....Is my DOS file path screwed up or is
|    there something else I need....I have Python2.0....or maybe I need a
|    new DOS prompt....how do I get one? Help Please  
|    

People having trouble figuring out how to run scripts make me feel old
-- they must not have used MS-DOS before the days of MS Windows came
about.  (Don't feel so bad, lots of people have this problem)

By default, Windows will close the DOS box when the app is done.  One
workaround is to put the following line at the end of your program.
Then it won't be done until you say it is ;-).

raw_input( "Press enter to quit." )


Since you get a flash when you try Start->Run that means Windows has
the association correct to run a .py file.  (Unless you get a weird
error in the DOS box, but you can't see it anyways...)


There are a few things you can do if you want to run scripts from the
commandline.

a)	Add c:\python20 (or whatever it is) to your PATH environment
variable.  This can be done in several ways :
	
	1)	type  set PATH %PATH%;c:\python20   when you start up
		a DOS box

	2)	append  set PATH %PATH%;c:\python20 to the end of your
		c:\autoexec.bat, then reboot ;-)  This will put python
		in the path for all DOS boxes you open

b)	Type the full path to python every time you run it (
	C:\myprog> c:\python20\python myscript.py )  =p

c)	Add a script (batch file) to a directory that is in the path,
	this script will run python with the full path and pass it any
	arguments you give

	-------- python.bat --------
	c:\python20\python %1 %2 %3 %4 %5 %6 %7 %8 %9


My preference is (c).  Actually, I use the bash shell provided by
cygwin (I really prefer Linux, but ...) and put similar scripts in
~/bin.  Bash is a much more powerful, convenient, and useful shell
than DOS provides. (FYI an example script :

	----------- ~/bin/python -------------
	#!/bin/bash

	//c/python20/python $*


As for your editor, notepad works but lacks the many conveniences of a
"real" editor.  I like gvim the best (www.vim.org) but it takes a
while to learn all of the commands.  There are other editors (and
IDEs) for windows.  I would strongly recommend finding one that you
like.  Some of the features I really like include :
	o autoindenting (and convenient re-indenting)
	o syntax highlighting
	o text wrapping (for long blocks of comments)
	o regex search and replace
	o rapid cursor movement

HTH,
-D


BTW	I'm not trying to start a flame war here about shells and
	editors, just providing some FYI



From Christopher Peet" <cpeet@git.org  Thu Feb 15 00:21:09 2001
From: Christopher Peet" <cpeet@git.org (Christopher Peet)
Date: Wed, 14 Feb 2001 16:21:09 -0800
Subject: [Tutor] Running the programs
References: <001101c096cc$50871a20$1008683f@laser151>
Message-ID: <011401c096e5$5123ed00$0200a8c0@horus>

For me this is the easiest thing to do. Start IDLE and do a Control+n to
open a new window. Type all your code in this new window and when you're
ready to run it, save it to temp.py - and then making sure focus is still on
the second window hit Control+F5. This will run the code in main IDLE
window. Making changes is easy, edit your code and type ALT f(ile) s(ave) to
save it again and rerun it with Control+F5. Very fast and you still have
IDLE color coding your text so you'll know right away if your syntax it
botched!


You'll never go back to using notepad after you get used to this setup..

Cheers,

Christopher Peet

----- Original Message -----
From: "Christopher Bemis" <laser151@tvn.net>
To: <tutor@python.org>
Sent: Wednesday, February 14, 2001 1:23 PM
Subject: [Tutor] Running the programs


I am learning Python with"Learn Python in 24 hours", and am getting quite a
good grasp of the programming aspect....However here's my
problem........With all the sample progs that I've written I've used Notepad
as my editor....I save them as text as script.py.....but when I try to run
them I can't. I've tried Start/Run/.....py and I get a flash of a DOS box. I
try command prompt and it won't go at all.....I'm running Win98Se....Is my
DOS file path screwed up or is there something else I need....I have
Python2.0....or maybe I need a new DOS prompt....how do I get one? Help
Please
The Great One







From darrell@brogdon.net  Thu Feb 15 03:59:42 2001
From: darrell@brogdon.net (Darrell Brogdon)
Date: Wed, 14 Feb 2001 22:59:42 -0500
Subject: [Tutor] building a tuple
Message-ID: <3A8B542E.6020202@brogdon.net>

I'm curious as to how to build a tuple out of data that I'm getting from a database result set.  Can anyone point me in the right direction?

Thanks

-- 
Darrell Brogdon
http://darrell.brogdon.net



From darrell@brogdon.net  Thu Feb 15 04:48:59 2001
From: darrell@brogdon.net (Darrell Brogdon)
Date: Wed, 14 Feb 2001 23:48:59 -0500
Subject: [Tutor] building a tuple
References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com>
Message-ID: <3A8B5FBB.9000803@brogdon.net>

Ok, so for example, I'm getting the following data:

Field Name        Value
------------------------
fname             John
lname             Doe
address           123 Any St.
city              Anytown

Now I know I can manually build a tuple out of this data with the following:

    my_tuple {
        "fname" : "John",
        "lname" : "Doe",
        "address" : "123 Any St."
        "city" : "Anytown"
    }

But obviously with this data coming from the database I wouldn't know what the values are.  I've figured out how to get the data out of the 
database for the most part.  Now its just a matter of how to get that data into a tuple.

I think partly I'm confusing myself with my knowledge of PHP where you can pretty much get away with anything. :)

-Darrell

R. A. wrote:

> Can you provide a little more info?  Info on tuples themselves may be
> found in all the standard tutorials.  Do you have to interact with the
> database itself, or just with a data table?
> 
> Rob
> 
> Darrell Brogdon wrote:
> 
>> I'm curious as to how to build a tuple out of data that I'm getting from a database result set.  Can anyone point me in the right direction?
>> 
>> Thanks
>> 
>> --
>> Darrell Brogdon
>> http://darrell.brogdon.net
>> 
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
> 
-- 
Darrell Brogdon
http://darrell.brogdon.net



From Lindsay.Davies@moonshine.co.uk  Thu Feb 15 08:15:54 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Thu, 15 Feb 2001 08:15:54 +0000
Subject: [Tutor] building a tuple
In-Reply-To: <3A8B5FBB.9000803@brogdon.net>
References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com>
 <3A8B5FBB.9000803@brogdon.net>
Message-ID: <a05010468b6b13ec1233e@[195.102.186.233]>

Darrell -

I think I see where some of the confusion is coming from. The code 
snippet below  shows you building a dictionary (AKA hash or 
associative array), NOT a tuple, which is an immutable array.

If you are asking how do you build a dictionary from the result of a 
database query, then that is a different question from how to build a 
tuple.

The answer to dictionary-building does depend on the module you are 
using to access the database. For example, both the MySQLdb.py and 
PgSQL.py modules allow you to retrieve a dictionary (or 
dictionary-like object) from a *.fetchall() call for example. There 
is devil in the detail though, so perhaps you need to supply more 
information, like the database and DB API module you are using to 
access it.

Best wishes,

Lindsay



On 14/2/01, Darrell Brogdon wrote about 'Re: [Tutor] building a tuple':
>Ok, so for example, I'm getting the following data:
>
>Field Name        Value
>------------------------
>fname             John
>lname             Doe
>address           123 Any St.
>city              Anytown
>
>Now I know I can manually build a tuple out of this data with the following:
>
>    my_tuple {
>        "fname" : "John",
>        "lname" : "Doe",
>        "address" : "123 Any St."
>        "city" : "Anytown"
>    }
>
>But obviously with this data coming from the database I wouldn't 
>know what the values are.  I've figured out how to get the data out 
>of the database for the most part.  Now its just a matter of how to 
>get that data into a tuple.
>
>I think partly I'm confusing myself with my knowledge of PHP where 
>you can pretty much get away with anything. :)
>


From wheelege@tsn.cc  Thu Feb 15 08:21:26 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 15 Feb 2001 19:21:26 +1100
Subject: [Tutor] Running the programs
References: <001101c096cc$50871a20$1008683f@laser151> <20010214171026.B17793@harmony.cs.rit.edu>
Message-ID: <007a01c09728$4ac6c340$8f755cca@glen>

  As Kalle said, this has been asked many times before.  Can you not receive
tutor mail back?



From rsmith@ffs.cc  Thu Feb 15 13:23:17 2001
From: rsmith@ffs.cc (Ryan Smith)
Date: Thu, 15 Feb 2001 08:23:17 -0500
Subject: [Tutor] i want to learn to hack
Message-ID: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>

how do i hack?

-Ryan


From Lindsay.Davies@moonshine.co.uk  Thu Feb 15 13:43:34 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Thu, 15 Feb 2001 13:43:34 +0000
Subject: [Tutor] i want to learn to hack
In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>
References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>
Message-ID: <a05010472b6b18b482353@[195.102.186.233]>

On 15/2/01, Ryan Smith wrote about '[Tutor] i want to learn to hack':
>how do i hack?

Hacking[1] or cracking[2]?

In the latter case, this isn't the right list. If you want to learn 
to program, and be creative and constructive in your programming, 
then of course, Python's a good starting point.

Best wishes,

Lindsay



--courtesy of everything2.com--

[1] The art of programming that uses both accepted design principles, 
kluges, and software/hardware fixes (whichever is inappropriate) to 
get the job done. It is frequently confused with cracking.

[2] The act of breaking into a computer system; what a cracker does. 
Contrary to widespread myth, this does not usually involve some 
mysterious leap of hackerly brilliance, but rather persistence and 
the dogged repetition of a handful of fairly well-known tricks that 
exploit common weaknesses in the security of target systems. 
Accordingly, most crackers are only mediocre hackers.


From scarblac@pino.selwerd.nl  Thu Feb 15 13:52:38 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 15 Feb 2001 14:52:38 +0100
Subject: [Tutor] i want to learn to hack
In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>; from rsmith@ffs.cc on Thu, Feb 15, 2001 at 08:23:17AM -0500
References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>
Message-ID: <20010215145238.A7487@pino.selwerd.nl>

On Thu, Feb 15, 2001 at 08:23:17AM -0500, Ryan Smith wrote:
> how do i hack?

That depends on what you mean. If you mean breaking into computers, that is
called "cracking", is not the subject of this list, and is a sad thing
for kids who have nothing better to do. No help from us there.

The first two meanings of the verb 'hack' that the Jargon File gives:
1.n Originally, a quick job that produces what is needed, but not well.
2.n An incredibly good, and perhaps very time-consuming piece of work that
    produces exactly what is needed.

In general, it's a style of programming, very informal, but very fanatical.
A lot of the best open source software came into being because someone
started programming something cool, and continued for a few nights. Hacking
is fun.

As a start, I'd say you read
- ESR's "How to become a Hacker FAQ" at
  http://www.tuxedo.org/~esr/faqs/hacker-howto.html
  Or maybe you read that and then came here.
- If you're not a programmer yet, I suggest you start with Alan Gauld's
  online book http://www.crosswinds.net/~agauld/
  to learn programming, using Python.
  
This list is for beginning Python programmers, to ask questions. So if you
have any problems with that part, you're welcome to ask here :).

-- 
Remco Gerlich


From dsh8290@rit.edu  Thu Feb 15 14:20:13 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 15 Feb 2001 09:20:13 -0500
Subject: [Tutor] i want to learn to hack
In-Reply-To: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>; from rsmith@ffs.cc on Thu, Feb 15, 2001 at 08:23:17AM -0500
References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>
Message-ID: <20010215092013.B132@harmony.cs.rit.edu>

On Thu, Feb 15, 2001 at 08:23:17AM -0500, Ryan Smith wrote:
| how do i hack?
| 
| -Ryan
| 

Is this a new e-mail address, or are you not the same Ryan on the
gimpwin-users list?


I'll assume that you intend the good definition of 'hack'.  What do
you want to accomplish from your hacking?  This list is very helpful
at explaining various programming concepts and how they apply to
python, but you must have some questions first.  For example, to start
with you could write the canonical "Hello World" program.  In python
that would be:

--------------------
print "Hello World"
--------------------

If you wanted to print it 10 times, you could


------------------------------
for i in range( 10 ) :
	print "Hello World"
------------------------------

Have you taken a look at the tutorial on www.python.org?  It's a
rather good tutorial, but I think it expects a basic knowledge of
programming and computer operation.  Alan Gauld also has a nice book
(so I've heard) and I think there is quite a bit of useful information
on his web site  (I haven't been there, but other people say it is
good,  check the list archives for a url).

Enjoy learning python!  The gimp even has a plugin module so you can
script it in python.

-D 



From lumbricus@gmx.net  Thu Feb 15 17:09:32 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Thu, 15 Feb 2001 18:09:32 +0100 (MET)
Subject: [Tutor] i want to learn to hack
References: <000101c09752$75f6e0c0$70ea3fd0@oemcomputer>
Message-ID: <26883.982256972@www37.gmx.net>

> how do i hack?
> 
> -Ryan
> 
> _______________________________________________
youre running windoze - right?
fire up a dos prompt and type format c:
hit return and get an os. ;->
read the dox.
write progs.
-jö

-- 
Sent through GMX FreeMail - http://www.gmx.net


From dbrogdon@valinux.com  Thu Feb 15 18:44:06 2001
From: dbrogdon@valinux.com (Darrell Brogdon)
Date: Thu, 15 Feb 2001 13:44:06 -0500
Subject: [Tutor] building a tuple
References: <3A8B542E.6020202@brogdon.net> <3A8B56AB.26AA9EFD@jam.rr.com>
 <3A8B5FBB.9000803@brogdon.net> <a05010468b6b13ec1233e@[195.102.186.233]>
Message-ID: <3A8C2376.3030605@valinux.com>

Well, I found that I could instead create a list and append to it using 
the extend() method and then convert the list into a tuple where I can 
work from there.

You're right about my confusion.  Here again, the line can be blurry 
sometimes in PHP. :)

Anyway, thanks for the help and sorry for the vague post.  When you're 
learning sometimes you don't quite know how to phrase your question.

Lindsay Davies wrote:

> Darrell -
> 
> I think I see where some of the confusion is coming from. The code 
> snippet below  shows you building a dictionary (AKA hash or associative 
> array), NOT a tuple, which is an immutable array.
> 
> If you are asking how do you build a dictionary from the result of a 
> database query, then that is a different question from how to build a 
> tuple.
> 
> The answer to dictionary-building does depend on the module you are 
> using to access the database. For example, both the MySQLdb.py and 
> PgSQL.py modules allow you to retrieve a dictionary (or dictionary-like 
> object) from a *.fetchall() call for example. There is devil in the 
> detail though, so perhaps you need to supply more information, like the 
> database and DB API module you are using to access it.
> 
> Best wishes,
> 
> Lindsay
> 
> 
> 
> On 14/2/01, Darrell Brogdon wrote about 'Re: [Tutor] building a tuple':
> 
>> Ok, so for example, I'm getting the following data:
>> 
>> Field Name        Value
>> ------------------------
>> fname             John
>> lname             Doe
>> address           123 Any St.
>> city              Anytown
>> 
>> Now I know I can manually build a tuple out of this data with the 
>> following:
>> 
>>    my_tuple {
>>        "fname" : "John",
>>        "lname" : "Doe",
>>        "address" : "123 Any St."
>>        "city" : "Anytown"
>>    }
>> 
>> But obviously with this data coming from the database I wouldn't know 
>> what the values are.  I've figured out how to get the data out of the 
>> database for the most part.  Now its just a matter of how to get that 
>> data into a tuple.
>> 
>> I think partly I'm confusing myself with my knowledge of PHP where you 
>> can pretty much get away with anything. :)
>> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Darrell Brogdon               http://darrell.brogdon.net
Web Developer - SourceForge   http://sourceforge.net
VA Linux Systems, Inc.        http://www.valinux.com



From tim@johnsons-web.com  Thu Feb 15 20:43:19 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Thu, 15 Feb 2001 11:43:19 -0900
Subject: [Tutor] Need Python Images
References: <a05010472b6b18b482353@[195.102.186.233]>
Message-ID: <01021511445503.01167@shecom>

Hi:
	I'm doing an online class on Programming using python.
I'd appreciate being pointed towards images (preferably gifs) displaying python.
They will help to dress up the content
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From randrews@planhouse.com  Thu Feb 15 20:55:00 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 15 Feb 2001 14:55:00 -0600
Subject: [Tutor] Need Python Images
References: <a05010472b6b18b482353@[195.102.186.233]> <01021511445503.01167@shecom>
Message-ID: <001801c09791$90c5ad20$9600a8c0@Planhouse5>

The "Python Powered" logo may be found at:
http://www.python.org/psa/Logo.html

I've been intending to whip up some snazzy Python pics in Photoshop lately,
but haven't been able to fit it into my copious free time lately.  What's
your deadline?

Rob
----- Original Message -----

> Hi:
> I'm doing an online class on Programming using python.
> I'd appreciate being pointed towards images (preferably gifs) displaying
python.
> They will help to dress up the content
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides



From pythoperson@yahoo.com  Thu Feb 15 21:02:43 2001
From: pythoperson@yahoo.com (folklore hopeful)
Date: Thu, 15 Feb 2001 13:02:43 -0800 (PST)
Subject: [Tutor] Python copyright question?
Message-ID: <20010215210243.673.qmail@web12402.mail.yahoo.com>

Hello everyone,

I have made quite a few handy python/tkinter programs
that the professors at my college would like to
distribute to students in their classes.   Since
downloading and installing python is a lot to ask of
all the students, and since not all the students would
have home computers, we are trying to come up with an
alternate solution.  So far, we were thinking of
distributing a cd-rom with python installed on it and
the scripts for the programs I have written.  This
way, students could use them either on their home
computers OR on the college's comptuers (which don't
take kindly to installations but will run CD-ROMs). 
Would this sort of copying be legal?  

Thanks,

- pythoperson

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/


From Christopher Bemis" <laser151@tvn.net  Thu Feb 15 21:50:56 2001
From: Christopher Bemis" <laser151@tvn.net (Christopher Bemis)
Date: Thu, 15 Feb 2001 16:50:56 -0500
Subject: [Tutor] Thank yous
Message-ID: <000d01c09799$622d4ba0$3808683f@laser151>

This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C0976F.7768E120
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

It worked! I can run the programs! I feel like a lumberjack!!! Thank you =
all for your suggestions on running my programs, they all helped to some =
degree....
The Great One

------=_NextPart_000_000A_01C0976F.7768E120
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><STRONG><FONT face=3D"Californian FB" color=3D#800080 size=3D2>It =
worked! I can=20
run the programs! I feel like a lumberjack!!! Thank you all for your =
suggestions=20
on running my programs, they all helped to some =
degree....</FONT></STRONG></DIV>
<DIV><STRONG><FONT face=3D"Californian FB" color=3D#800080 size=3D2>The =
Great=20
One</FONT></STRONG></DIV></BODY></HTML>

------=_NextPart_000_000A_01C0976F.7768E120--



From shaleh@valinux.com  Thu Feb 15 22:23:37 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Thu, 15 Feb 2001 14:23:37 -0800
Subject: [Tutor] question about glob.glob() implementation
Message-ID: <20010215142337.E11714@valinux.com>

glob.glob() has a section like:

if not has_magic(basename):
        result = []
        for dirname in list:
            if basename or os.path.isdir(dirname):
                name = os.path.join(dirname, basename)
                if os.path.exists(name):
                    result.append(name)
else:

For every iteration of the for loop, basename is tested, yet its value never
changes.  Am I missing something here or is this wasteful like i think it is?


From dsh8290@rit.edu  Thu Feb 15 23:57:00 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 15 Feb 2001 18:57:00 -0500
Subject: [Tutor] Python copyright question?
In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com>; from pythoperson@yahoo.com on Thu, Feb 15, 2001 at 01:02:43PM -0800
References: <20010215210243.673.qmail@web12402.mail.yahoo.com>
Message-ID: <20010215185659.A1668@harmony.cs.rit.edu>

On Thu, Feb 15, 2001 at 01:02:43PM -0800, folklore hopeful wrote:
| Hello everyone,
| 
| I have made quite a few handy python/tkinter programs
| that the professors at my college would like to
| distribute to students in their classes.   Since
| downloading and installing python is a lot to ask of
| all the students, and since not all the students would
| have home computers, we are trying to come up with an
| alternate solution.  So far, we were thinking of
| distributing a cd-rom with python installed on it and
| the scripts for the programs I have written.  This
| way, students could use them either on their home
| computers OR on the college's comptuers (which don't
| take kindly to installations but will run CD-ROMs). 
| Would this sort of copying be legal?  
| 
| Thanks,
| 
| - pythoperson
|

I think it would be legal to copy the interpreter like that.  But I'm
not a lawyer, so don't quote me.  The license is freely available,
and the interpreter is freely available as well.  It would probably be
simpler for you to just install python on the school's computers.
(That is, get the appropriate authority's permission and have them set
up by the proper admin)

You should probably ask on python-list since there are people with a
better understanding of the license.

Programs such as py2exe and Gordon McMillan's installer allow you to
package the interpreter with your program into an installer (for
Windows) so I don't think there is any problems with redistributing
the interpreter.

HTH,
-D

 


From scarblac@pino.selwerd.nl  Fri Feb 16 00:20:51 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Fri, 16 Feb 2001 01:20:51 +0100
Subject: [Tutor] Python copyright question?
In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com>; from pythoperson@yahoo.com on Thu, Feb 15, 2001 at 01:02:43PM -0800
References: <20010215210243.673.qmail@web12402.mail.yahoo.com>
Message-ID: <20010216012051.A279@pino.selwerd.nl>

On Thu, Feb 15, 2001 at 01:02:43PM -0800, folklore hopeful wrote:
> I have made quite a few handy python/tkinter programs
> that the professors at my college would like to
> distribute to students in their classes.   Since
> downloading and installing python is a lot to ask of
> all the students, and since not all the students would
> have home computers, we are trying to come up with an
> alternate solution.  So far, we were thinking of
> distributing a cd-rom with python installed on it and
> the scripts for the programs I have written.  This
> way, students could use them either on their home
> computers OR on the college's comptuers (which don't
> take kindly to installations but will run CD-ROMs). 
> Would this sort of copying be legal?  

Certainly. Quoting from the Python 1.6 license which was basically carried
to 2.0, you as individual or organization using Python 1.6 are the Licensee,
and 

"2. Subject to the terms and conditions of this License Agreement, CNRI
hereby grants Licensee a nonexclusive, royalty-free, world-wide license to
reproduce, anayze, test, perform and/or display publicly, prepare derivative
works, distribute, and otherwise use Python 1.6 alone or in any derivative
version, ..." [provided that the copyright notice is retained].

Well, *read the exact license yourself*. You are allowed to do absolutely
anything with the code, as long as you list any changes to the original in
some way, and CNRI/BeOpen/etc has no obligations to you whatsoever.

-- 
Remco Gerlich


From tim_one@email.msn.com  Fri Feb 16 00:22:31 2001
From: tim_one@email.msn.com (Tim Peters)
Date: Thu, 15 Feb 2001 19:22:31 -0500
Subject: [Tutor] Python copyright question?
In-Reply-To: <20010215210243.673.qmail@web12402.mail.yahoo.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCGEKPIPAA.tim_one@email.msn.com>

[folklore hopeful]

Cool handle!

> ...
> So far, we were thinking of distributing a cd-rom with
> python installed on it and the scripts for the programs
> I have written.  This way, students could use them either
> on their home computers OR on the college's comptuers
> (which don't take kindly to installations but will run
> CD-ROMs).  Would this sort of copying be legal?

You didn't say which version of Python you're using.  Each version comes
with a license.  Read the license -- it's good practice for the Real World
<wink>.  All Python licenses to date allow you to make copies and do
distribution without asking for permission, or even telling us, unless
you're using the ActiveState distribution.  More details have to be gotten
from the specific license for the specific version of Python you're using.

While this is certainly not legal advice, just between us nobody has ever
gotten in any trouble for doing anything with Python, and that's the way we
like it.

share-and-enjoy-but-read-the-darn-license-first-ly y'rs  - tim



From joejava@dragoncat.net  Fri Feb 16 00:39:07 2001
From: joejava@dragoncat.net (Joel Ricker)
Date: Thu, 15 Feb 2001 19:39:07 -0500
Subject: [Tutor] Automating Web Browsing
References: <20010215210243.673.qmail@web12402.mail.yahoo.com> <20010216012051.A279@pino.selwerd.nl>
Message-ID: <00aa01c097b0$ea52b120$a0a2d6d1@ceo>

    In my idle time -- when I have some anyway -- my diversion of choice has
been the Hollywood Stock Exchange.  For those not familiar with it, it is a
simulation where you buy and sell stocks on actual movies.  Alot like the
real stock market it takes a little shrewness and research to make money and
all around quite fun.

    My problem is that now that my portfolio has grown quite a bit, I'm
having trouble keeping up with it.  The number of stocks I have to buy and
sell on a given day has increased to the point where it takes too much time
to even play.

    [How this relates to Python] What I would like to do is automate my
buying and selling, which amounts to logging in to the site, going to the
buy/sell section, filling out a form with the Movies stock symbol, pressing
buy, and pressing the confirm button, and then repeat.  What modules can I
use to accomplish this? In searching around for information I ran across a
mention of LWP::UserAgent for Perl and it sounds kind of what I'm looking
for -- except it uses Perl.  Any ideas?

Thanks
Joel



From tescoil@irtc.net  Fri Feb 16 03:45:13 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Thu, 15 Feb 2001 21:45:13 -0600
Subject: [Tutor] Need Python Images
References: <a05010472b6b18b482353@[195.102.186.233]> <01021511445503.01167@shecom>
Message-ID: <3A8CA249.27D0DAB6@irtc.net>

On 15 Feb 2001, Tim Johnson wrote:
> I'm doing an online class on Programming using python.
> I'd appreciate being pointed towards images (preferably
> gifs) displaying python.  They will help to dress up the
> content

There's two or three images in http://www.python.org/pics/
I'm not certain are used in any html page on the site--like
kick_camels_butt.gif and pythondo.gif.  I took pythonHi.gif,
did various snazzy stuff with it--not all extant and none of
it published on the web, but easy enough to whip up again
if you'd want 'em in email attachments ... or if R.A. decides
to add a gallery for collecting Python propaganda images.  ;)






From britt_green@hotmail.com  Fri Feb 16 04:38:58 2001
From: britt_green@hotmail.com (Britt Green)
Date: Thu, 15 Feb 2001 20:38:58 -0800
Subject: [Tutor] Errr...Capitalizing Words
Message-ID: <F71oryKFRJrzdDW6lCP00017947@hotmail.com>

Hello,

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

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

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

Can anyone point me in the right direction for this?

Thanks,

Britt

--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From darrell@brogdon.net  Fri Feb 16 06:41:01 2001
From: darrell@brogdon.net (Darrell Brogdon)
Date: Fri, 16 Feb 2001 01:41:01 -0500
Subject: [Tutor] xmlrpclib docs/examples
Message-ID: <3A8CCB7D.4020801@brogdon.net>

Does anyone know where I can find *good* (see: any) documentation on xmlrpclib as well as some examples of how to use it?   
I've been playing around with it as a side project but the code isn't really documented all that well and what little info I find 
elsewhere really doesn't indicate how to use it.

-- 
Darrell Brogdon
http://darrell.brogdon.net



From bsass@freenet.edmonton.ab.ca  Fri Feb 16 08:19:31 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 16 Feb 2001 01:19:31 -0700 (MST)
Subject: [Tutor] question about glob.glob() implementation
In-Reply-To: <20010215142337.E11714@valinux.com>
Message-ID: <Pine.LNX.4.33.0102160001070.6396-100000@bms>

On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote:

> glob.glob() has a section like:
>
> if not has_magic(basename):
>         result = []
>         for dirname in list:
>             if basename or os.path.isdir(dirname):
>                 name = os.path.join(dirname, basename)
>                 if os.path.exists(name):
>                     result.append(name)
> else:
>
> For every iteration of the for loop, basename is tested, yet its value never
> changes.  Am I missing something here or is this wasteful like i think it is?

Hmmm, it looks like a dual purpose routine.  If basename is an empty
string, result ends up with the paths to the dirs in list that exist
(i.e., where can I look?).  If basename has a value, result ends up
with the paths that end in basename (i.e., is it there?).

I think you're missing the logic of the for loop. If basename is
"true", the action is always performed on dirname; if it is "false",
the action is only performed when dirname is a dir.  If dirname is a
dir, the action is always performed; if dirname is not a dir the
action is performed if basename is true. Since neither basename or
os.path.isdir(dirname) alone can determine what to do it is necessary
to test both for each value taken on by dirname.  Check out the truth
table; b is the basename term, d is the os.path.isdir(dirname) term,
action is what happens.

b d action
- - ------
0 0 skip
0 1 do
1 0 do
1 1 do

Since it can't be simplified, both terms are necessary.


- Bruce



From bsass@freenet.edmonton.ab.ca  Fri Feb 16 08:51:13 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 16 Feb 2001 01:51:13 -0700 (MST)
Subject: [Tutor] Errr...Capitalizing Words
In-Reply-To: <F71oryKFRJrzdDW6lCP00017947@hotmail.com>
Message-ID: <Pine.LNX.4.33.0102160136350.6396-100000@bms>

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

string.capitalize(a_sentence) works, once you split the text into
sentences.


- Bruce



From bxuef@freemail.sx.cn  Fri Feb 16 08:57:01 2001
From: bxuef@freemail.sx.cn (bxuef@freemail.sx.cn)
Date: Fri, 16 Feb 2001 16:57:01 +0800 (CST)
Subject: [Tutor] need help
Message-ID: <AC989783834298.08861@freemail>

 Hi, everyone,
Please help me to make a webpage username and password authentication program.
I started learning Python mainly for this function but right now I still can not do the job.
I typed 
>s = raw_input("please enter your password: ")
>if raw_input=="password"
     print "authenticated"
#go to another page.

I described this in human language, could help me right a simple example for me?
This is not my homework and I am a newbie down-to-earth, so please kindly help me.
thanks.


-----------------------------------------------------------
»¶Ó­Ê¹ÓÃɽÎ÷µçÐÅÃâ·Ñµç×ÓÓʼþϵͳ <http://freemail.sx.cn> ¡£
ÈçÓÐÎÊÌ⣬ÇëÓë webmaster@freemail.sx.cn <mailto:webmaster@freemail.sx.cn> ÁªÏµ¡£
ллÄúµÄʹÓã¡



From Lindsay.Davies@moonshine.co.uk  Fri Feb 16 09:05:42 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Fri, 16 Feb 2001 09:05:42 +0000
Subject: [Tutor] Errr...Capitalizing Words
In-Reply-To: <F71oryKFRJrzdDW6lCP00017947@hotmail.com>
References: <F71oryKFRJrzdDW6lCP00017947@hotmail.com>
Message-ID: <a05010478b6b2972e254b@[195.102.186.233]>

--============_-1229808104==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

Well, here's a quick line that will do it for you...

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

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

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

Best wishes,

Lindsay


On 15/2/01, Britt Green wrote about '[Tutor] Errr...Capitalizing Words':
>Hello,
>
>I'm kind of stuck on something seemingly trivial, and I'm hoping 
>someone can help me out. Say I have a block of text, all in lower 
>case:
>
>this is some sample text. its all in lower case. there are no 
>capitals in this block of text. you get the idea, and now i'm just 
>typing to make a lot of text.
>
>What I want to do with Python is take the first letter of each 
>sentance and capitalize it. By looking into the string library I've 
>found the string.capitalize() function. This only seems to work if 
>you know the word you're trying to use. Then string.capwords() will 
>capitalize each word instead of just the first one.
>
>Can anyone point me in the right direction for this?
>
>Thanks,
>
>Britt
>
>--
>It is pitch black. You are likely to be eaten by a grue.
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--============_-1229808104==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
 --></style><title>Re: [Tutor] Errr...Capitalizing
Words</title></head><body>
<div>Well, here's a quick line that will do it for you...</div>
<div><br></div>
<div><font color="#000000"><b>import</b> string,re</font></div>
<div><font color="#000000">s =</font><font color="#007F00"> '''this is
some sample text. its all in lower case. there are no capitals in this
block of text. you get the idea, and now i'm just typing to make a lot
of text.'''</font></div>
<div><font color="#000000"><br></font></div>
<div><font color="#000000"><b>s =</b> re.sub(</font><font
color="#007F00">&quot;(\.\s*|^\s*)(\w)&quot;</font><font
color="#000000">, (<b>lambda</b> x: x.group(1) +\</font></div>
<div><font color="#000000">&nbsp;&nbsp;&nbsp;
string.upper(x.group(2))), s)</font></div>
<div><br></div>
<div>This matches appropriate characters with a regular expression,
and then capitalizes them.</div>
<div><br></div>
<div>Best wishes,</div>
<div><br></div>
<div>Lindsay</div>
<div><br></div>
<div><br></div>
<div>On 15/2/01, Britt Green wrote about '[Tutor] Errr...Capitalizing
Words':</div>
<blockquote type="cite" cite>Hello,<br>
<br>
I'm kind of stuck on something seemingly trivial, and I'm hoping
someone can help me out. Say I have a block of text, all in lower
case:<br>
<br>
this is some sample text. its all in lower case. there are no capitals
in this block of text. you get the idea, and now i'm just typing to
make a lot of text.<br>
<br>
What I want to do with Python is take the first letter of each
sentance and capitalize it. By looking into the string library I've
found the string.capitalize() function. This only seems to work if you
know the word you're trying to use. Then string.capwords() will
capitalize each word instead of just the first one.<br>
<br>
Can anyone point me in the right direction for this?<br>
<br>
Thanks,<br>
<br>
Britt<br>
<br>
--<br>
It is pitch black. You are likely to be eaten by a grue.<br>
<br>
_________________________________________________________________<br>
Get your FREE download of MSN Explorer at http://explorer.msn.com<br>
<br>
<br>
_______________________________________________</blockquote>
<blockquote type="cite" cite>Tutor maillist&nbsp; -&nbsp;
Tutor@python.org</blockquote>
<blockquote type="cite"
cite>http://mail.python.org/mailman/listinfo/tutor</blockquote>
<div><br></div>
</body>
</html>
--============_-1229808104==_ma============--


From NHYTRO@compuserve.com  Fri Feb 16 09:22:37 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 16 Feb 2001 04:22:37 -0500
Subject: [Tutor] Errr...Capitalizing Words
Message-ID: <200102160422_MC2-C5D1-B20E@compuserve.com>

Hi Britt!

In this case I would store the text in a variable then loop a  function
that contains a "Regular expression" over it.. The exprssion sorts out th=
e
first words in a sentences and capitilizes it.

Hope that helps somehow


Sharriff



Message text written by INTERNET:tutor@python.org
>Message: 13
From: "Britt Green" <britt_green@hotmail.com>
To: tutor@python.org
Date: Thu, 15 Feb 2001 20:38:58 -0800
Subject: [Tutor] Errr...Capitalizing Words

Hello,

I'm kind of stuck on something seemingly trivial, and I'm hoping someone
can =

help me out. Say I have a block of text, all in lower case:

this is some sample text. its all in lower case. there are no capitals in=
 =

this block of text. you get the idea, and now i'm just typing to make a l=
ot

of text.

What I want to do with Python is take the first letter of each sentance a=
nd

capitalize it. By looking into the string library I've found the =

string.capitalize() function. This only seems to work if you know the wor=
d =

you're trying to use. Then string.capwords() will capitalize each word =

instead of just the first one.

Can anyone point me in the right direction for this?

Thanks,

Britt<



From ibraheem@micromuse.com  Fri Feb 16 09:31:33 2001
From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed)
Date: Fri, 16 Feb 2001 09:31:33 +0000
Subject: [Tutor] need help
In-Reply-To: <AC989783834298.08861@freemail>; from bxuef@freemail.sx.cn on Fri, Feb 16, 2001 at 04:57:01PM +0800
References: <AC989783834298.08861@freemail>
Message-ID: <20010216093133.A7216@micromuse.com>

Hi,


On Fri, Feb 16, 2001 at 04:57:01PM +0800, bxuef@freemail.sx.cn wrote:
>  Hi, everyone,
> Please help me to make a webpage username and password authentication p=
rogram.
> I started learning Python mainly for this function but right now I stil=
l can not do the job.
> I typed=20
> >s =3D raw_input("please enter your password: ")
> >if raw_input=3D=3D"password"
>      print "authenticated"
> #go to another page.
>=20

I think what you meant to write is something like this:

	>>>def test():
	...	s =3D raw_input("please enter your password: ")
	...	if s =3D=3D "password":
	...		print "authenticated"
	...	else:
	...		print "authentication failure"
	>>> test()
	please enter your password: password
	authenticated
	>>> test()
	please enter your password: boo
	authentication failure
	>>>

basically I think you meant to compare "s" and not "raw_input".

kindest regards,

	--ibs.
=09
=09
> I described this in human language, could help me right a simple exampl=
e for me?
> This is not my homework and I am a newbie down-to-earth, so please kind=
ly help me.
> thanks.
>=20
>=20
> -----------------------------------------------------------
> =BB=B6=D3=AD=CA=B9=D3=C3=C9=BD=CE=F7=B5=E7=D0=C5=C3=E2=B7=D1=B5=E7=D7=D3=
=D3=CA=BC=FE=CF=B5=CD=B3 <http://freemail.sx.cn> =A1=A3
> =C8=E7=D3=D0=CE=CA=CC=E2=A3=AC=C7=EB=D3=EB webmaster@freemail.sx.cn <ma=
ilto:webmaster@freemail.sx.cn> =C1=AA=CF=B5=A1=A3
> =D0=BB=D0=BB=C4=FA=B5=C4=CA=B9=D3=C3=A3=A1
>=20
>=20
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>=20

--=20
-------------------------------------------------------------------------=
-------
			--  Ibraheem Umaru-Mohammed  --
			--  Email:ium@micromuse.com  --
-- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA =
--
			--  http://www.micromuse.com --
-------------------------------------------------------------------------=
-------


From jcm@bigskytel.com  Fri Feb 16 09:40:37 2001
From: jcm@bigskytel.com (David Porter)
Date: Fri, 16 Feb 2001 02:40:37 -0700
Subject: [Tutor] xmlrpclib docs/examples
In-Reply-To: <3A8CCB7D.4020801@brogdon.net>; from darrell@brogdon.net on Fri, Feb 16, 2001 at 01:41:01AM -0500
References: <3A8CCB7D.4020801@brogdon.net>
Message-ID: <20010216024037.A20435@bigskytel.com>

* Darrell Brogdon <darrell@brogdon.net>:

> Does anyone know where I can find *good* (see: any) documentation on
> xmlrpclib as well as some examples of how to use it? 
<..>

Here are some to get you started:

XML-RPC in Python:
  http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html

XML-RPC: It Works Both Ways:
  http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html

XML-RPC HOWTO:  
  http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html


I should read these too...  
  
David  


From amoreira@mercury.ubi.pt  Fri Feb 16 10:19:56 2001
From: amoreira@mercury.ubi.pt (Jose Amoreira)
Date: Fri, 16 Feb 2001 10:19:56 +0000
Subject: [Tutor] off-topic? (dos box)
Message-ID: <3A8CFECB.A0F47DF6@mercury.ubi.pt>

I'm sorry if this is somewhat offtopic, but anyway...
At home, I usually run idle, but sometimes I'd prefer to run the
interpreter in a dos box. The problem is that I loose all the facilities
provided by readline, like command recall and editing. At work, I use a
linux pc, and install python from sources, with the readline option; but
in windows I don't have the make utility,  so I install precompiled
binaries. Replacing windows with an operating system is not an option
because the majority (my wife and kids) voted against it, go figure...
So my question is:
Is there any way of running the python interpreter in a command line
shell, with readline (or something similar) in windows? If so, could you
tell me how to do it, please?

Many thanks,
Ze

amoreira@mercury.ubi.pt



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 16 11:05:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 16 Feb 2001 03:05:34 -0800 (PST)
Subject: [Tutor] Errr...Capitalizing Words
In-Reply-To: <a05010478b6b2972e254b@[195.102.186.233]>
Message-ID: <Pine.LNX.4.21.0102160302510.743-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 16 Feb 2001, Lindsay Davies wrote:

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

As a safety tip: it's safer to make the regular expression an explicit
"raw" string, because it's only coincidence that '\s' doesn't match up as
a special character:

    s = re.sub(r"(\.\s*|  ...



From randrews@planhouse.com  Fri Feb 16 14:13:13 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 16 Feb 2001 08:13:13 -0600
Subject: [Tutor] Need Python Images
References: <a05010472b6b18b482353@[195.102.186.233]> <01021511445503.01167@shecom> <3A8CA249.27D0DAB6@irtc.net>
Message-ID: <000f01c09822$9bc28360$9600a8c0@Planhouse5>

It's a tempting idea, actually, since I'm working on some of my own.  We'd
just have to make sure people who submit images know how to make them
*small-ish* for the web.

Anything else Useless we should add to the site? ;->

Rob

----- Original Message -----
From: "Tesla Coil" <tescoil@irtc.net>


> On 15 Feb 2001, Tim Johnson wrote:
or if R.A. decides
> to add a gallery for collecting Python propaganda images.  ;)
>




From dsh8290@rit.edu  Fri Feb 16 15:44:02 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 16 Feb 2001 10:44:02 -0500
Subject: [Tutor] question about glob.glob() implementation
In-Reply-To: <Pine.LNX.4.33.0102160001070.6396-100000@bms>; from bsass@freenet.edmonton.ab.ca on Fri, Feb 16, 2001 at 01:19:31AM -0700
References: <20010215142337.E11714@valinux.com> <Pine.LNX.4.33.0102160001070.6396-100000@bms>
Message-ID: <20010216104402.F2913@harmony.cs.rit.edu>

On Fri, Feb 16, 2001 at 01:19:31AM -0700, Bruce Sass wrote:
| On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote:
[snip]

| 
| b d action
| - - ------
| 0 0 skip
| 0 1 do
| 1 0 do
| 1 1 do
| 
| Since it can't be simplified, both terms are necessary.
| 

Couldn't it be reduced to 

if (not b) and (not d) :
    skip
else :
    do

or

if b or d :
    do
else :
    skip

?

I don't know if that would make any improvement, but ...

-D



From dsh8290@rit.edu  Fri Feb 16 15:51:04 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 16 Feb 2001 10:51:04 -0500
Subject: [Tutor] off-topic? (dos box)
In-Reply-To: <3A8CFECB.A0F47DF6@mercury.ubi.pt>; from amoreira@mercury.ubi.pt on Fri, Feb 16, 2001 at 10:19:56AM +0000
References: <3A8CFECB.A0F47DF6@mercury.ubi.pt>
Message-ID: <20010216105104.G2913@harmony.cs.rit.edu>

On Fri, Feb 16, 2001 at 10:19:56AM +0000, Jose Amoreira wrote:
| I'm sorry if this is somewhat offtopic, but anyway...
| At home, I usually run idle, but sometimes I'd prefer to run the
| interpreter in a dos box. The problem is that I loose all the facilities
| provided by readline, like command recall and editing. At work, I use a
| linux pc, and install python from sources, with the readline option; but
| in windows I don't have the make utility,  so I install precompiled
| binaries. Replacing windows with an operating system is not an option
| because the majority (my wife and kids) voted against it, go figure...
| So my question is:
| Is there any way of running the python interpreter in a command line
| shell, with readline (or something similar) in windows? If so, could you
| tell me how to do it, please?
| 

The Python 2.0 binaries I installed on this Win2k machine have command
history and editing (no ^U though) if run from a DOS box.  If I run it
from bash it doens't =p.  Jython doesn't (because Java
doesn't have readline =p).

You could probably build from source like it was a unix machine after
installing cygwin.  You'll probably want cygwin anyways since you are
familiar with Linux.  http://sources.redhat.com

HTH,
-D



From darrell@brogdon.net  Fri Feb 16 16:09:38 2001
From: darrell@brogdon.net (Darrell Brogdon)
Date: Fri, 16 Feb 2001 11:09:38 -0500
Subject: [Tutor] xmlrpclib docs/examples
References: <3A8CCB7D.4020801@brogdon.net> <20010216024037.A20435@bigskytel.com>
Message-ID: <3A8D50C2.1060002@brogdon.net>

Thanks for the links David.  The third is new to me so I will definately 
have a look.  I Found "XML-RPC: It Works Both Ways" to be helpful but 
the problem I have is that when I try to add additional methods to the 
class and call them with my client I get errors back saying something to 
the effect of "...expected 1 argument, got 3" which is really confusing 
because the methods I've created have no arguments.

David Porter wrote:

> * Darrell Brogdon <darrell@brogdon.net>:
> 
> 
>> Does anyone know where I can find *good* (see: any) documentation on
>> xmlrpclib as well as some examples of how to use it? 
> 
> <..>
> 
> Here are some to get you started:
> 
> XML-RPC in Python:
>   http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html
> 
> XML-RPC: It Works Both Ways:
>   http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html
> 
> XML-RPC HOWTO:  
>   http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html
> 
> 
> I should read these too...  
>   
> David  
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Darrell Brogdon
http://darrell.brogdon.net



From shaleh@valinux.com  Fri Feb 16 16:15:39 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 16 Feb 2001 08:15:39 -0800 (PST)
Subject: [Tutor] question about glob.glob() implementation
In-Reply-To: <Pine.LNX.4.33.0102160001070.6396-100000@bms>
Message-ID: <XFMail.20010216081539.shaleh@valinux.com>

On 16-Feb-2001 Bruce Sass wrote:
> On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote:
> 
>> glob.glob() has a section like:
>>
>> if not has_magic(basename):
>>         result = []
>>         for dirname in list:
>>             if basename or os.path.isdir(dirname):
>>                 name = os.path.join(dirname, basename)
>>                 if os.path.exists(name):
>>                     result.append(name)
>> else:
>>
>> For every iteration of the for loop, basename is tested, yet its value never
>> changes.  Am I missing something here or is this wasteful like i think it
>> is?
> 
> Hmmm, it looks like a dual purpose routine.  If basename is an empty
> string, result ends up with the paths to the dirs in list that exist
> (i.e., where can I look?).  If basename has a value, result ends up
> with the paths that end in basename (i.e., is it there?).
> 

Could use a comment then.  What it looks like it is doing is making sure it is
not using an empty basename string.  And since the basename value never changes
the check seems superfluous.  I still feel this could be better coded, although
I am struggling to find the answer.  Thanks for the help.


From gibbs05@flash.net  Fri Feb 16 16:58:58 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Fri, 16 Feb 2001 10:58:58 -0600
Subject: [Tutor] xmlrpclib docs/examples
References: <3A8CCB7D.4020801@brogdon.net> <20010216024037.A20435@bigskytel.com> <3A8D50C2.1060002@brogdon.net>
Message-ID: <017d01c09839$dde05bc0$e9ef3040@gibbs05>

Greetings Darrell & All,

Your call method is probably passing two additional arguments: method &
params.  At least that's what it's supposed to do. :-)

Try changing the method definitions you created to something like the
following:

    def YourMethod(self, method, anyparams):
        # your code

See what happens from there...


Good luck,
Sam


> Thanks for the links David.  The third is new to me so I will definately
> have a look.  I Found "XML-RPC: It Works Both Ways" to be helpful but
> the problem I have is that when I try to add additional methods to the
> class and call them with my client I get errors back saying something to
> the effect of "...expected 1 argument, got 3" which is really confusing
> because the methods I've created have no arguments.
>
> David Porter wrote:
>
> > * Darrell Brogdon <darrell@brogdon.net>:
> >
> >
> >> Does anyone know where I can find *good* (see: any) documentation on
> >> xmlrpclib as well as some examples of how to use it?
> >
> > <..>
> >
> > Here are some to get you started:
> >
> > XML-RPC in Python:
> >   http://www.oreillynet.com/pub/a/python/2000/11/22/xmlrpcclient.html
> >
> > XML-RPC: It Works Both Ways:
> >   http://www.oreillynet.com/pub/a/python/2001/01/17/xmlrpcserver.html
> >
> > XML-RPC HOWTO:
> >   http://www.linuxdoc.org/HOWTO/XML-RPC-HOWTO/index.html
> >
> >
> > I should read these too...
> >
> > David
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>
> --
> Darrell Brogdon
> http://darrell.brogdon.net




From mr804@users.757.org  Fri Feb 16 18:17:32 2001
From: mr804@users.757.org (Mr 804)
Date: Fri, 16 Feb 2001 13:17:32 -0500 (EST)
Subject: [Tutor] reading stdin?
In-Reply-To: <Pine.LNX.4.33.0102160001070.6396-100000@bms>
Message-ID: <Pine.BSO.4.21.0102161316560.118-100000@users.757.org>

how do I read stdin?





From dsh8290@rit.edu  Fri Feb 16 18:30:00 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 16 Feb 2001 13:30:00 -0500
Subject: [Tutor] reading stdin?
In-Reply-To: <Pine.BSO.4.21.0102161316560.118-100000@users.757.org>; from mr804@users.757.org on Fri, Feb 16, 2001 at 01:17:32PM -0500
References: <Pine.LNX.4.33.0102160001070.6396-100000@bms> <Pine.BSO.4.21.0102161316560.118-100000@users.757.org>
Message-ID: <20010216133000.A3862@harmony.cs.rit.edu>

On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote:
| 
| how do I read stdin?
| 

>>> data = raw_input( "Please give me some data: " )
Please give me some data: Hello World
>>> type( data )
<type 'string'>
>>> print data
Hello World
>>>


raw_input is good if you want random stuff or text stuff,
if you want other stuff, input can be helpful

>>> data = input( "Enter some data: " )
Enter some data: 2
>>> type( data )
<type 'int'>
>>> print data
2
>>>


However, be careful how you use input() :

>>> data = input( "Enter some data: " )
Enter some data: foo
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 0, in ?
NameError: There is no variable named 'foo'
>>>

>>> i = 2
>>> data = input( "Enter some data: " )
Enter some data: lambda x : x + i
>>> type( data )
<type 'function'>
>>> print data
<function <lambda> at 007A8574>
>>> print data( 3 )
5
>>>


input won't always do what you want, if the user inputs bad stuff.
You can use raw_input, then convert the string how you want to.  Ex:

>>> try :
...     data = int( raw_input( "Enter a number: " ) )
... except ValueError , err :
...     print "You didn't enter a valid number"
...
Enter a number: 3
>>> print data
3
>>>
>>> try :
...     data = int( raw_input( "Enter a number: " ) )
... except ValueError , err :
...     print "You didn't enter a valid number"
...
Enter a number: asdf
You didn't enter a valid number
>>>


If you have more questions, just ask.

HTH,
-D



From kalle@gnupung.net  Fri Feb 16 19:52:12 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 16 Feb 2001 20:52:12 +0100
Subject: [Tutor] reading stdin?
In-Reply-To: <20010216133000.A3862@harmony.cs.rit.edu>; from dsh8290@rit.edu on Fri, Feb 16, 2001 at 01:30:00PM -0500
References: <Pine.LNX.4.33.0102160001070.6396-100000@bms> <Pine.BSO.4.21.0102161316560.118-100000@users.757.org> <20010216133000.A3862@harmony.cs.rit.edu>
Message-ID: <20010216205212.A926@apone.network.loc>

--1yeeQ81UyVL57Vl7
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez D-Man:
> On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote:
> |=20
> | how do I read stdin?
> |=20
[snip great introduction to input/raw_input]

If you want to read from standard input in a more low-level way, perhaps
better suited for redirected input and that kind of stuff, use sys.stdin.

import sys
# get input
s =3D sys.stdin.read()
# do stuff

sys.{stdin|stdout|stderr} are ordinary file objects.  This makes it easy to
use standard input/output as defaults, e.g. if no input/output files are
specified on the command line:

# crude example
import sys
if len(sys.argv) =3D=3D 1:
    outfile =3D sys.stdout
    infile =3D sys.stdin
elif len(sys.argv) =3D=3D 2:
    outfile =3D open(sys.argv[1])
    infile =3D sys.stdin
else:
    outfile =3D open(sys.argv[1])
    infile =3D open(sys.argv[2])

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--1yeeQ81UyVL57Vl7
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6jYTsdNeA1787sd0RAsbmAKCPalN1+ULLJGql/BIT1e5R8tY7fwCgqZlO
/U7UlVZLhKK+CmI+WDyx6Gg=
=GPzc
-----END PGP SIGNATURE-----

--1yeeQ81UyVL57Vl7--


From bsass@freenet.edmonton.ab.ca  Fri Feb 16 20:47:58 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 16 Feb 2001 13:47:58 -0700 (MST)
Subject: [Tutor] question about glob.glob() implementation
In-Reply-To: <20010216104402.F2913@harmony.cs.rit.edu>
Message-ID: <Pine.LNX.4.33.0102161308070.7317-100000@bms>

On Fri, 16 Feb 2001, D-Man wrote:

> On Fri, Feb 16, 2001 at 01:19:31AM -0700, Bruce Sass wrote:
> | On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote:
> [snip]
>
> |
> | b d action
> | - - ------
> | 0 0 skip
> | 0 1 do
> | 1 0 do
> | 1 1 do
> |
> | Since it can't be simplified, both terms are necessary.
> |
>
> Couldn't it be reduced to
>
> if (not b) and (not d) :
>     skip
> else :
>     do

Ya, but it is not a reduction or simplification.
You could rewrite as...
	if not ((not b) and (not d)):
	    do
	else:
	    skip
simply by reversing the sense of the test; applying a couple of the
"rules of replacement" (I'll use Boolean algebra syntax, 'cause
it's shorter)[1]...

	(b'*d')' ---------> b''+d'' -------> b+d
                  DeMorgan           Double
                                    Negation

So, it is the same logically, but requires 4 operators instead of 1.


> or
>
> if b or d :
>     do
> else :
>     skip

This is what is there already; "else: skip" == "", right.


- Bruce


[1] Boolean Algebra	words	others
    ---------------     -----   ------
	+		or	v, |
	*		and     &
	'		not	~


A couple of replacement rules, expressed in yet another logic system
(just to confuse you ;)...

DeMorgan's Theorem:	~(P&Q)::~Pv~Q
Double Negation:	P::~~P



From dsh8290@rit.edu  Fri Feb 16 20:57:45 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 16 Feb 2001 15:57:45 -0500
Subject: [Tutor] question about glob.glob() implementation
In-Reply-To: <Pine.LNX.4.33.0102161308070.7317-100000@bms>; from bsass@freenet.edmonton.ab.ca on Fri, Feb 16, 2001 at 01:47:58PM -0700
References: <20010216104402.F2913@harmony.cs.rit.edu> <Pine.LNX.4.33.0102161308070.7317-100000@bms>
Message-ID: <20010216155744.A4932@harmony.cs.rit.edu>

On Fri, Feb 16, 2001 at 01:47:58PM -0700, Bruce Sass wrote:
| On Fri, 16 Feb 2001, D-Man wrote:
[snip]
| > Couldn't it be reduced to
| >
[snip]
| Ya, but it is not a reduction or simplification.
[snip]
| > if b or d :
| >     do
| > else :
| >     skip
| 
| This is what is there already; "else: skip" == "", right.

I just took another look and it is what is there already.  I guess I
didn't look closely enough at the original.

-D



From abreu@penguinpowered.com  Sat Feb 17 09:39:33 2001
From: abreu@penguinpowered.com (Jose Alberto Abreu)
Date: Sat, 17 Feb 2001 03:39:33 -0600
Subject: [Tutor] anybody tried PMZ for cgi?
Message-ID: <3A8E46D5.1C2F8F98@penguinpowered.com>

Has anybody tried Poor Man's Zope? I stumbled upon it on sourceforge and
would like to try it, anybody has any comments about it?


From m_r_quick@yahoo.co.uk  Sat Feb 17 11:47:04 2001
From: m_r_quick@yahoo.co.uk (Martyn Quick)
Date: Sat, 17 Feb 2001 11:47:04 +0000
Subject: [Tutor] Turning some Tkinter stuff into classes
Message-ID: <3A8E64B8.E1183007@yahoo.co.uk>

I have the following code which *seems* to work ok:

--------------------------------
from Tkinter import *

class Popup:
	def __init__(self,master):
		self.win = Toplevel(master)

def popup():
	newwin = Popup(root)

class PopupButton:
	def __init(self,master):
		self.button = Button(master,text="New!",command=popup)
		self.button.pack()

root = Tk()
button = PopupButton(root)

root.mainloop()
--------------------------------

The problem is that the definition of "popup" is stylistically horrible
(I think - I'm still rather new to Object Oriented Programming) since it
has to refer to the fixed object root, but I'm using it within the class
PopupButton, so could theoretically create another object with no
reference to root using this class.  My attempt to create a better
definition inside the class definition was as follows:

---------------------------
from Tkinter import *

class Popup:
	def __init__(self,master):
		self.win = Toplevel(master)

class PopupButton:
	def __init__(self,master):
		self.button=Button(master,text="New!",command=self.popup(master))
		self.button.pack()

	def popup(self,master):
		self.newwin = Popup(master)

root = Tk()
button = PopupButton(root)

root.mainloop()
----------------------------------------

Of course, the above didn't work - I got the new popup window
immediately and the button didn't do anything.  Other attempts to do a
similar thing (deleting the master reference in the various bits of the
popup command) produced syntax errors.

Any suggestions to correct what it is wrong in my second attempt?

Thanks,

Martyn


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From W.W.vandenBroek  Sat Feb 17 12:58:03 2001
From: W.W.vandenBroek (W.W.vandenBroek)
Date: Sat, 17 Feb 2001 13:58:03 +0100
Subject: [Tutor] Re: hacking
In-Reply-To: <E14TgmC-0002DA-00@mail.python.org>
References: <E14TgmC-0002DA-00@mail.python.org>
Message-ID: <01021713580303.02006@vdbroekw>

> Message: 1
> Date: Thu, 15 Feb 2001 18:09:32 +0100 (MET)
> To: <rsmith@ffs.cc>
> Cc: tutor@python.org
> Cc: tutor@python.org
> Subject: Re: [Tutor] i want to learn to hack
> From: =?ISO-8859-1?Q?J=F6rg_W=F6lke?= <lumbricus@gmx.net>
>
> > how do i hack?
> >
> > -Ryan
> >
> > _______________________________________________
>
> youre running windoze - right?
> fire up a dos prompt and type format c:
> hit return and get an os. ;->
> read the dox.
> write progs.
> -jö
Or much better read the book: "The Cathedral & The Bazaar" by Eric S. Raymond.
He will teach you how to "hack"
Bye walter

-- 
W.W. van den Broek	e-mail:		vandenbroek@psyd.azr.nl
AZR-Dijkzigt		fax:		010-4633217
afdeling psychiatrie	tel:		010-4639222
Postbus 2040		e-mail		vdbroekw@wxs.nl (thuis)
3000 CA Rotterdam	homepage:	http://home.planet.nl/~vdbroekw


From arcege@shore.net  Sat Feb 17 13:05:06 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Sat, 17 Feb 2001 08:05:06 -0500 (EST)
Subject: [Tutor] Turning some Tkinter stuff into classes
In-Reply-To: <3A8E64B8.E1183007@yahoo.co.uk> from "Martyn Quick" at Feb 17, 2001 11:47:04 AM
Message-ID: <200102171305.IAA01125@northshore.shore.net>

> 
> I have the following code which *seems* to work ok:
> 
> --------------------------------
> from Tkinter import *
> 
> class Popup:
>         def __init__(self,master):
>                 self.win = Toplevel(master)
> 
> def popup():
>         newwin = Popup(root)
> 
> class PopupButton:
>         def __init(self,master):
>                 self.button = Button(master,text="New!",command=popup)
>                 self.button.pack()
> 
> root = Tk()
> button = PopupButton(root)
> 
> root.mainloop()
> --------------------------------
> 
> The problem is that the definition of "popup" is stylistically horrible
> (I think - I'm still rather new to Object Oriented Programming) since it
> has to refer to the fixed object root, but I'm using it within the class
> PopupButton, so could theoretically create another object with no
> reference to root using this class.  My attempt to create a better
> definition inside the class definition was as follows:
> 
> ---------------------------
> from Tkinter import *
> 
> class Popup:
>         def __init__(self,master):
>                 self.win = Toplevel(master)
> 
> class PopupButton:
>         def __init__(self,master):
>                 self.button=Button(master,text="New!",command=self.popup(master))
>                 self.button.pack()
> 
>         def popup(self,master):
>                 self.newwin = Popup(master)
> 
> root = Tk()
> button = PopupButton(root)
> 
> root.mainloop()
> ----------------------------------------
> 
> Of course, the above didn't work - I got the new popup window
> immediately and the button didn't do anything.  Other attempts to do a
> similar thing (deleting the master reference in the various bits of the
> popup command) produced syntax errors.
> 
> Any suggestions to correct what it is wrong in my second attempt?

Hi there,

You are calling a function when the Button is created, not passing
which function to call at a later point.

class PopupButton:
        def __init__(self,master):
                # store the master widget for the popup
                self.master = master
                # pass the method
                self.button=Button(master,text="New!",command=self.popup)
                self.button.pack()

        # pass only the class instance, self
        def popup(self):
                # get master from the member stored in __init__
                self.newwin = Popup(self.master)

Good luck,
  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From lumbricus@gmx.net  Sat Feb 17 16:20:07 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Sat, 17 Feb 2001 17:20:07 +0100 (MET)
Subject: [Tutor] reading stdin?
References: <20010216133000.A3862@harmony.cs.rit.edu>
Message-ID: <862.982426807@www27.gmx.net>

> On Fri, Feb 16, 2001 at 01:17:32PM -0500, Mr 804 wrote:
> | 
> | how do I read stdin?
> | 
> 
> >>> data = raw_input( "Please give me some data: " )
> Please give me some data: Hello World
> >>> type( data )
> <type 'string'>
> >>> print data
> Hello World
> >>>
> 
> 
> raw_input is good if you want random stuff or text stuff,
> if you want other stuff, input can be helpful
> 
> >>> data = input( "Enter some data: " )
> Enter some data: 2
> >>> type( data )
> <type 'int'>
> >>> print data
> 2
> >>>
> 
> 
> However, be careful how you use input() :
> 
> >>> data = input( "Enter some data: " )
> Enter some data: foo
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<string>", line 0, in ?
> NameError: There is no variable named 'foo'
> >>>
> 
> >>> i = 2
> >>> data = input( "Enter some data: " )
> Enter some data: lambda x : x + i
> >>> type( data )
> <type 'function'>
> >>> print data
> <function <lambda> at 007A8574>
> >>> print data( 3 )
> 5
> >>>
> 
> 
> input won't always do what you want, if the user inputs bad stuff.
> You can use raw_input, then convert the string how you want to.  Ex:
> 
> >>> try :
> ...     data = int( raw_input( "Enter a number: " ) )
> ... except ValueError , err :
> ...     print "You didn't enter a valid number"
> ...

excuse me if that's a silly question:
why not just
try:
     data = input("Enter number: ")
except:
     "wrong"

which would trap all errors?

greets jö!

> 
> 
> If you have more questions, just ask.
> 
> HTH,
> -D
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Sent through GMX FreeMail - http://www.gmx.net


From dsh8290@rit.edu  Sat Feb 17 16:37:10 2001
From: dsh8290@rit.edu (D-Man)
Date: Sat, 17 Feb 2001 11:37:10 -0500
Subject: [Tutor] reading stdin?
In-Reply-To: <862.982426807@www27.gmx.net>; from lumbricus@gmx.net on Sat, Feb 17, 2001 at 05:20:07PM +0100
References: <20010216133000.A3862@harmony.cs.rit.edu> <862.982426807@www27.gmx.net>
Message-ID: <20010217113710.A8457@harmony.cs.rit.edu>

On Sat, Feb 17, 2001 at 05:20:07PM +0100, J=F6rg W=F6lke wrote:
[snip]
| > >>> try :
| > ...     data =3D int( raw_input( "Enter a number: " ) )
| > ... except ValueError , err :
| > ...     print "You didn't enter a valid number"
| > ...
|=20
| excuse me if that's a silly question:
| why not just

It's a perfectly good question.

| try:
|      data =3D input("Enter number: ")
| except:
|      "wrong"
|=20
| which would trap all errors?

This is exactly why you don't want to use a universal except clause --
do you really want to catch KeyBoardError, OutOfMemoryError,
SystemExit and ComputerExplodingError?  Using a universal except will
work if you never get one of these kind of errors, but if you do get
one, the program won't behave as expected.  It is generally good to be
as explicit as you can in what exceptions you want to catch and
handle.  I didn't do it here, but in an earlier post (see archives) I
used the exception to tell the user what exactly they entered that
wasn't a valid number.  By explicitly catching certain exceptions, you
can use their data to improve the error handling.

-D



From DOUGS@oceanic.com  Sat Feb 17 17:43:27 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Sat, 17 Feb 2001 07:43:27 -1000
Subject: [Tutor] reading stdin?
Message-ID: <8457258D741DD411BD3D0050DA62365907A624@huina.oceanic.com>

[D-Man wrote:]
> On Sat, Feb 17, 2001 at 05:20:07PM +0100, J=F6rg W=F6lke wrote:
> [snip]
> | > >>> try :
> | > ...     data =3D int( raw_input( "Enter a number: " ) )
> | > ... except ValueError , err :
> | > ...     print "You didn't enter a valid number"
> | > ...
> |=20
> | excuse me if that's a silly question:
> | why not just
>=20
> It's a perfectly good question.
>=20
> | try:
> |      data =3D input("Enter number: ")
> | except:
> |      "wrong"
> |=20
> | which would trap all errors?
>=20
> This is exactly why you don't want to use a universal except clause =
--
> do you really want to catch KeyBoardError, OutOfMemoryError,
> SystemExit and ComputerExplodingError?  Using a universal except will
> work if you never get one of these kind of errors, but if you do get
> one, the program won't behave as expected.  It is generally good to =
be
> as explicit as you can in what exceptions you want to catch and
> handle.  I didn't do it here, but in an earlier post (see archives) I
> used the exception to tell the user what exactly they entered that
> wasn't a valid number.  By explicitly catching certain exceptions, =
you
> can use their data to improve the error handling.

In addition, please note the difference between 'raw_input' and =
'input'.
The use of 'input' is generally unsafe.  Using 'raw_input' is almost =
always
what you want in this scenario of getting data from a user.

-Doug-


From dyoo@hkn.eecs.berkeley.edu  Sun Feb 18 00:34:33 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 17 Feb 2001 16:34:33 -0800 (PST)
Subject: [Tutor] reading stdin?
In-Reply-To: <8457258D741DD411BD3D0050DA62365907A624@huina.oceanic.com>
Message-ID: <Pine.LNX.4.21.0102171624080.720-100000@c82114-a.pinol1.sfba.home.com>

On Sat, 17 Feb 2001, Doug Stanfield wrote:

> > | > ...     data = int( raw_input( "Enter a number: " ) )

> > | why not just

> > |      data = input("Enter number: ")

> In addition, please note the difference between 'raw_input' and
> 'input'. The use of 'input' is generally unsafe.  Using 'raw_input' is
> almost always what you want in this scenario of getting data from a
> user.

Clarification on what it means to be unsafe: sometimes, when we write
programs, we need to imagine a "worst case" scenario.  (Not that our users
are malevolant, but it's quite possible for them to make typing mistakes).  
For example, with the following program:

###
try:
   myint = input("Enter a number: ")
except:
   print "Error!"
###

What happens when the user enters this at our prompt? :

   open('really-important-file-would-be-clobbered-muhahaha', 'w')

This is evil, but it works.  *grin*

input() is really powerful... sometimes TOO powerful.  input() will accept
any Python expression, and this includes the file-opening functions.

Hope this helps!



From britt_green@hotmail.com  Sun Feb 18 01:37:10 2001
From: britt_green@hotmail.com (Britt Green)
Date: Sat, 17 Feb 2001 17:37:10 -0800
Subject: [Tutor] A Better Way to Write This?
Message-ID: <F269UpU7hUF6WhZB7IC0001068d@hotmail.com>

Hello all,

I have a tiny program that asks a user to enter a color choice. There are 
four valid choices for the user to enter. I have a function that checks to 
see if the user entered one of the valid choices. A snippet from it looks 
like this:

    if choice == ("black") or choice == ("white") or choice == ("green") or 
choice == ("blue"):
        return 1
    else:
        return 0

While this works, it seems ugly. What would happen, for example, if there 
were ten or twenty correct colors?

So I'm wondering if there is a better way to write this?

Thanks,

Britt

--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From gko@gko.net  Sun Feb 18 01:57:51 2001
From: gko@gko.net (Georges Ko)
Date: 18 Feb 2001 09:57:51 +0800
Subject: [Tutor] A Better Way to Write This?
In-Reply-To: <F269UpU7hUF6WhZB7IC0001068d@hotmail.com>
References: <F269UpU7hUF6WhZB7IC0001068d@hotmail.com>
Message-ID: <m3r90wlpls.fsf@symbiose.dnsalias.net>

"Britt Green" <britt_green@hotmail.com> wrote: 

>     if choice == ("black") or choice == ("white") or choice ==
> ("green") or choice == ("blue"):
>         return 1
>     else:
>         return 0
> 
> While this works, it seems ugly. What would happen, for example, if
> there were ten or twenty correct colors?
> 
> So I'm wondering if there is a better way to write this?

    Use:

    return choice in ['black', 'white', 'green', 'blue']

    instead.

    Because this list may be used somewhere else, it would be better
    to put it in a variable so that when you add a color, you won't
    have to mess with parts of the code that use it.

    acceptable_colors = ['black', 'white', 'green', 'blue']

    .
    .
    .

    return choice in acceptable_colors
-- 
 Georges Ko (Taipei, Taiwan)      2001-02-18      gko@gko.net / ICQ: 8719684


From tim.one@home.com  Sun Feb 18 03:18:51 2001
From: tim.one@home.com (Tim Peters)
Date: Sat, 17 Feb 2001 22:18:51 -0500
Subject: [Tutor] A Better Way to Write This?
In-Reply-To: <F269UpU7hUF6WhZB7IC0001068d@hotmail.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCIEBOJAAA.tim.one@home.com>

[Britt Green]
> I have a tiny program that asks a user to enter a color choice. There are
> four valid choices for the user to enter. I have a function that
> checks to  see if the user entered one of the valid choices. A snippet
> from it looks like this:
>
>     if choice == ("black") or choice == ("white") or \
>        choice == ("green") or choice == ("blue"):
>         return 1
>     else:
>         return 0
>
> While this works, it seems ugly.

Here are two easy steps:

1. The parentheses aren't needed, so:

     if choice == "black" or choice == "white" or \
        choice == "green" or choice == "blue":
         return 1
     else:
         return 0

2. What value does choice == "black" yield?  Well, 1 if it's black, 0 if
it's not.  Same for the rest of them.  So this does the same thing:

    return choice == "black" or choice == "white" or \
           choice == "green" or choice == "blue"

That is, the if/else isn't needed either.

> What would happen, for example, if there were ten or twenty
> correct colors?

It would get *very* ugly <wink>.  And what if there were hundreds?
Thousands?

> So I'm wondering if there is a better way to write this?

There are three ways you're more likely to see this written, two using lists
or tuples, and one using dicts.

1.

_VALID_COLORS = ["black", "white", "green", "blue"]

def is_valid_color(choice):
    for valid in _VALID_COLORS:
        if choice == valid:
            return 1
    return 0

This scales to any number of colors, of course.  If there are many of them,
it's helpful to sort the list of colors, most popular color first.  That way
you'll usually get out of the loop more quickly.

2. Actually the same as #1:

def is_valid_color(choice):
    return choice in _VALID_COLORS

People who come to Python from languages like C are likely to use #1, not
realizing that Python has the higher-level "in" operator that searches over
a list (or tuple, or any other sequence) for them.  #2 is easy to recommend,
but you can do a lot better in *speed* if there are thousands, or hundreds
of thousands(! it can happen) of "good" choices.  Like so:

3.

_VALID_COLOR_DICT = {}
for choice in _VALID_COLORS:
    _VALID_COLOR_DICT[choice] = 1  # value irrelevant

def is_valid_color(choice):
    return _VALID_COLOR_DICT.has_key(choice)

Unlike searching for something in a list, dict lookup goes very fast even if
the number of good choices is huge.  dicts are way cool.  But they take a
little more effort to set up.

Just for fun, here's a reasonably quick method you'll almost never see
<wink> (note that this uses string methods, which were new in Python 2.0):

4.

_VALID_COLORS = " black white green blue "

def is_valid_color(choice):
   return _VALID_COLORS.find(" " + choice + " ") >= 0

So, lots of choices.  If you want to learn only one, learn #3, because it
remains quick and just as easy no matter how large the set of choices grows.



From bxuef@freemail.sx.cn  Sun Feb 18 13:54:50 2001
From: bxuef@freemail.sx.cn (bxuef@freemail.sx.cn)
Date: Sun, 18 Feb 2001 21:54:50 +0800 (CST)
Subject: [Tutor] not a good tutorial, in my view
Message-ID: <Kj989781784549.08861@freemail>

Hi, everyone,

It appears the Python 2.0 tutorial are not written for beginners without  programming background.

The language is claimed to be a desktop program for everyone but the tutorial is already hard to read.

I am currently learning Python through the tutorial but I think it just neglected the programming level of the general readship.

There are several questions that I hope to seek answer from the veterans of Python programming:


1. I typed:

>>>"doesn\t"
# and it produced the following result:
>>>'doesn\011'
>>> 'yes\'he said'
"yes'he said"
>>>>>> "\"yes,\" he said"
'"yes," he said'
what is the use of this slash? 

2. What is the use of 'strip' here?
>>> string.strip('str') + 'ing'
'string'
and why this does not work:
>>> string.strip('str') 'ing'
SyntaxError: invalid syntax
It is explained in the tutorial, but I can not understand.

3. In the tutorial 3.1.3. Why there is the unicode part. what's the use of unicode in programming?

I input this but why it did not produce the desired result?
>>> u'Hello\\u0020World !'
u'Hello\\u0020World !'

The desired result should be
>>>u'Hello World !'

Under what conditions will the Interpreter shows the second prompt(...)? In the turtorial, it reads "for continuation lines it prompts with the second prompt...".

I am a little frustrated by the tutorial, can anyone show me some links to the easier tutorial (for instance, Alan's)? Or hopefuly there will be a beginner's version of the tutorial.

Thank you very much!

Best wishes.
-------bxuef

-----------------------------------------------------------
»¶Ó­Ê¹ÓÃɽÎ÷µçÐÅÃâ·Ñµç×ÓÓʼþϵͳ <http://freemail.sx.cn> ¡£
ÈçÓÐÎÊÌ⣬ÇëÓë webmaster@freemail.sx.cn <mailto:webmaster@freemail.sx.cn> ÁªÏµ¡£
ллÄúµÄʹÓã¡



From scarblac@pino.selwerd.nl  Sun Feb 18 14:30:18 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 18 Feb 2001 15:30:18 +0100
Subject: [Tutor] not a good tutorial, in my view
In-Reply-To: <Kj989781784549.08861@freemail>; from bxuef@freemail.sx.cn on Sun, Feb 18, 2001 at 09:54:50PM +0800
References: <Kj989781784549.08861@freemail>
Message-ID: <20010218153018.A4193@pino.selwerd.nl>

On Sun, Feb 18, 2001 at 09:54:50PM +0800, bxuef@freemail.sx.cn wrote:
> It appears the Python 2.0 tutorial are not written for beginners without
> programming background.

I agree. Try Alan Gauld's webpage instead, at
http://www.crosswinds.net/~agauld (there are a few others, on www.python.org
go to Documentation, then look for "Introductions", and "Introductions for
non-programmers").


> 1. I typed:

If you write down a string, the \ is used to "escape" things. For instance,
if a string is enclosed between " ", you need a way to have a " inside the
string - you write it \".

Similarly, there are some special characters that you can't simply write down.
A newline is spelled as \n, a tab is spelled \t. \011 is the same thing as \t,
in another representation.

> >>>"doesn\t"
> # and it produced the following result:
> >>>'doesn\011'

See above. The \t you typed shows as \011 in the interpreter's representation.
The string is "doesn" followed by a tab character.

> >>> 'yes\'he said'
> "yes'he said"
> >>>>>> "\"yes,\" he said"
> '"yes," he said'
> what is the use of this slash? 

If you don't use the slash, Python thinks the ' means the end of the string.
Same for " in the second example.

> 2. What is the use of 'strip' here?
> >>> string.strip('str') + 'ing'
> 'string'

string.strip removes whitespace from the begin and end of a string.

Try this alternative:
>>> string.strip("       str     \n")+'ing'

(the \n is a newline, it also counts as whitespace)

> and why this does not work:
> >>> string.strip('str') 'ing'
> SyntaxError: invalid syntax
> It is explained in the tutorial, but I can not understand.

You have first a call to a function (string.strip) and then a string
('ing'). Python doesn't know what to do with that, this is not what Python
looks like. If you want to add them together, you can do so with +.

> 3. In the tutorial 3.1.3. Why there is the unicode part. 
> what's the use of unicode in programming?

Standard ASCII has only 127 different characters. That is not enough to
represent text in all the world's languages, by far. Unicode is newer, and
it has over 60,000 different codes. But moving programs like Python to
Unicode is a slow and complicated process, and I propose you ignore it
totally for now.

> I input this but why it did not produce the desired result?
> >>> u'Hello\\u0020World !'
> u'Hello\\u0020World !'

One backslash too many. \\ inside a string means simply \.

> The desired result should be
> >>>u'Hello World !'
 
> Under what conditions will the Interpreter shows the second prompt(...)?
> In the turtorial, it reads "for continuation lines it prompts with the 
> second prompt...".

If the command you started to enter isn't done yet. For instance, when you
still have a ( open without an ), or when you're writing a block of code, 
for instance after an if: statement:

>>> if 2 > 1:
...    print "whee"
...

It writes ... because you can still enter lines that belong to the 'if'
statement.

> I am a little frustrated by the tutorial, can anyone show me some links to
> the easier tutorial (for instance, Alan's)? Or hopefuly there will be a
> beginner's version of the tutorial.

See above.

-- 
Remco Gerlich


From tim@johnsons-web.com  Sun Feb 18 18:09:45 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 18 Feb 2001 09:09:45 -0900
Subject: [Tutor] not a good tutorial, in my view
References: <20010218153018.A4193@pino.selwerd.nl>
Message-ID: <01021809113504.02173@shecom>

Hello
On Sun, 18 Feb 2001, you wrote:

> I agree. Try Alan Gauld's webpage instead, at
> http://www.crosswinds.net/~agauld (there are a few others, on www.python.org
> go to Documentation, then look for "Introductions", and "Introductions for
> non-programmers").
I'll add a ditto to that. I just got his good bood also, and it is great. I'm
modeling a class on Python programming around it

 --
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From rha2077@netzero.net  Sun Feb 18 20:33:27 2001
From: rha2077@netzero.net (Ron)
Date: Sun, 18 Feb 2001 15:33:27 -0500
Subject: [Tutor] not a good tutorail
Message-ID: <000701c099ea$0e5c4960$80c545d1@computer>

This is a multi-part message in MIME format.

------=_NextPart_000_0004_01C099C0.23B970A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm working my way through HOW TO THINK LIKE A COMPUTER SCIENTIST and I =
think it's pretty good. I haven't found one tutorial that I'm completely =
happy with, but then I'm a newbie and have a lot to learn.

Oh, here's the link if you want to take a look.

http://www.ibiblio.org/obp/thinkCSpy/

------=_NextPart_000_0004_01C099C0.23B970A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Dwindows-1252" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>I'm working my way through HOW TO THINK LIKE A =
COMPUTER=20
SCIENTIST and I think it's pretty good. I haven't found one tutorial =
that I'm=20
completely happy with, but then I'm a newbie and have a lot to=20
learn.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Oh, here's the link if you want to take a =
look.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2><A=20
href=3D"http://www.ibiblio.org/obp/thinkCSpy/">http://www.ibiblio.org/obp=
/thinkCSpy/</A></FONT></DIV></BODY></HTML>

------=_NextPart_000_0004_01C099C0.23B970A0--


Shop online without a credit card
http://www.rocketcash.com
RocketCash, a NetZero subsidiary


From tim@johnsons-web.com  Sun Feb 18 23:18:34 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 18 Feb 2001 14:18:34 -0900
Subject: [Tutor] Python Access to Computer speaker
References: <000701c099ea$0e5c4960$80c545d1@computer>
Message-ID: <01021814195505.02173@shecom>

Hi :
	Does Python have a function to access for the computer
speaker for frequency and duration?
.....like the the "C" sound() function.
TIA
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From kalle@gnupung.net  Mon Feb 19 00:13:10 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 19 Feb 2001 01:13:10 +0100
Subject: [Tutor] Python Access to Computer speaker
In-Reply-To: <01021814195505.02173@shecom>; from tim@johnsons-web.com on Sun, Feb 18, 2001 at 02:18:34PM -0900
References: <000701c099ea$0e5c4960$80c545d1@computer> <01021814195505.02173@shecom>
Message-ID: <20010219011310.A2379@apone.network.loc>

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Tim Johnson:
> Hi :
> 	Does Python have a function to access for the computer
> speaker for frequency and duration?

No, not generally.  On Windows NT, there is winsound.Beep(), but there is no
support on other platforms.  On GNU/Linux, you could use the 'beep' program
by Johnathan Nightingale: http://www.johnath.com/beep/.  You'll have to use
it through os.system, or wrap it in a python module.

> .....like the the "C" sound() function.

What library?  Platform?  Just curious.

Peace,
  Kalle (from Sweden)
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--PEIAKu/WMn1b1Hv9
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6kGUWdNeA1787sd0RAkSiAJ9BYHLigWErMjQ+ktr2jQ71JbnCrACgiEDk
UNocLZDVLv9o/8b4u0bmv48=
=PDqM
-----END PGP SIGNATURE-----

--PEIAKu/WMn1b1Hv9--


From dyoo@hkn.eecs.berkeley.edu  Mon Feb 19 00:19:08 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 18 Feb 2001 16:19:08 -0800 (PST)
Subject: [Tutor] not a good tutorial, in my view
In-Reply-To: <Kj989781784549.08861@freemail>
Message-ID: <Pine.LNX.4.21.0102181556040.1126-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 18 Feb 2001 bxuef@freemail.sx.cn wrote:

> It appears the Python 2.0 tutorial are not written for beginners
> without programming background.

In one sense, the tutorial's is a "good" one because it is specifically
tailored for people who have previous programming experience.  For those
who haven't programmed before though, it stinks.  *grin*

Take a look at the Introductions section of python.org: it has tutorials
that are targeted toward newcomers:

    http://python.org/doc/Intros.html


> 1. I typed:
> 
> >>>"doesn\t"
> # and it produced the following result:
> >>>'doesn\011'
> >>> 'yes\'he said'
> "yes'he said"
> >>>>>> "\"yes,\" he said"
> '"yes," he said'
> what is the use of this slash? 

Let's see what happens when we don't put the slash.

###
>>> ""yes, " he said"
  File "<stdin>", line 1
    ""yes, " he said"
        ^
SyntaxError: invalid syntax
###

Strings in Python are surrounded by pairs of quotation marks.  For
example:

    "hello world"
    "how to solve it"
    "harry potter"

The tricky part is when we want to put quotation marks within a
string.  When we tried:

   ""yes", he said"

we wanted Python to understand that we wanted quotes around
"yes".  However, here's that Python sees, piece by piece:

   "    : Ok, we have an opening quote, so I'm reading a string.

   "    : There's the closing quote.  We must mean the empty string.

   yes  : What does yes mean?  It's outside quotes, and I don't 
          know what to do!


And that's the problem; how can we put quotes within a string?  The
solution that Python chooses is to make a character that's special;
whenever Python sees it during string reading, it'll escape out of it's
regular set of rules.  For example, when we feed it:

    "\""

here's what Python's thinking:

    "  : ok, opening quote mark
    \  : Oh!  This is an escape character.  That means I should do
         something special to the next thing I see.
    "  : Ah, ok, so I won't close off the string yet.  I'll just add
         the literal quote character to our string.  Let's go back
         to our normal set of rules.
    "  : Closing quote

and we end up with the string that contains one quotation mark.


> 2. What is the use of 'strip' here?
> >>> string.strip('str') + 'ing'
> 'string'
> and why this does not work:
> >>> string.strip('str') 'ing'
> SyntaxError: invalid syntax
> It is explained in the tutorial, but I can not understand.

Ah.  Really subtle point; you don't need to worry about this for a while.  
This is what they mean:  Whenever we put two strings together like this:

###
>>> "this is" "two literal strings"
'this istwo literal strings'
###

Python can see that both are obviously strings, so it'll put them together
automatically.  However, when we do:

###
>>> string.strip('str') 'ing'
  File "<stdin>", line 1
    string.strip('str') 'ing'
                            ^
SyntaxError: invalid syntax
###

The idea is that Python has no clue if string.strip() will return a string
or not, so it'll go bonkers again.  What we need to do is convince Python
that we really want it to put strings together:

###
>>> string.strip('str') + 'ing'
'string'
###

Adding a '+' in the middle of those two tells Python to try adding the
result of string.strip() with 'ing', in any way possible.



> 3. In the tutorial 3.1.3. Why there is the unicode part. what's the
> use of unicode in programming?

Unicode's important for people who plan to write multilingual programs;
that is, programs that need to deal with more than english text.  Since
the tutorials tailored to professional programmers, that's why it talks
about this issue.

To tell the truth, I don't know Unicode either.  *grin*


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Mon Feb 19 00:25:12 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 18 Feb 2001 16:25:12 -0800 (PST)
Subject: [Tutor] Python Access to Computer speaker
In-Reply-To: <01021814195505.02173@shecom>
Message-ID: <Pine.LNX.4.21.0102181622580.1312-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 18 Feb 2001, Tim Johnson wrote:

> 	Does Python have a function to access for the computer
> speaker for frequency and duration?
> .....like the the "C" sound() function.

I'll assume that you're working on a Windows system for the moment.  
There's a module called winsound that'll let you do this:

    http://www.python.org/doc/current/lib/module-winsound.html

In it, there's a function called Beep(), and it does take in frequency and
duration.  However, I have to admit that I have no experience with it.  
Perhaps someone else on tutor's played around with it?

Good luck!



From kalle@gnupung.net  Mon Feb 19 01:16:46 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 19 Feb 2001 02:16:46 +0100
Subject: [Tutor] Python Access to Computer speaker
In-Reply-To: <Pine.LNX.4.21.0102181622580.1312-100000@c82114-a.pinol1.sfba.home.com>; from dyoo@hkn.eecs.berkeley.edu on Sun, Feb 18, 2001 at 04:25:12PM -0800
References: <01021814195505.02173@shecom> <Pine.LNX.4.21.0102181622580.1312-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <20010219021646.C2379@apone.network.loc>

--dkEUBIird37B8yKS
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Danny Yoo:
> On Sun, 18 Feb 2001, Tim Johnson wrote:
>=20
> > 	Does Python have a function to access for the computer
> > speaker for frequency and duration?
> > .....like the the "C" sound() function.
>=20
> I'll assume that you're working on a Windows system for the moment. =20
> There's a module called winsound that'll let you do this:
>=20
>     http://www.python.org/doc/current/lib/module-winsound.html
>=20
> In it, there's a function called Beep(), and it does take in frequency and
> duration.  However, I have to admit that I have no experience with it. =
=20
> Perhaps someone else on tutor's played around with it?

I haven't used it myself, but from reading comp.lang.python I have learned
that this doesn't work as advertised on Win95/98/ME systems.  On those
systems, it plays the windows bell sound, regardless of the parameters.

Peace,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--dkEUBIird37B8yKS
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6kHP+dNeA1787sd0RAg/ZAKCn9WmLWNZmO/CmVZ7z5xiPEEC35wCghXXA
LCq8wW7dlht3xnt1tia3XdA=
=C1I6
-----END PGP SIGNATURE-----

--dkEUBIird37B8yKS--


From tim.one@home.com  Mon Feb 19 02:06:38 2001
From: tim.one@home.com (Tim Peters)
Date: Sun, 18 Feb 2001 21:06:38 -0500
Subject: [Tutor] Python Access to Computer speaker
In-Reply-To: <Pine.LNX.4.21.0102181622580.1312-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCMEENJAAA.tim.one@home.com>

[Tim Johnson]
> 	Does Python have a function to access for the computer
> speaker for frequency and duration?
> .....like the the "C" sound() function.

[Danny Yoo]
> I'll assume that you're working on a Windows system for the moment.
> There's a module called winsound that'll let you do this:
>
>     http://www.python.org/doc/current/lib/module-winsound.html
>
> In it, there's a function called Beep(), and it does take in frequency
> and duration.

This is a case where you really need to use the development docs:

    http://python.sourceforge.net/devel-docs/lib/module-winsound.html

They point out that-- alas --Beep()'s arguments are ignored except under
Windows NT and 2000.  Under 95 and 98, Windows doesn't supply anything "that
works".  Unsure about Windows ME.

Note that standard C doesn't have a "sound" function -- that must be
specific to some particular vendor-extended C you used.

no-good-news-here!-ly y'rs  - tim



From sandy@mnic.net  Mon Feb 19 06:49:58 2001
From: sandy@mnic.net (Sandy Oppegard)
Date: Mon, 19 Feb 2001 00:49:58 -0600
Subject: [Tutor] sign me up!
Message-ID: <000a01c09a40$30a862a0$0100007f@ic.mankato.mn.us>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C09A0D.E24B1E40
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable



------=_NextPart_000_0007_01C09A0D.E24B1E40
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0007_01C09A0D.E24B1E40--



From tim.one@home.com  Mon Feb 19 07:21:06 2001
From: tim.one@home.com (Tim Peters)
Date: Mon, 19 Feb 2001 02:21:06 -0500
Subject: [Tutor] Python Access to Computer speaker
In-Reply-To: <LNBBLJKPBEHFEDALKOLCMEENJAAA.tim.one@home.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCKEFGJAAA.tim.one@home.com>

[Tim (this Tim -- that's me) bemoaned]
> This is a case where you really need to use the development docs:
>
>     http://python.sourceforge.net/devel-docs/lib/module-winsound.html
>
> They point out that-- alas --Beep()'s arguments are ignored except under
> Windows NT and 2000.  Under 95 and 98, Windows doesn't supply
> anything "that works".  Unsure about Windows ME.
>
> ...
>
> no-good-news-here!-ly y'rs  - tim

OK, I confess I got really irritated with this.  What good is having a
computer if you can't play stupid one-voice tunes on it laboriously poking
each note in by hand <wink>?  So I added Win9X support for winsound.Beep(),
and that will be released in Python 2.1.

Here's the heart of the Win9X code.  This is educational, because it
demonstrates why you want to stick with coding in Python just as long as you
can <snarl>:

static PyObject *
sound_beep(PyObject *self, PyObject *args)
{
	int freq;
	int dur;

	if (!PyArg_ParseTuple(args, "ii:Beep", &freq,  &dur))
		return NULL;

	if (freq < 37 || freq > 32767) {
		PyErr_SetString(PyExc_ValueError,
				"frequency must be in 37 thru 32767");
		return NULL;
	}

	/* On NT and 2000, the SDK Beep() function does the whole job.
	 * But while Beep() exists before NT, it ignores its arguments and
	 * plays the system default sound.  Sheesh ...
	 * The Win9X code is mondo bizarre.  I (Tim) pieced it together from
	 * crap all over the web.  The original IBM PC used some particular
	 * pieces of hardware (Intel 8255 and 8254 chips) hardwired to
	 * particular port addresses and running at particular clock speeds,
	 * and the poor sound card folks have been forced to emulate that in
	 * all particulars ever since.  But NT and 2000 don't support port
	 * manipulation,   Don't know about WinME; guessing it's like 98.
	 */

	if (whichOS == WinNT2000) {
		BOOL ok;
		Py_BEGIN_ALLOW_THREADS
		ok = Beep(freq, dur);
		Py_END_ALLOW_THREADS
		if (!ok) {
			PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
			return NULL;
		}
	}
	else if (whichOS == Win9X) {
		int speaker_state;
		/* Force timer into oscillator mode via timer control port. */
		_outp(0x43, 0xb6);
		/* Compute ratio of ancient hardcoded timer frequency to
		 * frequency we want.  Then feed that ratio (lowest byte
		 * first) into timer data port.
		 */
		freq = 1193180 / freq;
		_outp(0x42, freq & 0xff);
		_outp(0x42, (freq >> 8) & 0xff);
		/* Get speaker control state. */
		speaker_state = _inp(0x61);
		/* Turn the speaker on (bit 1)
		 * and drive speaker from timer (bit 0).
		 */
		_outp(0x61, speaker_state | 0x3);
		/* Let it blast in peace for the duration. */
		Py_BEGIN_ALLOW_THREADS
		Sleep(dur);
		Py_END_ALLOW_THREADS
		/* Restore speaker control to original state. */
		_outp(0x61, speaker_state);
	}
	else {
		assert(!"winsound's whichOS has insane value");
	}
	Py_INCREF(Py_None);
	return Py_None;
}

you-can-like-python-as-a-first-language-but-you-won't-truly-love-
    it-until-you've-suffered-with-everything-else-ly y'rs  - tim



From abreu@penguinpowered.com  Mon Feb 19 16:39:11 2001
From: abreu@penguinpowered.com (Jose Alberto Abreu)
Date: Mon, 19 Feb 2001 10:39:11 -0600
Subject: [Tutor] Has anyone tried PMZ
Message-ID: <3A914C2F.85F95CEB@penguinpowered.com>

I found the "Poor Man's Zope" proyect in sourceforge, and it looks like
something I would like to try...

http://pmz.sourceforge.net/

Looks easy to learn and powerful, but has anyone tried it yet?

Any comments?




Thanks in advance to the List Moms for their infinite wisdom...


From alan.gauld@bt.com  Mon Feb 19 17:43:37 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 19 Feb 2001 17:43:37 -0000
Subject: [Tutor] Python Access to Computer speaker
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5A9@mbtlipnt02.btlabs.bt.co.uk>

> 	Does Python have a function to access for the computer
> speaker for frequency and duration?

Sound is a very platform specific thing.

> .....like the the "C" sound() function.

Not all C compilers have a sound() function.

Python provides several sound modules for different 
platforms. I think theres a winsound module that might 
do and I think there's a set of sound APIs in Mark
Hammond's winall wrapper of the MFC clsses.

Alan G. 


From dhhoward@hotmail.com  Mon Feb 19 20:10:37 2001
From: dhhoward@hotmail.com (Dan Howard)
Date: Mon, 19 Feb 2001 15:10:37 -0500
Subject: [Tutor] Serial Port Access - Help!!
References: <E14UtgV-0006xJ-00@mail.python.org>
Message-ID: <OE52AXbqXGe6xr9RAkW00009ac2@hotmail.com>

I've been quite excited about the power and ease of use of Pthon and have
been continuing my learning...
However I have a need to access a serial port ( I'm an avid Ham Radio nut
and would like to control my various radios using a Python set of routines).
I have found this to be a challenge that seems out of what I thought was a
design philosophy of Python - ie ease of learning and use.
I have yet to successfully get access to the serial port.
I've tried to use various 'downloads' referenced in the Python  books - but
no doubt due to my noice skills - I have not been successful in getting any
of them to work.  I'm trying this from a Windows 98 system.

I sure would welcome some advice as to an easy approach to using a serial
port

Thanks
Dan ( VA3MA)
>


From bobhicks@adelphia.net  Mon Feb 19 23:55:55 2001
From: bobhicks@adelphia.net (Robert L Hicks)
Date: Mon, 19 Feb 2001 18:55:55 -0500
Subject: [Tutor] PMZ
Message-ID: <E14V0AR-0007vy-00@mail.python.org>

I have *tried* it but unsuccessfully so far...I just need to tweak the =
pmz.py file to reflect my environment but I am kinda clueless on the =
paths that pmz.py wants.

A better place to post would be the newsgroup...

- Bob=


From tim@johnsons-web.com  Tue Feb 20 03:50:26 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Mon, 19 Feb 2001 18:50:26 -0900
Subject: [Tutor] Button, Button, How do I put the Button
References: <E14V0AR-0007vy-00@mail.python.org>
Message-ID: <01021918550700.01148@shecom>

Hello All:
Below is some code that is meant to hold two buttons and a text window.

<duh> I don't know quite how to place the buttons</duh>

Two Questions:
1)How do I place the buttons side by side, instead of one above the other?
2)Where is documentation relevant to my questions.
BTW: Thanks to all for all the input on my question on sound()
Code to follow
################################################################
from Tkinter import *
from ScrolledText import *
import sys

def die(event):
	sys.exit(0)
def test(event):
	pass
root = Tk()
text_frame = Frame(root)
text_frame.pack(expand=1,fill=BOTH)
# build the "quit" button
q_button = Button(text_frame,width=25)
q_button["text"] = "Quit"
q_button.bind("<Button>",die)
q_button.pack()
#build the "test" button
t_button = Button(text_frame,width=25)
t_button["text"] = "Test"
t_button.bind("<Button>",test)
t_button.pack()
#would like to put the buttons side by side, but how?
st = ScrolledText(text_frame ,background="white")
st.pack()

root.mainloop()
################################################################
TIA :)
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From arcege@shore.net  Tue Feb 20 13:19:50 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Tue, 20 Feb 2001 08:19:50 -0500 (EST)
Subject: [Tutor] Button, Button, How do I put the Button
In-Reply-To: <01021918550700.01148@shecom> from "Tim Johnson" at Feb 19, 2001 06:50:26 PM
Message-ID: <200102201319.IAA02535@northshore.shore.net>

> 
> Hello All:
> Below is some code that is meant to hold two buttons and a text window.
> 
> <duh> I don't know quite how to place the buttons</duh>
> 
> Two Questions:
> 1)How do I place the buttons side by side, instead of one above the other?
> 2)Where is documentation relevant to my questions.
> BTW: Thanks to all for all the input on my question on sound()
> Code to follow

You can make two simple changes to get what you want:
> ################################################################
> from Tkinter import *
> from ScrolledText import *
> import sys
> 
> def die(event):
>     sys.exit(0)
> def test(event):
>     pass
> root = Tk()
> text_frame = Frame(root)
> text_frame.pack(expand=1,fill=BOTH)
  text_frame.pack(expand=1,fill=BOTH,side=BOTTOM)

> # build the "quit" button
> q_button = Button(text_frame,width=25)
  q_button = Button(root,      width=25)

> q_button["text"] = "Quit"
> q_button.bind("<Button>",die)
> q_button.pack()
  q_button.pack(side=LEFT)

> #build the "test" button
> t_button = Button(text_frame,width=25)
  t_button = Button(root,      width=25)

> t_button["text"] = "Test"
> t_button.bind("<Button>",test)
> t_button.pack()
  t_button.pack(side=LEFT)

> #would like to put the buttons side by side, but how?
> st = ScrolledText(text_frame ,background="white")
> st.pack()
> 
> root.mainloop()
> ################################################################

The "trick" is the Frame.  Most newbies would probably look at the
Frame class as a useless widget, but its purpose is to organize your
widgets better using the various geometry managers (pack, grid,
place).

Here is an example of your code that will position the buttons above,
below, left or right of the text, depending on what the first program
argument is.

import sys
from Tkinter import *
from ScrolledText import *
root = Tk()
# where do we put the frame?
if sys.argv[1] == 'top':
  button_side=LEFT    # stack buttons left-right or top-bottom within frame
  where_bar = TOP     # buttons above scrolled text
elif sys.argv[1] == 'bottom':
  button_side=LEFT
  where_bar = BOTTOM  # buttons below scrolled text
elif sys.argv[1] == 'left':
  button_side=TOP
  where_bar = LEFT    # buttons left of scrolled text
elif sys.argv[1] == 'right':
  button_side=TOP
  where_bar = RIGHT   # buttons right of scrolled text
# create a frame for just the buttons
button_bar = Frame(root)
q_button = Button(button_bar, text="Quit", command=root.quit)
q_button.pack(side=button_side, expand=YES)
t_button = Button(button_bar, text="Test")
t_button.pack(side=button_side, expand=YES)
st = ScrolledText(root, background='white')
# we don't care where the scrolled text is, so place the buttons first
button_bar.pack(side=where_bar)
st.pack()
root.mainloop()

Notice that I pack the button bar before the ScrolledText, that I
don't create the text_frame widget (using the button_bar instead),
and that I put the buttons in the button_bar, but the scrolled text
widget is _not_ put in the same frame.

I'd suggest getting either a Tcl/Tk book, or John E. Grayson's "Python
and Tkinter programming" book.  There are Tkinter web documents that
have been published here recently and can be found through the
Python.org website.  And you might want to look at the files in the
Demo/tkinter/ directory in the distribution.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From wheelege@tsn.cc  Tue Feb 20 05:19:05 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 20 Feb 2001 16:19:05 +1100
Subject: [Tutor] Button, Button, How do I put the Button
References: <E14V0AR-0007vy-00@mail.python.org> <01021918550700.01148@shecom>
Message-ID: <002201c09afc$a55633e0$d5755cca@glen>

(note: I'm still what I classify as newbie to tkinter, so watch out for what
I say....could be wrong!)

  I think what you are looking for here is documentation of the various
geometry managers that Tkinter uses (from Tcl/Tk).
  These are Place, Grid and Pack.  The documentation I refer from is John
Graysons book 'Python and Tkinter Programmin' which I have found extremewly
useful.  However there is more documentation located on the web - most
probably linked from somewhere in www.python.org.

  HTH,
  Glen.

----- Original Message -----
From: Tim Johnson <tim@johnsons-web.com>
To: <tutor@python.org>
Sent: Tuesday, February 20, 2001 2:50 PM
Subject: [Tutor] Button, Button, How do I put the Button


> Hello All:
> Below is some code that is meant to hold two buttons and a text window.
>
> <duh> I don't know quite how to place the buttons</duh>
>
> Two Questions:
> 1)How do I place the buttons side by side, instead of one above the other?
> 2)Where is documentation relevant to my questions.
> BTW: Thanks to all for all the input on my question on sound()
> Code to follow
> ################################################################
> from Tkinter import *
> from ScrolledText import *
> import sys
>
> def die(event):
> sys.exit(0)
> def test(event):
> pass
> root = Tk()
> text_frame = Frame(root)
> text_frame.pack(expand=1,fill=BOTH)
> # build the "quit" button
> q_button = Button(text_frame,width=25)
> q_button["text"] = "Quit"
> q_button.bind("<Button>",die)
> q_button.pack()
> #build the "test" button
> t_button = Button(text_frame,width=25)
> t_button["text"] = "Test"
> t_button.bind("<Button>",test)
> t_button.pack()
> #would like to put the buttons side by side, but how?
> st = ScrolledText(text_frame ,background="white")
> st.pack()
>
> root.mainloop()
> ################################################################
> TIA :)
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From Desai.Dinakar@mayo.edu  Tue Feb 20 15:52:26 2001
From: Desai.Dinakar@mayo.edu (Dinakar Desai)
Date: Tue, 20 Feb 2001 09:52:26 -0600
Subject: [Tutor] request for  suggestions
References: <200102201319.IAA02535@northshore.shore.net>
Message-ID: <3A9292BA.36B7AEE0@mayo.edu>

This is a multi-part message in MIME format.
--------------34D2505EB73EBCDD3753B88B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Hello:

I am trying to learn python from scratch. I have been following this
mailing for sometime. I have learnt a lot from this group. I have been
reading about Tkinter and PyGTK+ and other GUI interface development
tools available for python. I use linux platform to learn python and
like to get my feet wet with GUI development. 

I come from powerbuilder and c++ background(i have not used C++ for GUI
development and not familiar with MFC class libraries). I would
appreciate, if you could suggest whether I should start learning Tkinter
or PyGTK+ or some other GUI tools.

I look forward to hear from you. 

Thank you.

Dinakar
--------------34D2505EB73EBCDD3753B88B
Content-Type: text/x-vcard; charset=us-ascii;
 name="desai.dinakar.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Dinakar Desai
Content-Disposition: attachment;
 filename="desai.dinakar.vcf"

begin:vcard 
n:Desai;Dinakar
tel;fax:507-284-0615
tel;home:507-289-3972
tel;work:507-266-2831
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:desai.dinakar@mayo.edu
fn:Dinakar
end:vcard

--------------34D2505EB73EBCDD3753B88B--



From tim@johnsons-web.com  Tue Feb 20 16:54:22 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Tue, 20 Feb 2001 07:54:22 -0900
Subject: [Tutor] Button, Button, How do I put the Button
References: <200102201319.IAA02535@northshore.shore.net>
Message-ID: <01022007553801.03075@shecom>

Thanks to all.... I got a wealth of info. :)
Cheers
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From bsass@freenet.edmonton.ab.ca  Tue Feb 20 20:21:01 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Tue, 20 Feb 2001 13:21:01 -0700 (MST)
Subject: [Tutor] request for  suggestions
In-Reply-To: <3A9292BA.36B7AEE0@mayo.edu>
Message-ID: <Pine.LNX.4.33.0102201306130.2082-100000@bms>

Hi,

On Tue, 20 Feb 2001, Dinakar Desai wrote:
> I am trying to learn python from scratch. I have been following this
> mailing for sometime. I have learnt a lot from this group. I have been
> reading about Tkinter and PyGTK+ and other GUI interface development
> tools available for python. I use linux platform to learn python and
> like to get my feet wet with GUI development.
>
> I come from powerbuilder and c++ background(i have not used C++ for GUI
> development and not familiar with MFC class libraries). I would
> appreciate, if you could suggest whether I should start learning Tkinter
> or PyGTK+ or some other GUI tools.

There is also PyQT, gratis and (more or less) liberated on unix
platforms.  http://www.thekompany.com/projects/pykde

The (inexperienced) impression I get when looking at Tkinter vs. PyQt
is that PyQt is to Tkinter what Python is to Perl.


- Bruce



From wheelege@tsn.cc  Tue Feb 20 21:23:19 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 21 Feb 2001 08:23:19 +1100
Subject: [Tutor] request for  suggestions
References: <200102201319.IAA02535@northshore.shore.net> <3A9292BA.36B7AEE0@mayo.edu>
Message-ID: <004201c09b83$59c556e0$dc755cca@glen>

  Hi,

  Well, what I would recommend is Tkinter - but I may be biased.  I hear
that PyGTK+ is actually very well suited to people with C, C++ backgrounds.
  I've been programming in Tkinter for a while now (6 months...still
semi-newbie :) and it is very nice.  As long as you get really object
oriented really fast, you should be fine.  However, there are some tricky
bits that you won't really get unless you have good documentation.  I'd
recommend searching around the python.org website or  buying a good book on
the subject.

  HTH,
  Glen.


----- Original Message -----
From: Dinakar Desai <Desai.Dinakar@mayo.edu>
To: <wheelege (rfc822 Compliance issue To: added by system POTENTIAL SPAM)>
Cc: <tutor@python.org>
Sent: Wednesday, February 21, 2001 2:52 AM
Subject: [Tutor] request for suggestions


>
> Hello:
>
> I am trying to learn python from scratch. I have been following this
> mailing for sometime. I have learnt a lot from this group. I have been
> reading about Tkinter and PyGTK+ and other GUI interface development
> tools available for python. I use linux platform to learn python and
> like to get my feet wet with GUI development.
>
> I come from powerbuilder and c++ background(i have not used C++ for GUI
> development and not familiar with MFC class libraries). I would
> appreciate, if you could suggest whether I should start learning Tkinter
> or PyGTK+ or some other GUI tools.
>
> I look forward to hear from you.
>
> Thank you.
>
> Dinakar



From charlie@webmind.com  Tue Feb 20 21:46:31 2001
From: charlie@webmind.com (Charlie Derr)
Date: Tue, 20 Feb 2001 16:46:31 -0500
Subject: [Tutor] request for  suggestions
In-Reply-To: <Pine.LNX.4.33.0102201306130.2082-100000@bms>
Message-ID: <NDBBLJJLLFOJMLCMJPLOEELFGMAA.charlie@webmind.com>

Bruce Sass wrote:
|
|Hi,
|
|On Tue, 20 Feb 2001, Dinakar Desai wrote:
|> I am trying to learn python from scratch. I have been following this
|> mailing for sometime. I have learnt a lot from this group. I have been
|> reading about Tkinter and PyGTK+ and other GUI interface development
|> tools available for python. I use linux platform to learn python and
|> like to get my feet wet with GUI development.
|>
|> I come from powerbuilder and c++ background(i have not used C++ for GUI
|> development and not familiar with MFC class libraries). I would
|> appreciate, if you could suggest whether I should start learning Tkinter
|> or PyGTK+ or some other GUI tools.
|
|There is also PyQT, gratis and (more or less) liberated on unix
|platforms.  http://www.thekompany.com/projects/pykde
|
|The (inexperienced) impression I get when looking at Tkinter vs. PyQt
|is that PyQt is to Tkinter what Python is to Perl.
|
|
|- Bruce
|

I think it's also worth pointing out wxPython.  The boa contructor project
provides a very nice tool for building with wxPython.  If you do try boa,
you should check out the CVS version, as the release version is
substantially behind current development.

http://wxpython.sourceforge.net
http://boa-constructor.sourceforge.net

	good luck,
			~c

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



From Desai.Dinakar@mayo.edu  Tue Feb 20 22:12:14 2001
From: Desai.Dinakar@mayo.edu (Dinakar Desai)
Date: Tue, 20 Feb 2001 16:12:14 -0600
Subject: [Tutor] request for  suggestions
References: <Pine.LNX.4.33.0102201306130.2082-100000@bms>
Message-ID: <3A92EBBE.1EADA464@mayo.edu>

This is a multi-part message in MIME format.
--------------B05DC27F7776836EF4A6103B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


hello everyone:

Thank you very much for all the suggestions. I really appreciate your
time and effort.  
Thank you.

Dinakar

Bruce Sass wrote:
> 
> Hi,
> 
> On Tue, 20 Feb 2001, Dinakar Desai wrote:
> > I am trying to learn python from scratch. I have been following this
> > mailing for sometime. I have learnt a lot from this group. I have been
> > reading about Tkinter and PyGTK+ and other GUI interface development
> > tools available for python. I use linux platform to learn python and
> > like to get my feet wet with GUI development.
> >
> > I come from powerbuilder and c++ background(i have not used C++ for GUI
> > development and not familiar with MFC class libraries). I would
> > appreciate, if you could suggest whether I should start learning Tkinter
> > or PyGTK+ or some other GUI tools.
> 
> There is also PyQT, gratis and (more or less) liberated on unix
> platforms.  http://www.thekompany.com/projects/pykde
> 
> The (inexperienced) impression I get when looking at Tkinter vs. PyQt
> is that PyQt is to Tkinter what Python is to Perl.
> 
> - Bruce
--------------B05DC27F7776836EF4A6103B
Content-Type: text/x-vcard; charset=us-ascii;
 name="desai.dinakar.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Dinakar Desai
Content-Disposition: attachment;
 filename="desai.dinakar.vcf"

begin:vcard 
n:Desai;Dinakar
tel;fax:507-284-0615
tel;home:507-289-3972
tel;work:507-266-2831
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:desai.dinakar@mayo.edu
fn:Dinakar
end:vcard

--------------B05DC27F7776836EF4A6103B--



From kstoner@netins.net  Wed Feb 21 01:10:10 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 20 Feb 2001 19:10:10 -0600
Subject: [Tutor] C to Python
Message-ID: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0137_01C09B70.BEAFAB40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

How is Python like C/C++?  Can it do everything C/C++ can do?

Cameron
kstoner@netins.net

------=_NextPart_000_0137_01C09B70.BEAFAB40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>How is Python like C/C++?&nbsp; Can it =
do=20
everything C/C++ can do?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>kstoner@netins.net</FONT></DIV></BODY></HTML>

------=_NextPart_000_0137_01C09B70.BEAFAB40--



From tim@johnsons-web.com  Wed Feb 21 03:38:22 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Tue, 20 Feb 2001 18:38:22 -0900
Subject: [Tutor] Where's the Walrus?
References: <3A92EBBE.1EADA464@mayo.edu>
Message-ID: <01022018451100.03498@shecom>

Hello:
	I'm creating my first object.
I have a method to advance an index.  
The method doesn't respond.
code is below:
#######################################################
class schiz:
	def __init__(self):
		self.moods = ["I'm a little teapot", "I am the Walrus", 
		              "I hate broccoli", "I'm the Jolly Green Giant"] 
		self.which = 0
            # my code doesn't even get called, or so it appears
	def next_personality():
		print "next personality"
		if self.which < 4:
			self.which = self.which + 1
			print "next"
		else:
			self.which = 0
			print "first"
	def __str__(self):
		return self.moods[self.which]
	def __repr__(self):
		return self.moods[self.which]
	def __call__(self):
		return self.next_personality()
ally_oop = schiz()
print ally_oop
ally_oop.next_personality
print ally_oop
#######################################################
FYI: Am coming from a background in C++
but please don't hold that against me :)
TIA
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From dsh8290@rit.edu  Wed Feb 21 03:53:18 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 20 Feb 2001 22:53:18 -0500
Subject: [Tutor] C to Python
In-Reply-To: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>; from kstoner@netins.net on Tue, Feb 20, 2001 at 07:10:10PM -0600
References: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>
Message-ID: <20010220225318.A23613@harmony.cs.rit.edu>

On Tue, Feb 20, 2001 at 07:10:10PM -0600, Katharine Stoner wrote:
| 
|    
|    How is Python like C/C++?  Can it do everything C/C++ can do?
|    

Python is similar to C/C++ in that is has if, while, for, functions,
classes, etc.  It is different in that indentation is significant
(improves readability and reduces the stupid typo bugs), memory
management is automatic, high-level concepts and structures are
built-in (like lists, dicts, and iterating over a list), and typing is
dynamic.

Python can do almost everything C/C++ can do.  It can't give you
segmentation faults (except in a C module, but that's C) and direct
access to arbitrary memory locations (applications don't need that
anyways, only kernels, device drivers, and the like).

Give python a try.  I am sure you will find it to be a much more
pleasant experience when solving higher-level problems and in
scripting/application level programming.  (Not that C/C++ is bad, it
is just better suited for low-level operations and systems
programming).

-D



From tbrauch@mindless.com  Wed Feb 21 04:28:14 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Tue, 20 Feb 2001 23:28:14 -0500
Subject: [Tutor] Cards Program
Message-ID: <3A9343DE.6D27F22B@mindless.com>

I am slowly working on a program that simulates dealing cards.  While
right now I have no real purpose for this program, it is just something
I thought I'd like to try.  However, I have come to a stumbling block. 
As it is right now, I can get the program to deal as many cards as I
want, but I cannot think of a way to get the cards into seperate hands,
other than just having the program deal out the cards and then manually
split these cards up into hands myself.  That is not what I am looking
for.  Here is my code so far:

######################################################################

import random

cards = input('How many cards do you want for each hand? ')
dealt=[]
c=0
values=['2','3','4','5','6','7','8','9','10','Jack','Queen','King','Ace']
suits=['Hearts','Spades','Diamonds','Clubs']

def card():
    value=random.randint(0,12)
    suit=random.randint(0,3)
    return [suit,value]
    
while (c<cards):
    new_card=card()
    if new_card not in dealt:
        dealt.append(new_card)
        c=c+1
    else: pass

dealt.sort()
for item in dealt:
    print values[item[1]]+' of '+suits[item[0]]

raw_input('Press enter to end. ')

######################################################################

This code will work for one hand, but if I try to just run it again for
anotehr hand, there will be repeated cards.  Ideally I'd like to be able
to have the program ask me how many hands I want dealt and how many
cards in each hand.  But I just cannot seem to make anything I try
work.  Any help would be appreciated.

 - Tim


From rick@niof.net  Wed Feb 21 04:34:03 2001
From: rick@niof.net (Rick Pasotto)
Date: Tue, 20 Feb 2001 23:34:03 -0500
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>; from tim@johnsons-web.com on Tue, Feb 20, 2001 at 06:38:22PM -0900
References: <3A92EBBE.1EADA464@mayo.edu> <01022018451100.03498@shecom>
Message-ID: <20010220233403.A26420@tc.niof.net>

1) next_personality is a method so python needs the parens when it is called.

2) your definition of next_personality should have a 'self' arg.

3) self.which will become a 4 which is out of range. The way I code this
   type of situation is:

	self.which = (self.which + 1) % 4

   (instead of using an if statement)
   which makes sure self.which is only 0, 1, 2, or 3.

On Tue, Feb 20, 2001 at 06:38:22PM -0900, Tim Johnson wrote:
> Hello:
> 	I'm creating my first object.
> I have a method to advance an index.  
> The method doesn't respond.
> code is below:
> #######################################################
> class schiz:
> 	def __init__(self):
> 		self.moods = ["I'm a little teapot", "I am the Walrus", 
> 		              "I hate broccoli", "I'm the Jolly Green Giant"] 
> 		self.which = 0
>             # my code doesn't even get called, or so it appears
> 	def next_personality():
> 		print "next personality"
> 		if self.which < 4:
> 			self.which = self.which + 1
> 			print "next"
> 		else:
> 			self.which = 0
> 			print "first"
> 	def __str__(self):
> 		return self.moods[self.which]
> 	def __repr__(self):
> 		return self.moods[self.which]
> 	def __call__(self):
> 		return self.next_personality()
> ally_oop = schiz()
> print ally_oop
> ally_oop.next_personality
> print ally_oop
> #######################################################
> FYI: Am coming from a background in C++
> but please don't hold that against me :)
> TIA
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
"Half of the American people never read a newspaper. Half never voted for
President. One hopes it is the same half."
		-- Gore Vidal
		   Rick Pasotto email: rickp@telocity.com


From bsass@freenet.edmonton.ab.ca  Wed Feb 21 05:04:02 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Tue, 20 Feb 2001 22:04:02 -0700 (MST)
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>
Message-ID: <Pine.LNX.4.33.0102202158001.5789-100000@bms>

Hi,


A couple of small changes...

---8<---
class schiz:
	def __init__(self):
		self.moods = ["I'm a little teapot", "I am the Walrus",
		              "I hate broccoli", "I'm the Jolly Green Giant"]
		self.which = 0
            # my code doesn't even get called, or so it appears
# *vvv* this needed the "self" reference
	def next_personality(self):
		print "next personality"
		if self.which < 4:
			self.which = self.which + 1
			print "next"
		else:
			self.which = 0
			print "first"
	def __str__(self):
		return self.moods[self.which]
	def __repr__(self):
		return self.moods[self.which]
	def __call__(self):
		return self.next_personality()
ally_oop = schiz()
print ally_oop
# *vvv* forgot the "()"
ally_oop.next_personality()
print ally_oop
# *vvv* this tests the __call__ method
ally_oop()
print ally_oop
--->8---

gets this output...
I'm a little teapot
next personality
next
I am the Walrus
next personality
next
I hate broccoli


- Bruce



From scarblac@pino.selwerd.nl  Wed Feb 21 07:01:58 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 21 Feb 2001 08:01:58 +0100
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>; from tim@johnsons-web.com on Tue, Feb 20, 2001 at 06:38:22PM -0900
References: <3A92EBBE.1EADA464@mayo.edu> <01022018451100.03498@shecom>
Message-ID: <20010221080158.A8786@pino.selwerd.nl>

On Tue, Feb 20, 2001 at 06:38:22PM -0900, Tim Johnson wrote:
> Hello:
> 	I'm creating my first object.
> I have a method to advance an index.  
> The method doesn't respond.
> code is below:

Two simple mistakes:

> #######################################################
> class schiz:
> 	def __init__(self):
> 		self.moods = ["I'm a little teapot", "I am the Walrus", 
> 		              "I hate broccoli", "I'm the Jolly Green Giant"] 
> 		self.which = 0
>             # my code doesn't even get called, or so it appears
> 	def next_personality():

You forgot the argument "self" here.

> 		print "next personality"
> 		if self.which < 4:
> 			self.which = self.which + 1
> 			print "next"
> 		else:
> 			self.which = 0
> 			print "first"
> 	def __str__(self):
> 		return self.moods[self.which]
> 	def __repr__(self):
> 		return self.moods[self.which]
> 	def __call__(self):
> 		return self.next_personality()
> ally_oop = schiz()
> print ally_oop
> ally_oop.next_personality

And here you merely mention the method, but don't call it; add () to the end.

> print ally_oop

-- 
Remco Gerlich


From dyoo@hkn.eecs.berkeley.edu  Wed Feb 21 07:07:32 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 20 Feb 2001 23:07:32 -0800 (PST)
Subject: [Tutor] C to Python
In-Reply-To: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>
Message-ID: <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com>

On Tue, 20 Feb 2001, Katharine Stoner wrote:

> How is Python like C/C++?  Can it do everything C/C++ can do?

Hmmm... Well, they're both programming languages.  *grin*

More seriously: Python has some features that make it "higher-level" than
C++.  For example, Python has a "long integer" type built into the
language:

###
>>> def factorial(x):
...     if x == 0: return 1
...     else: return x * factorial(x-1)
... 
>>> factorial(20)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
[ some error messages cut ]
  File "<stdin>", line 3, in factorial
  File "<stdin>", line 3, in factorial
OverflowError: integer multiplication      # oh.  Must use long ints.
>>> factorial(20L)
2432902008176640000L                       # ah.  Better.
###

So if you every deal with large numbers, just append an "L" to it, and you
have long integers of unbounded size.  (Well, unbounded if you have
unbounded memory.)  You also have access to complex numbers, lists and
tuples, and hashtables.


Classes are less complicated in Python --- in C++ terms, everything is
"virtual" and "public" by default.  The classic Account class in C++:

###
class Account {
public:
    Account(int amount) { this->money = amount); }
    void deposit(int amount) { this->money += amount; }
    void report() { cout << this->money; }
private:
    int money;
};
###

looks this this in Python:

###
class Account:
    def __init__(self, amount): self.money = amount
    def deposit(self, amount): self.money += amount
    def report(self): print self.money
###

Because there's less that needs to be formally declared in Python, writing
Python programs feels less constraining than in the C-ish languages.  
Whether this is a good thing or a bad thing depends on your outlook: do
you like straitjackets?  *grin*

You'll probably want to look more closely at the language introductions
and tutorials section on Python org; there's even the infamous "language
comparision" page linked there:

    http://python.org/doc/Intros.html
    http://python.org/doc/current/tut/tut.html


Finally, what's very neat about Python is that if you ever find something
that's difficult in Python, you can do in C/C++, and extend your results
as a "C Extension": you can allow Python to use those new features!  
You'll probably want to look at the material here:

    http://python.org/doc/current/ext/ext.html

which talks about C/C++ extension stuff.


If you have any questions, please feel free to ask us.



From scarblac@pino.selwerd.nl  Wed Feb 21 07:12:01 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 21 Feb 2001 08:12:01 +0100
Subject: [Tutor] C to Python
In-Reply-To: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>; from kstoner@netins.net on Tue, Feb 20, 2001 at 07:10:10PM -0600
References: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer>
Message-ID: <20010221081201.B8786@pino.selwerd.nl>

On Tue, Feb 20, 2001 at 07:10:10PM -0600, Katharine Stoner wrote:
> How is Python like C/C++?  Can it do everything C/C++ can do?

No. You can't use Python for very low-level things, like writing device
drivers. Also, if you need extreme speed, pure Python will often be too
slow, although you can write the critical parts in C and call them from
Python.

Python is an interpreted, very dynamic language. This give great power and
flexibility, for instance the program can change almost every aspect of
itself at runtime. It is very easy to have a database of bits of code, send
some of them out over the network, and integrate them with a program already
running at the other end; you can't do that sort of thing in C. I'm not
saying that's something you want to do often, but then I've never written a
device driver either...

Python is very powerful, in that you can do almost everything with just a
little bit of code, but it's also slow.

Most applications don't need extreme speed.

-- 
Remco Gerlich


From dyoo@hkn.eecs.berkeley.edu  Wed Feb 21 07:19:56 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 20 Feb 2001 23:19:56 -0800 (PST)
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>
Message-ID: <Pine.LNX.4.21.0102202308060.6935-100000@c82114-a.pinol1.sfba.home.com>

On Tue, 20 Feb 2001, Tim Johnson wrote:

> FYI: Am coming from a background in C++
> but please don't hold that against me :)

That's no problem; don't worry about it.  Let's take a look... oh!  Take a
look here:

> ally_oop = schiz()
> print ally_oop
> ally_oop.next_personality
> print ally_oop

"ally_oop.next_personality" refers to the next_personality method, which
is what you want to call.  But you need something more to tell Python to
execute that function:

    ally_oop.next_personality()

Even if it doesn't take in any arguments, "ally_oop.next_personality" has
a different meaning to Python as opposed to "ally_oop.next_personality()":
the first gives us the function itself as a value, while the second
invokes that function.

(Random note: in Matlab, functions that don't take one argument force you
NOT to include the parentheses.  Really evil language.  Grrr.  Back to
Python...)


Here's a small interpreter session that tries to show the difference
between function as a "process" and function as a "value":

###
>>> def sayHello(name):
...     print "hello", name
... 
>>> sayHello('Tim')
hello Tim

>>> sayHello
<function sayHello at 0x81cbd9c>     # Hey!  So sayHello is a function

>>> greet = sayHello
>>> greet('Tim')
hello Tim
###

Being able to treat functions themselves as values is neat, because now we
can give different names to functions.  (You might recognize this as
"function-pointer" stuff in C++, but in a simpler presentation.)  That's
not the main advantage of using functions as values, but it's one of them.

Feel free to ask any questions to us.  It's good to find another C++'er
among us.  *grin*



From dyoo@hkn.eecs.berkeley.edu  Wed Feb 21 07:22:18 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 20 Feb 2001 23:22:18 -0800 (PST)
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>
Message-ID: <Pine.LNX.4.21.0102202320160.6935-100000@c82114-a.pinol1.sfba.home.com>

On Tue, 20 Feb 2001, Tim Johnson wrote:

> 	def next_personality():
> 		print "next personality"
> 		if self.which < 4:
> 			self.which = self.which + 1
> 			print "next"
> 		else:
> 			self.which = 0
> 			print "first"

One other thing; even if next_personality() doesn't take in an argument,
since it's still a member function, you'll need to refer to a "self" as
its argument.

    def next_personality(self):
        ...

In C++, you might be familiar with the 'this' pointer.  It's the same
idea, but with Python, we explicitly show it as a parameter, just to
disambiguate things.



From wheelege@tsn.cc  Wed Feb 21 07:35:11 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 21 Feb 2001 18:35:11 +1100
Subject: [Tutor] Where's the Walrus?
Message-ID: <004601c09bd8$d2f6ba40$ad755cca@glen>

This is a multi-part message in MIME format.

------=_NextPart_000_0043_01C09C35.05D02260
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


  Howdy how,

  Just two little errors I can see....read on :)

----- Original Message -----
From: Tim Johnson <tim@johnsons-web.com>
To: <tutor@python.org>
Sent: Wednesday, February 21, 2001 2:38 PM
Subject: [Tutor] Where's the Walrus?


> Hello:
> I'm creating my first object.
> I have a method to advance an index.
> The method doesn't respond.
> code is below:
> #######################################################
> class schiz:
> def __init__(self):
> self.moods =3D ["I'm a little teapot", "I am the Walrus",
>               "I hate broccoli", "I'm the Jolly Green Giant"]
> self.which =3D 0
>             # my code doesn't even get called, or so it appears
> def next_personality(self):  ## you need to have it pass self to every
single function inside a class
> print "next personality"
> if self.which < 4:
> self.which =3D self.which + 1
> print "next"
> else:
> self.which =3D 0
> print "first"
> def __str__(self):
> return self.moods[self.which]
> def __repr__(self):
> return self.moods[self.which]
> def __call__(self):
> return self.next_personality()
> ally_oop =3D schiz()
> print ally_oop
> ally_oop.next_personality() ## you had no brackets - that does not =
call
the function.  Same as if you put brackets in a binding it would call =
it,
not having brackets 'assigns' it.
> print ally_oop
> #######################################################
> FYI: Am coming from a background in C++
> but please don't hold that against me :)
> TIA
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



  Then it works like a charm :)


------=_NextPart_000_0043_01C09C35.05D02260
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><BR>&nbsp; Howdy how,<BR><BR>&nbsp; Just two little errors I can=20
see....read on :)<BR><BR>----- Original Message -----<BR>From: Tim =
Johnson=20
&lt;<A =
href=3D"mailto:tim@johnsons-web.com">tim@johnsons-web.com</A>&gt;<BR>To: =

&lt;<A =
href=3D"mailto:tutor@python.org">tutor@python.org</A>&gt;<BR>Sent:=20
Wednesday, February 21, 2001 2:38 PM<BR>Subject: [Tutor] Where's the=20
Walrus?<BR><BR><BR>&gt; Hello:<BR>&gt; I'm creating my first =
object.<BR>&gt; I=20
have a method to advance an index.<BR>&gt; The method doesn't =
respond.<BR>&gt;=20
code is below:<BR>&gt;=20
#######################################################<BR>&gt; class=20
schiz:<BR>&gt; def __init__(self):<BR>&gt; self.moods =3D ["I'm a little =
teapot",=20
"I am the=20
Walrus",<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
"I hate broccoli", "I'm the Jolly Green Giant"]<BR>&gt; self.which =3D=20
0<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
# my code doesn't even get called, or so it appears<BR>&gt; def=20
next_personality(self):&nbsp; ## you need to have it pass self to=20
every<BR>single function inside a class<BR>&gt; print "next =
personality"<BR>&gt;=20
if self.which &lt; 4:<BR>&gt; self.which =3D self.which + 1<BR>&gt; =
print=20
"next"<BR>&gt; else:<BR>&gt; self.which =3D 0<BR>&gt; print =
"first"<BR>&gt; def=20
__str__(self):<BR>&gt; return self.moods[self.which]<BR>&gt; def=20
__repr__(self):<BR>&gt; return self.moods[self.which]<BR>&gt; def=20
__call__(self):<BR>&gt; return self.next_personality()<BR>&gt; ally_oop =
=3D=20
schiz()<BR>&gt; print ally_oop<BR>&gt; ally_oop.next_personality() ## =
you had no=20
brackets - that does not call<BR>the function.&nbsp; Same as if you put =
brackets=20
in a binding it would call it,<BR>not having brackets 'assigns' =
it.<BR>&gt;=20
print ally_oop<BR>&gt;=20
#######################################################<BR>&gt; FYI: Am =
coming=20
from a background in C++<BR>&gt; but please don't hold that against me=20
:)<BR>&gt; TIA<BR>&gt; --<BR>&gt; Tim Johnson<BR>&gt; =
-----------<BR>&gt; "Of=20
all manifestations of power,<BR>&gt;&nbsp; restraint impresses the=20
most."<BR>&gt;&nbsp; -Thucydides<BR>&gt;<BR>&gt;=20
_______________________________________________<BR>&gt; Tutor =
maillist&nbsp;=20
-&nbsp; <A href=3D"mailto:Tutor@python.org">Tutor@python.org</A><BR>&gt; =
<A=20
href=3D"http://mail.python.org/mailman/listinfo/tutor">http://mail.python=
.org/mailman/listinfo/tutor</A><BR><BR><BR><BR>&nbsp;=20
Then it works like a charm :)<BR></DIV></BODY></HTML>

------=_NextPart_000_0043_01C09C35.05D02260--



From Lindsay.Davies@moonshine.co.uk  Wed Feb 21 08:02:59 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Wed, 21 Feb 2001 08:02:59 +0000
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>
References: <3A92EBBE.1EADA464@mayo.edu> <01022018451100.03498@shecom>
Message-ID: <p0501041cb6b925e71cc4@[195.102.186.233]>

Two small changes...

line 7    def next_personality(self):
                                ^^^^
and

line 23   ally_oop.next_personality()
                                    ^^
Best wishes,

Lindsay


On 20/2/01, Tim Johnson wrote about '[Tutor] Where's the Walrus?':
>Hello:
>	I'm creating my first object.
>I have a method to advance an index. 
>The method doesn't respond.
>code is below:
>#######################################################
>class schiz:
>	def __init__(self):
>		self.moods = ["I'm a little teapot", "I am the Walrus",
>		              "I hate broccoli", "I'm the Jolly Green Giant"]
>		self.which = 0
>             # my code doesn't even get called, or so it appears
>	def next_personality():
>		print "next personality"
>		if self.which < 4:
>			self.which = self.which + 1
>			print "next"
>		else:
>			self.which = 0
>			print "first"
>	def __str__(self):
>		return self.moods[self.which]
>	def __repr__(self):
>		return self.moods[self.which]
>	def __call__(self):
>		return self.next_personality()
>ally_oop = schiz()
>print ally_oop
>ally_oop.next_personality
>print ally_oop
>#######################################################
>FYI: Am coming from a background in C++
>but please don't hold that against me :)
>TIA
>--
>Tim Johnson
>-----------
>"Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From chantier@esker.fr  Wed Feb 21 09:01:30 2001
From: chantier@esker.fr (Chantier Thierry)
Date: Wed, 21 Feb 2001 10:01:30 +0100
Subject: [Tutor] Where's the Walrus?
In-Reply-To: <01022018451100.03498@shecom>
References: <3A92EBBE.1EADA464@mayo.edu> <01022018451100.03498@shecom>
Message-ID: <01022110032701.05523@chantier>

Don't you have an error with 'one argument expected' or something like th=
at ?
I think your def next_personality(): should be def next_personality(self)=
:

I'm just a newbie but I had some problem like that this one I believe.

Thierry

Le mer, 21 f=E9v 2001, Tim Johnson a =E9crit :
> Hello:
> 	I'm creating my first object.
> I have a method to advance an index. =20
> The method doesn't respond.
> code is below:
> #######################################################
> class schiz:
> 	def __init__(self):
> 		self.moods =3D ["I'm a little teapot", "I am the Walrus",=20
> 		              "I hate broccoli", "I'm the Jolly Green Giant"]=20
> 		self.which =3D 0
>             # my code doesn't even get called, or so it appears
> 	def next_personality():
> 		print "next personality"
> 		if self.which < 4:
> 			self.which =3D self.which + 1
> 			print "next"
> 		else:
> 			self.which =3D 0
> 			print "first"
> 	def __str__(self):
> 		return self.moods[self.which]
> 	def __repr__(self):
> 		return self.moods[self.which]
> 	def __call__(self):
> 		return self.next_personality()
> ally_oop =3D schiz()
> print ally_oop
> ally_oop.next_personality
> print ally_oop
> #######################################################
> FYI: Am coming from a background in C++
> but please don't hold that against me :)
> TIA


From amoreira@mercury.ubi.pt  Wed Feb 21 10:16:40 2001
From: amoreira@mercury.ubi.pt (Jose Amoreira)
Date: Wed, 21 Feb 2001 10:16:40 +0000
Subject: [Tutor] Where's the Walrus?
References: <3A92EBBE.1EADA464@mayo.edu> <01022018451100.03498@shecom>
Message-ID: <3A939588.C57C8BC7@mercury.ubi.pt>

Hello !
It's just a typo! You frogot the 'self' argument in 'def next_personality()'!




Tim Johnson wrote:

> Hello:
>         I'm creating my first object.
> I have a method to advance an index.
> The method doesn't respond.
> code is below:
> #######################################################
> class schiz:
>         def __init__(self):
>                 self.moods = ["I'm a little teapot", "I am the Walrus",
>                               "I hate broccoli", "I'm the Jolly Green Giant"]
>                 self.which = 0
>             # my code doesn't even get called, or so it appears

# Don't forget the 'self' argument in class methods definitions!!!!

>
>         def next_personality():
>                 print "next personality"
>                 if self.which < 4:
>                         self.which = self.which + 1
>                         print "next"
>                 else:
>                         self.which = 0
>                         print "first"
>         def __str__(self):
>                 return self.moods[self.which]
>         def __repr__(self):
>                 return self.moods[self.which]
>         def __call__(self):
>                 return self.next_personality()
> ally_oop = schiz()
> print ally_oop
> ally_oop.next_personality
> print ally_oop
> #######################################################
> FYI: Am coming from a background in C++
> but please don't hold that against me :)
> TIA
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides






From alan.gauld@bt.com  Wed Feb 21 10:20:49 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 21 Feb 2001 10:20:49 -0000
Subject: [Tutor] request for  suggestions
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5AB@mbtlipnt02.btlabs.bt.co.uk>

> reading about Tkinter and PyGTK+ and other GUI interface development

> I come from powerbuilder and c++ background(i have not used 
> C++ for GUI development and not familiar with MFC class libraries). 

Thats an advantage then! :-)

MFC and most windows tools use a horrible paradigm for building 
GUIS based on absolute (often pixel based) locations. The other 
higher order toolkits tend to use layout managers to locate the 
controls for you - much nicer and a lot easier to control screen 
resizing etc.

> learning Tkinter

Easy to learn, available on Python, Tcl and Tk so the knowledge 
is transferrable and its multi platform. FWIW I like it :-)

> or PyGTK+ 

Somewhat multi platform, you can get compiled language support 
(C/C++) if thats important and is a somewhat more "conventional" 
GUI toolkit than Tk. Allows more sophistication thaty Tk but has 
a steeper learning curve IMHO. Integrates "easily" with the GNOME
project facilities.

> or some other GUI tools.

There are lots to choose from but I'd suggest sticking with Tk 
because there is more(not a lot but more!) documentation available
(especially for raw Tk) and most of the principles will transfer 
to other GUI toolkits later. For just slapping together a quick 
GUI interface over a ext based tool it takes a lot of beating.

my 2 cents worth,

Alan g


From jcm@bigskytel.com  Wed Feb 21 12:26:07 2001
From: jcm@bigskytel.com (David Porter)
Date: Wed, 21 Feb 2001 05:26:07 -0700
Subject: [Tutor] Has anyone tried PMZ
In-Reply-To: <3A914C2F.85F95CEB@penguinpowered.com>; from abreu@penguinpowered.com on Mon, Feb 19, 2001 at 10:39:11AM -0600
References: <3A914C2F.85F95CEB@penguinpowered.com>
Message-ID: <20010221052605.A284@bigskytel.com>

* Jose Alberto Abreu <abreu@penguinpowered.com>:
> I found the "Poor Man's Zope" proyect in sourceforge, and it looks like
> something I would like to try...
> 
> http://pmz.sourceforge.net/
> 
> Looks easy to learn and powerful, but has anyone tried it yet?

I have. It is very easy. You just embed python code in html documents and it
is executed:

<?
for x in range(10):
    print x
?>    

Try it out. 

David

-- 
She was an ftp site to California. 


From NHYTRO@compuserve.com  Wed Feb 21 13:19:07 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 21 Feb 2001 08:19:07 -0500
Subject: [Tutor] File uploads perr HTTP
Message-ID: <200102210819_MC2-C651-6593@compuserve.com>

Hi there!

can someone point me to a URL where I can RTFM "file uploads per HTTP in
Python" for dummies? I would be extremly nice if  someone posted a snippe=
t
to the list, that would give me a push in the right direction.

Great thanks

Sharriff


From randrews@planhouse.com  Wed Feb 21 16:32:09 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 21 Feb 2001 10:32:09 -0600
Subject: [Tutor] Cards Program
References: <3A9343DE.6D27F22B@mindless.com>
Message-ID: <007901c09c23$d6c99f20$9600a8c0@Planhouse5>

How about adding a little extra flow control during the card dealing so that
a list of players is iterated through and dealt to w/o having to restart the
deal with a fresh deck?

One idea is to try coding this program using classes, having a *dealer* and
several *player* objects.

Rob

----- Original Message -----
From: "Timothy M. Brauch" <tbrauch@mindless.com>
To: "Python Tutor" <tutor@python.org>
Sent: Tuesday, February 20, 2001 10:28 PM
Subject: [Tutor] Cards Program


> I am slowly working on a program that simulates dealing cards.  While
> right now I have no real purpose for this program, it is just something
> I thought I'd like to try.  However, I have come to a stumbling block.
> As it is right now, I can get the program to deal as many cards as I
> want, but I cannot think of a way to get the cards into seperate hands,
> other than just having the program deal out the cards and then manually
> split these cards up into hands myself.  That is not what I am looking
> for.  Here is my code so far:
>
> ######################################################################
>
> import random
>
> cards = input('How many cards do you want for each hand? ')
> dealt=[]
> c=0
> values=['2','3','4','5','6','7','8','9','10','Jack','Queen','King','Ace']
> suits=['Hearts','Spades','Diamonds','Clubs']
>
> def card():
>     value=random.randint(0,12)
>     suit=random.randint(0,3)
>     return [suit,value]
>
> while (c<cards):
>     new_card=card()
>     if new_card not in dealt:
>         dealt.append(new_card)
>         c=c+1
>     else: pass
>
> dealt.sort()
> for item in dealt:
>     print values[item[1]]+' of '+suits[item[0]]
>
> raw_input('Press enter to end. ')
>
> ######################################################################
>
> This code will work for one hand, but if I try to just run it again for
> anotehr hand, there will be repeated cards.  Ideally I'd like to be able
> to have the program ask me how many hands I want dealt and how many
> cards in each hand.  But I just cannot seem to make anything I try
> work.  Any help would be appreciated.
>
>  - Tim
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From tim@johnsons-web.com  Wed Feb 21 16:48:16 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Wed, 21 Feb 2001 07:48:16 -0900
Subject: [Tutor] Where's the Walrus?
References: <Pine.LNX.4.21.0102202308060.6935-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <01022107563800.04244@shecom>

Hello:
Thanks very much to everyone for all the great help!! :)
On Tue, 20 Feb 2001, Danny Yoo wrote:

> > FYI: Am coming from a background in C++
> > but please don't hold that against me :)
> 
> That's no problem; don't worry about it.  Let's take a look... oh!  Take a
> look here:
Yes, that explicit passing of the self argument tripped me up....

> Even if it doesn't take in any arguments, "ally_oop.next_personality" has
> a different meaning to Python as opposed to "ally_oop.next_personality()":
> the first gives us the function itself as a value, while the second
> invokes that function.
Like the () operator override in C++................... 
> (Random note: in Matlab, functions that don't take one argument force you
> NOT to include the parentheses.  Really evil language.  Grrr.  Back to
> Python...)
Yes, VBA does that too.
<snip.............>
> Feel free to ask any questions to us.  It's good to find another C++'er
> among us.  *grin*
Wonderful little exercise that you put in there.
I believe there is less C++ and more python in my future....
Thanks much
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From tim@johnsons-web.com  Wed Feb 21 17:09:29 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Wed, 21 Feb 2001 08:09:29 -0900
Subject: [Tutor] Python Usage Question
References: <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <01022108170203.04244@shecom>

Hi: I have a general question here:

I've been programming in C/C++ for some years now, also work with rebol, in
both cases commercially.

I've been asked to create a series of on-line programming classes in
programming for a local school district. It is targeted at sophomores through
senior level.

We will be teaching in order from first semester to last: Rebol, Python, Perl,
and C/C++.

We are also gathering information in the relative usage of programming
languages. (I suppose to extrapolate job opportunities)

Can anyone comment on the extent of usage of python in the commercial vs. the
educational community?

Thanks in advance, and also a big thanks for all the help and comments that I
have gotten for this list.

Regards
 --
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From randrews@planhouse.com  Wed Feb 21 17:31:23 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 21 Feb 2001 11:31:23 -0600
Subject: [Tutor] Python Usage Question
References: <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com> <01022108170203.04244@shecom>
Message-ID: <001701c09c2c$1d600520$9600a8c0@Planhouse5>

While Python isn't one of the most demanded languages (yet) in industry, its
popularity is growing due to the relatively shallow learning curve and the
newbie-friendly user community.

<longstory>I was directed several months ago to *quickly* learn Java for a
project and found myself unable to wrap my head around it all by my
lonesome, although I made some headway by juggling a little Perl and a litle
Java simultaneously, which helped me fill in the blanks with some context.
Still, almost no headway, though.

Python kinda dropped into my lap (although not entirely like a 16-ton
weight), and I found that using IDLE was more fun than Diablo (no, really).
So I kept playing with it, reading through tutorials, and following the
Tutor list a bit, and have learned just about enough Python to be of small
danger.

To my joy, however, I cracked open my Java books this weekend when the edict
from several months ago reared its ugly head again.  Although I hadn't even
glanced at Java during my Python adventures, I found that I was able to
comprehend the code I was reading in Java.

If nothing else, I owe Python for smoothing over my neural pathways for the
Java travails to come.</longstory>

Rob Andrews
----- Original Message -----
From: "Tim Johnson" <tim@johnsons-web.com>

> Hi: I have a general question here:
>
> I've been programming in C/C++ for some years now, also work with rebol,
in
> both cases commercially.
>
> I've been asked to create a series of on-line programming classes in
> programming for a local school district. It is targeted at sophomores
through
> senior level.
>
> We will be teaching in order from first semester to last: Rebol, Python,
Perl,
> and C/C++.
>
> We are also gathering information in the relative usage of programming
> languages. (I suppose to extrapolate job opportunities)
>
> Can anyone comment on the extent of usage of python in the commercial vs.
the
> educational community?
>
> Thanks in advance, and also a big thanks for all the help and comments
that I
> have gotten for this list.
>
> Regards
>  --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From shaleh@valinux.com  Wed Feb 21 17:37:48 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Wed, 21 Feb 2001 09:37:48 -0800 (PST)
Subject: [Tutor] Python Usage Question
In-Reply-To: <01022108170203.04244@shecom>
Message-ID: <XFMail.20010221093748.shaleh@valinux.com>

> 
> We will be teaching in order from first semester to last: Rebol, Python,
> Perl,
> and C/C++.
> 

interesting order, and not a bad one.  Teach them good skills, then perl (-:

Python is useful everywhere perl is (or any other scripting language for that
matter).  CGI, site design (Zope), etc.  Also good for real programming.  GUIs,
admin tools, etc.  Red Hat's installer is a lot of python.  python is also
great as a design language.  Work out the rough flow of the program then write
it in C(++).


From deirdre@deirdre.net  Wed Feb 21 18:08:19 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Wed, 21 Feb 2001 10:08:19 -0800 (PST)
Subject: [Tutor] Python Usage Question
In-Reply-To: <001701c09c2c$1d600520$9600a8c0@Planhouse5>
Message-ID: <Pine.LNX.4.31.0102211006580.5663-100000@emperor.deirdre.org>

On Wed, 21 Feb 2001, Rob Andrews wrote:

> If nothing else, I owe Python for smoothing over my neural pathways for the
> Java travails to come.</longstory>

While I'm glad learning Python helped you, I tremble at the thought of
using Python as a ramp for Java. Python WAS designed as a teaching
language, so it's not entirely unexpected. But as someone who is
(understatement) Not A Fan of Java, well....

--
_Deirdre              deirdre@deirdre.net         http://www.deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From dsh8290@rit.edu  Wed Feb 21 19:37:50 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 21 Feb 2001 14:37:50 -0500
Subject: [Tutor] C to Python
In-Reply-To: <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com>; from dyoo@hkn.eecs.berkeley.edu on Tue, Feb 20, 2001 at 11:07:32PM -0800
References: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer> <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <20010221143750.A24094@harmony.cs.rit.edu>

On Tue, Feb 20, 2001 at 11:07:32PM -0800, Danny Yoo wrote:
| 
| Classes are less complicated in Python --- in C++ terms, everything is
| "virtual" and "public" by default.  The classic Account class in C++:
| 

Not quite.  In C++, members are "final" by default.  They are only
virtual if you explicitly declare them as virtual.  In Java, on the
other hand, everything is "virtual" without specifying it, and "final"
only if declared final.

(BTW, the term "virtual" only really applies to C++, and "final" to
Java even though the concepts are universal)

-D



From ibraheem@micromuse.com  Wed Feb 21 19:56:08 2001
From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed)
Date: Wed, 21 Feb 2001 19:56:08 +0000
Subject: [ibraheem: Re: [Tutor] C to Python]
Message-ID: <20010221195608.A28264@micromuse.com>

--bp/iNruPH9dso1Pn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline



--bp/iNruPH9dso1Pn
Content-Type: message/rfc822
Content-Disposition: inline

Date: Wed, 21 Feb 2001 19:54:33 +0000
From: Ibraheem Umaru-Mohammed <ibraheem>
To: D-Man <dsh8290@rit.edu>
Subject: Re: [Tutor] C to Python
Message-ID: <20010221195433.A28257@micromuse.com>
References: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer> <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com> <20010221143750.A24094@harmony.cs.rit.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5i
In-Reply-To: <20010221143750.A24094@harmony.cs.rit.edu>; from dsh8290@rit.edu on Wed, Feb 21, 2001 at 02:37:50PM -0500

On Wed, Feb 21, 2001 at 02:37:50PM -0500, D-Man wrote:
> On Tue, Feb 20, 2001 at 11:07:32PM -0800, Danny Yoo wrote:
> | 
> | Classes are less complicated in Python --- in C++ terms, everything is
> | "virtual" and "public" by default.  The classic Account class in C++:
> | 
> 
> Not quite.  In C++, members are "final" by default.  They are only
> virtual if you explicitly declare them as virtual.  In Java, on the
> other hand, everything is "virtual" without specifying it, and "final"
> only if declared final.
> 

I think you *might* have misunderstood what Danny wrote.

I think he meant Classes in *Python* would be the equivalent of "virtual" and
"public" classes in C++.

Kindest regards,

	--ibs.

--
---------------------------------------------------------------------------
			--  Ibraheem Umaru-Mohammed  --
			--  Email:ium@micromuse.com  --
-- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA --
			--  http://www.micromuse.com --
---------------------------------------------------------------------------

--bp/iNruPH9dso1Pn--


From dsh8290@rit.edu  Wed Feb 21 20:24:33 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 21 Feb 2001 15:24:33 -0500
Subject: [Tutor] C to Python
In-Reply-To: <20010221195433.A28257@micromuse.com>; from ibraheem@micromuse.com on Wed, Feb 21, 2001 at 07:54:33PM +0000
References: <013a01c09ba3$0a02bce0$7452b1cf@oemcomputer> <Pine.LNX.4.21.0102202245320.6935-100000@c82114-a.pinol1.sfba.home.com> <20010221143750.A24094@harmony.cs.rit.edu> <20010221195433.A28257@micromuse.com>
Message-ID: <20010221152433.A24193@harmony.cs.rit.edu>

On Wed, Feb 21, 2001 at 07:54:33PM +0000, Ibraheem Umaru-Mohammed wrote:
| On Wed, Feb 21, 2001 at 02:37:50PM -0500, D-Man wrote:
| > On Tue, Feb 20, 2001 at 11:07:32PM -0800, Danny Yoo wrote:
| > | 
| > | Classes are less complicated in Python --- in C++ terms, everything is
| > | "virtual" and "public" by default.  The classic Account class in C++:
| > | 
| > 
| > Not quite.  In C++, members are "final" by default.  They are only
| > virtual if you explicitly declare them as virtual.  In Java, on the
| > other hand, everything is "virtual" without specifying it, and "final"
| > only if declared final.
| > 
| 
| I think you *might* have misunderstood what Danny wrote.
| 
| I think he meant Classes in *Python* would be the equivalent of "virtual" and
| "public" classes in C++.
| 

Ok, yeah, I read it too fast and missed the word "terms" there.  I
thought he wrote "in C++, ...".

Sorry about that.

-D



From bsass@freenet.edmonton.ab.ca  Wed Feb 21 20:50:49 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Wed, 21 Feb 2001 13:50:49 -0700 (MST)
Subject: [Tutor] Cards Program
In-Reply-To: <007901c09c23$d6c99f20$9600a8c0@Planhouse5>
Message-ID: <Pine.LNX.4.33.0102211237510.7147-100000@bms>

I gotta agree with Rob, take a more object oriented approach.

Not only could you have classes for instances of dealer and player
objects, the deck(s) of cards and the rules of the game can also be
objects.  To see that last one, consider the "I am the Walrus" state
machine a few messages back[1], then have each "personality" be the
possibilities for a particular state of the game.

The top level could look something like this:

eric = AIPokerPlayer()
john = AIPokerPlayer()
tim = HumanPokerPlayer()
players = [john, eric, tim]
gametype = "stud"
game = Poker(players, gametype)
while not game.winner:
    game()
print "The winner is...", game.winner

When game is instantiated it would setup to mediate stud poker between
eric and john - get a new deck, start a dealer, tell the dealer to
deal a hand to everyone.  The game() calls will move the game along;
e.g., "how many cards do you want?", "what's your bet?", `is there
a winner', etc.

A *Player would need to respond to the various queries the game could
generate; for the human player it is a matter of prompting and
waiting, the ai player would need to know the rules.

The *Player classes and Poker class could be derived from classes that
define the stuff in common to a variety of different types of players
and games.  So maybe you would have:

class Poker(CardGame): ...
class AIPlayer(GamePlayer): ...
class AIPokerPlayer(AIPlayer): ...
etc.

Ya, ok, I haven't answered your question; but I hope I have shown you
a way of looking at the problem that lets you break it down into
independent pieces so it is easier to handle.


- Bruce


[1] ...state machine core... in case you missed it

class StateMachine:
    def __init__(self):
        # do stuff that is done only one time. e.g.,
        self.state = 0
    ...
    def __call__(self):
        # move to the next state
        self.state = ...
        self.handlestate(self.state)  # whatever


-- 
On Wed, 21 Feb 2001, Rob Andrews wrote:
> How about adding a little extra flow control during the card dealing so that
> a list of players is iterated through and dealt to w/o having to restart the
> deal with a fresh deck?
>
> One idea is to try coding this program using classes, having a *dealer* and
> several *player* objects.
>
> ----- Original Message -----
> From: "Timothy M. Brauch" <tbrauch@mindless.com>
>
> > I am slowly working on a program that simulates dealing cards.  While
> > right now I have no real purpose for this program, it is just something
> > I thought I'd like to try.  However, I have come to a stumbling block.
> > As it is right now, I can get the program to deal as many cards as I
> > want, but I cannot think of a way to get the cards into seperate hands,
> > other than just having the program deal out the cards and then manually
> > split these cards up into hands myself.  That is not what I am looking
> > for.  Here is my code so far:
<...code snipped...>
> > This code will work for one hand, but if I try to just run it again for
> > anotehr hand, there will be repeated cards.  Ideally I'd like to be able
> > to have the program ask me how many hands I want dealt and how many
> > cards in each hand.  But I just cannot seem to make anything I try
> > work.  Any help would be appreciated.




From gibbs05@flash.net  Wed Feb 21 22:22:20 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Wed, 21 Feb 2001 16:22:20 -0600
Subject: [Tutor] Tkinter Question
Message-ID: <0f9001c09c55$295eb640$bafa32d8@gibbs05>

Greetings All,

I've a question for the experienced Tkinter programmers out there.  Well,
for any Tkinter programmer out there.  Consider that tiny 'TK' icon that
appears in the upper left-hand corner in Windows Tkinter guis.  I'd like to
replace that icon with something else.  Perhaps a little green snake would
be better. :-)

I've searched through the Tkinter documentation I'm aware of, but I haven't
found an answer yet.  Does anyone know where I can find documentation on how
to replace that icon?


Thanks,
Sam



From pbfisher@ispchannel.com  Wed Feb 21 22:55:11 2001
From: pbfisher@ispchannel.com (Pat/Bob Fisher)
Date: Wed, 21 Feb 2001 17:55:11 -0500
Subject: [Tutor] Files and file attributes
Message-ID: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C09C2F.6FB67B80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am pretty new at programming in Python, but have had experience in =
programming in other languages.  I went through the tutorial which I =
thought was fairly good, except the section on the methods of file =
objects was pretty sparse.  It seems to me that dealing with files is =
rather awkward. I have used the  list representation  filelist =3D =
f.readlines() and then used the fine list methods to manipulate the =
filelist, but I am having trouble getting a new file from  my new =
filelist.  The g.write('string') gives me a whole lot of extraneous =
stuff.
Another problem I am having is trying  to open files in other =
directories.  For example,
=20
   f=3Dopen('C:\tmp\testfile','r+') just doesn't work for me.

Can anyone help, or at least tell me where I can learn more about file =
manipulation?
I suppose it is obvious I am using a windows platform, specifically =
WindowsME.

Thanks in advance,
Robert Fisher
pbfisher@bigfoot.com

------=_NextPart_000_0007_01C09C2F.6FB67B80
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Courier New" size=3D2>I am pretty new at programming =
in Python,=20
but have had experience in programming in other languages.&nbsp; I went =
through=20
the tutorial which I thought was fairly good, except the section on the =
methods=20
of file objects was pretty sparse.&nbsp; It seems to me that dealing =
with files=20
is rather awkward. I have used the&nbsp; list representation&nbsp; =
filelist =3D=20
f.readlines() and then used the fine list methods to manipulate the =
filelist,=20
but I am having trouble getting a new file from&nbsp; my new =
filelist.&nbsp; The=20
g.write('string') gives me a whole lot of extraneous stuff.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Another problem I am having is =
trying&nbsp;=20
to open files in other directories.&nbsp; For example,</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp; =
f=3Dopen('C:\tmp\testfile','r+')=20
just doesn't work for me.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Can anyone help, or at least =
tell me where=20
I can learn more about file manipulation?</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>I suppose it is obvious I am =
using a=20
windows platform, specifically WindowsME.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Thanks in advance,</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Robert Fisher</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>pbfisher@bigfoot.com</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C09C2F.6FB67B80--



From scarblac@pino.selwerd.nl  Wed Feb 21 23:20:32 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 00:20:32 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>; from pbfisher@ispchannel.com on Wed, Feb 21, 2001 at 05:55:11PM -0500
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>
Message-ID: <20010222002032.A1435@pino.selwerd.nl>

On Wed, Feb 21, 2001 at 05:55:11PM -0500, Pat/Bob Fisher wrote:
> I am pretty new at programming in Python, but have had experience in
> programming in other languages.  I went through the tutorial which I thought
> was fairly good, except the section on the methods of file objects was
> pretty sparse.  It seems to me that dealing with files is rather awkward. I
> have used the list representation filelist = f.readlines() and then used the
> fine list methods to manipulate the filelist, but I am having trouble
> getting a new file from my new filelist.

Wait! I don't understand that. What 'filelist = f.readlines()' does, is read
the whole file f, turn it into a line by line list, and assign it to
filelist. What do you mean, getting a new file from a list of lines?

> The g.write('string') gives me a whole lot of extraneous stuff.

It should write the string 'string' to file g and nothing else. Can you
describe what you're seeing?

> Another problem I am having is trying  to open files in other directories.  For example,
>  
>    f=open('C:\tmp\testfile','r+') just doesn't work for me.

A \ inside a string has a special meaning, so that filename isn't what you
think it is. Use one of these three options:

1. Forward slashes. f=open('C:/tmp/testfile','r+'). Yes, that works!
2. 'Raw' strings. f=open(r'C:\tmp\testfile','r+'). The r before the string
   means that the backslashes are to be left in the string.
3. Escape the backslashes. f=open('C:\\tmp\\testfile','r+').
 
> Can anyone help, or at least tell me where I can learn more about file manipulation?

It's really pretty simple. For instance, if you want to read file 'a',
add a space to each line, and write the lot to file 'b', you could do:

a = open('a','r')
b = open('b','w')
for line in a.readlines():
   b.write(" "+line)
a.close()
b.close()


Please try to explain what goes wrong exactly.

-- 
Remco Gerlich


From gibbs05@flash.net  Wed Feb 21 23:39:30 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Wed, 21 Feb 2001 17:39:30 -0600
Subject: [Tutor] Files and file attributes
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>
Message-ID: <142401c09c5f$979626c0$bafa32d8@gibbs05>

This is a multi-part message in MIME format.

------=_NextPart_000_1421_01C09C2D.3EF0BE40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Greetings Robert & All,

I've had the same problem with opening files in other directories.  The =
problem's that Windows style path separator.  Python interprets them as =
escape characters, so it's turning those '\t's into tabs.

I've solved it in the following ways:
1). Using raw strings:
    f =3D open(r"C:\tmp\testfile", 'r+')
2). Using capital T's:  ;-)
    f =3D open('C:\Tmp\Testfile', 'r+')

There's more than one way to do it.  Wait!   That's that other 'P' =
language...  Just use the first method. :-)

As for g.write('string')...  Can you give us the error you're receiving?


Good luck,
Sam
  ----- Original Message -----=20
  From: Pat/Bob Fisher=20
  To: tutor@python.org=20
  Sent: Wednesday, February 21, 2001 4:55 PM
  Subject: [Tutor] Files and file attributes


  I am pretty new at programming in Python, but have had experience in =
programming in other languages.  I went through the tutorial which I =
thought was fairly good, except the section on the methods of file =
objects was pretty sparse.  It seems to me that dealing with files is =
rather awkward. I have used the  list representation  filelist =3D =
f.readlines() and then used the fine list methods to manipulate the =
filelist, but I am having trouble getting a new file from  my new =
filelist.  The g.write('string') gives me a whole lot of extraneous =
stuff.
  Another problem I am having is trying  to open files in other =
directories.  For example,
  =20
     f=3Dopen('C:\tmp\testfile','r+') just doesn't work for me.
  =20
  Can anyone help, or at least tell me where I can learn more about file =
manipulation?
  I suppose it is obvious I am using a windows platform, specifically =
WindowsME.
  =20
  Thanks in advance,
  Robert Fisher
  pbfisher@bigfoot.com

------=_NextPart_000_1421_01C09C2D.3EF0BE40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Greetings Robert &amp; All,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>I've had the same problem with opening files in =
other=20
directories.&nbsp; The problem's that Windows style path =
separator.&nbsp; Python=20
interprets them as escape characters, so it's turning those '\t's into=20
tabs.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>I've solved it in the following ways:</FONT></DIV>
<DIV><FONT size=3D2>1). Using raw strings:</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; f =3D open(r"C:\tmp\testfile",=20
'r+')</FONT></DIV>
<DIV><FONT size=3D2>2). Using capital T's:&nbsp; ;-)</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; f =3D open('C:\Tmp\Testfile',=20
'r+')</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>There's more than one way to do it.&nbsp; =
Wait!&nbsp;&nbsp;=20
That's that other 'P' language...&nbsp; Just use the first method.=20
:-)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>As for g.write('string')...&nbsp; Can you give us =
the error=20
you're receiving?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Good luck,</FONT></DIV>
<DIV><FONT size=3D2>Sam</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:pbfisher@ispchannel.com" =
title=3Dpbfisher@ispchannel.com>Pat/Bob=20
  Fisher</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
  title=3Dtutor@python.org>tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, February 21, =
2001 4:55=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Files and file =

  attributes</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>I am pretty new at =
programming in Python,=20
  but have had experience in programming in other languages.&nbsp; I =
went=20
  through the tutorial which I thought was fairly good, except the =
section on=20
  the methods of file objects was pretty sparse.&nbsp; It seems to me =
that=20
  dealing with files is rather awkward. I have used the&nbsp; list=20
  representation&nbsp; filelist =3D f.readlines() and then used the fine =
list=20
  methods to manipulate the filelist, but I am having trouble getting a =
new file=20
  from&nbsp; my new filelist.&nbsp; The g.write('string') gives me a =
whole lot=20
  of extraneous stuff.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Another problem I am having =
is=20
  trying&nbsp; to open files in other directories.&nbsp; For=20
  example,</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>&nbsp;</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;=20
  f=3Dopen('C:\tmp\testfile','r+') just doesn't work for =
me.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Can anyone help, or at least =
tell me=20
  where I can learn more about file manipulation?</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>I suppose it is obvious I am =
using a=20
  windows platform, specifically WindowsME.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Thanks in =
advance,</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Robert Fisher</FONT></DIV>
  <DIV><FONT face=3D"Courier New"=20
size=3D2>pbfisher@bigfoot.com</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_1421_01C09C2D.3EF0BE40--



From dyoo@hkn.eecs.berkeley.edu  Wed Feb 21 23:54:01 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 21 Feb 2001 15:54:01 -0800 (PST)
Subject: [Tutor] Cards Program
In-Reply-To: <3A9343DE.6D27F22B@mindless.com>
Message-ID: <Pine.LNX.4.21.0102211543180.1387-100000@c82114-a.pinol1.sfba.home.com>

On Tue, 20 Feb 2001, Timothy M. Brauch wrote:

> As it is right now, I can get the program to deal as many cards as I
> want, but I cannot think of a way to get the cards into seperate hands,
> other than just having the program deal out the cards and then manually
> split these cards up into hands myself.  That is not what I am looking
> for.  Here is my code so far:

> values=['2','3','4','5','6','7','8','9','10','Jack','Queen','King','Ace']
> suits=['Hearts','Spades','Diamonds','Clubs']
> 
> def card():
>     value=random.randint(0,12)
>     suit=random.randint(0,3)
>     return [suit,value]
>     
> while (c<cards):
>     new_card=card()
>     if new_card not in dealt:
>         dealt.append(new_card)
>         c=c+1
>     else: pass


Although this will work, there's another way to approach this problem.  We
can construct the whole deck as a list of [value/suit] pairs:

###
def makeDeck():
    values=['2','3','4','5','6','7','8','9','10',
            'Jack','Queen','King','Ace']
    suits=['Hearts','Spades','Diamonds','Clubs']

    deck = []
    for v in values:                
        for s in suits:              
            deck.append([v, s])
    return deck
###

Let's see how this will work:

###
>>> makeDeck()
[['2', 'Hearts'], ['2', 'Spades'], ['2', 'Diamonds'], ['2', 'Clubs'],
['3', 'Hearts'], ['3', 'Spades'], ['3', 'Diamonds'], ['3', 'Clubs'],
# [... lots and lots of cards.]

>>> len(makeDeck())
52
###

So that sounds like the right number of cards.  Then all we'd need to do
to draw new cards is to pull out a random card from the deck with
random.choice().

###
>>> deck = makeDeck()
>>> random.choice(deck)
['3', 'Spades']
>>> random.choice(deck)
['8', 'Hearts']
>>> random.choice(deck)
['King', 'Clubs']
###

(Note: the above might be buggy because it's as if we take a random card
from the deck, but then put it right back into the deck.  We need to
actually _pull_ our choice out of the deck; otherwise, we'll hit
duplicates.)

So this might lead to an easier way of generating hands, and you even get
a fully contructed deck too.

Good luck!



From jcm@bigskytel.com  Wed Feb 21 23:56:56 2001
From: jcm@bigskytel.com (David Porter)
Date: Wed, 21 Feb 2001 16:56:56 -0700
Subject: [Tutor] Files and file attributes
In-Reply-To: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>; from pbfisher@ispchannel.com on Wed, Feb 21, 2001 at 05:55:11PM -0500
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>
Message-ID: <20010221165656.A3383@bigskytel.com>

* Pat/Bob Fisher <pbfisher@ispchannel.com>:

> I am pretty new at programming in Python, but have had experience in
> programming in other languages.  I went through the tutorial which I
> thought was fairly good, except the section on the methods of file objects
> was pretty sparse.  It seems to me that dealing with files is rather
> awkward. I have used the list representation filelist = f.readlines() and
> then used the fine list methods to manipulate the filelist, but I am having
> trouble getting a new file from my new filelist.

Could you elaborate on this?

> The g.write('string') gives me a whole lot of extraneous stuff.

What is the extraneous stuff? My guess is that you did not open g for
writing:

g = open('file', 'w')
g.write('string')

> Another problem I am having is trying to open files in other directories.
> For example,
>  
>    f=open('C:\tmp\testfile','r+') just doesn't work for me.

Backslashes mean something special inside strings. E.g., \n is a newline and
\t is a tab (looking above, you accidentally embedded two tabs in the
filename). If you want it to really be a backslash then use two:

f = open('c:\\tmp\\testfile', 'r+')


David


From dsh8290@rit.edu  Thu Feb 22 00:46:14 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 21 Feb 2001 19:46:14 -0500
Subject: [Tutor] Files and file attributes
In-Reply-To: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>; from pbfisher@ispchannel.com on Wed, Feb 21, 2001 at 05:55:11PM -0500
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>
Message-ID: <20010221194613.A25405@harmony.cs.rit.edu>

On Wed, Feb 21, 2001 at 05:55:11PM -0500, Pat/Bob Fisher wrote:
| 
|    I am pretty new at programming in Python, but have had experience in
|    programming in other languages.  I went through the tutorial which I
|    thought was fairly good, except the section on the methods of file
|    objects was pretty sparse.  It seems to me that dealing with files is
|    rather awkward. I have used the  list representation  filelist =
|    f.readlines() and then used the fine list methods to manipulate the
|    filelist, but I am having trouble getting a new file from  my new
|    filelist.  The g.write('string') gives me a whole lot of extraneous
|    stuff.

What kind of extraneous stuff?  f.readlines() gives you a list of
strings.  That list is completely independent of any files (except
that it happens to have originated from a file).

Use the dir() function on a file object in the interpreter to see all
the available functions of a file object.  Use
print fileobject.function.__doc__  to print the docstring.  (Or just
browse the library reference manual ;-))

If you use g.write( list_of_strings )  you will get "extra" stuff --
the visual representation of a list.  Use string.join() to concatenate
the strings in the list into a single string before writing it to a
file.

|    
|    Another problem I am having is trying  to open files in other
|    directories.  For example,
|    
|    
|    
|       f=open('C:\tmp\testfile','r+') just doesn't work for me.
                  ^^  ^^

These \t are tab characters, not \ followed by t.  IMO using \ to
delimit paths is evil, partly because it is inconsisten (POSIX/Unix
uses /) and more importantly because it is a special character in
strings in all the languages I've used (except for maybe Common Lisp).

One solution is to escape all \ in filename :

f = open( 'C:\\tmp\\testfile' , 'r+' )

or Python has a neat way of declaring a string as raw data :

f = open( r'c:\tmp\testfile' , 'r+' )

Also, I think tqs don't do any special character expansion :

f = open( """c:\tmp\testfile""" , 'r+' )

|    
|    Can anyone help, or at least tell me where I can learn more about file
|    manipulation?
|    
|    I suppose it is obvious I am using a windows platform, specifically
|    WindowsME.

Ugh.

|    

HTH,
-D



From chris@voodooland.net  Thu Feb 22 03:44:20 2001
From: chris@voodooland.net (Chris Watson)
Date: Wed, 21 Feb 2001 21:44:20 -0600 (CST)
Subject: [Tutor] Files and file attributes
In-Reply-To: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com>
Message-ID: <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net>

> Another problem I am having is trying  to open files in other directories.  For example,
>  
>    f=open('C:\tmp\testfile','r+') just doesn't work for me.

	ACK! First try using a mailer that word wraps at 80 lines :-)

Try using f = open("C:\tmp\testfile", "r")

Give that a shot. That should fix you right up. I get confused sometimes
between '' and "" for things as well. :-)

Chris





From tbrauch@mindless.com  Thu Feb 22 05:09:33 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Thu, 22 Feb 2001 00:09:33 -0500
Subject: [Tutor] Cards Program
Message-ID: <3A949F0D.A82F1C06@mindless.com>

Thanks for all the help so far.  What I thought would be a fairly simple
program has turned out to be one of the biggest projects I have
attempted so far.  I will keep in mind all of your suggestions and put
some real work into this over the weekend.  Hopefully by Monday I might
have made some progress, and when I am done, perhaps this is something
to post on Useless Python.

Of course, after I get the program worked out so it will deal cards to
players, the next step would be, as already suggested, to create rules
for games and use these hands in these games.  That will probably take a
little more than a weekend.

 - Tim


From scarblac@pino.selwerd.nl  Thu Feb 22 09:42:38 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 10:42:38 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010221194613.A25405@harmony.cs.rit.edu>; from dsh8290@rit.edu on Wed, Feb 21, 2001 at 07:46:14PM -0500
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <20010221194613.A25405@harmony.cs.rit.edu>
Message-ID: <20010222104238.A2146@pino.selwerd.nl>

On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
> Also, I think tqs don't do any special character expansion :
> 
> f = open( """c:\tmp\testfile""" , 'r+' )

They do, this one doesn't work. There are also *raw* tqs, ie r"""\t"""...

I repeat my favorite solution, as I see everybody else omits it :)

f = open("c:/tmp/testfile","r+")

Windows is perfectly ok with forward slashes. They keep it a bit of a secret
though...

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu Feb 22 09:48:10 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 10:48:10 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net>; from chris@voodooland.net on Wed, Feb 21, 2001 at 09:44:20PM -0600
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net>
Message-ID: <20010222104810.B2146@pino.selwerd.nl>

On Wed, Feb 21, 2001 at 09:44:20PM -0600, Chris Watson wrote:
> > Another problem I am having is trying  to open files in other directories.  For example,
> >  
> >    f=open('C:\tmp\testfile','r+') just doesn't work for me.
> 
> 	ACK! First try using a mailer that word wraps at 80 lines :-)
> 
> Try using f = open("C:\tmp\testfile", "r")
> 
> Give that a shot. That should fix you right up. I get confused sometimes
> between '' and "" for things as well. :-)

In Python, there is no difference between '' and "" strings except that you
need to escape ' in the first and " in the latter. You're confusing other
languages :)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu Feb 22 10:33:09 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 11:33:09 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net>; from chris@voodooland.net on Wed, Feb 21, 2001 at 09:44:20PM -0600
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net>
Message-ID: <20010222113309.A2262@pino.selwerd.nl>

On Wed, Feb 21, 2001 at 09:44:20PM -0600, Chris Watson wrote:
> > Another problem I am having is trying  to open files in other directories.  For example,
> >  
> >    f=open('C:\tmp\testfile','r+') just doesn't work for me.
> 
> 	ACK! First try using a mailer that word wraps at 80 lines :-)
> 
> Try using f = open("C:\tmp\testfile", "r")
> 
> Give that a shot. That should fix you right up. I get confused sometimes
> between '' and "" for things as well. :-)

In Python, there is no difference between '' and "" strings except that you
have to escape ' in the first and " in the latter.

Confused with other languages? :)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu Feb 22 10:36:40 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 11:36:40 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010222113309.A2262@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Feb 22, 2001 at 11:33:09AM +0100
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <Pine.BSF.4.21.0102212125250.3622-100000@open-systems.net> <20010222113309.A2262@pino.selwerd.nl>
Message-ID: <20010222113640.A2283@pino.selwerd.nl>

On Thu, Feb 22, 2001 at 11:33:09AM +0100, Remco Gerlich wrote:
<snip>

Sorry for sending that twice, I received a bounce message from some list
member and concluded that I hadn't sent it to the list.

-- 
Remco Gerlich


From dyoo@hkn.eecs.berkeley.edu  Thu Feb 22 11:02:26 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 22 Feb 2001 03:02:26 -0800 (PST)
Subject: [Tutor] Cards Program
In-Reply-To: <3A949F0D.A82F1C06@mindless.com>
Message-ID: <Pine.LNX.4.21.0102220301130.2589-100000@c82114-a.pinol1.sfba.home.com>

On Thu, 22 Feb 2001, Timothy M. Brauch wrote:

> Thanks for all the help so far.  What I thought would be a fairly
> simple program has turned out to be one of the biggest projects I have
> attempted so far.  I will keep in mind all of your suggestions and put
> some real work into this over the weekend.  Hopefully by Monday I
> might have made some progress, and when I am done, perhaps this is
> something to post on Useless Python.

Sounds good!


> Of course, after I get the program worked out so it will deal cards to
> players, the next step would be, as already suggested, to create rules
> for games and use these hands in these games.  That will probably take
> a little more than a weekend.

Don't worry about it.  Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Thu Feb 22 11:24:19 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 22 Feb 2001 03:24:19 -0800 (PST)
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <200102210819_MC2-C651-6593@compuserve.com>
Message-ID: <Pine.LNX.4.21.0102220321240.2589-100000@c82114-a.pinol1.sfba.home.com>

On Wed, 21 Feb 2001, Sharriff Aina wrote:

> can someone point me to a URL where I can RTFM "file uploads per HTTP
> in Python" for dummies? I would be extremly nice if someone posted a
> snippet to the list, that would give me a push in the right direction.

I'm not quite sure I understand your question yet; could you explain a
little more about what you're doing?

In the meantime, if you haven't seen it already, here's a link to the
httplib library documentation:

    http://python.org/doc/current/lib/module-httplib.html



From alan.gauld@bt.com  Thu Feb 22 11:36:03 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 22 Feb 2001 11:36:03 -0000
Subject: [Tutor] C to Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B0@mbtlipnt02.btlabs.bt.co.uk>

> How is Python like C/C++?  

They are all general purpose programming languages.

C/C++ programs will usually run faster but require 
that you write about 3 times as many lines of code 
to achieve the same end. 

C/C++ programs are compiled and usually easier to distribute but will only
work on the platform they were compiled for. Python willl usually work on
any platform with an interpreter installed.

> Can it do everything C/C++ can do?

No. 
It can also do things that C/C++ can't do.

Alan g.


From alan.gauld@bt.com  Thu Feb 22 11:52:10 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 22 Feb 2001 11:52:10 -0000
Subject: [Tutor] Python Usage Question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B2@mbtlipnt02.btlabs.bt.co.uk>

> While I'm glad learning Python helped you, 
> I tremble at the thought of using Python as 
> a ramp for Java. 
...
> But as someone who is
> (understatement) Not A Fan of Java, well....

Heh! I'm glad I'm not the only one who doesn't like Java.

<RANT>
I just don't see the point of it - it needs almost as 
much work as C++, runs much slower and is full of 
horrible inconsistencies and (IMHO) plain bad design.
For browser applets its a reasonable solution as a 
platform but for Server work and as a language it 
just seems weird the hype that's been built up.
The more I use Java the less I like it! Its the 
first "class based" language I've ever seen and 
confirms my belief that objects beat classes 
every time!
</RANT>

Alan g.


From alan.gauld@bt.com  Thu Feb 22 11:53:52 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 22 Feb 2001 11:53:52 -0000
Subject: [Tutor] C to Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B3@mbtlipnt02.btlabs.bt.co.uk>

> (BTW, the term "virtual" only really applies to C++, 

To be picky virtiual applies to several langueages, 
eg Object Pascal(aka Delphi) also uses virtual as 
a keyword.

Having a bad week so feeling picky...

Alan g


From alan.gauld@bt.com  Thu Feb 22 11:56:23 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 22 Feb 2001 11:56:23 -0000
Subject: [Tutor] Tkinter Question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B4@mbtlipnt02.btlabs.bt.co.uk>

> for any Tkinter programmer out there.  Consider that tiny 
> 'TK' icon that appears in the upper left-hand corner in 
> Windows Tkinter guis.  I'd like to replace that icon 

I've looked everywhere for a solution to this and can't 
find one. I don't understand why because the X windows 
version of Tk can do it and the Windows API can do it 
so why the Tk developers haven't  provided for it 
beats me...

If anyone knows different I look forward to the answer...

Alan g


From rob@jam.rr.com  Thu Feb 22 13:05:08 2001
From: rob@jam.rr.com (R. A.)
Date: Thu, 22 Feb 2001 07:05:08 -0600
Subject: [Tutor] Cards Program
References: <3A949F0D.A82F1C06@mindless.com>
Message-ID: <3A950E84.4B60D0C1@jam.rr.com>


"Timothy M. Brauch" wrote:
> 
> Thanks for all the help so far.  What I thought would be a fairly simple
> program has turned out to be one of the biggest projects I have
> attempted so far.  I will keep in mind all of your suggestions and put
> some real work into this over the weekend.  Hopefully by Monday I might
> have made some progress, and when I am done, perhaps this is something
> to post on Useless Python.

Your project is of course welcome on Useless Python, which itself has
turned into more than I had even hoped.

>  - Tim

The Useless Python Repository has received an XHTML face-lift!
http://www.lowerstandard.com/python/pythonsource.html


From arcege@shore.net  Thu Feb 22 13:19:35 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 22 Feb 2001 08:19:35 -0500 (EST)
Subject: [Tutor] Cards Program
In-Reply-To: <3A949F0D.A82F1C06@mindless.com> from "Timothy M. Brauch" at Feb 22, 2001 12:09:33 AM
Message-ID: <200102221319.IAA22530@northshore.shore.net>

> Thanks for all the help so far.  What I thought would be a fairly simple
> program has turned out to be one of the biggest projects I have
> attempted so far.  I will keep in mind all of your suggestions and put
> some real work into this over the weekend.  Hopefully by Monday I might
> have made some progress, and when I am done, perhaps this is something
> to post on Useless Python.

When you get done with the work over the weekend, you might want to
look in Demo/tkinter/guido/solitaire.py in the Python distribution.
But don't cheat! ;)

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From NHYTRO@compuserve.com  Thu Feb 22 13:58:21 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 22 Feb 2001 08:58:21 -0500
Subject: [Tutor] Help with CGI output
Message-ID: <200102220858_MC2-C669-540E@compuserve.com>

Hi guys!

I=B4m trying to generate thumbnails of images per CGI, somehow, my script=
 is
not behaving as it should, could someone please have a look at my code?
Please excuse my sloppy coding, this is a test scipt that I=B4ll clean up=

when I get everything working.

Thanks a million!

Sharriff


The code
----------------------
#!C:/Python/python.exe -u

print "Content-Type: text/html\n\n"


import cgi
import os
#
#

os.chdir("c:\\Xitami\medintouch\images")
test2 =3D os.getcwd()
print "<html><title>test</title>"
print '<body>'
print "<br></br>"
print "saving HTML file to disk..."
print "<br></br>"
print test2
print "<br></br>"
templist =3D os.listdir("c:\\Xitami\medintouch\images")
print '<table border=3D"1">'
for x in templist:
    print '<tr>'
    print '<td>'    =

    print x
    print '</td>'
    print '<td><img src=3D"'
    print '<img src=3D"'
    print 'http://10.104.98.70/medintouch/images'
  # print os.getcwd() + '\\' + x
    print '/' + x
    print '"></td>'
    print '<td><input type=3D"checkbox"></input></td>'
    print '<tr>'
print '</table>'
print '</body>'
print '</html>'


I just cant get the images to show up on my pages :-(


From dsh8290@rit.edu  Thu Feb 22 14:30:58 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 09:30:58 -0500
Subject: [Tutor] Re: A simple (newbie) question.
In-Reply-To: <9736r4+7on0@eGroups.com>; from mike.mellor@tbe.com on Thu, Feb 22, 2001 at 02:13:56PM +0000
References: <20010221121006.A23949@harmony.cs.rit.edu> <9736r4+7on0@eGroups.com>
Message-ID: <20010222093058.A29385@harmony.cs.rit.edu>

On Thu, Feb 22, 2001 at 02:13:56PM +0000, mike.mellor@tbe.com wrote:
| D - 
| I tried it, and couldn't make it work this way either.  Here is what 
| I got:
| 
| >>> eval(c)
| Traceback (most recent call last):
|   File "<pyshell#4>", line 1, in ?
|     eval(c)
|   File "<string>", line 1
|     print "Python"
|         ^
| SyntaxError: invalid syntax
| 
| 
| Am I doing something wrong?  Thanks.

Oh, yeah, I forgot -- Python makes a distinction between statements
and expressions.  eval() only works on expressions and returns the
value of the expression.  exec() handles statements, but doesn't
return anything.  (If I had tried what I suggested I would have seen
it not work)  For this example, use  exec( c )  If you want to try
eval, try something like

a = "3"
b = "4" 
c = a + " + " + b
d = eval( c )
print d


(I tested this this time ;-))

-D

PS.  I believe that Common Lisp and Scheme don't make this
distinction since all "statements" are actually functions.  The funny
thing is I haven't used CL or Scheme much so I should remember the
Python way more than the Lisp way.



From Lindsay.Davies@moonshine.co.uk  Thu Feb 22 14:31:19 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Thu, 22 Feb 2001 14:31:19 +0000
Subject: [Tutor] Help with CGI output
In-Reply-To: <200102220858_MC2-C669-540E@compuserve.com>
References: <200102220858_MC2-C669-540E@compuserve.com>
Message-ID: <p0501044cb6bad1abc0d9@[195.102.186.233]>

These lines won't help things...

>     print 'http://10.104.98.70/medintouch/images'
>   # print os.getcwd() + '\\' + x
>     print '/' + x
>     print '"></td>'


They will output something like...

http://10.104.98.70/medintouch/images
/some.gif
"></td>

...which isn't going to make a web server terribly happy to oblige 
you because of the carriage returns output by the print statements 
which are screwing up the URL. You can wrap your HTML in triple 
quotes and use string formatting to make it easier to deal with. eg

print """<img src="http://10.104.98.70/medintouch/images/%s">""" % x




On 22/2/01, Sharriff Aina wrote about '[Tutor] Help with CGI output':
>Hi guys!
>
>I´m trying to generate thumbnails of images per CGI, somehow, my script is
>not behaving as it should, could someone please have a look at my code?
>Please excuse my sloppy coding, this is a test scipt that I´ll clean up
>when I get everything working.
>
>Thanks a million!
>
>Sharriff
>
>
>The code
>----------------------
>#!C:/Python/python.exe -u
>
>print "Content-Type: text/html\n\n"
>
>
>import cgi
>import os
>#
>#
>
>os.chdir("c:\\Xitami\medintouch\images")
>test2 = os.getcwd()
>print "<html><title>test</title>"
>print '<body>'
>print "<br></br>"
>print "saving HTML file to disk..."
>print "<br></br>"
>print test2
>print "<br></br>"
>templist = os.listdir("c:\\Xitami\medintouch\images")
>print '<table border="1">'
>for x in templist:
>     print '<tr>'
>     print '<td>'   
>     print x
>     print '</td>'
>     print '<td><img src="'
>     print '<img src="'
>     print 'http://10.104.98.70/medintouch/images'
>   # print os.getcwd() + '\\' + x
>     print '/' + x
>     print '"></td>'
>     print '<td><input type="checkbox"></input></td>'
>     print '<tr>'
>print '</table>'
>print '</body>'
>print '</html>'
>
>
>I just cant get the images to show up on my pages :-(
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From dsh8290@rit.edu  Thu Feb 22 14:32:31 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 09:32:31 -0500
Subject: [Tutor] C to Python
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B3@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Thu, Feb 22, 2001 at 11:53:52AM +0000
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B3@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010222093231.B29385@harmony.cs.rit.edu>

On Thu, Feb 22, 2001 at 11:53:52AM +0000, alan.gauld@bt.com wrote:
| > (BTW, the term "virtual" only really applies to C++, 
| 
| To be picky virtiual applies to several langueages, 
| eg Object Pascal(aka Delphi) also uses virtual as 
| a keyword.
| 

Oh, ok.  I haven't used Object Pascal before.

| Having a bad week so feeling picky...

I hope next week is better.

-D



From dsh8290@rit.edu  Thu Feb 22 14:36:39 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 09:36:39 -0500
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010222104238.A2146@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Feb 22, 2001 at 10:42:38AM +0100
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <20010221194613.A25405@harmony.cs.rit.edu> <"from dsh8290"@rit.edu> <20010222104238.A2146@pino.selwerd.nl>
Message-ID: <20010222093639.C29385@harmony.cs.rit.edu>

On Thu, Feb 22, 2001 at 10:42:38AM +0100, Remco Gerlich wrote:
| On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
| I repeat my favorite solution, as I see everybody else omits it :)
| 
| f = open("c:/tmp/testfile","r+")
| 
| Windows is perfectly ok with forward slashes. They keep it a bit of a secret
| though...

Oh, cool.  I like this!

-D



From ibraheem@micromuse.com  Thu Feb 22 14:48:48 2001
From: ibraheem@micromuse.com (Ibraheem Umaru-Mohammed)
Date: Thu, 22 Feb 2001 14:48:48 +0000
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010222093639.C29385@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Feb 22, 2001 at 09:36:39AM -0500
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <20010221194613.A25405@harmony.cs.rit.edu> <"from <20010222104238.A2146@pino.selwerd.nl> <20010222093639.C29385@harmony.cs.rit.edu>
Message-ID: <20010222144848.A320@micromuse.com>

> On Thu, Feb 22, 2001 at 10:42:38AM +0100, Remco Gerlich wrote:
> | On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
> | I repeat my favorite solution, as I see everybody else omits it :)
> | 
> | f = open("c:/tmp/testfile","r+")
> | 
> | Windows is perfectly ok with forward slashes. They keep it a bit of a secret
> | though...

is this a "Windows" feature or a Python induced platform specific translation?
I thought forward slashes were used for something like environmental
variables or something. ???

Kindest regards,

	--ibs.

--
---------------------------------------------------------------------------
			--  Ibraheem Umaru-Mohammed  --
			--  Email:ium@micromuse.com  --
-- Micromuse PLC, Disraeli House, 90 Putney Bridge Road, London SW18 1DA --
			--  http://www.micromuse.com --
---------------------------------------------------------------------------


From lumbricus@gmx.net  Thu Feb 22 15:14:12 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Thu, 22 Feb 2001 16:14:12 +0100 (MET)
Subject: [Tutor] Files and file attributes
References: <20010222144848.A320@micromuse.com>
Message-ID: <5137.982854852@www25.gmx.net>

> > On Thu, Feb 22, 2001 at 10:42:38AM +0100, Remco Gerlich wrote:
> > | On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
> > | I repeat my favorite solution, as I see everybody else omits it :)
> > | 
> > | f = open("c:/tmp/testfile","r+")
> > | 
> > | Windows is perfectly ok with forward slashes. They keep it a bit of a
> secret
> > | though...
> 
> is this a "Windows" feature or a Python induced platform specific
> translation?
> I thought forward slashes were used for something like environmental
> variables or something. ???

Jo -- windows interprets the string following a slash as a commandline
argument.

greets jö!

-------------------------------------------------------------------

-- 
Sent through GMX FreeMail - http://www.gmx.net


From dsh8290@rit.edu  Thu Feb 22 16:08:30 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 11:08:30 -0500
Subject: [Tutor] Files and file attributes
In-Reply-To: <5137.982854852@www25.gmx.net>; from lumbricus@gmx.net on Thu, Feb 22, 2001 at 04:14:12PM +0100
References: <20010222144848.A320@micromuse.com> <5137.982854852@www25.gmx.net>
Message-ID: <20010222110830.C29565@harmony.cs.rit.edu>

On Thu, Feb 22, 2001 at 04:14:12PM +0100, J=F6rg W=F6lke wrote:
| > > On Thu, Feb 22, 2001 at 10:42:38AM +0100, Remco Gerlich wrote:
| > > | On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
| > > | I repeat my favorite solution, as I see everybody else omits it :=
)
| > > |=20
| > > | f =3D open("c:/tmp/testfile","r+")
| > > |=20
| > > | Windows is perfectly ok with forward slashes. They keep it a bit =
of a
| > secret
| > > | though...
| >=20
| > is this a "Windows" feature or a Python induced platform specific
| > translation?
| > I thought forward slashes were used for something like environmental
| > variables or something. ???
|=20
| Jo -- windows interprets the string following a slash as a commandline
| argument.

At least, in a DOS shell it does.  Then the question becomes  Is it
Windows or the DOS shell that interprets slash in that manner?  I use
bash anyways so I use / for paths (and use cygpath to convert it for
Windows-only apps) and - or -- for arguments usually.  I don't use the
DOS utilities that want / for arguments.

Java also allows using / for a path delimiter in some contexts (such
as this.getClass().getResource(
"/path/to/some/resource/probably/in/a/jar/file" ) )

I suppose one way to test that would be to write a C/C++ app that used
a forward slash and see if it works.  If not, then it is a Python
feature, not a Windows one.

-D



From alan.gauld@bt.com  Thu Feb 22 16:00:13 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 22 Feb 2001 16:00:13 -0000
Subject: [Tutor] Help with CGI output
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5BB@mbtlipnt02.btlabs.bt.co.uk>

I'm guessing here but...

> print "<html><title>test</title>"

Shouldn't there be <head></head> tags in there too?

> ....
>     print '<td><img src="'
>     print '<img src="'
>     print 'http://10.104.98.70/medintouch/images'
>     print '/' + x
>     print '"></td>'
Will output:

<td><img src="
http://10.104.98.70/medintouch/images
/someXvalue
"></td>

I'm not sure whether breaking the url like that is a 
good idea, it might be better to build the whole img 
tag as a string then print it... but I don't do much 
CGI som maybe it won't matter.

>     print '<td><input type="checkbox"></input></td>'

Won't that need to be inside a <form>,/form> pair to 
take effect?


Just some random thoughts!

Alan G


From NHYTRO@compuserve.com  Thu Feb 22 16:22:22 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 22 Feb 2001 11:22:22 -0500
Subject: [Tutor] Help with CGI output
Message-ID: <200102221122_MC2-C67C-DD27@compuserve.com>

Thanks Alan!

I noticed  an hour ago the same mistakes, this is what it looks like now:=


######################################

#!C:/Python/python.exe -u

print "Content-Type: text/html\n\n"


import cgi
import os
#
os.chdir("c:\\Xitami\medintouch\images")
test2 =3D os.getcwd()
print "<html><head><title>test</title></head>"
print '<body>'
print "<br></br>"
print "<h3>Available images on server</h3>"
#print "<br></br>"
#print test2
print "<br></br>"
templist =3D os.listdir("c:\\Xitami\medintouch\images")
print '<table border=3D"1">'
for x in templist:
    print '<tr>'
    print '<td>'    =

    print x
    print '</td>'
    print '<td>'
    print '<img src=3D"'
    print '../images'
  # print os.getcwd() + '\\' + x
    print '/' + x
    print '"></td>'
    print '<td><input type=3D"button" value=3D"insert image"></input></td=
>'
    print '<tr>'
print '<tr><td>&nbsp</td></tr>'
print '<tr><td><input type=3D"submit" value=3D"insert image"></td></tr>'
print '</table>'
print '</body>'
print '</html>'
##### end of script #########

this works, although very dirty.. all I need now is someone to show me ho=
w
to write an upload script for the images..

Thanks for your reply Alan!

Regards

Sharriff

 =

I'm guessing here but...

> print "<html><title>test</title>"

Shouldn't there be <head></head> tags in there too?

> ....
>     print '<td><img src=3D"'
>     print '<img src=3D"'
>     print 'http://10.104.98.70/medintouch/images'
>     print '/' + x
>     print '"></td>'
Will output:

<td><img src=3D"
http://10.104.98.70/medintouch/images
/someXvalue
"></td>

I'm not sure whether breaking the url like that is a =

good idea, it might be better to build the whole img =

tag as a string then print it... but I don't do much =

CGI som maybe it won't matter.

>     print '<td><input type=3D"checkbox"></input></td>'

Won't that need to be inside a <form>,/form> pair to =

take effect?


Just some random thoughts!

Alan G




----------------------- Internet Header --------------------------------
Sender: alan.gauld@bt.com
Received: from gollum.axion.bt.co.uk (gollum.axion.bt.co.uk
[132.146.17.41])
        by spdmgaae.compuserve.com (8.9.3/8.9.3/SUN-1.9) with ESMTP id
LAA17615
        for <NHYTRO@compuserve.com>; Thu, 22 Feb 2001 11:09:35 -0500 (EST=
)
From: alan.gauld@bt.com
Received: from cbtlipnt02.btlabs.bt.co.uk by gollum (local) with ESMTP;
          Thu, 22 Feb 2001 16:04:14 +0000
Received: by cbtlipnt02.btlabs.bt.co.uk =

          with Internet Mail Service (5.5.2652.35) id <1PP7WPG5>;
          Thu, 22 Feb 2001 16:00:26 -0000
Message-ID:
<5104D4DBC598D211B5FE0000F8FE7EB20751D5BB@mbtlipnt02.btlabs.bt.co.uk>
To: NHYTRO@compuserve.com, tutor@python.org
Subject: RE: [Tutor] Help with CGI output
Date: Thu, 22 Feb 2001 16:00:13 -0000
X-Mailer: Internet Mail Service (5.5.2652.35)
MIME-version: 1.0
Content-type: text/plain; charset=3D"iso-8859-1"


 =

I'm guessing here but...

> print "<html><title>test</title>"

Shouldn't there be <head></head> tags in there too?

> ....
>     print '<td><img src=3D"'
>     print '<img src=3D"'
>     print 'http://10.104.98.70/medintouch/images'
>     print '/' + x
>     print '"></td>'
Will output:

<td><img src=3D"
http://10.104.98.70/medintouch/images
/someXvalue
"></td>

I'm not sure whether breaking the url like that is a =

good idea, it might be better to build the whole img =

tag as a string then print it... but I don't do much =

CGI som maybe it won't matter.

>     print '<td><input type=3D"checkbox"></input></td>'

Won't that need to be inside a <form>,/form> pair to =

take effect?


Just some random thoughts!

Alan G




----------------------- Internet Header --------------------------------
Sender: alan.gauld@bt.com
Received: from gollum.axion.bt.co.uk (gollum.axion.bt.co.uk
[132.146.17.41])
        by spdmgaae.compuserve.com (8.9.3/8.9.3/SUN-1.9) with ESMTP id
LAA17615
        for <NHYTRO@compuserve.com>; Thu, 22 Feb 2001 11:09:35 -0500 (EST=
)
From: alan.gauld@bt.com
Received: from cbtlipnt02.btlabs.bt.co.uk by gollum (local) with ESMTP;
          Thu, 22 Feb 2001 16:04:14 +0000
Received: by cbtlipnt02.btlabs.bt.co.uk =

          with Internet Mail Service (5.5.2652.35) id <1PP7WPG5>;
          Thu, 22 Feb 2001 16:00:26 -0000
Message-ID:
<5104D4DBC598D211B5FE0000F8FE7EB20751D5BB@mbtlipnt02.btlabs.bt.co.uk>
To: NHYTRO@compuserve.com, tutor@python.org
Subject: RE: [Tutor] Help with CGI output
Date: Thu, 22 Feb 2001 16:00:13 -0000
X-Mailer: Internet Mail Service (5.5.2652.35)
MIME-version: 1.0
Content-type: text/plain; charset=3D"iso-8859-1"



Message text written by INTERNET:alan.gauld@bt.com
> =

I'm guessing here but...

> print "<html><title>test</title>"

Shouldn't there be <head></head> tags in there too?

> ....
>     print '<td><img src=3D"'
>     print '<img src=3D"'
>     print 'http://10.104.98.70/medintouch/images'
>     print '/' + x
>     print '"></td>'
Will output:

<td><img src=3D"
http://10.104.98.70/medintouch/images
/someXvalue
"></td>

I'm not sure whether breaking the url like that is a =

good idea, it might be better to build the whole img =

tag as a string then print it... but I don't do much =

CGI som maybe it won't matter.

>     print '<td><input type=3D"checkbox"></input></td>'

Won't that need to be inside a <form>,/form> pair to =

take effect?


Just some random thoughts!

Alan G




----------------------- Internet Header --------------------------------
Sender: alan.gauld@bt.com
Received: from gollum.axion.bt.co.uk (gollum.axion.bt.co.uk
[132.146.17.41])
        by spdmgaae.compuserve.com (8.9.3/8.9.3/SUN-1.9) with ESMTP id
LAA17615
        for <NHYTRO@compuserve.com>; Thu, 22 Feb 2001 11:09:35 -0500 (EST=
)
From: alan.gauld@bt.com
Received: from cbtlipnt02.btlabs.bt.co.uk by gollum (local) with ESMTP;
          Thu, 22 Feb 2001 16:04:14 +0000
Received: by cbtlipnt02.btlabs.bt.co.uk =

          with Internet Mail Service (5.5.2652.35) id <1PP7WPG5>;
          Thu, 22 Feb 2001 16:00:26 -0000
Message-ID:
<5104D4DBC598D211B5FE0000F8FE7EB20751D5BB@mbtlipnt02.btlabs.bt.co.uk>
To: NHYTRO@compuserve.com, tutor@python.org
Subject: RE: [Tutor] Help with CGI output
Date: Thu, 22 Feb 2001 16:00:13 -0000
X-Mailer: Internet Mail Service (5.5.2652.35)
MIME-version: 1.0
Content-type: text/plain; charset=3D"iso-8859-1"

<



From dsh8290@rit.edu  Thu Feb 22 16:32:58 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 11:32:58 -0500
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <200102210819_MC2-C651-6593@compuserve.com>; from NHYTRO@compuserve.com on Wed, Feb 21, 2001 at 08:19:07AM -0500
References: <200102210819_MC2-C651-6593@compuserve.com>
Message-ID: <20010222113258.A29612@harmony.cs.rit.edu>

On Wed, Feb 21, 2001 at 08:19:07AM -0500, Sharriff Aina wrote:
| Hi there!
| 
| can someone point me to a URL where I can RTFM "file uploads per HTTP in
| Python" for dummies? I would be extremly nice if  someone posted a snippet
| to the list, that would give me a push in the right direction.
| 

I don't think this is generally possible/(easily) feasible.  AFAIK
HTTP is intended for recieving.  I know that Hotmail allows this for
putting attachments in e-mail, so a work-around exists.  I think you
would need to have a form that causes a script on the server to run.
That script would have to be able to read from the local disk (on the
client) and then write to the disk on the server.  I'm not sure how to
get the file from the client's disk though.  Perhaps the data could be
included in the form submission?

If you can get FTP or rsync access to the server it would be easier.

-D



From gibbs05@flash.net  Thu Feb 22 18:49:07 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Thu, 22 Feb 2001 12:49:07 -0600
Subject: [Tutor] Tkinter Question
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B4@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <005b01c09d00$299279c0$c8df3040@gibbs05>

Greetings Alan & All,

Alan, I understand from this that you believe a modification to Tk itself
would have to be made?  I'm a bit surprised too.

I guess my next step, unless Alan has already tried this, would be to post
this question in comp.lang.tcl and see if anyone speaks up.  I'm also
considering e-mailing Fredrik Lundh about this topic to see what he knows.
Does anyone know if he's a friendly sort?  Alan, have you already tried that
route also?

A cursory glance at comp.lang.tcl revealed something called TkTable!!!  A
Tkinter table widget would be much more useful than that little icon. :-)


Thanks,
Sam

> > for any Tkinter programmer out there.  Consider that tiny
> > 'TK' icon that appears in the upper left-hand corner in
> > Windows Tkinter guis.  I'd like to replace that icon
>
> I've looked everywhere for a solution to this and can't
> find one. I don't understand why because the X windows
> version of Tk can do it and the Windows API can do it
> so why the Tk developers haven't  provided for it
> beats me...
>
> If anyone knows different I look forward to the answer...
>
> Alan g



From patrick_fourc@wanadoo.fr  Thu Feb 22 18:59:14 2001
From: patrick_fourc@wanadoo.fr (Patrick Fourcade)
Date: Thu, 22 Feb 2001 19:59:14 +0100
Subject: [Tutor] File browser
Message-ID: <006401c09d01$8d10f200$df8424d5@univpau.fr>

C'est un message de format MIME en plusieurs parties.

------=_NextPart_000_0061_01C09D09.EE1CB860
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello, I'm a french student looking for a file browser written in Python =
to
include it in my study project.

Does anyone got it ?


Thanks

------=_NextPart_000_0061_01C09D09.EE1CB860
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Hello, I'm a french student looking for a file browser written in =
Python=20
to<BR>include it in my study project.<BR><BR>Does anyone got it=20
?<BR><BR><BR>Thanks</DIV></BODY></HTML>

------=_NextPart_000_0061_01C09D09.EE1CB860--



From rick@niof.net  Thu Feb 22 19:01:29 2001
From: rick@niof.net (Rick Pasotto)
Date: Thu, 22 Feb 2001 14:01:29 -0500
Subject: [Tutor] Tkinter Question
In-Reply-To: <005b01c09d00$299279c0$c8df3040@gibbs05>; from gibbs05@flash.net on Thu, Feb 22, 2001 at 12:49:07PM -0600
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5B4@mbtlipnt02.btlabs.bt.co.uk> <005b01c09d00$299279c0$c8df3040@gibbs05>
Message-ID: <20010222140129.B5869@tc.niof.net>

On Thu, Feb 22, 2001 at 12:49:07PM -0600, Harry Kattz wrote:
> 
>   I'm also considering e-mailing Fredrik Lundh about this topic to see
>   what he knows.  Does anyone know if he's a friendly sort? 

Lundh posts numerous, friendly replies to comp.lang.python on a daily
basis.

-- 
"The care of every man's soul belongs to himself.  But what if he
neglect the care of it?  Well what if he neglect the care of his
health or his estate, which would more nearly relate to the state.
Will the magistrate make a law that he not be poor or sick?  Laws
provide against injury from others; but not from ourselves.  God
himself will not save men against their wills."
		-- Thomas Jefferson 1776-10
		   Rick Pasotto email: rickp@telocity.com


From scarblac@pino.selwerd.nl  Thu Feb 22 20:10:55 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 21:10:55 +0100
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010222144848.A320@micromuse.com>; from ibraheem@micromuse.com on Thu, Feb 22, 2001 at 02:48:48PM +0000
References: <000401c09c59$6dc31de0$fefe8e18@hendersonville.mediacom.ispchannel.com> <20010221194613.A25405@harmony.cs.rit.edu> <"from <20010222104238.A2146@pino.selwerd.nl> <20010222093639.C29385@harmony.cs.rit.edu> <20010222144848.A320@micromuse.com>
Message-ID: <20010222211055.A3223@pino.selwerd.nl>

On Thu, Feb 22, 2001 at 02:48:48PM +0000, Ibraheem Umaru-Mohammed wrote:
> > On Thu, Feb 22, 2001 at 10:42:38AM +0100, Remco Gerlich wrote:
> > | On Wed, Feb 21, 2001 at 07:46:14PM -0500, D-Man wrote:
> > | I repeat my favorite solution, as I see everybody else omits it :)
> > | 
> > | f = open("c:/tmp/testfile","r+")
> > | 
> > | Windows is perfectly ok with forward slashes. They keep it a bit of a secret
> > | though...
> 
> is this a "Windows" feature or a Python induced platform specific translation?
> I thought forward slashes were used for something like environmental
> variables or something. ???

This is a Windows feature. Actually, DOS system calls also supported it both
forms, at least that's what I've heard.

Some DOS commands accept command line options with a /, like dir /p, but
that has nothing to do with this.

(I've know all this only from posts to comp.lang.python and the like, I
don't use Windows myself, but try it out, it'll work...)
-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu Feb 22 20:18:20 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 22 Feb 2001 21:18:20 +0100
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <20010222113258.A29612@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Feb 22, 2001 at 11:32:58AM -0500
References: <200102210819_MC2-C651-6593@compuserve.com> <20010222113258.A29612@harmony.cs.rit.edu>
Message-ID: <20010222211820.B3223@pino.selwerd.nl>

On Thu, Feb 22, 2001 at 11:32:58AM -0500, D-Man wrote:
> On Wed, Feb 21, 2001 at 08:19:07AM -0500, Sharriff Aina wrote:
> | Hi there!
> | 
> | can someone point me to a URL where I can RTFM "file uploads per HTTP in
> | Python" for dummies? I would be extremly nice if  someone posted a snippet
> | to the list, that would give me a push in the right direction.
> | 
> 
> I don't think this is generally possible/(easily) feasible.  AFAIK
> HTTP is intended for recieving. 

This is not true, HTTP does PUT requests as well as GET requests. It's just
that most servers have the option turned off. Assuming that he has it turned
on, it shouldn't be a problem.

With httplib, a snippet for putting index.html would look something like this:

import httplib
connection = httplib.HTTP("www.mywebserver.org",80)
connection.putrequest('PUT','/index.html')
connection.putheader('Content-type','text/html') # Guessing
connection.endheaders()
connection.send('<html></html>') # Insert your data here
connection.getreply() # Send everything, stop sending, get some reply

Something like this would work, but I haven't tried it out.

-- 
Remco Gerlich


From dsh8290@rit.edu  Thu Feb 22 20:24:17 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 22 Feb 2001 15:24:17 -0500
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <20010222211820.B3223@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Feb 22, 2001 at 09:18:20PM +0100
References: <200102210819_MC2-C651-6593@compuserve.com> <20010222113258.A29612@harmony.cs.rit.edu> <"from dsh8290"@rit.edu> <20010222211820.B3223@pino.selwerd.nl>
Message-ID: <20010222152417.A1726@harmony.cs.rit.edu>

On Thu, Feb 22, 2001 at 09:18:20PM +0100, Remco Gerlich wrote:
| This is not true, HTTP does PUT requests as well as GET requests. It's just
| that most servers have the option turned off. Assuming that he has it turned
| on, it shouldn't be a problem.

I haven't heard of such a thing before.  Ok, hope it works for you ...

:-)

-D


From arcege@shore.net  Thu Feb 22 20:49:04 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 22 Feb 2001 15:49:04 -0500 (EST)
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <200102210819_MC2-C651-6593@compuserve.com> from "Sharriff Aina" at Feb 21, 2001 08:19:07 AM
Message-ID: <200102222049.PAA06831@northshore.shore.net>

> can someone point me to a URL where I can RTFM "file uploads per HTTP in
> Python" for dummies? I would be extremly nice if  someone posted a snippe=
> t
> to the list, that would give me a push in the right direction.

I don't know about a generalized document for file uploads (I assume
through a <INPUT type="file"> tag).  But Python can certainly support
this through the cgi.py module.  What happens is that instead of the
usual application/x-www-form-urlencoded Mime type, multipart/form-data
is sent from the client (this is ONLY for post method forms).  Within
the Mime data is the contents of the file, this is accessible from
the CGI form object.  Read the cgi.__doc__ doc string for a semi-
decent explaination.

import cgi
form = cgi.FieldStorage()
if form.has_key('file'):  # from <INPUT name="file"...>
    fileitem = form['file']
    if fileitem.file:
        contents = []
        line = fileitem.file.readline()
        while line:
            bytes = len(len)
            contents.append( line )
            line = fileitem.file.readline()
            if fileitem.length != -1 and fileitem.length != bytes:
                raise ValueError("data read not same as Content-Length")
        # get the client-given filename, the contents and length
        file = (fileitem.filename, contents, fileitem.length)

Or instead of reading all the lines, you can open a new file (in a
location accessible to the web server) and write the thumbnail data to
that.

About the only other documentation that I've found for this is in
O'Reilly's "CGI Programming on the World Wide Web" (it's a perl based
book *blech*).

Good luck,
  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From albert@vsys.com  Thu Feb 22 21:18:24 2001
From: albert@vsys.com (Albert Hook)
Date: Thu, 22 Feb 2001 14:18:24 -0700
Subject: [Tutor] embedding a simple C++ program
Message-ID: <3A958220.D9348916@vsys.com>

Hi,
I have a HelloWorld program, Header, body and a main body that calls
helloworld. In that header and body I have a printHelloWorld function.
I want to acces the methods that I create in the class HelloWorld with
Python via the shared object.

Do I do that by importing that function into python by simply having a
init function that calls the is has the following,

PyObject *m;
m = Py_InitModule("helloworld". HelloWorldMethods);

Or is it much more difficult than that, if it is can I see an example.
I have tried to use the tutorial and the demo.c, the latter doesn't
compile and I can't see how I can access C++ methods with the tutorial.

Thanks,
Albert Hook




From tim.one@home.com  Thu Feb 22 22:06:37 2001
From: tim.one@home.com (Tim Peters)
Date: Thu, 22 Feb 2001 17:06:37 -0500
Subject: [Tutor] Files and file attributes
In-Reply-To: <20010222144848.A320@micromuse.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCIEFDJBAA.tim.one@home.com>

[attribution lost]
> f = open("c:/tmp/testfile","r+")
>
> Windows is perfectly ok with forward slashes. They keep it a
> bit of a secret though...

[Ibraheem Umaru-Mohammed]
> is this a "Windows" feature or a Python induced platform specific
> translation?

Python never does any translation of path strings on any platform, unless
you explicitly invoke functions like os.path.normpath().  All of the native
Windows API calls, and all the C libraries under Windows, accept forward or
backward slashes (or mixtures).  The DOS shell (command.com on Win9X,
cmd.exe on NT/2000) is what insists on backslashes, becase it uses forward
slashes to mark command arguments.  Note, though, that Python's os.system()
passes its argument to a newly-created DOS shell on Windows, so pathnames in
that do need to use backslashes.

consistency-is-overrated<wink>-ly y'rs  - tim



From Carolali@btinternet.com  Thu Feb 15 18:57:50 2001
From: Carolali@btinternet.com (Carol Ali)
Date: Thu, 15 Feb 2001 18:57:50 -0000
Subject: [Tutor] help
Message-ID: <006901c09781$320f1b00$24f67ad5@e9d2a5>

This is a multi-part message in MIME format.

------=_NextPart_000_0066_01C09781.3168C8E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,How do I tie up TclTk with Python?.Carol.

------=_NextPart_000_0066_01C09781.3168C8E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,How do I tie up TclTk with=20
Python?.Carol.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0066_01C09781.3168C8E0--



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 00:51:26 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 22 Feb 2001 16:51:26 -0800 (PST)
Subject: [Tutor] File uploads perr HTTP (fwd)
Message-ID: <Pine.LNX.4.21.0102221651160.2488-100000@c82114-a.pinol1.sfba.home.com>


---------- Forwarded message ----------
Date: Thu, 22 Feb 2001 07:33:29 -0500
From: Sharriff Aina <NHYTRO@compuserve.com>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] File uploads perr HTTP

Hi Danny!

I would actually like to code a webpage with the pssibility to upload and
browse images on a webserver, the clients are=B4nt that much PC literate so=
 I
would prefer that they just "search" for the image on a local or remote
drive then click to upload to a directory on the server..

Regards

Sharriff


Message text written by Danny Yoo
>On Wed, 21 Feb 2001, Sharriff Aina wrote:

> can someone point me to a URL where I can RTFM "file uploads per HTTP
> in Python" for dummies? I would be extremly nice if someone posted a
> snippet to the list, that would give me a push in the right direction.

I'm not quite sure I understand your question yet; could you explain a
little more about what you're doing?

In the meantime, if you haven't seen it already, here's a link to the
httplib library documentation:

    http://python.org/doc/current/lib/module-httplib.html
<



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 01:11:30 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 22 Feb 2001 17:11:30 -0800 (PST)
Subject: [Tutor] help
In-Reply-To: <006901c09781$320f1b00$24f67ad5@e9d2a5>
Message-ID: <Pine.LNX.4.21.0102221709400.2488-100000@c82114-a.pinol1.sfba.home.com>

On Thu, 15 Feb 2001, Carol Ali wrote:

> Hi,How do I tie up TclTk with Python?.Carol.

The "Tkinter" module in Python takes care of the details; you may want to
look at the Tkinter topic guide, which has quite a few tutorials about
this:

    http://python.org/topics/tkinter/

Also, I've heard that "Python and Tkinter Programming" is one of the
definitive books on this subject; if you're going to do serious Tk/Tcl
stuff, you may want to invest in this book.

Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 01:17:01 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 22 Feb 2001 17:17:01 -0800 (PST)
Subject: [Tutor] [Python-Help] Anita Panda: request (fwd)
Message-ID: <Pine.LNX.4.21.0102221716010.2716-100000@c82114-a.pinol1.sfba.home.com>

This looks like an interesting question; can anyone point out a good
Python OOP tutorial for Anita?


---------- Forwarded message ----------
Date: Wed, 21 Feb 2001 21:29:21 -0500
From: Guido van Rossum <guido@digicool.com>
To: help@python.org
Subject: [Python-Help] Anita Panda: request

Anybody know a good tutorial on the web that explains classes and
inheritance for newbies?  (I'd like to hear about one myself too!)

--Guido van Rossum (home page: http://www.python.org/~guido/)

------- Forwarded Message

Date:    Fri, 09 Feb 2001 13:04:36 +0530
From:    Anita Panda <anita.panda@uulogic.com>
To:      webmaster@python.org
Subject: request

sir
       Regarding the class & inheritance of python language Pls tell the
good site or give us some tips.
Its not clearly given in the tutorial.Here at india  python books are
not available also.
                                                            Anita



From jdrake@jam.rr.com  Fri Feb 23 03:23:36 2001
From: jdrake@jam.rr.com (Jason Drake)
Date: Thu, 22 Feb 2001 21:23:36 -0600
Subject: [Tutor] CGI and Better Programming Practice
Message-ID: <00e001c09d48$027c98a0$80c8a418@jam.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_00DD_01C09D15.B78E3C40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I've been rather silent lately because of other projects, but I'm taking =
some time again tonight to play around again in the Python/CGI arena. =
When last I sat here playing with the snake... err... Python that is, =
not my John Thomas, I managed to piece together a simple bit of code =
which used the Python CGI module to extract information passed by an =
HTML form using the post method and print it using basic HTML statements =
combined with Python to a fresh page. I then took a little time to =
pretty both the form and the output up just a little, and will probably =
do a little more of that tonight also. (Hey, we've gotta have balance, =
right?)=20

So I manage to get info from a user and print it back to him/her which =
is great and I then determine to forge ahead and, with a little =
prompting (competition is good) from Random, I set out to have the next =
incarnation spit out the circumference of a circle based on the radius =
as supplied by the user. Wow! Neat! I managed to get it to work... =
almost. It happily dropped decimal places on me so I was back to the =
research. After a few more moments of banging my head against the =
monitor and a few hints and suggestions alluding to the eventual =
conclusion I manage to figure out how to control the variables to have =
them output as floating point and no longer lose my decimals! Yay! =
Having done it once, I figure I need to test that bit of learning a =
little further and recode the whole thing over again, only this time I =
change up the equations and have the code output the area instead of the =
circumference.

Okay, so here is where the success story pauses and I look for more =
info. 1st off, although I know I can keep on cruising along as I am and =
end up making mammoth sized programs that work, I know for fact that I =
really need to start figuring out how to break my programs up into =
'modules' or 'snippets' which can be written once and used repeatedly. =
Also, the next step in my gameplan of learning to use Python as an =
effective programming language for CGI programming is learning to write =
to a file. Specifically what I am wanting to do (as a first measure) is =
to extract the data from the form, format the data as a comma delimited =
string with double-quote qualifiers and append the line to a text file =
such as testrun.csv. Why a .csv? Well, simply put, I've found .csv files =
to be astoundingly versatile and easy to use with most mainstream =
programs. It's very easy for me, for instance, to download a .csv file =
with a header row and import it into an Access table, work with the data =
and use it effectively in my day-to-day life for printing labels, =
sending form letters, etc. Also, it's a format I've used for so many =
years now for so many reasons that I'm simply all too familiar with it =
which allows a little extra comfort in my life. (Don't worry, I am =
working toward the eventuality of using a SQL database, the .csv thing =
is just a step.)

These things said and a cold Heineken at my side, I would post the code =
thus far, but would rather not stick so much bad code into one document =
:) Instead I'll post the offensive code at =
www.lowerstandard.com/frik/thecode.html by way of links to .txt =
documents for the curious to peruse as well as links to the actual =
working versions. Give me 5-10 minutes and it'll be there.

Jay

PS - I am documenting this learning experience as I go along and *WILL* =
at the 'end' be uploading what I hope will be a fairly good tutorial =
with practical examples of each of the experiences I have to =
lowerstandard.com when I get to a point that I feel that I can make a =
contribution that some poor schmoe like me would appreciate and =
understand ;)

------=_NextPart_000_00DD_01C09D15.B78E3C40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>
<DIV><FONT face=3DArial size=3D2>I've been rather silent lately because =
of other=20
projects, but I'm taking some time again tonight to play around again in =
the=20
Python/CGI arena. When last I sat here playing with the snake... err... =
Python=20
that is, not my John Thomas, I managed to piece together a simple bit of =
code=20
which used the Python CGI module to extract information passed by an =
HTML form=20
using the post method and print it using basic HTML statements combined =
with=20
Python to a fresh page. I then took a little time to pretty both the =
form and=20
the output up just a little, and will probably do a little more of that =
tonight=20
also. (Hey, we've gotta have balance, right?) </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So I manage to get info from a user and =
print it=20
back to him/her which is great and I then determine to forge ahead and, =
with a=20
little prompting (competition is good) from Random, I set out to have =
the next=20
incarnation spit out the circumference of a circle based on the radius =
as=20
supplied by the user. Wow! Neat! I managed to get it to work... almost. =
It=20
happily dropped decimal places on me so I was back to the research. =
After a few=20
more moments of banging my head against the monitor and a few hints and=20
suggestions alluding to the eventual conclusion I manage to figure out =
how to=20
control the variables to have them output as floating point and no =
longer lose=20
my decimals! Yay! Having done it once, I figure I need to test that bit =
of=20
learning a little further and recode the whole thing over again, only =
this time=20
I change up the equations and have the code output the area instead of =
the=20
circumference.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Okay, so here is where the success =
story pauses and=20
I look for more info. 1st off, although I know I can keep on cruising =
along as I=20
am and end up making mammoth sized programs that work, I know for fact =
that I=20
really need to start figuring out how to break my programs up into =
'modules' or=20
'snippets' which can be written once and used repeatedly. Also, the next =
step in=20
my gameplan of learning to use Python as an effective programming =
language for=20
CGI programming is learning to write to a file. Specifically what I am =
wanting=20
to do (as a first measure) is to extract the data from the form, format =
the data=20
as a comma delimited string with double-quote qualifiers and append the =
line to=20
a text file such as testrun.csv. Why a .csv? Well, simply put, I've =
found .csv=20
files to be astoundingly versatile and easy to use with most mainstream=20
programs. It's very easy for me, for instance, to download a .csv file =
with a=20
header row and import it into an Access table, work with the data and =
use it=20
effectively in my day-to-day life for printing labels, sending form =
letters,=20
etc. Also, it's a format I've used for so many years now for so many =
reasons=20
that I'm simply all too familiar with it which allows a little extra =
comfort in=20
my life. (Don't worry, I am working toward the eventuality of using a =
SQL=20
database, the .csv thing is just a step.)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>These things said and a cold Heineken =
at my side, I=20
would post the code thus far, but would rather not stick so much bad =
code into=20
one document :) Instead I'll post the offensive code at <A=20
href=3D"http://www.lowerstandard.com/frik/thecode.html">www.lowerstandard=
.com/frik/thecode.html</A>=20
by way of links to .txt documents for the curious to peruse as well as =
links to=20
the actual working versions. Give me 5-10 minutes and it'll be=20
there.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jay</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>PS - I am documenting this learning =
experience as I=20
go along and *WILL* at the 'end' be uploading what I hope will be a =
fairly good=20
tutorial with practical examples of each of the experiences I have to=20
lowerstandard.com when I get to a point that I feel that I can make a=20
contribution that some poor schmoe like me would appreciate and =
understand=20
;)</FONT></DIV></DIV></BODY></HTML>

------=_NextPart_000_00DD_01C09D15.B78E3C40--



From jdrake@jam.rr.com  Fri Feb 23 03:24:48 2001
From: jdrake@jam.rr.com (Jason Drake)
Date: Thu, 22 Feb 2001 21:24:48 -0600
Subject: [Tutor] Dwah!
Message-ID: <00ef01c09d48$317f3400$80c8a418@jam.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_00EA_01C09D15.E24F5D60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Okay... slipped and fired this to Mr. Danny Yoo on accident when I meant =
to send it to the tutor list... Sorry Danny! (That's what I get for =
using the reply button rather than sending a new message -- laziness =
does not pay off)

Message as follows:

Out of curiosity, how many of us use IRC and which servers? Does anyone =
know
of an IRC #Python channel? I know that I personally would find such a
channel a great place to spend my evenings learning how to do the things =
I
want to eventually be able to do using a medium with slightly improved
communication flow :)

Jay

------=_NextPart_000_00EA_01C09D15.E24F5D60
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Okay... slipped and fired this to Mr. =
Danny Yoo on=20
accident when I meant to send it to the tutor list... Sorry Danny! =
(That's what=20
I get for using the reply button rather than sending a new message -- =
laziness=20
does not pay off)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Message as follows:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>Out of curiosity, how many of us use IRC and which servers? Does =
anyone=20
know<BR>of an IRC #Python channel? I know that I personally would find =
such=20
a<BR>channel a great place to spend my evenings learning how to do the =
things=20
I<BR>want to eventually be able to do using a medium with slightly=20
improved<BR>communication flow :)<BR><BR>Jay</DIV></BODY></HTML>

------=_NextPart_000_00EA_01C09D15.E24F5D60--



From bwinton@tor.dhs.org  Fri Feb 23 03:26:37 2001
From: bwinton@tor.dhs.org (Blake Winton)
Date: Thu, 22 Feb 2001 22:26:37 -0500
Subject: [Tutor] [Python-Help] Anita Panda: request (fwd)
In-Reply-To: <Pine.LNX.4.21.0102221716010.2716-100000@c82114-a.pinol1.sfba.home.com>
References: <Pine.LNX.4.21.0102221716010.2716-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <20010222222637.A29282@tor.dhs.org>

* Danny Yoo <dyoo@hkn.eecs.berkeley.edu> [010222 20:16]:
>>> Regarding the class & inheritance of python language Pls tell the
>>> good site or give us some tips.  Its not clearly given in the
>>> tutorial.Here at india  python books are not available also.
>> Anybody know a good tutorial on the web that explains classes and
>> inheritance for newbies?  (I'd like to hear about one myself too!)
> This looks like an interesting question; can anyone point out a good
> Python OOP tutorial for Anita?

Bruce Eckel's "Thinking In Java" is a good introduction to OOP, but it's
in Java.  I hear he's working on "Thinking In Python", and checking his
site (http://www.bruceeckel.com/), I see that it's not going to be ready
for a while...  Pity...

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07


From jdrake@jam.rr.com  Fri Feb 23 03:47:27 2001
From: jdrake@jam.rr.com (Jason Drake)
Date: Thu, 22 Feb 2001 21:47:27 -0600
Subject: [Tutor] Offensive Code
Message-ID: <010d01c09d4b$57e66980$80c8a418@jam.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_010A_01C09D19.0CC5B280
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

For those of you who actually took me at my word and believed the page =
regarding my somewhat ugly code being up in 5-10 minutes I apologize for =
my slow implementation. I got to building the page and determined that I =
should put more onto it than I had first intended... :)=20

Anyhow, without further ado, the page is up now and any criticism is =
graciously accepted!

www.lowerstandard.com/frik/thecode.html

Jay

------=_NextPart_000_010A_01C09D19.0CC5B280
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>For those of you who actually took me =
at my word=20
and believed the page regarding my somewhat ugly code being up in 5-10 =
minutes I=20
apologize for my slow implementation. I got to building the page and =
determined=20
that I should put more onto it than I had first intended... :) =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anyhow, without further ado, the page =
is up now and=20
any criticism is graciously accepted!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"http://www.lowerstandard.com/frik/thecode.html">www.lowerstandard=
.com/frik/thecode.html</A></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jay</FONT></DIV></BODY></HTML>

------=_NextPart_000_010A_01C09D19.0CC5B280--



From brett42@flex.com  Fri Feb 23 06:41:27 2001
From: brett42@flex.com (Brett)
Date: Thu, 22 Feb 2001 20:41:27 -1000
Subject: [Tutor] cant get a program run as installer .exe
In-Reply-To: <E14W8ZS-0002Qq-00@mail.python.org>
Message-ID: <4.3.2.7.0.20010222200449.00aa3a90@mail.flex.com>

I'm using python 2.0 on windows98.  I made a small program that uses 
urllibto get html source from a web page and save it locally.  It worked as 
a python file.  Then I  used installer(standalone.py)  to make it into an 
.exe, but when I try to run the executable it crashes at the part when it 
should call 'urllib.urlopen' it gives a traceback with 
'attributeerror:compile'.   Installer successfully made an executable for a 
simple x=input(), print x program, so its not totally screwed.  Does 
installer usually work with urllib? anyone have any idea why it 
crashes?  Here's the code:

import urllib
print 'if this works it should use urllib to get the source for a web 
page.  it should also copy the web page to source.htm'
theurl=raw_input('enter url(needs http:// and filename) or type <1> for an 
example \n')
if theurl=='1':
     theurl='http://bigempire.com/filthy/index.html'
www=urllib.urlopen(theurl) #here's where it crashes
source=www.read()
txt=open('source.htm','w')
txt.write(source)
txt.close()
stuff=input('done')

When Schrodinger's cat's away,
the mice may or may not play,
no one can tell.



From NHYTRO@compuserve.com  Fri Feb 23 06:56:44 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 23 Feb 2001 01:56:44 -0500
Subject: [Tutor] Http Upload
Message-ID: <200102230156_MC2-C699-11DB@compuserve.com>

Thank you guys for your help, I=B4ll tinker with all the methods you=B4ve=

posted to see which one suits my needs best.


Best regards

I still wonder why people use stuff like VB or VBscript when Python is
around (hope this does=B4nt cause a flame, I=B4m just curious :-) )

Sharriff


From NHYTRO@compuserve.com  Fri Feb 23 07:07:23 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 23 Feb 2001 02:07:23 -0500
Subject: [Tutor] File browse/ read filter
Message-ID: <200102230207_MC2-C694-F742@compuserve.com>

Hi guys!


How does one limit a directory read ( os.listdir() )  to certain types of=

files? I=B4d like to have only Image files displayed.

Thanks

Sharriff


From chris@voodooland.net  Fri Feb 23 08:11:11 2001
From: chris@voodooland.net (Chris Watson)
Date: Fri, 23 Feb 2001 02:11:11 -0600 (CST)
Subject: [Tutor] Confused about lists...
Message-ID: <Pine.BSF.4.21.0102230156060.11923-100000@open-systems.net>

Hellow everyone!

	I seem to be having a bit of trouble with a VERY simple routine.
I guess I simply do not understand list's. Here is my code snipit then my
problem:

#!/usr/local/bin/python

# Read in the maillog file
f = open("/var/log/maillog", "r")
# Read the entire maillog as opposed to line by line
for i in f.readlines():
# Use a simple if to see if field 4 contains the word 'open-sytems'
    if i[4] == 'open-sytems':
# If the 4th field matches the above increase f by 1
        f += 1
# Print f which tells us how many occurences of 'open-systems' are in the
# log in field 4
    print f
# Close the file
f.close()

Feb 23 00:35:09 open-systems postfix/cleanup[11489]: A11D516C: message-id=<foo@foo.com>

I didnt wrap this line so it appears as it does in the log.
What I was TRYING to do is get the above code to read a maillog and count
the ammount of times 'open-systems' appears in the 4th field. I am trying
to write a simple parser for a maillog to count things like total messages
received/sent, connections/day, total time spent on connections, etc..
I had 'f +=1' and 'print f' changed to use i instead of f. But that
printed out TWICE as many lines as it should have. It seems to be just
counting the lines in the log file ignoring my i[4] == 'open-systems'
line. 5 lines of code and apparently I only know how open and close work
for SURE. heh. Any pointers? And any pointers to some good doc's on lists
and loops? I appreciate the advice.

Chris




From NHYTRO@compuserve.com  Fri Feb 23 08:34:13 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 23 Feb 2001 03:34:13 -0500
Subject: [Tutor] Tutor digest, Vol 1 #609 - 14 msgs
Message-ID: <200102230334_MC2-C695-2E4A@compuserve.com>

Hello Arcege!

should=B4nt the code read:

  #### if form.has_key('name') ###

Instead? =


Regards

Sharriff


Message text written by INTERNET:tutor@python.org
>import cgi
form =3D cgi.FieldStorage()
if form.has_key('file'):  # from <INPUT name=3D"file"...>
    fileitem =3D form['file']
    if fileitem.file:
        contents =3D []
        line =3D fileitem.file.readline()
        while line:
            bytes =3D len(len)
            contents.append( line )
            line =3D fileitem.file.readline()
            if fileitem.length !=3D -1 and fileitem.length !=3D bytes:
                raise ValueError("data read not same as Content-Length")
        # get the client-given filename, the contents and length
        file =3D (fileitem.filename, contents, fileitem.length)<



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 09:25:44 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 01:25:44 -0800 (PST)
Subject: [Tutor] File browse/ read filter
In-Reply-To: <200102230207_MC2-C694-F742@compuserve.com>
Message-ID: <Pine.LNX.4.21.0102230118340.761-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 23 Feb 2001, Sharriff Aina wrote:

> How does one limit a directory read ( os.listdir() )  to certain types of
> files? I=B4d like to have only Image files displayed.

There are a few approaches you can take.  One is to using the
'glob.glob()' function, which lets you get a directory list that searches
based on a wildcard.  For example:

###
from glob import glob
print glob('./*.jpg')
###

will print us a list of all jpeg files in the current directory.  The
documentation talks about glob.glob (that's fun to say!  *grin*) here:

    http://python.org/doc/current/lib/module-glob.html


glob.glob() itself internally uses os.listdir(), filtering the results out
behind the scenes.  You might want to do the filtering yourself, but
glob.glob() should work pretty well for you.


Good luck!



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 09:37:50 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 01:37:50 -0800 (PST)
Subject: [Tutor] CGI and Better Programming Practice
In-Reply-To: <00e001c09d48$027c98a0$80c8a418@jam.rr.com>
Message-ID: <Pine.LNX.4.21.0102230127190.761-100000@c82114-a.pinol1.sfba.home.com>

On Thu, 22 Feb 2001, Jason Drake wrote:

> These things said and a cold Heineken at my side, I would post the
> code thus far, but would rather not stick so much bad code into one
> document :) Instead I'll post the offensive code at
> www.lowerstandard.com/frik/thecode.html by way of links to .txt
> documents for the curious to peruse as well as links to the actual
> working versions. Give me 5-10 minutes and it'll be there.

I've looked at some of your code; one improvement you can make is to use
Python's string interpolation feature.  For example, the following code:

###
print "<html>"
print "<head>"
print "<title>"
print "Your Info"
print "</title>"
print "</head>"
print "<body>"
print "You gave the following information:"
print "<br>"
print "<br>"
print form["name"].value
print "<br>"
print form["age"].value
print "<br>"
print form["class"].value
print "<br>"
print "<br>"
print "or... "
print output
###

can be written like this (with some formatting liberties...):

###
template = """
<html>
<head><title>Your Info</title></head>
<body>
You gave the following information:
<br><br>
%(name)s
<br>
%(age)s
<br>
%(class)s
<br><br>
or...
%(output)s
"""
print output % { 'name' : form['name'].value,
                 'age' : form['age'].value,
                 'class': form['class'].value,
                 'output': output }
###

(note: I have not tested this code yet; it might contain bugs.)

When we apply the string interpolation operator '%' to our template,
Python will substitute anything that looks like '%(some_key_name)s' with
the value of the dictionary we're passing in.

What's nice about this interpolation method is that our template looks
more like the HTML that its representing.  It's also neat because we could
conceivable read off that template from a different file if we wanted to;
it would be a snap to make changes to the look of the template.

Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 09:41:38 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 01:41:38 -0800 (PST)
Subject: [Tutor] embedding a simple C++ program
In-Reply-To: <3A958220.D9348916@vsys.com>
Message-ID: <Pine.LNX.4.21.0102230138360.761-100000@c82114-a.pinol1.sfba.home.com>

Dear Albert,

Hello!  Hmmm... I haven't had too much experience embedding Python into a
C/C++ application, and I'm not sure if the other tutors have responded
yet.  You might want to ask the comp.lang.python newsgroup itself about
this; there should be some experienced people there who can help.

By the way, I'll try playing with this tonight to see if I can get an
example up and running; not sure if I'll succeed immediately though...
*grin*

Good luck to you.


On Thu, 22 Feb 2001, Albert Hook wrote:

> I have a HelloWorld program, Header, body and a main body that calls
> helloworld. In that header and body I have a printHelloWorld function.
> I want to acces the methods that I create in the class HelloWorld with
> Python via the shared object.
> 
> Do I do that by importing that function into python by simply having a
> init function that calls the is has the following,
> 
> PyObject *m;
> m = Py_InitModule("helloworld". HelloWorldMethods);
> 
> Or is it much more difficult than that, if it is can I see an example.
> I have tried to use the tutorial and the demo.c, the latter doesn't
> compile and I can't see how I can access C++ methods with the
> tutorial.



From alan.gauld@bt.com  Fri Feb 23 09:45:48 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 23 Feb 2001 09:45:48 -0000
Subject: [Tutor] Tkinter Question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5BD@mbtlipnt02.btlabs.bt.co.uk>

> Alan, I understand from this that you believe a modification 
> to Tk itself would have to be made?  I'm a bit surprised too.

I believe so since there doesn't seem to be a way to set or 
change the icon in Tcl/Tk either. Therefore the problem lies 
in the Windows implementation of Tk, I assume.

> I guess my next step, unless Alan has already tried this, 
> would be to post this question in comp.lang.tcl 

Nope, I tried the Tcl/Tk FAQ and several books. I also tried 
the c.l.python newsgroups but didn''t think of the c.l.tcl 
one. OTOH Cameron Laird hangs out in both and I think would 
have responded if there was a simple solution (the question 
gets asked a lot - as a search on deja news reveals!).

> considering e-mailing Fredrik Lundh about this topic to see 
> what he knows. Does anyone know if he's a friendly sort?  

He regularly contributes on c.l.python...

> A cursory glance at comp.lang.tcl revealed something called 
> TkTable!!!  

Whats one of them??? I've never heard of it and how would 
that help change the icon?

> Tkinter table widget would be much more useful than that 
> little icon. :-)

Or do you just mean in general... Isn't there a Tkinter table 
widget floating around? Matbe via the Vaults of p webpage? 
Or is it part of PMW?

Alan G


From NHYTRO@compuserve.com  Fri Feb 23 09:51:23 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 23 Feb 2001 04:51:23 -0500
Subject: [Tutor] HTTP upload- Second try
Message-ID: <200102230451_MC2-C698-4D5B@compuserve.com>

Hi Guys, I=B4m sorry to be a bore, but could someone tell my why my code
fails?

#### code follows ##

#!C:/Python/python.exe -u

print "Content-Type: text/html\n\n"


import cgi
#import os
#
#
form =3D cgi.FieldStorage()
if form.has_key('name'):  # from <INPUT name=3D"newimage"...>
   imageitem =3D form['name']
   if imageitem.file:
       contents =3D form['newimage']
       tempthumb =3D open('.\medintouch\images\testimage.txt', 'w')
       tempthumb.write(contents)
print "<br></br>"
print "<html><head><title>Image uploaded</title></head>"
print '<body>'
print "<br></br>"
print "saving Image file to disk..."
print "<br></br>"
print "<br></br>"
print '</body>'
print '</html>'

#### code end ##

The test file is nor written at all :-(

Thanks guys

Sharriff


From dyoo@hkn.eecs.berkeley.edu  Fri Feb 23 10:02:39 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 02:02:39 -0800 (PST)
Subject: [Tutor] Confused about lists...
In-Reply-To: <Pine.BSF.4.21.0102230156060.11923-100000@open-systems.net>
Message-ID: <Pine.LNX.4.21.0102230143230.761-100000@c82114-a.pinol1.sfba.home.com>

Dear Chris,

Commenting is a good thing, but commenting every line is a little bit
of... overkill.  *grin*

Let's take a look at the code itself:

> f = open("/var/log/maillog", "r")
> for i in f.readlines():
>     if i[4] == 'open-sytems':
>         f += 1
>     print f
> f.close()


> I didnt wrap this line so it appears as it does in the log.
> What I was TRYING to do is get the above code to read a maillog and count
> the ammount of times 'open-systems' appears in the 4th field. I am trying

One thing I see is that you're using the name 'f' for two purposes: first,
as a handle to some file, and second, as a counter.  You might want to
separate the usage of these into two variables.  Let's call them 'f' for
the file, and 'c' for the counter.  If you have time, you might want to
think of slightly more descriptive names for your variables to make things
easier to read.


> to write a simple parser for a maillog to count things like total messages
> received/sent, connections/day, total time spent on connections, etc..
> I had 'f +=1' and 'print f' changed to use i instead of f. But that
> printed out TWICE as many lines as it should have. It seems to be just

Can you explain more what you mean by twice?  Oh!  I think I see what you
mean.  This part of the code might be what's causing the duplicate
printing:

>     if i[4] == 'open-sytems':
>         c += 1                 ## [some text changed from the original]
>     print c


In this case, regardless if we see an 'open-sytems' or not, the program
will print the value of f.  This might lead to the following output:

###
0
0
1
1
2
2
2
3
###

which would look like its doubling up.  You probably want to print out the
value of your counter only if its just recently changed.  If so, try
this:

     if i[4] == 'open-sytems':
         c += 1                  # let's change it to 'c'
         print c                 # because 'f' sounds like a 'file'




The other thing you'll need to check involves this part:

###
for i in f.readlines():
     if i[4] == 'open-sytems':
###

Could you show us an example of what your file would look like?  The only
thing that worries me is that 'i' will be a line, but 'i[4]' is going to
be a single character --- Python will not automatically pull columns out
of a string without some help.  For example, say that '/var/log/maillog'
contains the following line of text:

"Feb 19 04:24:27 c82114-a  sendmail[7269]: EAA07269: \
to=<dyoo@hkn.eecs.berkeley.edu>, delay=00:00:00, xdelay=00:00:00,\
mailer=esmtp, relay=hkn.eecs.berkeley.edu. [128.32.138.117],\
stat=Sent (EAA01739 Message accepted for delivery)"

i[4] looks like the '1' from the date 'Feb 19', and not 'c82114-a'.

We need to tell Python how we break up a string into columns.  We could
separate things between commas, or between spaces---but we need to give
Python a "delimiter" character that separates the columns.

You might want to play around with string.split():

###
>>> string.split('this is a short string', ' ')                
['this', 'is', 'a', 'short', 'string']
>>> string.split('i,could,be a line,from a,,csf file', ',')
['i', 'could', 'be a line', 'from a', '', 'csf file']
###

I think I went a little fast though; if you have any questions, please
feel free to ask the tutor list again.  Good luck to you.



From bsass@freenet.edmonton.ab.ca  Fri Feb 23 10:23:44 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 23 Feb 2001 03:23:44 -0700 (MST)
Subject: [Tutor] Confused about lists...
In-Reply-To: <Pine.BSF.4.21.0102230156060.11923-100000@open-systems.net>
Message-ID: <Pine.LNX.4.33.0102230131370.26688-100000@bms>

Hi,


Here is a revised version of your program, with pointers...

---8<---
#!/usr/local/bin/python

# you're gonna need this
import string

# It is a good idea to use a number of contrived data sets to
# test your code with, that way you can make sure it does what you
# want in all cases.  e.g.(for this prg): no 'open-system' on any
# line, on all lines, no field 4, etc.
f = open("test/data1", "r")

# Use descriptive variable names and initialize them.
counter = 0
for i in f.readlines():
#  ^^^ i will be a line, i.e., a string of characters
# you want a list of words so you need to split up the string...
    if string.strip(i) and string.split(i)[3] == 'open-systems':
        counter = counter + 1
print counter
f.close()
--->8---

The "if" condition needs some explaining.

The first element, string.strip(i), removes any leading and trailing
whitespace from the line, it is there to catch any blank lines.  All
the log files I looked at on my system ended with "\n\n", this will
turn the last line, "\n", into "" (i.e., "false").

The next element is a little more complex... string.split(i) returns a
list of words, the [3] gets at the fourth item in the list (indices
start at zero).  I could have done...

	wordlist = string.split(i)
	word = wordlist[3]

...then tested for...

	word == 'open-systems'

...and that may even be a better way to handle the situation,
depending on what you think of this next bit...

So, the condition is true if the line is not blank and the fourth word
is 'open-systems' - it works, but is a hack!  The reason it is a hack
is because it relies on a quirk in the way Python processes the "and"
and "or" operators.  To see the effect just reverse the 'split' and
'strip' terms so that string.split(i)[3] is evaluated first, then run
the program on a data set with a blank line in it.  Keep in mind that,
logically, (A and B) is the same as (B and A).  I'll leave it up to
you to find a way to fix the bad code (homework ;).

HTH


- Bruce

-- 
On Fri, 23 Feb 2001, Chris Watson wrote:
<...>
> Feb 23 00:35:09 open-systems postfix/cleanup[11489]: A11D516C: message-id=<foo@foo.com>
>
> I didnt wrap this line so it appears as it does in the log.
> What I was TRYING to do is get the above code to read a maillog and count
> the ammount of times 'open-systems' appears in the 4th field. I am trying
> to write a simple parser for a maillog to count things like total messages
> received/sent, connections/day, total time spent on connections, etc..
> I had 'f +=1' and 'print f' changed to use i instead of f. But that
> printed out TWICE as many lines as it should have. It seems to be just
> counting the lines in the log file ignoring my i[4] == 'open-systems'
> line. 5 lines of code and apparently I only know how open and close work
> for SURE. heh. Any pointers? And any pointers to some good doc's on lists
> and loops? I appreciate the advice.



From arcege@shore.net  Fri Feb 23 13:20:14 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 23 Feb 2001 08:20:14 -0500 (EST)
Subject: [Tutor] Tutor digest, Vol 1 #609 - 14 msgs
In-Reply-To: <200102230334_MC2-C695-2E4A@compuserve.com> from "Sharriff Aina" at Feb 23, 2001 03:34:13 AM
Message-ID: <200102231320.IAA05844@northshore.shore.net>

> Hello Arcege!
> 
> should=B4nt the code read:
> 
>   #### if form.has_key('name') ###
> 
> Instead? =

Nope, I meant "file".  In an INPUT tag, the name= attribute defines the
name in the form.  In my last posting, I called the field "file".

<FORM METHOD=GET ACTION="/cgi-bin/form.cgi">
First name: <INPUT name="first" type="text"><BR>
Last name: <INPUT name="last" type="text"><BR>
</FORM>

Give a URL of "/cgi-bin/form.cgi?first=Sharriff&last=Aina".

And for a file upload:
<FORM METHOD=POST ENCTYPE="multipart/form-data"
  ACTION="/cgi-bin/form.cgi">
Filename: <INPUT name="uploadfile" type="file"><BR>
</FORM>

gives:
--192168202199
Content-disposition: form-data; name="uploadfile"; filename="menu.txt"

Spam, spam, eggs & toast
Spam, eggs, toast and spam
Spam, spam, spam and spam
--192168202199--

Here you would get:
>>> form['uploadfile'].filename
'menu'
>>>

The name is "uploadfile".

  -Arcege

> Message text written by INTERNET:tutor@python.org
> >import cgi
> form =3D cgi.FieldStorage()
> if form.has_key('file'):  # from <INPUT name=3D"file"...>
>     fileitem =3D form['file']
>     if fileitem.file:
>         contents =3D []
>         line =3D fileitem.file.readline()
>         while line:
>             bytes =3D len(len)
>             contents.append( line )
>             line =3D fileitem.file.readline()
>             if fileitem.length !=3D -1 and fileitem.length !=3D bytes:
>                 raise ValueError("data read not same as Content-Length")
>         # get the client-given filename, the contents and length
>         file =3D (fileitem.filename, contents, fileitem.length)<


-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From dsh8290@rit.edu  Fri Feb 23 15:15:14 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 23 Feb 2001 10:15:14 -0500
Subject: [Tutor] HTTP upload- Second try
In-Reply-To: <200102230451_MC2-C698-4D5B@compuserve.com>; from NHYTRO@compuserve.com on Fri, Feb 23, 2001 at 04:51:23AM -0500
References: <200102230451_MC2-C698-4D5B@compuserve.com>
Message-ID: <20010223101514.B4848@harmony.cs.rit.edu>

On Fri, Feb 23, 2001 at 04:51:23AM -0500, Sharriff Aina wrote:
| Hi Guys, I=B4m sorry to be a bore, but could someone tell my why my cod=
e
| fails?
|=20
| #### code follows ##
|=20
| #!C:/Python/python.exe -u
|=20
| print "Content-Type: text/html\n\n"
|=20
|=20
| import cgi
| #import os
| #
| #
| form =3D cgi.FieldStorage()
| if form.has_key('name'):  # from <INPUT name=3D"newimage"...>
|    imageitem =3D form['name']
|    if imageitem.file:
|        contents =3D form['newimage']
|        tempthumb =3D open('.\medintouch\images\testimage.txt', 'w')
|        tempthumb.write(contents)
         tempthumb.close()
| print "<br></br>"
| print "<html><head><title>Image uploaded</title></head>"
| print '<body>'
| print "<br></br>"
| print "saving Image file to disk..."
| print "<br></br>"
| print "<br></br>"
| print '</body>'
| print '</html>'
|=20
| #### code end ##
|=20
| The test file is nor written at all :-(
|=20

It is always a good idea to close a file when you are done, but I
think the interpreter will do that for you when it terminates (or
collects the file object).  You will also want to change the mode to
"wb" so that you don't get EOL trickery corrupting the file.  Plain
"w" will work on a Unix system because it doesn't play such tricks,
but on Windows it will put a \r (0xD) in front of each \n (0xA).  This
was an ugly bug I found in mutt when I compiled it under cygwin.

Can you write to any file?  Do you have permission?  Is the disk full?
(When debugging, always ask dumb questions, you might be surprised by
the answer ;-))

I don't know if it matters, but you might want to put the "Saving
file ..." before the actual write so the client can (maybe, depends on
network, etc) see a result.  It would also be a good idea to put a
try-except block around the work part of the code so any errors can be
reported to the client.


Umm, I just looked again and noticed you used un-escaped backslashes in
the string.  The file was probably written, but isn't named what you
think it is.  Use forward slashes instead, or use a raw string for the
file name.  The file's path is probably

.\medintouch\images	estimage.txt

(\m and \i don't mean anything do they?)


HTH,
-D



From arcege@shore.net  Fri Feb 23 16:20:30 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 23 Feb 2001 11:20:30 -0500 (EST)
Subject: [Tutor] HTTP upload- Second try
In-Reply-To: <200102230451_MC2-C698-4D5B@compuserve.com> from "Sharriff Aina" at Feb 23, 2001 04:51:23 AM
Message-ID: <200102231620.LAA20470@northshore.shore.net>

> Hi Guys, I=B4m sorry to be a bore, but could someone tell my why my code
> fails?
> 
> #### code follows ##
> 
> #!C:/Python/python.exe -u
> 
> print "Content-Type: text/html\n\n"
> 
> 
> import cgi
> #import os
> #
> #
> form =3D cgi.FieldStorage()
> if form.has_key('name'):  # from <INPUT name=3D"newimage"...>
>    imageitem =3D form['name']
>    if imageitem.file:
>        contents =3D form['newimage']
>        tempthumb =3D open('.\medintouch\images\testimage.txt', 'w')
>        tempthumb.write(contents)
> print "<br></br>"
> print "<html><head><title>Image uploaded</title></head>"
> print '<body>'
> print "<br></br>"
> print "saving Image file to disk..."
> print "<br></br>"
> print "<br></br>"
> print '</body>'
> print '</html>'
> 
> #### code end ##

Unless your form had an additional tag with <INPUT name="name"
type="file"> then you will never get to the "form['newimage']" part of
the code.

Try:

form = cgi.FieldStorage()
# is there a newimage being loaded?
if form.has_key("newimage") and form["newimage'].file:
  fp = form["newimage"].file
  # write to some file with an "image" extension instead of a text file
  tempthumb = open('.\\medintouch\\images\\testimage.img', 'w')
  block = fp.read(8192)
  while block:
    tempthumb.write(block)
    block = fp.read(8192)
...
print '<img src="/images/testimage.img">'

There have been some recent discussions here about WinXX pathnames and
the backslash character.  Your file would also be written with an
embedded tab character. :(

Good luck :)
  -Arcege

PS: I verified this with Apache on FreeBSD, changing pathnames as
necessary.

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From FxItAL@aol.com  Fri Feb 23 17:12:27 2001
From: FxItAL@aol.com (FxItAL@aol.com)
Date: Fri, 23 Feb 2001 12:12:27 EST
Subject: [Tutor] modem
Message-ID: <21.7d202c8.27c7f3fb@aol.com>

--part1_21.7d202c8.27c7f3fb_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Hello All,

       Can someone tell me if there is a module that allows communication 
(read, write, enable and disable) to your serial port.  

Python 2.0 on windows 9X.

Thanks, Al

--part1_21.7d202c8.27c7f3fb_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2>Hello All,
<BR>
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Can someone tell me if there is a module that allows communication 
<BR>(read, write, enable and disable) to your serial port. &nbsp;
<BR>
<BR>Python 2.0 on windows 9X.
<BR>
<BR>Thanks, Al</FONT></HTML>

--part1_21.7d202c8.27c7f3fb_boundary--


From arcege@shore.net  Fri Feb 23 19:29:01 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 23 Feb 2001 14:29:01 -0500 (EST)
Subject: [Tutor] modem
In-Reply-To: <21.7d202c8.27c7f3fb@aol.com> from "FxItAL@aol.com" at Feb 23, 2001 12:12:27 PM
Message-ID: <200102231929.OAA18008@northshore.shore.net>

> Hello All,
> 
>        Can someone tell me if there is a module that allows communication 
> (read, write, enable and disable) to your serial port.  
> 
> Python 2.0 on windows 9X.
> 
> Thanks, Al

The "Python Programming on Win32" book documents a Serial module (as
part of the Win32 Extensions distribution?).  You might want to look
there.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From rick@niof.net  Fri Feb 23 19:53:54 2001
From: rick@niof.net (Rick Pasotto)
Date: Fri, 23 Feb 2001 14:53:54 -0500
Subject: [Tutor] ImageTk problem
Message-ID: <20010223145354.C5869@tc.niof.net>

The following code produces no error and no visible picture. The size of
the picture is known since using a different image will change the size
of the label. It doesn't matter whether it's a gif or a jpg.

What am I overlooking?

from Tkinter import *
import Image, ImageTk

class Main:
	def __init__(self,win):
		self.win = win
		im1 = Image.open("picture.gif")
		im2 = ImageTk.PhotoImage(im1)
		Label(self.win, image = im2).pack()
		b = Button(self.win,text='Quit',height=2)
		b.pack()
		b.config(command = lambda w = self.win: w.destroy())

def main():
	root = Tk()
	Main(root)
	root.mainloop()

if __name__ == '__main__':
	main()

-- 
"The financial policy of the welfare state requires that there be no
way for the owners of wealth to protect themselves.  This is the
shabby secret of the welfare statists' tirades against gold.   Deficit
spending is simply a scheme for the 'hidden' confiscation of wealth.
Gold stands in the way of this insidious process.   It stands as a
protector of property rights."
		-- Alan Greenspan
		   Rick Pasotto email: rickp@telocity.com


From arcege@shore.net  Fri Feb 23 20:24:39 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 23 Feb 2001 15:24:39 -0500 (EST)
Subject: [Tutor] ImageTk problem
In-Reply-To: <20010223145354.C5869@tc.niof.net> from "Rick Pasotto" at Feb 23, 2001 02:53:54 PM
Message-ID: <200102232024.PAA27019@northshore.shore.net>

> 
> The following code produces no error and no visible picture. The size of
> the picture is known since using a different image will change the size
> of the label. It doesn't matter whether it's a gif or a jpg.
> 
> What am I overlooking?
> 
> from Tkinter import *
> import Image, ImageTk
> 
> class Main:
>     def __init__(self,win):
>         self.win = win
>         im1 = Image.open("picture.gif")
>         im2 = ImageTk.PhotoImage(im1)
>         Label(self.win, image = im2).pack()
>         b = Button(self.win,text='Quit',height=2)
>         b.pack()
>         b.config(command = lambda w = self.win: w.destroy())
> 
> def main():
>     root = Tk()
>     Main(root)
>     root.mainloop()
> 
> if __name__ == '__main__':
>     main()

I could easily be wrong, since I don't have documentation with me,
but a reference to the image being passed of a Tkinter widget must kept
during its existance.  The easiest way to do this here would be to
assign the PhotoImage instance to "self.im2" instead of im.

Next, keep the Main instance around, otherwise again the PhotoImage
is dereferenced and the image is not displayed:

...
  self.im2 = ImageTk.PhoneImage(im1)
  Label(self.win, image=self.im2).pack()
  ...
main = Main(root)
root.mainloop()

These changes work on my FreeBSD Python 1.5 with PIL 0.3b2.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From chris@voodooland.net  Fri Feb 23 20:27:36 2001
From: chris@voodooland.net (Chris Watson)
Date: Fri, 23 Feb 2001 14:27:36 -0600 (CST)
Subject: [Tutor] Confused about lists...
In-Reply-To: <Pine.LNX.4.21.0102230143230.761-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <Pine.BSF.4.21.0102231414130.24953-100000@open-systems.net>

> Commenting is a good thing, but commenting every line is a little bit
> of... overkill.  *grin*

	True :-) I just wanted to make clear what I was *trying* to do so
if I failed to explain it well hopefully the comments would explain it :-)

> Let's take a look at the code itself:
> 
> > f = open("/var/log/maillog", "r")
> > for i in f.readlines():
> >     if i[4] == 'open-sytems':
> >         f += 1
> >     print f
> > f.close()

> One thing I see is that you're using the name 'f' for two purposes: first,
> as a handle to some file, and second, as a counter.  You might want to
> separate the usage of these into two variables.  Let's call them 'f' for
> the file, and 'c' for the counter.  If you have time, you might want to
> think of slightly more descriptive names for your variables to make things
> easier to read.

for i in f.readlines():
    if i[3] == 'open-sytems':
        counter += 1
    print counter

I changed the code to the above. But it fails to do what I want :-/ It
ignores the if i[3] line and just prints 0's down the screen. If I pipe it
to |wc -l it tells me it is counting each line in the maillog twice. If
there are 100 lines in the maillog it prints 200 0's. Weird.

> > to write a simple parser for a maillog to count things like total messages
> > received/sent, connections/day, total time spent on connections, etc..
> > I had 'f +=1' and 'print f' changed to use i instead of f. But that
> > printed out TWICE as many lines as it should have. It seems to be just
> 
> Can you explain more what you mean by twice?  Oh!  I think I see what you
> mean.  This part of the code might be what's causing the duplicate
> printing:

I mean it's counting each line in the logfile twice. For some reason. :-/

> >     if i[4] == 'open-sytems':
> >         c += 1                 ## [some text changed from the original]
> >     print c
> 
> 
> In this case, regardless if we see an 'open-sytems' or not, the program
> will print the value of f.  This might lead to the following output:
> 
> ###
> 0
> 0
> 1
> 1
> 2
> 2
> 2
> 3
> ###

	Sort of. It's actually printing:

0
0
0
0
0
...

	And for each line in the log its printing two 0's for each line.
So its counting each line twice and ignoring my if i[3] part. Hrmm.

> which would look like its doubling up.  You probably want to print out the
> value of your counter only if its just recently changed.  If so, try
> this:
> 
>      if i[4] == 'open-sytems':
>          c += 1                  # let's change it to 'c'
>          print c                 # because 'f' sounds like a 'file'

for i in f.readlines():
    if i[3] == 'open-sytems':
        counter += 1
        print counter

Moving the print counter line inline with counter prints one 0. Hmm.

> The other thing you'll need to check involves this part:
> 
> ###
> for i in f.readlines():
>      if i[4] == 'open-sytems':
> ###
> 
> Could you show us an example of what your file would look like?  The only
> thing that worries me is that 'i' will be a line, but 'i[4]' is going to
> be a single character --- Python will not automatically pull columns out
> of a string without some help.  For example, say that '/var/log/maillog'
> contains the following line of text:

	Yes. I was afraid of that too. I want the 4th field. In the log
below you note that each field is seperated by whitespace. I.e. i[1] would
I think/want to grab "delay=00:00:00". 0 being the the "to" line 1 being
the delay. See what I mean?

> to=<dyoo@hkn.eecs.berkeley.edu>, delay=00:00:00, xdelay=00:00:00,\
> mailer=esmtp, relay=hkn.eecs.berkeley.edu. [128.32.138.117],\
> stat=Sent (EAA01739 Message accepted for delivery)"
> 
> i[4] looks like the '1' from the date 'Feb 19', and not 'c82114-a'.

	Well but its ignoring the if i[n] line anyway because it isnt
counting the hostname. It's just counting the whole line.

> We need to tell Python how we break up a string into columns.  We could
> separate things between commas, or between spaces---but we need to give
> Python a "delimiter" character that separates the columns.

	Hrmm I guess thats true. Since the log is alread pre-formatted I
didnt think it was neccessary. Maybe thats goofing things up.

> You might want to play around with string.split():
> 
> ###
> >>> string.split('this is a short string', ' ')                
> ['this', 'is', 'a', 'short', 'string']
> >>> string.split('i,could,be a line,from a,,csf file', ',')
> ['i', 'could', 'be a line', 'from a', '', 'csf file']
> ###
> 
> I think I went a little fast though; if you have any questions, please
> feel free to ask the tutor list again.  Good luck to you.

I'm about to try bob's example. And see if string.split(i)... work.
I still would like to know why it's ignoring my if i[4] line though and
counting each whole line twice. hrmm. I really appreciate the explanation
of things so far. I should of used better counter names :-) It does make
things much easier to know whats going on.

--
=============================================================================
-Chris Watson         (316) 326-3862 | FreeBSD Consultant, FreeBSD Geek 
Work:              scanner@jurai.net | Open Systems Inc., Wellington, Kansas
Home:  scanner@deceptively.shady.org | http://open-systems.net
=============================================================================
WINDOWS: "Where do you want to go today?"
LINUX: "Where do you want to go tomorrow?"
BSD: "Are you guys coming or what?"
=============================================================================
irc.openprojects.net #FreeBSD -Join the revolution!
ICQ: 20016186



From gibbs05@flash.net  Fri Feb 23 20:38:40 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Fri, 23 Feb 2001 14:38:40 -0600
Subject: [Tutor] Tkinter Question
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D5BD@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <06a601c09dd8$b1e5d460$e7dd3040@gibbs05>

Greetings All,

I may not have found the answer to the icon question yet, but I have learned
about The Vaults of Parnassus and more about Tcl/Tk.

I guess the next step in this is to barge in on the Tcl folks. :-)


Thanks,
Sam

> > Alan, I understand from this that you believe a modification
> > to Tk itself would have to be made?  I'm a bit surprised too.
>
> I believe so since there doesn't seem to be a way to set or
> change the icon in Tcl/Tk either. Therefore the problem lies
> in the Windows implementation of Tk, I assume.
>
> > I guess my next step, unless Alan has already tried this,
> > would be to post this question in comp.lang.tcl
>
> Nope, I tried the Tcl/Tk FAQ and several books. I also tried
> the c.l.python newsgroups but didn''t think of the c.l.tcl
> one. OTOH Cameron Laird hangs out in both and I think would
> have responded if there was a simple solution (the question
> gets asked a lot - as a search on deja news reveals!).
>
> > considering e-mailing Fredrik Lundh about this topic to see
> > what he knows. Does anyone know if he's a friendly sort?
>
> He regularly contributes on c.l.python...
>
> > A cursory glance at comp.lang.tcl revealed something called
> > TkTable!!!
>
> Whats one of them??? I've never heard of it and how would
> that help change the icon?
>
> > Tkinter table widget would be much more useful than that
> > little icon. :-)
>
> Or do you just mean in general... Isn't there a Tkinter table
> widget floating around? Matbe via the Vaults of p webpage?
> Or is it part of PMW?
>
> Alan G




From mbc2@netdoor.com  Fri Feb 23 20:52:01 2001
From: mbc2@netdoor.com (Brad Chandler)
Date: Fri, 23 Feb 2001 14:52:01 -0600
Subject: [Tutor] modem
In-Reply-To: <21.7d202c8.27c7f3fb@aol.com>
Message-ID: <NDBBINFOMECHGDGPFKMKGEEFCAAA.mbc2@netdoor.com>

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
FxItAL@aol.com
Sent: Friday, February 23, 2001 11:12 AM
To: tutor@python.org
Subject: [Tutor] modem


>Can someone tell me if there is a module that allows communication
>(read, write, enable and disable) to your serial port.
>
>Python 2.0 on windows 9X.
>
>Thanks, Al

I've never tried it on windows, but the following works on linux. You might
want to try it, with the exception of the "/dev/cua0" as the modem device,
it shouldn't be specific to linux. Also, check the serial how-to and the
modem how-to at http://www.linuxdoc.org

I realize that's a linux site but I think there might still be some usefull
information there for you.

import os

modem = open('/dev/cua0','w+') # replace /dev/cua0 with your modem device
os.write(modem.fileno(),"AT")
# "AT" is part of an initialization string for your modem, check you modem's
# documentation.

x = os.read(modem.fileno(),200)
print x
# You should get "OK" from this after sending "AT" with os.write. "200" is
# the maximum number of bytes to read, I just used 200 as an example.





From gibbs05@flash.net  Fri Feb 23 21:13:49 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Fri, 23 Feb 2001 15:13:49 -0600
Subject: [Tutor] ImageTk problem
References: <20010223145354.C5869@tc.niof.net>
Message-ID: <06c601c09ddd$987dfa20$e7dd3040@gibbs05>

Greetings Rick & All,

I've been having the same kind problems with PIL.

I think Michael Reilly is correct about retaining a reference, though I
couldn't get his solution to work under Windows.

I could get Rick's example to work when I modified it as follows to match
examples by creating a subclass of Label to hold the image:

from Tkinter import *
import Image, ImageTk

class ImageLabel(Label):

    def __init__(self, master, im):

        self.im2 = ImageTk.PhotoImage(im)
        Label.__init__(self, master, image=self.im2)

class Main:
    def __init__(self,win):
        self.win = win
        im1 = Image.open("picture.gif")
        ImageLabel(self.win, im = im1).pack()
        b = Button(self.win,text='Quit',height=2)
        b.pack()
        b.config(command = lambda w = self.win: w.destroy())

def main():
    root = Tk()
    Main(root)
    root.mainloop()

if __name__ == '__main__':
    main()


I really don't know why this works and the other doesn't.


Good luck,
Sam


> The following code produces no error and no visible picture. The size of
> the picture is known since using a different image will change the size
> of the label. It doesn't matter whether it's a gif or a jpg.
>
> What am I overlooking?
>
> from Tkinter import *
> import Image, ImageTk
>
> class Main:
> def __init__(self,win):
> self.win = win
> im1 = Image.open("picture.gif")
> im2 = ImageTk.PhotoImage(im1)
> Label(self.win, image = im2).pack()
> b = Button(self.win,text='Quit',height=2)
> b.pack()
> b.config(command = lambda w = self.win: w.destroy())
>
> def main():
> root = Tk()
> Main(root)
> root.mainloop()
>
> if __name__ == '__main__':
> main()
>
> --
> "The financial policy of the welfare state requires that there be no
> way for the owners of wealth to protect themselves.  This is the
> shabby secret of the welfare statists' tirades against gold.   Deficit
> spending is simply a scheme for the 'hidden' confiscation of wealth.
> Gold stands in the way of this insidious process.   It stands as a
> protector of property rights."
> -- Alan Greenspan
>    Rick Pasotto email: rickp@telocity.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From arcege@shore.net  Fri Feb 23 21:29:22 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 23 Feb 2001 16:29:22 -0500 (EST)
Subject: [Tutor] ImageTk problem
In-Reply-To: <06c601c09ddd$987dfa20$e7dd3040@gibbs05> from "Harry Kattz" at Feb 23, 2001 03:13:49 PM
Message-ID: <200102232129.QAA06870@northshore.shore.net>

> 
> Greetings Rick & All,
> 
> I've been having the same kind problems with PIL.
> 
> I think Michael Reilly is correct about retaining a reference, though I
> couldn't get his solution to work under Windows.
> 
> I could get Rick's example to work when I modified it as follows to match
> examples by creating a subclass of Label to hold the image:
> 
> from Tkinter import *
> import Image, ImageTk
> 
> class ImageLabel(Label):
> 
>     def __init__(self, master, im):
> 
>         self.im2 = ImageTk.PhotoImage(im)
>         Label.__init__(self, master, image=self.im2)
> 
> class Main:
>     def __init__(self,win):
>         self.win = win
>         im1 = Image.open("picture.gif")
>         ImageLabel(self.win, im = im1).pack()
          # keep a reference beyond the end of the method
          self.iml = ImageLabel(self.win, im=im1).pack()

>         b = Button(self.win,text='Quit',height=2)
>         b.pack()
>         b.config(command = lambda w = self.win: w.destroy())
> 
> def main():
>     root = Tk()
>     Main(root)
      # keep a reference until at least after mainloop()
      main = Main(root)

>     root.mainloop()
> 
> if __name__ == '__main__':
>     main()
> 
> 
> I really don't know why this works and the other doesn't.

For the same reason I said to keep a reference to Main(root) as well,
you lose the reference to ImageLabel (it gets created, packed then
dereferenced inside of Main.__init__), and still lose the reference
to Main(root) inside of main().

The interaction between Tk and Tkinter is a little odd where it
comes to sharing objects.  One place this is clear is the "Variable"
classes (StringVar, Intvar, etc.).  Suffice to say, if the Python
version of the PhotoImage or BitmapImage (in Tkinter or PIL) is
destroyed, then Tcl/Tk will remove its reference as well.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From gibbs05@flash.net  Fri Feb 23 21:54:09 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Fri, 23 Feb 2001 15:54:09 -0600
Subject: [Tutor] ImageTk problem
References: <200102232129.QAA06870@northshore.shore.net>
Message-ID: <06eb01c09de3$2c9875a0$e7dd3040@gibbs05>

Greetings Arcege, Rick, & All,

I'm afraid I was misunderstood.  Arcege, the code I place in my last message
worked even without the modifications you suggested.  ImageLabel is not
destroyed in that version of the code.  I don't know if that code works on
your machine though.

After reading your latest post I've gone back to Rick's original code and
made the changes you suggested without adding the ImageLabel class and it
does indeed work now!  saving the reference to main was what I was missing.
The ImageLabel class isn't needed is Main is saved.

Thanks,
Sam


> >
> > Greetings Rick & All,
> >
> > I've been having the same kind problems with PIL.
> >
> > I think Michael Reilly is correct about retaining a reference, though I
> > couldn't get his solution to work under Windows.
> >
> > I could get Rick's example to work when I modified it as follows to
match
> > examples by creating a subclass of Label to hold the image:
> >
> > from Tkinter import *
> > import Image, ImageTk
> >
> > class ImageLabel(Label):
> >
> >     def __init__(self, master, im):
> >
> >         self.im2 = ImageTk.PhotoImage(im)
> >         Label.__init__(self, master, image=self.im2)
> >
> > class Main:
> >     def __init__(self,win):
> >         self.win = win
> >         im1 = Image.open("picture.gif")
> >         ImageLabel(self.win, im = im1).pack()
>           # keep a reference beyond the end of the method
>           self.iml = ImageLabel(self.win, im=im1).pack()
>
> >         b = Button(self.win,text='Quit',height=2)
> >         b.pack()
> >         b.config(command = lambda w = self.win: w.destroy())
> >
> > def main():
> >     root = Tk()
> >     Main(root)
>       # keep a reference until at least after mainloop()
>       main = Main(root)
>
> >     root.mainloop()
> >
> > if __name__ == '__main__':
> >     main()
> >
> >
> > I really don't know why this works and the other doesn't.
>
> For the same reason I said to keep a reference to Main(root) as well,
> you lose the reference to ImageLabel (it gets created, packed then
> dereferenced inside of Main.__init__), and still lose the reference
> to Main(root) inside of main().
>
> The interaction between Tk and Tkinter is a little odd where it
> comes to sharing objects.  One place this is clear is the "Variable"
> classes (StringVar, Intvar, etc.).  Suffice to say, if the Python
> version of the PhotoImage or BitmapImage (in Tkinter or PIL) is
> destroyed, then Tcl/Tk will remove its reference as well.
>
>   -Arcege
>
> --
> ------------------------------------------------------------------------
> | Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
> | Salem, Mass. USA  01970             |                                |
> ------------------------------------------------------------------------



From britt_green@hotmail.com  Sat Feb 24 00:31:37 2001
From: britt_green@hotmail.com (Britt Green)
Date: Fri, 23 Feb 2001 16:31:37 -0800
Subject: [Tutor] A Couple of Questions
Message-ID: <F482EeiDREAa4uez1ek0000a179@hotmail.com>

Hello everyone,

Here is my situation: Ever since playing Zork way back when, I've really 
wanted to write my own text adventure. I've also wanted to learn to code. So 
I'm combining the two and learning Python by, amongst other things, writing 
up a very simple text adventure.

I'm still in the pre-coding stages of it. There's a couple of problems I've 
encountered that I'm hoping some of you can help me with.

The first is classes. I'm thinking of having everything in my game fit 
within five classes: Player, Rooms, Objects, Mobs and Game. The first four 
of these are self-explanatory. The Game class is sort of a catch-all for 
different things, like the UI and maybe networking code and whatnot. Can 
anyone think of a better way to break things up?

  Secondly, if I want to put the information in a text file, rather than 
hard-coded into the program, what would be a good format for it, and how can 
I make Python read in each class. For example, if I had a text file with a 
list of all the rooms, what would the code look like to have Python read in 
each room, and assign that information into an instance of the Room class.

If anyone can point me in the right direction, I'd be grateful!

Britt

--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From dyoo@hkn.eecs.berkeley.edu  Sat Feb 24 01:00:04 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 17:00:04 -0800 (PST)
Subject: [Tutor] Confused about lists...
In-Reply-To: <Pine.BSF.4.21.0102231414130.24953-100000@open-systems.net>
Message-ID: <Pine.LNX.4.21.0102231657490.762-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 23 Feb 2001, Chris Watson wrote:

> I'm about to try bob's example. And see if string.split(i)... work. I
> still would like to know why it's ignoring my if i[4] line though and
> counting each whole line twice. hrmm. I really appreciate the
> explanation of things so far. I should of used better counter names
> :-) It does make things much easier to know whats going on.

It's not quite a matter of ignoring that line; it's more a matter of the
test within:

    if i[4] == 'open-sytems': ...

always failing.  If it helps, try putting the line:

    print 'Here's what i[4] contains:', i[4]

right before your if-statement, and you'll see something peculiar.  *grin*



From dyoo@hkn.eecs.berkeley.edu  Sat Feb 24 01:11:59 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 23 Feb 2001 17:11:59 -0800 (PST)
Subject: [Tutor] HTTP upload- Second try
In-Reply-To: <200102230451_MC2-C698-4D5B@compuserve.com>
Message-ID: <Pine.LNX.4.21.0102231708000.762-100000@c82114-a.pinol1.sfba.home.com>

On Fri, 23 Feb 2001, Sharriff Aina wrote:

> Hi Guys, I=B4m sorry to be a bore, but could someone tell my why my code
> fails?

You might want to tell us a little more about what it means to "fail";
otherwise, we'll have to flail about a bit.  *grin*


I did catch one thing, though:

>        tempthumb =3D open('.\medintouch\images\testimage.txt', 'w')

Python treats the sequence:

    '\t'

as the Tab character, so that's definitely going to interfere with the
file opening.  To prevent that from happening, try this:

    tempthumb =3D open('.\\medintouch\\images\\testimage.txt', 'w')

or:

    tempthumb =3D open(r'.\medintouch\images\testimage.txt', 'w')

instead; both tell Python to avoid treating the backslash as the start of
an escape character.  The second is the nicer approach: it's called a
"raw" string, and it's useful whenever you want to have backslashes in
your string.

Good luck!



From DOUGS@oceanic.com  Sat Feb 24 02:16:13 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Fri, 23 Feb 2001 16:16:13 -1000
Subject: [Tutor] A Couple of Questions
Message-ID: <8457258D741DD411BD3D0050DA62365907A660@huina.oceanic.com>

[Britt Green wrote:]
> Here is my situation: Ever since playing Zork way back when, 
> I've really 
> wanted to write my own text adventure. I've also wanted to 
> learn to code. So 
> I'm combining the two and learning Python by, amongst other 
> things, writing 
> up a very simple text adventure.

Its a great way to start.  I think I did something similar, pre- OOP
paradigm in some dark age.

> I'm still in the pre-coding stages of it. There's a couple of 
> problems I've 
> encountered that I'm hoping some of you can help me with.

The first problem is that you're in the PRE-coding stage instead of jumping
right in.  ;-) There is nothing like programming to learn how to program.

> The first is classes. I'm thinking of having everything in my 
> game fit 
> within five classes: Player, Rooms, Objects, Mobs and Game. 
> The first four 
> of these are self-explanatory. The Game class is sort of a 
> catch-all for 
> different things, like the UI and maybe networking code and 
> whatnot. Can 
> anyone think of a better way to break things up?

What you are describing is what you should be trying.  The level of analysis
you've done is sufficient to begin writing code.  There is an old axiom of
programming that you write at least one to throw away.  In other words, in
the analysis and design stages you'll never think of all the right ways to
do it.  Begin, and assume you'll have to start over and then you won't be
disapointed when it happens.

The advent of object oriented methodologies has made this a lot less painful
than it used to be.  There is even some formalism arising around it.  At
some point do yourself a favor and look into unit testing, refactoring, and
Extreme Programming.  Even if you don't do professional programming the
style espoused is good to know about.

If I were you I'd begin by putting together a module file with exactly those
classes you have above.  Start adding attributes to the classes and methods
as you think of the need.  Make sure the file runs from the very first and
don't add more code than you can get to run something minimally useful or
fun.  Share your specific questions here as you progress.  This may lead you
to redefine the whole thing with a different set of classes, but at least
you'll have some basis to discuss the answers the next time you ask about it
here.

>   Secondly, if I want to put the information in a text file, 
> rather than 
> hard-coded into the program, what would be a good format for 
> it, and how can 
> I make Python read in each class. For example, if I had a 
> text file with a 
> list of all the rooms, what would the code look like to have 
> Python read in 
> each room, and assign that information into an instance of 
> the Room class.

I'd suggest plain ascii text strings are a great start.  Python has some
great string manipulation functions.  The solution du jour seems to be XML,
but that would be excessive and in my opinion counter to this being a
learning to program project.

For instance, you might have an attribute of a room object that is called
items (Objects might not be such a good class name maybe).  You set it to a
list of item instances.  Each item is going to have a set of attributes.
When its time to save the game state you'll need a method of the item class
that can create a stringified version of the class instance.  Reading it
back then just becomes an exercise in pulling the info out of the formatting
you added when you wrote it:

class Item:
    #  init code and other functions ...
    # __repr__ is a magic class method that is useful for this kind of thing
    def __repr__(self):
        template = "[item]%s:%s:%s" # printf formatting, very useful, sorta
obscure
        return template % (self.name,self.description,self.id) # assume
they're defined
    def load(self,stuff): # 'stuff' being that which was returned from
__repr__
        spam = string.split(stuff[1:],']') # take the [item] off the front
        # a good program would check to make sure spam[0] == "item" :->
        self.name,self.description,self.id = string.split(spam[1],':')

Usage is left as an exercise, but I'd guess the room instance would be
calling these functions of each of the items in its items list.  I hope this
wasn't too obtuse or preachy.  Its hard to answer these kind of general
questions.  Much easier when you've got some code examples you're asking for
help to make work.  My having posted some (untested) code here might
generate some debate amongst others of the best way to do code this kind of
thing.
 
> If anyone can point me in the right direction, I'd be grateful!

HTH.  By the way, 'Mobs' as a class isn't self-explanatory to me.  What is
that?

-Doug-


From lakicsv@usa.net  Sat Feb 24 08:56:18 2001
From: lakicsv@usa.net (Viktor Lakics)
Date: Sat, 24 Feb 2001 08:56:18 +0000
Subject: [Tutor] exec* and co.
Message-ID: <20010224085618.A13036@Diogenes.co.uk>

I recently wrote a little python script to run fetchmail at certain
times (depending on whether it is a weekday or weekend and certain
times on a day). I have the script working, except the very last
bit, to invoke fetchmail. Here is what I want with pseudo-code:

if weekDay() and workHours():
	run "fetchmail -d 2000"
else:
	sys.exit

I did RTFM and know that I need to use one of the
os.exec...commands. But I am confused about the syntax:

1."os.execv('/bin/echo', ['foo', 'bar']" works, prints out only
"bar". Foo is ignored. But "os.execv('ls', ['foo', '-al']" does not
work, gives me an error. Why? What would be the syntax of "ls -al"?
Also I am confused why we need execv execl execlp etc.? 

Could anyone give me a short tutorial how to use these (please give
real life examples, I did RTFM an still confused) I mean how to
invoke "fetchmail -d 2000", "ls -al", "tar xzvf foo.tar.gz", in
general: "command -param -anotherparam file1.txt file2.bak"!?

And please explain WHY is that particular exec* command was used?


TIA :    Viktor



From dyoo@hkn.eecs.berkeley.edu  Sat Feb 24 10:10:39 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 24 Feb 2001 02:10:39 -0800 (PST)
Subject: [Tutor] exec* and co.
In-Reply-To: <20010224085618.A13036@Diogenes.co.uk>
Message-ID: <Pine.LNX.4.21.0102240205020.884-100000@c82114-a.pinol1.sfba.home.com>

On Sat, 24 Feb 2001, Viktor Lakics wrote:

> I recently wrote a little python script to run fetchmail at certain
> times (depending on whether it is a weekday or weekend and certain
> times on a day). I have the script working, except the very last
> bit, to invoke fetchmail. Here is what I want with pseudo-code:
> 
> if weekDay() and workHours():
> 	run "fetchmail -d 2000"
> else:
> 	sys.exit
> 
> I did RTFM and know that I need to use one of the
> os.exec...commands. But I am confused about the syntax:

I'm actually not too familiar with os.exec(), but have you tried
os.system()?  Here's an example:

###
>>> import os
>>> os.system("ls *.txt")
barfoo.txt  cs3hw2sol.txt  foo.txt
0
###

It's fairly easy to use, and might be just the thing to call fetchmail.  
Good luck!



From rob@jam.rr.com  Sat Feb 24 14:17:35 2001
From: rob@jam.rr.com (R. A.)
Date: Sat, 24 Feb 2001 08:17:35 -0600
Subject: [Tutor] ACM programming problems
Message-ID: <3A97C27F.5C435E38@jam.rr.com>

I swapped email with Antonio Sanchez at the ACM website we have been
referencing on Useless Python yesterday.  After informing them what
we've been up to and giving them a chance to look at the page, I was
told that they hope to keep the problems available for "long" and have
recently upgraded their server.

Mr. Sanchez also proposed that "perhaps you can provide us a python
judge where people can send their solutions".  As far as I can tell,
their site uses a judge program which tests the solutions, although I
don't know how much human involvement in the judging process happens.

Anyway, I found this to be a pleasant and interesting exchange, even
though I know nothing about programming contests and how they work.

Rob
-- 

The Useless Python Repository has received an XHTML face-lift!
http://www.lowerstandard.com/python/pythonsource.html


From tim@johnsons-web.com  Sat Feb 24 17:35:21 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 24 Feb 2001 08:35:21 -0900
Subject: [Tutor] Checking for file existence
References: <007f01c08e46$d79205e0$a410fea9@glen>
Message-ID: <01022408382405.01155@shecom>

Hello:
	Python newbie here.... I'm checking documentation, but can't
find anything like the C access() function.
Is such a function available.
Thanks
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From deirdre@deirdre.net  Sat Feb 24 17:47:45 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Sat, 24 Feb 2001 09:47:45 -0800 (PST)
Subject: [Tutor] Checking for file existence
In-Reply-To: <01022408382405.01155@shecom>
Message-ID: <Pine.LNX.4.31.0102240946210.26089-100000@emperor.deirdre.org>

On Sat, 24 Feb 2001, Tim Johnson wrote:

> Python newbie here.... I'm checking documentation, but can't
> find anything like the C access() function.
> Is such a function available.

What are you trying to do?

access() is NOT a function of the C language.

--
_Deirdre              deirdre@deirdre.net         http://www.deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From tim@johnsons-web.com  Sat Feb 24 19:38:41 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 24 Feb 2001 10:38:41 -0900
Subject: [Tutor] Checking for file existence
References: <Pine.LNX.4.31.0102240946210.26089-100000@emperor.deirdre.org>
Message-ID: <01022410080406.01155@shecom>

Hello Deirdre
On Sat, 24 Feb 2001, you wrote:
> On Sat, 24 Feb 2001, Tim Johnson wrote:
> 
> > Python newbie here.... I'm checking documentation, but can't
> > find anything like the C access() function.
I've earned a living programming in C for some years now...... :)
> > Is such a function available.
> 
> What are you trying to do?
=======================================
Check for the existence of a specific file name, 
before attempting to open it.
=======================================
==>>
> access() is NOT a function of the C language.
Respectfully, I must differ with the statement above
with these qualifications:
1) I do not believe that access() is a *ansi* standard, but is used by most
windows compilers. 
2) I have recently switched to Linux, haven't run any C
code on this machine yet, but 
$ man access
returns:
SYNOPSIS
       #include <unistd.h>
       int access(const char *pathname, int mode);

same prototype as is on dos/borland compiler

Regards
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From rick@niof.net  Sat Feb 24 19:45:26 2001
From: rick@niof.net (Rick Pasotto)
Date: Sat, 24 Feb 2001 14:45:26 -0500
Subject: [Tutor] Checking for file existence
In-Reply-To: <01022408382405.01155@shecom>; from tim@johnsons-web.com on Sat, Feb 24, 2001 at 08:35:21AM -0900
References: <007f01c08e46$d79205e0$a410fea9@glen> <01022408382405.01155@shecom>
Message-ID: <20010224144526.G5869@tc.niof.net>

On Sat, Feb 24, 2001 at 08:35:21AM -0900, Tim Johnson wrote:
> Hello:
> 	Python newbie here.... I'm checking documentation, but can't
> find anything like the C access() function.
> Is such a function available.

import os
if os.path.exists('/full/path/to/file'):
	print 'yes'
else:
	print 'no'

-- 
"The fact that a man has no claim on others (i.e. that it is not their
moral duty to help him & that he cannot demand their help as his
right) does not preclude or prohibit good will among men & does not
make it immoral to offer or to accept voluntary, non-sacrificial
assistance.  It is altruism that has corrupted & perverted human
benevolence by regarding the giver as an object of immolation, & the
receiver as a helplessly miserable object of pity who holds a mortgage
on the lives of others... leaving men no choice but the roles of
sacrificial victim or moral cannibal...   one must begin by rejecting
altruism's terms & all of its ugly emotional after-taste, then take a
fresh look at human relationships.  It is morally proper to accept
help, when it is offered, not as a moral duty, but as an act of good
will & generosity, when the giver can afford it (i.e. when it does not
involve self-sacrifice on his part), & when it is offered in response
to the receiver's virtues, not in response to his flaws, weaknesses or
moral failures, & not on the ground of his need as such."
		-- Ayn Rand
		   Rick Pasotto email: rickp@telocity.com


From tim@johnsons-web.com  Sat Feb 24 20:01:49 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 24 Feb 2001 11:01:49 -0900
Subject: [Tutor] Checking for file existence
References: <20010224144526.G5869@tc.niof.net>
Message-ID: <01022411100508.01155@shecom>

Hi Rick:
On Sat, 24 Feb 2001, you wrote:
> import os
> if os.path.exists('/full/path/to/file'):
> 	print 'yes'
> else:
> 	print 'no'
Yes. Exactly what I was looking for.  Will review os.py for other useful
methods, now that you have brought it to my attention.
Thanks
<snip>
 > -- 
> "The
   --Ayn Rand
</snip> Ah yes,  the "sage" herself. And Thomas Jefferson said....
"Luck is essential to success, and the harder I work, the luckier I get"

Thank you!!
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From dsh8290@rit.edu  Sat Feb 24 21:11:34 2001
From: dsh8290@rit.edu (D-Man)
Date: Sat, 24 Feb 2001 16:11:34 -0500
Subject: [Tutor] exec* and co.
In-Reply-To: <20010224085618.A13036@Diogenes.co.uk>; from lakicsv@usa.net on Sat, Feb 24, 2001 at 08:56:18AM +0000
References: <20010224085618.A13036@Diogenes.co.uk>
Message-ID: <20010224161134.A10504@harmony.cs.rit.edu>

On Sat, Feb 24, 2001 at 08:56:18AM +0000, Viktor Lakics wrote:
| I recently wrote a little python script to run fetchmail at certain
| times (depending on whether it is a weekday or weekend and certain
| times on a day). I have the script working, except the very last
| bit, to invoke fetchmail. Here is what I want with pseudo-code:
| 
| if weekDay() and workHours():
| 	run "fetchmail -d 2000"
| else:
| 	sys.exit

Just a note, you probably mean to call exit, so you need parenthesis.

sys.exit()


| 
| I did RTFM and know that I need to use one of the
| os.exec...commands. But I am confused about the syntax:
| 
| 1."os.execv('/bin/echo', ['foo', 'bar']" works, prints out only
| "bar". Foo is ignored. But "os.execv('ls', ['foo', '-al']" does not
| work, gives me an error. Why? What would be the syntax of "ls -al"?
| Also I am confused why we need execv execl execlp etc.? 
| 


The exec* family of functions descend directly from their C
counterparts.  I haven't used them, but I RTFM'd Linux Programming
(from Sams publishing).  The purpose of them is to replace the current
running process with a different one.  The various forms allow you
different ways of controlling the environment the replacement process
runs in.  (Very important when considering security)  Note that once
the exec call is complete, no more code from you program will run --
your process has been replaced by the new process.  It is usually
wrapped in an if-else with an associated fork() call.  The fork
duplicates the process.  Ex: (psuedo C/Pytnon)

pid = fork()
if ( pid == 0 ) :
    # this is the child process, replace with fechmail
    execv( "fetchmail" , other_args ) # I don't know the proper usage ;-)
else :
    # this is the parent (original) process, wait for the child to
    # exit
    exit_code = wait( pid )


This idiom is so common that both C and Python provide a convenience
function to do this for you.  However, if you are concerned with
security, don't use it. 


import os
exit_code = os.system( "fetchmail options and args as a string like in
bash" )


exit_code will be an integer, and is returned from main() (C programs)
or the argument to sys.exit().  (0 by default, means no errors)

HTH,
-D


From dyoo@hkn.eecs.berkeley.edu  Sat Feb 24 21:30:43 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 24 Feb 2001 13:30:43 -0800 (PST)
Subject: [Tutor] Checking for file existence
In-Reply-To: <01022408382405.01155@shecom>
Message-ID: <Pine.LNX.4.21.0102241330120.6299-100000@c82114-a.pinol1.sfba.home.com>

On Sat, 24 Feb 2001, Tim Johnson wrote:

> Hello:
> 	Python newbie here.... I'm checking documentation, but can't
> find anything like the C access() function.
> Is such a function available.

Hello!  Try the os.path.exists() function: it's documented here:

    http://python.org/doc/current/lib/module-os.path.html



From jdrake@jam.rr.com  Sat Feb 24 21:52:19 2001
From: jdrake@jam.rr.com (Jason Drake)
Date: Sat, 24 Feb 2001 15:52:19 -0600
Subject: [Tutor] Append To File
Message-ID: <001301c09eac$0f896540$80c8a418@jam.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C09E79.C49367C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Okay, first I will admit that I'm still digesting Danny Yoo's advice re: =
string interpolation. I will make attempts to use the technique he =
outlined some time today. What I'm up against right now has to do with =
appending to a file. My current code reads as follows:

#!/usr/bin/python
# append.cgi
# Author: Frik -- www.lowerstandard.com
# append data to a file, then print the data to screen
#

output =3D "no"

print "Content-type: text/html\n"

###
file =3D open('testdb.txt', 'w')
file.write(output)
###
print output
###

Although simple, this does exactly what I want it to do at this stage =
except for one little detail. If I hit this cgi it will write 'no' to my =
text file as it is supposed to, but I want to write to a new line rather =
than on the same line directly after the first. At present my text file =
which is being appended to reads=20

nonononono

What I want it to read as is

no
no
no
no
no

The obvious question, how do I write to a new line in an opened file?

TIA

Jay D

------=_NextPart_000_0010_01C09E79.C49367C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Okay, first I will admit that I'm still =
digesting=20
Danny Yoo's advice re: string interpolation. I will make attempts to use =
the=20
technique he outlined some time today. What I'm up against right now has =
to do=20
with appending to a file. My current code reads as follows:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/bin/python<BR># append.cgi<BR># =
Author: Frik=20
-- <A =
href=3D"http://www.lowerstandard.com">www.lowerstandard.com</A><BR># =
append=20
data to a file, then print the data to screen<BR>#</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>output =3D "no"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>print "Content-type: =
text/html\n"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>###<BR>file =3D open('testdb.txt',=20
'w')<BR>file.write(output)<BR>###<BR>print output<BR>###</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Although simple, this does exactly what =
I want it=20
to do at this stage except for one little detail. If I hit this cgi it =
will=20
write 'no' to my text file as it is supposed to, but I want to write to =
a new=20
line rather than on the same line directly after the first. At present =
my text=20
file which is being appended to reads </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>nonononono</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What I want it to read as =
is</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The obvious question, how do I write to =
a new line=20
in an opened file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jay D</FONT></DIV></BODY></HTML>

------=_NextPart_000_0010_01C09E79.C49367C0--



From sassonir@cs.bgu.ac.il  Sat Feb 24 21:46:25 2001
From: sassonir@cs.bgu.ac.il (sasson iris)
Date: Sat, 24 Feb 2001 23:46:25 +0200 (IST)
Subject: [Tutor] (no subject)
Message-ID: <Pine.SOL.4.10_heb2.08.10102242341410.7153-100000@lace>

Hi i am trying to print the titles of hrefs of an html page 
for example if an html page contains the definition:
<a href="www.google.com">to_google</a>
i am trying to print to_google
when i invoke the method anchor_bgn of the html parser i cant get the 
following words.
could you please help me with that?
thanks



From sassonir@cs.bgu.ac.il  Sat Feb 24 22:03:52 2001
From: sassonir@cs.bgu.ac.il (sasson iris)
Date: Sun, 25 Feb 2001 00:03:52 +0200 (IST)
Subject: [Tutor] Append To File
In-Reply-To: <001301c09eac$0f896540$80c8a418@jam.rr.com>
Message-ID: <Pine.SOL.4.10_heb2.08.10102250001070.9633-100000@lace>

Hi
just write f.write(output +"\n")
On Sat, 24 Feb 2001, Jason Drake wrote:

> Okay, first I will admit that I'm still digesting Danny Yoo's advice re: string interpolation. I will make attempts to use the technique he outlined some time today. What I'm up against right now has to do with appending to a file. My current code reads as follows:
> 
> #!/usr/bin/python
> # append.cgi
> # Author: Frik -- www.lowerstandard.com
> # append data to a file, then print the data to screen
> #
> 
> output = "no"
> 
> print "Content-type: text/html\n"
> 
> ###
> file = open('testdb.txt', 'w')
> file.write(output)
> ###
> print output
> ###
> 
> Although simple, this does exactly what I want it to do at this stage except for one little detail. If I hit this cgi it will write 'no' to my text file as it is supposed to, but I want to write to a new line rather than onthe same line directly after the first. At present my text file which is being appended to reads
> 
> nonononono
> 
> What I want it to read as is
> 
> no
> no
> no
> no
> no
> 
> The obvious question, how do I write to a new line in an opened file?
> 
> TIA
> 
> Jay D
> 



From deirdre@deirdre.net  Sun Feb 25 00:14:30 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Sat, 24 Feb 2001 16:14:30 -0800 (PST)
Subject: [Tutor] File uploads perr HTTP
In-Reply-To: <20010222113258.A29612@harmony.cs.rit.edu>
Message-ID: <Pine.LNX.4.31.0102241612530.11113-100000@emperor.deirdre.org>

On Thu, 22 Feb 2001, D-Man wrote:

> On Wed, Feb 21, 2001 at 08:19:07AM -0500, Sharriff Aina wrote:
> | can someone point me to a URL where I can RTFM "file uploads per HTTP in
> | Python" for dummies? I would be extremly nice if  someone posted a snippet
> | to the list, that would give me a push in the right direction.

> I don't think this is generally possible/(easily) feasible.

Actually, it does. I wrote such a script in Python at one point for Nissan
but I no longer have a copy.

> If you can get FTP or rsync access to the server it would be easier.

That requires that you give a user access; http uploads allow
contributions from untrusted users.

--
_Deirdre              deirdre@deirdre.net         http://www.deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From michaelbaker@operamail.com  Sun Feb 25 00:38:26 2001
From: michaelbaker@operamail.com (michaelbaker@operamail.com)
Date: Sat, 24 Feb 2001 16:38:26 -0800
Subject: [Tutor] PYTHONPATH
In-Reply-To: <E14Wi4B-0002Ze-00@mail.python.org>
Message-ID: <4.3.2.7.1.20010224163102.00a87f00@operamail.com>

I'm  LinuxPPC (based on Red Hat 6.1), the python interpreter works just 
fine, but another program (Blender) which has a pyhton API cannot find 
modules to import. I'm trying to change my .cshrc file to set PYTHONPATH 
without luck. I've added this line to my .cshrc:

setenv PYTHONPATH "/usr/lib/python1.5/"

this doesn't work - help???
thanks



From jar@mminternet.com  Sun Feb 25 01:24:17 2001
From: jar@mminternet.com (James A Roush)
Date: Sat, 24 Feb 2001 17:24:17 -0800
Subject: [Tutor] Stupid newbie question
Message-ID: <000001c09ec9$abb11c20$7fc256d8@thor>

I have a piece of code, listed below, it runs fine except for the line I
commented out.  The code reads a sequential text file, with two fields per
record, delimited by a tab.  The two fields are placed in a dictionary.  The
problem starts when I try to convert one field to uppercase.  Any ideas?

BTW, I'm new to Python but not programming in general.

site_list = {}
SITELIST = open(sitelist_file, 'r')
for line in SITELIST.readlines():
    web_site = line.split('\t')
    print web_site[0],web_site[1]
#    site_list[web_site[0].upper] = web_site[1]
SITELIST.close



From baris@gelecek.com.tr  Sun Feb 25 01:54:10 2001
From: baris@gelecek.com.tr (=?iso8859-9?Q?Bar=FD=FE_Metin?=)
Date: Sun, 25 Feb 2001 03:54:10 +0200 (EET)
Subject: [Tutor] Stupid newbie question
In-Reply-To: <000001c09ec9$abb11c20$7fc256d8@thor>
Message-ID: <Pine.LNX.4.10.10102250351150.15464-100000@localhost.localdomain>

Hello;

You should use parantheses after upper like :

site_list[web_site[0].upper()]= web_site[1]

Because it is a built-in method 

	   -----
	Baris Metin
	   -----

On Sat, 24 Feb 2001, James A Roush wrote:

> I have a piece of code, listed below, it runs fine except for the line I
> commented out.  The code reads a sequential text file, with two fields per
> record, delimited by a tab.  The two fields are placed in a dictionary.  The
> problem starts when I try to convert one field to uppercase.  Any ideas?
> 
> BTW, I'm new to Python but not programming in general.
> 
> site_list = {}
> SITELIST = open(sitelist_file, 'r')
> for line in SITELIST.readlines():
>     web_site = line.split('\t')
>     print web_site[0],web_site[1]
> #    site_list[web_site[0].upper] = web_site[1]
> SITELIST.close
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 25 05:51:51 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 24 Feb 2001 21:51:51 -0800 (PST)
Subject: [Tutor] exec vs system (fwd)
Message-ID: <Pine.LNX.4.21.0102242151460.9736-100000@c82114-a.pinol1.sfba.home.com>


---------- Forwarded message ----------
Date: Sat, 24 Feb 2001 21:05:50 +0000
From: Viktor Lakics <lakicsv@usa.net>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: exec vs system

On Sat, Feb 24, 2001 at 02:10:39AM -0800, Danny Yoo wrote:
> On Sat, 24 Feb 2001, Viktor Lakics wrote:
> 
> > I have the script working, except the very last
> > bit, to invoke fetchmail. Here is what I want with pseudo-code:
> > 
> > if weekDay() and workHours():
> > 	run "fetchmail -d 2000"
> > else:
> > 	sys.exit
> > 
> > I did RTFM and know that I need to use one of the
> > os.exec...commands. But I am confused about the syntax:
> 
> I'm actually not too familiar with os.exec(), but have you tried
> os.system()?  Here's an example:

The reason I have not tried, was that I thought that the difference
between execv and system is that exec is replacing the python
interpreter when it is invoked. And I thought if I invoke fetchmail
in demon mode (that is what the -d stands for) it is better to run
it this way...

Is that right? Does it make any difference?

Viktor 



From bsass@freenet.edmonton.ab.ca  Sun Feb 25 07:49:14 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Sun, 25 Feb 2001 00:49:14 -0700 (MST)
Subject: [Tutor] PYTHONPATH
In-Reply-To: <4.3.2.7.1.20010224163102.00a87f00@operamail.com>
Message-ID: <Pine.LNX.4.33.0102250039590.27464-100000@bms>

On Sat, 24 Feb 2001 michaelbaker@operamail.com wrote:
> I'm  LinuxPPC (based on Red Hat 6.1), the python interpreter works just
> fine, but another program (Blender) which has a pyhton API cannot find
> modules to import. I'm trying to change my .cshrc file to set PYTHONPATH
> without luck. I've added this line to my .cshrc:
>
> setenv PYTHONPATH "/usr/lib/python1.5/"
>
> this doesn't work - help???
> thanks

This is what python 1.5.2 thinks the path is on my Debian box,

>>> sys.path
['', '/usr/lib/python1.5/', '/usr/lib/python1.5/plat-linux2',
'/usr/lib/python1.5/lib-tk', '/usr/lib/python1.5/lib-dynload',
'/usr/local/lib/python1.5/site-packages',
'/usr/local/lib/site-python', '/usr/lib/python1.5/site-packages',
'/usr/lib/python1.5/site-packages/HTMLgen',
'/usr/lib/python1.5/site-packages/PIL',
'/usr/lib/python1.5/site-packages/graphics',
'/usr/lib/python1.5/site-packages/Numerical',
'/usr/lib/site-python']


- Bruce



From SanHwtt@netscape.net  Sun Feb 25 09:03:09 2001
From: SanHwtt@netscape.net (SanHwtt@netscape.net)
Date: Sun, 25 Feb 2001 04:03:09 -0500
Subject: [Tutor] (no subject)
Message-ID: <3A98CA4D.5070309@netscape.net>

hi um i kinda dont know alot about computers but would like to learn uh 
the tutorial is really confusing and i kinda need to learn to use it 
from a human in english cuz you know everybody has to start somewhere 
and im startin with python



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 25 10:14:31 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 25 Feb 2001 02:14:31 -0800 (PST)
Subject: [Tutor] (no subject)
In-Reply-To: <3A98CA4D.5070309@netscape.net>
Message-ID: <Pine.LNX.4.21.0102250207150.11626-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 25 Feb 2001 SanHwtt@netscape.net wrote:

> hi um i kinda dont know alot about computers but would like to learn uh 
> the tutorial is really confusing and i kinda need to learn to use it 
> from a human in english cuz you know everybody has to start somewhere 

*laugh*  Sure, understandable.


> and im startin with python

If you're looking at the official Python tutorial from:

    http://python.org/doc/current/tut/tut.html

then stop!  That particular one is a whirlwind tour that assumes that you
already know a C-ish language.  Don't read it for a while; it will
probably frustrate someone just beginning to learn a new language.  This
is a common complaint from people; perhaps Guido should put a little
warning label at the beginning of that tutorial.  *grin*


Instead, take a look at the Introductions section of python.org:

    http://python.org/doc/Intros.html

which has more focused and comprehensive tutorials on learning Python.  
There's a section there called "Introductions to Python programming for
non-programmers", which has some very good tutorials, including these:

    http://members.xoom.com/alan_gauld/tutor/tutindex.htm
    http://www.honors.montana.edu/~jjc/easytut/easytut/

and all of the tutorials there are very good.  Also, if you have any
question while you're going through them, you can always ask us, and we'll
try to clarify their points.

Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 25 10:29:54 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 25 Feb 2001 02:29:54 -0800 (PST)
Subject: [Tutor] A Python introduction for lisp hackers!
Message-ID: <Pine.LNX.4.21.0102250226460.11626-100000@c82114-a.pinol1.sfba.home.com>

Peter Norvig, the author of "Paradigms of Artificial Intelligence
Programming: Case Studies in Common Lisp", has written a comparison piece
between Python and Lisp:

    http://www.norvig.com/python-lisp.html

Actually, this was written a LONG LONG time ago... but I thought it might
be interesting to look at.



From Desai.Dinakar@mayo.edu  Sun Feb 25 13:04:59 2001
From: Desai.Dinakar@mayo.edu (Dinakar)
Date: Sun, 25 Feb 2001 07:04:59 -0600
Subject: [Tutor] PYTHONPATH
References: <Pine.LNX.4.33.0102250039590.27464-100000@bms>
Message-ID: <3A9902FA.A1FEF7F8@mayo.edu>

This is a multi-part message in MIME format.
--------------526C824442FB29C12D1DA7B9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Bruce:

how to change the path shown by sys.path. Does one need to change PYTHONPATH
in .bashrc or someother file. I would appreciate, if some one on the group
clarify this.

Thank you.

Dinakar


Bruce Sass wrote:

> On Sat, 24 Feb 2001 michaelbaker@operamail.com wrote:
> > I'm  LinuxPPC (based on Red Hat 6.1), the python interpreter works just
> > fine, but another program (Blender) which has a pyhton API cannot find
> > modules to import. I'm trying to change my .cshrc file to set PYTHONPATH
> > without luck. I've added this line to my .cshrc:
> >
> > setenv PYTHONPATH "/usr/lib/python1.5/"
> >
> > this doesn't work - help???
> > thanks
>
> This is what python 1.5.2 thinks the path is on my Debian box,
>
> >>> sys.path
> ['', '/usr/lib/python1.5/', '/usr/lib/python1.5/plat-linux2',
> '/usr/lib/python1.5/lib-tk', '/usr/lib/python1.5/lib-dynload',
> '/usr/local/lib/python1.5/site-packages',
> '/usr/local/lib/site-python', '/usr/lib/python1.5/site-packages',
> '/usr/lib/python1.5/site-packages/HTMLgen',
> '/usr/lib/python1.5/site-packages/PIL',
> '/usr/lib/python1.5/site-packages/graphics',
> '/usr/lib/python1.5/site-packages/Numerical',
> '/usr/lib/site-python']
>
> - Bruce
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--------------526C824442FB29C12D1DA7B9
Content-Type: text/x-vcard; charset=us-ascii;
 name="desai.dinakar.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Dinakar
Content-Disposition: attachment;
 filename="desai.dinakar.vcf"

begin:vcard 
n:Desai;Dinakar 
tel;work:507-266-2831
x-mozilla-html:FALSE
org:Mayo Foundation;Clinical Trials Section
adr:;;;Rochester ;MN;55905;USA
version:2.1
email;internet:desai.dinakar@mayo.edu
x-mozilla-cpt:;0
fn:Dinakar Desai
end:vcard

--------------526C824442FB29C12D1DA7B9--



From markmitchell13@hotmail.com  Sun Feb 25 15:39:43 2001
From: markmitchell13@hotmail.com (Mark Mitchell)
Date: Sun, 25 Feb 2001 15:39:43
Subject: [Tutor] (no subject)
Message-ID: <F62dX9ypOydcH2ETM21000109f4@hotmail.com>

I'm in the same boat as you are, and I have found Alan Gauld's book Learn to 
Program Using Python a major help. It's in plain English and easily 
accessible. Good luck!


>From: SanHwtt@netscape.net
>To: tutor@python.org
>Subject: [Tutor] (no subject)
>Date: Sun, 25 Feb 2001 04:03:09 -0500
>
>hi um i kinda dont know alot about computers but would like to learn uh
>the tutorial is really confusing and i kinda need to learn to use it
>from a human in english cuz you know everybody has to start somewhere
>and im startin with python
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From frankg@overland.net  Sun Feb 25 18:27:02 2001
From: frankg@overland.net (Frank Garcia)
Date: Sun, 25 Feb 2001 12:27:02 -0600
Subject: [Tutor] (no subject)
In-Reply-To: <Pine.LNX.4.21.0102250207150.11626-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <B6BE9F05.8A82%frankg@overland.net>

> There's a section there called "Introductions to Python programming for
> non-programmers", which has some very good tutorials, including these:
> 
> http://members.xoom.com/alan_gauld/tutor/tutindex.htm

The url for Alan Gauld's tutorial has changed to:

http://www.crosswinds.net/~agauld

Frank



From jar@mminternet.com  Sun Feb 25 18:26:57 2001
From: jar@mminternet.com (James A Roush)
Date: Sun, 25 Feb 2001 10:26:57 -0800
Subject: [Tutor] Stupid newbie question
In-Reply-To: <Pine.LNX.4.10.10102250351150.15464-100000@localhost.localdomain>
Message-ID: <000501c09f58$88f63870$7fc256d8@thor>

Yes, that works.  Thank you.

> -----Original Message-----
> From: Bar=FD=FE Metin [mailto:baris@gelecek.com.tr]
> Sent: Saturday, February 24, 2001 5:54 PM
> To: James A Roush
> Cc: tutor@python.org
> Subject: Re: [Tutor] Stupid newbie question
>
>
> Hello;
>
> You should use parantheses after upper like :
>
> site_list[web_site[0].upper()]=3D web_site[1]
>
> Because it is a built-in method
>
> 	   -----
> 	Baris Metin
> 	   -----
>
> On Sat, 24 Feb 2001, James A Roush wrote:
>
> > I have a piece of code, listed below, it runs fine except for the lin=
e I
> > commented out.  The code reads a sequential text file, with two
> fields per
> > record, delimited by a tab.  The two fields are placed in a
> dictionary.  The
> > problem starts when I try to convert one field to uppercase.  Any ide=
as?
> >
> > BTW, I'm new to Python but not programming in general.
> >
> > site_list =3D {}
> > SITELIST =3D open(sitelist_file, 'r')
> > for line in SITELIST.readlines():
> >     web_site =3D line.split('\t')
> >     print web_site[0],web_site[1]
> > #    site_list[web_site[0].upper] =3D web_site[1]
> > SITELIST.close
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 25 18:56:45 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 25 Feb 2001 10:56:45 -0800 (PST)
Subject: [Tutor] (no subject)
In-Reply-To: <B6BE9F05.8A82%frankg@overland.net>
Message-ID: <Pine.LNX.4.21.0102251055510.21116-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 25 Feb 2001, Frank Garcia wrote:

> > There's a section there called "Introductions to Python programming for
> > non-programmers", which has some very good tutorials, including these:
> > 
> > http://members.xoom.com/alan_gauld/tutor/tutindex.htm
> 
> The url for Alan Gauld's tutorial has changed to:
> 
> http://www.crosswinds.net/~agauld

Ooops!  Thanks.  The link on python.org is still directed at the old
location though.



From bsass@freenet.edmonton.ab.ca  Sun Feb 25 21:31:36 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Sun, 25 Feb 2001 14:31:36 -0700 (MST)
Subject: [Tutor] PYTHONPATH
In-Reply-To: <3A9902FA.A1FEF7F8@mayo.edu>
Message-ID: <Pine.LNX.4.33.0102251315370.27849-100000@bms>

On Sun, 25 Feb 2001, Dinakar wrote:
> how to change the path shown by sys.path. Does one need to change PYTHONPATH
> in .bashrc or someother file. I would appreciate, if some one on the group
> clarify this.

Well, you have at least two choices regarding PYTHONPATH; put it in
the system wide shell profile (/etc/profile), or your per-user shell
profile (.bashrc, .cshrc, both if you use both shells).  This really
has little to do with Python, use private-email if you need help with
shell stuff.

What I'm wondering is if it is Blender you need to tell about Python
modules, or Python you need to tell about Blender modules?  In the
first case, setting the PYTHONPATH in the environment is probably the
thing to do; in the second case it would be best to but the Blender
modules on the sys.path.

What I would do is find the location of the modules that are not being
found automatically, if they are not on the sys.path then make a
symlink from the dir containing the missing modules to inside a dir on
the sys.path.  Exactly where this link points to depends on the
characteristics of the modules and whether or not Blender (assuming
Blender module are out of place) is from a .rpm or not.  If the Python
code in Blender depends on Python-1.5, then use
/usr/lib/python1.5/site-packages; if it will work with any version of
Python, use /usr/lib/site-python; if you built Blender yourself, use
/usr/local/lib/{python1.5,site-packages}, as appropriate.


- Bruce

-- 
> Bruce Sass wrote:
>
> > On Sat, 24 Feb 2001 michaelbaker@operamail.com wrote:
> > > I'm  LinuxPPC (based on Red Hat 6.1), the python interpreter works just
> > > fine, but another program (Blender) which has a pyhton API cannot find
> > > modules to import. I'm trying to change my .cshrc file to set PYTHONPATH
> > > without luck. I've added this line to my .cshrc:
> > >
> > > setenv PYTHONPATH "/usr/lib/python1.5/"
> > >
> > > this doesn't work - help???
> > > thanks
> >
> > This is what python 1.5.2 thinks the path is on my Debian box,
> >
> > >>> sys.path
> > ['', '/usr/lib/python1.5/', '/usr/lib/python1.5/plat-linux2',
> > '/usr/lib/python1.5/lib-tk', '/usr/lib/python1.5/lib-dynload',
> > '/usr/local/lib/python1.5/site-packages',
> > '/usr/local/lib/site-python', '/usr/lib/python1.5/site-packages',
> > '/usr/lib/python1.5/site-packages/HTMLgen',
> > '/usr/lib/python1.5/site-packages/PIL',
> > '/usr/lib/python1.5/site-packages/graphics',
> > '/usr/lib/python1.5/site-packages/Numerical',
> > '/usr/lib/site-python']



From dyoo@hkn.eecs.berkeley.edu  Sun Feb 25 23:01:02 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 25 Feb 2001 15:01:02 -0800 (PST)
Subject: [Tutor] (no subject)
In-Reply-To: <3A993B0C.4080004@netscape.net>
Message-ID: <Pine.LNX.4.21.0102251459450.22772-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 25 Feb 2001 SanHwtt@netscape.net wrote:

> thanks im so glad i finally got through to a human! i am as i speak 
> reviewing the tutorial by alan gauld it still confusing but im getting 
> somewhere! again thank you very much

No problem; don't forget, when you're replying, to do a reply to all, so
that we can continue the discussion with everyone else.

(Hmmm... it's interesting that you're assuming I'm human.  *grin*)



From jdrake@jam.rr.com  Sun Feb 25 23:23:26 2001
From: jdrake@jam.rr.com (Jason Drake)
Date: Sun, 25 Feb 2001 17:23:26 -0600
Subject: [Tutor] Human?
Message-ID: <007801c09f81$f4b564e0$80c8a418@jam.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0075_01C09F4F.A9CEA9A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

As often and as quickly as Danny Yoo replies to Python questions, I'm =
not so sure he isn't actually a well compiled interpreter... Where can I =
get a copy?

Jay D.

------=_NextPart_000_0075_01C09F4F.A9CEA9A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>As often and as quickly as Danny Yoo =
replies to=20
Python questions, I'm not so sure he isn't actually a well compiled=20
interpreter... Where can I get a copy?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jay D.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0075_01C09F4F.A9CEA9A0--



From scarblac@pino.selwerd.nl  Sun Feb 25 23:15:20 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 26 Feb 2001 00:15:20 +0100
Subject: [Tutor] Human?
In-Reply-To: <007801c09f81$f4b564e0$80c8a418@jam.rr.com>; from jdrake@jam.rr.com on Sun, Feb 25, 2001 at 05:23:26PM -0600
References: <007801c09f81$f4b564e0$80c8a418@jam.rr.com>
Message-ID: <20010226001520.A7735@pino.selwerd.nl>

On Sun, Feb 25, 2001 at 05:23:26PM -0600, Jason Drake wrote:
> As often and as quickly as Danny Yoo replies to Python questions, I'm not
> so sure he isn't actually a well compiled interpreter... Where can I get a
> copy?

This is an accepted, unexplained phenomenon in the Python worlds; see the
famous bots Timbot and effbot on comp.lang.python, and the newer and
extremely verbose Alexbot. It's unknown where they all come from, but
speculation often implies the "Python Secret Underground", which of course
does not exist. However, it is hard to check these stories bec


From dsh8290@rit.edu  Sun Feb 25 23:50:45 2001
From: dsh8290@rit.edu (D-Man)
Date: Sun, 25 Feb 2001 18:50:45 -0500
Subject: [Tutor] exec vs system (fwd)
In-Reply-To: <Pine.LNX.4.21.0102242151460.9736-100000@c82114-a.pinol1.sfba.home.com>; from dyoo@hkn.eecs.berkeley.edu on Sat, Feb 24, 2001 at 09:51:51PM -0800
References: <Pine.LNX.4.21.0102242151460.9736-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <20010225185045.A12893@harmony.cs.rit.edu>

| ---------- Forwarded message ----------
| Date: Sat, 24 Feb 2001 21:05:50 +0000
| From: Viktor Lakics <lakicsv@usa.net>
| To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
| Subject: exec vs system
| 
| On Sat, Feb 24, 2001 at 02:10:39AM -0800, Danny Yoo wrote:
| 
| The reason I have not tried, was that I thought that the difference
| between execv and system is that exec is replacing the python
| interpreter when it is invoked. And I thought if I invoke fetchmail
| in demon mode (that is what the -d stands for) it is better to run
| it this way...
| 
| Is that right? Does it make any difference?
| 

That is right, execv will replace the current process (the python
interperter) with a new proecss (fetchmail in your case).

I don't think it makes any difference.  If you run fetchmail in daemon
mode from the command line, your shell returns to an interactive state
immediately (after reporting the PID of the fetchmail daemon).  The
way fetchmail works (basically), if you start it in daemon mode is :


pid = fork()
if pid == 0 :
    # this is the child,
    while 1 :
        get_mail()
        sleep( 1000 )
else :
    # this is the original parent, 
    # return control back to the previous process (shell, whatever)
    sys.exit( 0 )



If your script simply invokes fetchmial using os.system, you will get
the success exit value almost immediately, while the deamon runs in
the background and your script is free to terminate the python
interpreter at its leisure.  If you use execv, the interpreter will be
replaced by fetchmail, which will fork and then terminate the parent
process.

You can also start fetchmail in daemon mode by specifying it in your
fetchmailrc file.

I don't know if this is relevant/helpful at all, but I simply put
"fetchmail" in my .bash_profile file so that fetchmail is run when I
login.  I put "fetchmail --kill" (or whatever the option is, I'm not
at my linux box right now) in my .logout file so that it terminates
when I log out.  I can also run fetchmail at any time since it will
check for an already running daemon and simply wake it up if it
exists.

-D



From sheila@thinkspot.net  Mon Feb 26 04:30:59 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 25 Feb 2001 20:30:59 -0800
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
Message-ID: <2103F5B0E76@kserver.org>

OK, now I'm really confused.

I don't really "get" the difference yet, between mutable and immutable types,
but I figured I would eventually get it. But at least I thought I understood
that an object could not change its type or its id. At least I thought I
understood that.

Then, explain this from my Python IDLE:
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> mytuple = 'a', 'b', 'c'
>>> mytuple
('a', 'b', 'c')
>>> type (mytuple)
<type 'tuple'>
>>> mytyple = 'b'
>>> mytyple
'b'
>>> type (mytyple)
<type 'string'>
>>> mytuple = mytyple
>>> type (mytuple)
<type 'string'>
>>>  

mytuple is originally a tuple. And then I end up changing it to a string? I
thought this was not possible.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From sheila@thinkspot.net  Mon Feb 26 04:36:49 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 25 Feb 2001 20:36:49 -0800
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2103F5B0E76@kserver.org>
References: <2103F5B0E76@kserver.org>
Message-ID: <21580C50AFB@kserver.org>

OK, it gets better and better. Now explain this:

>>> mytuple
'b'
>>> mylist =['a', 'b', 'c']
>>> type (mylist)
<type 'list'>
>>> id(mylist)
11519964
>>> id (mytuple)
8532608
>>> mylist = mytuple
>>> type (mylist)
<type 'string'>
>>> id (mylist)
8532608
>>> 



--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/


From rick@niof.net  Mon Feb 26 04:49:53 2001
From: rick@niof.net (Rick Pasotto)
Date: Sun, 25 Feb 2001 23:49:53 -0500
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2103F5B0E76@kserver.org>; from sheila@thinkspot.net on Sun, Feb 25, 2001 at 08:30:59PM -0800
References: <2103F5B0E76@kserver.org>
Message-ID: <20010225234953.I5869@tc.niof.net>

On Sun, Feb 25, 2001 at 08:30:59PM -0800, Sheila King wrote:
> OK, now I'm really confused.
> 
> I don't really "get" the difference yet, between mutable and immutable types,
> but I figured I would eventually get it. But at least I thought I understood
> that an object could not change its type or its id. At least I thought I
> understood that.
> 
> Then, explain this from my Python IDLE:
> Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.6 -- press F1 for help
> >>> mytuple = 'a', 'b', 'c'
> >>> mytuple
> ('a', 'b', 'c')
> >>> type (mytuple)
> <type 'tuple'>
> >>> mytyple = 'b'
> >>> mytyple
> 'b'
> >>> type (mytyple)
> <type 'string'>
> >>> mytuple = mytyple
> >>> type (mytuple)
> <type 'string'>
> >>>  
> 
> mytuple is originally a tuple. And then I end up changing it to a string? I
> thought this was not possible.

'mytuple' is a *name*. First it is the name of a tuple and then it is
the name of a string. "The map is not the territory." It is the *object*
that 'mytuple' names when it is the name of a tuple that is immutable.

-- 
"There is no more subtle means of transforming the basic concepts of
our government, or shifting from the preeminence of individual rights,
to the preeminence of government wishes, than is afforded by
redefinition of 'general welfare', as that term is used to define the
Government's power of seizures...  In essence the claim is that if
slums exist the Government may seize, redevelop & sell all the
property in any area it may select as appropriate, so long as the area
includes the slum area.  This amounts to a claim on the part of the
authorities for unreviewable power to seize & sell whole sections of
the city."
		-- DC District Court 1953
		   Rick Pasotto email: rickp@telocity.com


From sheila@thinkspot.net  Mon Feb 26 05:25:07 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 25 Feb 2001 21:25:07 -0800
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <20010225234953.I5869@tc.niof.net>
References: <2103F5B0E76@kserver.org> <20010225234953.I5869@tc.niof.net>
Message-ID: <2418AF346E6@kserver.org>

On Sun, 25 Feb 2001 23:49:53 -0500, Rick Pasotto <rick@niof.net>  wrote about
Re: [Tutor] Tuples, Dictionarys and mutable vs. immutable:

:
:'mytuple' is a *name*. First it is the name of a tuple and then it is
:the name of a string. "The map is not the territory." It is the *object*
:that 'mytuple' names when it is the name of a tuple that is immutable.

Yes, OK. I can get used to this. I'm just used to strongly typed programming
languages like Pascal. You could never change the type that a variable
identifier referred to during a program. And the slot in the memory where the
object is stored would be a different location if you did something like what
I tried above, having two different "local" variables, and then assigning the
value of one to another. It would be the same value, but stored in two
different memory locations. Rather than having one object, with two different
variable names referring to the same memory location. 

I guess it will just take some getting used to.


--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From sheila@thinkspot.net  Mon Feb 26 06:35:33 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 25 Feb 2001 22:35:33 -0800
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2418AF346E6@kserver.org>
References: <2103F5B0E76@kserver.org> <20010225234953.I5869@tc.niof.net> <2418AF346E6@kserver.org>
Message-ID: <28178443B07@kserver.org>

OK, another question.

Here is something I ran on IDLE. A fresh session:

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> x=1
>>> id(x)
8400864
>>> y=1
>>> id(y)
8400864
>>> del x
>>> del y
>>> z = 1
>>> id(z)
8400864
>>> id(1)
8400864
>>> id('a')
8532752
>>> id(('a', 'b', 'c'))
8756556
>>> z=('a', 'b', 'c')
>>> id(z)
8756556
>>> 

OK, question:

See how, even before I assigned the tuple ('a', 'b', 'c') to any variable, in
fact, the first time I mentioned it in the shell session, it already had an
id(). Which, means it had a memory location.

Does Python create that location and assign the object to it as soon as I
mention it? Was that memory assignment made when I typed:
>>> id(('a', 'b', 'c'))

I'm trying to figure out the way this all works in the memories. I did read
http://www.python.org/doc/current/ref/objects.html

but it still isn't clear to me how this works. (I'm sort of working through
"Diving into Python" right now, in slow motion...)

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From scarblac@pino.selwerd.nl  Mon Feb 26 07:09:58 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 26 Feb 2001 08:09:58 +0100
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2103F5B0E76@kserver.org>; from sheila@thinkspot.net on Sun, Feb 25, 2001 at 08:30:59PM -0800
References: <2103F5B0E76@kserver.org>
Message-ID: <20010226080958.A8148@pino.selwerd.nl>

On Sun, Feb 25, 2001 at 08:30:59PM -0800, Sheila King wrote:
> OK, now I'm really confused.
> 
> I don't really "get" the difference yet, between mutable and immutable types,
> but I figured I would eventually get it. But at least I thought I understood
> that an object could not change its type or its id. At least I thought I
> understood that.
> 
> Then, explain this from my Python IDLE:
> Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.6 -- press F1 for help
> >>> mytuple = 'a', 'b', 'c'
> >>> mytuple
> ('a', 'b', 'c')
> >>> type (mytuple)
> <type 'tuple'>
> >>> mytyple = 'b'
> >>> mytyple
> 'b'
> >>> type (mytyple)
> <type 'string'>
> >>> mytuple = mytyple
> >>> type (mytuple)
> <type 'string'>
> >>>  
> 
> mytuple is originally a tuple. And then I end up changing it to a string? I
> thought this was not possible.

The key thing to remember is that 'mytuple' is just a name for some object.
When you assign to it, it becomes a name for another object.

If that object is immutable, then *it* can't be changed. But you can always
give the name to something else.

The id() of an object never changes; the object gets an id when it's created
and that is that.

Simple assignment never changes an object, so it doesn't care if something
is mutable or not. It gives a name to an object.

The exception is when you assign to something *inside* an object, like x[3]=4
(when x is a list or dictionary). The object 4 isn't changed, but the object
x is, since one of its contents now refers to something else.

Therefore, with tuples you can't do mytuple[0]=4, but you can say mytuple=4
(the old tuple object is simply discarded when nothing else refers to it).

>>> x = [1,2]
>>> id(x)
136158892
>>> x[0]=3   # x is mutable, so we can change it
>>> x
[3, 2]
>>> id(x)
136158892    # x is still the same object
>>> y=x      # now y and x are names for the same object
>>> y.append(4) # again, the object is changed
>>> x
[3, 2, 4]    # So x is changed as well, after all they're the same


>>> x = (1,2) # Now x is immutable
>>> id(x)
136049924
>>> x[0]=3    # Error! x is immutable so can't assign to internals
>>> y=x       # Now x and y are names for the same object
>>> x = x+(3,4)
>>> x
(1,2,3,4)
>>> y
(1,2)
>>> id(y)
136049924     # Still the old object
>>> id(x)
136126740     # New object!

Now y is not changed, since when we did "x = x+(3,4)", x became a name for a
*new* object, namely the result of the addition.

I believe this is the key thing to understand about Python. Ask more
questions if you don't get it yet :)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon Feb 26 07:20:04 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 26 Feb 2001 08:20:04 +0100
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <28178443B07@kserver.org>; from sheila@thinkspot.net on Sun, Feb 25, 2001 at 10:35:33PM -0800
References: <2103F5B0E76@kserver.org> <20010225234953.I5869@tc.niof.net> <2418AF346E6@kserver.org> <28178443B07@kserver.org>
Message-ID: <20010226082004.B8148@pino.selwerd.nl>

On Sun, Feb 25, 2001 at 10:35:33PM -0800, Sheila King wrote:
> OK, another question.
> 
> Here is something I ran on IDLE. A fresh session:
> 
> Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.6 -- press F1 for help
> >>> x=1
> >>> id(x)
> 8400864
> >>> y=1
> >>> id(y)
> 8400864
> >>> del x
> >>> del y
> >>> z = 1
> >>> id(z)
> 8400864
> >>> id(1)
> 8400864
> >>> id('a')
> 8532752
> >>> id(('a', 'b', 'c'))
> 8756556
> >>> z=('a', 'b', 'c')
> >>> id(z)
> 8756556
> >>> 
> 
> OK, question:
> 
> See how, even before I assigned the tuple ('a', 'b', 'c') to any variable, in
> fact, the first time I mentioned it in the shell session, it already had an
> id(). Which, means it had a memory location.
> 
> Does Python create that location and assign the object to it as soon as I
> mention it? Was that memory assignment made when I typed:
> >>> id(('a', 'b', 'c'))

Yes. Once you mention ('a','b','c') in some expression, it needs a memory
location, since it needs to exists somewhere before you do further
computation on it (like give it as an argument to id(), in this case).

However, right after the expression, nothing refers to the tuple anymore,
and the memory space is freed. 'z' simply takes the same memory, so the ids
are accidentally equal.

Actually, that is how it works in a normal program. Try typing
print id((1,2))
z=(3,4)
print id(z)

into some file, and then run "python filename". For me, that prints the same
number twice. However, it doesn't work in the interactive interpreter:
apparently it keeps a reference to the old tuple around somewhere in its
internals, or something like that...

-- 
Remco Gerlich


From sheila@thinkspot.net  Mon Feb 26 07:37:53 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 25 Feb 2001 23:37:53 -0800
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <20010226080958.A8148@pino.selwerd.nl>
References: <2103F5B0E76@kserver.org> <20010226080958.A8148@pino.selwerd.nl>
Message-ID: <2BA15647C39@kserver.org>

On Mon, 26 Feb 2001 08:09:58 +0100, Remco Gerlich <scarblac@pino.selwerd.nl>
wrote about Re: [Tutor] Tuples, Dictionarys and mutable vs. immutable:

:Now y is not changed, since when we did "x = x+(3,4)", x became a name for a
:*new* object, namely the result of the addition.
:
:I believe this is the key thing to understand about Python. Ask more
:questions if you don't get it yet :)

Yes, I think this is extremely important, and I need to get it. Thanks for
your examples. They are very helpful. Thanks for the invitation to ask
questions. I think I will!

OK, an immutable type, such as a tuple, cannot be changed. Once created, it is
assigned a memory location, and if I do something like this:

>>> z=(1,2)
>>> z+=(3,4)
>>> print z
(1, 2, 3, 4)
>>> 

The tuple I end up with is not the same as the one I started with. It has a
different memory location, and a different id(). However, based on what Remco
wrote earlier in this thread, I'd guess that the memory for the tuple (1,2)
has now been freed, if it has no name assigned to it, and I can now assume
that the operating system now has access to that memory location again?

OK, but now the mutable types:
lists and dictionaries.

I know a dictionary has a copy method, so that I can have a new dictionary
with same contents, without having to worry about modifying the contents of
the original:

>>> dict={1:"one", 2:"two"}
>>> dict
{2: 'two', 1: 'one'}
>>> id(dict)
12029900
>>> dict2 = dict.copy()
>>> id(dict2)
12064908
>>> 

What about lists? So far as I can determine, they do not have a copy method,
and I would be modifying the "original" list, if I tried to assign it to a
second variable name and then make modifications to that one, without
modifying the original.

What is the proscribed method for handling lists so that one is a copy that
can be modified without changing the original version?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




From scarblac@pino.selwerd.nl  Mon Feb 26 07:47:24 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 26 Feb 2001 08:47:24 +0100
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2BA15647C39@kserver.org>; from sheila@thinkspot.net on Sun, Feb 25, 2001 at 11:37:53PM -0800
References: <2103F5B0E76@kserver.org> <20010226080958.A8148@pino.selwerd.nl> <2BA15647C39@kserver.org>
Message-ID: <20010226084724.A8221@pino.selwerd.nl>

On Sun, Feb 25, 2001 at 11:37:53PM -0800, Sheila King wrote:
> What about lists? So far as I can determine, they do not have a copy method,
> and I would be modifying the "original" list, if I tried to assign it to a
> second variable name and then make modifications to that one, without
> modifying the original.
> 
> What is the proscribed method for handling lists so that one is a copy that
> can be modified without changing the original version?

list1 = [1,2,3]

list2 = list1[:]  # Use slice notation to get the whole list
or
import copy
list2 = copy.copy(list1)

Now list2 is a so-called "shallow" copy of list1, the things in the list are
copied, but those may again be the same objects (think lists in lists).
If you want to recursively copy them all, use copy.deepcopy().

-- 
Remco Gerlich


From tim.one@home.com  Mon Feb 26 08:18:28 2001
From: tim.one@home.com (Tim Peters)
Date: Mon, 26 Feb 2001 03:18:28 -0500
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2BA15647C39@kserver.org>
Message-ID: <LNBBLJKPBEHFEDALKOLCIEPKJBAA.tim.one@home.com>

[Sheila King]
> ...
> OK, an immutable type, such as a tuple, cannot be changed. Once
> created, it is assigned a memory location,

That last part is true, but is not unique to tuples, of course.  *Every*
object needs some memory to live in, even None.

> and if I do something like this:
>
> >>> z=(1,2)
> >>> z+=(3,4)
> >>> print z
> (1, 2, 3, 4)
> >>>
>
> The tuple I end up with is not the same as the one I started
> with. It has a different memory location, and a different id().

Right.  By the way, under the covers, id(x) *is* the memory location of x.

> However, based on what Remco wrote earlier in this thread, I'd guess
> that the memory for the tuple (1,2) has now been freed, if it has
> no name assigned to it,

It may or may not be, but it *can* be freed.  The language doesn't define
*when* unreachable memory will be reused.  CPython generally reuses memory
very quickly; Jython generally does not.

> and I can now assume that the operating system now has access to
> that memory location again?

Python can reuse it again, which is what I believe you really want to know.
Whether the operating system has access to it is a different question, and
the answer varies across platforms (it involves platform-specific details
about how the C library functions malloc() and free() are implemented on the
platform, and about operating system policies, and ... trust me, you don't
really want to know the answer to that one <wink>).

> OK, but now the mutable types:  lists and dictionaries.
>
> I know a dictionary has a copy method, so that I can have a new
> dictionary with same contents, without having to worry about modifying
> the contents of the original:
>
> >>> dict={1:"one", 2:"two"}
> >>> dict
> {2: 'two', 1: 'one'}
> >>> id(dict)
> 12029900
> >>> dict2 = dict.copy()
> >>> id(dict2)
> 12064908
> >>>

Note that this a "shallow copy", though:

>>> d = {1: [1, 2]}
>>> e = d.copy()
>>> d[1].append(3)
>>> e
{1: [1, 2, 3]}
>>>

Mututating the list [1, 2] from d also affects the list in the shallow copy
e, because a shallow copy only copies references to the objects; it does not
descend *into* objects to make copies of all their components too.

Shallow copies are *usually* what you want.  The copy *module* supplies a
deepcopy() function if you want a "deep copy":

>>> import copy
>>> d = {1: [1, 2]}
>>> e = copy.deepcopy(d)
>>> d[1].append(3)
>>> e
{1: [1, 2]}
>>> d
{1: [1, 2, 3]}
>>>

There the deep copy e isn't affected by anything you do to d *or* to
anything you to do anything *inside* d.

> What about lists? So far as I can determine, they do not have a
> copy method, and I would be modifying the "original" list, if I
> tried to assign it to a second variable name and then make
> modifications to that one, without modifying the original.

Yes, and the first dict example above actually illustrates that.  There are
several ways to copy a list x:

y = x[:]  # makes a shallow copy; this is what you'll see most often
y = copy.deepcopy(x) # makes a deep copy
y = copy.copy(x) # makes a shallow copy
y = list(x) # makes a shallow copy
y = [z for z in x] # a shallow copy; requires 2.0 or later

x[:] is such a common and obvious (once you're used to it <wink>) way to
make a shallow copy of a list that there wasn't a real need to implement a
list.copy() method.  Slice notation (x[:]) doesn't apply to dicts, though,
and while copy.copy(dict) also works to make a shallow copy, shallow copies
of dicts are frequent enough that it seemed worthwhile to give dicts a
.copy() method.

> What is the proscribed method for handling lists so that one is a
> copy that can be modified without changing the original version?

x[:] or copy.deepcopy(x), depending on whether you want a shallow or deep
copy.  deep copies are more expensive to make.  Which one you need depends
entirely on *why* you're making a copy.  Shallow copies are usually good
enough.





From dyoo@hkn.eecs.berkeley.edu  Mon Feb 26 09:23:49 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 26 Feb 2001 01:23:49 -0800 (PST)
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2103F5B0E76@kserver.org>
Message-ID: <Pine.LNX.4.21.0102260049340.27752-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 25 Feb 2001, Sheila King wrote:

> OK, now I'm really confused.
> 
> I don't really "get" the difference yet, between mutable and immutable
> types, but I figured I would eventually get it. But at least I thought
> I understood that an object could not change its type or its id. At
> least I thought I understood that.

I'll try to help explain the mutable/immutable system that Python's uses,
and perhaps this will make things clearer.  This message will be long
because of all the pretty ASCII graphics.  *grin*

Python uses a name-object methodology; that is, when we type something
like this:

###
>>> x = 5
>>> y = x
###

we have the following curious picture:

x -------> 5
           ^
           |
y ---------|

We call "x" and "y" the references to the value 5.  Whenever we write a
number, Python creates a number value, and we can imagine that it floats
around in space, tied to the ground only by our references.  The value 5
will stick around until we cut loose both x and y.  That is, if we do:

###
>>> del x
>>> y
5
###

we can see that 'y' is still attached to the value '5'.  Intuitive enough.

The idea about immutability involves the following problem: what happens
when we begin to manipulate our variables, through addition,
multiplication, or anything else?  For example, what happens here?

###
>>> x = 3          # (a)
>>> y = x          # (b)
>>> x = x + y      # (c)
###

At step (a), we create a value 3, and name it 'x'.  Then, we direct our y
reference to the same thing.  There's no problem there, since we'd expect
x and y to be both 3.  Step (c) might be weird, depending on your
background.  Let's draw out what it looks like:


(before assignment)       (doing the right hand side)
x------>3                     (rhs)---->6
        ^                 
y-------|                      x---->3
                                     ^
                               y-----|


(finally directing x to this new right hand side)
               x------>6
               y------>3


By immutability, we mean that whenever we start manipulating a immutable
item, Python will spawn off another value for us; it leaves the original
value intact.  Changing the value that 'x' is directed to will not affect
'y', because they're directed at two distinct values.

The same thing goes for tuples and string --- the only way we can
manipulate these immutable values is to create whole new values.  That's
why strings don't allow arbitrary index assignment, to make things a
little easier to work with.  For example, when we do this:

###
>>> mystr1 = "hello world"
>>> mystr2 = mystr1
>>> mystr1 = mystr1[:-1]
>>> mystr1
'hello worl'
>>> mystr2
'hello world'
###

whatever we did to mystr1 doesn't affect mystr2, because they're pointed
to distinct values.  Taking slices of strings, in affect, will create a
whole new string.  If you've worked with other programming languages,
(like C, for example), you'll notice a big difference!



That introduces immutability; immutable values can't be changed, and
manipulating them results in creating whole new values.  Now that we sorta
know about immutable types, what does it mean to be mutable?  In this
case, values CAN change.

Lists are mutable, so let's take a look at them.  When we do this:

###
>>> mylist = range(4)
>>> samelist = mylist
>>> mylist
[0, 1, 2, 3]
>>> samelist
[0, 1, 2, 3]
###

we get this picture:

mylist--------> [1, 2, 3, 4]
                ^
                |
samelist--------|


Same thing as when we were working with numbers.  However, let's see what
happens here:

###
>>> mylist.append(4)
>>> mylist
[0, 1, 2, 3, 4]
###

Mutable types allow their values to change.  What our picture now shows is
this:

mylist--------> [1, 2, 3, 4, 5]
                ^
                |
samelist--------|

and we can confirm this!

###
>>> samelist
[0, 1, 2, 3, 4]
###

That's what we mean by immutable types; the manipulations that we make
with them have the potential for changing the value.  If two references
point to the same value, then, we need to realize that changing the value
will reflect on both references.

This is not to say that we can't spawn off new copies of a mutable
value.  That's what list slicing is for.  As soon as we do this:

###
>>> samelist = mylist[:]
###

Python will create a whole new list, populated with the values of mylist:

mylist--------> [1, 2, 3, 4, 5]
samelist------> [1, 2, 3, 4, 5]

which means that we can mangle mylist with reckless abandon, without
having to worry about the stability of samelist:

###
>>> del mylist[0]
>>> mylist[0], mylist[3] = mylist[3], mylist[0]
>>> mylist
[4, 2, 3, 1]
>>> samelist
[0, 1, 2, 3, 4]
###



> Then, explain this from my Python IDLE:
> Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.6 -- press F1 for help
> >>> mytuple = 'a', 'b', 'c'
> >>> mytuple
> ('a', 'b', 'c')
> >>> type (mytuple)
> <type 'tuple'>
> >>> mytyple = 'b'
> >>> mytyple
> 'b'
> >>> type (mytyple)
> <type 'string'>
> >>> mytuple = mytyple
> >>> type (mytuple)
> <type 'string'>

> mytuple is originally a tuple. And then I end up changing it to a
> string? I thought this was not possible.

Immutable values themselves cannot change.  However, we can direct our
references, these names, back and forth from one value to another without
restriction:

###
>>> a, b = 'one', 1 
>>> b, a = a, b
>>> a
1
>>> b
'one'
>>> a, b = b, a
>>> a
'one'
>>> b
1
###

Back and forth.  *grin*  It IS a little weird though, so don't worry if it
doesn't make too much sense yet.

If you have any questions, please feel free to ask.



From topgan1@otenet.gr  Mon Feb 26 09:35:17 2001
From: topgan1@otenet.gr (Sotiris Ganouris)
Date: Mon, 26 Feb 2001 11:35:17 +0200
Subject: [Tutor] Newbie Questions.
Message-ID: <001601c09fd7$6e5f53a0$ccff673e@sotirisg>

This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C09FE8.3127E0E0
Content-Type: text/plain;
	charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

Hello,=20
I have just d/l the Python Language and I like to ask some questions =
about some basic commands.
To be more specific I would like to know the commands for file managing, =
keyboard managing and locating specific points at the screen.

thank you in advance...
Sotiris

------=_NextPart_000_0013_01C09FE8.3127E0E0
Content-Type: text/html;
	charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-7" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hello, </FONT></DIV>
<DIV><FONT size=3D2>I have just d/l the Python Language and I like to =
ask some=20
questions about some basic commands.</FONT></DIV>
<DIV><FONT size=3D2>To be more specific I would like to know the =
commands for file=20
managing, keyboard managing and locating specific points at the=20
screen.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>thank you in advance...</FONT></DIV>
<DIV><FONT size=3D2>Sotiris</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C09FE8.3127E0E0--



From dyoo@hkn.eecs.berkeley.edu  Mon Feb 26 09:39:21 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 26 Feb 2001 01:39:21 -0800 (PST)
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <21580C50AFB@kserver.org>
Message-ID: <Pine.LNX.4.21.0102260124350.27752-100000@c82114-a.pinol1.sfba.home.com>

On Sun, 25 Feb 2001, Sheila King wrote:

> OK, it gets better and better. Now explain this:
> 
> >>> mytuple
> 'b'
> >>> mylist =['a', 'b', 'c']


Ok, we have this picture so far:

mytuple -----> 'b'
mylist  -----> ['a', 'b', 'c']


> >>> type (mylist)
> <type 'list'>
> >>> id(mylist)
> 11519964

Wait, let me remind myself what id does:

###
>>> print id.__doc__
id(object) -> integer

Return the identity of an object.  This is guaranteed to be unique among
simultaneously existing objects.  (Hint: it's the object's memory
address.)
###

Ah, ok, so that means that our picture is too simplified; there's actually
a memory position involved here:


mytuple -----> 'b' (don't know yet)
mylist  -----> ['a', 'b', 'c'] (at position 11519964)


> >>> id (mytuple)
> 8532608


Ok, so our picture is now:

mytuple -----> 'b' (at position 8532608)
mylist  -----> ['a', 'b', 'c'] (at position 11519964)


> >>> mylist = mytuple


Now its:

mytuple -----> 'b' (at position 8532608)
mylist  --------^


You might be wondering where the value ['a', 'b', 'c'] just went to.  
Because we've just cut off the only reference to that value, it just
"floats away".  Nice idylic picture.  Too bad we have to call it GARBAGE
COLLECTION.  *grin*



> >>> type (mylist)
> <type 'string'>
> >>> id (mylist)
> 8532608

And the picture above reflects why it gives us these results.  The thing
that might be confusing is that there's a separation between the "name"
(reference) of a thing and its "value".  Python will let us put hundreds
of names, all directed to the same value.

###
>>> a = ['some value in a mutable list']
>>> b = a
>>> c = b
>>> a, b, c
(['some value in a mutable list'], ['some value in a mutable list'],
['some value in a mutable list'])
###

and by changing that mutable value, we'll see its effect across the board:

###
>>> a[0] = 'changed!'
>>> a, b, c
(['changed!'], ['changed!'], ['changed!'])
###



Side note: one thing you might have noticed is that when we take the id()
of numbers:

###
>>> x = 5
>>> y = 5
>>> id(x), id(y)
(135823832, 135823832)
###

it appears that we're getting the same value.  No shock yet; why shouldn't
it?  But here's something weird:

###
>>> u = 3000
>>> v = 3000
>>> id(u)
135942320
>>> id(v)
135942368      ## They're different!
###

Try to think of a reason why this happens.  Hint: there's a point in which
this strangeness triggers, and it's somewhere between 5 and 3000.  *grin*



From lumbricus@gmx.net  Mon Feb 26 13:05:19 2001
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Mon, 26 Feb 2001 14:05:19 +0100 (MET)
Subject: [Tutor] Newbie Questions.
References: <001601c09fd7$6e5f53a0$ccff673e@sotirisg>
Message-ID: <30471.983192719@www29.gmx.net>

This is a multi-part message in MIME format.


------=_NextPart_000_0013_01C09FE8.3127E0E0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

> Hello, 
> I have just d/l the Python Language and I like to ask some questions about
> some basic commands.
> To be more specific I would like to know the commands for file managing,
> keyboard managing and locating specific points at the screen.

file=open("name","mode")
file.write(string)
file.close() etc ...

keyb and screen (termcap specific things) go in the curses module
at the python prompt type "import curses"
"dir(curses)"
etc ...

greetz jö!

-- 
Sent through GMX FreeMail - http://www.gmx.net
------=_NextPart_000_0013_01C09FE8.3127E0E0
Content-Type: text/html;
	charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-7" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hello, </FONT></DIV>
<DIV><FONT size=3D2>I have just d/l the Python Language and I like to =
ask some=20
questions about some basic commands.</FONT></DIV>
<DIV><FONT size=3D2>To be more specific I would like to know the =
commands for file=20
managing, keyboard managing and locating specific points at the=20
screen.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>thank you in advance...</FONT></DIV>
<DIV><FONT size=3D2>Sotiris</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C09FE8.3127E0E0--


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



From mbc2@netdoor.com  Mon Feb 26 14:35:42 2001
From: mbc2@netdoor.com (Brad Chandler)
Date: Mon, 26 Feb 2001 08:35:42 -0600
Subject: [Tutor] Append To File
In-Reply-To: <001301c09eac$0f896540$80c8a418@jam.rr.com>
Message-ID: <NDBBINFOMECHGDGPFKMKEEEPCAAA.mbc2@netdoor.com>

>file = open('testdb.txt', 'w')

Have you tried using open('testdb.txt', 'a')?  I believe that will append
the new text to the end of the file.

Brad



From randrews@planhouse.com  Mon Feb 26 15:05:35 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Mon, 26 Feb 2001 09:05:35 -0600
Subject: [Tutor] Human?
References: <007801c09f81$f4b564e0$80c8a418@jam.rr.com>
Message-ID: <003301c0a005$932aa4e0$9600a8c0@Planhouse5>

Perhaps he's a new project out at Berkeley.  BSD could mean Berkeley
Standard Danny now.

Rob

----- Original Message -----
From: Jason Drake
To: Python Tutor List
Sent: Sunday, February 25, 2001 5:23 PM
Subject: [Tutor] Human?


As often and as quickly as Danny Yoo replies to Python questions, I'm not so
sure he isn't actually a well compiled interpreter... Where can I get a
copy?

Jay D.



From tamezi_2000@yahoo.com  Mon Feb 26 15:26:48 2001
From: tamezi_2000@yahoo.com (IVAN TAMEZ)
Date: Mon, 26 Feb 2001 07:26:48 -0800 (PST)
Subject: [Tutor] how to?
In-Reply-To: <007801c09f81$f4b564e0$80c8a418@jam.rr.com>
Message-ID: <20010226152648.91348.qmail@web9503.mail.yahoo.com>

--0-1751280372-983201208=:88846
Content-Type: text/plain; charset=us-ascii


 
I wonder if someone can tell me how to take my e´mail adress off the list, so I don´t receive more mails like this... Thanks!!!



---------------------------------
Do You Yahoo!?
Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail.
--0-1751280372-983201208=:88846
Content-Type: text/html; charset=us-ascii

<P>&nbsp;<BR>I wonder if someone can tell me how to take my e´mail adress off the list, so I don´t receive more mails like this... Thanks!!!</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</a> - 
Get email at your own domain with Yahoo! Mail.
--0-1751280372-983201208=:88846--


From scarblac@pino.selwerd.nl  Mon Feb 26 15:39:05 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 26 Feb 2001 16:39:05 +0100
Subject: [Tutor] how to?
In-Reply-To: <20010226152648.91348.qmail@web9503.mail.yahoo.com>; from tamezi_2000@yahoo.com on Mon, Feb 26, 2001 at 07:26:48AM -0800
References: <007801c09f81$f4b564e0$80c8a418@jam.rr.com> <20010226152648.91348.qmail@web9503.mail.yahoo.com>
Message-ID: <20010226163905.A17736@pino.selwerd.nl>

On Mon, Feb 26, 2001 at 07:26:48AM -0800, IVAN TAMEZ wrote:
> I wonder if someone can tell me how to take my e´mail adress off the list,
> so I don´t receive more mails like this... Thanks!!!

Go to http://mail.python.org/mailman/listinfo/tutor/

Enter your email address at the bottom, go to the next page, enter password
and unsubscribe.

-- 
Remco Gerlich




From livelikemad@yahoo.com  Mon Feb 26 17:48:36 2001
From: livelikemad@yahoo.com (Chris McCormick)
Date: Mon, 26 Feb 2001 09:48:36 -0800 (PST)
Subject: [Tutor] <NEWBIE> - Need help with displaying graphics in a window
Message-ID: <20010226174836.67211.qmail@web10502.mail.yahoo.com>

First off, thanks for reading a newbie post.

Here's my situation:
I'm pretty new at Python (a week or so), though I have
some programming experience, and a pretty good
grounding in oo design.  I'm designing an AI testbed
for fun.  It'll have various agents moving around and
looking for food, hunting each other, reproducing and
whatnot.

So far, I've been doing it all in a text-based manner.
I have a list object representing my map, and I
reprint the map (as a grid of symbols) with each
iteration.

This has gotten to be a major pain.  What I'd really
like to do is switch over to a (very!) simple Tk
window with bitmapped graphics.  

I've spent the last couple of evenings downloading TK
and PIL, getting them set up, reading the docs, and
playing with them.  But for the life of me, I can't
get an image into a Tk window.

If someone could give me some quick source code (or
point to a project in Parnassus) that does the
following things, I'd be immensely grateful:

1.  Create a display window.  Could use any modules,
but I'm using Tk because it seems to be common and
cross-platform.
2.  Display a bitmapped graphic (BMP or JPG, heck,
even PNG) in the window.

Bonus points for examples of surface (canvas?)
flipping or access to a timing function.  I'm using
Python 2.0, Tk 8.3, and Win 98, by the way.

I know this is asking a lot, but I promise I've
scoured the web and haven't found anything good. 
Mostly I get hung up on how to connect PIL to Tk.  I
can create the window with Tk, but then how do I use
PIL to get graphics in there?

Thanks in advance and looking forward to being
Python-literate,
Chris McCormick

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/


From phil.bertram@clear.net.nz  Mon Feb 26 17:51:01 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Tue, 27 Feb 2001 06:51:01 +1300
Subject: [Tutor] Java Observer/Observable type module in Python
Message-ID: <001401c0a01d$68a407d0$cec7a7cb@pf05nt.bayernz.co.nz>

Hi all

I was reading some Java info and came across  the Observer and Observable
classes which appear to work together to communicate changes in an object's
state to one or many other objects.

Is there a similar feature in Python ?

Phil



From dsh8290@rit.edu  Mon Feb 26 18:39:30 2001
From: dsh8290@rit.edu (D-Man)
Date: Mon, 26 Feb 2001 13:39:30 -0500
Subject: [Tutor] Java Observer/Observable type module in Python
In-Reply-To: <001401c0a01d$68a407d0$cec7a7cb@pf05nt.bayernz.co.nz>; from phil.bertram@clear.net.nz on Tue, Feb 27, 2001 at 06:51:01AM +1300
References: <001401c0a01d$68a407d0$cec7a7cb@pf05nt.bayernz.co.nz>
Message-ID: <20010226133930.A14108@harmony.cs.rit.edu>

On Tue, Feb 27, 2001 at 06:51:01AM +1300, Phil Bertram wrote:
| Hi all
| 
| I was reading some Java info and came across  the Observer and Observable
| classes which appear to work together to communicate changes in an object's
| state to one or many other objects.
| 
| Is there a similar feature in Python ?

This can be done with (almost) any language.  The Observer pattern
actually comes from "Design Patterns" by the Gang of Four, with the
example being in C++.  (or Smalltalk, they used both languages in the
book)



class Observer :
    def changed( self , observable ) :
        print "%s has changed" % str( observable )

class Observable :
    def __init__( self , init_value ) :
        self.observers = []
        self.value = init_value

    def __str__( self ) :
        return "Observable %d : %s" % id( self ) , self.value

    def add_observer( self , observer ) :
        self.observers.append( observer )

    def remove_observer( self , observer ) :
        self.observer.remove( observer )

    def _notify_of_change( self ) :
        for observer in self.observers :
            observer.changed( self )

    def mutator_function_that_changes_self( self , new_value ) :
        self.value = new_value
        self._notify_of_change()


# test my code :
if __name__ == "__main__" :
    observer1 = Observer()
    observer2 = Observer()
    observable = Observable( 13 )
    observable.add_observer( observer1 )
    observable.add_observer( observer2 )

    observable.mutator_function_that_changes_self( 50 )

    observable.remove_observer( observer1 )

    observable.mutator_function_that_changes_self( 20 )

    observable.remove_observer( observer2 )




BTW,  I just wrote this and haven't tested it so if something looks
ridiculously stupid, I probably made a mistake.  Also, instead of
using a list in the Observable class, a dictionary could be used to
improve performance on adding/removing observers.  This would require
that the observers be hashable.  Using a list like this makes the
order the observers recieve notification the same as the order they
registered themselves.  A dictionary wouldn't allow this.


Java provides classes/interfaces in the standard library called
Observer and Observable that implement this pattern in a very basic
way.  The main need for this in Java is its static type checking and
inablility to pass function "pointers" (pointers in C/C++, objects in
Python) so the Observable must know the name of the method to call in
the Observer.  AFIAK Swing doesn't use those classes (maybe part of
the implementation, I don't know) but it uses the Observer Pattern
heavily.  Since you are using Python, you can just create the
Observer/Observable interfaces you need when you need them and make
the suitable for that particular task, rather than trying to make a
generalized implementation.  Also, you could choose to accept a
function object in the add_observer function, instead of an Observer
object allowing clients to determine exactly which function will get
the notification.  (A la gtk--, the C++ bindings for the GTK+ toolkit)
This is my preferred mechanism for listening for GUI events.


HTH,
-D




From dsh8290@rit.edu  Mon Feb 26 18:59:58 2001
From: dsh8290@rit.edu (D-Man)
Date: Mon, 26 Feb 2001 13:59:58 -0500
Subject: [Tutor] Tuples, Dictionarys and mutable vs. immutable
In-Reply-To: <2103F5B0E76@kserver.org>; from sheila@thinkspot.net on Sun, Feb 25, 2001 at 08:30:59PM -0800
References: <2103F5B0E76@kserver.org>
Message-ID: <20010226135958.B14108@harmony.cs.rit.edu>

On Sun, Feb 25, 2001 at 08:30:59PM -0800, Sheila King wrote:
| OK, now I'm really confused.
| 
| I don't really "get" the difference yet, between mutable and immutable types,
| but I figured I would eventually get it. But at least I thought I understood
| that an object could not change its type or its id. At least I thought I
| understood that.

Since you understand C++ I'll make an analogy with it.

In Python all identifiers are "typeless" pointers (void*).  They refer
to an object, which has a particular type, when you assign that object
to them.  If you assign a different type to it, it will refer to a
different type of object.  

Mutable objects are objects that you can actually change.  It is as if
they have all public data members, or provide public mutator
functions.  Immutable objects don't have any public data that can be
changed (only read/copied) and no public mutator methods.

The *identifiers* are always mutable (since they are little more than
pointers) -- you can assign a new object of whatever type you want to
it whenever you want to.

It is useful, IMO, to name your identifiers to describe the type of
object you expect it is referring to.  This helps readability.
However, if need be, python allows you to assign a different type of
object to it.  This is coolest when debugging since you can simply
throw some new code in the middle to see what the state of the system
is at that time without the overhead of static type checking (or C's
requirement that all identifiers be declared at the beginning of a
block).


Also, as others have already mentioned, id() simply returns the
address of the object its argument refers to.  CPython has a tendency
to free() objects shortly after the last reference is removed, and
then to malloc() the next new object at that same location.  (Although
I'm not sure if it actually calls malloc/free or just maintains it's
own free lists)  This is why it seems you are seeing multiple objects
with the same id.  They had the same id, just not simultaneously.



BTW,  In the interactive interpreter, all expressions get assigned to
a variable named _.  Ex :

>>> class Foo :
...     def __del__( self ) :
...             print "I was del'ed : %d" % id( self )
...
>>> obj = Foo()
>>> id( obj )
8171332
>>> obj = None
I was del'ed : 8171332
>>>
>>> Foo()
<__main__.Foo instance at 007CF46C>

# note : I didn't assign the new object to anything, but it wasn't
# del'ed yet
# this is because it was assigned to _, so a reference still exists

>>> print _
<__main__.Foo instance at 007CF46C>
>>> 13
I was del'ed : 8189036
13

# here I implicitly assigned 13 to _, so the Foo object was del'd

>>>


This peculiarity exists only in the interactive interpreter.  I
believe it is so that you can maintain a handle to a return value or
expression after the fact, if you didn't realize you wanted it  when
you typed the expression.


HTH,
-D



From crisp@wizshop.com  Mon Feb 26 21:30:58 2001
From: crisp@wizshop.com (Cris Paltenghe)
Date: Mon, 26 Feb 2001 13:30:58 -0800
Subject: [Tutor] run time parameters
Message-ID: <MFEPKEDCPKJMBBKNEDDOIEDLCEAA.crisp@wizshop.com>

Folks,

I have been trying to learn Python by writing a program that will be useful
at work.
We have been needing some statistics from our log files and I thought I
would write a program to do that.
It basically scans a file for the occurrence of some target strings and
counts them.
For the life of me, I can't figure out how to pass the file name (or a
directory) as a run time parameter.
I have found directory functions, but I would like to know how generally to
pass parameters to a program.

Also, where should I have gone to figure this out?
I have been pouring over all the docs I could find.

Regards,
Cris




From dsh8290@rit.edu  Mon Feb 26 21:36:40 2001
From: dsh8290@rit.edu (D-Man)
Date: Mon, 26 Feb 2001 16:36:40 -0500
Subject: [Tutor] run time parameters
In-Reply-To: <MFEPKEDCPKJMBBKNEDDOIEDLCEAA.crisp@wizshop.com>; from crisp@wizshop.com on Mon, Feb 26, 2001 at 01:30:58PM -0800
References: <MFEPKEDCPKJMBBKNEDDOIEDLCEAA.crisp@wizshop.com>
Message-ID: <20010226163640.A14751@harmony.cs.rit.edu>

On Mon, Feb 26, 2001 at 01:30:58PM -0800, Cris Paltenghe wrote:
| 
| For the life of me, I can't figure out how to pass the file name (or a
| directory) as a run time parameter.
| I have found directory functions, but I would like to know how generally to
| pass parameters to a program.
| 
| Also, where should I have gone to figure this out?
| I have been pouring over all the docs I could find.

sys.argv is the same as argv , len( sys.argv ) is the same as argc in
C :

int main( int argc , char** argv ) { ... }


~~~~~~~~~~~ Test.py ~~~~~~~~~~~~~~
#!/usr/bin/env python

import sys
print sys.argv
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$ ./Test.py arg1 some_file a_directory
['Test.py', 'arg1', 'some_file', 'a_directory']



HTH,
-D



From livelikemad@yahoo.com  Mon Feb 26 21:48:28 2001
From: livelikemad@yahoo.com (Chris McCormick)
Date: Mon, 26 Feb 2001 13:48:28 -0800 (PST)
Subject: [Tutor] <<NEWBIE>>  Soooooo CLOSE!!! :-)
Message-ID: <20010226214828.92691.qmail@web10507.mail.yahoo.com>

Ok peeps,
  As per my message earlier today, I am trying to get
an image to display in a Tk window.  Here is my source
code:

from Tkinter import *

class App:
  def __init__(self, master):
    frame = Frame(master)
    frame.pack()
    self.canvas = Canvas(frame, bg="red",width=601,
height=601)
    self.canvas.pack()
		
    photo = PhotoImage(file="bg1.gif")
    self.item = self.canvas.create_image(10, 10,
anchor=NW, image=photo)

root = Tk()
app = App(root)
root.mainloop()

I don't get any error messages - what I do get is a
big window with the red background.  My guess is that
after I create the image, I have to do something to
make it visible?  I tried adding a line like this:

self.item.pack()

but it gives me the error:

AttributeError: 'int' object has no attribute 'pack'

I guess that means that item is just the ID of the
image rather than the image itself?

*sigh*  I'm so close I can taste it. If anyone can
help me, I'd be much obliged.

- Chris

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/


From michaelbaker@operamail.com  Mon Feb 26 22:35:32 2001
From: michaelbaker@operamail.com (Michael Baker)
Date: Mon, 26 Feb 2001 17:35:32 -0500
Subject: [Tutor] PYTHONPATH - got it
Message-ID: <3B041E0D@operamail.com>

I added this line to /etc/profile:

export PYTHONPATH=.:/usr/lib/python1.5/

...and all appears to be well. thanks for the help. btw typing the same in a 
shell prior to launching Blender works too, but is less convenient.


>===== Original Message From Bruce Sass <bsass@freenet.edmonton.ab.ca> =====
>On Sun, 25 Feb 2001, Dinakar wrote:
>> how to change the path shown by sys.path. Does one need to change 
PYTHONPATH
>> in .bashrc or someother file. I would appreciate, if some one on the group
>> clarify this.
>
>Well, you have at least two choices regarding PYTHONPATH; put it in
>the system wide shell profile (/etc/profile), or your per-user shell
>profile (.bashrc, .cshrc, both if you use both shells).  This really
>has little to do with Python, use private-email if you need help with
>shell stuff.
>
>What I'm wondering is if it is Blender you need to tell about Python
>modules, or Python you need to tell about Blender modules?  In the
>first case, setting the PYTHONPATH in the environment is probably the
>thing to do; in the second case it would be best to but the Blender
>modules on the sys.path.
>
>What I would do is find the location of the modules that are not being
>found automatically, if they are not on the sys.path then make a
>symlink from the dir containing the missing modules to inside a dir on
>the sys.path.  Exactly where this link points to depends on the
>characteristics of the modules and whether or not Blender (assuming
>Blender module are out of place) is from a .rpm or not.  If the Python
>code in Blender depends on Python-1.5, then use
>/usr/lib/python1.5/site-packages; if it will work with any version of
>Python, use /usr/lib/site-python; if you built Blender yourself, use
>/usr/local/lib/{python1.5,site-packages}, as appropriate.
>
>
>- Bruce
>
>--
>> Bruce Sass wrote:
>>
>> > On Sat, 24 Feb 2001 michaelbaker@operamail.com wrote:
>> > > I'm  LinuxPPC (based on Red Hat 6.1), the python interpreter works just
>> > > fine, but another program (Blender) which has a pyhton API cannot find
>> > > modules to import. I'm trying to change my .cshrc file to set 
PYTHONPATH
>> > > without luck. I've added this line to my .cshrc:
>> > >
>> > > setenv PYTHONPATH "/usr/lib/python1.5/"
>> > >
>> > > this doesn't work - help???
>> > > thanks
>> >
>> > This is what python 1.5.2 thinks the path is on my Debian box,
>> >
>> > >>> sys.path
>> > ['', '/usr/lib/python1.5/', '/usr/lib/python1.5/plat-linux2',
>> > '/usr/lib/python1.5/lib-tk', '/usr/lib/python1.5/lib-dynload',
>> > '/usr/local/lib/python1.5/site-packages',
>> > '/usr/local/lib/site-python', '/usr/lib/python1.5/site-packages',
>> > '/usr/lib/python1.5/site-packages/HTMLgen',
>> > '/usr/lib/python1.5/site-packages/PIL',
>> > '/usr/lib/python1.5/site-packages/graphics',
>> > '/usr/lib/python1.5/site-packages/Numerical',
>> > '/usr/lib/site-python']



From lakicsv@usa.net  Mon Feb 26 23:27:45 2001
From: lakicsv@usa.net (Viktor Lakics)
Date: Mon, 26 Feb 2001 23:27:45 +0000
Subject: [Tutor] exec vs system (fwd)
In-Reply-To: <20010225185045.A12893@harmony.cs.rit.edu>; from dsh8290@rit.edu on Sun, Feb 25, 2001 at 06:50:45PM -0500
References: <Pine.LNX.4.21.0102242151460.9736-100000@c82114-a.pinol1.sfba.home.com> <20010225185045.A12893@harmony.cs.rit.edu>
Message-ID: <20010226232745.B24037@Diogenes.co.uk>

On Sun, Feb 25, 2001 at 06:50:45PM -0500, D-Man wrote:
> I don't think it makes any difference.  If you run fetchmail in daemon
> mode from the command line, your shell returns to an interactive state
> immediately (after reporting the PID of the fetchmail daemon).  The
> way fetchmail works (basically), if you start it in daemon mode is :
> 
> 
> pid = fork()
> if pid == 0 :
>     # this is the child,
>     while 1 :
>         get_mail()
>         sleep( 1000 )
> else :
>     # this is the original parent, 
>     # return control back to the previous process (shell, whatever)
>     sys.exit( 0 )
> 
> 
> 
> If your script simply invokes fetchmial using os.system, you will get
> the success exit value almost immediately, while the deamon runs in
> the background and your script is free to terminate the python
> interpreter at its leisure.  If you use execv, the interpreter will be
> replaced by fetchmail, which will fork and then terminate the parent
> process.
> 
> You can also start fetchmail in daemon mode by specifying it in your
> fetchmailrc file.

Thanks for the info...

 
> I don't know if this is relevant/helpful at all, but I simply put
> "fetchmail" in my .bash_profile file so that fetchmail is run when I
> login.  I put "fetchmail --kill" (or whatever the option is, I'm not
> at my linux box right now) in my .logout file so that it terminates
> when I log out.  I can also run fetchmail at any time since it will
> check for an already running daemon and simply wake it up if it
> exists.

What I usually do (and this was the point of writing the script) is
to have fetchmail -d in my /etc/ppp/ip-up.local, so every time I
dial into my isp my mail is downloaded. But I want to read my email
at work, even when someone at home connets to browse the internet. So
on weekdays between 8 to 6 PM my mail is not automatically
downloaded, any other time it is... 

Viktor


From tim@johnsons-web.com  Tue Feb 27 02:36:29 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Mon, 26 Feb 2001 17:36:29 -0900
Subject: [Tutor] Simple Object Question
References: <MFEPKEDCPKJMBBKNEDDOIEDLCEAA.crisp@wizshop.com>
Message-ID: <01022617405002.02153@shecom>

Newbie Object Question
The following code with class 
###########################
#!/usr/bin/python
class cgitools:
	def __init__(self):	
		pass
	def header(self):
		print "Content-type: text/html\n\n"
	def __repr__(self):
		return self.header()
cgi = cgitools
cgi.header()
###########################
Generates the error message:
cgi.header()
TypeError: unbound method must be called with class instance 1st argument

I wish for cgi.header to print out the mime-type string.

Any advice would be appreciated.
TIA :)
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From tim@johnsons-web.com  Tue Feb 27 03:30:57 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Mon, 26 Feb 2001 18:30:57 -0900
Subject: [Tutor] Simple Object Question
References: <MFEPKEDCPKJMBBKNEDDOIEDLCEAA.crisp@wizshop.com>
Message-ID: <01022617405002.02153@shecom>

Sorry..... I should not have sent the question below.
neglected the parens after the class instantiation.
Never mind! 
I've been coding in 3 different languages today.
duh~

Newbie Object Question
The following code with class 
###########################
#!/usr/bin/python
class cgitools:
	def __init__(self):	
		pass
	def header(self):
		print "Content-type: text/html\n\n"
	def __repr__(self):
		return self.header()
cgi = cgitools
cgi.header()
###########################
Generates the error message:
cgi.header()
TypeError: unbound method must be called with class instance 1st argument

I wish for cgi.header to print out the mime-type string.

Any advice would be appreciated.
TIA :)
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From tim@johnsons-web.com  Tue Feb 27 03:33:36 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Mon, 26 Feb 2001 18:33:36 -0900
Subject: [Tutor] Trapping Interpreter errors as a string
References: <20010226232745.B24037@Diogenes.co.uk>
Message-ID: <01022618444804.02153@shecom>

Hello:
	Am looking for a way to trap python errors as a string.
A quick example would be like the disarm function in the rebol language.

To be more specific:
Let's say I had a simple cgi program to first sent the the mime-type
print "Content-type: text/html\n"

then I do something dumb, like

integer = string.atoi("duh")

Guido will then say:

Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for atoi(): duh

To reduce this inquiry:
1)Can that error message be returned to the user as a string.
2)Is there a specific numeric error code attached to the error message.
   i.e. ValueError = ?

Then the programmer could gracefully complete the output form with
the error message within it.

I hope I being clear here.
TIA

--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From wheelege@tsn.cc  Tue Feb 27 06:45:14 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 27 Feb 2001 17:45:14 +1100
Subject: [Tutor] Re: Python newbie with a couple of questions... :-)
References: <3A9AB64D.E8651BDD@thestate.com>
Message-ID: <00a401c0a088$d79c1220$0200a8c0@ACE>

(note: I'm sending this to the python list as well so they can help with any
more information...it's like a sea of great people who seem to like helping,
why not take advantage of it?)


  Hi Chris,

  I still have yet to finish that project - I've been very busy lately.
However, I can try to help you with some of your questions.
  A great general resource is the book by John Grayson - Python and Tkinter
Programming.  If your looking for some good Tkinter source code, I'd suggest
looking here - http://www.manning.com/grayson.  That is the website for the
book, and even if you don't have the book you can still d/l the source code
used in the examples.  The ones I have seen are well documented and are a
good example of nice neat python programming.
  I got most of my answers, believe it or not, from a couple of websites on
a programming language called Lisp.  It is very similar to python and I have
heard it is very useful for programming AI - thus it may be helpful for you
to see how it works in lisp then translate that into python.  A good webpage
comparing lisp to python can be found here -
http://www.norvig.com/python-lisp.html.  That link is from Danny Yoo.
  Speaking of Danny, he was also good for inspiration - he gave me some
ideas that although are not what I'm using now, were good to get me thinking
the right way.  I'm sure he will respond in his
I-am-Danny-Yoo-the-Python-Elemental kind of way :)
  If you are displaying or manipulating images of any kind, you really want
to look for the Canvas class widget in tkinter.  I've used a single Canvas
for the entire playing field of my little game and it has proven very
useful.
  Another thing you may want to look into may be threads.  These allow you
to do simultaneous operations, and I could not have gone much further than
nowhere without them.  You can find documentation on them inside python.
  Also, which interpreter are you using?  I was using IDLE for a long time,
but found it was buggy.  I compiled it on a Linux machine and it would run
differently from IDLE - same with a Macintosh machine.  So I changed to the
activestate product.  This seems to work much better.

  Let me know how you go,
  Glen.

  PS As a final tip...OOP is the way to go.  If your not already using it,
then get into it - it's great

----- Original Message -----
From: Chris McCormick <cmccormick@thestate.com>
To: wheelege <wheelege@tsn.cc>
Sent: Tuesday, February 27, 2001 7:02 AM
Subject: Python newbie with a couple of questions... :-)


> Glen,
>     I am a nebwie Python programmer, working on an AI testbed.  It'll be
> animated, and so I'm trying to learn how to display bitmaps, flip
> images, time events, and so on.  I'm having a terrible time finding
> decent documentation for any of this stuff.
>     I saw that you had some questions a few months ago that were very
> similar to mine.  I was hoping that you might share some of your source
> code with me, or at least where you got your answers.  If I could just
> get to the point where I'm displaying and flipping images, then I could
> get to the real work of my program.
>
> Thanks in advance for any help,
> Chris McCormick
>



From scarblac@pino.selwerd.nl  Tue Feb 27 07:10:09 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 27 Feb 2001 08:10:09 +0100
Subject: [Tutor] Trapping Interpreter errors as a string
In-Reply-To: <01022618444804.02153@shecom>; from tim@johnsons-web.com on Mon, Feb 26, 2001 at 06:33:36PM -0900
References: <20010226232745.B24037@Diogenes.co.uk> <01022618444804.02153@shecom>
Message-ID: <20010227081009.A18634@pino.selwerd.nl>

On Mon, Feb 26, 2001 at 06:33:36PM -0900, Tim Johnson wrote:
> 	Am looking for a way to trap python errors as a string.
> A quick example would be like the disarm function in the rebol language.
> 
> To be more specific:
> Let's say I had a simple cgi program to first sent the the mime-type
> print "Content-type: text/html\n"
> 
> then I do something dumb, like
> 
> integer = string.atoi("duh")
> 
> Guido will then say:
> 
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ValueError: invalid literal for atoi(): duh
> 
> To reduce this inquiry:
> 1)Can that error message be returned to the user as a string.
> 2)Is there a specific numeric error code attached to the error message.
>    i.e. ValueError = ?
> 
> Then the programmer could gracefully complete the output form with
> the error message within it.

In Python, you would usually make something like this:

try:
   x = string.atoi("duh")
except ValueError, problem:
   print problem
   
This will print "invalid literal for int(): duh" and then continue. You put
whatever code you need to handle the exception in the except: block. You can
look at sys.exc_info for more information on the current exception, or
inspect the traceback and/or print it with functions from the traceback
module.

If you don't know about exceptions yet, read chapter 8 of the Tutorial.

-- 
Remco Gerlich


From Lindsay.Davies@moonshine.co.uk  Tue Feb 27 09:39:56 2001
From: Lindsay.Davies@moonshine.co.uk (Lindsay Davies)
Date: Tue, 27 Feb 2001 09:39:56 +0000
Subject: [Tutor] Trapping Interpreter errors as a string
In-Reply-To: <20010227081009.A18634@pino.selwerd.nl>
References: <20010226232745.B24037@Diogenes.co.uk>
 <01022618444804.02153@shecom> <20010227081009.A18634@pino.selwerd.nl>
Message-ID: <p05010400b6c1254e7904@[195.102.186.233]>

--============_-1228855651==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

It's also worth being aware of the StandardError exception. If you 
don't know which specific exception will be raised, then 
StandardError will catch all raised exceptions, rather than specific 
ones (AFAIK!).

try:
    x = string.atoi("duh")
except StandardError, problem:
    print problem

Best wishes,

Lindsay


On 27/2/01, Remco Gerlich wrote about 'Re: [Tutor] Trapping 
Interpreter errors as a string':
>In Python, you would usually make something like this:
>
>try:
>    x = string.atoi("duh")
>except ValueError, problem:
>    print problem
>   
>This will print "invalid literal for int(): duh" and then continue. You put
>whatever code you need to handle the exception in the except: block. You can
>look at sys.exc_info for more information on the current exception, or
>inspect the traceback and/or print it with functions from the traceback
>module.
>
>If you don't know about exceptions yet, read chapter 8 of the Tutorial.
--============_-1228855651==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
 --></style><title>Re: [Tutor] Trapping Interpreter errors as a
string</title></head><body>
<div>It's also worth being aware of the<font color="#000000">
StandardError</font> exception. If you don't know which specific
exception will be raised, then<font color="#000000">
StandardError</font> will catch all raised exceptions, rather than
specific ones (AFAIK!).</div>
<div><br></div>
<div>try:</div>
<div>&nbsp;&nbsp; x = string.atoi(&quot;duh&quot;)</div>
<div><font color="#000000"><b>except</b> StandardError,
problem:</font></div>
<div><font color="#000000">&nbsp;&nbsp;<b> print</b>
problem</font></div>
<div><br></div>
<div>Best wishes,</div>
<div><br></div>
<div>Lindsay</div>
<div><br></div>
<div><br></div>
<div>On 27/2/01, Remco Gerlich wrote about 'Re: [Tutor] Trapping
Interpreter errors as a string':</div>
<blockquote type="cite" cite>In Python, you would usually make
something like this:<br>
</blockquote>
<blockquote type="cite" cite>try:<br>
&nbsp;&nbsp; x = string.atoi(&quot;duh&quot;)</blockquote>
<blockquote type="cite" cite>except ValueError, problem:<br>
&nbsp;&nbsp; print problem</blockquote>
<blockquote type="cite" cite>&nbsp;&nbsp;<br>
This will print &quot;invalid literal for int(): duh&quot; and then
continue. You put<br>
whatever code you need to handle the exception in the except: block.
You can<br>
look at sys.exc_info for more information on the current exception,
or<br>
inspect the traceback and/or print it with functions from the
traceback</blockquote>
<blockquote type="cite" cite>module.</blockquote>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite>If you don't know about exceptions yet,
read chapter 8 of the Tutorial.</blockquote>
</body>
</html>
--============_-1228855651==_ma============--


From rick@niof.net  Tue Feb 27 15:12:44 2001
From: rick@niof.net (Rick Pasotto)
Date: Tue, 27 Feb 2001 10:12:44 -0500
Subject: [Tutor] Tk Menus and filerequesters
Message-ID: <20010227101244.A7940@tc.niof.net>

1) Working with the Pmw module and menus I read and read and puzzled how
to get a menu to show up on the right as the help menu usually does.
Finally I stumbled on the name='help' parameter in an example but
nowhere can I find this documented. It's not in the Tkinter docs nor in
the Pmw docs -- at least not that I can find.

2) Is there a filerequester module available for Tkinter? The closest
thing I've found is TreeNavigator (which I haven't gotten to work) in
PmwContribD -- but this would be only a building block for a
filerequester.

-- 
"Action from principle, the perception and the performance of right,
changes things and relations; it is essentially revolutionary...  It not
only divides states and churches, it divides families; aye, it divides
the individual, separating the diabolical in him from the divine."
		-- Henry D. Thoreau, 1849 "Resistance to Civil Government"
		   Rick Pasotto email: rickp@telocity.com


From cmccormick@thestate.com  Tue Feb 27 15:33:51 2001
From: cmccormick@thestate.com (Chris McCormick)
Date: Tue, 27 Feb 2001 10:33:51 -0500
Subject: [Tutor] >> Thanks <<
Message-ID: <3A9BC8DB.C607F2E9@thestate.com>

I just wanted to thank the list for the responses I received yesterday.
Soon after my first post, I got useful replies from more than one
person.  Now I get to move on to all of the other fun things.  I have a
ton of ideas, and all I need is time. :-)

I was thinking that maybe a Python game programming web site would be
useful?  A place where I (and more advanced programmers) could put game
source code, and the wisdom we gain from our experiences?  Do you think
that would be useful, or would it duplicate other efforts, like the
Vaults?  I, for one, find  documentation to be fairly sparse.

Anyway, thanks again, and I'm sure there will be more questions.  I know
I sound a little over-excited, but that is the result of achieving, with
Python, what I spent weeks trying (and failing) to do with C++ and
DirectX.

More to come,
Chris



From randrews@planhouse.com  Tue Feb 27 17:03:14 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 27 Feb 2001 11:03:14 -0600
Subject: [Tutor] >> Thanks <<
References: <3A9BC8DB.C607F2E9@thestate.com>
Message-ID: <002001c0a0df$2cd3c0c0$9600a8c0@Planhouse5>

Well, although it's not exclusively dedicated to gaming, Useless Python
features several games and other novelties.  You are welcome to post any of
your Python source there, and we are working on ways to make the process of
collaborating on projects more automatic.  So far, a few of us have already
presented fresh ways of addressing the same problem and/or provided changes
to one another's code.

It's almost exclusively source code currently, but the lowerstandard.com
staff is working on tutorials for various Python topics.  Of course, we
welcome any contributions people would like to make, such as how to do stuff
and contributions to source code posted by others on the site.

Here's the URL, if you wish to take a gander:
http://www.lowerstandard.com/python/pythonsource.html

Rob Andrews

----- Original Message -----
From: "Chris McCormick" <cmccormick@thestate.com>
To: <tutor@python.org>
Sent: Tuesday, February 27, 2001 9:33 AM
Subject: [Tutor] >> Thanks <<


> I just wanted to thank the list for the responses I received yesterday.
> Soon after my first post, I got useful replies from more than one
> person.  Now I get to move on to all of the other fun things.  I have a
> ton of ideas, and all I need is time. :-)
>
> I was thinking that maybe a Python game programming web site would be
> useful?  A place where I (and more advanced programmers) could put game
> source code, and the wisdom we gain from our experiences?  Do you think
> that would be useful, or would it duplicate other efforts, like the
> Vaults?  I, for one, find  documentation to be fairly sparse.
>
> Anyway, thanks again, and I'm sure there will be more questions.  I know
> I sound a little over-excited, but that is the result of achieving, with
> Python, what I spent weeks trying (and failing) to do with C++ and
> DirectX.
>
> More to come,
> Chris
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From phil.bertram@clear.net.nz  Tue Feb 27 19:37:35 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Wed, 28 Feb 2001 08:37:35 +1300
Subject: [Tutor] Java Observer/Observable type module in Python
Message-ID: <000d01c0a0f4$d6364880$4dc6a7cb@pf05nt.bayernz.co.nz>

Many thanks. I think I understand.

I was under the impression that the Java Observer classes somehow searched
the memory for any Observerables without any looping and I thought that
would be neat. Sort of 'like magic'. But I guess my thinking was flawed.
Python is definately much easier to understand for a self taught
'programmer' like me as compared to Java.

It seems as though my program already uses the 'Observer' pattern by
updating a Player's score when a team wins a game. In a round about fashion
any way !

I'll get busy tidying things up to follow this pattern a little closer
because it certainly is more elegant than what I have done.

Hopefully substituting 'class Player' for 'class Observer' and 'class Game
for 'class Observable' should do the trick.

>Message: 3
>Date: Mon, 26 Feb 2001 13:39:30 -0500
>From: D-Man <dsh8290@rit.edu>
>To: tutor@python.org
>Subject: Re: [Tutor] Java Observer/Observable type module in Python
>
>On Tue, Feb 27, 2001 at 06:51:01AM +1300, Phil Bertram wrote:
>| Hi all
>|
>| I was reading some Java info and came across  the Observer and Observable
>| classes which appear to work together to communicate changes in an
object's
>| state to one or many other objects.
>|
>| Is there a similar feature in Python ?
>
>This can be done with (almost) any language.  The Observer pattern
>actually comes from "Design Patterns" by the Gang of Four, with the
>example being in C++.  (or Smalltalk, they used both languages in the
>book)
>
>
>
>class Observer :
>    def changed( self , observable ) :
>        print "%s has changed" % str( observable )
>
>class Observable :
>    def __init__( self , init_value ) :
>        self.observers = []
>        self.value = init_value
>
>    def __str__( self ) :
>        return "Observable %d : %s" % id( self ) , self.value
>
>    def add_observer( self , observer ) :
>        self.observers.append( observer )
>
>    def remove_observer( self , observer ) :
>        self.observer.remove( observer )
>
>    def _notify_of_change( self ) :
>        for observer in self.observers :
>            observer.changed( self )
>
>    def mutator_function_that_changes_self( self , new_value ) :
>        self.value = new_value
>        self._notify_of_change()
>
>
># test my code :
>if __name__ == "__main__" :
>    observer1 = Observer()
>    observer2 = Observer()
>    observable = Observable( 13 )
>    observable.add_observer( observer1 )
>    observable.add_observer( observer2 )
>
>    observable.mutator_function_that_changes_self( 50 )
>
>    observable.remove_observer( observer1 )
>
>    observable.mutator_function_that_changes_self( 20 )
>
>    observable.remove_observer( observer2 )
>
>
>
>
>BTW,  I just wrote this and haven't tested it so if something looks
>ridiculously stupid, I probably made a mistake.  Also, instead of
>using a list in the Observable class, a dictionary could be used to
>improve performance on adding/removing observers.  This would require
>that the observers be hashable.  Using a list like this makes the
>order the observers recieve notification the same as the order they
>registered themselves.  A dictionary wouldn't allow this.
>
>
>Java provides classes/interfaces in the standard library called
>Observer and Observable that implement this pattern in a very basic
>way.  The main need for this in Java is its static type checking and
>inablility to pass function "pointers" (pointers in C/C++, objects in
>Python) so the Observable must know the name of the method to call in
>the Observer.  AFIAK Swing doesn't use those classes (maybe part of
>the implementation, I don't know) but it uses the Observer Pattern
>heavily.  Since you are using Python, you can just create the
>Observer/Observable interfaces you need when you need them and make
>the suitable for that particular task, rather than trying to make a
>generalized implementation.  Also, you could choose to accept a
>function object in the add_observer function, instead of an Observer
>object allowing clients to determine exactly which function will get
>the notification.  (A la gtk--, the C++ bindings for the GTK+ toolkit)
>This is my preferred mechanism for listening for GUI events.
>
>
>HTH,
>-D




From dyoo@hkn.eecs.berkeley.edu  Tue Feb 27 21:54:47 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 27 Feb 2001 13:54:47 -0800 (PST)
Subject: [Tutor] >> Thanks <<
In-Reply-To: <3A9BC8DB.C607F2E9@thestate.com>
Message-ID: <Pine.LNX.4.21.0102271352380.13895-100000@c82114-a.pinol1.sfba.home.com>

On Tue, 27 Feb 2001, Chris McCormick wrote:

> I was thinking that maybe a Python game programming web site would be
> useful?  A place where I (and more advanced programmers) could put
> game source code, and the wisdom we gain from our experiences?  Do you
> think that would be useful, or would it duplicate other efforts, like
> the Vaults?  I, for one, find documentation to be fairly sparse.

Here ya go:

    http://pygame.seul.org/

They seem to be very specific about the SDL, but their resources below may
be useful in making a generic Python Gaming web site.  I think it would be
a great idea!


> Anyway, thanks again, and I'm sure there will be more questions.  I
> know I sound a little over-excited, but that is the result of
> achieving, with Python, what I spent weeks trying (and failing) to do
> with C++ and DirectX.



From britt_green@hotmail.com  Wed Feb 28 00:55:12 2001
From: britt_green@hotmail.com (Britt Green)
Date: Tue, 27 Feb 2001 16:55:12 -0800
Subject: [Tutor] Question About Subclasses
Message-ID: <F216CiZQWLU70httXc0000003d0@hotmail.com>

Hello,

I'm having some problems getting Python to create a subclass. I have a class 
called Items, and then a subclass of that called Containers. Python doesn't 
recognize Containers as a valid subclass.

This is what I have in a file called "Classes.py":

class Items:
    def __init__(self, name, ip):
        self.name = name
        self.inPossesion = ip

class Containers(Items):
    def __init__(self, name, ip, oc):
        Items.__init__(self, name, ip)
        self.openClosed = oc

Then within another file called "game.py" I have the following code:

import Classes

cupboard = Containers("cupboard", 0, "closed")

key = Items ("worn key", 0)

When I go to run this code, Python spits this back at me:

>>>
Traceback (innermost last):
  File "C:/Program Files/Python20/game.py", line 3, in ?
    cupboard = Containers("cupboard", 0, "closed")
NameError: There is no variable named 'Containers'

What am I doing wrong?

Thanks,

Britt

--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From arcege@shore.net  Wed Feb 28 01:06:45 2001
From: arcege@shore.net (Michael P. Reilly)
Date: Tue, 27 Feb 2001 20:06:45 -0500 (EST)
Subject: [Tutor] Question About Subclasses
In-Reply-To: <F216CiZQWLU70httXc0000003d0@hotmail.com> from Britt Green at "Feb 27, 2001  4:55:12 pm"
Message-ID: <E14Xv4n-0004vW-00@nautilus.shore.net>

> I'm having some problems getting Python to create a subclass. I have a class 
> called Items, and then a subclass of that called Containers. Python doesn't 
> recognize Containers as a valid subclass.
> 
> This is what I have in a file called "Classes.py":
> 
> class Items:
>     def __init__(self, name, ip):
>         self.name = name
>         self.inPossesion = ip
> 
> class Containers(Items):
>     def __init__(self, name, ip, oc):
>         Items.__init__(self, name, ip)
>         self.openClosed = oc
> 
> Then within another file called "game.py" I have the following code:
> 
> import Classes
> 
> cupboard = Containers("cupboard", 0, "closed")
> 
> key = Items ("worn key", 0)
> 
> When I go to run this code, Python spits this back at me:
> 
> >>>
> Traceback (innermost last):
>   File "C:/Program Files/Python20/game.py", line 3, in ?
>     cupboard = Containers("cupboard", 0, "closed")
> NameError: There is no variable named 'Containers'
> 
> What am I doing wrong?

It is not a problem with your classes, it is how you are importing the
module.  Using the "import" statement as you are, you need to qualify
the subclass.

>>> import Classes
>>> cupboard = Classes.Containers("cupboard", 0, "closed")

If you use "from Classes import Containers", then you can use just
"Containers".

>>> from Classes import Containers
>>> cupboard = Containers("cupboard", 0, "closed")

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From deirdre@deirdre.net  Wed Feb 28 01:00:59 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Tue, 27 Feb 2001 17:00:59 -0800 (PST)
Subject: [Tutor] Question About Subclasses
In-Reply-To: <F216CiZQWLU70httXc0000003d0@hotmail.com>
Message-ID: <Pine.LNX.4.31.0102271659500.12635-100000@emperor.deirdre.org>

On Tue, 27 Feb 2001, Britt Green wrote:

> Then within another file called "game.py" I have the following code:
>
> import Classes
>
> cupboard = Containers("cupboard", 0, "closed")

This is a namespace problem. You can solve it one of two ways:

from Classes import *
cupboard = Containers("cupboard", 0, "closed")

or (better)

import Classes
cupboard = Classes.Containers("cupboard", 0, "closed")

--
_Deirdre              deirdre@deirdre.net         http://www.deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From charlie@webmind.com  Wed Feb 28 01:22:57 2001
From: charlie@webmind.com (Charlie Derr)
Date: Tue, 27 Feb 2001 20:22:57 -0500
Subject: [Tutor] Question About Subclasses
In-Reply-To: <F216CiZQWLU70httXc0000003d0@hotmail.com>
Message-ID: <NDBBLJJLLFOJMLCMJPLOEEOGGNAA.charlie@webmind.com>

try

cupboard = Classes.Containers("cupboard", 0, "closed")


it will also work without that change if you subsitute

from Classes import *

for

import Classes

but there are a bunch of reasons for *not* doing it this way  -- get in the
habit of using the syntax in the first solution


	hth,
		~c

|-----Original Message-----
|From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
|Britt Green
|Sent: Tuesday, February 27, 2001 7:55 PM
|To: tutor@python.org
|Subject: [Tutor] Question About Subclasses
|
|
|Hello,
|
|I'm having some problems getting Python to create a subclass. I
|have a class
|called Items, and then a subclass of that called Containers.
|Python doesn't
|recognize Containers as a valid subclass.
|
|This is what I have in a file called "Classes.py":
|
|class Items:
|    def __init__(self, name, ip):
|        self.name = name
|        self.inPossesion = ip
|
|class Containers(Items):
|    def __init__(self, name, ip, oc):
|        Items.__init__(self, name, ip)
|        self.openClosed = oc
|
|Then within another file called "game.py" I have the following code:
|
|import Classes
|
|cupboard = Containers("cupboard", 0, "closed")
|
|key = Items ("worn key", 0)
|
|When I go to run this code, Python spits this back at me:
|
|>>>
|Traceback (innermost last):
|  File "C:/Program Files/Python20/game.py", line 3, in ?
|    cupboard = Containers("cupboard", 0, "closed")
|NameError: There is no variable named 'Containers'
|
|What am I doing wrong?
|
|Thanks,
|
|Britt
|
|--
|It is pitch black. You are likely to be eaten by a grue.
|
|_________________________________________________________________
|Get your FREE download of MSN Explorer at http://explorer.msn.com
|
|
|_______________________________________________
|Tutor maillist  -  Tutor@python.org
|http://mail.python.org/mailman/listinfo/tutor



From britt_green@hotmail.com  Wed Feb 28 01:39:50 2001
From: britt_green@hotmail.com (Britt Green)
Date: Tue, 27 Feb 2001 17:39:50 -0800
Subject: [Tutor] Two More Questions
Message-ID: <F143EvzX3sSJPv01YUS00007b3c@hotmail.com>

First off, thanks to everyone who helped me out with my previous question.

Now I've got another one. I have the following code added to my Classes.py 
file:

class Items:
    def __init__(self, name, ip):
        self.name = name
        self.inPossesion = ip

class Containers(Items):
    def __init__(self, name, ip, oc):
        Items.__init__(self, name, ip)
        self.openClosed = oc

class Rooms:
    def __init__(self, name):
        self.name = name

Then I have this code which uses the Classes.py file:

import Classes

cupboard = Classes.Containers("cupboard", 0, "closed")

key = Classes.Items ("worn key", 0)

kitchen = Classes.Rooms("Kitchen")

However, when I run the above code, Python replies with this:

>>>
Traceback (innermost last):
  File "C:/Program Files/Python20/game.py", line 7, in ?
    kitchen = Classes.Rooms("Kitchen")
AttributeError: Rooms

What might be causing this? I've checked for typos and whatnot, but I don't 
see any.

Also, I was wondering how I could put a fairly large string into the 
constructor. If I had a couple of paragraphs of a room description, what 
would it look like when I called the constructor? I haven't been able to 
figure out how to get Python to accept multi-line strings this way.

Thanks!

Britt

--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From arthur.watts@gbst.com  Wed Feb 28 02:43:53 2001
From: arthur.watts@gbst.com (Arthur Watts)
Date: Wed, 28 Feb 2001 12:43:53 +1000
Subject: [Tutor] My two cents worth re Python Newbies
Message-ID: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au>

Guys,

	I know that this post may attract the odd flame, but please read it
in its entirety before you begin your reply. 

	The majority of posts to the Tutor mailing lists are from people who
have tried to resolve a particular problem before resorting to the list.
Some, however, are simply 'noise'. I find the patient, thoughtful replies
given by the good souls on this list to be a real eye-opener, and I commend
you for your warmth and dedication when responding to newbie enquiries. My
own view is that the list should be for people who are able to :

	a. Read
	b. Use a Net search engine
	c. Navigate to www.python.org
	d. Use the skills detailed above to find other Python resources

	 If people still need to ask questions, then I'm willing to bet that
the answer will be something which enlightens the majority of the list
recipients. Python is growing at a phenomenal rate, but we need to keep the
'information <-> noise' ratio to a minimum, and a Tutor digest filled with
questions such as 'Is Python any good for CGI / GUI programming /
pre-schoolers ?' does neither the author nor the Python community any good.
This is all covered at python.org (OK, some thought may be required re the
pre-schoolers ..). As for the people who balatantly ask for someone to do
their Uni assignment for them, I think the moderators have been way too
polite / lenient ! 

	I realise that some may brand me elitist, but I am far from it : I
still have a lot to learn re. Python and other Open Source products. The key
is that I am prepared to actually cut some code or attempt to configure a
product before I fire off a posting re. a particular issue.  We need to
welcome thinking people to the Python community, and filter out those who
have a problem with RTFM. 

	I welcome any constructive criticism on this subject. I don't own
the list and I'm willing to accept the decision of other subscribers, be it
ever so painful :}

Regards,

Arthur

Arthur Watts
Software Engineer GBST Automation
Global Banking & Securities Transactions

Telephone + 61 7 3331 5555
mailto: arthur.watts@gbst.com
www.gbst.com




 

	


From rob@jam.rr.com  Wed Feb 28 04:18:47 2001
From: rob@jam.rr.com (R. A.)
Date: Tue, 27 Feb 2001 22:18:47 -0600
Subject: [Tutor] My two cents worth re Python Newbies
References: <1CDB101F0CB6D311882F0000F806392402F1636C@aquarius.bne.star.com.au>
Message-ID: <3A9C7C27.CE91E1D0@jam.rr.com>

Your post seems thoughtful, and hardly flameworthy.  This list is an
exceptional resource, and it's nice to see that others appreciate it
enough to express concern.  I find nothing to criticize about Python
Tutor, but you do remind us of a few significant points.

I add a few comments below:
Rob Andrews

Arthur Watts wrote:
> 
> Guys,
> 
>         I know that this post may attract the odd flame, but please read it
> in its entirety before you begin your reply.
> 
>         The majority of posts to the Tutor mailing lists are from people who
> have tried to resolve a particular problem before resorting to the list.
> Some, however, are simply 'noise'. I find the patient, thoughtful replies
> given by the good souls on this list to be a real eye-opener, and I commend
> you for your warmth and dedication when responding to newbie enquiries. My
> own view is that the list should be for people who are able to :
> 
>         a. Read
>         b. Use a Net search engine
>         c. Navigate to www.python.org
>         d. Use the skills detailed above to find other Python resources

All handy skills.  Let's not forget comp.lang.python and repositories of
source code which often provide rich veins of working solutions for the
curious.

> 
>          If people still need to ask questions, then I'm willing to bet that
> the answer will be something which enlightens the majority of the list
> recipients. Python is growing at a phenomenal rate, but we need to keep the
> 'information <-> noise' ratio to a minimum, and a Tutor digest filled with
> questions such as 'Is Python any good for CGI / GUI programming /
> pre-schoolers ?' does neither the author nor the Python community any good.
> This is all covered at python.org (OK, some thought may be required re the
> pre-schoolers ..). As for the people who balatantly ask for someone to do
> their Uni assignment for them, I think the moderators have been way too
> polite / lenient !

I'm not a university student, but a career network geek who learns quite
a bit from some of these questions, so there's at least that much good
in it.  I can't recall off-hand any of these threads getting out of
hand, and the channel seems to exhibit a certain warmth that I like.

> 
>         I realise that some may brand me elitist, but I am far from it : I
> still have a lot to learn re. Python and other Open Source products. The key
> is that I am prepared to actually cut some code or attempt to configure a
> product before I fire off a posting re. a particular issue.  We need to
> welcome thinking people to the Python community, and filter out those who
> have a problem with RTFM.
> 
>         I welcome any constructive criticism on this subject. I don't own
> the list and I'm willing to accept the decision of other subscribers, be it
> ever so painful :}
> 
> Regards,
> 
> Arthur
> 
> Arthur Watts
> Software Engineer GBST Automation
> Global Banking & Securities Transactions
> 
> Telephone + 61 7 3331 5555
> mailto: arthur.watts@gbst.com
> www.gbst.com
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

The Useless Python Repository has received an XHTML face-lift!
http://www.lowerstandard.com/python/pythonsource.html


From michaelbaker@operamail.com  Wed Feb 28 04:46:37 2001
From: michaelbaker@operamail.com (Michael Baker)
Date: Tue, 27 Feb 2001 23:46:37 -0500
Subject: [Tutor] BeOpen-Python-2.0-1.src.rpm
Message-ID: <3B1C69AA@operamail.com>

thanks to all for the recent help with PYTHONPATH. on to the next inquiry...

this might be more of a linux question, but here it is. I'm running LinuxPPC 
on a Powermac. the most recent python rpm I can find is v 1.52. I tried to 
compile the source rpm for v 2.0 but an error occurred after about 20 seconds 
of crunching:

+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd Python-2.0
++ /usr/bin/id -u
+ '[' 0 = 0 ']'
+ /bin/chown -Rhf root .
++ /usr/bin/id -u
+ '[' 0 = 0 ']'
+ /bin/chgrp -Rhf root .
+ /bin/chmod -Rf a+rX,g-w,o-w .
+ echo 'Patch #0 (BeOpen-Python-2.0-Setup.patch):'
Patch #0 (BeOpen-Python-2.0-Setup.patch):
+ patch -p0 -s
/var/tmp/rpm-tmp.17620: patch: command not found
Bad exit status from /var/tmp/rpm-tmp.17620 (%prep)

if this question is more appropriate for a different list please advise.
:)

thanks



From dyoo@hkn.eecs.berkeley.edu  Wed Feb 28 07:20:53 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 27 Feb 2001 23:20:53 -0800 (PST)
Subject: [Tutor] BeOpen-Python-2.0-1.src.rpm
In-Reply-To: <3B1C69AA@operamail.com>
Message-ID: <Pine.LNX.4.21.0102272319290.25253-100000@hkn.eecs.berkeley.edu>

On Tue, 27 Feb 2001, Michael Baker wrote:

> if this question is more appropriate for a different list please
> advise. :)

Hmmm... don't know.  You might want to ask this to the main
comp.lang.python newsgroup instead.  I'm not sure how many of us are
versed in the arts of RPM management.  *grin*



From dyoo@hkn.eecs.berkeley.edu  Wed Feb 28 07:38:36 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 27 Feb 2001 23:38:36 -0800 (PST)
Subject: [Tutor] Two More Questions
In-Reply-To: <F143EvzX3sSJPv01YUS00007b3c@hotmail.com>
Message-ID: <Pine.LNX.4.21.0102272323330.25253-100000@hkn.eecs.berkeley.edu>

On Tue, 27 Feb 2001, Britt Green wrote:

> cupboard = Classes.Containers("cupboard", 0, "closed")
> key = Classes.Items ("worn key", 0)
> kitchen = Classes.Rooms("Kitchen")
> 
> However, when I run the above code, Python replies with this:
> 
> >>>
> Traceback (innermost last):
>   File "C:/Program Files/Python20/game.py", line 7, in ?
>     kitchen = Classes.Rooms("Kitchen")
> AttributeError: Rooms

Strange!  I tried out your code, and didn't run into any problems.  Can
you recheck your work?

While you're in the interpreter, if you start making changes to
Classes.py, you need to tell the interpreter that your module has
undergone changes.

Doing the obvious:

###
>>> import Classes
###

doesn't work; as an optimization step, if Python sees that a module's
already loaded, it'll ignore any more 'import Blah' calls.  So we really
do need to force the issue, by using reload():

>>> reload(Classes)
<module 'Classes' from 'Classes.pyc'>

That's a wild shot in the dark, but perhaps this is what's happening for
you.



> Also, I was wondering how I could put a fairly large string into the
> constructor. If I had a couple of paragraphs of a room description,
> what would it look like when I called the constructor? I haven't been
> able to figure out how to get Python to accept multi-line strings this
> way.

Python supports multi-line strings, which are very nice.  For example, we
could do this:

roomdesc = """It is pitch dark.

You are likely to get eaten by a grue.
"""

Triple quotes begin and end a multi-line string; otherwise, they're not
different from regular strings.  They can be passed around as parameters:

###
>>> string.center('''hello world.
... this is a test.''', 45)
'         hello world.\012this is a test.        '
###

Hmmm... but it depends on the function if it handles a multi-line string
properly or not.  string.center() certainly didn't handle that nicely.  
Whoops.

If you want to take a look at the gory details, here's the link to the
reference manual:

    http://python.org/doc/current/ref/strings.html

Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Wed Feb 28 11:22:18 2001
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 28 Feb 2001 03:22:18 -0800 (PST)
Subject: [Tutor] Trapping Interpreter errors as a string
In-Reply-To: <01022618444804.02153@shecom>
Message-ID: <Pine.LNX.4.21.0102280315450.22614-100000@c82114-a.pinol1.sfba.home.com>

On Mon, 26 Feb 2001, Tim Johnson wrote:

> integer = string.atoi("duh")
> 
> Guido will then say:
> 
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ValueError: invalid literal for atoi(): duh
> 
> To reduce this inquiry:
> 1)Can that error message be returned to the user as a string.
> 2)Is there a specific numeric error code attached to the error message.
>    i.e. ValueError = ?

It sounds like you might want to use exception handling: Exception
handling often takes the place of error codes in Python programming.

We can get at the ValueError as a string:

###
>>> try:
...     integer = string.atoi("duh")
... except ValueError, e:
...     print "Something went wrong."
...     print "Error message: ", e
... 
Something went wrong.
Error message:  invalid literal for int(): duh
###

The idea is that we wrap a try/except block around whatever code might
need some error trapping, and handle exceptional situations appropriately.  
Exception handling should be flexible enough to let you clean up the
situation if its possible, and exit gracefully otherwise.  The Python
tutorial talks about this here:

    http://python.org/doc/current/tut/node10.html

Hope this helps!



From rob@jam.rr.com  Wed Feb 28 12:43:42 2001
From: rob@jam.rr.com (R. A.)
Date: Wed, 28 Feb 2001 06:43:42 -0600
Subject: [Tutor] BeOpen-Python-2.0-1.src.rpm
References: <Pine.LNX.4.21.0102272319290.25253-100000@hkn.eecs.berkeley.edu>
Message-ID: <3A9CF27E.C67F5795@jam.rr.com>

There are also some good linux help lists out there to check with.  The
one local to me is lugoj@lugoj.org and seems populated with intelligent
and experienced people who like to help if they can.  Their website is
www.lugoj.org.

However, if you're a linux user, you may already have some support
network in place.

Good fortunes,
Rob

Daniel Yoo wrote:
> 
> On Tue, 27 Feb 2001, Michael Baker wrote:
> 
> > if this question is more appropriate for a different list please
> > advise. :)
> 
> Hmmm... don't know.  You might want to ask this to the main
> comp.lang.python newsgroup instead.  I'm not sure how many of us are
> versed in the arts of RPM management.  *grin*


-- 

The Useless Python Repository has received an XHTML face-lift!
http://www.lowerstandard.com/python/pythonsource.html


From dsh8290@rit.edu  Wed Feb 28 14:57:19 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 28 Feb 2001 09:57:19 -0500
Subject: [Tutor] BeOpen-Python-2.0-1.src.rpm
In-Reply-To: <3B1C69AA@operamail.com>; from michaelbaker@operamail.com on Tue, Feb 27, 2001 at 11:46:37PM -0500
References: <3B1C69AA@operamail.com>
Message-ID: <20010228095719.A21723@harmony.cs.rit.edu>

On Tue, Feb 27, 2001 at 11:46:37PM -0500, Michael Baker wrote:
| thanks to all for the recent help with PYTHONPATH. on to the next inquiry...
| 
| this might be more of a linux question, but here it is. I'm running LinuxPPC 
| on a Powermac. the most recent python rpm I can find is v 1.52. I tried to 
| compile the source rpm for v 2.0 but an error occurred after about 20 seconds 
| of crunching:
| 

| Patch #0 (BeOpen-Python-2.0-Setup.patch):
| + patch -p0 -s
| /var/tmp/rpm-tmp.17620: patch: command not found
| Bad exit status from /var/tmp/rpm-tmp.17620 (%prep)
| 
| if this question is more appropriate for a different list please advise.
| :)
| 

This does seem to be more of a linux issue than a python one.

Do you have 'patch' on your system?  Try typing "patch" or "which
patch" at a shell prompt.  You could also try "rpm -qa | grep patch"
or "rpm -qf *patch" (I'm not sure of the syntax for the last command,
I hope it reports the package owning a file named *patch (using shell
globbing)).  The rpm was instructed to patch the sources with a patch
that BeOpen provided in the rpm.  A patch is really nothing more than
a diff, and the patch program works like diff in reverse -- instead of
reporting the differences between 2 versions, it takes one version and
the differences to create the other.

Perhaps the main list can help more?  Or maybe a LinuxPPC list, since
it is not python specific.

HTH,
-D



From tim@johnsons-web.com  Wed Feb 28 16:58:42 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Wed, 28 Feb 2001 07:58:42 -0900
Subject: [Tutor] Trapping Interpreter errors as a string
References: <Pine.LNX.4.21.0102280315450.22614-100000@c82114-a.pinol1.sfba.home.com>
Message-ID: <01022808043400.02349@shecom>

Hi Danny:

> It sounds like you might want to use exception handling: Exception
> handling often takes the place of error codes in Python programming.
I was familar with exeception handling in rebol and C++ when I posted that
question. What I was looking for was the broadest possible "net", 
the reason for asking about an error code, was that, if such existed,
I could modify the error messages.

The reason for this is that I want to set up a "desktop cgi" process for
students to test code, instead of directly from the command line.

Python-newbie-old-coder-learning-python-while-designing-
online-course-for-high-schoolers
Thanks
--
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides


From scarblac@pino.selwerd.nl  Wed Feb 28 17:07:27 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 28 Feb 2001 18:07:27 +0100
Subject: [Tutor] Trapping Interpreter errors as a string
In-Reply-To: <01022808043400.02349@shecom>; from tim@johnsons-web.com on Wed, Feb 28, 2001 at 07:58:42AM -0900
References: <Pine.LNX.4.21.0102280315450.22614-100000@c82114-a.pinol1.sfba.home.com> <01022808043400.02349@shecom>
Message-ID: <20010228180727.A21317@pino.selwerd.nl>

On Wed, Feb 28, 2001 at 07:58:42AM -0900, Tim Johnson wrote:
> Hi Danny:
> 
> > It sounds like you might want to use exception handling: Exception
> > handling often takes the place of error codes in Python programming.
> I was familar with exeception handling in rebol and C++ when I posted that
> question. What I was looking for was the broadest possible "net", 
> the reason for asking about an error code, was that, if such existed,
> I could modify the error messages.

The broadest possible net is the simple except: clause that catches
everything:

try:
   x = int("whee")
except:
   # Do anything you want here; the current exception is in
   # sys.exc_info().
   import sys
   exception, argument, traceback = sys.exc_info()
   # See also the traceback module for printing info
  
   if exception is ValueError:
       print "Make sure that the string you give to int() has only numbers."
   else:
       # Re-raise every exception you can't handle, like out of memory errors,
       # or KeyboardInterrupt (a user hitting ctrl-C)
       raise
       


From alan.gauld@bt.com  Wed Feb 28 17:20:26 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 28 Feb 2001 17:20:26 -0000
Subject: [Tutor] Two More Questions
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D5D8@mbtlipnt02.btlabs.bt.co.uk>

> >>> string.center('''hello world.
> ... this is a test.''', 45)
> '         hello world.\012this is a test.        '
> ###
> 
> Hmmm... but it depends on the function if it handles a 
> multi-line string properly or not.  string.center() 
> certainly didn't handle that nicely.  


Why not? It preserved the \012 nicely. if you had 'print'ed 
the output then it would have been laid out as you requested:

            hello world
this is a test

Now whether thats what you expected centre to dso is another 
matter, it certainly won't centre each line, but it doesn't 
claim to do so.

Alan g.


From cmccormick@thestate.com  Wed Feb 28 19:25:15 2001
From: cmccormick@thestate.com (Chris McCormick)
Date: Wed, 28 Feb 2001 14:25:15 -0500
Subject: [Tutor] >> Best setup for animation? <<
Message-ID: <3A9D509B.DCA827DE@thestate.com>

Hi again,
    So, I've been writing a program with Python and Tkinter.  It does
some simple animation, but it is all procedural.  That is to say, I have
several agents moving around my canvas, and they all *take turns* moving
and being re-displayed.  I'm not sure how to do animation the way I
would do it in directX, which is as follows:

1.  Create a primary surface(canvas).
2.  Draw everything in its initial state.
3.  Process AI.
4.  Move everything to its next-frame state on a *hidden* surface.
5.  Make the canvas point to the hidden surface, so all moves are seen
at once.

Thus, my question is two-fold:

1.  Is there a way to create two canvases, and switch between them to
create a blitting effect?  I have to admit that I'm a little fuzzy on
exactly how packing works, and maybe there's a way to display all
updated objects at once with *one* canvas?
2.  Before I go much farther, is the Python Tkinter combo the best setup
for game-type animation?  I've also started looking at wxPython and
PyGame, which uses something called SDL.

I'd like to settle on an evironment and really concentrate on the AI.
I'd stick with Tkinter if only I could get it to blit.

Thanks in advance for any help (or pointers to help) you can provide,
Chris



From tamezi_2000@yahoo.com  Wed Feb 28 19:55:12 2001
From: tamezi_2000@yahoo.com (IVAN TAMEZ)
Date: Wed, 28 Feb 2001 11:55:12 -0800 (PST)
Subject: [Tutor] como chingados me quito de la lista?
In-Reply-To: <3A9D509B.DCA827DE@thestate.com>
Message-ID: <20010228195512.15233.qmail@web9506.mail.yahoo.com>

--0-554072655-983390112=:15109
Content-Type: text/plain; charset=us-ascii


 Can you tell me how to remove me from the mailing list? I don't need to recieve"tutor" mail anymore

thanks


  Chris McCormick <cmccormick@thestate.com> wrote: 
Hi again,
So, I've been writing a program with Python and Tkinter. It does
some simple animation, but it is all procedural. That is to say, I have
several agents moving around my canvas, and they all *take turns* moving
and being re-displayed. I'm not sure how to do animation the way I
would do it in directX, which is as follows:

1. Create a primary surface(canvas).
2. Draw everything in its initial state.
3. Process AI.
4. Move everything to its next-frame state on a *hidden* surface.
5. Make the canvas point to the hidden surface, so all moves are seen
at once.

Thus, my question is two-fold:

1. Is there a way to create two canvases, and switch between them to
create a blitting effect? I have to admit that I'm a little fuzzy on
exactly how packing works, and maybe there's a way to display all
updated objects at once with *one* canvas?
2. Before I go much farther, is the Python Tkinter combo the best setup
for game-type animation? I've also started looking at wxPython and
PyGame, which uses something called SDL.

I'd like to settle on an evironment and really concentrate on the AI.
I'd stick with Tkinter if only I could get it to blit.

Thanks in advance for any help (or pointers to help) you can provide,
Chris


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


---------------------------------
Do You Yahoo!?
Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail.
--0-554072655-983390112=:15109
Content-Type: text/html; charset=us-ascii

<P> Can you tell me how to remove me from the mailing list? I don't need to recieve"tutor" mail anymore</P>
<P>thanks<BR></P>
<P>&nbsp; <B><I>Chris McCormick &lt;cmccormick@thestate.com&gt;</I></B> wrote: <BR>
<BLOCKQUOTE style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">Hi again,<BR>So, I've been writing a program with Python and Tkinter. It does<BR>some simple animation, but it is all procedural. That is to say, I have<BR>several agents moving around my canvas, and they all *take turns* moving<BR>and being re-displayed. I'm not sure how to do animation the way I<BR>would do it in directX, which is as follows:<BR><BR>1. Create a primary surface(canvas).<BR>2. Draw everything in its initial state.<BR>3. Process AI.<BR>4. Move everything to its next-frame state on a *hidden* surface.<BR>5. Make the canvas point to the hidden surface, so all moves are seen<BR>at once.<BR><BR>Thus, my question is two-fold:<BR><BR>1. Is there a way to create two canvases, and switch between them to<BR>create a blitting effect? I have to admit that I'm a little fuzzy on<BR>exactly how packing works, and maybe there's a way to display all<BR>updated objects at once with *one* canvas?<BR>2. Before I go much farther, is the Python Tkinter combo the best setup<BR>for game-type animation? I've also started looking at wxPython and<BR>PyGame, which uses something called SDL.<BR><BR>I'd like to settle on an evironment and really concentrate on the AI.<BR>I'd stick with Tkinter if only I could get it to blit.<BR><BR>Thanks in advance for any help (or pointers to help) you can provide,<BR>Chris<BR><BR><BR>_______________________________________________<BR>Tutor maillist - Tutor@python.org<BR>http://mail.python.org/mailman/listinfo/tutor</BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</a> - 
Get email at your own domain with Yahoo! Mail.
--0-554072655-983390112=:15109--


From deirdre@deirdre.net  Wed Feb 28 19:54:09 2001
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Wed, 28 Feb 2001 11:54:09 -0800 (PST)
Subject: [Tutor] como chingados me quito de la lista?
In-Reply-To: <20010228195512.15233.qmail@web9506.mail.yahoo.com>
Message-ID: <Pine.LNX.4.31.0102281152100.22724-100000@emperor.deirdre.org>

On Wed, 28 Feb 2001, IVAN TAMEZ wrote:

>  Can you tell me how to remove me from the mailing list? I don't need
> to recieve"tutor" mail anymore

It's on the bottom of every single tutor post. specifically, point your
web-browser to:

> http://mail.python.org/mailman/listinfo/tutor

And follow the instructions there. Hint: it's in the bottom section of the
page.


--
_Deirdre              deirdre@deirdre.net         http://www.deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From tim.one@home.com  Wed Feb 28 20:04:02 2001
From: tim.one@home.com (Tim Peters)
Date: Wed, 28 Feb 2001 15:04:02 -0500
Subject: [Tutor] como chingados me quito de la lista?
In-Reply-To: <20010228195512.15233.qmail@web9506.mail.yahoo.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCCEMKJCAA.tim.one@home.com>

[IVAN TAMEZ]
> Can you tell me how to remove me from the mailing list? I don't need
> to recieve "tutor" mail anymore

At the bottom of every piece of email you get from the Tutor list, you'll
find something like this:

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

Click on the link!  Then follow the instructions near the bottom:  you signed
yourself up, you sign yourself off.



From gibbs05@flash.net  Wed Feb 28 22:04:11 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Wed, 28 Feb 2001 16:04:11 -0600
Subject: [Tutor] >> Best setup for animation? <<
References: <3A9D509B.DCA827DE@thestate.com>
Message-ID: <000f01c0a1d2$78087c40$c6f832d8@gibbs05>

Greetings Chris & All,

I hit this problem just this Sunday.  Switching out images is much easier
with Label than Canvas.  In fact, it's this easy:

    LabelVar['image'] = OtherImage

The rub is you'll have to write all the event handling logic yourself. :-)

So, you can compose two or more images using PIL and switch them out on the
label.  As long as they're almost identical, its fairly smooth.


I think Tkinter is fine for doing prototypes of this kind of work.  That's
what I'm trying to do.


Good luck,
Sam

> Hi again,
>     So, I've been writing a program with Python and Tkinter.  It does
> some simple animation, but it is all procedural.  That is to say, I have
> several agents moving around my canvas, and they all *take turns* moving
> and being re-displayed.  I'm not sure how to do animation the way I
> would do it in directX, which is as follows:
>
> 1.  Create a primary surface(canvas).
> 2.  Draw everything in its initial state.
> 3.  Process AI.
> 4.  Move everything to its next-frame state on a *hidden* surface.
> 5.  Make the canvas point to the hidden surface, so all moves are seen
> at once.
>
> Thus, my question is two-fold:
>
> 1.  Is there a way to create two canvases, and switch between them to
> create a blitting effect?  I have to admit that I'm a little fuzzy on
> exactly how packing works, and maybe there's a way to display all
> updated objects at once with *one* canvas?
> 2.  Before I go much farther, is the Python Tkinter combo the best setup
> for game-type animation?  I've also started looking at wxPython and
> PyGame, which uses something called SDL.
>
> I'd like to settle on an evironment and really concentrate on the AI.
> I'd stick with Tkinter if only I could get it to blit.
>
> Thanks in advance for any help (or pointers to help) you can provide,
> Chris
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From kstoner@netins.net  Wed Feb 28 23:55:07 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Wed, 28 Feb 2001 17:55:07 -0600
Subject: [Tutor] what's wrong with this code
Message-ID: <000801c0a1e1$e17923a0$f952b1cf@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C0A1AF.963E7C00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

What's wrong with this code?  I don't understand. Please help.

input("What is the temperature of the spam?") =3D temperature

    if temperature > 50:
        print "The salad is properly cooked."
    else:
        print "Cook the salad some more."

-Cameron Stoner

------=_NextPart_000_0005_01C0A1AF.963E7C00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>What's wrong with this code?&nbsp; I=20
don't&nbsp;understand. Please help.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>input("What is the temperature of the =
spam?") =3D=20
temperature</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if temperature &gt;=20
50:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "The salad is =
properly=20
cooked."<BR>&nbsp;&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Cook the =
salad some=20
more."</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C0A1AF.963E7C00--