From alan.gauld@bt.com  Sat Jun  1 00:00:58 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 1 Jun 2002 00:00:58 +0100
Subject: [Tutor] Catching the exit
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C631@mbtlipnt02.btlabs.bt.co.uk>

> def catchexit(event):
>     query = askyesno(title='Warning', message='Did you save 
> your work')
>     print query
>     if query == 'Yes':
> 	    sys.exit()
>     else:
> 	    return

I think this return will now take you into the default 
handler which will exit anyway.

You need to use

          return "break"

to turn off the default behaviour.


Alan G



From mpeters@mac.com  Sat Jun  1 10:31:12 2002
From: mpeters@mac.com (Michael A. Peters)
Date: Sat, 1 Jun 2002 02:31:12 -0700
Subject: [Tutor] Python and PHP config files
Message-ID: <20020601023112.7fec147b.mpeters@mac.com>

Hi all-

I'm trying to have python run as a cron in the background to assist in a
php web application.

I need to have the python script be able to get values from a php config
file.
Here's the relative parts of my script so far-

-------------------------------
#!/usr/local/bin/python
PathToConfig = "/var/www/folding_stats/folding.config.php"

import os, sys, urllib
try:
	import MySQLdb
except ImportError, e:
	print "It seems you do not have the python MySQLdb module installed."
	sys.exit(1)

if os.path.isfile(PathToConfig):
	# here is where I read the data I need
	datafile = open(PathToConfig)
	config = datafile.readlines()
	datafile.close()
else:
	print "I can not find your config file."
	print "Please specify its location at"
	print "line 2 of this file."
	sys.exit(1)
-------------------------------

config is now an array containing the php file- but I need to extract info
out of that, and I can't seem to figure out how :(

For example, the lines in the file i need are-

$db_name="foldingathome";
$db_host="localhost";
$db_port="3306";
$db_user="samwise";
$db_password="xyzzy";

I need to find where the php variable for db_name is defined and assign a
python variable for that- such as

db_name = somefunction(config, db_name)
where
somefunction(config, db_name)
would find $db_name= in the config list and then return what's in their.

Anyone know how to do it?

in bourne with shell tools I would do
db_name=`grep "^\$db_name=" filename |cut -d"\"" -f2`

but I'm using python, not bourne :D

Thanks for any help



From kalle@lysator.liu.se  Sat Jun  1 14:44:37 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sat, 1 Jun 2002 15:44:37 +0200
Subject: [Tutor] Python and PHP config files
In-Reply-To: <20020601023112.7fec147b.mpeters@mac.com>
References: <20020601023112.7fec147b.mpeters@mac.com>
Message-ID: <20020601134437.GA1640@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Michael A. Peters]
> For example, the lines in the file i need are-
> 
> $db_name="foldingathome";
> $db_host="localhost";
> $db_port="3306";
> $db_user="samwise";
> $db_password="xyzzy";
> 
> I need to find where the php variable for db_name is defined and assign a
> python variable for that- such as
> 
> db_name = somefunction(config, db_name)
> where
> somefunction(config, db_name)
> would find $db_name= in the config list and then return what's in their.

A rough beginning might look something like this:

def find_parameter(config_lines, parameter):
    for line in config_lines:
        if line.find(parameter) >= 0:
            return line.split("=")[1]

It can be used like this:

>>> config = ['foo\n', '$db_host="host";\n', '$db_user="user";\n']
>>> find_parameter(config, "$db_user")
'"user";\n'

See http://python.org/doc/current/lib/string-methods.html for more
information about string methods like find and split.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE8+M+odNeA1787sd0RAhNBAKC0WIDuM8Utz7UtDKAytDc/8z6+HgCeKeDL
UgwMzmTkaqyIkbrspapR4Hs=
=7UWR
-----END PGP SIGNATURE-----



From lkvam@venix.com  Sat Jun  1 23:43:55 2002
From: lkvam@venix.com (Lloyd Kvam)
Date: Sat, 01 Jun 2002 18:43:55 -0400
Subject: [Tutor] Python and PHP config files
References: <20020601023112.7fec147b.mpeters@mac.com> <20020601134437.GA1640@i92.ryd.student.liu.se>
Message-ID: <3CF94E2B.2020604@venix.com>

An alternative approach would be to put the config information into a
dictionary.  Picking up from your code:
	...
	config = datafile.readlines()
	config_dict = {}
	for con in config:	#line by line
		name,value = con.split('=')	#split as Kalle did
		config_dict[name] = value
	...

now
	db = config_dict["db_name"]

When I can, I like to save my config info directly in a dictionary that I
simply import.


Kalle Svensson wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> [Michael A. Peters]
> 
>>For example, the lines in the file i need are-
>>
>>$db_name="foldingathome";
>>$db_host="localhost";
>>$db_port="3306";
>>$db_user="samwise";
>>$db_password="xyzzy";
>>
>>I need to find where the php variable for db_name is defined and assign a
>>python variable for that- such as
>>
>>db_name = somefunction(config, db_name)
>>where
>>somefunction(config, db_name)
>>would find $db_name= in the config list and then return what's in their.
>>
> 
> A rough beginning might look something like this:
> 
> def find_parameter(config_lines, parameter):
>     for line in config_lines:
>         if line.find(parameter) >= 0:
>             return line.split("=")[1]
> 
> It can be used like this:
> 
> 
>>>>config = ['foo\n', '$db_host="host";\n', '$db_user="user";\n']
>>>>find_parameter(config, "$db_user")
>>>>
> '"user";\n'
> 
> See http://python.org/doc/current/lib/string-methods.html for more
> information about string methods like find and split.
> 
> Peace,
>   Kalle
> - -- 
> Kalle Svensson, http://www.juckapan.org/~kalle/
> Student, root and saint in the Church of Emacs.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>
> 
> iD8DBQE8+M+odNeA1787sd0RAhNBAKC0WIDuM8Utz7UtDKAytDc/8z6+HgCeKeDL
> UgwMzmTkaqyIkbrspapR4Hs=
> =7UWR
> -----END PGP SIGNATURE-----
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From dyoo@hkn.eecs.berkeley.edu  Sun Jun  2 02:07:29 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 1 Jun 2002 18:07:29 -0700 (PDT)
Subject: [Tutor] Why NOT to Use Python?   [A Perl apologist]
In-Reply-To: <20020529224330.C6147@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0205292057300.10891-100000@hkn.eecs.berkeley.edu>

> I learned perl first, and switched to python because I wanted a language
> with better object oriented support. I also wanted to parse xml data,
> and I was told python was much better for this task than perl.

I may need to get myself in a mean frame of mind before I defend Perl.
*grin*


Cheekiness aside, I think Perl does have excellent XML support; Michel
Rodriguez's XML::Twig module is very nice:

    http://www.xmltwig.com/

and I think it would be great if there were a Python equivalent to
XML::Twig, but perhaps I haven't looked hard enough yet.


> So far, I think python is *much* better than perl. In fact, I would tell
> anybody learning perl this: "Don't bother. Python can do everything perl
> can, but the code is much more readable and easier to maintain.

At the same time, it's still a good thing to peek at the other side of the
fence every now and then, just to see what's out there.  There is
something... seductive about tricky programming.  I can understand how
Perl can appeal to certain minds.


I guess I'm trying to say that it might be counterproductive to discourage
people from looking at the other languages.  I feel that most people are
intelligent enough to look at the choices out there, weigh the pros and
cons, and decide for themselves that Python is a superb language.  *grin*


Hope this helps!




From shalehperry@attbi.com  Sun Jun  2 05:27:29 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 01 Jun 2002 21:27:29 -0700 (PDT)
Subject: [Tutor] Why NOT to Use Python?   [A Perl apologist]
In-Reply-To: <Pine.LNX.4.44.0205292057300.10891-100000@hkn.eecs.berkeley.edu>
Message-ID: <XFMail.20020601212729.shalehperry@attbi.com>

> 
>> So far, I think python is *much* better than perl. In fact, I would tell
>> anybody learning perl this: "Don't bother. Python can do everything perl
>> can, but the code is much more readable and easier to maintain.
> 
> At the same time, it's still a good thing to peek at the other side of the
> fence every now and then, just to see what's out there.  There is
> something... seductive about tricky programming.  I can understand how
> Perl can appeal to certain minds.
> 
> 
> I guess I'm trying to say that it might be counterproductive to discourage
> people from looking at the other languages.  I feel that most people are
> intelligent enough to look at the choices out there, weigh the pros and
> cons, and decide for themselves that Python is a superb language.  *grin*
> 

I do not remember where the quote it from but it goes something like "A man
willing to test his convictions is better than one who blindly believes".

I too am a recovering perl user who can't imaging going back.  However 80% of
the last group I worked with were rabid perl hackers.  I know why too -- it
matched how they thought.  Quick hacks, their own personal (and often weird)
approach to coding, etc.  Python's "bland" and "homogenizing" approach would
not fit them.

Coding is a personal thing, people need to use what works for them.



From dyoo@hkn.eecs.berkeley.edu  Sun Jun  2 07:47:59 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 1 Jun 2002 23:47:59 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
Message-ID: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu>

Hi everyone,

[Warning; somewhat long message.  Sorry!]


For fun, I picked up Elwyn Berlekamp's "The Dots and Boxes Game", which is
a book about a deceptively simple game.  Here's Berlekamp's paragraph
describing the game:


"""Dots-and-Boxes is a familiar paper an pencil game for two players; it
has other names in various parts of the world.  Two players start from a
rectangular array of dots and take turns to join two horizonally or
vertically adjacent dots.  If a player completes the fourth side of a
square (box) he initials that box and must then draw another line.  When
all the boxes have een completed the game ends and whoever has initialed
more boxes is declared the winner.

A player who can complete a box is not obligated to do so if he has
something else he prefers to do."""



To make the game clearer, I'll run through a sample game.  Let's say that
two players, A and B, are playing Dots-And-Boxes on a 3x3 board:


 +  +  +

 +  +  +

 +  +  +



Here's one run through the game:


 +--+  +

 +  +  +

 +  +  +


Player A chooses to join the first two dots.




 +--+  +
    |
 +  +  +

 +  +  +

Player B chooses to join the mid-top and middle.  The game can proceed
like this:




 +--+  +
    |
 +  +  +        A moves a bit more down.
    |
 +  +  +



 +--+  +
    |
 +  +  +        B makes it snake around a bit.
    |
 +  +--+


 +--+  +
    |
 +  +  +        A connects the lower left and mid left points.
 |  |
 +  +--+



 +--+  +
    |
 +  +  +        A connects the lower left and mid left points.
 |  |
 +  +--+


 +--+  +
    |
 +  +  +        B forgets that the game is not Hangman.
 |  |
 +--+--+


 +--+  +
    |
 +--+  +        A completes a square.  Because of this, it's A's turn
 | A|           again.
 +--+--+



 +--+  +
 | A|
 +--+  +        A completes the upper left square.  Another free turn.
 | A|
 +--+--+


 +--+--+
 | A|
 +--+  +        A plays the upper right square, finally giving a turn
 | A|           to B.  But it's too late.
 +--+--+


 +--+--+
 | A|
 +--+  +        B places a futile line.
 | A|  |
 +--+--+


 +--+--+
 | A|
 +--+--+        And A promptly trounces.
 | A| A|
 +--+--+


 +--+--+
 | A| A|
 +--+--+        A dominates the game.
 | A| A|
 +--+--+


So it's sorta like Tic-Tac-Toe, but a little more interesting.  Yahoo
Games actually has this as one of their Java applets, I think... but
wouldn't it be fun to write a Python program to play this game?  *grin*

(We could even hold a Tutor Dots-And-Boxes competition, where our program
battle each other!  Hmmm!)



Fantasies aside, I'm written some toy code and thought perhaps someone
here might be interested too.  My code for the game is here:

    http://hkn.eecs.berkeley.edu/~dyoo/python/dots-and-boxes/board.py

I need to start working on the GUI for it since entering coordinates can
be a bit non-user-friendly; I'll start on this tomorrow.




From urnerk@qwest.net  Sun Jun  2 08:09:21 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 02 Jun 2002 00:09:21 -0700
Subject: [Tutor] Why NOT to Use Python?   [A Perl apologist]
In-Reply-To: <XFMail.20020601212729.shalehperry@attbi.com>
References: <Pine.LNX.4.44.0205292057300.10891-100000@hkn.eecs.berkeley.edu>
Message-ID: <4.2.0.58.20020601234955.01bfef00@pop3.norton.antivirus>

>
>I too am a recovering perl user who can't imaging going back.  However 80% of
>the last group I worked with were rabid perl hackers.  I know why too -- it
>matched how they thought.  Quick hacks, their own personal (and often weird)
>approach to coding, etc.  Python's "bland" and "homogenizing" approach would
>not fit them.
>
>Coding is a personal thing, people need to use what works for them.

I'm currently a Python coder (coming from APL, PL/1, Fortran,
some Java, dBase -> VFP7 (mainly this last, as a career even)).
However, I have fun learning Perl in my spare time.

I'm currently perusing the print version (O'Reilly, 1999)
of Eric S. Raymond's 'The Cathedral & the Bazaar' (a key text
in the open source syllabus, which I tend to link to 'design
science revolution' -- another story (see Stutz, Linux Cookbook))
suggests Python -> Java -> C/C++ as a good sequence, and I agree
that this is a fine way to go.  He also throws LISP into the
bag, which I might approach via Scheme (the PLT flavor by
Matthias & Co. and Rice Univ., to be specific).

It's somewhat ironic, ain't it?, that Java was designed with
C/C++ programmers in mind (aimed to capitalize on this huge
skillbase by adopting similar syntax) and yet now we have a
next generation of hacker using the similarities to go _from_
Java _to_ C, instead of coming the other way.  Likewise,
Python can be an onramp into programming in general, and from
there one branch out into whatever -- Perl included (continuing
literacy in this language most definitely a plus, especially
given the trajectory of Unix/GNU/Linux in century 0x15).

I think the most healthful attitude is to become a connoisseur
of many languages, vs. a partisan/fanatic/religious-warrior who
gets sucked in to thinking that what's best is to behave as a
proselytizer/missionary on behalf of one in particular.

Likewise when it comes to operating systems -- provided none
are backed against the wall in danger of complete extinction
(Linux is in no such danger, so I don't do bared fangs thing
-- Windows is more the dinosaur in this evolutionary picture,
which doesn't mean we should hasten its extinction (we need to
buy some time here, as a lot of the best apps/games are written
to that massively popular platform))).  BeOS is also worth
adding to a multi-boot system.

So yes, Python is exceedingly great, a fantastic language, but
that doesn't move me to diss Perl, which I also appreciate,
and love spending some free time tackling (was reading about
package-level symbol tables vs. my() variables earlier tonight).
I'm also revisiting C/C++ and have plenty of respect for Scheme
and LISP.  And I'll always be nostalgic for my first love: APL.

Vive le Difference!

Kirby




From urnerk@qwest.net  Sun Jun  2 08:14:46 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 02 Jun 2002 00:14:46 -0700
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley
 .edu>
Message-ID: <4.2.0.58.20020602001027.01bfebc0@pop3.norton.antivirus>

>\
>"""Dots-and-Boxes is a familiar paper an pencil game for two players;


Thanks for bringing this up Danny.  In earlier lives (as a
younger guy), I played this game quite a bit on paper, with
my sister Julie, peer group.  Taught it to a few people.
Then I forgot about it completely -- until now.  I always
called it "Square Off" and played it on graphing paper
(grid paper).

Yes, having a GUI version w/ Python guts would be mucho fun
and a challenging project.  I salute you for initiating this
bold proposal, backed with original code.

Kirby





From shalehperry@attbi.com  Sun Jun  2 08:21:48 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 02 Jun 2002 00:21:48 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <4.2.0.58.20020602001027.01bfebc0@pop3.norton.antivirus>
Message-ID: <XFMail.20020602002148.shalehperry@attbi.com>

On 02-Jun-2002 Kirby Urner wrote:
> 
>>\
>>"""Dots-and-Boxes is a familiar paper an pencil game for two players;
> 
> 
> Thanks for bringing this up Danny.  In earlier lives (as a
> younger guy), I played this game quite a bit on paper, with
> my sister Julie, peer group.  Taught it to a few people.
> Then I forgot about it completely -- until now.  I always
> called it "Square Off" and played it on graphing paper
> (grid paper).
> 
> Yes, having a GUI version w/ Python guts would be mucho fun
> and a challenging project.  I salute you for initiating this
> bold proposal, backed with original code.
> 

yeah, great one from childhood.

For the competition the design can be much simpler.

Have the player program read state from stdin and output moves to stdout.  A
mediator program can init to players and control the game.  Much like the
various net programming contests.

a sample session from the mediator's perspective would be:

(>> is output, <1 is player1 input, <2 is player2 input)
player 1 always goes first.

>1 init player1 as 1, grid 5x5
>2 init player2 as 2, grid 5x5
<1 move (0,0) (0,1)
>2 connect (0,), (0,1)
<2 move (5,0), (5,1)
1> connect (5,0), (5,1)
...
<1 move (3,2), (3,3) # this move makes a box and wins
>2 connect (3,2), (3,3)
>2 conceed
>> Player 1 wins, total .. out of ..




From cpepperrell@hotmail.com  Sun Jun  2 08:43:53 2002
From: cpepperrell@hotmail.com (christopher pepperrell)
Date: Sun, 02 Jun 2002 07:43:53 +0000
Subject: [Tutor] Im just starting
Message-ID: <F10csQMpK5KBpQvYnhT0000e914@hotmail.com>

Hi All!
       I am new to this and have just downloaded "Python" can anyone give me 
advice as to the best online Tutor to start with.

                 Regards Chris


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




From dyoo@hkn.eecs.berkeley.edu  Sun Jun  2 08:51:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 00:51:03 -0700 (PDT)
Subject: [Tutor] Im just starting
In-Reply-To: <F10csQMpK5KBpQvYnhT0000e914@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206020047010.6637-100000@hkn.eecs.berkeley.edu>


On Sun, 2 Jun 2002, christopher pepperrell wrote:

>        I am new to this and have just downloaded "Python" can anyone
> give me advice as to the best online Tutor to start with.

Hi Chris, welcome aboard!


Check out the "Python for Beginners" page --- it has a bunch of links to
online tutorials:

    http://www.python.org/doc/Newbies.html

I'm partial to "Learn to Program Using Python", but that's just because
I'm trying to make Alan Gauld blush (he's one of the Tutors here too).
But all of the tutorials there are really good.


And if you're looking for online Tutors of the human kind, you've come to
the right place.  Feel free to ask questions here on tutor@python.org, and
we'll be happy to talk with you.




From virketis@post.harvard.edu  Sun Jun  2 16:24:20 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Sun, 2 Jun 2002 11:24:20 -0400
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu>
Message-ID: <200206021524.g52FOM532726@smtp3.fas.harvard.edu>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Reading through Danny's code, I found a frequently used=
 keyword &quot;assert&quot;, like so:<br></div>
<div>&nbsp;</div>
<div>assert 2 &lt;=3D self.width and 2 &lt;=3D=
 self.height,\<br></div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; &quot;Game can't be played on this=
 board's dimension.&quot;<br></div>
<div>&nbsp;</div>
<div>I've never seen if before, so I checked the Reference, and=
 found a description here: <a=
 href=3D"http://www.python.org/doc/current/ref/assert.html">http://=
www.python.org/doc/current/ref/assert.html</a>. However, the=
 syntax given there is different:<br></div>
<div>&nbsp;</div>
<div>if __debug__:<br></div>
<div>&nbsp;&nbsp; if not expression: raise=
 AssertionError<br></div>
<div><br>
Also, the keyword itself is not really mentioned. So, my question=
 is this: what does &quot;assert&quot; do, and where can I find=
 out more about its use the way Danny employs it?<br></div>
<div>&nbsp;</div>
<div>Cheers, <br></div>
<div>&nbsp;</div>
<div>Pijus<br>
<br></div>
<div>-- <br></div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann<br></div>
</body></html>




From wolf_binary@hotmail.com  Sun Jun  2 16:58:07 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Sun, 2 Jun 2002 10:58:07 -0500
Subject: [Tutor] inherince and dependancy
Message-ID: <DAV74arcR4ZDgC81Tbd0000834c@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C20A24.60D70580
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

I have a few questions listed here:

1.)  If your have classes inherit from mulitple other classes doesn't =
that build dependency in your program? =20

2.)  Doesn't it also make reusability of code more difficult? =20

3.)  If you have multiple inheritance doesn't it make changeability in =
the code easier?  You don't have to make changes in multiple places then =
right?

Thanks for your help,
Cameron Stoner



------=_NextPart_000_0009_01C20A24.60D70580
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a few questions listed =
here:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1.)&nbsp; If your have classes inherit =
from=20
mulitple other classes doesn't that build dependency in your =
program?&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2.)&nbsp; Doesn't it also make =
reusability of code=20
more difficult?&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>3.)&nbsp; If you have multiple =
inheritance doesn't=20
it make changeability in the code easier?&nbsp; You don't have to make =
changes=20
in multiple places then right?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for your help,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron Stoner</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0009_01C20A24.60D70580--



From kalle@lysator.liu.se  Sun Jun  2 17:27:59 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun, 2 Jun 2002 18:27:59 +0200
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <200206021524.g52FOM532726@smtp3.fas.harvard.edu>
References: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu> <200206021524.g52FOM532726@smtp3.fas.harvard.edu>
Message-ID: <20020602162759.GA972@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Pijus Virketis]
> Reading through Danny's code, I found a frequently used keyword
> "assert", like so:
>  
> assert 2 <= self.width and 2 <= self.height,\
>                "Game can't be played on this board's dimension."
>  
> I've never seen if before, so I checked the Reference, and found a
> description here:
> http://www.python.org/doc/current/ref/assert.html. However, the
> syntax given there is different:
>  
> if __debug__:
>    if not expression: raise AssertionError

This is the eqivalent replacement syntax for

assert expression

> Also, the keyword itself is not really mentioned. So, my question is
> this: what does "assert" do, and where can I find out more about its
> use the way Danny employs it?

The assert statement evaluates an expression, and if the result is
false (0, None, [], () or "", for example) raises an AssertionError.
This only happens if the built-in variable __debug__ is true.

Thus:

assert a == b

and 

if __debug__:
    if not a == b:
        raise AssertionError

do the same thing.

__debug__ is always true if you haven't started python with the -O
option.  For example:

: kalle@chloe [~]$ ; python -O -c "assert 0; print 'Hi'"
Hi
: kalle@chloe [~]$ ; python -c "assert 0; print 'Hi'"
Traceback (most recent call last):
  File "<string>", line 1, in ?
AssertionError

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE8+keJdNeA1787sd0RApPXAKDIMTMxwawwq/nmnxS5kQikVcy97ACgqJrh
+e8UgNtFiAQwG9K99dw3nWc=
=kybv
-----END PGP SIGNATURE-----



From kalle@lysator.liu.se  Sun Jun  2 17:45:42 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun, 2 Jun 2002 18:45:42 +0200
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <20020602162759.GA972@i92.ryd.student.liu.se>
References: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu> <200206021524.g52FOM532726@smtp3.fas.harvard.edu> <20020602162759.GA972@i92.ryd.student.liu.se>
Message-ID: <20020602164542.GB972@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[I wrote about assert statements]
> __debug__ is always true if you haven't started python with the -O
> option.  For example:
> 
> : kalle@chloe [~]$ ; python -O -c "assert 0; print 'Hi'"
> Hi
> : kalle@chloe [~]$ ; python -c "assert 0; print 'Hi'"
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
> AssertionError

Note, though:

: kalle@chloe [~]$ ; python -c "__debug__ = 0; assert 0; print 'Hi'"
<string>:0: SyntaxWarning: can not assign to __debug__
Hi
: kalle@chloe [~]$ ; python -V
Python 2.1.3

That is, __debug__ can be assigned to in Python 2.1.3 (and earlier),
but it will raise a SyntaxWarning (in 2.1.x).

: kalle@chloe [~]$ ; python2.2 -c "__debug__ = 0; assert 0; print 'Hi'"
  File "<string>", line 1
SyntaxError: can not assign to __debug__
: kalle@chloe [~]$ ; python2.2 -V
Python 2.2.1

In Python 2.2 it is no longer possible to assign to __debug__.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE8+kuzdNeA1787sd0RAmpoAJ9dm8Ig+rNHkSisVxcBaIlAqAwkFQCfd/01
Q/jm/jAdVPccrw4+Eq1EdNc=
=WxjD
-----END PGP SIGNATURE-----



From alex@gabuzomeu.net  Sun Jun  2 18:05:54 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sun, 02 Jun 2002 19:05:54 +0200
Subject: assert (was "[Tutor] Dots-And-Boxes")
In-Reply-To: <20020602160004.8543.12057.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020602185246.00b78b70@pop3.norton.antivirus>

Hi Pijus,


At 12:00 02/06/2002 -0400, you wrote:
>From: Pijus Virketis <virketis@fas.harvard.edu>
>Date: Sun, 2 Jun 2002 11:24:20 -0400
>Subject: Re: [Tutor] Dots-And-Boxes

>Reading through Danny's code, I found a frequently used keyword "assert"

>Also, the keyword itself is not really mentioned. So, my question is this: 
>what does "assert" do, and where can I find out more about its use the way 
>Danny employs it?

Here is a short description:

"""There is now an assert statement: ``assert <condition>'' or ``assert 
<condition>, <errormessage>''. It raises AssertionError if the condition 
evaluates to false.  The default error message is empty; the source text of 
the assertion statement is printed as part of the traceback."""

Source: http://www.python.org/1.5/whatsnew.html

You can use "assert" to test a condition in a program. With "assert", you 
don't need to include "if" tests when debugging. Example:

 >>> toto = 2
 >>> assert toto > 1, "Wrong value"

Nothing happens, i.e. assertion is true.

 >>> assert toto < 1, "Wrong value"
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AssertionError: Wrong value

Here the test failed, so you get a traceback.

I remember dimly assertion testing can be switched off for speed (with a 
command line flag, I think).


Cheers.

Alexandre




From phinsxiii@knology.net  Sun Jun  2 18:10:13 2002
From: phinsxiii@knology.net (SA)
Date: Sun, 02 Jun 2002 12:10:13 -0500
Subject: [Tutor] Text to HTML question.
Message-ID: <B91FBBA5.5A28%phinsxiii@knology.net>

Hi Everyone-

    I have a couple of questions for ya. Remember I'm new to Python and am
still learning:

1. I have a bunch of text files. I have a python script to generate html. I
would like to substitute the body of the text files in between <body></body>
of the html file. I think I can get this part. The trouble I'm having is
formatting the text body into html. For instance for every "\n" in the text
body I need to substitute <BR> before placing it into the html file body
section. And for every "\n\n" I wish to substitute <P>. I suppose I nead to
use regexp, but how do you call the re module and search/sub these patterns?

2. I'm sure this is probably a problem that has been solved before, so does
anyone know of a module to do this and how do I use it to accomplish the
goal?

Thanks in advance for your help. I'm just now starting to get the whole
class thing in Python.

SA




From haroldmerrill@yahoo.com  Mon Jun  3 00:02:15 2002
From: haroldmerrill@yahoo.com (Harold Merrill)
Date: Sun, 2 Jun 2002 16:02:15 -0700 (PDT)
Subject: [Tutor] Extension
Message-ID: <20020602230215.11217.qmail@web20002.mail.yahoo.com>

Can you write Python in WordPad?  What is the
extension (ex. HTML is *.htm or *.html)?

Thanks,

Harold

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 00:53:46 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 16:53:46 -0700 (PDT)
Subject: [Tutor] Extension
In-Reply-To: <20020602230215.11217.qmail@web20002.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206021647240.23329-100000@hkn.eecs.berkeley.edu>


On Sun, 2 Jun 2002, Harold Merrill wrote:

> Can you write Python in WordPad?

Hi Harold,

It would be technically possible, but not too fun, since WordPad will try
to treat the Python source as if it were a document for humans --- it
would get in the way a lot.  Notepad would be a better program to edit
Python, since it wouldn't interfere as much, but there are actually better
text editors you can use.

If you install Python, it automatically comes with a text editor called
IDLE, and IDLE's pretty good.  I have a small tutorial on how to start
playing with it here:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro



>  What is the extension (ex. HTML is *.htm or *.html)?

Python programs often have the extension '.py'.


If you have more questions, please feel free to ask.  Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 01:02:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 17:02:00 -0700 (PDT)
Subject: [Tutor] Text to HTML question.  [string.replace()]
In-Reply-To: <B91FBBA5.5A28%phinsxiii@knology.net>
Message-ID: <Pine.LNX.4.44.0206021653520.23329-100000@hkn.eecs.berkeley.edu>


On Sun, 2 Jun 2002, SA wrote:

>     I have a couple of questions for ya. Remember I'm new to Python and
> am still learning:

No problem!  Let's take a look at your question.


> 1. I have a bunch of text files. I have a python script to generate
> html. I would like to substitute the body of the text files in between
> <body></body> of the html file. I think I can get this part. The trouble
> I'm having is formatting the text body into html. For instance for every
> "\n" in the text body I need to substitute <BR> before placing it into
> the html file body section. And for every "\n\n" I wish to substitute
> <P>. I suppose I nead to use regexp, but how do you call the re module
> and search/sub these patterns?

For text substitution like this, we might be able to get away with just
using the 'replace()' method of strings.  Here's an example of what I
mean:

###
>>> story = """Gully Foyle is my name
... And Terra is my nation
... Deep space is my dwelling place
... And death's my destination."""
>>> new_story = story.replace("And death's", "The stars")
>>> print story
Gully Foyle is my name
And Terra is my nation
Deep space is my dwelling place
And death's my destination.
>>> print new_story
Gully Foyle is my name
And Terra is my nation
Deep space is my dwelling place
The stars my destination.
###



What comes out of replace() is a new string, where all instances of the
thing we want to replace will be substituted.  This leaves the old string
alone though.

If we want to make it look as if the string were being transformed,
in-place, we can do something like this:

###
>>> story = story.replace("And death's", "The stars")
>>> print story
Gully Foyle is my name
And Terra is my nation
Deep space is my dwelling place
The stars my destination.
###

and now 'story' contains the modified story.

You can use string.replace() to solve your text->HTML problem.  Just make
sure to convert all the "\n\n" substrings first --- if you convert all
single '\n' characters first, that wipes out the empty lines!  *grin* So
be careful about the order.


Good luck!




From glingl@aon.at  Mon Jun  3 01:50:06 2002
From: glingl@aon.at (Gregor Lingl)
Date: Mon, 3 Jun 2002 02:50:06 +0200
Subject: [Tutor] Dots-And-Boxes
References: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu>
Message-ID: <001901c20a98$9abfc100$1615a8c0@mega>

This is a multi-part message in MIME format.

------=_NextPart_000_0016_01C20AA9.5E03E6E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi!

Until now I didn't know "The Dots and Boxes" Game, but Dannies
program made me interested in it.

So I wrote the beginning of a gui version. I tried hard to use
Dannies code as is - so the gui code is (nearly) completely
separated from the game machinery. I consider this a proof for
the exceptionally good design of Dannies program (imho).

O.k., maybe my extension of the program still needs some more
buttons or textfields or so, but perhaps it could be a starting
point.

Critical remarks are strongly welcome.
I'm especially interested in a comparison with an implementation
using Pygame - this is what Danny has in mind to do?

Making the computer play the game is still another point ...

Gregor

P.S.:  There is one point, which is not completely clear to me:
Danny's algorithm always assigns only one square to the player
who did the last move, even if his draw completes two squares,
So in the end the sum of the points may be less than (w-1)*(h-1).
Is this according to the rules of the game?



--------------   here follows the code, which is also attached:


"""Graphic user interface to Danny Yoo's 'dots and boxes' -program.
I tried to avoid changes to this program as far as possible.
So there remain the following changes:

Line  222: Return statement in play() now returns the
           square_corner instead of 1 (this was the only
           necessary one (in m opinion)

Line  255/256: head of for-loop --- this was the easiest way
           to accomodate text-output to graphical one.
           ( Bad design decision for the graphics display,
             may be reverted if there is time ...)

Lines 305-318, 332, 333: A somewhat safer input method for
           more convenient testing

Lines 354ff: Incorporate graphics mode into __main__()
"""

from Tkinter  import *
from Canvas import Rectangle

def cartesian( v1, v2 ):
    """ Helper function
    returns cartesian product of the two
    'sets' v1, v2"""
    return tuple([(x,y) for x in v1 for y in v2])

def right(x):
    """Helper function: argument x must be a dot.
    Returns dot right of x."""
    return (x[0]+1,x[1])

def upper(x):
    """Helper function: argument x must be a dot.
    Returns dot above (actually below) x."""
    return (x[0], x[1]+1)


class GameGUI:
    def __init__(self, board):
        """Initializes graphic display of a rectangular gameboard."""
        # Properties of gameboard
        dw = self.dotwidth = 6
        sw = self.squarewidth = 60
        sk = self.skip = 4
        fw = self.fieldwidth = dw + sw + 2*sk
        ins = self.inset = sw/2
        self.barcolors = ['red','blue']
        self.squarecolors = ['orange', 'lightblue']

        # Construct Canvas
        self.board = board
        width, height = board.width, board.height
        # compute size of canvas:
        w = width * fw
        h = height * fw
        self.root = Tk()
        cv = self.cv = Canvas(self.root, width=w, height=h, bg='white')
        cv.bind('<Button-1>', self._callback)
        cv.pack()

        # Put geometrical objects - dots, bars and squares - on canvas
        self.bars = {}
        self.squares = {}
        for dot in cartesian(range(width), range(height)):
            # dots. Never used again
            Rectangle( cv, ins+dot[0]*fw,      ins+dot[1]*fw,
                           ins+dot[0]*fw + dw, ins+dot[1]*fw + dw,
                       fill='black', outline='' )
            # horizontal bars
            if dot[0] < width - 1:
                x0 = ins+dot[0]*fw+dw+sk
                y0 = ins+dot[1]*fw
                self.bars[(dot,right(dot))] =\

Rectangle(cv,x0,y0,x0+sw,y0+dw,fill='lightgray',outline='')
            # vertical bars
            if dot[1] < height - 1:
                x0 = ins+dot[0]*fw
                y0 = ins+dot[1]*fw + dw + sk
                self.bars[(dot,upper(dot))] =\

Rectangle(cv,x0,y0,x0+dw,y0+sw,fill='lightgray',outline='')
            # squares
            if (dot[0] < width - 1) and (dot[1] < height - 1):
                x0 =ins+dot[0]*fw + dw + sk
                y0 =ins+dot[1]*fw + dw + sk
                self.squares[dot] =\

Rectangle(cv,x0,y0,x0+sw,y0+sw,fill='lightyellow',outline='')
        cv.update()
        self.root.mainloop()

    def _coord(self,x):
        """returns pixel-coordinate corresponding to
        a dot-coordinate x"""
        return self.inset + self.dotwidth/2 + self.fieldwidth*x

    def _find_bar(self,event):
        """returns bar next to mouse-position when clicked,
        if applicable, otherwise None"""
        ex, ey = event.x, event.y
        for bar in self.bars:
            ((x1,y1),(x2,y2))=bar
            mx, my = (self._coord(x1)+self._coord(x2))/2,
(self._coord(y1)+self._coord(y2))/2
            if abs(ex-mx)+abs(ey-my) < self.squarewidth/2:
                return bar

    def _callback(self, event):
        """Action following a mouse-click"""
        hit = self._find_bar(event)
        board = self.board
        print "Hit:", hit
        if not hit or board.isGameOver() or board.board.has_key(hit):
            return
        # Do a move
        player = board.getPlayer()
        print "Turn %d (Player %s)" % (board.turn, player)
        self.bars[hit]['fill']=self.barcolors[player]
        target = board.play(hit)
        print "Target:", target
        if target:
            print "Square completed.", board.squares[target]
            self.squares[target]['fill'] = self.squarecolors[player]
            board.scores[player] += 1
        board.turn = board.turn + 1
        print "\n"
        if board.isGameOver():
            print "Game over!"
            print "Final board position:"
            print board
            print
            print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \
                                tuple(board.scores)

def _gtest(width, height):
    """A small driver to make sure that the board works.  It's not
    safe to use this test function in production, because it uses
    input()."""
    print "Running _gtest... "
    board = GameBoard(width, height)
    board.turn = 1
    board.scores = [0, 0]
    gui = GameGUI(board)


##### Danny Yoo's board.py  #########################################

import types

class GameBoard:
    def __init__(self, width=5, height=5):
        """Initializes a rectangular gameboard."""
        self.width, self.height = width, height
        assert 2 <= self.width and 2 <= self.height,\
               "Game can't be played on this board's dimension."
        self.board = {}
        self.squares = {}
        self.player = 0


    def isGameOver(self):
        """Returns true if no more moves can be made.

        The maximum number of moves is equal to the number of possible
        lines between adjacent dots.  I'm calculating this to be
        $2*w*h - h - w$; I think that's right.  *grin*
        """
        w, h = self.width, self.height
        return len(self.board.keys()) == 2*w*h - h - w



    def _isSquareMove(self, move):
        """Returns a true value if a particular move will create a
        square.  In particular, returns the lower left corner of the
        created square."""
        b = self.board
        mmove = self._makeMove       ## just to make typing easier
        ((x1, y1), (x2, y2)) = move
        if self._isHorizontal(move):
            for j in [-1, 1]:
                if (b.has_key(mmove((x1, y1), (x1, y1-j)))
                    and b.has_key(mmove((x1, y1-j), (x1+1, y1-j)))
                    and b.has_key(mmove((x1+1, y1-j), (x2, y2)))):
                    return min([(x1, y1), (x1, y1-j),
                                (x1+1, y1-j), (x2, y2)])
        else:
            for j in [-1, 1]:
                if (b.has_key(mmove((x1, y1), (x1-j, y1)))
                    and b.has_key(mmove((x1-j, y1), (x1-j, y1+1)))
                    and b.has_key(mmove((x1-j, y1+1), (x2, y2)))):
                    return min([(x1, y1), (x1-j, y1),
                                (x1-j, y1+1), (x2, y2)])
        return None



    def _isHorizontal(self, move):
        "Return true if the move is in horizontal orientation."
        return abs(move[0][0] - move[1][0]) == 1


    def _isVertical(self, move):
        "Return true if the move is in vertical orientation."
        return not self.isHorizontal(self, move)


    def play(self, move):
        """Place a particular move on the board.  If any wackiness
        occurs, raise an AssertionError."""
        assert (self._isGoodCoord(move[0]) and
                self._isGoodCoord(move[1])),\
                "Bad coordinates, out of bounds of the board."
        move = self._makeMove(move[0], move[1])
        assert(not self.board.has_key(move)),\
                   "Bad move, line already occupied."
        self.board[move] = self.player
        ## Check if a square is completed.
        square_corner = self._isSquareMove(move)
        if square_corner:
            self.squares[square_corner] = self.player
            # return 1
            return square_corner  # CHANGED to get information which
                                  # square to colour
        else:
            self._switchPlayer()
            return 0


    def _switchPlayer(self):
        self.player = (self.player + 1) % 2


    def getPlayer(self): return self.player


    def getSquares(self):
        """Returns a dictionary of squares captured.  Returns
        a dict of lower left corner keys marked with the
        player who captured them."""
        return self.squares


    def __str__(self):
        """Return a nice string representation of the board."""
        buffer = []

        ## do the top line
        for i in range(self.width-1):
            if self.board.has_key(((i, self.height-1), (i+1,
self.height-1))):
                buffer.append("+--")
            else: buffer.append("+  ")
        buffer.append("+\n")

        ## and now do alternating vertical/horizontal passes
#       for j in range(self.height-2, -1, -1):  #  CHANGED  for
corresponence
        for j in range(self.height-1):          #  with graphical display
            ## vertical:
            for i in range(self.width):
                if self.board.has_key(((i, j), (i, j+1))):
                    buffer.append("|")
                else:
                    buffer.append(" ")
                if self.squares.has_key((i, j)):
                    buffer.append("%s " % self.squares[i,j])
                else:
                    buffer.append("  ")
            buffer.append("\n")

            ## horizontal
            for i in range(self.width-1):
                if self.board.has_key(((i, j), (i+1, j))):
                    buffer.append("+--")
                else: buffer.append("+  ")
            buffer.append("+\n")

        return ''.join(buffer)



    def _makeMove(self, coord1, coord2):
        """Return a new "move", and ensure it's in canonical form.
        (That is, force it so that it's an ordered tuple of tuples.)
        """
        ## TODO: do the Flyweight thing here to reduce object creation
        xdelta, ydelta = coord2[0] - coord1[0], coord2[1] - coord1[1]
        assert ((abs(xdelta) == 1 and abs(ydelta) == 0) or
                (abs(xdelta) == 0 and abs(ydelta) == 1)),\
                "Bad coordinates, not adjacent points."
        if coord1 < coord2:
            return (coord1, coord2)
        else:
            return (tuple(coord2), tuple(coord1))


    def _isGoodCoord(self, coord):
        """Returns true if the given coordinate is good.

        A coordinate is "good" if it's within the boundaries of the
        game board, and if the coordinates are integers."""
        return (0 <= coord[0] < self.width
                and 0 <= coord[1] < self.height
                and isinstance(coord[0], types.IntType)
                and isinstance(coord[1], types.IntType))

    def getMove(self):    # <=== NEW NEW NEW
        """Found this little bit of error-checking useful
        for testing, because I tend to mistype everything
        rather often.
        Moreover now it's more safe"""
        done = 0
        while not done:
            try:
                x1, y1, sep, x2, y2 = raw_input("Move?").split()
                move = ((int(x1),int(y1)),(int(x2),int(y2)))
                done = 1
            except:
                pass
        return move


def _test(width, height):
    """A small driver to make sure that the board works.  It's not
    safe to use this test function in production, because it uses
    input()."""
    board = GameBoard(width, height)
    turn = 1
    scores = [0, 0]
    while not board.isGameOver():
        player = board.getPlayer()
        print "Turn %d (Player %s)" % (turn, player)
        print board
        # move = input("Move? ")
        move = board.getMove()         # <==  CHANGED !!!
        if board.play(move):
            print "Square completed."
            scores[player] += 1
        turn = turn + 1
        print "\n"
    print "Game over!"
    print "Final board position:"
    print board
    print
    print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \
          (scores[0], scores[1])


if __name__ == "__main__":
    """If we're provided arguments,
    look if first one equals 't', in which case
    textmode only is invoked.
    try using rest of the arguments as the
    width/height of the game board."""
    import sys
    if len(sys.argv[1:]) > 0 and sys.argv[1] == 't':
        # textmode
        if len(sys.argv[1:]) == 3:
            _test(int(sys.argv[2]), int(sys.argv[3]))
        elif len(sys.argv[1:]) == 2:
            _test(int(sys.argv[2]), int(sys.argv[2]))
        else:
            _test(5, 5)
    else:
        # grachics mode
        if len(sys.argv[1:]) == 2:
            _gtest(int(sys.argv[1]), int(sys.argv[2]))
        elif len(sys.argv[1:]) == 1:
            _gtest(int(sys.argv[1]), int(sys.argv[1]))
        else:
            _gtest(5, 5)



------=_NextPart_000_0016_01C20AA9.5E03E6E0
Content-Type: text/plain;
	name="gboard.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="gboard.py"

"""Graphic user interface to Danny Yoo's 'dots and boxes' -program.
I tried to avoid changes to this program as far as possible.
So there remain the following changes:

Line  222: Return statement in play() now returns the
           square_corner instead of 1 (this was the only
           necessary one (in m opinion)

Line  255/256: head of for-loop --- this was the easiest way
           to accomodate text-output to graphical one.
           ( Bad design decision for the graphics display,
             may be reverted if there is time ...)

Lines 305-318, 332, 333: A somewhat safer input method for
           more convenient testing

Lines 354ff: Incorporate graphics mode into __main__()
"""

from Tkinter  import *
from Canvas import Rectangle

def cartesian( v1, v2 ):
    """ Helper function
    returns cartesian product of the two
    'sets' v1, v2"""
    return tuple([(x,y) for x in v1 for y in v2])

def right(x):
    """Helper function: argument x must be a dot.
    Returns dot right of x."""
    return (x[0]+1,x[1])

def upper(x):
    """Helper function: argument x must be a dot.
    Returns dot above (actually below) x."""
    return (x[0], x[1]+1)


class GameGUI:
    def __init__(self, board):
        """Initializes graphic display of a rectangular gameboard."""
        # Properties of gameboard
        dw =3D self.dotwidth =3D 6
        sw =3D self.squarewidth =3D 60
        sk =3D self.skip =3D 4
        fw =3D self.fieldwidth =3D dw + sw + 2*sk
        ins =3D self.inset =3D sw/2
        self.barcolors =3D ['red','blue']
        self.squarecolors =3D ['orange', 'lightblue']

        # Construct Canvas        =20
        self.board =3D board
        width, height =3D board.width, board.height
        # compute size of canvas:
        w =3D width * fw=20
        h =3D height * fw=20
        self.root =3D Tk()
        cv =3D self.cv =3D Canvas(self.root, width=3Dw, height=3Dh, =
bg=3D'white')
        cv.bind('<Button-1>', self._callback)
        cv.pack()

        # Put geometrical objects - dots, bars and squares - on canvas
        self.bars =3D {}
        self.squares =3D {}
        for dot in cartesian(range(width), range(height)):
            # dots. Never used again
            Rectangle( cv, ins+dot[0]*fw,      ins+dot[1]*fw,
                           ins+dot[0]*fw + dw, ins+dot[1]*fw + dw,
                       fill=3D'black', outline=3D'' )
            # horizontal bars
            if dot[0] < width - 1:
                x0 =3D ins+dot[0]*fw+dw+sk
                y0 =3D ins+dot[1]*fw
                self.bars[(dot,right(dot))] =3D\
                    =
Rectangle(cv,x0,y0,x0+sw,y0+dw,fill=3D'lightgray',outline=3D'')
            # vertical bars
            if dot[1] < height - 1:
                x0 =3D ins+dot[0]*fw
                y0 =3D ins+dot[1]*fw + dw + sk
                self.bars[(dot,upper(dot))] =3D\
                    =
Rectangle(cv,x0,y0,x0+dw,y0+sw,fill=3D'lightgray',outline=3D'')
            # squares
            if (dot[0] < width - 1) and (dot[1] < height - 1):
                x0 =3Dins+dot[0]*fw + dw + sk
                y0 =3Dins+dot[1]*fw + dw + sk=20
                self.squares[dot] =3D\
                    =
Rectangle(cv,x0,y0,x0+sw,y0+sw,fill=3D'lightyellow',outline=3D'')
        cv.update()
        self.root.mainloop()       =20

    def _coord(self,x):
        """returns pixel-coordinate corresponding to
        a dot-coordinate x"""
        return self.inset + self.dotwidth/2 + self.fieldwidth*x

    def _find_bar(self,event):
        """returns bar next to mouse-position when clicked,
        if applicable, otherwise None"""
        ex, ey =3D event.x, event.y
        for bar in self.bars:
            ((x1,y1),(x2,y2))=3Dbar
            mx, my =3D (self._coord(x1)+self._coord(x2))/2, =
(self._coord(y1)+self._coord(y2))/2
            if abs(ex-mx)+abs(ey-my) < self.squarewidth/2:
                return bar
       =20
    def _callback(self, event):
        """Action following a mouse-click"""
        hit =3D self._find_bar(event)
        board =3D self.board
        print "Hit:", hit
        if not hit or board.isGameOver() or board.board.has_key(hit):
            return
        # Do a move
        player =3D board.getPlayer()
        print "Turn %d (Player %s)" % (board.turn, player)
        self.bars[hit]['fill']=3Dself.barcolors[player]
        target =3D board.play(hit)
        print "Target:", target
        if target:
            print "Square completed.", board.squares[target]
            self.squares[target]['fill'] =3D self.squarecolors[player]
            board.scores[player] +=3D 1
        board.turn =3D board.turn + 1
        print "\n"
        if board.isGameOver():
            print "Game over!"
            print "Final board position:"
            print board
            print
            print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \
                                tuple(board.scores)

def _gtest(width, height):=0A=
    """A small driver to make sure that the board works.  It's not=0A=
    safe to use this test function in production, because it uses=0A=
    input()."""
    print "Running _gtest... "=0A=
    board =3D GameBoard(width, height)=0A=
    board.turn =3D 1=0A=
    board.scores =3D [0, 0]
    gui =3D GameGUI(board)


##### Danny Yoo's board.py  #########################################

import types=0A=
=0A=
class GameBoard:=0A=
    def __init__(self, width=3D5, height=3D5):=0A=
        """Initializes a rectangular gameboard."""=0A=
        self.width, self.height =3D width, height=0A=
        assert 2 <=3D self.width and 2 <=3D self.height,\=0A=
               "Game can't be played on this board's dimension."=0A=
        self.board =3D {}=0A=
        self.squares =3D {}=0A=
        self.player =3D 0=0A=
=0A=
=0A=
    def isGameOver(self):=0A=
        """Returns true if no more moves can be made.=0A=
=0A=
        The maximum number of moves is equal to the number of possible=0A=
        lines between adjacent dots.  I'm calculating this to be=0A=
        $2*w*h - h - w$; I think that's right.  *grin*=0A=
        """=0A=
        w, h =3D self.width, self.height=0A=
        return len(self.board.keys()) =3D=3D 2*w*h - h - w=0A=
=0A=
=0A=
=0A=
    def _isSquareMove(self, move):=0A=
        """Returns a true value if a particular move will create a=0A=
        square.  In particular, returns the lower left corner of the=0A=
        created square."""=0A=
        b =3D self.board=0A=
        mmove =3D self._makeMove       ## just to make typing easier=0A=
        ((x1, y1), (x2, y2)) =3D move=0A=
        if self._isHorizontal(move):=0A=
            for j in [-1, 1]:=0A=
                if (b.has_key(mmove((x1, y1), (x1, y1-j)))=0A=
                    and b.has_key(mmove((x1, y1-j), (x1+1, y1-j)))=0A=
                    and b.has_key(mmove((x1+1, y1-j), (x2, y2)))):=0A=
                    return min([(x1, y1), (x1, y1-j),=0A=
                                (x1+1, y1-j), (x2, y2)])=0A=
        else:=0A=
            for j in [-1, 1]:=0A=
                if (b.has_key(mmove((x1, y1), (x1-j, y1)))=0A=
                    and b.has_key(mmove((x1-j, y1), (x1-j, y1+1)))=0A=
                    and b.has_key(mmove((x1-j, y1+1), (x2, y2)))):=0A=
                    return min([(x1, y1), (x1-j, y1),=0A=
                                (x1-j, y1+1), (x2, y2)])=0A=
        return None=0A=
=0A=
=0A=
=0A=
    def _isHorizontal(self, move):=0A=
        "Return true if the move is in horizontal orientation."=0A=
        return abs(move[0][0] - move[1][0]) =3D=3D 1=0A=
=0A=
=0A=
    def _isVertical(self, move):=0A=
        "Return true if the move is in vertical orientation."=0A=
        return not self.isHorizontal(self, move)=0A=
=0A=
=0A=
    def play(self, move):=0A=
        """Place a particular move on the board.  If any wackiness=0A=
        occurs, raise an AssertionError."""=0A=
        assert (self._isGoodCoord(move[0]) and=0A=
                self._isGoodCoord(move[1])),\=0A=
                "Bad coordinates, out of bounds of the board."=0A=
        move =3D self._makeMove(move[0], move[1])=0A=
        assert(not self.board.has_key(move)),\=0A=
                   "Bad move, line already occupied."=0A=
        self.board[move] =3D self.player=0A=
        ## Check if a square is completed.=0A=
        square_corner =3D self._isSquareMove(move)=0A=
        if square_corner:=0A=
            self.squares[square_corner] =3D self.player=0A=
            # return 1
            return square_corner  # CHANGED to get information which
                                  # square to colour=0A=
        else:=0A=
            self._switchPlayer()=0A=
            return 0=0A=
=0A=
=0A=
    def _switchPlayer(self):=0A=
        self.player =3D (self.player + 1) % 2=0A=
=0A=
=0A=
    def getPlayer(self): return self.player=0A=
=0A=
=0A=
    def getSquares(self):=0A=
        """Returns a dictionary of squares captured.  Returns=0A=
        a dict of lower left corner keys marked with the=0A=
        player who captured them."""=0A=
        return self.squares=0A=
=0A=
=0A=
    def __str__(self):=0A=
        """Return a nice string representation of the board."""=0A=
        buffer =3D []=0A=
        =0A=
        ## do the top line=0A=
        for i in range(self.width-1):=0A=
            if self.board.has_key(((i, self.height-1), (i+1, =
self.height-1))):=0A=
                buffer.append("+--")=0A=
            else: buffer.append("+  ")=0A=
        buffer.append("+\n")=0A=
=0A=
        ## and now do alternating vertical/horizontal passes=0A=
#       for j in range(self.height-2, -1, -1):  #  CHANGED  for =
corresponence =0A=
        for j in range(self.height-1):          #  with graphical display=0A=
            ## vertical:=0A=
            for i in range(self.width):=0A=
                if self.board.has_key(((i, j), (i, j+1))):=0A=
                    buffer.append("|")=0A=
                else:=0A=
                    buffer.append(" ")=0A=
                if self.squares.has_key((i, j)):=0A=
                    buffer.append("%s " % self.squares[i,j])=0A=
                else:=0A=
                    buffer.append("  ")=0A=
            buffer.append("\n")=0A=
=0A=
            ## horizontal=0A=
            for i in range(self.width-1):=0A=
                if self.board.has_key(((i, j), (i+1, j))):=0A=
                    buffer.append("+--")=0A=
                else: buffer.append("+  ")=0A=
            buffer.append("+\n")=0A=
=0A=
        return ''.join(buffer)=0A=
=0A=
=0A=
=0A=
    def _makeMove(self, coord1, coord2):=0A=
        """Return a new "move", and ensure it's in canonical form.=0A=
        (That is, force it so that it's an ordered tuple of tuples.)=0A=
        """=0A=
        ## TODO: do the Flyweight thing here to reduce object creation=0A=
        xdelta, ydelta =3D coord2[0] - coord1[0], coord2[1] - coord1[1]=0A=
        assert ((abs(xdelta) =3D=3D 1 and abs(ydelta) =3D=3D 0) or=0A=
                (abs(xdelta) =3D=3D 0 and abs(ydelta) =3D=3D 1)),\=0A=
                "Bad coordinates, not adjacent points."=0A=
        if coord1 < coord2:=0A=
            return (coord1, coord2)=0A=
        else:=0A=
            return (tuple(coord2), tuple(coord1))=0A=
=0A=
=0A=
    def _isGoodCoord(self, coord):=0A=
        """Returns true if the given coordinate is good.=0A=
=0A=
        A coordinate is "good" if it's within the boundaries of the=0A=
        game board, and if the coordinates are integers."""=0A=
        return (0 <=3D coord[0] < self.width=0A=
                and 0 <=3D coord[1] < self.height=0A=
                and isinstance(coord[0], types.IntType)=0A=
                and isinstance(coord[1], types.IntType))=0A=

    def getMove(self):    # <=3D=3D=3D NEW NEW NEW
        """Found this little bit of error-checking useful
        for testing, because I tend to mistype everything
        rather often.
        Moreover now it's more safe"""
        done =3D 0
        while not done:
            try:
                x1, y1, sep, x2, y2 =3D raw_input("Move?").split()
                move =3D ((int(x1),int(y1)),(int(x2),int(y2)))
                done =3D 1
            except:
                pass
        return move
    =0A=
=0A=
def _test(width, height):=0A=
    """A small driver to make sure that the board works.  It's not=0A=
    safe to use this test function in production, because it uses=0A=
    input()."""=0A=
    board =3D GameBoard(width, height)=0A=
    turn =3D 1=0A=
    scores =3D [0, 0]=0A=
    while not board.isGameOver():=0A=
        player =3D board.getPlayer()=0A=
        print "Turn %d (Player %s)" % (turn, player)=0A=
        print board=0A=
        # move =3D input("Move? ")
        move =3D board.getMove()         # <=3D=3D  CHANGED !!!=0A=
        if board.play(move):=0A=
            print "Square completed."=0A=
            scores[player] +=3D 1=0A=
        turn =3D turn + 1=0A=
        print "\n"=0A=
    print "Game over!"=0A=
    print "Final board position:"=0A=
    print board=0A=
    print=0A=
    print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \=0A=
          (scores[0], scores[1])=0A=

=0A=
if __name__ =3D=3D "__main__":
    """If we're provided arguments,
    look if first one equals 't', in which case
    textmode only is invoked.
    try using rest of the arguments as the
    width/height of the game board."""
    import sys
    if len(sys.argv[1:]) > 0 and sys.argv[1] =3D=3D 't':
        # textmode
        if len(sys.argv[1:]) =3D=3D 3:
            _test(int(sys.argv[2]), int(sys.argv[3]))
        elif len(sys.argv[1:]) =3D=3D 2:
            _test(int(sys.argv[2]), int(sys.argv[2]))
        else:
            _test(5, 5)
    else:
        # grachics mode
        if len(sys.argv[1:]) =3D=3D 2:
            _gtest(int(sys.argv[1]), int(sys.argv[2]))
        elif len(sys.argv[1:]) =3D=3D 1:
            _gtest(int(sys.argv[1]), int(sys.argv[1]))
        else:
            _gtest(5, 5)


------=_NextPart_000_0016_01C20AA9.5E03E6E0--




From shalehperry@attbi.com  Mon Jun  3 02:17:20 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 02 Jun 2002 18:17:20 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <001901c20a98$9abfc100$1615a8c0@mega>
Message-ID: <XFMail.20020602181720.shalehperry@attbi.com>

> 
> P.S.:  There is one point, which is not completely clear to me:
> Danny's algorithm always assigns only one square to the player
> who did the last move, even if his draw completes two squares,
> So in the end the sum of the points may be less than (w-1)*(h-1).
> Is this according to the rules of the game?
> 

no.  If your move boxes in any number of squares you get all of them.



From glingl@aon.at  Mon Jun  3 02:28:52 2002
From: glingl@aon.at (Gregor Lingl)
Date: Mon, 3 Jun 2002 03:28:52 +0200
Subject: [Tutor] Dots-And-Boxes
References: <XFMail.20020602181720.shalehperry@attbi.com>
Message-ID: <003b01c20a9e$054b59d0$1615a8c0@mega>

So the method play() (and perhaps already
the method _isSquareMove() should better
return a list of the corners of all the
affected squares?

Can 'any number' be greater than 2? Under
which circumstances?

Gregor

----- Original Message ----- 
From: "Sean 'Shaleh' Perry" <shalehperry@attbi.com>
To: "Gregor Lingl" <glingl@aon.at>
Cc: <tutor@python.org>
Sent: Monday, June 03, 2002 3:17 AM
Subject: Re: [Tutor] Dots-And-Boxes


> 
> P.S.:  There is one point, which is not completely clear to me:
> Danny's algorithm always assigns only one square to the player
> who did the last move, even if his draw completes two squares,
> So in the end the sum of the points may be less than (w-1)*(h-1).
> Is this according to the rules of the game?
> 

no.  If your move boxes in any number of squares you get all of them.





From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 02:42:09 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 18:42:09 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <XFMail.20020602181720.shalehperry@attbi.com>
Message-ID: <Pine.LNX.4.44.0206021841190.26176-100000@hkn.eecs.berkeley.edu>


On Sun, 2 Jun 2002, Sean 'Shaleh' Perry wrote:

> > P.S.:  There is one point, which is not completely clear to me:
> > Danny's algorithm always assigns only one square to the player who did
> > the last move, even if his draw completes two squares, So in the end
> > the sum of the points may be less than (w-1)*(h-1). Is this according
> > to the rules of the game?
> >
>
> no.  If your move boxes in any number of squares you get all of them.

Yikes, that's a bug in my program then!  I completely forgot about
double-cross moves.  I'll try to fix this tonight; thanks for reminding me
about this!




From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 02:53:52 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 18:53:52 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <Pine.LNX.4.44.0206021841190.26176-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0206021847400.26176-100000@hkn.eecs.berkeley.edu>


> > > P.S.:  There is one point, which is not completely clear to me:
> > > Danny's algorithm always assigns only one square to the player who
> > > did the last move, even if his draw completes two squares, So in the
> > > end the sum of the points may be less than (w-1)*(h-1). Is this
> > > according to the rules of the game?
> > >
> >
> > no.  If your move boxes in any number of squares you get all of them.
>
> Yikes, that's a bug in my program then!  I completely forgot about
> double-cross moves.  I'll try to fix this tonight; thanks for reminding me
> about this!

Ok, fixed, I think.  I took Gregor's suggestions, and now my
_isSquareMove()  returns a list of squares instead of just one potential
square.


At most 2 squares can be created by a move, via a "double-crossed" move.
The following play shows how this can be done:

###
dyoo@coffeetable:~/dots-and-boxes$ python board.py
Turn 1 (Player 0)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

Move? (0, 0), (0, 1)


Turn 2 (Player 1)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+  +  +  +  +
|
+  +  +  +  +

Move? (0, 1), (1, 1)


Turn 3 (Player 0)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+  +  +  +
|
+  +  +  +  +

Move? (1, 1), (2, 1)


Turn 4 (Player 1)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+--+  +  +
|
+  +  +  +  +

Move? (2, 1), (2, 0)


Turn 5 (Player 0)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+--+  +  +
|     |
+  +  +  +  +

Move? (2, 0), (1, 0)


Turn 6 (Player 1)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+--+  +  +
|     |
+  +--+  +  +

Move? (1, 0), (0, 0)


Turn 7 (Player 0)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+--+  +  +
|     |
+--+--+  +  +

Move? (1, 1), (1, 0)
Square completed.


Turn 8 (Player 0)
+  +  +  +  +

+  +  +  +  +

+  +  +  +  +

+--+--+  +  +
|0 |0 |
+--+--+  +  +

###


So this should fix things properly now.  I've updated my source code, so
you can download it again:

    http://hkn.eecs.berkeley.edu/~dyoo/python/dots-and-boxes/board.py


Thanks again!




From glingl@aon.at  Mon Jun  3 03:14:19 2002
From: glingl@aon.at (Gregor Lingl)
Date: Mon, 3 Jun 2002 04:14:19 +0200
Subject: [Tutor] Dots-And-Boxes
References: <Pine.LNX.4.44.0206021847400.26176-100000@hkn.eecs.berkeley.edu>
Message-ID: <006301c20aa4$5e8f0220$1615a8c0@mega>

This is a multi-part message in MIME format.

------=_NextPart_000_0060_01C20AB5.21C0B170
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


----- Original Message ----- 
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>

Ok, fixed, I think.  I took Gregor's suggestions, and now my
_isSquareMove()  returns a list of squares instead of just one potential
square.


At most 2 squares can be created by a move, via a "double-crossed" move.
The following play shows how this can be done:

----------------

gui version accordingly fixed. see attachment
Gregor


------=_NextPart_000_0060_01C20AB5.21C0B170
Content-Type: text/plain;
	name="gboard2.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="gboard2.py"

"""Graphic user interface to Danny Yoo's 'dots and boxes' -program.
I tried to avoid changes to this program as far as possible.
So there remain the following changes:

Line  229: Return statement in play() now returns the
           square_corners instead of 1 (this was the only
           necessary one (in m opinion)

Line  258/259: head of for-loop --- this was the easiest way
           to accomodate text-output to graphical one.
           ( Bad design decision for the graphics display,
             may be reverted if there is time ...)

Lines 308-321, 335, 336: A somewhat safer input method for
           more convenient testing

Lines 357ff: Incorporate graphics mode into __main__()
"""

from Tkinter  import *
from Canvas import Rectangle

def cartesian( v1, v2 ):
    """ Helper function
    returns cartesian product of the two
    'sets' v1, v2"""
    return tuple([(x,y) for x in v1 for y in v2])

def right(x):
    """Helper function: argument x must be a dot.
    Returns dot right of x."""
    return (x[0]+1,x[1])

def upper(x):
    """Helper function: argument x must be a dot.
    Returns dot above (actually below) x."""
    return (x[0], x[1]+1)


class GameGUI:
    def __init__(self, board):
        """Initializes graphic display of a rectangular gameboard."""
        # Properties of gameboard
        dw =3D self.dotwidth =3D 6
        sw =3D self.squarewidth =3D 60
        sk =3D self.skip =3D 4
        fw =3D self.fieldwidth =3D dw + sw + 2*sk
        ins =3D self.inset =3D sw/2
        self.barcolors =3D ['red','blue']
        self.squarecolors =3D ['orange', 'lightblue']

        # Construct Canvas        =20
        self.board =3D board
        width, height =3D board.width, board.height
        # compute size of canvas:
        w =3D width * fw=20
        h =3D height * fw=20
        self.root =3D Tk()
        cv =3D self.cv =3D Canvas(self.root, width=3Dw, height=3Dh, =
bg=3D'white')
        cv.bind('<Button-1>', self._callback)
        cv.pack()

        # Put geometrical objects - dots, bars and squares - on canvas
        self.bars =3D {}
        self.squares =3D {}
        for dot in cartesian(range(width), range(height)):
            # dots. Never used again
            Rectangle( cv, ins+dot[0]*fw,      ins+dot[1]*fw,
                           ins+dot[0]*fw + dw, ins+dot[1]*fw + dw,
                       fill=3D'black', outline=3D'' )
            # horizontal bars
            if dot[0] < width - 1:
                x0 =3D ins+dot[0]*fw+dw+sk
                y0 =3D ins+dot[1]*fw
                self.bars[(dot,right(dot))] =3D\
                    =
Rectangle(cv,x0,y0,x0+sw,y0+dw,fill=3D'lightgray',outline=3D'')
            # vertical bars
            if dot[1] < height - 1:
                x0 =3D ins+dot[0]*fw
                y0 =3D ins+dot[1]*fw + dw + sk
                self.bars[(dot,upper(dot))] =3D\
                    =
Rectangle(cv,x0,y0,x0+dw,y0+sw,fill=3D'lightgray',outline=3D'')
            # squares
            if (dot[0] < width - 1) and (dot[1] < height - 1):
                x0 =3Dins+dot[0]*fw + dw + sk
                y0 =3Dins+dot[1]*fw + dw + sk=20
                self.squares[dot] =3D\
                    =
Rectangle(cv,x0,y0,x0+sw,y0+sw,fill=3D'lightyellow',outline=3D'')
        cv.update()
        self.root.mainloop()       =20

    def _coord(self,x):
        """returns pixel-coordinate corresponding to
        a dot-coordinate x"""
        return self.inset + self.dotwidth/2 + self.fieldwidth*x

    def _find_bar(self,event):
        """returns bar next to mouse-position when clicked,
        if applicable, otherwise None"""
        ex, ey =3D event.x, event.y
        for bar in self.bars:
            ((x1,y1),(x2,y2))=3Dbar
            mx, my =3D (self._coord(x1)+self._coord(x2))/2, =
(self._coord(y1)+self._coord(y2))/2
            if abs(ex-mx)+abs(ey-my) < self.squarewidth/2:
                return bar
       =20
    def _callback(self, event):
        """Action following a mouse-click"""
        hit =3D self._find_bar(event)
        board =3D self.board
        print "Hit:", hit
        if not hit or board.isGameOver() or board.board.has_key(hit):
            return
        # Do a move
        player =3D board.getPlayer()
        print "Turn %d (Player %s)" % (board.turn, player)
        self.bars[hit]['fill']=3Dself.barcolors[player]
        # Here following Danny's bug fix
        targets =3D board.play(hit)
        print "Targets:", targets
        for target in targets:
            print "Square completed.", board.squares[target]
            self.squares[target]['fill'] =3D self.squarecolors[player]
            board.scores[player] +=3D 1
        board.turn =3D board.turn + 1
        print "\n"
        if board.isGameOver():
            print "Game over!"
            print "Final board position:"
            print board
            print
            print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \
                                tuple(board.scores)

def _gtest(width, height):=0A=
    """A small driver to make sure that the board works.  It's not=0A=
    safe to use this test function in production, because it uses=0A=
    input()."""
    print "Running _gtest... "=0A=
    board =3D GameBoard(width, height)=0A=
    board.turn =3D 1=0A=
    board.scores =3D [0, 0]
    gui =3D GameGUI(board)


##### Danny Yoo's board.py  #########################################

import types=0A=
=0A=
class GameBoard:=0A=
    def __init__(self, width=3D5, height=3D5):=0A=
        """Initializes a rectangular gameboard."""=0A=
        self.width, self.height =3D width, height=0A=
        assert 2 <=3D self.width and 2 <=3D self.height,\=0A=
               "Game can't be played on this board's dimension."=0A=
        self.board =3D {}=0A=
        self.squares =3D {}=0A=
        self.player =3D 0=0A=
=0A=
=0A=
    def isGameOver(self):=0A=
        """Returns true if no more moves can be made.=0A=
=0A=
        The maximum number of moves is equal to the number of possible=0A=
        lines between adjacent dots.  I'm calculating this to be=0A=
        $2*w*h - h - w$; I think that's right.  *grin*=0A=
        """=0A=
        w, h =3D self.width, self.height=0A=
        return len(self.board.keys()) =3D=3D 2*w*h - h - w=0A=
=0A=
=0A=
=0A=
    def _isSquareMove(self, move):=0A=
        """Returns a true value if a particular move will create a=0A=
        square.  In particular, returns a list of the the lower left=0A=
        corners of the squares captured by a move.=0A=
=0A=
        (Note: I had forgotten about double crossed moves.  Gregor=0A=
        Lingl reported the bug; I'd better fix it now!  *grin*) """=0A=
        b =3D self.board=0A=
        mmove =3D self._makeMove       ## just to make typing easier=0A=
        ((x1, y1), (x2, y2)) =3D move=0A=
        captured_squares =3D []=0A=
        if self._isHorizontal(move):=0A=
            for j in [-1, 1]:=0A=
                if (b.has_key(mmove((x1, y1), (x1, y1-j)))=0A=
                    and b.has_key(mmove((x1, y1-j), (x1+1, y1-j)))=0A=
                    and b.has_key(mmove((x1+1, y1-j), (x2, y2)))):=0A=
                    captured_squares.append(min([(x1, y1), (x1, y1-j),=0A=
                                                 (x1+1, y1-j), (x2, =
y2)]))=0A=
        else:=0A=
            for j in [-1, 1]:=0A=
                if (b.has_key(mmove((x1, y1), (x1-j, y1)))=0A=
                    and b.has_key(mmove((x1-j, y1), (x1-j, y1+1)))=0A=
                    and b.has_key(mmove((x1-j, y1+1), (x2, y2)))):=0A=
                    captured_squares.append(min([(x1, y1), (x1-j, y1),=0A=
                                                 (x1-j, y1+1), (x2, =
y2)]))=0A=
        return captured_squares=0A=
=0A=
=0A=
=0A=
    def _isHorizontal(self, move):=0A=
        "Return true if the move is in horizontal orientation."=0A=
        return abs(move[0][0] - move[1][0]) =3D=3D 1=0A=
=0A=
=0A=
    def _isVertical(self, move):=0A=
        "Return true if the move is in vertical orientation."=0A=
        return not self.isHorizontal(self, move)=0A=
=0A=
=0A=
    def play(self, move):=0A=
        """Place a particular move on the board.  If any wackiness=0A=
        occurs, raise an AssertionError."""=0A=
        assert (self._isGoodCoord(move[0]) and=0A=
                self._isGoodCoord(move[1])),\=0A=
                "Bad coordinates, out of bounds of the board."=0A=
        move =3D self._makeMove(move[0], move[1])=0A=
        assert(not self.board.has_key(move)),\=0A=
                   "Bad move, line already occupied."=0A=
        self.board[move] =3D self.player=0A=
        ## Check if a square is completed.=0A=
        square_corners =3D self._isSquareMove(move)=0A=
        if square_corners:=0A=
            for corner in square_corners:=0A=
                self.squares[corner] =3D self.player=0A=
        else:=0A=
            self._switchPlayer()=0A=
        return square_corners         # <=3D=3D here also change =
necessary!!=0A=
=0A=
=0A=
    def _switchPlayer(self):=0A=
        self.player =3D (self.player + 1) % 2=0A=
=0A=
=0A=
    def getPlayer(self): return self.player=0A=
=0A=
=0A=
    def getSquares(self):=0A=
        """Returns a dictionary of squares captured.  Returns=0A=
        a dict of lower left corner keys marked with the=0A=
        player who captured them."""=0A=
        return self.squares=0A=
=0A=
=0A=
    def __str__(self):=0A=
        """Return a nice string representation of the board."""=0A=
        buffer =3D []=0A=
        =0A=
        ## do the top line=0A=
        for i in range(self.width-1):=0A=
            if self.board.has_key(((i, self.height-1), (i+1, =
self.height-1))):=0A=
                buffer.append("+--")=0A=
            else: buffer.append("+  ")=0A=
        buffer.append("+\n")=0A=
=0A=
        ## and now do alternating vertical/horizontal passes=0A=
#       for j in range(self.height-2, -1, -1):  #  CHANGED  for =
corresponence =0A=
        for j in range(self.height-1):          #  with graphical display=0A=
            ## vertical:=0A=
            for i in range(self.width):=0A=
                if self.board.has_key(((i, j), (i, j+1))):=0A=
                    buffer.append("|")=0A=
                else:=0A=
                    buffer.append(" ")=0A=
                if self.squares.has_key((i, j)):=0A=
                    buffer.append("%s " % self.squares[i,j])=0A=
                else:=0A=
                    buffer.append("  ")=0A=
            buffer.append("\n")=0A=
=0A=
            ## horizontal=0A=
            for i in range(self.width-1):=0A=
                if self.board.has_key(((i, j), (i+1, j))):=0A=
                    buffer.append("+--")=0A=
                else: buffer.append("+  ")=0A=
            buffer.append("+\n")=0A=
=0A=
        return ''.join(buffer)=0A=
=0A=
=0A=
=0A=
    def _makeMove(self, coord1, coord2):=0A=
        """Return a new "move", and ensure it's in canonical form.=0A=
        (That is, force it so that it's an ordered tuple of tuples.)=0A=
        """=0A=
        ## TODO: do the Flyweight thing here to reduce object creation=0A=
        xdelta, ydelta =3D coord2[0] - coord1[0], coord2[1] - coord1[1]=0A=
        assert ((abs(xdelta) =3D=3D 1 and abs(ydelta) =3D=3D 0) or=0A=
                (abs(xdelta) =3D=3D 0 and abs(ydelta) =3D=3D 1)),\=0A=
                "Bad coordinates, not adjacent points."=0A=
        if coord1 < coord2:=0A=
            return (coord1, coord2)=0A=
        else:=0A=
            return (tuple(coord2), tuple(coord1))=0A=
=0A=
=0A=
    def _isGoodCoord(self, coord):=0A=
        """Returns true if the given coordinate is good.=0A=
=0A=
        A coordinate is "good" if it's within the boundaries of the=0A=
        game board, and if the coordinates are integers."""=0A=
        return (0 <=3D coord[0] < self.width=0A=
                and 0 <=3D coord[1] < self.height=0A=
                and isinstance(coord[0], types.IntType)=0A=
                and isinstance(coord[1], types.IntType))=0A=

    def getMove(self):    # <=3D=3D=3D NEW NEW NEW
        """Found this little bit of error-checking useful
        for testing, because I tend to mistype everything
        rather often.
        Moreover now it's more safe"""
        done =3D 0
        while not done:
            try:
                x1, y1, sep, x2, y2 =3D raw_input("Move?").split()
                move =3D ((int(x1),int(y1)),(int(x2),int(y2)))
                done =3D 1
            except:
                pass
        return move
    =0A=
=0A=
def _test(width, height):=0A=
    """A small driver to make sure that the board works.  It's not=0A=
    safe to use this test function in production, because it uses=0A=
    input()."""=0A=
    board =3D GameBoard(width, height)=0A=
    turn =3D 1=0A=
    scores =3D [0, 0]=0A=
    while not board.isGameOver():=0A=
        player =3D board.getPlayer()=0A=
        print "Turn %d (Player %s)" % (turn, player)=0A=
        print board=0A=
        # move =3D input("Move? ")
        move =3D board.getMove()         # <=3D=3D  CHANGED !!!=0A=
        if board.play(move):=0A=
            print "Square completed."=0A=
            scores[player] +=3D 1=0A=
        turn =3D turn + 1=0A=
        print "\n"=0A=
    print "Game over!"=0A=
    print "Final board position:"=0A=
    print board=0A=
    print=0A=
    print "Final score:\n\tPlayer 0: %s\n\tPlayer 1: %s" % \=0A=
          (scores[0], scores[1])=0A=

=0A=
if __name__ =3D=3D "__main__":
    """If we're provided arguments,
    look if first one equals 't', in which case
    textmode only is invoked.
    try using rest of the arguments as the
    width/height of the game board."""
    import sys
    if len(sys.argv[1:]) > 0 and sys.argv[1] =3D=3D 't':
        # textmode
        if len(sys.argv[1:]) =3D=3D 3:
            _test(int(sys.argv[2]), int(sys.argv[3]))
        elif len(sys.argv[1:]) =3D=3D 2:
            _test(int(sys.argv[2]), int(sys.argv[2]))
        else:
            _test(5, 5)
    else:
        # grachics mode
        if len(sys.argv[1:]) =3D=3D 2:
            _gtest(int(sys.argv[1]), int(sys.argv[2]))
        elif len(sys.argv[1:]) =3D=3D 1:
            _gtest(int(sys.argv[1]), int(sys.argv[1]))
        else:
            _gtest(5, 5)


------=_NextPart_000_0060_01C20AB5.21C0B170--




From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 03:21:57 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 2 Jun 2002 19:21:57 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes
In-Reply-To: <001901c20a98$9abfc100$1615a8c0@mega>
Message-ID: <Pine.LNX.4.44.0206021913090.26176-100000@hkn.eecs.berkeley.edu>


> """Graphic user interface to Danny Yoo's 'dots and boxes' -program.
> I tried to avoid changes to this program as far as possible.
> So there remain the following changes:
>
> Line  222: Return statement in play() now returns the
>            square_corner instead of 1 (this was the only
>            necessary one (in m opinion)

Ok, that makes perfect sense.  I'll reflect this in my code too.



> Line  255/256: head of for-loop --- this was the easiest way
>            to accomodate text-output to graphical one.
>            ( Bad design decision for the graphics display,
>              may be reverted if there is time ...)
>
> Lines 305-318, 332, 333: A somewhat safer input method for
>            more convenient testing
>
> Lines 354ff: Incorporate graphics mode into __main__()

Very cool!  I'll play around with this tonight.  Thank you!

A muse is murmuring to me that we should put this code up on a source code
repository like Sourceforge.  *grin* Should I do this?




From sarmstrong13@mac.com  Mon Jun  3 05:09:55 2002
From: sarmstrong13@mac.com (SA)
Date: Sun, 02 Jun 2002 23:09:55 -0500
Subject: [Tutor] Input variable help please.
Message-ID: <B9205643.5E97%sarmstrong13@mac.com>

Hi everyone -

    I'm trying to get the user to input the directory of their choosing into
a variable:

x = input("Please enter directory name: ")


But when I enter something like:
/Users/username

I get the following error:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1
    /Users/username
    ^
SyntaxError: invalid syntax

Please point out my error and how I can fix this so that it accepts UNIX
style directory listings.

Thanks.
SA




From paulsid@shaw.ca  Mon Jun  3 05:56:03 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Sun, 02 Jun 2002 22:56:03 -0600
Subject: [Tutor] Dots-And-Boxes
References: <Pine.LNX.4.44.0205282325280.12136-100000@hkn.eecs.berkeley.edu>
Message-ID: <3CFAF6E3.5ECFED58@shaw.ca>

Danny Yoo wrote:

> For fun, I picked up Elwyn Berlekamp's "The Dots and Boxes Game", which is
> a book about a deceptively simple game.  Here's Berlekamp's paragraph
> describing the game:
[snip]

Damn, why is it I'm always doing something when you bring up the cool
topics?  :-)

I remember this game very well, only as a solitaire version.  It came in
books with invisible ink that you had to rub a special pen over to
reveal.  Each line you picked was either broken or solid, and you had to
complete a box with a particular type of line (I believe it was solid)
to be allowed to claim the box.  It was loads of fun; I think I went
through 2 or 3 of those books.  IIRC there was also some kind of
guarantee so you could deduce something about the location of the solid
lines.  It might have been that every square had a solid line touching
it somewhere, not sure.

Anyhow, I took a look at Danny's code and Gregor's GUI front-end, looks
good!  I'll be following developments of this closely.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From glingl@aon.at  Mon Jun  3 07:15:26 2002
From: glingl@aon.at (Gregor Lingl)
Date: Mon, 3 Jun 2002 08:15:26 +0200
Subject: [Tutor] Input variable help please.
References: <B9205643.5E97%sarmstrong13@mac.com>
Message-ID: <002901c20ac6$0d571b50$1615a8c0@mega>

----- Original Message -----
From: "SA" <sarmstrong13@mac.com>
To: "tutor" <tutor@python.org>

    I'm trying to get the user to input the directory of their choosing into
a variable:

x = input("Please enter directory name: ")


But when I enter something like:
/Users/username

I get the following error:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1
    /Users/username
    ^
SyntaxError: invalid syntax

------------------´reply:

You have to use the function raw_input() instead of
input to enter arbitrary strings:

>>> x = raw_input("Please enter directory name: ")
Please enter directory name: /Users/username
>>> x
'/Users/username'
>>>

input() only accepts leagal Python expression, which
are immediately evaluated before assignment, e.g.:

>>> x = input("Gimme an expression: ")
Gimme an expression: 6  # legal Python
>>> x
6
>>> x = input("Gimme an expression: ")
Gimme an expression: 6 + 6
>>> x
12
>>> x = input("Gimme an expression: ")
Gimme an expression: '/Users/username'
>>> x
'/Users/username'
>>>

You see, you have to put your directory name
between ' ' s (quotation marks (?)).
That doesn't make sense in your case.
So stick with raw_input()

Best wishes
Gregor





From dyoo@hkn.eecs.berkeley.edu  Mon Jun  3 08:39:14 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 3 Jun 2002 00:39:14 -0700 (PDT)
Subject: [Tutor] Dots-And-Boxes  [on sourceforge now!]
In-Reply-To: <3CFAF6E3.5ECFED58@shaw.ca>
Message-ID: <Pine.LNX.4.44.0206030026230.2094-100000@hkn.eecs.berkeley.edu>


On Sun, 2 Jun 2002, Paul Sidorsky wrote:

> Danny Yoo wrote:
>
> > For fun, I picked up Elwyn Berlekamp's "The Dots and Boxes Game",
> > which is a book about a deceptively simple game.  Here's Berlekamp's
> > paragraph describing the game:
> [snip]
>
> Damn, why is it I'm always doing something when you bring up the cool
> topics?  :-)

Please feel free to contribute!  I didn't expect so many people to be
interested, but I'm very glad that people are.


I've set things up on Sourceforge, so anyone's welcome to take a look at
how the code mutates.

    http://sourceforge.net/projects/tutorbot/

The code is under the 'dots-and-boxes' directory, under the main cvs root
diretory.  If you have an account on Sourceforge already, and you'd like
to fiddle with the code, just email me, and I'll be happy to add you as a
developer!


> Anyhow, I took a look at Danny's code and Gregor's GUI front-end, looks
> good!  I'll be following developments of this closely.

I just played with Gregor's GUI; I'm floored.  It looks really nice.




From lumbricus@gmx.net  Mon Jun  3 13:06:47 2002
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Mon, 3 Jun 2002 14:06:47 +0200 (MEST)
Subject: [Tutor] Text to HTML question.
References: <B91FBBA5.5A28%phinsxiii@knology.net>
Message-ID: <25218.1023106007@www40.gmx.net>

> Hi Everyone-

Hello

>     I have a couple of questions for ya. Remember I'm new to Python and am
> still learning:
> 
> 1. I have a bunch of text files. I have a python script to generate html.
> I
> would like to substitute the body of the text files in between
> <body></body>
> of the html file. I think I can get this part. The trouble I'm having is
> formatting the text body into html. For instance for every "\n" in the
> text
> body I need to substitute <BR> before placing it into the html file body
> section.

Don't do this. It's the Browsers job to do the linebreaking.
If you want to enforce a linebreak for every "\n" in the 
HTML source, use the <pre> tag.

> And for every "\n\n" I wish to substitute <P>. I suppose I nead
> to
> use regexp, but how do you call the re module and search/sub these
> patterns?
> 
> 2. I'm sure this is probably a problem that has been solved before, so
> does
> anyone know of a module to do this and how do I use it to accomplish the
> goal?
> 
> Thanks in advance for your help. I'm just now starting to get the whole
> class thing in Python.
> 
> SA

HTH, HAND and
Greetings, J"o!

-- 
sigfault

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net




From purplebo@babylonia.flatirons.org  Mon Jun  3 17:29:09 2002
From: purplebo@babylonia.flatirons.org (Chris Avery)
Date: Mon, 3 Jun 2002 10:29:09 -0600
Subject: [Tutor] formatting strings
In-Reply-To: <20020603160004.30168.6044.Mailman@mail.python.org>; from tutor-request@python.org on Mon, Jun 03, 2002 at 12:00:04PM -0400
References: <20020603160004.30168.6044.Mailman@mail.python.org>
Message-ID: <20020603102909.A9561@babylonia.flatirons.org>

Hi.  I need to format a string so that the newline is indented.  For example, it would need to look like this:

	* this is a line that is really long and should change to a newline abou	t here and it is the same line still and I am a turkey etc. etc.

and not like this:
	* this is a line that is really long and should change to a newline about here and it is the same line still and I am a turkey etc. etc. 

Thanks for your help


-- 
+++++++++++++++++++
Chris Avery, KC0KTH
+++++++++++++++++++



From shalehperry@attbi.com  Mon Jun  3 17:42:44 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 03 Jun 2002 09:42:44 -0700 (PDT)
Subject: [Tutor] formatting strings
In-Reply-To: <20020603102909.A9561@babylonia.flatirons.org>
Message-ID: <XFMail.20020603094244.shalehperry@attbi.com>

On 03-Jun-2002 Chris Avery wrote:
> Hi.  I need to format a string so that the newline is indented.  For example,
> it would need to look like this:
> 
>       * this is a line that is really long and should change to a newline
abou        t
> here and it is the same line still and I am a turkey etc. etc.
> 
> and not like this:
>       * this is a line that is really long and should change to a newline
about
> here and it is the same line still and I am a turkey etc. etc. 
> 
> Thanks for your help
> 

so let's stop and think about this one for a moment.  How does say your text
editor handle line wrapping?  It keeps a maximum line width variable and checks
the line against it.  When the length is reached it inserts a newline and the
rest of the line becomes a new line.

Indentation is simply extra whitespace (a tab, 4 chars, something).  So it
would go something like this:

....
handle line things
....
if (len(line) > max_line_length):
  line = (line before max_line_length) + '\n'
  next_line = (indent) + (remainder)
....
....



From wolf_binary@hotmail.com  Mon Jun  3 20:26:40 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Mon, 3 Jun 2002 14:26:40 -0500
Subject: [Tutor] computers
Message-ID: <DAV66itcEctybK8YoSq0000a1b6@hotmail.com>

This is a multi-part message in MIME format.

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

Hi all,

I have an opportunity to get a dual processored computer that would =
replace my old one.  My question is can Windows 98 be used on it and can =
I use all my other programs on it?  I don't wanted to loose the ability =
to do all the old things with this one.

Thanks,

Cameron Stoner

------=_NextPart_000_000A_01C20B0A.AD981940
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have an opportunity to get a dual =
processored=20
computer that would replace my old one.&nbsp; My question is can Windows =
98 be=20
used on it and can I use all my other programs on it?&nbsp; I don't =
wanted to=20
loose the ability to do all the old things with this one.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_000A_01C20B0A.AD981940--



From sarmstrong13@mac.com  Mon Jun  3 21:05:06 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 03 Jun 2002 15:05:06 -0500
Subject: [Tutor] computers
In-Reply-To: <DAV66itcEctybK8YoSq0000a1b6@hotmail.com>
Message-ID: <B9213622.61E8%sarmstrong13@mac.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.

--B_3105961508_885558
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

Yes you should be able to run win98. However, since Win98 is a piece of junk
(IMHO), Win98 will not be able to access both processors. If I remember
correctly, the only windoze capable of taking full advantage of
multiprocessor systems are NT, 2000, and XP.
Win 98 will only reecognize one processor, so there is no advantage.

Good Luck.
SA
On 6/3/02 2:26 PM, "Cameron Stoner" <wolf_binary@hotmail.com> wrote:

> Hi all,
>  
> I have an opportunity to get a dual processored computer that would replace my
> old one.  My question is can Windows 98 be used on it and can I use all my
> other programs on it?  I don't wanted to loose the ability to do all the old
> things with this one.
>  
> Thanks,
>  
> Cameron Stoner
> 



--B_3105961508_885558
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Re: [Tutor] computers</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">Yes you should be able to run win98. However, since Wi=
n98 is a piece of junk (IMHO), Win98 will not be able to access both process=
ors. If I remember correctly, the only windoze capable of taking full advant=
age of multiprocessor systems are NT, 2000, and XP.<BR>
Win 98 will only reecognize one processor, so there is no advantage.<BR>
<BR>
Good Luck.<BR>
SA<BR>
On 6/3/02 2:26 PM, &quot;Cameron Stoner&quot; &lt;wolf_binary@hotmail.com&g=
t; wrote:<BR>
<BR>
</FONT><BLOCKQUOTE><FONT SIZE=3D"2"><FONT FACE=3D"Arial">Hi all,<BR>
</FONT></FONT><FONT FACE=3D"Verdana"> <BR>
</FONT><FONT SIZE=3D"2"><FONT FACE=3D"Arial">I have an opportunity to get a dua=
l processored computer that would replace my old one. &nbsp;My question is c=
an Windows 98 be used on it and can I use all my other programs on it? &nbsp=
;I don't wanted to loose the ability to do all the old things with this one.=
<BR>
</FONT></FONT><FONT FACE=3D"Verdana"> <BR>
</FONT><FONT SIZE=3D"2"><FONT FACE=3D"Arial">Thanks,<BR>
</FONT></FONT><FONT FACE=3D"Verdana"> <BR>
</FONT><FONT SIZE=3D"2"><FONT FACE=3D"Arial">Cameron Stoner<BR>
</FONT></FONT><FONT FACE=3D"Verdana"><BR>
</FONT></BLOCKQUOTE><FONT FACE=3D"Verdana"><BR>
</FONT>
</BODY>
</HTML>


--B_3105961508_885558--




From ATrautman@perryjudds.com  Mon Jun  3 21:18:02 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Mon, 3 Jun 2002 15:18:02 -0500
Subject: [Tutor] computers
Message-ID: <75EDF89FDE81D511840D00A0C9AD25DD0261A2BF@CORP_EXCHANGE>

You need more information on the motherboard many have an ability to turn of
the second processor unit (it would work more than likely). The approach to
the bios is very different and I would look to the bios maker to see if it
can disable the two processor part or if they state it can be used. My
experience is that the motherboard needs to be matched to operating system
in multi-processor system even some that work with NT 4.0 (the ones I had to
convert) will not work with 2000 and (IMHO I wouldn't even try 98 or XP
Home). 2000, BSD and Linux have good reputations with multi-processor use. 

Good Luck,

Alan

-----Original Message-----
From: Cameron Stoner [mailto:wolf_binary@hotmail.com]
Sent: Monday, June 03, 2002 2:27 PM
To: python tutor
Subject: [Tutor] computers


Hi all,

I have an opportunity to get a dual processored computer that would replace
my old one.  My question is can Windows 98 be used on it and can I use all
my other programs on it?  I don't wanted to loose the ability to do all the
old things with this one.

Thanks,

Cameron Stoner



From phthenry@earthlink.net  Tue Jun  4 03:13:55 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Mon, 3 Jun 2002 22:13:55 -0400
Subject: [Tutor] remove 2.2 install 2.1
Message-ID: <20020603221354.C20733@localhost.localdomain>

I need to go back to version 2.1 of python because of a conflict.
I would like to use the 4xslt suite, but the stable of version of
4xslt conflicts with python 2.2. 

I use linux, specifically Mandrake 8.1

I have already downloaded the source for python 2.1. Should I
remove the library in the /usr/local/lib folder? And should I
remove the exectubale from my /bin folder? 

When I installed python 2.2, I simply did:

make
make install

This worked like a charm, so I'm not anticipating any problems
with the actual installation. But I would like to make sure I get
rid of any conflicts in my library!

Thanks

Paul


-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From kojo@hal-pc.org  Tue Jun  4 04:29:50 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 03 Jun 2002 22:29:50 -0500
Subject: [Tutor] computers
Message-ID: <5.1.0.14.0.20020603222933.02398a30@mail.hal-pc.org>

--=====================_658883584==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Here's my question:  Does the new computer have to replace the old 
one?  Will you have to give up the old one to get the new one?  If not, try 
to keep both.  If you can't keep both, you might want to consider 
dual-booting Win98 with Linux/BSD or even Win2K.  It might be fun to 
practice some multi threaded Python programming with to procs.

Like everyone else has already said, Windows based on a 9x kernel won't do 
Multi-Proc.  You need an NT kernel (NT/2k/XP...not sure about XP Home).

At 02:26 PM 6/3/2002 -0500, you wrote:
>Hi all,
>
>I have an opportunity to get a dual processored computer that would 
>replace my old one.  My question is can Windows 98 be used on it and can I 
>use all my other programs on it?  I don't wanted to loose the ability to 
>do all the old things with this one.
>
>Thanks,
>
>Cameron Stoner

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_658883584==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Here's my question:&nbsp; Does the new computer have to <b>replace</b>
the old one?&nbsp; Will you have to give up the old one to get the new
one?&nbsp; If not, try to keep both.&nbsp; If you can't keep both, you
might want to consider dual-booting Win98 with Linux/BSD or even
Win2K.&nbsp; It might be fun to practice some multi threaded Python
programming with to procs.<br><br>
Like everyone else has already said, Windows based on a 9x kernel won't
do Multi-Proc.&nbsp; You need an NT kernel (NT/2k/XP...not sure about XP
Home).<br><br>
At 02:26 PM 6/3/2002 -0500, you wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>Hi
all,</font><br>
&nbsp;<br>
<font face="arial" size=2>I have an opportunity to get a dual processored
computer that would replace my old one.&nbsp; My question is can Windows
98 be used on it and can I use all my other programs on it?&nbsp; I don't
wanted to loose the ability to do all the old things with this
one.</font><br>
&nbsp;<br>
<font face="arial" size=2>Thanks,</font><br>
&nbsp;<br>
<font face="arial" size=2>Cameron Stoner</font></blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http://www.hal-pc.org/~kojo/</a><br>
****************************</html>

--=====================_658883584==_.ALT--





From canterol@wharton.upenn.edu  Tue Jun  4 05:19:57 2002
From: canterol@wharton.upenn.edu (Laura Cantero)
Date: Tue, 4 Jun 2002 00:19:57 -0400
Subject: [Tutor] Python and Excel
Message-ID: <000a01c20b7f$17aa8b00$23ecc797@vaio>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C20B5D.8EFE74E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

How can I export data strings from a .txt file, and display them on =
Excel (individually)???
I need the CODE!
Thanks,
Laura

------=_NextPart_000_0007_01C20B5D.8EFE74E0
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 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>How can I export data strings&nbsp;from =
a .txt=20
file, and display them on Excel (individually)???<BR>I need the=20
CODE!<BR>Thanks,<BR>Laura</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C20B5D.8EFE74E0--




From dyoo@hkn.eecs.berkeley.edu  Tue Jun  4 07:08:44 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 3 Jun 2002 23:08:44 -0700 (PDT)
Subject: [Tutor] Python and Excel
In-Reply-To: <000a01c20b7f$17aa8b00$23ecc797@vaio>
Message-ID: <Pine.LNX.4.44.0206032259100.30652-100000@hkn.eecs.berkeley.edu>


On Tue, 4 Jun 2002, Laura Cantero wrote:

> How can I export data strings from a .txt file,

Hi Laura,

This depends on how your data is formatted.  Python strings support
several utility functions you can use to parse out the data.  If it's in
tab-delimited format, you'll find the 'split()' string method pretty
useful.  Here's an example of how it might work:

###
>>> sample_line = 'hello world, this is a test'
>>> words = sample_line.split(' ')
>>> words
['hello', 'world,', 'this', 'is', 'a', 'test']
###

This example shows that we can split a line along space boundaries, and we
can do similar stuff with tabs if that's how your file is organized.  But
Excel already has the ability to load tab-delimited data, so perhaps your
information has some structure to it.  Tell us more information about the
file format, and we'll try giving suggestions.



> and display them on Excel (individually)??? I need the CODE! Thanks,

It sounds like you're planning to do win32 stuff.  I'd recommend taking a
look at "Python Programming on Win32":

    http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

I'm almost positive there's a chapter in there about driving Excel, so
looking through that book will be helpful.


Also, try contacting the python-win32 list; there are Windows experts
there who might be able to cook up a nice example for you.  Their mailing
list is here:

    http://mail.python.org/mailman/listinfo/python-win32


Do you have experience in Python already?  If you tell us more about what
you've tried already, we can tailor our responses better.


Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Tue Jun  4 07:20:27 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 3 Jun 2002 23:20:27 -0700 (PDT)
Subject: [Tutor] Python and Excel
In-Reply-To: <Pine.LNX.4.44.0206032259100.30652-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0206032315140.30652-100000@hkn.eecs.berkeley.edu>


> It sounds like you're planning to do win32 stuff.  I'd recommend taking a
> look at "Python Programming on Win32":
>
>     http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html
>
> I'm almost positive there's a chapter in there about driving Excel, so
> looking through that book will be helpful.

I'm still hunting through the web; here are a few other things I'm
dredging up:

    http://starship.python.net/crew/pirx/spam7/
    http://www.msdnaa.net/interchange/preview.asp?PeerID=1285
    http://www.faqts.com/knowledge_base/view.phtml/aid/3093/fid/591

Google is beautiful.  *grin*


The last link has example code; play around with it and tell us if it
works for you.  Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Tue Jun  4 07:13:41 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 3 Jun 2002 23:13:41 -0700 (PDT)
Subject: [Tutor] remove 2.2 install 2.1
In-Reply-To: <20020603221354.C20733@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0206032308520.30652-100000@hkn.eecs.berkeley.edu>


On Mon, 3 Jun 2002, Paul Tremblay wrote:
> I need to go back to version 2.1 of python because of a conflict.
> I would like to use the 4xslt suite, but the stable of version of
> 4xslt conflicts with python 2.2.

Hi Paul,

One thing to make sure is that '/usr/local/bin/python' is linked to
'/usr/local/bin/python2.1'; I think that the upgrade to 2.2 might have
overridden '/usr/local/bin/python'.  Otherwise, I haven't had any problems
myself, but then, testimonials are always a little unreliable... *grin*


By the way, if you want to experiment with compiled versions of Python,
you can use the '--prefix=/some/temporary/directory' flag during the
'./configure' step; by doing this, you can compile Python in the relative
safety of your own directories.  I've often done something like:

    './configure --prefix=/home/dyoo/local/python-2.2'

which makes it fairly easy to uninstall it later.


Good luck to you!




From rab121@york.ac.uk  Tue Jun  4 12:45:12 2002
From: rab121@york.ac.uk (Russell Bungay)
Date: Tue, 04 Jun 2002 12:45:12 +0100
Subject: [Tutor] Connection/Analyis Order
Message-ID: <3CFCA848.9B65E2C8@york.ac.uk>

Hello,

I am about to embark on a little project and was wondering if you
wonderful ppeeps could offer me some advice.

I am setting up a series of web pages to display certain data based upon
the input to a form (ratings for levels in a game to be precise).

Unfortunately, I currently have no access to proper cgi type stuff so I
am having to use a 'normal' email post from the services that my host
does provide.

So, emails arrive at my server with the form data in, I want to analyse
each, store the data and publish some of it to web pages.  All of the
coding I think I can handle (never done mail stuff before, but this is
Python, how hard can it be :o), my problem is more how I organise the
steps.  I currently have three ideas:

1.
Connect to server blah.
Check each mail (will not be just postings).
If mail has correct subject:
	Get body of mail and analyse etc.
Check next mail etc.
	
2.
Connect.
Check each mail.
If correct mail:
	Get body of mail, stick in variable.
Check next mail.
Analyse all data in variable (ie do all mails at once).

3.
Connect.
Check each mail.
If correct mail:
	Analyse mail in seperate thread whilst...
Continuting to check mail...

Now, I think my exact connection circumstances may effect this...

At present I have access to a permanent, fast connection to an IMAP
server.  However, in the future I will probably have to connect over
normal dial-up, possible to IMAP, possibly to POP3.

Given my current status, I tend to favour 1, but over dial up would 2 or
3 make more sense?

I have never done any thread programming before (though Prog. Python
makes it look easy enough), but I am concerned about different threads
accessing the storage of the data at incompatible times and mucking it
up and similar problems connecting to the mail server (I want to delete
successfully analysed mails.)

Your advice is very welcome...

Russell
--
http://www.bigmaddrongo.com
President of York University Trampolining Club:
http://york.trampolining.net
Chair of The York Glee Singers:
http://www.gleesingers.co.uk



From shalehperry@attbi.com  Tue Jun  4 15:51:31 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 04 Jun 2002 07:51:31 -0700 (PDT)
Subject: [Tutor] Connection/Analyis Order
In-Reply-To: <3CFCA848.9B65E2C8@york.ac.uk>
Message-ID: <XFMail.20020604075131.shalehperry@attbi.com>

> 
> I have never done any thread programming before (though Prog. Python
> makes it look easy enough), but I am concerned about different threads
> accessing the storage of the data at incompatible times and mucking it
> up and similar problems connecting to the mail server (I want to delete
> successfully analysed mails.)
> 
> Your advice is very welcome...
> 

The only reason to play with threads would be if you wanted to have a mail
parser thread and a mail retriever thread.  Reasonable, but not a requirement.

If you look at any of the comp sci books on threads one of the models discussed
is "producer/consumer" which is exactly what you describe.

The way it works is the producer thread does some work to produce data which is
stored in a common area.  The consumer eats one piece of data at a time.  This
could easily be done with python via a list accessible by both threads.  Have
the consumer eat from the front of the list and the producer add to the end.



From python@rcn.com  Tue Jun  4 16:10:30 2002
From: python@rcn.com (Raymond Hettinger)
Date: Tue, 4 Jun 2002 11:10:30 -0400
Subject: [Tutor] Python and Excel
References: <000a01c20b7f$17aa8b00$23ecc797@vaio>
Message-ID: <005801c20bd9$f8701920$12f8a4d8@othello>

This is a multi-part message in MIME format.

------=_NextPart_000_0055_01C20BB8.706BDBC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Laura,

from win32com.client.dynamic import Dispatch
xl =3D Dispatch( 'Excel.Application' )
xl.Range('a1:a100').Value =3D [[line] for line in open('file.txt')]

Raymond Hettinger
  ----- Original Message -----=20
  From: Laura Cantero=20
  To: tutor@python.org=20
  Sent: Tuesday, June 04, 2002 12:19 AM
  Subject: [Tutor] Python and Excel


  How can I export data strings from a .txt file, and display them on =
Excel (individually)???
  I need the CODE!
  Thanks,
  Laura

------=_NextPart_000_0055_01C20BB8.706BDBC0
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=3DArial size=3D2>Laura,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>from win32com.client.dynamic import =
Dispatch<BR>xl=20
=3D Dispatch( 'Excel.Application' )</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>xl.Range('a1:a100').Value =3D [[line] =
for line in=20
open('file.txt')]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Raymond Hettinger</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dcanterol@wharton.upenn.edu=20
  href=3D"mailto:canterol@wharton.upenn.edu">Laura Cantero</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, June 04, 2002 =
12:19=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Python and =
Excel</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>How can I export data =
strings&nbsp;from a .txt=20
  file, and display them on Excel (individually)???<BR>I need the=20
  CODE!<BR>Thanks,<BR>Laura</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0055_01C20BB8.706BDBC0--




From kojo@hal-pc.org  Tue Jun  4 16:17:20 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Tue, 04 Jun 2002 10:17:20 -0500
Subject: [Tutor] Connection/Analyis Order
In-Reply-To: <3CFCA848.9B65E2C8@york.ac.uk>
Message-ID: <5.1.0.14.0.20020604101315.0237ed28@mail.hal-pc.org>

--=====================_701528454==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

And now, for something completely different...

This is about you not having access to CGI type stuff.  Have you considered 
Freezope.org? <http://www.freezope.org/>
You can set up a free account and have access to Zope and a lot of other 
Zope/Python related stuff.  Free for non-commercial use.  I just set up an 
account yesterday and plan to use it to practice some Python and WebDev 
stuff.  My ISP doesn't offer CGI through Python, only Perl.

Of course, there' s the added learning curve of Zope, but hey, it's all 
done in Python, how hard could it be?
:-)
Seriously, given what you seem to want to do, Zope has all the 
functionality you need.  Ok, it's overkill, but hey, it's free!

Just an "out of the box" suggestion, not so much a direct response to your 
query.

At 12:45 PM 6/4/2002 +0100, Russell Bungay wrote:
>Hello,
>I am setting up a series of web pages to display certain data based upon
>the input to a form (ratings for levels in a game to be precise).
>
>Unfortunately, I currently have no access to proper cgi type stuff so I
>am having to use a 'normal' email post from the services that my host
>does provide.
>
>So, emails arrive at my server with the form data in, I want to analyse
>each, store the data and publish some of it to web pages.  All of the
>coding I think I can handle (never done mail stuff before, but this is
>Python, how hard can it be :o), my problem is more how I organise the
>steps.  I currently have three ideas:
>
>1.
>Connect to server blah.
>Check each mail (will not be just postings).
>If mail has correct subject:
>         Get body of mail and analyse etc.
>Check next mail etc.
>
>2.
>Connect.
>Check each mail.
>If correct mail:
>         Get body of mail, stick in variable.
>Check next mail.
>Analyse all data in variable (ie do all mails at once).
>
>3.
>Connect.
>Check each mail.
>If correct mail:
>         Analyse mail in seperate thread whilst...
>Continuting to check mail...
>
>Now, I think my exact connection circumstances may effect this...
>
>At present I have access to a permanent, fast connection to an IMAP
>server.  However, in the future I will probably have to connect over
>normal dial-up, possible to IMAP, possibly to POP3.
>
>Given my current status, I tend to favour 1, but over dial up would 2 or
>3 make more sense?
>
>I have never done any thread programming before (though Prog. Python
>makes it look easy enough), but I am concerned about different threads
>accessing the storage of the data at incompatible times and mucking it
>up and similar problems connecting to the mail server (I want to delete
>successfully analysed mails.)
>
>Your advice is very welcome...
>
>Russell
>--

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_701528454==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
And now, for something completely different...<br><br>
This is about you not having access to CGI type stuff.&nbsp; Have you
considered Freezope.org?
&lt;<a href="http://www.freezope.org/" eudora="autourl">http://www.freezope.org/</a>&gt;<br>
You can set up a free account and have access to Zope and a lot of other
Zope/Python related stuff.&nbsp; Free for non-commercial use.&nbsp; I
just set up an account yesterday and plan to use it to practice some
Python and WebDev stuff.&nbsp; My ISP doesn't offer CGI through Python,
only Perl.<br><br>
Of course, there' s the added learning curve of Zope, but hey, it's all
done in Python, how hard could it be?<br>
<b>:-)<br>
</b>Seriously, given what you seem to want to do, Zope has all the
functionality you need.&nbsp; Ok, it's overkill, but hey, it's
free!<br><br>
Just an &quot;out of the box&quot; suggestion, not so much a direct
response to your query.<br><br>
At 12:45 PM 6/4/2002 +0100, Russell Bungay wrote:<br>
<blockquote type=cite class=cite cite>Hello,<br>
I am setting up a series of web pages to display certain data based
upon<br>
the input to a form (ratings for levels in a game to be
precise).<br><br>
Unfortunately, I currently have no access to proper cgi type stuff so
I<br>
am having to use a 'normal' email post from the services that my
host<br>
does provide.<br><br>
So, emails arrive at my server with the form data in, I want to
analyse<br>
each, store the data and publish some of it to web pages.&nbsp; All of
the<br>
coding I think I can handle (never done mail stuff before, but this
is<br>
Python, how hard can it be :o), my problem is more how I organise
the<br>
steps.&nbsp; I currently have three ideas:<br><br>
1.<br>
Connect to server blah.<br>
Check each mail (will not be just postings).<br>
If mail has correct subject:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>Get body
of mail and analyse etc.<br>
Check next mail etc.<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
2.<br>
Connect.<br>
Check each mail.<br>
If correct mail:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>Get body
of mail, stick in variable.<br>
Check next mail.<br>
Analyse all data in variable (ie do all mails at once).<br><br>
3.<br>
Connect.<br>
Check each mail.<br>
If correct mail:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>Analyse
mail in seperate thread whilst...<br>
Continuting to check mail...<br><br>
Now, I think my exact connection circumstances may effect
this...<br><br>
At present I have access to a permanent, fast connection to an IMAP<br>
server.&nbsp; However, in the future I will probably have to connect
over<br>
normal dial-up, possible to IMAP, possibly to POP3.<br><br>
Given my current status, I tend to favour 1, but over dial up would 2
or<br>
3 make more sense?<br><br>
I have never done any thread programming before (though Prog. 
Python<br>
makes it look easy enough), but I am concerned about different
threads<br>
accessing the storage of the data at incompatible times and mucking
it<br>
up and similar problems connecting to the mail server (I want to
delete<br>
successfully analysed mails.)<br><br>
Your advice is very welcome...<br><br>
Russell<br>
--</blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http://www.hal-pc.org/~kojo/<br>
</a>****************************</html>

--=====================_701528454==_.ALT--





From rab121@york.ac.uk  Tue Jun  4 16:25:39 2002
From: rab121@york.ac.uk (Russell Bungay)
Date: Tue, 04 Jun 2002 16:25:39 +0100
Subject: [Tutor] Connection/Analyis Order
References: <XFMail.20020604075131.shalehperry@attbi.com>
Message-ID: <3CFCDBF3.4D637C35@york.ac.uk>

Sean 'Shaleh' Perry wrote:
>>I have never done any thread programming before (though Prog. Python
>>makes it look easy enough), but I am concerned about different threads
>>accessing the storage of the data at incompatible times and mucking it
>>up and similar problems connecting to the mail server (I want to >>delete successfully analysed mails.)
>The only reason to play with threads would be if you wanted to have a >mail parser thread and a mail retriever thread.  Reasonable, but not a >requirement.

Thats what I was thinking.  So I would only run one parser at a time?  I
can see the advantages to this and really should of thought of it myself
:o)  

My current implementation (half written) runs unthreaded, but when I
have to go dial up again, I think I will rewrite it.

Thankyou,

Russell
--
http://www.bigmaddrongo.com
President of York University Trampolining Club:
http://york.trampolining.net
Chair of The York Glee Singers:
http://www.gleesingers.co.uk



From rab121@york.ac.uk  Tue Jun  4 16:27:23 2002
From: rab121@york.ac.uk (Russell Bungay)
Date: Tue, 04 Jun 2002 16:27:23 +0100
Subject: [Tutor] Connection/Analyis Order
References: <5.1.0.14.0.20020604101315.0237ed28@mail.hal-pc.org>
Message-ID: <3CFCDC5B.58733AC9@york.ac.uk>

>Have you considered Freezope.org? <http://www.freezope.org/>

Yes, but not for this project :o)

Like you say, I would have the learning curve of Zope, and at the moment
I an interest in a quick fix, I can tidy it up later.

I am probably going to go Zope for a future project I am planning
though...

Thankyou,

Russell
--
http://www.bigmaddrongo.com
President of York University Trampolining Club:
http://york.trampolining.net
Chair of The York Glee Singers:
http://www.gleesingers.co.uk



From shalehperry@attbi.com  Tue Jun  4 16:33:27 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 04 Jun 2002 08:33:27 -0700 (PDT)
Subject: [Tutor] Connection/Analyis Order
In-Reply-To: <3CFCDBF3.4D637C35@york.ac.uk>
Message-ID: <XFMail.20020604083327.shalehperry@attbi.com>

On 04-Jun-2002 Russell Bungay wrote:
> Sean 'Shaleh' Perry wrote:
>>>I have never done any thread programming before (though Prog. Python
>>>makes it look easy enough), but I am concerned about different threads
>>>accessing the storage of the data at incompatible times and mucking it
>>>up and similar problems connecting to the mail server (I want to >>delete
>>>successfully analysed mails.)
>>The only reason to play with threads would be if you wanted to have a >mail
>>parser thread and a mail retriever thread.  Reasonable, but not a
>>>requirement.
> 
> Thats what I was thinking.  So I would only run one parser at a time?  I
> can see the advantages to this and really should of thought of it myself
>:o)  
> 

yeah the parser thread would do:

while (not blocked):
  mail = eatMailFromQueue()
  output = parse(mail)
  use output




From jeff@ccvcorp.com  Tue Jun  4 17:14:36 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 04 Jun 2002 09:14:36 -0700
Subject: [Tutor] Connection/Analyis Order
References: <3CFCA848.9B65E2C8@york.ac.uk>
Message-ID: <3CFCE76C.6C247F83@ccvcorp.com>


Russell Bungay wrote:

> Given my current status, I tend to favour 1, but over dial up would 2 or
> 3 make more sense?

Personally, I'd be inclined to use #2 in any case.  It depends not only on
your connection to your mailserver, but also to the connection to the
webserver that you're publishing your data on.  I'd think that you will
probably want to update the web page only once for each run of your script.
To my mind, the simplest way to do this is stepwise -- first grab all data,
then analyze all data, then publish the results.

If you *do* decide to use option #3 and go with threads, you will
*definately* want to look into the Queue module.  Queue does exactly what
you'd need for passing chunks of data from one thread to another, safely.
Your producer thread(s) add data to the Queue, your consumer thread(s) pull
data from the Queue, and the Queue itself will make sure that nobody steps
on each other's toes.  You could also have a separate "publisher" thread --
once your data has been analyzed by your parser thread, the results can be
put in another Queue to be pulled out by the publisher thread.  That thread
could accumulate results from multiple messages, and when the Queue is
empty, update your web page.  Or perhaps the publisher should wait for the
Queue to be empty for longer than some time limit, such as half a second, to
allow for some slight delays in the reading/parsing.


> I have never done any thread programming before (though Prog. Python
> makes it look easy enough), but I am concerned about different threads
> accessing the storage of the data at incompatible times and mucking it
> up and similar problems connecting to the mail server (I want to delete
> successfully analysed mails.)

Thread programming isn't *too* complicated if you're careful... ;)  If you
use a Queue to manage any data passed between threads, you'll probably be in
good shape.  Just be sure to think about all the possible conditions of "if
*this* thread does X before or after *that* thread does Y, what will the
effect be?"  It's easy to assume a particular order of occurrences, but with
threading those assumptions are dangerous -- if the order is important, then
you *must* enforce it with thread synchronization techniques (of which
Queues are perhaps the easiest...)

And, while I haven't done anything with IMAP mailservers, using poplib to
access POP3 accounts *is* indeed dead easy.  :)  (I sometimes check my home
email while I'm at work, by firing up the Python interpreter and
interactively poking through it with poplib...)

Jeff Shannon
Technician/Programmer
Credit International





From stuart_clemons@us.ibm.com  Tue Jun  4 19:59:47 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Tue, 4 Jun 2002 14:59:47 -0400
Subject: [Tutor] Use of dictionary or DBM instead of spreadsheet
Message-ID: <OFD60A0EC4.8965AF6F-ON85256BCE.006839B8@lotus.com>

--0__=0ABBE15DDFFBBF288f9e8a93df938690918c0ABBE15DDFFBBF28
Content-type: text/plain; charset=US-ASCII


Hi all:

I have an WinNT application I run that consists of three phases, 1) Python,
2) spreadsheet, and 3) Python.   I would like to eliminate the spreadsheet
and make this an all Python application.

Here's the details.

1) I run a python program that "pings" a list of IP addresses and
determines if the IP addresses are being used.  I run this daily.  The
result is collected daily in a text file called ipresult.txt, which looks
like this:

      9.99.99.1 noreply
      9.99.99.2 reply
      9.99.99.3 reply
      9.99.99.4 noreply, etc.

2) I then import this file daily into a spreadsheet which is acting as a
collection repository.  The spreadsheet file looks like this, with column
entries for each day's results.

            6/1         6/2         6/3         6/4
      9.99.9.1    noreply           reply       reply       reply
      9.99.9.2    reply       reply       reply       reply
      9.99.9.3    reply       noreply           reply       reply
      9.99.9.4    noreply           noreply           noreply
noreply

3) I then export this file into a text file that looks like the above, only
it's a text file.  I then run another Python program that will print out
only those IP address that have only no reply's.  In the above example, the
IP address 9.99.9.4 is the only IP address that has not had a reply.

I would like to eliminate using the spreadsheet as the data repository and
make this all python.  I was thinking I could use either a dictionary or
the anydbm module to act as the collection repository instead of the
spreadsheet, but I don't know how to do it.   My Python reference books
only touch on dictionaries and the anydbm module.   I ruled out appending
to a file, since it would not allow for columns of data.

I guess I need to know how to add data to the repository and then how to
check the entries for each IP address in the repository.

Any guidance would be greatly appreciated.

- Stuart

--0__=0ABBE15DDFFBBF288f9e8a93df938690918c0ABBE15DDFFBBF28
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p>Hi all:<br>
<br>
I have an WinNT application I run that consists of three phases, 1) Python, 2) spreadsheet, and 3) Python.   I would like to eliminate the spreadsheet and make this an all Python application.<br>
<br>
Here's the details.  <br>
<br>
1) I run a python program that &quot;pings&quot; a list of IP addresses and determines if the IP addresses are being used.  I run this daily.  The result is collected daily in a text file called ipresult.txt, which looks like this:<br>
<br>
	9.99.99.1 noreply<br>
	9.99.99.2 reply<br>
	9.99.99.3 reply<br>
	9.99.99.4 noreply, etc.<br>
<br>
2) I then import this file daily into a spreadsheet which is acting as a collection repository.  The spreadsheet file looks like this, with column entries for each day's results.<br>
<br>
		6/1		6/2		6/3		6/4<br>
	9.99.9.1	noreply		reply		reply		reply<br>
	9.99.9.2	reply		reply		reply		reply<br>
	9.99.9.3	reply		noreply		reply		reply<br>
	9.99.9.4	noreply		noreply		noreply		noreply<br>
<br>
3) I then export this file into a text file that looks like the above, only it's a text file.  I then run another Python program that will print out only those IP address that have only no reply's.  In the above example, the IP address 9.99.9.4 is the only IP address that has not had a reply.<br>
<br>
I would like to eliminate using the spreadsheet as the data repository and make this all python.  I was thinking I could use either a dictionary or the anydbm module to act as the collection repository instead of the spreadsheet, but I don't know how to do it.   My Python reference books only touch on dictionaries and the anydbm module.   I ruled out appending to a file, since it would not allow for columns of data.  <br>
<br>
I guess I need to know how to add data to the repository and then how to check the entries for each IP address in the repository.  <br>
<br>
Any guidance would be greatly appreciated.<br>
<br>
- Stuart <br>
<br>
</body></html>
--0__=0ABBE15DDFFBBF288f9e8a93df938690918c0ABBE15DDFFBBF28--




From stuart_clemons@us.ibm.com  Tue Jun  4 20:20:51 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Tue, 4 Jun 2002 15:20:51 -0400
Subject: [Tutor] re: computers
Message-ID: <OF6F8F28CD.E23ABB07-ON85256BCE.00695C53@lotus.com>

--0__=0ABBE15DDFFADAC38f9e8a93df938690918c0ABBE15DDFFADAC3
Content-type: text/plain; charset=US-ASCII


FYI.  Even if your OS, such as NT, is capable of running on a multi-
processor system, it does not mean that your programs or compilers  will
run any faster than when run on a single processor system.  Most programs
and compilers do not take advantage of multi-processor systems, which is
something most people don't seem to realise.  In fact, in some cases a
single processor system will complete tasks faster than a multi-processor
system.   So, for most people, having a multiprocessor system is a waste
time, money, and resources.
--0__=0ABBE15DDFFADAC38f9e8a93df938690918c0ABBE15DDFFADAC3
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p>FYI.  Even if your OS, such as NT, is capable of running on a multi-processor system, it does not mean that your programs or compilers  will run any faster than when run on a single processor system.  Most programs and compilers do not take advantage of multi-processor systems, which is something most people don't seem to realise.  In fact, in some cases a single processor system will complete tasks faster than a multi-processor system.   So, for most people, having a multiprocessor system is a waste time, money, and resources.</body></html>
--0__=0ABBE15DDFFADAC38f9e8a93df938690918c0ABBE15DDFFADAC3--




From wolf_binary@hotmail.com  Tue Jun  4 21:30:44 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Tue, 4 Jun 2002 15:30:44 -0500
Subject: [Tutor] re: computers
References: <OF6F8F28CD.E23ABB07-ON85256BCE.00695C53@lotus.com>
Message-ID: <DAV30SimD3JkUwWpSWe0000b299@hotmail.com>

This is a multi-part message in MIME format.

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

Thanks Stuart,

That's what I was thinking.  I wondered if programs would run faster.  I =
was looking into it to make my graphics work, ie: 3D modeling, take less =
time to use.  When doing animation it currently takes me like a =
half-hour to save my work.  This is not a gross overestamation either.  =
It then turns out to be less than 30 sec of animation when I play it.  =
Would having multiple processors make it more efficient?

Thanks,
Cameron Stoner
----- Original Message -----=20
  From: stuart_clemons@us.ibm.com=20
  To: tutor@python.org=20
  Sent: Tuesday, June 04, 2002 2:20 PM
  Subject: [Tutor] re: computers


  FYI. Even if your OS, such as NT, is capable of running on a =
multi-processor system, it does not mean that your programs or compilers =
will run any faster than when run on a single processor system. Most =
programs and compilers do not take advantage of multi-processor systems, =
which is something most people don't seem to realise. In fact, in some =
cases a single processor system will complete tasks faster than a =
multi-processor system. So, for most people, having a multiprocessor =
system is a waste time, money, and resources.


------=_NextPart_000_000A_01C20BDC.CAEC7540
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks Stuart,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>That's what I was thinking.&nbsp; I =
wondered if=20
programs would run faster.&nbsp; I was looking into it to make my =
graphics work,=20
ie: 3D modeling, take less time to use.&nbsp; When doing animation it =
currently=20
takes me like a half-hour to save my work.&nbsp; This is not a gross=20
overestamation either.&nbsp; It then turns out to be less than 30 sec of =

animation when I play it.&nbsp; Would having multiple processors make it =
more=20
efficient?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron Stoner</FONT></DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dstuart_clemons@us.ibm.com=20
  =
href=3D"mailto:stuart_clemons@us.ibm.com">stuart_clemons@us.ibm.com</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, June 04, 2002 =
2:20=20
PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] re: =
computers</DIV>
  <DIV><BR></DIV>
  <P>FYI. Even if your OS, such as NT, is capable of running on a=20
  multi-processor system, it does not mean that your programs or =
compilers will=20
  run any faster than when run on a single processor system. Most =
programs and=20
  compilers do not take advantage of multi-processor systems, which is =
something=20
  most people don't seem to realise. In fact, in some cases a single =
processor=20
  system will complete tasks faster than a multi-processor system. So, =
for most=20
  people, having a multiprocessor system is a waste time, money, and=20
  resources.</P></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000A_01C20BDC.CAEC7540--



From ATrautman@perryjudds.com  Tue Jun  4 22:01:04 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Tue, 4 Jun 2002 16:01:04 -0500
Subject: [Tutor] re: computers
Message-ID: <75EDF89FDE81D511840D00A0C9AD25DD0261A2C6@CORP_EXCHANGE>

Cameron,

This depends a huge amount upon your software and the type of animation.  Is
this vector based animation or pixel resolution? In addition based on the
amount of time it takes to save what amount of RAM is free during your save
edit? Unless you increase you free RAM the two processor unit will use more
RAM to support the second unit so it could be even slower. If the program
supports two processors and most high end programs do it separates the file
and IO function from the vector math functions which will give you a lot
more speed. See the high end MAC workstations as that is what they are
routinely used for. IMHO If you don't have this type of software an upgrade
to a single processor, high end vector video card, high sped hard drive, and
lots of RAM are probably the best answer. 

Peace
Alan
-----Original Message-----
From: Cameron Stoner [mailto:wolf_binary@hotmail.com]
Sent: Tuesday, June 04, 2002 3:31 PM
To: tutor@python.org; stuart_clemons@us.ibm.com
Subject: Re: [Tutor] re: computers


Thanks Stuart,

That's what I was thinking.  I wondered if programs would run faster.  I was
looking into it to make my graphics work, ie: 3D modeling, take less time to
use.  When doing animation it currently takes me like a half-hour to save my
work.  This is not a gross overestamation either.  It then turns out to be
less than 30 sec of animation when I play it.  Would having multiple
processors make it more efficient?

Thanks,
Cameron Stoner
----- Original Message ----- 
From: stuart_clemons@us.ibm.com 
To: tutor@python.org 
Sent: Tuesday, June 04, 2002 2:20 PM
Subject: [Tutor] re: computers


FYI. Even if your OS, such as NT, is capable of running on a multi-processor
system, it does not mean that your programs or compilers will run any faster
than when run on a single processor system. Most programs and compilers do
not take advantage of multi-processor systems, which is something most
people don't seem to realise. In fact, in some cases a single processor
system will complete tasks faster than a multi-processor system. So, for
most people, having a multiprocessor system is a waste time, money, and
resources.



From marcolinux@linuxbr.com.br  Tue Jun  4 22:16:24 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Tue, 4 Jun 2002 18:16:24 -0300
Subject: [Tutor] re: computers
In-Reply-To: <OF6F8F28CD.E23ABB07-ON85256BCE.00695C53@lotus.com>
References: <OF6F8F28CD.E23ABB07-ON85256BCE.00695C53@lotus.com>
Message-ID: <20020604181624.A7870@marcolab.proconet>

stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com) wrote:

> 
> FYI.  Even if your OS, such as NT, is capable of running on a multi-
> processor system, it does not mean that your programs or compilers  will
> run any faster than when run on a single processor system.  Most programs
> and compilers do not take advantage of multi-processor systems, which is
> something most people don't seem to realise.  In fact, in some cases a
> single processor system will complete tasks faster than a multi-processor
> system.   So, for most people, having a multiprocessor system is a waste
> time, money, and resources.

Supose two programs (A,B) not multi-processor aware.
So you are saying that if I run a program A on a multi-processor system,
and call another program B, it will wait for the processor that is
working with A even if I have another processor sitting there 
doing nothing?
Shouldnt the OS take care of that? Or am I missing something?





From stuart_clemons@us.ibm.com  Tue Jun  4 23:24:45 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Tue, 4 Jun 2002 18:24:45 -0400
Subject: [Tutor] re: computers
Message-ID: <OFCDEE529A.93537258-ON85256BCE.007A5BBA@lotus.com>

--0__=0ABBE15DDFE9DD2A8f9e8a93df938690918c0ABBE15DDFE9DD2A
Content-type: text/plain; charset=US-ASCII


Hi Cameron:

I would highly doubt that a two processor system would even minimally speed
up your graphic work.  I would speak with the makers of the 3D modeling
software and get their suggestions on improving performance.  My guess is
that they will suggest a high-end graphics card, more RAM and a faster disk
subsystem (highend SCSI controller and harddrive) and then possibly a
better single processor in that order.  I would not think that they would
even mention adding a second processor, but then, I don't really know all
the details.  Just my guess.  Also, I would guess that Win2000 would run
your software more efficiently than Win98.  Let us know what they say.

- Stuart

---------------------- Forwarded by Stuart Clemons/Westford/IBM on
06/04/2002 06:30 PM ---------------------------


"Cameron Stoner" <wolf_binary@hotmail.com> on 06/04/2002 04:30:44 PM

To:    <tutor@python.org>, <stuart_clemons@us.ibm.com>
cc:
Subject:    Re: [Tutor] re: computers

Thanks Stuart,

That's what I was thinking.  I wondered if programs would run faster.  I
was looking into it to make my graphics work, ie: 3D modeling, take less
time to use.  When doing animation it currently takes me like a half-hour
to save my work.  This is not a gross overestamation either.  It then turns
out to be less than 30 sec of animation when I play it.  Would having
multiple processors make it more efficient?

Thanks,
Cameron Stoner
----- Original Message -----
 From: stuart_clemons@us.ibm.com
 To: tutor@python.org
 Sent: Tuesday, June 04, 2002 2:20 PM
 Subject: [Tutor] re: computers



 FYI. Even if your OS, such as NT, is capable of running on a multi-
 processor system, it does not mean that your programs or compilers will
 run any faster than when run on a single processor system. Most programs
 and compilers do not take advantage of multi-processor systems, which is
 something most people don't seem to realise. In fact, in some cases a
 single processor system will complete tasks faster than a multi-processor
 system. So, for most people, having a multiprocessor system is a waste
 time, money, and resources.



--0__=0ABBE15DDFE9DD2A8f9e8a93df938690918c0ABBE15DDFE9DD2A
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body bgcolor="#FFFFFF">
<p>Hi Cameron:<br>
<br>
I would highly doubt that a two processor system would even minimally speed up your graphic work.  I would speak with the makers of the 3D modeling software and get their suggestions on improving performance.  My guess is that they will suggest a high-end graphics card, more RAM and a faster disk subsystem (highend SCSI controller and harddrive) and then possibly a better single processor in that order.  I would not think that they would even mention adding a second processor, but then, I don't really know all the details.  Just my guess.  Also, I would guess that Win2000 would run your software more efficiently than Win98.  Let us know what they say.<br>
<br>
- Stuart<br>
 <br>
<font color="#800080">----------------------</font><font size="2" color="#800080"> Forwarded by Stuart Clemons/Westford/IBM on 06/04/2002 06:30 PM </font><font color="#800080">---------------------------</font><br>

<p><font size="2" color="#800080">To:	</font><font size="2">&lt;tutor@python.org&gt;, &lt;stuart_clemons@us.ibm.com&gt;</font><br>
<font size="2" color="#800080">cc:	 </font><br>
<font size="2" color="#800080">Subject:	</font><font size="2">Re: [Tutor] re: computers</font><br>
<br>
<font face="Arial">Thanks Stuart,</font><br>
<font size="4" face="Times New Roman"> </font><br>
<font face="Arial">That's what I was thinking.  I wondered if programs would run faster.  I was looking into it to make my graphics work, ie: 3D modeling, take less time to use.  When doing animation it currently takes me like a half-hour to save my work.  This is not a gross overestamation either.  It then turns out to be less than 30 sec of animation when I play it.  Would having multiple processors make it more efficient?</font><br>
<font size="4" face="Times New Roman"> </font><br>
<font face="Arial">Thanks,</font><br>
<font face="Arial">Cameron Stoner</font><br>
<font size="4" face="Times New Roman">----- Original Message ----- </font><br>
<b><font size="4" face="Times New Roman">From:</font></b><font size="4" face="Times New Roman"> </font><a href="mailto:stuart_clemons@us.ibm.com"><u><font size="4" color="#0000FF" face="Times New Roman">stuart_clemons@us.ibm.com</font></u></a><font size="4" face="Times New Roman"> </font><br>
<b><font size="4" face="Times New Roman">To:</font></b><font size="4" face="Times New Roman"> </font><a href="mailto:tutor@python.org"><u><font size="4" color="#0000FF" face="Times New Roman">tutor@python.org</font></u></a><font size="4" face="Times New Roman"> </font><br>
<b><font size="4" face="Times New Roman">Sent:</font></b><font size="4" face="Times New Roman"> Tuesday, June 04, 2002 2:20 PM</font><br>
<b><font size="4" face="Times New Roman">Subject:</font></b><font size="4" face="Times New Roman"> [Tutor] re: computers</font><br>

<p><font size="4" face="Times New Roman">FYI. Even if your OS, such as NT, is capable of running on a multi-processor system, it does not mean that your programs or compilers will run any faster than when run on a single processor system. Most programs and compilers do not take advantage of multi-processor systems, which is something most people don't seem to realise. In fact, in some cases a single processor system will complete tasks faster than a multi-processor system. So, for most people, having a multiprocessor system is a waste time, money, and resources.</font>
<p><br>
</body></html>
--0__=0ABBE15DDFE9DD2A8f9e8a93df938690918c0ABBE15DDFE9DD2A--




From stuart_clemons@us.ibm.com  Wed Jun  5 18:11:11 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Wed, 5 Jun 2002 13:11:11 -0400
Subject: [Tutor] re: computers
Message-ID: <OFF59A104D.5017E5DC-ON85256BCF.00585770@lotus.com>

--0__=0ABBE15CDFCBD1E08f9e8a93df938690918c0ABBE15CDFCBD1E0
Content-type: text/plain; charset=US-ASCII


Hi Marc:

In my experience with NT and multiprocessor systems, running the two "not
multi-processor aware" programs you mentioned would be handled one of two
ways in a two processor system:

1) Believe it or not, one processor would handle the full load of running
both programs.  The second processor would be virtually idle. (In most
cases, this is actually irrelevant to overall performance times)

2) The two processors would each split the load.

In either case, the total time to accomplish whatever task you were asking
the two programs to accomplish would be nearly identical.  There are a
number of reasons for this, but in general terms, one significant reason
related to processors is that the vast majority of programs are not written
to run parallel tasks or threads using multiple processors.

However, more importantly, in the vast majority of program useage, the
processor is not the bottleneck in regards to performance. RAM, bus speed,
disk subsystem, caching, net access, etc all usually have a more
significant impact on program performance than the processor (which is
usually underutilized). In most cases, the number of processors being used
is usually irrelevant to performance.  They can't make disk I/O go faster
or move data across the bus faster, for example.

I've never delved into how NT decides to split its tasks with multiple
processors, mainly because it wasn't that important to me in terms of
overall performance, which is important to me.

Most of my experience is with general use applications and compilers. I
don't have experience with compute intensive applications which are
designed for multiprocessors.  I'm sure in those cases, load-balanced
multiprocessors (and RAM) would be important factors in performance.

Marc wrote:
Supose two programs (A,B) not multi-processor aware.
So you are saying that if I run a program A on a multi-processor system,
and call another program B, it will wait for the processor that is
working with A even if I have another processor sitting there
doing nothing?
Shouldnt the OS take care of that? Or am I missing something?


Message: 6
Date: Tue, 4 Jun 2002 18:16:24 -0300
From: Marc <marcolinux@linuxbr.com.br>
To: tutor@python.org
Subject: Re: [Tutor] re: computers
Organization: "Doo Bee Doo Inc"

stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com) wrote:

>
> FYI.  Even if your OS, such as NT, is capable of running on a multi-
> processor system, it does not mean that your programs or compilers  will
> run any faster than when run on a single processor system.  Most programs
> and compilers do not take advantage of multi-processor systems, which is
> something most people don't seem to realise.  In fact, in some cases a
> single processor system will complete tasks faster than a multi-processor
> system.   So, for most people, having a multiprocessor system is a waste
> time, money, and resources.

--0__=0ABBE15CDFCBD1E08f9e8a93df938690918c0ABBE15CDFCBD1E0
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p><font face="Courier New">Hi Marc:</font><br>
<br>
<font face="Courier New">In my experience with NT and multiprocessor systems, running the two &quot;not multi-processor aware&quot; programs you mentioned would be handled one of two ways in a two processor system:</font><br>
<br>
<font face="Courier New">1) Believe it or not, one processor would handle the full load of running both programs.  The second processor would be virtually idle. (In most cases, this is actually irrelevant to overall performance times)</font><br>
<br>
<font face="Courier New">2) The two processors would each split the load.  </font><br>
<br>
<font face="Courier New">In either case, the total time to accomplish whatever task you were asking the two programs to accomplish would be nearly identical.  There are a number of reasons for this, but in general terms, one significant reason related to processors is that the vast majority of programs are not written to run parallel tasks or threads using multiple processors.  </font><br>
<br>
<font face="Courier New">However, more importantly, in the vast majority of program useage, the processor is not the bottleneck in regards to performance. RAM, bus speed, disk subsystem, caching, net access, etc all usually have a more significant impact on program performance than the processor (which is usually underutilized). In most cases, the number of processors being used is usually irrelevant to performance.  They can't make disk I/O go faster or move data across the bus faster, for example.</font><br>
<br>
<font face="Courier New">I've never delved into how NT decides to split its tasks with multiple processors, mainly because it wasn't that important to me in terms of overall performance, which is important to me. </font><br>
<br>
<font face="Courier New">Most of my experience is with general use applications and compilers. I don't have experience with compute intensive applications which are designed for multiprocessors.  I'm sure in those cases, load-balanced multiprocessors (and RAM) would be important factors in performance.</font><br>
<br>
<font face="Courier New">Marc wrote:</font><br>
<font face="Courier New">Supose two programs (A,B) not multi-processor aware.<br>
So you are saying that if I run a program A on a multi-processor system,<br>
and call another program B, it will wait for the processor that is<br>
working with A even if I have another processor sitting there <br>
doing nothing?<br>
Shouldnt the OS take care of that? Or am I missing something?</font><br>
<br>
<br>
<font face="Courier New">Message: 6<br>
Date: Tue, 4 Jun 2002 18:16:24 -0300<br>
From: Marc &lt;marcolinux@linuxbr.com.br&gt;<br>
To: tutor@python.org<br>
Subject: Re: [Tutor] re: computers<br>
Organization: &quot;Doo Bee Doo Inc&quot;<br>
<br>
stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com) wrote:<br>
<br>
&gt; <br>
&gt; FYI.  Even if your OS, such as NT, is capable of running on a multi-<br>
&gt; processor system, it does not mean that your programs or compilers  will<br>
&gt; run any faster than when run on a single processor system.  Most programs<br>
&gt; and compilers do not take advantage of multi-processor systems, which is<br>
&gt; something most people don't seem to realise.  In fact, in some cases a<br>
&gt; single processor system will complete tasks faster than a multi-processor<br>
&gt; system.   So, for most people, having a multiprocessor system is a waste<br>
&gt; time, money, and resources.<br>
<br>
</font></body></html>
--0__=0ABBE15CDFCBD1E08f9e8a93df938690918c0ABBE15CDFCBD1E0--




From terjeja@hotmail.com  Wed Jun  5 18:36:12 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Wed, 05 Jun 2002 17:36:12 +0000
Subject: [Tutor] xor
Message-ID: <F222dLTX8T1QmbRvVar0000ce26@hotmail.com>

What does really xor do? I tried an example,
>>>  30^76
82

^ means xor if I am completely wrong. I don't see any connection between the 
numbers. Can anyone explain?

Thanks,
Terje

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From paulsid@shaw.ca  Wed Jun  5 18:43:41 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Wed, 05 Jun 2002 11:43:41 -0600
Subject: [Tutor] xor
References: <F222dLTX8T1QmbRvVar0000ce26@hotmail.com>
Message-ID: <3CFE4DCD.EBACB2C3@shaw.ca>

Terje Johan Abrahamsen wrote:

> What does really xor do? I tried an example,
> >>>  30^76
> 82
> 
> ^ means xor if I am completely wrong. I don't see any connection between the
> numbers. Can anyone explain?

XOR works on the binary level.  x XOR y is true if and only if x != y,
where x and y are binary digits (bits).  So if we convert your example
to binary, it makes sense:

  0011110 = 30
^ 1001100 = 76
--------------
  1010010 = 82

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From terjeja@hotmail.com  Wed Jun  5 21:37:09 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Wed, 05 Jun 2002 20:37:09 +0000
Subject: [Tutor] PythonWin
Message-ID: <F121OhBOYtkoaBUIdpm0000f8b5@hotmail.com>

I use Pythonwin instead of the normal IDLE. THe version is 146 which should 
contain Python 2.2. I am currently trying a few of the modules that are 
included, but it seems like quite a few is missing. For example, os.getsize 
as an example. However, others like os.rename exists. It is described in the 
Python book I currently read (Core Python Programming), but is not 
accessible in Pythonwin. The same was the case with a number of modules I 
read about in the newest Python library reference. Am I just not finding 
them, or does the Pythonwin have an amputated number of modules?

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




From dyoo@hkn.eecs.berkeley.edu  Wed Jun  5 21:41:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 5 Jun 2002 13:41:45 -0700 (PDT)
Subject: [Tutor] xor
In-Reply-To: <3CFE4DCD.EBACB2C3@shaw.ca>
Message-ID: <Pine.LNX.4.44.0206051330590.22723-100000@hkn.eecs.berkeley.edu>

On Wed, 5 Jun 2002, Paul Sidorsky wrote:

> Terje Johan Abrahamsen wrote:
>
> > What does really xor do? I tried an example,
> > >>>  30^76
> > 82
> >
> > ^ means xor if I am completely wrong. I don't see any connection
> > between the numbers. Can anyone explain?
>
> XOR works on the binary level.  x XOR y is true if and only if x != y,
> where x and y are binary digits (bits).  So if we convert your example
> to binary, it makes sense:
>
>   0011110 = 30
> ^ 1001100 = 76
> --------------
>   1010010 = 82


XOR stands for "exclusive or", so you can think of it as the "one, or the
other, but not both" bit operation.



On a tangent note, there's a cute trick that assembly and C programmers
could use with XOR to swap two values around without using a temporary
variable.  Here's an interpreter session that shows how it works:

###
>>> a
42
>>> b
24
>>> a = a ^ b
>>> b = a ^ b
>>> a = a ^ b
>>> a
24
>>> b
42
###

(Danny Hillis mentions this trick in his talk with game developers on Dr.
Dobb's Technetcast:

    http://technetcast.ddj.com/tnc_play_stream.html?stream_id=220)



But in Python, to swap two values, it's probably just easier to write:

###
>>> a, b = b, a
###

anyway, so the XOR swap trick is much less useful in Python.  In other
languages, with unusual constraints, it might be a useful thing to know...
*grin*




From wolf_binary@hotmail.com  Thu Jun  6 00:42:49 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 5 Jun 2002 18:42:49 -0500
Subject: [Tutor] special class methods
Message-ID: <DAV67An0PVo3NPiVD2i0000c92f@hotmail.com>

This is a multi-part message in MIME format.

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

Hi all,

Why would you want to use the __add__ special class method in a class?  =
I know what it is soposed to do, but can't you just add two objects =
together.  I read somewhere that in Python everything is an object.  So =
having a special class method used to add objects seem to be redundant =
to me.  Is this true?

Thanks,
Cameron



------=_NextPart_000_0021_01C20CC0.CA858F80
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Why would you want to use the=20
<STRONG>__add__</STRONG> special class method in a class?&nbsp; I know =
what it=20
is soposed to do, but can't you just add two objects together.&nbsp; I =
read=20
somewhere that in Python everything is an object.&nbsp; So having a =
special=20
class method used to add objects seem to be redundant to me.&nbsp; Is =
this=20
true?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0021_01C20CC0.CA858F80--



From paulsid@shaw.ca  Thu Jun  6 01:13:42 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Wed, 05 Jun 2002 18:13:42 -0600
Subject: [Tutor] xor
References: <Pine.LNX.4.44.0206051330590.22723-100000@hkn.eecs.berkeley.edu>
Message-ID: <3CFEA936.C6AE36D5@shaw.ca>

Danny Yoo wrote:

> On a tangent note, there's a cute trick that assembly and C programmers
> could use with XOR to swap two values around without using a temporary
> variable.  Here's an interpreter session that shows how it works:

> >>> a = a ^ b
> >>> b = a ^ b
> >>> a = a ^ b

In C this is usually condensed to the ugly but very efficient
a^=b^=a^=b, which I first saw in Abrash's Zen of Graphics Programming. 
Aside from saving space, it's significantly faster.

Of course, this won't work in Python because a ^= b is an assignment and
assignments don't have values in Python.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From shalehperry@attbi.com  Thu Jun  6 01:51:58 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 05 Jun 2002 17:51:58 -0700 (PDT)
Subject: [Tutor] special class methods
In-Reply-To: <DAV67An0PVo3NPiVD2i0000c92f@hotmail.com>
Message-ID: <XFMail.20020605175158.shalehperry@attbi.com>

On 05-Jun-2002 Cameron Stoner wrote:
> Hi all,
> 
> Why would you want to use the __add__ special class method in a class?  I
> know what it is soposed to do, but can't you just add two objects together. 
> I read somewhere that in Python everything is an object.  So having a special
> class method used to add objects seem to be redundant to me.  Is this true?
> 

when you define __add__ (or its brothers) the interpreter calls them when you
use the respective symbols.

so:

>>> class Foo:
...   def __init__(self, v = 5):
...     self.value = v
...   def __add__(self, other):
...     return self.value * other.value 
... 
>>> a = Foo(3)
>>> b = Foo(7)
>>> a + b
21 # not 10

yes, this is a silly example.  But you define how the class acts with the math
ops by defining the equivalent function.

A more useful example would be something like:

class Rational:
  def __init__(self, top, bottom):
    self.numerator = top
    self.denominator = bottom

  def __add__(self, other):
    # do common denominator math then add the two numbers and reduce

then you could do:

a = Rational(1,2) # 1/2
b = Rational(2,3) # 2/3

c = a + b # 3/6 + 4/6 => 7/6

or

a = Rational(1,3)
b = Rational(1,6)

c = a + b # 2/6 + 1/6 => 3/6 => 1/2



From syrinx@simplecom.net  Thu Jun  6 04:07:38 2002
From: syrinx@simplecom.net (Scott)
Date: Wed, 5 Jun 2002 22:07:38 -0500
Subject: [Tutor] dialup
Message-ID: <20020605220738.42676167.syrinx@simplecom.net>

Hello.  I'm setting up a "Linux From Scratch" system, and thought I
would take a stab at writing my ppp-on script in Python (just for the
heck of it).  Which module should I look at to use to talk to my modem?




From dyoo@hkn.eecs.berkeley.edu  Thu Jun  6 07:13:54 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 5 Jun 2002 23:13:54 -0700 (PDT)
Subject: [Tutor] PythonWin
In-Reply-To: <F121OhBOYtkoaBUIdpm0000f8b5@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206052307160.5683-100000@hkn.eecs.berkeley.edu>


> contain Python 2.2. I am currently trying a few of the modules that are
> included, but it seems like quite a few is missing. For example,
> os.getsize as an example.

Hi Terje,

You're probably thinking of 'os.path.getsize()': The getsize() function is
within the 'os.path' module.


> However, others like os.rename exists. It is described in the Python
> book I currently read (Core Python Programming), but is not accessible
> in Pythonwin.

Hmmm!  This is most likely a typo then; do you have the page number where
it talks about this?  According to Wesley's Core Python Programming Errata
page:

    http://starship.python.net/crew/wesc/cpp/errata.htm

there's no reference to a bug with 'os.getsize', so it sounds like you
found something new.  Maybe you could convince Wes to send a check for
$2.56.  *grin*



> The same was the case with a number of modules I read about in the
> newest Python library reference. Am I just not finding them, or does the
> Pythonwin have an amputated number of modules?

Hmmm!  Not sure about this one.  I'm assuming that the Activestate
distribution of Python has, at least, the Standard Library.  For the
official documentation on the modules that come with Python, you can look
at:

    http://www.python.org/doc/lib/


If you have more questions, please feel free to ask!




From scot@possum.in-berlin.de  Thu Jun  6 05:46:35 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Thu, 6 Jun 2002 06:46:35 +0200
Subject: [Tutor] computers
In-Reply-To: <5.1.0.14.0.20020603222933.02398a30@mail.hal-pc.org>
References: <5.1.0.14.0.20020603222933.02398a30@mail.hal-pc.org>
Message-ID: <200206060646.35212.scot@possum.in-berlin.de>

Hi -=20

> It might be fun to
> practice some multi threaded Python programming with to procs.

Wait a moment. I thought that Python threads weren't really run in parall=
el=20
because of something called the Great Interpreter Lock. Wouldn't this mea=
n=20
that you can have all the processors you want, it will not make Python=20
faster?

(And, concerning another list thread here, wouldn't this be another reaso=
n=20
to use Java instead of Python?)

Y, Scot



From lumbricus@gmx.net  Thu Jun  6 11:18:43 2002
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Thu, 6 Jun 2002 12:18:43 +0200 (MEST)
Subject: [Tutor] dialup
References: <20020605220738.42676167.syrinx@simplecom.net>
Message-ID: <19355.1023358723@www42.gmx.net>

> Hello.  I'm setting up a "Linux From Scratch" system, and thought I
> would take a stab at writing my ppp-on script in Python (just for the
> heck of it).  Which module should I look at to use to talk to my modem?

__builtins__
;-)
man 2 open
man 2 read
man 2 write

HTH, HAND 
and Greetings, J"o!

-- 
sigfault

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net




From ericblack69@yahoo.com  Thu Jun  6 15:14:48 2002
From: ericblack69@yahoo.com (Eric Black)
Date: Thu, 6 Jun 2002 07:14:48 -0700 (PDT)
Subject: [Tutor] tuple sorting
Message-ID: <20020606141448.35195.qmail@web13201.mail.yahoo.com>

Hello all,
I am a newbie who's been lurking here for a couple of
months now and I just love this list. 

While considering the May 20 post of 
Raymond Hettinger:

Convert the outer tuple to a list so that it can be
sorted:

>>> a = ((4,1,8), (9,2,5),(3,6,9))
>>> b = list(a)
>>> b.sort()
>>> a = tuple(b)
>>> print a
((3, 6, 9), (4, 1, 8), (9, 2, 5))

I guess I found a very trivial typo in the
distribution. Is this worth reporting?
>>> tuple(  # the popup says: --> list, not tuple.
>>> tuple.__doc__() ## has the same typo.
'tuple(sequence) -> list\n\nReturn a tuple whose items
are the same as those of the argument sequence.\nIf
the argument is a tuple, the return value is the same
object.'
>>>

This gave me the ambition to rummage in the innards of
python. I know there is a doc string somewhere in the
source but after using windows find tool looking in
C:\Python21 for the text I couldn't find the physical
file where it's located. I am running the windows
executable version of 
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit
(Intel)] on win32
The entries in 7.3.4 Tuple Objects of the Python/C API
Reference Manual imply C code is involved.
If someone could explain where the doc string is and
how to rummage in the innards I would appreciate it.

                    TIA,
                    Eric Black

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Thu Jun  6 15:33:29 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 6 Jun 2002 07:33:29 -0700 (PDT)
Subject: [Tutor] tuple sorting
In-Reply-To: <20020606141448.35195.qmail@web13201.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206060717410.15350-100000@hkn.eecs.berkeley.edu>


> >>> a = ((4,1,8), (9,2,5),(3,6,9))
> >>> b = list(a)
> >>> b.sort()
> >>> a = tuple(b)
> >>> print a
> ((3, 6, 9), (4, 1, 8), (9, 2, 5))
>
> I guess I found a very trivial typo in the distribution. Is this worth
> reporting?

Yes.  Good eyes.  *grin*


The docstring was buggy, but this has been fixed in Python 2.2:

###
Python 2.2.1 (#1, Apr 13 2002, 13:15:33)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print tuple.__doc__
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items

If the argument is a tuple, the return value is the same object.
###



> This gave me the ambition to rummage in the innards of python. I know
> there is a doc string somewhere in the source but after using windows
> find tool looking in C:\Python21 for the text I couldn't find the
> physical file where it's located.

In Python 2.2, it should be located in the Objects/tupleobject.c file; the
docstring is held in a variable called 'tuple_doc'.

I don't have a copy of the Python 2.1 sources handy at the moment, but
looking at Sourceforge, I think I've found it in 'Python/bltinmodule.c':

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/python/python/dist/src/Python/bltinmodule.c?rev=2.197.2.1&only_with_tag=r213


The tuple() function moved between 2.1 to 2.2 as a side effect of the
unification between types and classes:

    http://www.python.org/2.2/descrintro.html

so that explains why it moved from 'bltinmodule.c' to 'tupleobject.c'.


Hope this helps!




From jeff@ccvcorp.com  Thu Jun  6 17:47:32 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 06 Jun 2002 09:47:32 -0700
Subject: [Tutor] computers
References: <5.1.0.14.0.20020603222933.02398a30@mail.hal-pc.org> <200206060646.35212.scot@possum.in-berlin.de>
Message-ID: <3CFF9224.4C5939AB@ccvcorp.com>

"Scot W. Stevenson" wrote:

> Hi -
>
> > It might be fun to
> > practice some multi threaded Python programming with to procs.
>
> Wait a moment. I thought that Python threads weren't really run in parallel
> because of something called the Great Interpreter Lock. Wouldn't this mean
> that you can have all the processors you want, it will not make Python
> faster?

Actually, it's the Global (not great) Interpreter Lock, but this is largely
true.  The Python interpreter itself has been made "threadsafe" in a rather
crude (but effective) way -- by only allowing a single Python thread to run at
a time.  This means that the only possible way that multithreading can speed up
a Python program is if it spends a fair amount of time either waiting for I/O,
or in C extensions (which release the GIL).  Of course, considering how few
people use multiproc systems, and that few of *those* will distribute threads
from a single process across different processors, the GIL is much less of a
bottleneck than it sounds like.  Especially when you consider that the majority
of real-world programs are I/O bound (or memory bound), not CPU bound -- the
processor spends a fair amount of time sitting idle anyhow, so squeezing CPU
efficiency any further tends to not have much practical effect.

The real advantage to multithreading is that it separates your program into
distinct, logical tasks, making it easier to understand what's going on (if
you're separating tasks right ;) ).  Only in very special cases does
multithreading really help with program speed.


> (And, concerning another list thread here, wouldn't this be another reason
> to use Java instead of Python?)

In a word, no.  ;)  First of all, on many platforms Java (IIRC) emulates
threads in a nonthreaded environment ("green" threads), with semantics that are
similar to Python's GIL (but weaker, because the GIL is typically released in
extensions).  Second, and more importantly, efficient use of multiple
processors (even if Java offered that) is typically a poor reason to choose a
language to develop in -- as mentioned above, it's probably not going to result
in a faster program.  And if you really needed that efficiency, then you should
be coding in C, not Java.

The point of using Python is that it's easier/faster to develop software with
it.  The (hypothetical) advantages that Java offers for SMP environments are
rarely going to be enough of a benefit to override the extra costs of
developing in Java.

Jeff Shannon
Technician/Programmer
Credit International





From jeff@ccvcorp.com  Thu Jun  6 17:56:50 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 06 Jun 2002 09:56:50 -0700
Subject: [Tutor] PythonWin
References: <Pine.LNX.4.44.0206052307160.5683-100000@hkn.eecs.berkeley.edu>
Message-ID: <3CFF9452.7B471D58@ccvcorp.com>


Danny Yoo wrote:

> > contain Python 2.2. I am currently trying a few of the modules that are
> > included, but it seems like quite a few is missing. [...]
>
> > The same was the case with a number of modules I read about in the
> > newest Python library reference. Am I just not finding them, or does the
> > Pythonwin have an amputated number of modules?
>
> Hmmm!  Not sure about this one.  I'm assuming that the Activestate
> distribution of Python has, at least, the Standard Library.

I have been using the ActiveState ActivePython distribution (and the
Windows-only IDE included with it, PythonWin) for versions 2.0, 2.1, and 2.2
now.  I have not yet found a single module available in the PythonLabs Windows
distribution that is not available in ActiveState's distribution.

However, you may be reading, in that library reference, about a number of
OS-specific modules.  There's a fair amount of stuff that's included on
Unix-ish distributions that isn't there in Windows distributions, simply
because the OS can't support it (or doesn't need it).  For example, the curses
module doesn't exist on Windows because there's no underlying curses library
for it to interface to -- Windows uses a different method to control terminal
screens.  Conversely, there's modules that are available for Windows that have
no Unix equivalents -- most notably Mark Hammond's Win32 extensions, which are
packaged with ActivePython.

I'd suggest checking the library reference a little more closely for the OS
availability.  I'm guessing that you'll see that those "missing" modules are
Unix-only.  (Or, like os.path.getsize(), you may be mistakenly looking for
them in the wrong place...)

Of course, if you *do* find anything that claims Windows availability, but you
don't have, we'd like to hear about it.  :)

Jeff Shannon
Technician/Programmer
Credit International





From stuart_clemons@us.ibm.com  Thu Jun  6 18:57:02 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Thu, 6 Jun 2002 13:57:02 -0400
Subject: [Tutor] Reading & printing lines from two different files
Message-ID: <OF8C3A0CA3.E7B35732-ON85256BD0.005FAFDC@lotus.com>

--0__=0ABBE143DFCC294C8f9e8a93df938690918c0ABBE143DFCC294C
Content-type: text/plain; charset=US-ASCII


Hi all:

I have two files, file1 and file2.  I want to print the first line from
file1, then the first line from file2, then the second line from file 1,
then the second line from file 2, etc.

Here are my files and what the output should look like:

File1.txt
First line file 1
Second line file 1
Third line file 1

File2.txt
First line file 2
Second line file 2
Third line file 3

This is the output I want when the program is run:

First line file 1
First line file 2
Second line file 1
Second line file 2
Third line file 1
Third line file 2

I've tried different looping techniques mainly using variations of the
structure below, but I can't seem to get the output I want.  Any
suggestions ?  Thanks.

infile1 = open('c:\file1.txt', 'r')
infile2 = open ('c:\file2.txt', 'r')
      for line1 in infile1.readlines():
            print line1
      for line2 in infile2.readlines()
            print line2
--0__=0ABBE143DFCC294C8f9e8a93df938690918c0ABBE143DFCC294C
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p>Hi all:<br>
<br>
I have two files, file1 and file2.  I want to print the first line from file1, then the first line from file2, then the second line from file 1, then the second line from file 2, etc.<br>
<br>
Here are my files and what the output should look like:<br>
<br>
File1.txt<br>
First line file 1<br>
Second line file 1<br>
Third line file 1<br>
<br>
File2.txt<br>
First line file 2<br>
Second line file 2<br>
Third line file 3<br>
<br>
This is the output I want when the program is run:<br>
<br>
First line file 1<br>
First line file 2<br>
Second line file 1<br>
Second line file 2<br>
Third line file 1<br>
Third line file 2<br>
<br>
I've tried different looping techniques mainly using variations of the structure below, but I can't seem to get the output I want.  Any suggestions ?  Thanks.<br>
<br>
infile1 = open('c:\file1.txt', 'r')<br>
infile2 = open ('c:\file2.txt', 'r')<br>
	for line1 in infile1.readlines():<br>
		print line1<br>
	for line2 in infile2.readlines()<br>
		print line2<br>
</body></html>
--0__=0ABBE143DFCC294C8f9e8a93df938690918c0ABBE143DFCC294C--




From jeff@ccvcorp.com  Thu Jun  6 19:48:15 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 06 Jun 2002 11:48:15 -0700
Subject: [Tutor] Reading & printing lines from two different files
References: <OF8C3A0CA3.E7B35732-ON85256BD0.005FAFDC@lotus.com>
Message-ID: <3CFFAE6F.F218950@ccvcorp.com>


stuart_clemons@us.ibm.com wrote:

> Hi all:
>
> I have two files, file1 and file2. I want to print the first line
> from file1, then the first line from file2, then the second line
> from file 1, then the second line from file 2, etc.

What do you want to do if one file is shorter than the other?

The basic method I would use would probably go something like this --

import sys

file1 = open('file1', 'r')
file2 = open('file2', 'r')

while 1:
    line1 = file1.readline()
    sys.stdout.write(line1)
    line2 = file2.readline()
    sys.stdout.write(line2)
    if not line1 and not line2:
        break

This will print interleaved lines until one file is exhausted, print
the remaining lines from the other file, and then break.  You can
alter this behavior by adjusting the conditions for the break
statement.  For example, 'if not line1 or not line2' would cause
printing to stop as soon as either file is exhausted.

You're probably wondering what that sys.stdout.write() stuff is.  I
used that instead of print, because print will add newlines (and
sometimes spaces).  Often this is useful, but since you're reading
lines from a file, they already have a newline at the end of them.  I
*could* strip that newline off before printing, but there's another
problem.  When one file is exhausted (we've reached EOF on it),
readline() will return an empty string, and printing that empty string
will output an extra space.  I could test for an empty line, too
(either before or after stripping the newline), but it's easier to use
sys.stdout.write(), which sends an exact string to the standard
output, without doing any of the "helpful" formatting that print
does.  This way, I use the newlines from the file without needing to
fiddle with them, and write()ing an empty string does nothing --
exactly what I want.

Hope this helps...

Jeff Shannon
Technician/Programmer
Credit International





From ak@silmarill.org  Thu Jun  6 20:01:39 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Thu, 6 Jun 2002 15:01:39 -0400
Subject: [Tutor] Reading & printing lines from two different files
In-Reply-To: <OF8C3A0CA3.E7B35732-ON85256BD0.005FAFDC@lotus.com>
References: <OF8C3A0CA3.E7B35732-ON85256BD0.005FAFDC@lotus.com>
Message-ID: <20020606190139.GA4566@ak.silmarill.org>

On Thu, Jun 06, 2002 at 01:57:02PM -0400, stuart_clemons@us.ibm.com wrote:
> 
> Hi all:
> 
> I have two files, file1 and file2.  I want to print the first line from
> file1, then the first line from file2, then the second line from file 1,
> then the second line from file 2, etc.
> 
> Here are my files and what the output should look like:
> 
> File1.txt
> First line file 1
> Second line file 1
> Third line file 1
> 
> File2.txt
> First line file 2
> Second line file 2
> Third line file 3
> 
> This is the output I want when the program is run:
> 
> First line file 1
> First line file 2
> Second line file 1
> Second line file 2
> Third line file 1
> Third line file 2
> 
> I've tried different looping techniques mainly using variations of the
> structure below, but I can't seem to get the output I want.  Any
> suggestions ?  Thanks.
> 
> infile1 = open('c:\file1.txt', 'r')
> infile2 = open ('c:\file2.txt', 'r')
>       for line1 in infile1.readlines():
>             print line1
>       for line2 in infile2.readlines()
>             print line2
>

while 1:
    l = file1.readline()
    if not l: break
    print l
    l = file2.readline()
    if not l: break
    print l

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From stuart_clemons@us.ibm.com  Thu Jun  6 20:02:36 2002
From: stuart_clemons@us.ibm.com (stuart_clemons@us.ibm.com)
Date: Thu, 6 Jun 2002 15:02:36 -0400
Subject: [Tutor] Reading & printing lines from two different files
Message-ID: <OF441F1AA7.455C6C9D-ON85256BD0.0067B872@lotus.com>

--0__=0ABBE143DFF43EE28f9e8a93df938690918c0ABBE143DFF43EE2
Content-type: text/plain; charset=US-ASCII


Thanks Jeff.  Your structure works perfectly.  I really appreciate the
intro to this structure and also the explanation of sys.stdout.write()!  I
think I can really build off of this.

It's coming slowly, but I'm learning.

Thanks again,

- Stuart

---------------------- Forwarded by Stuart Clemons/Westford/IBM on
06/06/2002 03:09 PM ---------------------------


"Jeff Shannon" <jeff@ccvcorp.com> on 06/06/2002 02:48:15 PM

To:    stuart_clemons@us.ibm.com
cc:    tutor@python.org
Subject:    Re: [Tutor] Reading & printing lines from two different files



stuart_clemons@us.ibm.com wrote:

> Hi all:
>
> I have two files, file1 and file2. I want to print the first line
> from file1, then the first line from file2, then the second line
> from file 1, then the second line from file 2, etc.

What do you want to do if one file is shorter than the other?

The basic method I would use would probably go something like this --

import sys

file1 = open('file1', 'r')
file2 = open('file2', 'r')

while 1:
    line1 = file1.readline()
    sys.stdout.write(line1)
    line2 = file2.readline()
    sys.stdout.write(line2)
    if not line1 and not line2:
        break

This will print interleaved lines until one file is exhausted, print
the remaining lines from the other file, and then break.  You can
alter this behavior by adjusting the conditions for the break
statement.  For example, 'if not line1 or not line2' would cause
printing to stop as soon as either file is exhausted.

You're probably wondering what that sys.stdout.write() stuff is.  I
used that instead of print, because print will add newlines (and
sometimes spaces).  Often this is useful, but since you're reading
lines from a file, they already have a newline at the end of them.  I
*could* strip that newline off before printing, but there's another
problem.  When one file is exhausted (we've reached EOF on it),
readline() will return an empty string, and printing that empty string
will output an extra space.  I could test for an empty line, too
(either before or after stripping the newline), but it's easier to use
sys.stdout.write(), which sends an exact string to the standard
output, without doing any of the "helpful" formatting that print
does.  This way, I use the newlines from the file without needing to
fiddle with them, and write()ing an empty string does nothing --
exactly what I want.

Hope this helps...

Jeff Shannon
Technician/Programmer
Credit International




--0__=0ABBE143DFF43EE28f9e8a93df938690918c0ABBE143DFF43EE2
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p>Thanks Jeff.  Your structure works perfectly.  I really appreciate the intro to this structure and also the explanation of sys.stdout.write()!  I think I can really build off of this.<br>
<br>
It's coming slowly, but I'm learning.<br>
<br>
Thanks again,<br>
<br>
- Stuart<br>
<br>
<font color="#800080">----------------------</font><font size="2" color="#800080"> Forwarded by Stuart Clemons/Westford/IBM on 06/06/2002 03:09 PM </font><font color="#800080">---------------------------</font><br>

<p><font size="2" color="#800080">To:	</font><font size="2">stuart_clemons@us.ibm.com</font><br>
<font size="2" color="#800080">cc:	</font><font size="2">tutor@python.org</font><font size="2" color="#800080"> </font><br>
<font size="2" color="#800080">Subject:	</font><font size="2">Re: [Tutor] Reading &amp; printing lines from two different files</font><br>
<br>
<font face="Courier New"><br>
<br>
stuart_clemons@us.ibm.com wrote:<br>
<br>
&gt; Hi all:<br>
&gt;<br>
&gt; I have two files, file1 and file2. I want to print the first line<br>
&gt; from file1, then the first line from file2, then the second line<br>
&gt; from file 1, then the second line from file 2, etc.<br>
<br>
What do you want to do if one file is shorter than the other?<br>
<br>
The basic method I would use would probably go something like this --<br>
<br>
import sys<br>
<br>
file1 = open('file1', 'r')<br>
file2 = open('file2', 'r')<br>
<br>
while 1:<br>
    line1 = file1.readline()<br>
    sys.stdout.write(line1)<br>
    line2 = file2.readline()<br>
    sys.stdout.write(line2)<br>
    if not line1 and not line2:<br>
        break<br>
<br>
This will print interleaved lines until one file is exhausted, print<br>
the remaining lines from the other file, and then break.  You can<br>
alter this behavior by adjusting the conditions for the break<br>
statement.  For example, 'if not line1 or not line2' would cause<br>
printing to stop as soon as either file is exhausted.<br>
<br>
You're probably wondering what that sys.stdout.write() stuff is.  I<br>
used that instead of print, because print will add newlines (and<br>
sometimes spaces).  Often this is useful, but since you're reading<br>
lines from a file, they already have a newline at the end of them.  I<br>
*could* strip that newline off before printing, but there's another<br>
problem.  When one file is exhausted (we've reached EOF on it),<br>
readline() will return an empty string, and printing that empty string<br>
will output an extra space.  I could test for an empty line, too<br>
(either before or after stripping the newline), but it's easier to use<br>
sys.stdout.write(), which sends an exact string to the standard<br>
output, without doing any of the &quot;helpful&quot; formatting that print<br>
does.  This way, I use the newlines from the file without needing to<br>
fiddle with them, and write()ing an empty string does nothing --<br>
exactly what I want.<br>
<br>
Hope this helps...<br>
<br>
Jeff Shannon<br>
Technician/Programmer<br>
Credit International<br>
<br>
<br>
</font><br>
<br>
</body></html>
--0__=0ABBE143DFF43EE28f9e8a93df938690918c0ABBE143DFF43EE2--




From amd@atlas.ucpel.tche.br  Thu Jun  6 21:44:23 2002
From: amd@atlas.ucpel.tche.br (Aurelio Magalhaes Dias)
Date: Thu, 6 Jun 2002 17:44:23 -0300 (BRT)
Subject: [Tutor] SWIG !!!
Message-ID: <Pine.LNX.4.44L.0206061741250.29328-100000@atlas.ucpel.tche.br>

Hi, I'm writing a Python/C++ API, and I would like to know if exists a
good tutorial for working with SWIG and classes.

Thanks, Aur=E9lio.

-----------------------------------------
        Aur=E9lio Magalh=E3es Dias
        Ci=EAncia da Computa=E7=E3o
        UCPel - RS - Brasil
-----------------------------------------




From dyoo@hkn.eecs.berkeley.edu  Thu Jun  6 22:40:53 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 6 Jun 2002 14:40:53 -0700 (PDT)
Subject: [Tutor] Reading & printing lines from two different files
In-Reply-To: <20020606190139.GA4566@ak.silmarill.org>
Message-ID: <Pine.LNX.4.44.0206061351080.25033-100000@hkn.eecs.berkeley.edu>


> > Here are my files and what the output should look like:
> >
> > File1.txt
> > First line file 1
> > Second line file 1
> > Third line file 1
> >
> > File2.txt
> > First line file 2
> > Second line file 2
> > Third line file 3
> >
> > This is the output I want when the program is run:
> >
> > First line file 1
> > First line file 2
> > Second line file 1
> > Second line file 2
> > Third line file 1
> > Third line file 2
> >
>
>
> while 1:
>     l = file1.readline()
>     if not l: break
>     print l
>     l = file2.readline()
>     if not l: break
>     print l

We can use another approach, using zip(), if both files aren't too long
and are of the same length:

###
for (line1, line2) in zip(file1.readlines(), file2.readlines()):
    print line1
    print line2
###

zip() will ruffle-shuffle the two lists, to make it easy to grab
corresponding elements.


(If the files are actually much longer, we might not need to abandon this
appraoch: we can use a variation of the zip() function by using Python 2.2
generators that's less of a memory hog.)






From phthenry@earthlink.net  Thu Jun  6 22:30:51 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Thu, 6 Jun 2002 17:30:51 -0400
Subject: [Tutor] time module missing
Message-ID: <20020606173051.A5545@localhost.localdomain>

I uninstalled python 2.2 and re-installed python 2.1 yesterday.
Everything worked fine, including scripts that used the time
module. However, when I try to installed 4Suite, it informed me
that it could not find the time module. I fired up python, and
found that it is in fact missing. 

I know I'm overlooking something simple. 

In order to unistall 2.2, I renamed the 2.2 library
"python2.2.temp." I did the same with the executable in /usr/bin.

I then ran ./configure, then make, and the make install. 

If I do 

import os

I get no error.

I believe time is a built in module (?). I can't find any module
name time in my library.

Thanks

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From phthenry@earthlink.net  Thu Jun  6 22:50:12 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Thu, 6 Jun 2002 17:50:12 -0400
Subject: [Tutor] time module missing
In-Reply-To: <20020606173051.A5545@localhost.localdomain>
References: <20020606173051.A5545@localhost.localdomain>
Message-ID: <20020606175012.A6010@localhost.localdomain>

On Thu, Jun 06, 2002 at 05:30:51PM -0400, Paul Tremblay wrote:
> From: Paul Tremblay <phthenry@earthlink.net>
> To: tutor@python.org
> User-Agent: Mutt/1.3.21i
> Subject: [Tutor] time module missing
> Date: Thu, 6 Jun 2002 17:30:51 -0400
> 
> I uninstalled python 2.2 and re-installed python 2.1 yesterday.
> Everything worked fine, including scripts that used the time
> module. However, when I try to installed 4Suite, it informed me
> that it could not find the time module. I fired up python, and
> found that it is in fact missing. 
>

Never mind. I had to set a variable called PYTHONHOME in order to
gnucash. I set this variable to /home/usr/lib/python2.1. 

I just unset this variable, and python can now find the time
module.

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From israel@lith.com  Thu Jun  6 23:49:27 2002
From: israel@lith.com (Israel Evans)
Date: Thu, 6 Jun 2002 15:49:27 -0700
Subject: [Tutor] Levels of Politeness, or Granularity and Placement of Methods?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B41A8@abbott.lith.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_01C20DAC.69974E15
Content-Type: text/plain

 
I have a question for the Tutor Community that pertains to OOP and, um other
stuff like that.  :-)
 
Let's say that I have a couple of types of objects:  A Player and a Card.
 
 
#####
#The Player would have look a little like this...(no methods or functions
yet)
 
class Player:
            def __init__(self, name):
                        self.name = name
                        self.coolness = 0
                        self.pythonicallity = 0
                        self.hand = []
                        self.applied_cards = []
 
#The Card would have look a little like this...(no methods or functions yet)
 
class Card:
            def __init__(self, name, suit, effects):
                        self.name = name
                        self.suit = suit
                        self.effects = effects
 
#Here I'll set up a couple of Cards
 
cool_card = Card('coolio', 'ice', {'coolness': 10}
snake_card = Card('Pythorlo the Pseudo Coder', 'slitherin',
{'pythonicallity':10}
 
 
And gather them into a list called deck.
#
deck = [cool_card, snake_card]
 
 
Now I've got a couple of functions for applying the effects of the card to
the Player's attributes, but I'm wondering how "polite" I should make them.
 
As it stands, the functions I have, take a look at the cards' innards and
applies the effects to the Players attributes. For instance the applyCard
function...
 
# inside Player
            def applyCard(self, deck, card):
                        self.applied_cards.append(deck.pop(card))
                        for effect in card.effects:
                                    self.__dict__[effect] = card[effect]
 
Instead of grubbing around inside of the card should the Player politely ask
the Card for the effect data and wait for an answer, then apply what given
to it to it's attributes?
Maybe something like the following...
 
# inside Card
            def reportEffects(self):
                        return self.effects
 
# inside Player
            def applyCard(self, deck, card)
                        self.applied_cards.append(deck.pop(card))
                        effects = card.reportEffects()
                        for effect in effects:
                                    self.__dict__[effect] = effects[effect]
 
 
I guess what I'm asking is :  Should "Communicate" with each other like
equals, or should they "Use" each other.  It seems that the more polite an
object is the easier it will be for the objects it deals with to change how
they work internally, but still retain functionality later on. 
 
What would your suggestions be on this subject?
 
Thanks,
                        
 
 
~Israel~
 

------_=_NextPart_001_01C20DAC.69974E15
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C20D71.C96748D0">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"country-region"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;
	mso-font-charset:2;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:0 268435456 0 0 -2147483648 0;}
@font-face
	{font-family:PMingLiU;
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-alt:\00A1Ps2OcuAe;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
@font-face
	{font-family:"\@PMingLiU";
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:PMingLiU;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-language:EN-US;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@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>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I have a question for the Tutor Community that =
pertains to
OOP and, um other stuff like that.<span =
style=3D'mso-spacerun:yes'>&nbsp; </span></span></font><font
size=3D2 face=3DWingdings><span =
style=3D'font-size:10.0pt;font-family:Wingdings;
mso-ascii-font-family:Arial;mso-hansi-font-family:Arial;mso-bidi-font-fa=
mily:
Arial;mso-char-type:symbol;mso-symbol-font-family:Wingdings'><span
style=3D'mso-char-type:symbol;mso-symbol-font-family:Wingdings'>J</span>=
</span></font><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><o:p></o:p></span></font></=
p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Let's say that I have a couple of types of =
objects:<span
style=3D'mso-spacerun:yes'>&nbsp; </span>A Player and a =
Card.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>#####<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>#The Player would have look a little like this<span
class=3DGramE>...(</span>no methods or functions =
yet)<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DGramE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>class</span></font></span><=
font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> =
Player:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>def</span> __init__(self, =
name):<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.name</span> =3D name<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.coolness</span> =3D 0<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.pythonicallity</span> =3D =
0<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.hand</span> =3D []<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.applied_cards</span> =3D =
[]<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>#The Card would have look a little like this<span
class=3DGramE>...(</span>no methods or functions =
yet)<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DGramE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>class</span></font></span><=
font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> =
Card:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>def</span> __init__(self, name, suit, =
effects):<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.name</span> =3D name<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.suit</span> =3D suit<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.effects</span> =3D =
effects<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>#<span class=3DGramE>Here</span> I'll set up a =
couple of
Cards<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DSpellE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>cool_card</span></font></sp=
an><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> =3D <span
class=3DGramE>Card(</span>'<span class=3DSpellE>coolio</span>', 'ice',
{'coolness': 10}<o:p></o:p></span></font></p>

<p class=3DMsoNormal><span class=3DSpellE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>snake_card</span></font></s=
pan><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> =3D <span
class=3DGramE>Card(</span>'<span class=3DSpellE>Pythorlo</span> the =
Pseudo
Coder', '<span class=3DSpellE>slitherin</span>', =
{'pythonicallity':10}<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>And gather them into a list called =
deck.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>#<o:p></o:p></span></font></p>

<p class=3DMsoNormal><span class=3DGramE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>deck</span></font></span><f=
ont
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> =3D [<span
class=3DSpellE>cool_card</span>, <span =
class=3DSpellE>snake_card</span>]<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Now I've got a couple of functions for applying the
effects of the card to the Player's attributes, but I'm wondering
how "polite" I should make them.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>As it stands, the functions I <span =
class=3DGramE>have,</span>
take a look at the cards' innards and applies the effects to the =
Players
attributes. For instance the <span class=3DSpellE>applyCard</span> =
function...<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'># <span class=3DGramE>inside</span> =
Player<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>def</span> <span class=3DSpellE>applyCard</span>(self, =
deck, card):<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.applied_<span =
class=3DGramE>cards.append</span></span><span
class=3DGramE>(</span><span =
class=3DSpellE>deck.pop</span>(card))<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>for</span> effect in <span =
class=3DSpellE>card.effects</span>:<br>
<span =
style=3D'mso-tab-count:3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.__dict</span>_<span class=3DGramE>_[</span>effect] =
=3D
card[effect]<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Instead of grubbing around inside of the card should =
the
Player politely ask the Card for the effect data and wait for an =
answer, then
apply what given to it to <span class=3DGramE>it's</span> =
attributes?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Maybe something like the =
following...<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'># <span class=3DGramE>inside</span> =
Card<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>def</span> <span =
class=3DSpellE>reportEffects</span>(self):<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>return</span> <span =
class=3DSpellE>self.effects</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'># <span class=3DGramE>inside</span> =
Player<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>def</span> <span class=3DSpellE>applyCard</span>(self, =
deck, card)<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.applied_<span =
class=3DGramE>cards.append</span></span><span
class=3DGramE>(</span><span =
class=3DSpellE>deck.pop</span>(card))<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>effects</span> =3D <span =
class=3DSpellE>card.reportEffects</span>()<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>for</span> effect in effects:<br>
<span =
style=3D'mso-tab-count:3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>self.__dict</span>_<span class=3DGramE>_[</span>effect] =
=3D effects[effect]<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I guess what I'm asking <span class=3DGramE>is =
:</span><span
style=3D'mso-spacerun:yes'>&nbsp; </span>Should "Communicate" with
each other like equals, or should they "Use" each other.<span
style=3D'mso-spacerun:yes'>&nbsp; </span>It seems that the more polite =
an object
is the easier it will be for the objects it deals with to change how =
they work
internally, but still retain functionality later on. =
<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>What would your suggestions be on this =
subject?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Thanks,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><span =
style=3D'mso-tab-count:2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt;font-family:"Courier =
New";mso-no-proof:yes'>~</span></font><st1:country-region><st1:place><fo=
nt
  size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
  =
mso-no-proof:yes'>Israel</span></font></st1:place></st1:country-region><=
font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
mso-no-proof:yes'>~<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01C20DAC.69974E15--



From dman@dman.ddts.net  Fri Jun  7 00:10:49 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 6 Jun 2002 18:10:49 -0500
Subject: [Tutor] computers
In-Reply-To: <3CFF9224.4C5939AB@ccvcorp.com>
References: <5.1.0.14.0.20020603222933.02398a30@mail.hal-pc.org> <200206060646.35212.scot@possum.in-berlin.de> <3CFF9224.4C5939AB@ccvcorp.com>
Message-ID: <20020606231049.GA23333@dman.ddts.net>

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

On Thu, Jun 06, 2002 at 09:47:32AM -0700, Jeff Shannon wrote:
| "Scot W. Stevenson" wrote:
=20
| > (And, concerning another list thread here, wouldn't this be another rea=
son
| > to use Java instead of Python?)
|=20
| In a word, no.  ;)  First of all, on many platforms Java (IIRC)
| emulates threads in a nonthreaded environment ("green" threads),
| with semantics that are similar to Python's GIL (but weaker, because
| the GIL is typically released in extensions).=20

I know for a fact that the Blackdown port of Sun's JDK uses native
threads on linux.  On solaris I know the admin/user has a choice
between native and "green" (user-space) threads.  If you want an
empirical comparision of green and native threads on Solaris/SPARC
configurations look around at java.sun.com.  I once read an article
there on the topic, and it included graphs as well.

Still, there are advantages to java's green threads over python's
threads on a multiproc system.  Java's green threads are User Space
threads -- they consume only a single kernel-level thread.  Thus java
will be (naturally) constrained to a single CPU.  Python uses
kernel-level threads, and you can end up with a multi-threaded python
app hogging both CPUs but not making effective use of both of them.

| Second, and more importantly, efficient use of multiple processors
| (even if Java offered that) is typically a poor reason to choose a
| language to develop in -- as mentioned above, it's probably not
| going to result in a faster program.  And if you really needed that
| efficiency, then you should be coding in C, not Java.
=20
Wholeheartedly agreed on both points.

| The point of using Python is that it's easier/faster to develop
| software with it.  The (hypothetical) advantages that Java offers
| for SMP environments are rarely going to be enough of a benefit to
| override the extra costs of developing in Java.

Right.  If you really need (or just want) to take full adavantage of
SMP hardware you need to use separate processes anyways with some sort
of efficient IPC (or shmem?) between them.  The problem with threads
is=20
    1)  they lead to greater programmer error
            -- not synchronizing when necessary
            -- deadlock
            -- bottlenecks due to locking (and thus blocking other threads)

    2)  they have overhead and must interact in unusual ways.  For one
        thing you can't kill a thread from another thread.  The best
        you can do is ask it to die and hope it behaves well.  There
        is no "SIGKILL" equilvalent for threads because they are part
        of the same process.  With separate processes you can kill an
        external process.

HTH,
-D

--=20

Pleasant words are a honeycomb,
sweet to the soul and healing to the bones.
        Proverbs 16:24
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAjz/6/kACgkQO8l8XBKTpRSd0wCfSry71+SqUdlGn+HqU0rIXcYX
EKEAn1zKn3tzT73iMiANI114ufFzbkFN
=EJ9e
-----END PGP SIGNATURE-----

--ew6BAiZeqk4r7MaW--



From idiot1@netzero.net  Fri Jun  7 06:07:54 2002
From: idiot1@netzero.net (Kirk 'Deliberatus' Bailey)
Date: Fri, 07 Jun 2002 01:07:54 -0400
Subject: [Tutor] ouch...
Message-ID: <3D003FA9.3A5DB129@netzero.net>

my computer died. This comes to you from my wife Bea's computer. HDD
controller board done screwed the pooch, bought the farm, failed the
smoke test.
4 years of work, poof.

DAMN glad most of it is in the server.




From pmcnally@alltel.net  Fri Jun  7 07:22:26 2002
From: pmcnally@alltel.net (Paul McNally)
Date: Fri, 7 Jun 2002 00:22:26 -0600
Subject: [Tutor] ouch...
References: <3D003FA9.3A5DB129@netzero.net>
Message-ID: <00b401c20deb$b16ad740$3b5928a2@adsl.navix.net>

It's passed on!  This computer is no more!  It has ceased
   to be!  It's expired and gone to meet 'is maker!  It's a stiff!  Bereft
   of life, it rests in peace!  It's electronic processes are now 'istory!
It's off
   the twig!  It kicked the bucket, It's shufflled off 'is mortal coil, run
   down the curtain and joined the bleedin' choir invisibile!!
   THIS IS AN EX-COMPUTER!!

----- Original Message -----
From: "Kirk 'Deliberatus' Bailey" <idiot1@netzero.net>
To: <tutor@python.org>; <tinylist-devlopers@tinylist.org>;
<tinylist-users@tinylist.org>; <isp-chat@isp-chat.org>
Sent: Thursday, June 06, 2002 11:07 PM
Subject: [Tutor] ouch...


my computer died. This comes to you from my wife Bea's computer. HDD
controller board done screwed the pooch, bought the farm, failed the
smoke test.
4 years of work, poof.

DAMN glad most of it is in the server.



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





From dyoo@hkn.eecs.berkeley.edu  Fri Jun  7 07:41:06 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 6 Jun 2002 23:41:06 -0700 (PDT)
Subject: [Tutor] ouch...
In-Reply-To: <3D003FA9.3A5DB129@netzero.net>
Message-ID: <Pine.LNX.4.44.0206062334130.7808-100000@hkn.eecs.berkeley.edu>


On Fri, 7 Jun 2002, Kirk 'Deliberatus' Bailey wrote:

> my computer died. This comes to you from my wife Bea's computer. HDD
> controller board done screwed the pooch, bought the farm, failed the
> smoke test. 4 years of work, poof.

Ouch.  Sorry to hear that!


> DAMN glad most of it is in the server.

You're very lucky.  Backing up data is very prudent, even if it is on a
server.  With hard drive capacities in the tens of gigabytes, there's so
much more to be lost in a hard drive crash.  I almost lost my web page and
all my source code when my school's server died!  Without backups, all
that source code would have been flushed.




From scot@possum.in-berlin.de  Fri Jun  7 07:54:04 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Fri, 7 Jun 2002 08:54:04 +0200
Subject: [Tutor] Reading & printing lines from two different files
In-Reply-To: <Pine.LNX.4.44.0206061351080.25033-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0206061351080.25033-100000@hkn.eecs.berkeley.edu>
Message-ID: <200206070854.04671.scot@possum.in-berlin.de>

Hi there,=20

Danny Yoo wrote:

> (If the files are actually much longer, we might not need to abandon
> this appraoch: we can use a variation of the zip() function by using
> Python 2.2 generators that's less of a memory hog.)

Would this be something like:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D

from __future__ import generators

file_one =3D 'text1.txt'
file_two =3D 'text2.txt'

def generate_line(filename):
    thisfile =3D open(filename, 'r')
    for line in thisfile:
        yield line

gen_one =3D generate_line(file_one)
gen_two =3D generate_line(file_two)

while 1:
    try:
        print gen_one.next()
        print gen_two.next()
    except StopIteration:
        break

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D

This does work here, tho it seems like an awful lot of code compared with=
=20
your zip-and-readlines combination. Is there any simple way to explain wh=
y=20
this is not such a memory hog?

One thing I'm not sure of in the example above is where to put the=20
thisfile.close() line to close those files again. My computer doesn't see=
m=20
any worse for not closing them, but it does seem like bad manners...

Y, Scot


--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany




From alex@gabuzomeu.net  Fri Jun  7 08:47:32 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Fri, 07 Jun 2002 09:47:32 +0200
Subject: [Tutor] computers
In-Reply-To: <20020606225012.14592.65415.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020607093024.00b72620@pop3.norton.antivirus>

Hello,


At 18:50 06/06/2002 -0400, you wrote:
>Date: Thu, 06 Jun 2002 09:47:32 -0700
>From: "Jeff Shannon" <jeff@ccvcorp.com>
>Subject: Re: [Tutor] computers

>The real advantage to multithreading is that it separates your program into
>distinct, logical tasks, making it easier to understand what's going on (if
>you're separating tasks right ;) ).  Only in very special cases does
>multithreading really help with program speed.

Could multithreading make a Web app more responsive? Here is the scheme I 
have in mind: imagine a Web app where a page can be edited in a form. When 
the user saves a page:
- the page is processed somehow (for instance, it is indexed);
- the page is saved to disk or in a database;
- the updated page is displayed back to the user.

=> Could the processing and the saving tasks be subcontracted to worker 
threads so that the main program can return faster and the updated page is 
displayed faster?


Thanks.

Alexandre





From pythontutor@venix.com  Fri Jun  7 14:22:20 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Fri, 07 Jun 2002 09:22:20 -0400
Subject: [Tutor] Levels of Politeness, or Granularity and Placement of Methods?
References: <AF020C5FC551DD43A4958A679EA16A15017B41A8@abbott.lith.com>
Message-ID: <3D00B38C.8060309@venix.com>

I would recommend using setattr(self, attr, value) rather than
self.__dict__[attr] = value

setattr() uses the regular __getattr__ and __setattr__ functions and will
therefore use any special handling that you code for your class.  Direct
assignment to the dictionary is useful when you MUST avoid the normal handling,
but I would not use it otherwise.

My rules of thumb are that classes should be as ignorant of each other as
possible.  Typically, a class knows the names of methods in the other classes
that it relies on.  When a method would simply be getProperty, I normally just
access the property directly (e.g. self.prop = obj.prop).  In Python, this is
very reasonable because the obj.__getattr__ can easily provide any special
handling that a getProperty method would have implemented.  (Also there are
new features in Python 2.2 for property handling.)

In your case, Card.effects is a dictionary.  (self.__dict__[effect] = effects[effect])
The Player knows that Card.effects is a dictionary.  The Player applies effects
by assigning the effects dictionary to self.  This is more class knowledge than
I like.

My inclination would be to either have:
	card.applyEffects( obj) where obj would be a player, but could be any object
or
	create an Effects class that implements effect.apply( obj) as in Card.

The apply method might return a list of changed attributes.
	#in Player
	self.applied_cards.append(deck.pop(card))
	changes = card.applyEffects( self)
	for change in changes:
		__player responds to change from effects__

NOTE, this means you need to watch out for attribute name conflicts!  If this is a real
concern use an Effects Class to package the effect names.  The player.effects are updated
from/by the card.effects depending on which seems to fit.
	card.effects.applyTo( player.effects) versus player.effects.updateFrom( card.effects)



HTH

Israel Evans wrote:

>  
> 
> I have a question for the Tutor Community that pertains to OOP and, um 
> other stuff like that.  J
> 
> 
> ~Israel~

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From dman@dman.ddts.net  Fri Jun  7 18:45:26 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Fri, 7 Jun 2002 12:45:26 -0500
Subject: [Tutor] computers
In-Reply-To: <4.3.2.7.2.20020607093024.00b72620@pop3.norton.antivirus>
References: <20020606225012.14592.65415.Mailman@mail.python.org> <4.3.2.7.2.20020607093024.00b72620@pop3.norton.antivirus>
Message-ID: <20020607174526.GA14600@dman.ddts.net>

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

On Fri, Jun 07, 2002 at 09:47:32AM +0200, Alexandre Ratti wrote:
| Hello,
|=20
|=20
| At 18:50 06/06/2002 -0400, you wrote:
| >Date: Thu, 06 Jun 2002 09:47:32 -0700
| >From: "Jeff Shannon" <jeff@ccvcorp.com>
| >Subject: Re: [Tutor] computers
|=20
| >The real advantage to multithreading is that it separates your program i=
nto
| >distinct, logical tasks, making it easier to understand what's going on =
(if
| >you're separating tasks right ;) ).  Only in very special cases does
| >multithreading really help with program speed.
|=20
| Could multithreading make a Web app more responsive?

It *could*.  One web server (medusa, written in python) is quite
responsive, but isn't threaded at all.  It uses select() to handle
reading/writing from/to multiple sockets without the overhead that
threads or IPC introduce.

| Here is the scheme I=20
| have in mind: imagine a Web app where a page can be edited in a form. Whe=
n=20
| the user saves a page:
| - the page is processed somehow (for instance, it is indexed);
| - the page is saved to disk or in a database;
| - the updated page is displayed back to the user.
|=20
| =3D> Could the processing and the saving tasks be subcontracted to worker=
=20
| threads so that the main program can return faster and the updated page i=
s=20
| displayed faster?

Sure.  If the saving is mainly IO bound, then multiple threads would
help you spread your CPU time around.  You could also do it with
multiple processes.  For example, once the processing is done, fork a
separate process to save to the db and immediately return the
post-processed page to the user.  Of course, that method prevents the
server from notifying the user if a problem occurs with the db.

-D

--=20

There are six things the Lord hates,
    seven that are detestable to him :
        haughty eyes,
        a lying tongue,
        hands that shed innocent blood,
        a heart that devises wicked schemes,
        feet that are quick to rush into evil,
        a false witness who pours out lies
        and a man who stirs up dissension among brothers.

        Proverbs 6:16-19
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAj0A8TYACgkQO8l8XBKTpRRJaQCfVKiIltKgTx8HiyUuUjtukgMu
VFIAn1etQXC2w+OpeQubhiSeZzgIK/N6
=Cl2f
-----END PGP SIGNATURE-----

--OXfL5xGRrasGEqWY--



From jeff@ccvcorp.com  Fri Jun  7 18:49:38 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 07 Jun 2002 10:49:38 -0700
Subject: [Tutor] computers
References: <4.3.2.7.2.20020607093024.00b72620@pop3.norton.antivirus>
Message-ID: <3D00F231.D92A825A@ccvcorp.com>


Alexandre Ratti wrote:

> >From: "Jeff Shannon" <jeff@ccvcorp.com>
>
> >The real advantage to multithreading is that it separates your program into
> >distinct, logical tasks, making it easier to understand what's going on (if
> >you're separating tasks right ;) ).  Only in very special cases does
> >multithreading really help with program speed.
>
> Could multithreading make a Web app more responsive? Here is the scheme I
> have in mind: imagine a Web app where a page can be edited in a form. When
> the user saves a page:
> - the page is processed somehow (for instance, it is indexed);
> - the page is saved to disk or in a database;
> - the updated page is displayed back to the user.
>
> => Could the processing and the saving tasks be subcontracted to worker
> threads so that the main program can return faster and the updated page is
> displayed faster?

Well, it *might* return the updated page faster, but it might not.  If all of
these threads share the same processor, then it will take the same amount of
time to do all the processing, whether it's in one thread or three -- in fact,
it'll take a tiny bit *more* time to do it in three, because you've got the
overhead of switching between the threads.  However, if the thread that returns
the updated page gets scheduled first, then that will happen sooner.  But you
*could* always write a single-threaded app that would return the updated page
before saving data into a database, thus guaranteeing the order would be what
you prefer -- at the cost of a certain amount of added complexity.  It's an open
question whether the complexity of multithreading (concurrency, deadlocks, etc)
is worse than the complexity of explicitly maintaining multiple states in a
single thread.  There's costs and benefits to both ways, and which pays off best
depends on the circumstances.  (Isn't that always how it is? ;) )

Jeff Shannon
Technician/Programmer
Credit International





From sarmstrong13@mac.com  Fri Jun  7 19:10:56 2002
From: sarmstrong13@mac.com (SA)
Date: Fri, 07 Jun 2002 13:10:56 -0500
Subject: [Tutor] Tkinter crash help please.
Message-ID: <B9266160.6931%sarmstrong13@mac.com>

Hi Everyone-

    I've installed python, tcl, tk on my MacOSX 10.1.5 system using the
--enable-frameworks configuration. I have a framework for tcl,tk,and python
under my /Library/Frameworks directory. When I run a simple button code in a
python script:

#!/usr/bin/env python

import sys
from Tkinter import *

def die(event):
    sys.exit()

root = Tk()
button = Button(root)
button["text"] = "Hello"
button.bind("<Button-1>", die)
button.pack()
root.mainloop()

I get the following output in my shell(tcsh by the way):

original argc=2
original argv[0] = "python"
original argv[1] = "./ave.py"
modified argc=2
modified argv[0] = "python"
modified argv[1] = "./ave.py"

Nothing happens.

So I then hit Ctrl-C to stop the script and I get the following Traceback
error:

Traceback (most recent call last):
  File "./ave.py", line 14, in ?
    root.mainloop()
  File 
"/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/lib-tk/Tkin
ter.py", line 929, in mainloop
    self.tk.mainloop(n)
KeyboardInterrupt

It looks like it is calling the correct Tkinter Module, but nothing is bein
displayed. If however I enter the code line for line in the Python.app that
I compile, I get the proper button widget. Maybe I'm wrong (because I
definitely do NOT fully understand the Mac OSX Frameworks system yet), but
if the coded is properly calling the correct Tkinter module, it should not
matter whether or not it is done within the Python.app or by calling python
from within Python.app. Is this correct? Is there a way to do this on a Mac?
(other than MacPython wich works only on pre OSX systems and doe not take
advantage of the BSD under OSX)

Thanks.
SA




From phthenry@earthlink.net  Fri Jun  7 22:10:07 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Fri, 7 Jun 2002 17:10:07 -0400
Subject: [Tutor] rtf to xml regexp question
Message-ID: <20020607171007.B6866@localhost.localdomain>

I have found a java utility that does a pretty good job of
converting rtf to xml. I had played around with the idea of
writing a parser myself, but realized it was pretty coplicated.

However, this utility does not convert footnotes. Before I run
the utlity, I want to convert footnotes into this format:

As Schmoo claims <footnote>footnote text at bottom of page.
Quoted from <i>Title</i></footnote>

The present rtf format looks like this:

\pard\plain Now a footnote. As Schmoo claims {\fs18\up6 \chftn
{\footnote \pard\plain \s246 \fs20  {\fs18\up6 \chftn }footnote
at bottom of page.Quoted from {\i Title}}}\par 

Majix, the rtf convertor will take care of a lot of this text,
converting the above to:

<p>Now a footnote. As Schmoo claims</p>

I am only inerested in the rtf text between {\footnote and }}}.

There are a few tricky parts, though. The text may break over
several lines. Also, if the actual title of the book does not end
the footnote reference,than the text I am interested in will end
in two }} rather than three.

The best method is to start a search that finds {\footnote. It
should add one to a footnote counter. Then the search should
continue from that point. If it finds another {, then it should
add another to the footnote counter. If it finds a }, then it
should subtract 1 from the footnote counter. It should stop
searchiing when it finds a } and when the footnote counter is
0. 

I don't know how to do this in Python. I remember that in perl
you could start searching from where you left off. 

Thanks!

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From shendric@arches.uga.edu  Fri Jun  7 16:27:41 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Fri,  7 Jun 2002 10:27:41 -0500
Subject: [Tutor] creating tables
Message-ID: <1023460061.smmsdV1.1.1@mail.arches.uga.edu>

Hi all,

Thanks for the help with exit handling and what not.  Here's another 
application that I'm playing with.  I'd like to have a widget that is a 
little editable table.  It has a fixed number of columns, but can have 
as many rows as the user wishes.  I came up with a class for a table 
row, but I'm trying to decide on the best implementation for creating 
new rows, when the user wants to create a new one.  

There has been so much discussion on dynamically creating classes, so I 
hate to bring it up again, but it's kind of crucial here, I think, and 
I'm still trying to get a handle on the details.  In essence, the idea 
here is that when a user requests (by an event), a new row is created in 
the table.  I'd like for each new class to be uniquely identified, 
because the program will need to eventually export the contents of the 
cells to a file.  So, it would need to iterate over each instance and 
export that instance's contents.  Also, the user might want to remove a 
row, in which case, the instance would need to be removed.

Sounds like a list, to me.  So, I guess the question is: can I create a 
list of class instances, adding a new instance every time the user 
requests, where the reference can be removed when the instance is 
destroyed?

Sorry if this sounds a bit cryptic, and a bunch of questions packed into 
one, but if anyone's got any ideas for any part of it, they would be 
very welcome.  Also, if there's already a module to handle such a table, 
that would be cool, too.

Sean





From williammperry08@cox.net  Sat Jun  8 06:41:02 2002
From: williammperry08@cox.net (William Perry)
Date: Sat, 08 Jun 2002 00:41:02 -0500
Subject: [Tutor] re: computers
In-Reply-To: <DAV30SimD3JkUwWpSWe0000b299@hotmail.com>
References: <OF6F8F28CD.E23ABB07-ON85256BCE.00695C53@lotus.com>
 <DAV30SimD3JkUwWpSWe0000b299@hotmail.com>
Message-ID: <200206080041020277.1055805B@smtp.central.cox.net>

--=====_10235148629881=_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Win98 DOES NOT support multi-processors, you need to change os (XP Pro (not=
 home) or NT)


ron Stoner wrote: 
Thanks Stuart,

That's what I was thinking.  I wondered if programs would run faster.  I=
 was looking into it to make my graphics work, ie: 3D modeling, take less=
 time to use.  When doing animation it currently takes me like a half-hour=
 to save my work.  This is not a gross overestamation either.  It then=
 turns out to be less than 30 sec of animation when I play it.  Would=
 having multiple processors make it more efficient?

Thanks,
Cameron Stoner
----- Original Message ----- 
From: stuart_clemons@us.ibm.com 
To: tutor@python.org 
Sent: Tuesday, June 04, 2002 2:20 PM
Subject: [Tutor] re: computers


FYI. Even if your OS, such as NT, is capable of running on a=
 multi-processor system, it does not mean that your programs or compilers=
 will run any faster than when run on a single processor system. Most=
 programs and compilers do not take advantage of multi-processor systems,=
 which is something most people don't seem to realise. In fact, in some=
 cases a single processor system will complete tasks faster than a=
 multi-processor system. So, for most people, having a multiprocessor=
 system is a waste time, money, and resources.


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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2716.2200" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>Win98 DOES NOT support multi-processors, you need to 
change os (XP Pro (not home) or NT)<BR><FONT face=Arial size=2><BR><BR>ron 
Stoner wrote:</FONT> 
<BLOCKQUOTE 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid">
  <DIV><FONT face=Arial size=2>Thanks Stuart,</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>That's what I was thinking.&nbsp; I wondered if 
  programs would run faster.&nbsp; I was looking into it to make my graphics 
  work, ie: 3D modeling, take less time to use.&nbsp; When doing animation it 
  currently takes me like a half-hour to save my work.&nbsp; This is not a gross 
  overestamation either.&nbsp; It then turns out to be less than 30 sec of 
  animation when I play it.&nbsp; Would having multiple processors make it more 
  efficient?</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Thanks,</FONT></DIV>
  <DIV><FONT face=Arial size=2>Cameron Stoner</FONT></DIV>
  <DIV>----- Original Message ----- </DIV>
  <BLOCKQUOTE dir=ltr 
  style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV 
    style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
    <A title=stuart_clemons@us.ibm.com 
    href="mailto:stuart_clemons@us.ibm.com">stuart_clemons@us.ibm.com</A> </DIV>
    <DIV style="FONT: 10pt arial"><B>To:</B> <A title=tutor@python.org 
    href="mailto:tutor@python.org">tutor@python.org</A> </DIV>
    <DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, June 04, 2002 2:20 
    PM</DIV>
    <DIV style="FONT: 10pt arial"><B>Subject:</B> [Tutor] re: computers</DIV>
    <DIV><BR></DIV>
    <P>FYI. Even if your OS, such as NT, is capable of running on a 
    multi-processor system, it does not mean that your programs or compilers 
    will run any faster than when run on a single processor system. Most 
    programs and compilers do not take advantage of multi-processor systems, 
    which is something most people don't seem to realise. In fact, in some cases 
    a single processor system will complete tasks faster than a multi-processor 
    system. So, for most people, having a multiprocessor system is a waste time, 
    money, and resources.</P></BLOCKQUOTE><FONT size=2 
Arial></BLOCKQUOTE></FONT></BODY></HTML>


--=====_10235148629881=_--




From donni@melwestmarket.com  Sat Jun  8 08:40:45 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Sat, 8 Jun 2002 17:40:45 +1000 (AUS Eastern Standard Time)
Subject: [Tutor] Is there a function for refreshing what's in the console?
Message-ID: <3D01B4FD.000007.47955@athlon900.vic.optushome.com.au>

--------------Boundary-00=_XNMDWCW0000000000000
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Is there a function for refreshing what's in the console? (Eg. delete eve=
rything printed previously in the window)
--------------Boundary-00=_XNMDWCW0000000000000
Content-Type: Text/HTML;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">
</head>

<BODY background=3D"" bgColor=3D#ffffff style=3D"BACKGROUND-POSITION: 0px=
 0px; FONT-SIZE: 10pt; MARGIN: 1px; FONT-FAMILY: Arial" scroll=3Dyes ORGY=
POS=3D"0">
<TABLE border=3D0 cellPadding=3D0 cellSpacing=3D0 id=3DINCREDIMAINTABLE w=
idth=3D"95%">
<TR>

<TD id=3DINCREDITEXTREGION width=3D"100%" style=3D"PADDING-RIGHT: 7px; PA=
DDING-LEFT: 7px; FONT-SIZE: 10pt; FONT-FAMILY: Arial"=20
   >
      <DIV>
      <P>Is there a function for refreshing what's in the console? (Eg. d=
elete=20
      everything printed previously in the window)</P></DIV></TD>
</TR>

<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">

=09<TABLE cellPadding=3D0 cellSpacing=3D0 width=3D"100%">
=09<TR>
=09<TD width=3D"100%"></TD>
=09<TD align=3Dmiddle id=3DINCREDISOUND vAlign=3Dbottom></TD>
=09<TD align=3Dmiddle id=3DINCREDIANIM vAlign=3Dbottom></TD>
=09</TR>
=09</TABLE>

</TD>
</TR>

</TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email ha=
s finally=20
evolved</B> - </FONT><A href=3D"http://www.bravenet.com/out.php?id=3D768"=
><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT>
</BODY>
</html>
--------------Boundary-00=_XNMDWCW0000000000000--




From donni@melwestmarket.com  Sat Jun  8 10:14:27 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Sat, 8 Jun 2002 19:14:27 +1000 (AUS Eastern Standard Time)
Subject: [Tutor] Time function
Message-ID: <3D01CAF3.000005.84443@athlon900.vic.optushome.com.au>

--------------Boundary-00=_30RD6RO0000000000000
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Is there a function that returns the time on the computer the script is r=
un on?
I found some functions on the net but they did not show it in the right f=
ormat. I want it to show the hour and the minutes (just like the clock in=
 windows and linux on the taskbar).

Thank you for your help :)
--------------Boundary-00=_30RD6RO0000000000000
Content-Type: Text/HTML;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">
</head>

<BODY background=3D"" bgColor=3D#ffffff style=3D"BACKGROUND-POSITION: 0px=
 0px; FONT-SIZE: 10pt; MARGIN: 1px; FONT-FAMILY: Arial" scroll=3Dyes ORGY=
POS=3D"0">
<TABLE border=3D0 cellPadding=3D0 cellSpacing=3D0 id=3DINCREDIMAINTABLE w=
idth=3D"95%">
<TR>

<TD id=3DINCREDITEXTREGION width=3D"100%" style=3D"PADDING-RIGHT: 7px; PA=
DDING-LEFT: 7px; FONT-SIZE: 10pt; FONT-FAMILY: Arial"=20
   >
      <DIV>Is there a function that returns the time on the computer the =
script=20
      is run on?</DIV>
      <DIV>I found some functions on the net but they did not show it in =
the=20
      right format. I want it to show the hour and the minutes (just like=
 the=20
      clock in windows and linux on the taskbar).</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>Thank you for your help :)</DIV></TD>
</TR>

<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">

=09<TABLE cellPadding=3D0 cellSpacing=3D0 width=3D"100%">
=09<TR>
=09<TD width=3D"100%"></TD>
=09<TD align=3Dmiddle id=3DINCREDISOUND vAlign=3Dbottom></TD>
=09<TD align=3Dmiddle id=3DINCREDIANIM vAlign=3Dbottom></TD>
=09</TR>
=09</TABLE>

</TD>
</TR>

</TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email ha=
s finally=20
evolved</B> - </FONT><A href=3D"http://www.bravenet.com/out.php?id=3D768"=
><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT>
</BODY>
</html>
--------------Boundary-00=_30RD6RO0000000000000--




From donni@melwestmarket.com  Sat Jun  8 10:37:06 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Sat, 8 Jun 2002 19:37:06 +1000 (AUS Eastern Standard Time)
Subject: [Tutor] Beep sound for Linux
Message-ID: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>

--------------Boundary-00=_U1SD6RO0000000000000
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I heard of beep sounds for Windows only, but is there a function for beep=
 sounds in Linux?
--------------Boundary-00=_U1SD6RO0000000000000
Content-Type: Text/HTML;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">
</head>

<BODY background=3D"" bgColor=3D#ffffff style=3D"BACKGROUND-POSITION: 0px=
 0px; FONT-SIZE: 10pt; MARGIN: 1px; FONT-FAMILY: Arial" scroll=3Dyes ORGY=
POS=3D"0">
<TABLE border=3D0 cellPadding=3D0 cellSpacing=3D0 id=3DINCREDIMAINTABLE w=
idth=3D"95%">
<TR>

<TD id=3DINCREDITEXTREGION width=3D"100%" style=3D"PADDING-RIGHT: 7px; PA=
DDING-LEFT: 7px; FONT-SIZE: 10pt; FONT-FAMILY: Arial"=20
   >
      <DIV>I heard of beep sounds for Windows only, but is there a functi=
on for=20
      beep sounds in Linux?</DIV></TD>
</TR>

<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">

=09<TABLE cellPadding=3D0 cellSpacing=3D0 width=3D"100%">
=09<TR>
=09<TD width=3D"100%"></TD>
=09<TD align=3Dmiddle id=3DINCREDISOUND vAlign=3Dbottom></TD>
=09<TD align=3Dmiddle id=3DINCREDIANIM vAlign=3Dbottom></TD>
=09</TR>
=09</TABLE>

</TD>
</TR>

</TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email ha=
s finally=20
evolved</B> - </FONT><A href=3D"http://www.bravenet.com/out.php?id=3D768"=
><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT>
</BODY>
</html>
--------------Boundary-00=_U1SD6RO0000000000000--




From glingl@aon.at  Sat Jun  8 12:16:58 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sat, 8 Jun 2002 13:16:58 +0200
Subject: [Tutor] Time function
References: <3D01CAF3.000005.84443@athlon900.vic.optushome.com.au>
Message-ID: <001401c20ede$014a2480$1615a8c0@mega>

This is a multi-part message in MIME format.

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


Things like these can easiliy be found in the Python Library Reference =
(or
in the Global Module Index) for instance via Python Help in IDLE, or:

http://www.python.org/doc/current/download.html

So I was able to produce immediately:

>>> import time
>>> time.time()
1023534027.09
>>> time.gmtime()
(2002, 6, 8, 11, 1, 20, 5, 159, 0)
>>> time.asctime(time.gmtime())
'Sat Jun 08 11:01:43 2002'
>>> time.asctime(time.localtime())
'Sat Jun 08 13:02:09 2002'
>>> "%02d:%02d:%02d" % time.localtime()[3:6]
'13:02:37'

and so on, what you want ...

Regards
Gregor


----- Original Message -----=20
From: Dimitrije Nikic=20
To: Python User Group=20
Sent: Saturday, June 08, 2002 11:14 AM
Subject: [Tutor] Time function


      Is there a function that returns the time on the computer the =
script is run on?
      I found some functions on the net but they did not show it in the =
right format. I want it to show the hour and the minutes (just like the =
clock in windows and linux on the taskbar).

      Thank you for your help :)=20
            =20
    =20
_________________________________________________
Bravenet IncrediMail - Email has finally evolved - Click Here=20

------=_NextPart_000_0011_01C20EEE.C48CC3C0
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 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY=20
style=3D"BACKGROUND-POSITION: 0px 0px; FONT-SIZE: 10pt; MARGIN: 1px; =
FONT-FAMILY: Arial"=20
bgColor=3D#ffffff background=3D"" scroll=3Dyes ORGYPOS=3D"0">
<DIV><FONT face=3D"Courier New"></FONT><FONT=20
face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">Things like these can easiliy be found =
in the=20
Python Library Reference (or</FONT></DIV>
<DIV><FONT face=3D"Courier New">in the Global Module Index) for instance =

via&nbsp;Python Help&nbsp;in IDLE, or:</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"><A=20
href=3D"http://www.python.org/doc/current/download.html">http://www.pytho=
n.org/doc/current/download.html</A></FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">So I was able to produce =
immediately:</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">&gt;&gt;&gt; import time<BR>&gt;&gt;&gt; =

time.time()<BR>1023534027.09<BR>&gt;&gt;&gt; time.gmtime()<BR>(2002, 6, =
8, 11,=20
1, 20, 5, 159, 0)<BR>&gt;&gt;&gt; time.asctime(time.gmtime())<BR>'Sat =
Jun 08=20
11:01:43 2002'<BR>&gt;&gt;&gt; time.asctime(time.localtime())<BR>'Sat =
Jun 08=20
13:02:09 2002'<BR>&gt;&gt;&gt; "%02d:%02d:%02d" %=20
time.localtime()[3:6]<BR>'13:02:37'<BR></FONT></DIV>
<DIV><FONT face=3D"Courier New">and so on, what you want =
...</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">Regards</FONT></DIV>
<DIV><FONT face=3D"Courier New">Gregor</DIV></FONT>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV style=3D"FONT: 10pt arial">----- Original Message -----=20
<DIV style=3D"BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A=20
title=3Ddonni@melwestmarket.com =
href=3D"mailto:donni@melwestmarket.com">Dimitrije=20
Nikic</A> </DIV>
<DIV><B>To:</B> <A title=3Dtutor@python.org =
href=3D"mailto:tutor@python.org">Python=20
User Group</A> </DIV>
<DIV><B>Sent:</B> Saturday, June 08, 2002 11:14 AM</DIV>
<DIV><B>Subject:</B> [Tutor] Time function</DIV></DIV>
<DIV><BR></DIV>
<TABLE id=3DINCREDIMAINTABLE cellSpacing=3D0 cellPadding=3D0 =
width=3D"95%" border=3D0>
  <TBODY>
  <TR>
    <TD id=3DINCREDITEXTREGION=20
    style=3D"PADDING-RIGHT: 7px; PADDING-LEFT: 7px; FONT-SIZE: 10pt; =
FONT-FAMILY: Arial"=20
    width=3D"100%">
      <DIV>Is there a function that returns the time on the computer the =
script=20
      is run on?</DIV>
      <DIV>I found some functions on the net but they did not show it in =
the=20
      right format. I want it to show the hour and the minutes (just =
like the=20
      clock in windows and linux on the taskbar).</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>Thank you for your help :)</DIV></TD></TR>
  <TR>
    <TD id=3DINCREDIFOOTER width=3D"100%">
      <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%">
        <TBODY>
        <TR>
          <TD width=3D"100%"></TD>
          <TD id=3DINCREDISOUND vAlign=3Dbottom align=3Dmiddle></TD>
          <TD id=3DINCREDIANIM vAlign=3Dbottom=20
  =
align=3Dmiddle></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><SPAN =

id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, =
sans-serif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email =
has finally=20
evolved</B> - </FONT><A =
href=3D"http://www.bravenet.com/out.php?id=3D768"><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT> </BODY></HTML>

------=_NextPart_000_0011_01C20EEE.C48CC3C0--




From dman@dman.ddts.net  Sat Jun  8 16:27:55 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 8 Jun 2002 10:27:55 -0500
Subject: [Tutor] Is there a function for refreshing what's in the console?
In-Reply-To: <3D01B4FD.000007.47955@athlon900.vic.optushome.com.au>
References: <3D01B4FD.000007.47955@athlon900.vic.optushome.com.au>
Message-ID: <20020608152755.GA17642@dman.ddts.net>

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

On Sat, Jun 08, 2002 at 05:40:45PM +1000, Dimitrije Nikic wrote:
| Is there a function for refreshing what's in the console? (Eg.
| delete everything printed previously in the window)

Yes and no.  There are a couple of ways you can do this, one doesn't
really work, one is not wholly cross-platform.  The problem is knowing
what the user's console looks like (eg how big it is, etc) and how to
tell it to clear.

The way that doesn't really work is to assume you know how many lines
it will contain and do something like this :
    print "\n"*24
That works for a VT-100 and work-alikes that only have 24 lines on the
screen.  When I work in gnome-terminal, it too has 24 lines (but it
allows that to be changed arbitrarily).  If I work in my linux console
I have about 64 lines on screen.  That's why it doesn't really work.
If some user gets a bigger screen, that won't push the text all the
way off it.

The way that works is to use the ncurses library.  Of course,
Microsoft didn't feel the need to provide a curses implementation on
their platform, so it doesn't work on Windows unless you require the
use of cygwin (to emulate UNIX :-)).  ncurses is a great library
because it abstracts away the details of each and every terminal ever
made and handles the interaction with the terminal for you.  You
simply tell it what you want it to do.  I've never done any curses
programming before, but I've heard that it isn't the easiest thing to
learn.

HTH,
-D

--=20

Whoever gives heed to instruction prospers,
and blessed is he who trusts in the Lord.
        Proverbs 16:20
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--5mCyUwZo2JvN/JJP
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0CInoACgkQO8l8XBKTpRTT9QCgtQv/CE96NQAqdzHe/wq9cNx+
DiQAn3lbF7QD9p1uI0DGqjsQx9x5wFMs
=muc/
-----END PGP SIGNATURE-----

--5mCyUwZo2JvN/JJP--



From sarmstrong13@mac.com  Sat Jun  8 17:29:32 2002
From: sarmstrong13@mac.com (SA)
Date: Sat, 08 Jun 2002 11:29:32 -0500
Subject: [Tutor] Newbie OOP Question.
Message-ID: <B9279B1C.6AEA%sarmstrong13@mac.com>

Hi Everyone-

    I'm still trying to grasp this OOP concept in Python. Can someone tell
me the difference between a function, a module, and a class? Since Python
defines them all as objects, how do they differ outside of being called from
inside the script or outside the script?

Thanks.
SA




From ak@silmarill.org  Sat Jun  8 18:15:59 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 8 Jun 2002 13:15:59 -0400
Subject: [Tutor] Beep sound for Linux
In-Reply-To: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
References: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
Message-ID: <20020608171559.GA428@ak.silmarill.org>

On Sat, Jun 08, 2002 at 07:37:06PM +1000, Dimitrije Nikic wrote:
> I heard of beep sounds for Windows only, but is there a function for beep sounds in Linux?
>
>
print '\a'

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From ak@silmarill.org  Sat Jun  8 18:35:44 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 8 Jun 2002 13:35:44 -0400
Subject: [Tutor] Newbie OOP Question.
In-Reply-To: <B9279B1C.6AEA%sarmstrong13@mac.com>
References: <B9279B1C.6AEA%sarmstrong13@mac.com>
Message-ID: <20020608173544.GA493@ak.silmarill.org>

On Sat, Jun 08, 2002 at 11:29:32AM -0500, SA wrote:
> Hi Everyone-
> 
>     I'm still trying to grasp this OOP concept in Python. Can someone tell
> me the difference between a function, a module, and a class? Since Python
> defines them all as objects, how do they differ outside of being called from
> inside the script or outside the script?
> 
> Thanks.
> SA
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Module is a file that has some code in it. Module may include many
functions and classes in it (or just a few lines of code. A function is
a chunk of code that may take in some data and then return some other
data:

def func(data_in):
    [do stuff]
    return data_out

a class usually contains a few functions, say a Tree class would have
grow_roots and grow_leaves functions, and would also have a boolean
attribute alive: tree.alive = 1. Oh, and there'd be a function tree.die
that would set tree.alive to 0.

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From lonetwin@yahoo.com  Sat Jun  8 11:28:37 2002
From: lonetwin@yahoo.com (Steve)
Date: Sat, 8 Jun 2002 15:58:37 +0530
Subject: [Tutor] Time function
In-Reply-To: <3D01CAF3.000005.84443@athlon900.vic.optushome.com.au>
References: <3D01CAF3.000005.84443@athlon900.vic.optushome.com.au>
Message-ID: <20020608102837.80A8C2F4A8@mercury.sapatmt>

Hi there, 

On Saturday 08 June 2002 02:44 pm, you wrote:
> Is there a function that returns the time on the computer the script is run
> on? I found some functions on the net but they did not show it in the right
> format. I want it to show the hour and the minutes (just like the clock in
> windows and linux on the taskbar).

You may want to look at the time module (doc. included within the standard 
Python documentation and also at 
http://www.python.org/doc/current/lib/module-time.html )
	Anyways, here is what you needed in an interpreter session:
-----------------------------------------
Python 2.2.1 (#3, May  8 2002, 19:51:42) 
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.ctime()
'Sat Jun  8 15:49:39 2002'
>>> time.ctime().split()[3]
'15:53:43'
>>> 
------------------------------------------

Hope that helps

Peace
Steve


-- 
Most people have two reasons for doing anything -- a good reason, and
the real reason.



From lonetwin@yahoo.com  Sat Jun  8 11:32:39 2002
From: lonetwin@yahoo.com (Steve)
Date: Sat, 8 Jun 2002 16:02:39 +0530
Subject: [Tutor] Beep sound for Linux
In-Reply-To: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
References: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
Message-ID: <20020608103240.007AC2F4A8@mercury.sapatmt>

Hi There,
On Saturday 08 June 2002 03:07 pm, you wrote:
> I heard of beep sounds for Windows only, but is there a function for beep
> sounds in Linux?
RE: did you mean this ...

>>> print "\a"

Peace
Steve
-- 
Q:	Why did the chicken cross the road?
A:	To see his friend Gregory peck.

Q:	Why did the chicken cross the playground?
A:	To get to the other slide.



From purplebo@babylonia.flatirons.org  Sat Jun  8 20:09:05 2002
From: purplebo@babylonia.flatirons.org (Chris Avery)
Date: Sat, 8 Jun 2002 13:09:05 -0600
Subject: [Tutor] Re: Time Function
In-Reply-To: <20020608111801.12146.60842.Mailman@mail.python.org>; from tutor-request@python.org on Sat, Jun 08, 2002 at 07:18:01AM -0400
References: <20020608111801.12146.60842.Mailman@mail.python.org>
Message-ID: <20020608130905.A27711@babylonia.flatirons.org>

time.strftime() returns the time you want.  
time.strftime("%h-%m") or something like that should work.
Good Luck!

-- 
+++++++++++++++++++
Chris Avery, KC0KTH
+++++++++++++++++++



From sarmstrong13@mac.com  Sat Jun  8 21:29:37 2002
From: sarmstrong13@mac.com (SA)
Date: Sat, 08 Jun 2002 15:29:37 -0500
Subject: [Tutor] Tkinter Help Please.
Message-ID: <B927D361.6B55%sarmstrong13@mac.com>

Hi Everyone-
Can someone explain what _tkinter in the Tkinter.py refers to?

Specifically from line:35 of Tkinter.py

import _tkinter # If this fails your Python may not be configured for Tk

Ok how do I compile Python to be configured for Tk and where is the _tkinter
module located?

Thanks.
SA




From marcolinux@linuxbr.com.br  Sat Jun  8 21:41:26 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Sat, 8 Jun 2002 17:41:26 -0300
Subject: [Tutor] Beep sound for Linux
In-Reply-To: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
References: <3D01D042.000005.09639@athlon900.vic.optushome.com.au>
Message-ID: <20020608174126.A1125@marcolab.net>

Dimitrije Nikic (donni@melwestmarket.com) wrote:

> I heard of beep sounds for Windows only, but is there a function for beep sounds in Linux?

Some time ago I was playing with a nice beep program: beep.
You can control the freq and duration of a beep.The only
problem: it must run suid root :/
You can get it at http://johnath.com/beep/beep-1.2.2.tar.gz

Test with:

$ beep -n -f 1500 -l 2000 -n 200 -l 3000

Should beep three times: a default,1500Hz for 2 seconds, 200Hz for 3
seconds.

Then I made  script to play with it. Feel free to improve it :)

#############################################################
#############################################################
#!/usr/bin/env python

import os

#tunes for beeporama: (frequence,duration)
tune1=[(1000,320),(900,10),(500,410),(400,10),(340,410),(300,10)]
tune2=[(1000,10),(500,10),(440,20),(340,2),(720,4),(880,40)]

tune=tune2

cmd='beep -f100 -l1 '

for i,j in tune: 
	cmd=cmd + ' -n -f '+ str(i) + ' -l'+str(j)

os.system(cmd)

#############################################################
#############################################################


Lame, but I was able to play some sounds for different situations like
incoming mail, ppp up/down, firewall alerts, etc.

Does any one know if is possible to find a way to get some "tunes" ?
Maybe extract from MIDI files or something like that.
It would be very nice to play some real music :)

Hope it helps.
Good luck.



From dyoo@hkn.eecs.berkeley.edu  Sat Jun  8 22:48:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 8 Jun 2002 14:48:45 -0700 (PDT)
Subject: [Tutor] Tkinter Help Please.
In-Reply-To: <B927D361.6B55%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206081445010.27357-100000@hkn.eecs.berkeley.edu>

On Sat, 8 Jun 2002, SA wrote:

> Hi Everyone-
> Can someone explain what _tkinter in the Tkinter.py refers to?
>
> Specifically from line:35 of Tkinter.py
>
> import _tkinter # If this fails your Python may not be configured for Tk

Hi SA,

This '_tkinter' module is a low-level module that supports Tkinter; it
gets compiled automatically if your system has Tk support.


> Ok how do I compile Python to be configured for Tk and where is the
> _tkinter module located?

If you already have the Tk libraries installed, you may want to make sure
that the development 'header libraries' are also around; otherwise, Python
can't build the '_tkinter' library.  What kind of system are you running?


Using a package management system can simplify this.  For example, on my
Debian Linux system, I just need to make sure I have the 'tk8.3-dev'
package installed.  On a Red Hat Linux system, the developmental packages
usually have a '-devel' suffix at the end of their package names.


Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Sat Jun  8 23:03:14 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 8 Jun 2002 15:03:14 -0700 (PDT)
Subject: [Tutor] Beep sound for Linux
In-Reply-To: <20020608174126.A1125@marcolab.net>
Message-ID: <Pine.LNX.4.44.0206081449170.27357-100000@hkn.eecs.berkeley.edu>

> Lame, but I was able to play some sounds for different situations like
> incoming mail, ppp up/down, firewall alerts, etc.
>
> Does any one know if is possible to find a way to get some "tunes" ?
> Maybe extract from MIDI files or something like that. It would be very
> nice to play some real music :)

Hmmm... maybe something in Pygame might help?


The game "SolarWolf",

    http://www.pygame.org/shredwheat/solarwolf/

uses "XM" formatted files for its songs, so Pygame definitely has some
tools here for playing music.  There are utilities available to convert
MIDI to XM, so one possiblity is to convert to XM, and then use Pygame to
play it.


Good luck!




From phthenry@earthlink.net  Sat Jun  8 23:23:50 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Sat, 8 Jun 2002 18:23:50 -0400
Subject: [Tutor] rtf to xml regexp question
In-Reply-To: <20020607171007.B6866@localhost.localdomain>
References: <20020607171007.B6866@localhost.localdomain>
Message-ID: <20020608182349.A10617@localhost.localdomain>

I'm responding to my own question. I've done a lot of research
the past few days, and rezlize that for my needs I really needed
a parser or state machine. 

As with many things with programming and linux, it is always
frustrating at first. Then once you understand, you think "Ah,
that is a much simpler solution!" 

That is how I feel about state machines. I have been killing
myself with regular expressions. No more! 

Paul

PS I'v included my code below, in case anyone is interested. The
only problem I am having at this point is that the state machine
is putting a space after my "{", but I think I can write a
sub-routine to strip trailing spaces.

PSS Originally this message was a plea for help. My regular
expressions were so greedy that they were overlapping each other.
But as soon as I started writing this email, the solution came to
me!


*******************************
!/usr/bin/python

from Plex import *
##from Plex.Traditional import re


class MyScanner(Scanner):

	def begin_footnote(self, text):
		self.produce('##Footnote', '')
		if self.nesting_level == 0:
			self.begin('footnote')
		self.nesting_level = self.nesting_level + 1

	def end_something(self, text):
		self.nesting_level = self.nesting_level - 1
		if self.nesting_level == 0:
			self.produce('##END OF FOOTNOTE##','')
			self.begin('')
		else:
			self.produce('}','')

	def begin_open_bracket(self, text):
		self.produce('{','')
		self.nesting_level = self.nesting_level + 1

	string = Rep1(AnyBut("{}"))

	lexicon = Lexicon([
		(Str(r"{\footnote"),     begin_footnote),
		
		State('footnote', [
			(Str(r"{\footnote"), begin_footnote),
			(Str("}"), end_something),
			(Str(r"{"), begin_open_bracket),
			(string,	  TEXT)
		]),
		(string,		TEXT),
		(Str("{"), 	TEXT),
		(Str("}"),	TEXT),
	])

	def __init__(self, file, name):
		Scanner.__init__(self, self.lexicon, file, name)
		self.nesting_level = 0

filename = "/home/paul/paultemp/my_file.txt"
file = open(filename, "r")

scanner = MyScanner(file, filename)
while 1:
	token = scanner.read()
	if token[0] is None:
		break
	print token[0],

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From sarmstrong13@mac.com  Sun Jun  9 03:26:37 2002
From: sarmstrong13@mac.com (SA)
Date: Sat, 08 Jun 2002 21:26:37 -0500
Subject: [Tutor] Newbie Question Again.
Message-ID: <B928270D.6BFA%sarmstrong13@mac.com>

Hi Everyone-

    I'm running Python on Mac OSX. (bsd based system) How do I call a
program from outside Python to be run from within my Python script/ In other
words if I have an executable file, say "someprogram", how would I execute
this program from within a python script.

Thanks.
SA




From dman@dman.ddts.net  Sun Jun  9 04:01:57 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 8 Jun 2002 22:01:57 -0500
Subject: [Tutor] Newbie Question Again.
In-Reply-To: <B928270D.6BFA%sarmstrong13@mac.com>
References: <B928270D.6BFA%sarmstrong13@mac.com>
Message-ID: <20020609030157.GA23916@dman.ddts.net>

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

On Sat, Jun 08, 2002 at 09:26:37PM -0500, SA wrote:
| Hi Everyone-
|=20
|     I'm running Python on Mac OSX. (bsd based system) How do I call a
| program from outside Python to be run from within my Python script/ In ot=
her
| words if I have an executable file, say "someprogram", how would I execute
| this program from within a python script.

There are various ways depending on what you want to do with it.  In
the simplest case, this works :

import os
os.system( "command" )

-D

--=20

"GUIs normally make it simple to accomplish simple actions and
impossible to accomplish complex actions."
    --Doug Gwyn  (22/Jun/91 in comp.unix.wizards)
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAj0CxSUACgkQO8l8XBKTpRQ35gCffgo8DqrDIvax98w5d3LO74fu
4p0AoKDTThLPT0FaikbcGEKK3QXNbUfF
=bs4X
-----END PGP SIGNATURE-----

--X1bOJ3K7DJ5YkBrT--



From beercanz@hotmail.com  Sun Jun  9 03:12:29 2002
From: beercanz@hotmail.com (Guess Who? Me)
Date: Sun, 09 Jun 2002 02:12:29 +0000
Subject: [Tutor] Python Question - Repeating output.
Message-ID: <F62iO9oRdUYPuj1DcYA00008f7a@hotmail.com>

<html><div style='background-color:'><DIV>I downloaded python yesterday and am working through the tutorial. I got to <A href="http://www.honors.montana.edu/~jjc/easytut/easytut/node6.html">http://www.honors.montana.edu/~jjc/easytut/easytut/node6.html</A>, the part about while. I couldn't get it, because if a=0, and a=a+1, then wouldn't 0=1???</DIV>
<DIV>&nbsp;</DIV>
<DIV>And I kept trying to make my own program with while, but they keep giving me infinite answers. Here's what I did:</DIV>
<DIV>&nbsp;</DIV>
<DIV>#I need an idea to make a program using "while". So I'll be lame.</DIV>
<DIV>a=input("Pick a number that is not lame:")<BR>while a==69:<BR>&nbsp;&nbsp;&nbsp; print "Good job!"<BR>while a !=69:<BR>&nbsp;&nbsp;&nbsp; print "Moron."<BR></DIV>
<DIV>It gave me infinite "Moron." or "Good job!"s. </DIV>
<DIV>So basically - any clearer definitions of while? And why does my little program keep giving me infinite loops??</DIV>
<DIV>Thanks.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></div><br clear=all><hr>Chat with friends online, try MSN Messenger: <a href='http://g.msn.com/1HM505401/43'>Click Here</a><br></html>



From dyoo@hkn.eecs.berkeley.edu  Sun Jun  9 08:00:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 9 Jun 2002 00:00:00 -0700 (PDT)
Subject: [Tutor] Newbie Question Again.
In-Reply-To: <B928270D.6BFA%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206082348580.7912-100000@hkn.eecs.berkeley.edu>


On Sat, 8 Jun 2002, SA wrote:

>     I'm running Python on Mac OSX. (bsd based system) How do I call a
> program from outside Python to be run from within my Python script/ In
> other words if I have an executable file, say "someprogram", how would I
> execute this program from within a python script.

Hi SA,

We can use the os.system() call to run external commands.  For example:

###
import os
print "The return code from os.system('ls') is", os.system('ls')
###

will run the 'ls' command, and give back to us a errorlevel value.


If we want to grab the 'standard out' output of that external program,
then the os.popen() command is more useful.  Here's an example:


###
>>> process_file = os.popen('ls -l gift/')
>>> process_file.readline()
'total 36\n'
>>> print process_file.read()
-rw-r--r--    1 dyoo     dyoo         1598 May 22 22:25 directed_point.py
-rw-r--r--    1 dyoo     dyoo         3573 May 22 22:35 directed_point.pyc
-rw-r--r--    1 dyoo     dyoo         1628 May 22 22:26 main.py
-rw-r--r--    1 dyoo     dyoo         2647 May 22 22:25 names.py
-rw-r--r--    1 dyoo     dyoo         3691 May 22 22:35 names.pyc
-rw-r--r--    1 dyoo     dyoo         3377 May 22 22:25 starfield.py
-rw-r--r--    1 dyoo     dyoo         3598 May 22 22:35 starfield.pyc
-rw-r--r--    1 dyoo     dyoo         2010 May 22 22:25 three_d.py
-rw-r--r--    1 dyoo     dyoo         3590 May 22 22:35 three_d.pyc
###

If you want to read more about these functions, you can find more details
in the Python Standard Library.  Here's are some links you might find
useful:

    http://www.python.org/doc/lib/os-procinfo.html
    http://www.python.org/doc/lib/os-newstreams.html
    http://www.python.org/doc/lib/module-popen2.html


(There are some other functions with the name 'exec...' in the 'os'
module, but they're probably not what you want: the 'exec...' functions
end up actually replacing the Python program altogether --- Python
reliquishes complete control to the 'exec'ed program.)


If you have more questions, please feel free to ask.  Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Sun Jun  9 08:11:48 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 9 Jun 2002 00:11:48 -0700 (PDT)
Subject: [Tutor] Python Question - Repeating output.
In-Reply-To: <F62iO9oRdUYPuj1DcYA00008f7a@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206090000110.7912-100000@hkn.eecs.berkeley.edu>


On Sun, 9 Jun 2002, Guess Who? Me wrote:

> I downloaded python yesterday and am working through the tutorial. I got
> to http://www.honors.montana.edu/~jjc/easytut/easytut/node6.html, the
> part about while. I couldn't get it, because if a=0, and a=a+1, then
> wouldn't 0=1???

Ah!  The thing is that '=' in many programming languages does not mean
equality: in Python, it's a symbol for 'assignment'.

If it helps, if you see:

    a = a + 1

try crossing your eyes so that the '=' sign looks more like an arrow:

    a  <-- a + 1

This says, "the value of the 'a + 1' expression will be assigned into the
'a' variable."

There's a sense of time, a sense of "state" involved here that may not
jive with the math that you may be used to.  At one point, the 'a'
variable contains '0', and after executing a few statements, time passes,
and now it might contain '1'.  So it's not math: it's more like
simulation, or like scratch paper.

Dunno if that made much sense.  *grin*



> And I kept trying to make my own program with while, but they keep
> giving me infinite answers. Here's what I did:
>
> #I need an idea to make a program using "while". So I'll be lame.
> a=input("Pick a number that is not lame:")
> while a==69:
>     print "Good job!"
> while a !=69:
>     print "Moron."
> It gave me infinite "Moron." or "Good job!"s.
> So basically - any clearer definitions of while?

You had the right idea: the only problem is that the code doesn't give the
user the opportunity to revise the value of 'a'.  It's as if a child were
asking "Are we there yet?  Are we there yet?" even before the parents have
a chance to holler "Not yet".


Here's one way to fix that:

###
a = input("Pick a number that is not lame:")
while a==69:
    print "Good job!"
while a !=69:
    print "Moron."
    a = input("Play it again, Sam: ")
###


And that might help more.  Computers are stupid machinery, so they'll do
pointless things until we tell them not to.  *grin* Note that what gets
repeated in a while loop is ONLY what's indented underneath it.


Hope this helps!




From glingl@aon.at  Sun Jun  9 08:27:37 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun, 9 Jun 2002 09:27:37 +0200
Subject: [Tutor] Python Question - Repeating output.
References: <Pine.LNX.4.44.0206090000110.7912-100000@hkn.eecs.berkeley.edu>
Message-ID: <001001c20f87$21afdbd0$1615a8c0@mega>

----- Original Message ----- 
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: "Guess Who? Me" <beercanz@hotmail.com>

> 
> Here's one way to fix that:

> .......
 
> ###
> a = input("Pick a number that is not lame:")
> while a==69:
>     print "Good job!"
> while a !=69:
>     print "Moron."
>     a = input("Play it again, Sam: ")
> ###
> 
> 

deh! still buggy (or did you intend infinite good jobs with 69?):

Pick a number that is not lame:69
Good job!
Good job!
Good job!
Good job!
Good job!
Good job!
Good job!
Good job!
Traceback (most recent call last):
  File "C:/____arbeit____/Py/infinit.py", line 3, in ?
    print "Good job!"
  File "C:\Python22\Tools\idle\PyShell.py", line 679, in write
    self.shell.write(s, self.tags)
  File "C:\Python22\Tools\idle\PyShell.py", line 670, in write
    raise KeyboardInterrupt
KeyboardInterrupt



The following might help more:

a = input("Pick a number that is not lame:")
while a!=0:
    if a==69:   
        print "Good job!"
    else:
        print "Moron."
    a = input("Play it again, Sam: ")
print "Huuuh!"

which works like this:

>>> Pick a number that is not lame:77
Moron.
Play it again, Sam: 70
Moron.
Play it again, Sam: 69
Good job!
Play it again, Sam: 69
Good job!
Play it again, Sam: 0
Huuuh!

>>> 

(or I misunderstood the question due to
incomplete knowledge of English)

Gregor





From dyoo@hkn.eecs.berkeley.edu  Sun Jun  9 08:33:58 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 9 Jun 2002 00:33:58 -0700 (PDT)
Subject: [Tutor] Re: Time Function  [strftime / strptime]
In-Reply-To: <20020608130905.A27711@babylonia.flatirons.org>
Message-ID: <Pine.LNX.4.44.0206090028520.7912-100000@hkn.eecs.berkeley.edu>


On Sat, 8 Jun 2002, Chris Avery wrote:

> time.strftime() returns the time you want.
> time.strftime("%h-%m") or something like that should work.

By the way, you may find this post useful:

http://groups.google.com/groups?selm=mailman.1023213423.29408.clpa-moderators%40python.org

time.strptime() is the function that does the inverse of strftime(): it
reads date strings back into the "epoch seconds" that Python can easily
work with... but it appears to be available only on Unix systems.

However, the message above refers to a pure Python implementation of the
time.strptime() function, so if you ever need to use it in a non-Unix
environment, this might be useful.


Good luck!




From dyoo@hkn.eecs.berkeley.edu  Sun Jun  9 08:44:24 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 9 Jun 2002 00:44:24 -0700 (PDT)
Subject: [Tutor] Is there a function for refreshing what's in the console?
In-Reply-To: <3D01B4FD.000007.47955@athlon900.vic.optushome.com.au>
Message-ID: <Pine.LNX.4.44.0206090040390.7912-100000@hkn.eecs.berkeley.edu>


On Sat, 8 Jun 2002, Dimitrije Nikic wrote:

> Is there a function for refreshing what's in the console? (Eg. delete
> everything printed previously in the window)

There's the silly answer of:

###
for i in range(80):
    print
###


*grin* But you're probably thinking something more on the lines of
clearing the whole screen, and having the cursor at the top.  For that, if
you're running Windows, try:

###
import os
os.system('cls')
###


If you're running a Unix:

###
import os
os.system('clear')
###


As you can tell, the problem is that it's somewhat system dependent, and I
don't think anyone's written a nice module that hides this dependency yet.



Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Sun Jun  9 08:48:13 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 9 Jun 2002 00:48:13 -0700 (PDT)
Subject: [Tutor] Python Question - Repeating output.
In-Reply-To: <001001c20f87$21afdbd0$1615a8c0@mega>
Message-ID: <Pine.LNX.4.44.0206090045060.7912-100000@hkn.eecs.berkeley.edu>


> > Here's one way to fix that:
>
> > .......
>
> > ###
> > a = input("Pick a number that is not lame:")
> > while a==69:
> >     print "Good job!"
> > while a !=69:
> >     print "Moron."
> >     a = input("Play it again, Sam: ")
> > ###
> >
> >
>
> deh! still buggy (or did you intend infinite good jobs with 69?):
>
> Pick a number that is not lame:69
> Good job!
> Good job!
> Good job!
> Good job!
> Good job!
> Good job!
> Good job!
> Good job!


Yikes!  Well, at least it's complementary.  *grin*

I was thinking of that second infinite loop, but you're right: the first
bug sideswiped me.  I have tunnel vision, which helps when I'm hunting
specific bugs, but I sometimes don't look at the big picture.

Thanks for the correction!




From donni@melwestmarket.com  Sun Jun  9 10:28:57 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Sun, 9 Jun 2002 19:28:57 +1000 (AUS Eastern Standard Time)
Subject: [Tutor] Thanks for your help guys...
Message-ID: <3D031FD9.000009.49799@athlon900.vic.optushome.com.au>

--------------Boundary-00=_9CMFMY50000000000000
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thank you all people for helping me with the clear and time functions. i =
appreciate it :)
although i still need the beep function which works for linux
i'm glad i joined this user group :)
--------------Boundary-00=_9CMFMY50000000000000
Content-Type: Text/HTML;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">
</head>

<BODY background=3D"" bgColor=3D#ffffff style=3D"BACKGROUND-POSITION: 0px=
 0px; FONT-SIZE: 10pt; MARGIN: 1px; FONT-FAMILY: Arial" scroll=3Dyes ORGY=
POS=3D"0">
<TABLE border=3D0 cellPadding=3D0 cellSpacing=3D0 id=3DINCREDIMAINTABLE w=
idth=3D"95%">
<TR>

<TD id=3DINCREDITEXTREGION width=3D"100%" style=3D"PADDING-RIGHT: 7px; PA=
DDING-LEFT: 7px; FONT-SIZE: 10pt; FONT-FAMILY: Arial"=20
   >
      <DIV>Thank you all people for helping me with the clear and time=20
      functions. i appreciate it :)</DIV>
      <DIV>although i still need the beep function which works for linux<=
/DIV>
      <DIV>i'm glad i joined this user group :)</DIV></TD>
</TR>

<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">

=09<TABLE cellPadding=3D0 cellSpacing=3D0 width=3D"100%">
=09<TR>
=09<TD width=3D"100%"></TD>
=09<TD align=3Dmiddle id=3DINCREDISOUND vAlign=3Dbottom></TD>
=09<TD align=3Dmiddle id=3DINCREDIANIM vAlign=3Dbottom></TD>
=09</TR>
=09</TABLE>

</TD>
</TR>

</TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email ha=
s finally=20
evolved</B> - </FONT><A href=3D"http://www.bravenet.com/out.php?id=3D768"=
><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT>
</BODY>
</html>
--------------Boundary-00=_9CMFMY50000000000000--




From glide@slingshot.co.nz  Sun Jun  9 21:15:46 2002
From: glide@slingshot.co.nz (Graeme Andrew)
Date: Mon, 10 Jun 2002 08:15:46 +1200
Subject: [Tutor] Menu Code ... ?
Message-ID: <200206100815.46576.glide@slingshot.co.nz>

Hi All,

I am new to Python and was wondering if anyone can point be to some sampl=
e=20
'Menu' type code. I am assuming  that there are no built in menu commands=
 ?

The python code I am writing  is server based and acts as an installation=
=20
script for out software. So must run on Windows and Unix. The menu part I=
 am=20
intending to make data driven .. ie read the 'ini' file and display a men=
u=20
accordingly.  There is no GUI requiremnt for the menu. ... closest thing =
I=20
can think of at the moment is the Red Hat Linux install program ... which=
 is=20
evidently python based.

Any ideas would be appreciated ...

Thanks in advance
Graeme Andrew
Kiwi
=20



From ak@silmarill.org  Sun Jun  9 21:55:17 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sun, 9 Jun 2002 16:55:17 -0400
Subject: [Tutor] Menu Code ... ?
In-Reply-To: <200206100815.46576.glide@slingshot.co.nz>
References: <200206100815.46576.glide@slingshot.co.nz>
Message-ID: <20020609205517.GA9985@ak.silmarill.org>

On Mon, Jun 10, 2002 at 08:15:46AM +1200, Graeme Andrew wrote:
> Hi All,
> 
> I am new to Python and was wondering if anyone can point be to some sample 
> 'Menu' type code. I am assuming  that there are no built in menu commands ?
> 
> The python code I am writing  is server based and acts as an installation 
> script for out software. So must run on Windows and Unix. The menu part I am 
> intending to make data driven .. ie read the 'ini' file and display a menu 
> accordingly.  There is no GUI requiremnt for the menu. ... closest thing I 
> can think of at the moment is the Red Hat Linux install program ... which is 
> evidently python based.
> 
> Any ideas would be appreciated ...
> 
> Thanks in advance
> Graeme Andrew
> Kiwi
>  
Do you mean something like this:

def do_this():
    ...

def do_that():
    ...

menu = {
    'a': do_this,
    'b': do_that,
}

answer = raw_input()

# run chosen function
menu[answer]()

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

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From neutron878@cayuse.net  Mon Jun 10 01:17:29 2002
From: neutron878@cayuse.net (Ricardo Ortega)
Date: Sun, 9 Jun 2002 20:17:29 -0400
Subject: [Tutor] integer
Message-ID: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>

This is a multi-part message in MIME format.

------=_NextPart_000_0001_01C20FF2.C542D930
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

How can I get an integer from a string example: =91BLK 15423 L=92
How can I get just the integer from that string if I didn=92t know what =
it
looked like before hand all I new is that there was a number somewhere
in the string.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
=20

------=_NextPart_000_0001_01C20FF2.C542D930
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DWindows-1252">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C20FF2.ACB17B10">
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </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:12.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;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
@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>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>How can I get an integer from a string example: =
=91BLK
15423 L=92<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>How can I get just the integer from that string if I =
didn=92t
know what it looked like before hand all I new is that there was a =
number somewhere
in the string.<o:p></o:p></span></font></p>

</div>

</body>

</html>
<BR>

<P><FONT SIZE=3D2>---<BR>
Outgoing mail is certified Virus Free.<BR>
Checked by AVG anti-virus system (http://www.grisoft.com).<BR>
Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002<BR>
</FONT> </P>

------=_NextPart_000_0001_01C20FF2.C542D930--




From dman@dman.ddts.net  Mon Jun 10 02:13:11 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun, 9 Jun 2002 20:13:11 -0500
Subject: [Tutor] Re: integer
In-Reply-To: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>
References: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>
Message-ID: <20020610011311.GA1725@dman.ddts.net>

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

On Sun, Jun 09, 2002 at 08:17:29PM -0400, Ricardo Ortega wrote:
| How can I get an integer from a string example: ?BLK 15423 L?
| How can I get just the integer from that string if I didn?t know what it
| looked like before hand all I new is that there was a number somewhere
| in the string.

In general, parsing an arbitrary string with no predefined structure
is impossible.  If I throw random data at you, how would you make any
sense out of it, unless we first agree on some structure?  Random data
looks much like grafiti does.

OTOH, if you know something about the string, for example the one you
gave above, it can be parsed :

# start with the data
s_org =3D "?BLK 15423 L?"

# split it on the spaces, and keep just the number part
s_num =3D s_org.split( ' ' )[1]

# now try and convert it to an integer.  be aware that if the data is
# malformed (eg a corrupt file) the conversion will fail
try :
    number =3D int( s_num )
except ValueError , err :
    print "Couldn't convert '%s' to a number.\n%s" % ( s_num , str( err ) )

HTH,
-D

--=20

Microsoft is to operating systems & security ....
                                     .... what McDonald's is to gourmet coo=
king
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAj0D/ScACgkQO8l8XBKTpRTrYgCfVMXM+Gz6+6knTJiOp2FwpaNA
uWEAn3sYeRtDFPYbis4M0DtehjcqLgtt
=hFWH
-----END PGP SIGNATURE-----

--IS0zKkzwUGydFO0o--



From urnerk@qwest.net  Sun Jun  9 23:21:04 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 9 Jun 2002 18:21:04 -0400
Subject: [Tutor] integer
In-Reply-To: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>
References: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>
Message-ID: <200206091821.04509.urnerk@qwest.net>

On Sunday 09 June 2002 08:17 pm, Ricardo Ortega wrote:
> How can I get an integer from a string example: =91BLK 15423 L=92
> How can I get just the integer from that string if I didn=92t know what=
 it
> looked like before hand all I new is that there was a number somewhere
> in the string.

Hi Ricardo:

Import the regular expression (regexp) module, named re:

>>> import re

Then compile a search pattern.  The one below looks for any string of one=
 or
more digits.  You only need to compile this pattern once, then use it ove=
r and
over.

>>> srch =3D re.compile("[0-9]+") =20

Now here's a short function that uses the search method of the srch objec=
t
(created by your re.compile()).  If it gets a result, it'll return the
matching segment, otherwise it returns the empty string.

>>> def getstr(thestr):
=09m =3D srch.search(thestr)
=09if m:  return m.group()
=09else:  return ''

Here it is in action:
=09
>>> getstr("BLK 15423 L")
'15423'

Another example:

>>> getstr("RRS 44523LL 12P")
'44523'

As written, we're only picking up the first match in the string, but=20
with tweaks could get them all.

You can adapt the above for your own purposes.

For a lot of interesting reading on regular expressions in Python, see:
http://py-howto.sourceforge.net/regex/regex.html

Kirby

PS:  instead of "[0-9]+" as the pattern, you could use "\d+" and get
the same result, as \d means the same as [0-9] i.e. "any decimal digit".




From lha2@columbia.edu  Mon Jun 10 04:22:37 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Sun, 09 Jun 2002 23:22:37 -0400
Subject: [Tutor] integer
References: <000001c21014$4c547930$96a594ce@neutronxmmrdqk>
Message-ID: <3D041B7D.933B96D5@mail.verizon.net>

Don't know why netscape isn't quoting the message, but too lazy to do
something about it. Maybe because it had been formatted text? The query
had been, "how do you pull an integer out of the middle of a string?"

This seems to do the trick, as long as you only want the first integer
and it is an integer, not a float (would require more work). Would also
want to do something like "answer = int(strbuild)" at the end in order
for the number to be a number:

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> foo = "blk 15423 l"
>>> sentinel = ''
>>> strbuild = ''
>>> for letter in foo:
	if letter.isdigit():
		sentinel = 1
		strbuild += letter
	elif sentinel:
		break

>>> strbuild
'15423'



From jgregorio@ultrasw.com  Mon Jun 10 06:12:02 2002
From: jgregorio@ultrasw.com (Josh Gregorio)
Date: Sun, 09 Jun 2002 22:12:02 -0700
Subject: [Tutor] Linux verson of msvcrt
Message-ID: <3D043522.8050502@ultrasw.com>

What is the GNU/Linux/Unix equivalent to
import msvcrt
msvcrt.getch() ?

I found the windows version in the docs because I knew what to look 
for--but I can't find how to getch() from Linux. Is there a way to use 
getch() (or something else that will wait for the user to press some 
key) that works the same in Windows and GNU/Linux?

Thanks,
Josh

ps Does anyone have any tips for searching documentation when you don't 
know the proper names for what you are looking for?






From billintucson@yahoo.com  Mon Jun 10 07:22:55 2002
From: billintucson@yahoo.com (Bill Gillespie)
Date: Sun, 9 Jun 2002 23:22:55 -0700 (PDT)
Subject: [Tutor] Where best to start? First program to: login, read from and close a serial line?
Message-ID: <20020610062255.51796.qmail@web11802.mail.yahoo.com>

Hi Folks,

I was very happy to find this resource. I'm a new guy and am just
starting to learn to do some simple programming, and Python is my first
"real programming" language. It's very exciting!

My first programming project: 
At work we have a "floor and oil temperature control system". I would
like to build a simple GUI, allowing us to interrogate, display and
change these two values: 

1) OIL set point 
2) FLOOR set point


The Tkinter (GUI) part looks learnable - but I don't know where to
start in terms of 

--> logging into a remote machine 
          (in Xterm from a Linux machine - to a sun os machine)

  --> opening a serial line on it
          (I normally just type "tip oftc" to connect <oil floor and   
        temp cont>)

   --> interrogating the embedded device on it,
          (two seperate commands ask for current - or order a change)  

    --> and then logging out again.
          ($. closes the connection) then I log out of the machine)

Any advice on the general idea of what should take place will be most
welcome. 

Thanks much,

Bill



  

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From papamountain@yahoo.com  Mon Jun 10 09:57:18 2002
From: papamountain@yahoo.com (Richard)
Date: Mon, 10 Jun 2002 01:57:18 -0700 (PDT)
Subject: [Tutor] Just learning
Message-ID: <20020610085718.35047.qmail@web12205.mail.yahoo.com>

--0-84738498-1023699438=:34063
Content-Type: text/plain; charset=us-ascii


Hello all!

I have installed Python and have started to play around a bit. It seems very interesting, and fun. Perhaps in the near future, I will be of a level where I can have a recourse with some of you and exchange ideas. I look forward to it!



---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup
--0-84738498-1023699438=:34063
Content-Type: text/html; charset=us-ascii

<P><FONT face="Comic Sans MS">Hello all!</FONT></P>
<P><FONT face="Comic Sans MS">I have installed Python and have started to play around a bit. It seems very interesting, and fun. Perhaps in the near future, I will be of a level where I can have a recourse with some of you and exchange ideas. I look forward to it!</FONT></P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://rd.yahoo.com/welcome/*http://fifaworldcup.yahoo.com/fc/en/spl">Sign-up for Video Highlights</a> of 2002 FIFA World Cup
--0-84738498-1023699438=:34063--



From wolf_binary@hotmail.com  Mon Jun 10 13:56:47 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Mon, 10 Jun 2002 07:56:47 -0500
Subject: [Tutor] reference material
Message-ID: <DAV27uwdUTaGmvSVMum000108d5@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C21054.5EC10300
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi all,

I wanted to know what you guys recommend for reference material on =
Tkinter widgets.  I need a source of all the attributes to each one so I =
know what I can do to my widgets.  Also, if you have any recomendations =
for general python programming reference book or online source let me =
know. =20

Thanks,
Cameron Stoner

------=_NextPart_000_0013_01C21054.5EC10300
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I wanted to know what you guys =
recommend for=20
reference material on Tkinter widgets.&nbsp; I need a source of all the=20
attributes to each one so I know what I can do to my widgets.&nbsp; =
Also, if you=20
have any recomendations for general python programming reference book or =
online=20
source let me know.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C21054.5EC10300--



From pythontutor@venix.com  Mon Jun 10 14:26:33 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Mon, 10 Jun 2002 09:26:33 -0400
Subject: [Tutor] Linux verson of msvcrt
References: <3D043522.8050502@ultrasw.com>
Message-ID: <3D04A909.9080108@venix.com>

http://mail.python.org/pipermail/tutor/2002-April/013989.html
[Tutor] program to count keys with timer display and clock display

I asked a somewhat similar question back in April.  This response from Paul
was quite helpful.  It use PyGame.

Alan Gauld also supplied a refernce to his website
pointing out how to use TKinter for processing the keystrokes.

Josh Gregorio wrote:

> What is the GNU/Linux/Unix equivalent to
> import msvcrt
> msvcrt.getch() ?
> 
> I found the windows version in the docs because I knew what to look 
> for--but I can't find how to getch() from Linux. Is there a way to use 
> getch() (or something else that will wait for the user to press some 
> key) that works the same in Windows and GNU/Linux?
> 
> Thanks,
> Josh
> 
> ps Does anyone have any tips for searching documentation when you don't 
> know the proper names for what you are looking for?
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From urnerk@qwest.net  Mon Jun 10 16:27:37 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 10 Jun 2002 08:27:37 -0700
Subject: [Tutor] Where best to start? First program to: login, read
 from and close a serial line?
In-Reply-To: <20020610062255.51796.qmail@web11802.mail.yahoo.com>
Message-ID: <4.2.0.58.20020610082145.01be7c00@pop3.norton.antivirus>

>
>Any advice on the general idea of what should take place will be most
>welcome.
>
>Thanks much,
>
>Bill

Hi Bill --

Probably easiest if you can wrap Python around the system
commands you already use.  t = popen('cmd') will execute
'cmd' (what you'd normally enter in the shell) and
t.readlines() will give back a list of what 'cmd'
returns, e.g. in the Python shell:

    >>> from os import popen
    >>> t = popen('ls')
    >>> for line in t.readlines():  print line,

should echo a directory listing to your screen.

So you should be able to pop up GUI widgets ala Tkinter
which wrap your existing system commands.  While testing,
you might write some dummy scripts on a standalone box
to simulate the commands and their return values.

Kirby




From sarmstrong13@mac.com  Mon Jun 10 14:46:25 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 10 Jun 2002 08:46:25 -0500
Subject: [Tutor] reference material
In-Reply-To: <DAV27uwdUTaGmvSVMum000108d5@hotmail.com>
Message-ID: <B92A17E1.6CA4%sarmstrong13@mac.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.

--B_3106550447_373257
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

Start with www.python.org.

There are many different links to online tutorials there under the Documents
section.

Good Luck.
SA

On 6/10/02 7:56 AM, "Cameron Stoner" <wolf_binary@hotmail.com> wrote:

> hi all,
>  
> I wanted to know what you guys recommend for reference material on Tkinter
> widgets.  I need a source of all the attributes to each one so I know what I
> can do to my widgets.  Also, if you have any recomendations for general python
> programming reference book or online source let me know.
>  
> Thanks,
> Cameron Stoner
> 



--B_3106550447_373257
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Re: [Tutor] reference material</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">Start with www.python.org.<BR>
<BR>
There are many different links to online tutorials there under the Document=
s section.<BR>
<BR>
Good Luck.<BR>
SA<BR>
<BR>
On 6/10/02 7:56 AM, &quot;Cameron Stoner&quot; &lt;wolf_binary@hotmail.com&=
gt; wrote:<BR>
<BR>
</FONT><BLOCKQUOTE><FONT SIZE=3D"2"><FONT FACE=3D"Arial">hi all,<BR>
</FONT></FONT><FONT FACE=3D"Verdana"> <BR>
</FONT><FONT SIZE=3D"2"><FONT FACE=3D"Arial">I wanted to know what you guys rec=
ommend for reference material on Tkinter widgets. &nbsp;I need a source of a=
ll the attributes to each one so I know what I can do to my widgets. &nbsp;A=
lso, if you have any recomendations for general python programming reference=
 book or online source let me know. &nbsp;<BR>
</FONT></FONT><FONT FACE=3D"Verdana"> <BR>
</FONT><FONT SIZE=3D"2"><FONT FACE=3D"Arial">Thanks,<BR>
Cameron Stoner<BR>
</FONT></FONT><FONT FACE=3D"Verdana"><BR>
</FONT></BLOCKQUOTE><FONT FACE=3D"Verdana"><BR>
</FONT>
</BODY>
</HTML>


--B_3106550447_373257--




From sarmstrong13@mac.com  Mon Jun 10 16:39:37 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 10 Jun 2002 10:39:37 -0500
Subject: [Tutor] Re: Newbie OOP Question.(diff between function, module and class)
In-Reply-To: <15620.49909.679355.726113@12-248-41-177.client.attbi.com>
Message-ID: <B92A3269.6CD0%sarmstrong13@mac.com>

On 6/10/02 10:17 AM, "Skip Montanaro" <skip@pobox.com> wrote:
> Here's my take on things:
> 
> * A function is an action to perform using a set of input arguments and
>  returning a set of output arguments.  For example:
> 
>>>> print sin(47)
>  0.123573122745
> 
Got it.

> * A class associates a chunk of data with a set of functions which operate
>  on that data.  The first argument to each function in a class (typically
>  called a "method" in Python) is a reference to the data stored in that
>  instance of the class.  For example:
> 
>   import math
>   class Point:
>       def __init__(self, x, y):
>           self.x = x
>           self.y = y
> 
>       def polar(self):
>           return math.sqrt(self.x**2+self.y**2), math.atan2(self.y, self.x)
> 

So the "def __init__" is a function in the class and is assigning the
variables x and y as attributes of the class, correct? If so, are the
variables x and y supplied outside of the class (I guess this would be
global)?

> * A module is an object that partitions the namespace in a hierarchy.  For
>  example, you can have a function named "sin" which is distinct from the
>  sin function in the math module ("math.sin").  Modules used in a
>  straightforward way only add a single extra level of hierarchy to the
>  namespace.  Packages generalize this concept to multiple levels (modules
>  inside modules).
A module is more or less, in very general terms, a package of classes and/or
functions that are then imported into the __main__ program, correct?

One last question, sorry if this is very basic but I feel these terms need
better definitions for newbies like me (the only other languages I have
experience with are Qbasic and HTML) what is a namespae? Is that analagous
to pwd of the program? For instance, if the program is currently in one are
of the script doing work, would that be considered the namespace?

See everything I read explains these terms in definitions that are readibly
understandable by people with programming experience. I kind of need a
"layman's" terms tutorial because I'm so new to programming.

But this has been very helpful dialogue in defining these terms and I feel
the people on this list have been very helpful. Thank You all.

Thanks.
SA




From phthenry@earthlink.net  Mon Jun 10 17:20:38 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Mon, 10 Jun 2002 12:20:38 -0400
Subject: [Tutor] parsing--is this right?
Message-ID: <20020610122037.A26494@localhost.localdomain>

I have just stumbled across the concept of parsing and parsing
grammars, and wondered if I am using the right tool.

I haved downloaded and installed plex in order to parse a rtf
document. The rtf looks like this:

{\footnote {\i an italicized word} {\i maybe another italicized
word} text }

In order to parse this text, I use a counter to count the number
of open and closed curly brackets. I am following the tutorial in
doing this.

However, I am wondering if plex does things the wrong way. 

If I understand things correctly, you should not have to count
brackets. A parser should use the grammar to understand what
state you are in. 

I have looked at another example using the rtf example of another
parser, mxTextTools. This parser does not count tags at all.

I like plex because it was the only parser that I could get to
work! However, I am wondering if it lacks the power a parser
should have, and if I should devote my time to a better tool.

Thanks

Paul


-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From alex@gabuzomeu.net  Mon Jun 10 18:06:36 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Mon, 10 Jun 2002 19:06:36 +0200
Subject: [Tutor] Re: Newbie OOP Question.(diff between function,
 module and class)
In-Reply-To: <20020610154108.24837.15883.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020610184206.00b99a20@pop3.norton.antivirus>

At 11:41 10/06/2002 -0400, you wrote:
>Date: Mon, 10 Jun 2002 10:39:37 -0500
>From: SA <sarmstrong13@mac.com>
>Subject: [Tutor] Re: Newbie OOP Question.(diff between function, module 
>and class)

> >   import math
> >   class Point:
> >       def __init__(self, x, y):
> >           self.x = x
> >           self.y = y
> >
> >       def polar(self):
> >           return math.sqrt(self.x**2+self.y**2), math.atan2(self.y, 
> self.x)
>
>So the "def __init__" is a function in the class and is assigning the
>variables x and y as attributes of the class, correct?

Yes. A function used in a class is usually called a "method".

>If so, are the variables x and y supplied outside of the class

Correct. They are parameters that are passed when the method (__init__()) 
is called.

>(I guess this would be global)?

Within __init__(), x and y are local variables. Hence they disappear when 
the method exits. That's why they are reassigned to self.x and self.y. 
self.x and self.y are attributes that survive as long as the class instance.

>A module is more or less, in very general terms, a package of classes 
>and/or functions that are then imported into the __main__ program, correct?

Yes, sounds reasonable.

>One last question, sorry if this is very basic but I feel these terms need
>better definitions for newbies like me (the only other languages I have
>experience with are Qbasic and HTML) what is a namespae? Is that analagous 
>to pwd of the program?

As I understand it, namespaces are related to scope of variables. 
Namespaces are similar to nested containers that holds variables. When you 
use a variable, Python looks up its value in the nearest, smallest 
namespace (i.e. local). If it cannot find it, it will look a bit farther 
(eg. the namespace of the current class instance). Still missing? Then it 
looks in the global namespace. Still missing? Python looks in the built-in 
namespace. What, still missing? Python gives up and raise an error.

I think namespaces can be pictured as small boxes in larger boxes. Values 
are searched in smaller boxes first. Also, the smaller the box, the shorter 
the variable lifetime.

>See everything I read explains these terms in definitions that are readibly
>understandable by people with programming experience. I kind of need a
>"layman's" terms tutorial because I'm so new to programming.

Here is a small test to try and make it more concrete:

##
globalFoo = "I am a global variable."

class Test:
     classFoo = "I am a class variable."

     def __init__(self):
         self.instanceFoo = "I am an instance variable."
         localFoo = "I am a local variable."
         print globalFoo
         print self.classFoo
         print self.instanceFoo
         print localFoo

if __name__ == "__main__":
     t = Test()
##


Cheers.

Alexandre




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 10 19:00:17 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 10 Jun 2002 11:00:17 -0700 (PDT)
Subject: [Tutor] Just learning
In-Reply-To: <20020610085718.35047.qmail@web12205.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206101056570.14790-100000@hkn.eecs.berkeley.edu>


On Mon, 10 Jun 2002, Richard wrote:

> I have installed Python and have started to play around a bit. It seems
> very interesting, and fun. Perhaps in the near future, I will be of a
> level where I can have a recourse with some of you and exchange ideas. I
> look forward to it!

Hi Richard,

We'll be happy to hear from you!  Please feel free to ask questions on the
list when you feel comfortable.


Good luck!




From skip@pobox.com  Mon Jun 10 18:26:52 2002
From: skip@pobox.com (Skip Montanaro)
Date: Mon, 10 Jun 2002 12:26:52 -0500
Subject: [Tutor] Re: Newbie OOP Question.(diff between function, module and class)
In-Reply-To: <B92A3269.6CD0%sarmstrong13@mac.com>
References: <15620.49909.679355.726113@12-248-41-177.client.attbi.com>
 <B92A3269.6CD0%sarmstrong13@mac.com>
Message-ID: <15620.57692.735525.490352@12-248-41-177.client.attbi.com>

    >> * A class associates a chunk of data with a set of functions which
    >>   operate on that data.  The first argument to each function in a
    >>   class (typically called a "method" in Python) is a reference to the
    >>   data stored in that instance of the class.  For example:
    >> 
    >> import math
    >> class Point:
    >>   def __init__(self, x, y):
    >>     self.x = x
    >>     self.y = y
    >> 
    >> def polar(self):
    >>   return math.sqrt(self.x**2+self.y**2), math.atan2(self.y, self.x)
    >> 

    SA> So the "def __init__" is a function in the class and is assigning
    SA> the variables x and y as attributes of the class, correct? If so,
    SA> are the variables x and y supplied outside of the class (I guess
    SA> this would be global)?

__init__ is the constructor for the class.  It's called for you when you
instantiate the class appropriately.  You create an instance of the class
like so:

    mypoint = Point(1,0)

    >> * A module is an object that partitions the namespace in a hierarchy.

    SA> A module is more or less, in very general terms, a package of
    SA> classes and/or functions that are then imported into the __main__
    SA> program, correct?

Even more generally, a package of objects.  Conceptually, it's no different
than how you'd carve up the namespace you live in outside of programming.
Ambiguous names need qualification.  If you wife says, "Honey, bring me up a
can of paint from the basement for the blue wall", and you have several
rooms painted in several shades of blue, you'd need a qualifier to decide
what room the paint was for.

    SA> One last question, sorry if this is very basic but I feel these
    SA> terms need better definitions for newbies like me (the only other
    SA> languages I have experience with are Qbasic and HTML) what is a
    SA> namespae? Is that analagous to pwd of the program? For instance, if
    SA> the program is currently in one are of the script doing work, would
    SA> that be considered the namespace?

Yes, it is more or less like the filesystem hierarchy.  In the current
directory, a reference to "blue.txt" would reference a file in the current
directory.  One significant difference is that Python's module/package
system doesn't have a syntax for referring to the current module's parent
(no "..").

-- 
Skip Montanaro (skip@pobox.com - http://www.mojam.com/)
Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 10 20:07:06 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 10 Jun 2002 12:07:06 -0700 (PDT)
Subject: [Tutor] Reading & printing lines from two different files
In-Reply-To: <200206070854.04671.scot@possum.in-berlin.de>
Message-ID: <Pine.LNX.4.44.0206070039140.8978-100000@hkn.eecs.berkeley.edu>

[Warning: this generator stuff depends on Python 2.2; we could mimic it
with Python 2.1, but it takes a little more work.]


> def generate_line(filename):
>     thisfile = open(filename, 'r')
>     for line in thisfile:
>         yield line

Actually, we can get this one for free --- Files implement the "iterators"
interface already, so we can say:

###
def generate_line(filename):
    return iter(open(file))
###

What this returns us is an "iterator", something that marches through, a
line at a time.  Here's an example that shows what a file iterator looks
like:

###
>>> file_iter = iter(open('/usr/share/dict/words'))
>>> file_iter
<xreadlines.xreadlines object at 0x8151760>
>>> file_iter.next()
'Aarhus\n'
>>> file_iter.next()
'Aaron\n'
>>> file_iter.next()
'Ababa\n'
>>> file_iter.next()
'aback\n'
>>> file_iter.next()
'abaft\n'
###


> while 1:
>     try:
>         print gen_one.next()
>         print gen_two.next()
>     except StopIteration:
>         break
>
> ==================================
>
> This does work here, tho it seems like an awful lot of code compared with
> your zip-and-readlines combination. Is there any simple way to explain why
> this is not such a memory hog?

readlines() sucks all of the lines into memory all at once, saving these
lines in a list.  Usually, this is a good thing, because it allows us to
look at any particular line --- we could look at line 42, or line 1009, or
line 4, or ... without having to do anything more than a simple list
element access.  What we get is the ability to "randomly-access" any line
in a file, and that's quite convenient.


But there is a cost to using readlines(): we load the whole file into
memory.  This becomes an issue if we're dealing with huge text files.
When we use iterators, we tell Python to sequentially march through our
sequence.  No more random access, but on the other hand, we only read a
line at a time.  So that's where the savings come in.



Here's a way of having the best of both works: making this look nice, and
having it be efficient too:

###
def zipiter(*sequences):
    """A generator version of the zip() function."""
    sequence_iters = [iter(seq) for seq in sequences]
    while 1:
        next_row = [seq_iter.next() for seq_iter in sequence_iters]
        yield tuple(next_row)


def printAlternatingLines(file1, file2):
    for (line1, line2) in zipiter(file1, file2):
        print line1
        print line2
###

(Warning: I have not tested this code yet.  I know this is going to bite
me, so I'll double check this tonight to make sure it works.)




> One thing I'm not sure of in the example above is where to put the
> thisfile.close() line to close those files again. My computer doesn't
> seem any worse for not closing them, but it does seem like bad
> manners...

We can leave it off in many cases, since Python will garbage collect files
that aren't accessible.  However, if we're writing some content into a
file, closing the file explicitely is a good idea, just to make sure our
mess is cleaned up.  *grin*

(Actually, the Jython variant of Python requires explicit file closing()
when we write.  See:

    http://www.jython.org/cgi-bin/faqw.py?req=show&file=faq03.008.htp

for more details.)



Hope this helps!




From alan.gauld@bt.com  Mon Jun 10 22:27:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 10 Jun 2002 22:27:04 +0100
Subject: [Tutor] Python Question - Repeating output.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21533F9EE@mbtlipnt02.btlabs.bt.co.uk>

>, the part about while. I couldn't get it, because 
> if a=0, and a=a+1, then wouldn't 0=1???</DIV>

This is a common problem for folks who speak math ;-)
In fact its so commoon some languages use a different 
symbol for assigning values such as ':='.
Thus Pascal would write your line as:

a := a+1

which is read 'a' becomes 'a' plus one.

So in python the '=' symbol doesn't mean 'is equal to' as 
in math, rather it means 'becomes' or 'takes on the value of'
and is called the 'assignment operator'

The math like equality test that you are used to is 
performed in Python with the double equal:

a == a + 1

which is always false as you would expect because 
mathematically it's nonsensical!


> a=input("Pick a number that is not lame:")<BR>
> while a==69:    # note you correctly used == here
>	 print "Good job!"
> while a !=69:
>	 print "Moron."<BR></DIV>

You only set the value of a once before going into the loop.
Try this instead:

a=input("Pick a number that is not lame:")
while a != 69:
   print 'Moron!'
   a=input("Pick a number that is not lame:")
print "Good job"

Now we change the value of a each time round the while loop.
Notice too that we only need one loop. The Good Job gets 
printed only when the while condition is false and the loop 
stops running.

> So basically - any clearer definitions of while? 

You could try my tutor under the Looping topic :-)

Basically the usual construct is:

set up initial condition(a above)
while condition:
     do something
     modify the test condition

Yours failed to change the test condition so it just 
kept on going round and round.

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From alan.gauld@bt.com  Mon Jun 10 22:27:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 10 Jun 2002 22:27:02 +0100
Subject: [Tutor] Newbie OOP Question.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21533F9ED@mbtlipnt02.btlabs.bt.co.uk>

> I'm still trying to grasp this OOP concept in Python. Can 
> someone tell me the difference between a function, a module, 
> and a class? 

In programming a module is a generic term for any kind of 
reusable software. In Pythin specifically it is formalised 
as a file containing Python program code that can be 
'import'ed into another Python session or program.

A module in the Python sense can encompass class definitions 
or functions or both as well as data and constant definitions.

The re module is a good example whereby you can use a 
functional interface or compile a regex into an object and 
call methods on it, both from the same module. It also defines 
some constants which are used top control the interpretation 
of regular expressions within those functions and methods.

(A method is just a jargon term for a function defined within 
  a class)

A class is a type of module in a programming sense and is 
often implemented inside a module in the pythonic sense.
A class is a template for a set of functions(methods) and 
the set of variables upon which they operate. (These 
variables are often called the state holders of the objects 
produced from the class.) We can create many different 
instances of a class each with its own "copy" of the methods 
and data. The methods will be identical in functionality but 
use the data values from the local instance.

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From sarmstrong13@mac.com  Mon Jun 10 22:36:41 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 10 Jun 2002 16:36:41 -0500
Subject: [Tutor] Re: Newbie OOP Question.(diff between function,
 module and class)
In-Reply-To: <4.3.2.7.2.20020610184206.00b99a20@pop3.norton.antivirus>
Message-ID: <B92A8619.6CED%sarmstrong13@mac.com>

On 6/10/02 12:06 PM, "Alexandre Ratti" <alex@gabuzomeu.net> wrote:

> 
> Here is a small test to try and make it more concrete:
> 
> ##
> globalFoo = "I am a global variable."
> 
> class Test:
>    classFoo = "I am a class variable."
> 
>    def __init__(self):
>        self.instanceFoo = "I am an instance variable."
>        localFoo = "I am a local variable."
>        print globalFoo
>        print self.classFoo
>        print self.instanceFoo
>        print localFoo
> 
> if __name__ == "__main__":
>    t = Test()
> ##
> 
> 
> Cheers.
> 
> Alexandre
> 
> 
Ok. This is all beginning to make more sense now.

Just a couple of more questions:

1. How does "print self.classFoo" know to print classFoo if the classFoo
   variable is defined prior to the __init__(self) function?

2. What is the purpose of the line "if __name__ == "__main__":"? (How does
   it work and why do you use this instead of just running "t = Test"?)


Thanks again in advance. Everyone here has been very helpful.

Thanks.
SA




From alan.gauld@bt.com  Mon Jun 10 22:45:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 10 Jun 2002 22:45:43 +0100
Subject: [Tutor] reference material
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C640@mbtlipnt02.btlabs.bt.co.uk>

> I wanted to know what you guys recommend for reference material on =
> Tkinter widgets.  

My primary source is the O'Reilly Tcl/Tk in a Nutshell
Its all Tcl based but its easy to translate.

Next stop is the online Tkinter reference by F Lundh

When that fails I turn to Graysons Tkinter book

Finally, I read the source code! Unfortunately that 
happens more often than I'd like :-(

> recomendations for general python programming 
> reference book or online source 

Books are Beasleys Essential Python and Lutz 
Programming Python. Very different books but both 
good one past the basics.

Online the best is the standard docs plus the SIGS.
Followed by the Dive into Python site

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From alan.gauld@bt.com  Mon Jun 10 22:47:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 10 Jun 2002 22:47:04 +0100
Subject: [Tutor] Linux verson of msvcrt
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C641@mbtlipnt02.btlabs.bt.co.uk>

> What is the GNU/Linux/Unix equivalent to
> import msvcrt
> msvcrt.getch() ?

import curses
curses.getch()

Alan G.



From aicolburn@yahoo.com  Mon Jun 10 22:52:17 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Mon, 10 Jun 2002 14:52:17 -0700 (PDT)
Subject: [Tutor] Newbie Q's
Message-ID: <20020610215217.25441.qmail@web20505.mail.yahoo.com>

Hi all--

I have two quick questions for you. First, if I have a
list made up of integers, is there a simple command to
let me find the sum of the integers (and assign the
value to a variable)? I've been able to do it, but
based on my miniscule knowledge of C++ something tells
me there's an easier way :-)

Second, as a way to practice what I've started
learning, I decided to try making a
(non-graphical)Blackjack game. I've got it set up so
that when cards are drawn from a deck, they go into a
list (one for the player, one for the dealer). (That's
where my question above comes from.)

The biggest difficulty I'm having is dealing with
aces, which can be valued at 1 or 11. I thought I had
everything figured out, until a hand came up that had
two aces in it :-) I'm sure many people have tried
making this kind of a program. How did you (or would
you) deal with this aspect of the program? 

Thanks for your help! It's great having this resource
available. -- Al (aicolburn@yahoo.com)

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From sarmstrong13@mac.com  Mon Jun 10 22:59:48 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 10 Jun 2002 16:59:48 -0500
Subject: [Tutor] Re: Newbie OOP Question.(diff between function,
 module and class)
In-Reply-To: <15620.57692.735525.490352@12-248-41-177.client.attbi.com>
Message-ID: <B92A8B84.6CF2%sarmstrong13@mac.com>

On 6/10/02 12:26 PM, "Skip Montanaro" <skip@pobox.com> wrote:

> 
>   SA> One last question, sorry if this is very basic but I feel these
>   SA> terms need better definitions for newbies like me (the only other
>   SA> languages I have experience with are Qbasic and HTML) what is a
>   SA> namespae? Is that analagous to pwd of the program? For instance, if
>   SA> the program is currently in one are of the script doing work, would
>   SA> that be considered the namespace?
> 
> Yes, it is more or less like the filesystem hierarchy.  In the current
> directory, a reference to "blue.txt" would reference a file in the current
> directory.  One significant difference is that Python's module/package
> system doesn't have a syntax for referring to the current module's parent
> (no "..").
Ahh. Now that may prove interesting. Would it be beneficial to make a
reserved command like .. That pops you back into the parent namespace?

Thanks.
SA




From alan.gauld@bt.com  Mon Jun 10 22:54:25 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 10 Jun 2002 22:54:25 +0100
Subject: [Tutor] Re: Newbie OOP Question.
 (diff between function, modu le and class)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C642@mbtlipnt02.btlabs.bt.co.uk>

> So the "def __init__" is a function in the class and is assigning the
> variables x and y as attributes of the class, correct? 

Correct, and is a special magic method that Python calls 
when you create an instance of the class.

> variables x and y supplied outside of the class 

When you instantiate it you pass the values in:

x,y = 7,8
pt = Point(3,4)
pt2 = Point(x,y)

Creates two instances of Point. One with x,y set to 3,4 the 
other set to 7,8

> A module is more or less, in very general terms, a package of 
> classes and/or functions that are then imported into the 
> __main__ program, correct?

Yes altho they could be imported into another module too.

> these terms need better definitions for newbies 

That's a large part of what my web tutor tries to do!

> what is a namespace? Is that analagous to pwd of the program? 

No. Its to do with the visibility of a name within a program.
Its explained in the 'Whats in a Name?' topic on my web site.

> understandable by people with programming experience. I kind of need a
> "layman's" terms tutorial because I'm so new to programming.

Thats exactly what my tutor is for, especially useful to you 
might be the 'namespaces', 'modules and functions' and OOP topics.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From alex@gabuzomeu.net  Mon Jun 10 23:05:22 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Tue, 11 Jun 2002 00:05:22 +0200
Subject: [Tutor] Re: Newbie OOP Question.(diff between function,
 module and class)
In-Reply-To: <B92A8619.6CED%sarmstrong13@mac.com>
References: <4.3.2.7.2.20020610184206.00b99a20@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020610235755.00b6b350@pop3.norton.antivirus>

At 16:36 10/06/2002 -0500, SA wrote:
> > globalFoo = "I am a global variable."
> >
> > class Test:
> >    classFoo = "I am a class variable."
> >
> >    def __init__(self):
> >        self.instanceFoo = "I am an instance variable."
> >        localFoo = "I am a local variable."
> >        print globalFoo
> >        print self.classFoo
> >        print self.instanceFoo
> >        print localFoo
> >
> > if __name__ == "__main__":
> >    t = Test()

>1. How does "print self.classFoo" know to print classFoo if the classFoo
>    variable is defined prior to the __init__(self) function?

Here, classFoo is a class attribute, whereas instanceFoo is an instance 
attribute. A class attribute is defined when the class is defined; it is 
available in all class instances (they share a common copy of the class 
attribute).

>2. What is the purpose of the line "if __name__ == "__main__":"? (How does 
>it work and why do you use this instead of just running "t = Test"?)

This is often used in Python for testing code. This condition is only true 
when the module is executed as standalone code; it is not true when the 
module is imported into another module. So you can store testing code after 
this condition; it won't run when the module is imported.

If you just use "t = Test" as top-level code in the module, it will be 
executed everytime (even when the code is imported into another module), 
which may not be what you want.


Cheers.

Alexandre




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 10 23:02:37 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 10 Jun 2002 15:02:37 -0700 (PDT)
Subject: [Tutor] parsing--is this right?
In-Reply-To: <20020610122037.A26494@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>


On Mon, 10 Jun 2002, Paul Tremblay wrote:

> I have just stumbled across the concept of parsing and parsing
> grammars, and wondered if I am using the right tool.
>
> I haved downloaded and installed plex in order to parse a rtf
> document. The rtf looks like this:
>
> {\footnote {\i an italicized word} {\i maybe another italicized
> word} text }

Hi Paul,


Hmmm... if the structure is always described by braces, perhaps it might
be easier to do a "recursive descent" parse through the message.  Here's a
sample parser that shows how the technique works.

###
import re

class Chunk:
    """We'll break up our data into Chunk pieces."""
    def __init__(self, type, data):
        self.type, self.data = type, data
    def __str__(self):
        if type(self.data) == type([]):
            stringed_data = [str(d) for d in self.data]
            return "TYPE %s: [%s]" % (self.type, ''.join(stringed_data))
        else:
            return str(self.data)

def parse(tokens):
    assert tokens, "Why are you trying to parse nothing?"

    if tokens[0] == '{':
        tokens.pop(0)        ## Eat the leading bracket.
        type = tokens.pop(0)
        collected_chunks = []
        while tokens[0] != '}':
            collected_chunks.append(parse(tokens))
        tokens.pop(0)        ## Eat the closing bracket.
        return Chunk(type, collected_chunks)
    else:
        ## Single token
        new_chunk = Chunk('text', tokens.pop(0))
        return new_chunk



def tokenize(text):
    "A toy tokenizer just for demonstration purposes."
    def nonEmpty(thing): return len(thing) > 0
    return filter(nonEmpty, re.split(r'([{}]|\s+)', text))



if __name__ == '__main__':
    EXAMPLE_TEXT = r"""{\footnote {\i an italicized word} {\i
maybe another italicized word} text }""".replace('\n', ' ')

    print parse(tokenize(EXAMPLE_TEXT))
###


The brackets make it really easy to detect boundaries where the parser
should clump things together.  I used a pathetically silly tokenizer()
function to do some initial preprocessing of the text: Plex would probably
do a better job at it.



> In order to parse this text, I use a counter to count the number
> of open and closed curly brackets. I am following the tutorial in
> doing this.
>
> However, I am wondering if plex does things the wrong way.

Plex is a tool for breaking the text into "tokens" that are easier to look
at.  However, it's not enough.  You'll probably want to use a parsing
technique like recursive descent, or use a specialized parser-building
tool.  We can talk about it more if you'd like.




> If I understand things correctly, you should not have to count brackets.
> A parser should use the grammar to understand what state you are in.

Yes, exactly.  The grammar that the example parser above is reading might
be described as:

;;;
Chunk :=  text                 # 'A "Chunk" is made of a piece of text
       | '{' Type Chunk* '}'   # 'or a bunch of Chunks between two
                               # brackets, associated with a particular
                               # chunk type.
;;;


With a parser, there's no need to count how deeply we're nested, as
grammars allow for a recursive definition that can go arbitrarily deep.



> However, I am wondering if it lacks the power a parser should have, and
> if I should devote my time to a better tool.

I've had some experience with the SPARK parser, and it's a nice tool:

    http://pages.cpsc.ucalgary.ca/~aycock/spark/

I used it a while back when I was playing with Pythonica, and it seemed to
work very well.  The only caveat I could make was that, back then, if
there was an error in the grammar, SPARK wouldn't give good error
messages.  I'm not sure if this complaints can be made now: perhaps this
has been fixed.



Another parser that I've heard good things about is Amit Patel's YAPPS
parser:

    http://theory.stanford.edu/~amitp/Yapps/



Anyway, I hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 10 23:28:28 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 10 Jun 2002 15:28:28 -0700 (PDT)
Subject: [Tutor] Python Question - Repeating output.  [defining special
 methods]
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB21533F9EE@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.44.0206101503210.18926-100000@hkn.eecs.berkeley.edu>

> The math like equality test that you are used to is performed in Python
> with the double equal:
>
> a == a + 1
>
> which is always false as you would expect because mathematically it's
> nonsensical!



That is, unless we're working in modulo arithmetic;

###
class ModNumber:
    def __init__(self, n, m):
        self.n, self.m = n % m, m

    def __add__(self, other):
        return ModNumber((self.n + other.n), self.m)

    def __str__(self):
        return "%s modulo %s" % (self.n, self.m)

    def __coerce__(self, other):
        if type(other) == type(42):
            return (self, ModNumber(other, self.m))

    def __eq__(self, other):
        return (self.n, self.m) == (other.n, other.m)
###


"Modulo arithmetic" wraps around a particular modulus, just as a clock's
hands wrap around twelve.  Here's an example of this modulo "clock"
arithmetic:


###
>>> print ModNumber(5, 12) + 9
2 modulo 12               ## Nine hours after six o'clock is
                          ## three o'clock.  We have to account
                          ## for the fact that humans count by one,
                          ## not zero.
>>> ModNumber(0, 1) == ModNumber(0, 1) + 1
1
###


I'm sorry, I just couldn't resist.  *grin*




From wesc@deirdre.org  Tue Jun 11 00:05:06 2002
From: wesc@deirdre.org (wesc@deirdre.org)
Date: Mon, 10 Jun 2002 16:05:06 -0700 (PDT)
Subject: [Tutor] [ANN] BayPIGgies meeting Wed 6/12 7:30pm
Message-ID: <200206102305.QAA28427@alpha.ece.ucsb.edu>

What:	Python for (Perl) Programmers
Who:	Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
When:	Wednesday, June 12, 2002
Where:	Stanford University, Palo Alto, CA
Time:	7:30pm - 9pm

This is a talk aimed at introducing Python to programmers
familar with Perl and other languages, and serves as a warm-up
to the full tutorial that will be presented at the O'Reilly
Open Source Convention in San Diego near the end of July.
Although the non-Python examples use Perl, it's aimed at
experienced programmers of all sorts. 

Our guest speaker is Aahz, long-time active member of the
Python community.  He has been kicking around the computer
industry for more than two decades, doing tech support,
programming, consulting, tech writing, and training. Aahz
recently signed a book contract for an intermediate-level
Python book, which will be published in early 2003. 

More information + directions:  http://deirdre.org/baypiggies/

-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"Core Python Programming", Prentice Hall PTR, © 2001
    http://starship.python.net/crew/wesc/cpp/

Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
    http://deirdre.org/baypiggies

wesley.j.chun :: wesc at deirdre.org
cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com
http://roadkill.com/~wesc/cyberweb/



From shalehperry@attbi.com  Tue Jun 11 00:49:50 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 10 Jun 2002 16:49:50 -0700 (PDT)
Subject: [Tutor] parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>
Message-ID: <XFMail.20020610164950.shalehperry@attbi.com>

> 
>> In order to parse this text, I use a counter to count the number
>> of open and closed curly brackets. I am following the tutorial in
>> doing this.
>>
>> However, I am wondering if plex does things the wrong way.
> 
> Plex is a tool for breaking the text into "tokens" that are easier to look
> at.  However, it's not enough.  You'll probably want to use a parsing
> technique like recursive descent, or use a specialized parser-building
> tool.  We can talk about it more if you'd like.
> 
> 

to be more explicit here.  plex is a lexer not a parser.  the lexer reads input
and decides what each piece it sees is.  This information is passed to the
parser.

foo { bar }

would result in:

word
brace
word
brace

being sent to the parser.  This is why you find yourself counting, you are
implementing a parser based on the tokens the lexer is sending you.



From HaakJ@masirv.com  Tue Jun 11 00:59:17 2002
From: HaakJ@masirv.com (Jim Haak)
Date: Mon, 10 Jun 2002 16:59:17 -0700
Subject: [Tutor] retreiving email file attachments
Message-ID: <9C9781ADDB73C549BC4D8E837BF8450E08C5D6@mail-socal01>

Does anyone have an example of using poplib to read an Inbox and then
passing the messages to the email package?   I am trying to parse zipped
attachments.  I've written low level code using just poplib.POP3 that works
fine in most cases, but the RFC variations in the headers makes it difficult
to consistently find the attachment boundaries.

If I could just get the email module to accept what I'm getting from poplib
retr() function....

Since the email module wants a file, I've tried writing all the 'lines' to a
file, but that doesn't seem to work.

This is probably really easy, but Python is my first and only language
experience and I still haven't groked all that class stuff yet.



From jeff@ccvcorp.com  Tue Jun 11 01:43:48 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 10 Jun 2002 17:43:48 -0700
Subject: [Tutor] retreiving email file attachments
References: <9C9781ADDB73C549BC4D8E837BF8450E08C5D6@mail-socal01>
Message-ID: <3D0547C4.FA0890FD@ccvcorp.com>


Jim Haak wrote:

> Does anyone have an example of using poplib to read an Inbox and then
> passing the messages to the email package?   I am trying to parse zipped
> attachments.  [...]
>
> Since the email module wants a file, I've tried writing all the 'lines' to a
> file, but that doesn't seem to work.

I haven't done this myself, but here's some ideas for you to research.

The POP3.retr() method returns a tuple, the second member of which is (iirc) a
list of lines.  You can probably safely discard the other two items.

lines = pop.retr(n)[1]

You need to feed a file to the email module, but saving all of this to a file
would be pointless.  The solution is the StringIO (or better yet, cStringIO),
which will convert a string into a file-like object.

import cStringIO
fakefile = cStringIO.StringIO( '\n'.join(lines) )

I use '\n'.join() to convert the list of lines into a single string with newline
separators, then feed that to StringIO to create a file-like object.  This
object is (for most purposes) no different than the object returned by
open(filename).  You should then be able to give this StringIO object to the
email package.

Hope that this helps...

Jeff Shannon
Technician/Programmer
Credit International






From dman@dman.ddts.net  Tue Jun 11 02:52:54 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon, 10 Jun 2002 20:52:54 -0500
Subject: [Tutor] Re: parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>
References: <20020610122037.A26494@localhost.localdomain> <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020611015254.GA15533@dman.ddts.net>

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

On Mon, Jun 10, 2002 at 03:02:37PM -0700, Danny Yoo wrote:
| On Mon, 10 Jun 2002, Paul Tremblay wrote:
|=20
| > I have just stumbled across the concept of parsing and parsing
| > grammars, and wondered if I am using the right tool.
| >
| > I haved downloaded and installed plex in order to parse a rtf
| > document. The rtf looks like this:
| >
| > {\footnote {\i an italicized word} {\i maybe another italicized
| > word} text }
=20
| > However, I am wondering if plex does things the wrong way.
|=20
| Plex is a tool for breaking the text into "tokens" that are easier to look
| at.  However, it's not enough.  You'll probably want to use a parsing
| technique like recursive descent, or use a specialized parser-building
| tool.  We can talk about it more if you'd like.
=20
Isn't there some sort of lex/yacc clone for python?

lex (or flex, if you use the GNU version) is a lexical analyzer
generator for C.  It is often used in conjuction with yacc (or bision,
if you use the GNU version) which is a "compiler compiler" (for C).
(yacc =3D=3D Yet Another Compiler Compiler)

The combination of lex and yacc allows rapid development of a flexible
and robust parser for your C program.  With lex you simply specify
regex patterns for identifying the tokens (I think plex is supposed to
do the same sort of thing), and those tokens are passed into the
"compiler" that yacc generates.  You tell yacc what the EBNF (aka CFG,
Context-Free Grammar) grammar is of your language and it generates the
necessary C code to recognize it from the tokens lex passes it.  It's
somewhat complicated to try and explain with no prior background, but
it's a really neat setup.

In one lab, in a matter of hours, a friend and I implemented a
calculator using lex and yacc.  That calculator was quite flexible,
allowed whitespace in various ways (like real tools such as the C
compiler or python allow) and allowd C-style comments.  Previously I
had implemented a similar tool in C++ with a larger group and we spent
weeks on it.  It had a much stricter use of whitespace because the
parser was all hand-coded and didn't use regex at all.  The difference
between hand-coding your own parser from scratch and using a generated
one is significant.

If I were you, I would try to find an existing tool if you can.  Look
for an RTF parser (though I don't think you're likely to find a decent
one unless you disassemble MS Word) or a parser generator like
lex/yacc.

HTH,
-D


--=20

The wise in heart are called discerning,
and pleasant words promote instruction.
        Proverbs 16:21
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--2oS5YaxWCcQjTEyO
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0FV/UACgkQO8l8XBKTpRQ3yACfY9yjD1yCgHWYadT/TI91xYOq
gWUAn18BCF5dcN5wwE4XlookheQh230F
=pwPL
-----END PGP SIGNATURE-----

--2oS5YaxWCcQjTEyO--



From dman@dman.ddts.net  Tue Jun 11 02:54:53 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon, 10 Jun 2002 20:54:53 -0500
Subject: [Tutor] Re: Re: Newbie OOP Question.(diff between function, module and class)
In-Reply-To: <B92A8B84.6CF2%sarmstrong13@mac.com>
References: <15620.57692.735525.490352@12-248-41-177.client.attbi.com> <B92A8B84.6CF2%sarmstrong13@mac.com>
Message-ID: <20020611015453.GB15533@dman.ddts.net>

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

On Mon, Jun 10, 2002 at 04:59:48PM -0500, SA wrote:
| On 6/10/02 12:26 PM, "Skip Montanaro" <skip@pobox.com> wrote:

| >   SA> One last question, sorry if this is very basic but I feel these
| >   SA> terms need better definitions for newbies like me (the only other
| >   SA> languages I have experience with are Qbasic and HTML) what is a
| >   SA> namespae? Is that analagous to pwd of the program? For instance, =
if
| >   SA> the program is currently in one are of the script doing work, wou=
ld
| >   SA> that be considered the namespace?
| >=20
| > Yes, it is more or less like the filesystem hierarchy.  In the current
| > directory, a reference to "blue.txt" would reference a file in the curr=
ent
| > directory.  One significant difference is that Python's module/package
| > system doesn't have a syntax for referring to the current module's pare=
nt
| > (no "..").
|
| Ahh. Now that may prove interesting. Would it be beneficial to make a
| reserved command like .. That pops you back into the parent namespace?

import foo
bar  =3D foo
baz  =3D foo
spam =3D foo

What's the parent namespace of module foo?

IOW, no.  Also, using such a feature would also break good module
design.

-D

--=20

Yes, Java is so bulletproofed that to a C programmer it feels like being in=
 a
straightjacket, but it's a really comfy and warm straightjacket, and the wo=
rld
would be a safer place if everyone was straightjacketed most of the time.
                                                      -- Mark 'Kamikaze' Hu=
ghes
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAj0FWG0ACgkQO8l8XBKTpRRdYQCgsz8wD+CbrM8hUu7+44di3qKD
Fi0Ani3CVo+T79QsViNoziA1Lh+uFAn6
=7DBz
-----END PGP SIGNATURE-----

--LpQ9ahxlCli8rRTG--



From dman@dman.ddts.net  Tue Jun 11 03:06:08 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon, 10 Jun 2002 21:06:08 -0500
Subject: [Tutor] Re: Where best to start? First program to: login, read from and close a serial line?
In-Reply-To: <20020610062255.51796.qmail@web11802.mail.yahoo.com>
References: <20020610062255.51796.qmail@web11802.mail.yahoo.com>
Message-ID: <20020611020608.GC15533@dman.ddts.net>

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

On Sun, Jun 09, 2002 at 11:22:55PM -0700, Bill Gillespie wrote:
| Hi Folks,
|=20
| I was very happy to find this resource. I'm a new guy and am just
| starting to learn to do some simple programming, and Python is my first
| "real programming" language. It's very exciting!
|=20
| My first programming project:=20
| At work we have a "floor and oil temperature control system". I would
| like to build a simple GUI, allowing us to interrogate, display and
| change these two values:=20
|=20
| 1) OIL set point=20
| 2) FLOOR set point
|=20
|=20
| The Tkinter (GUI) part looks learnable - but I don't know where to
| start in terms of=20
|=20
| --> logging into a remote machine=20
|           (in Xterm from a Linux machine - to a sun os machine)

What program do you usually use?  telnet?  ssh? =20

In unix-land it is really easy to piggy back off of stuff like this.
For example if you are using telnet, you can open a pipe to it like
this :

import os
tpipe_in , tpipe_out =3D os.popen2( [ "/usr/bin/telnet" , "the.host.name" ]=
 )

which gives you 2 file-like objects -- tpipe_in and tpipe_out -- which
are connected to the stdin and stdout of the telnet program.  In this
manner your python program can act just a like a person sitting at the
machine running telnet.

|   --> opening a serial line on it
|           (I normally just type "tip oftc" to connect <oil floor and  =20
|         temp cont>)

Opening a device (such as a serial port) is easy in unix.  I wrote a
(simple!) daemon a while ago to log data read from the serial port.
To open the serial port, use

the_port =3D open( "/dev/ttyS0" , "r+" )

(note: this opens the device on the local machine)

If you are using a command that you invoke through telnet, just feed
the text through the pipe you opened above.
=20
|    --> interrogating the embedded device on it,
|           (two seperate commands ask for current - or order a change) =20

If this is just a mattter of sending some text (command) and then
reading the output (text) back, just use the pipe you opened above.
It's as simple as working with plain old files on the local disk.
=20
|     --> and then logging out again.
|           ($. closes the connection) then I log out of the machine)

Send the sequence "$.\n" to the pipe's input, send the logout command,
and close both ends of the pipe.
=20
| Any advice on the general idea of what should take place will be most
| welcome.=20

Unix was well designed around the use of files and pipes.  Working
with a pipe is just as easy as working with any other file, and so is
working with various devices (such as the serial port) and network
sockets.  Read some UNIX texts on pipes and files to get a better
handle on that.

I would start with a simple console-based system.  You could have it
be interactive, or even just too dumb to do more than one thing.
Experiment with it and see how to get everything working and how to do
decent error handling.  As you get a better handle on that, build it
up to having a full GUI or whatever is actually necessary.  (GUI's are
complex, and if you can keep it down to a simple command line you'll
be better off, IMO)
=20
HTH,
-D

--=20

An anxious heart weighs a man down,
but a kind word cheers him up.
        Proverbs 12:25
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


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

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

iEYEARECAAYFAj0FWxAACgkQO8l8XBKTpRQbmQCgk+kf/7MbGH7nefKPv3+QZACr
N+0An0zLY3FDf4wv1USlUh02XJvnlGSt
=n5pW
-----END PGP SIGNATURE-----

--DIOMP1UsTsWJauNi--



From phthenry@earthlink.net  Tue Jun 11 04:21:15 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Mon, 10 Jun 2002 23:21:15 -0400
Subject: [Tutor] parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>
References: <20020610122037.A26494@localhost.localdomain> <Pine.LNX.4.44.0206101424040.18926-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020610232114.D26494@localhost.localdomain>

On Mon, Jun 10, 2002 at 03:02:37PM -0700, Danny Yoo wrote:

> 
> Hmmm... if the structure is always described by braces, perhaps it might
> be easier to do a "recursive descent" parse through the message.  Here's a
> sample parser that shows how the technique works.
> 

First, thanks for your post, and thanks also to Sean and Derrick.
Sean made a nice distinction between a parser and lexer. Derrick
suggested I used a parser already written. In fact, I haven't
been able to find a parser in python to parse rtf. The only thing
I found was in java, a nice utility called majix. However, for
some bizzare reason, this utility eliminates footnotes rather
than tag them.

Danny, I had a few questions about how all this code works. Keep
in mind I'm new to python. I see that you pass a list of tokesn
to the parser method in the class chunk. 

(1)I don't understand how this method continues to read each
item in the list. 

(2) I don't understand why you don't have to create an object
first to use this method.

(3) I don't understand how you can call on the Chunk method, when
it is the name of a class.

(4) I don't understand how this code would work if the tokens
were broken over lines. I guess you could read the file in as
lines and set your example text to lines. 

I posted my  code written in plex a few emails ago with the
subject "rtf to xml regexp question." Despite having to count
brackets, this code is easier for me to understand. It seems that
my code lets the lexer do most of the dirty work.

> I've had some experience with the SPARK parser, and it's a nice tool:
> 
>     http://pages.cpsc.ucalgary.ca/~aycock/spark/
> 
> I used it a while back when I was playing with Pythonica, and it seemed to
> work very well.  The only caveat I could make was that, back then, if
> there was an error in the grammar, SPARK wouldn't give good error
> messages.  I'm not sure if this complaints can be made now: perhaps this
> has been fixed.
> 
> 
> 
> Another parser that I've heard good things about is Amit Patel's YAPPS
> parser:
> 
>     http://theory.stanford.edu/~amitp/Yapps/
> 
> 
> 

Yes, I've heard some good things about SPARK. I couldn't find any
documentation on it, though! I also found a good parser called
simpleparse, which is based on the module written in C called
mxTextTools. Simpleparse has a very nice interface. However, I
got an error message when using code straight from a tutorial.

There is acutally a python special interest group (sig) just for
parsing. It was established in Feburary, and only one person has
posted to it.

Thanks!

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From sarmstrong13@mac.com  Tue Jun 11 04:47:38 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 10 Jun 2002 22:47:38 -0500
Subject: [Tutor] CGI Question.
Message-ID: <B92ADD0A.6D2E%sarmstrong13@mac.com>

Is there a way to capture when the user clicks a link in a web page?

In other words, If the link in a python generated web page was actually a
variable that when clicked calls another function in the program that
displays some pre-formatted text? I know an anchor will call the linked page
in HTML, but what I'm wanting to do is set up a cgi script that displays
text in the body of the web page depending upon a link that is clicked, but
handle all of the variables within the python cgi script instead of coding a
bunch of HTML pages and linking them all.

Thanks.
SA




From mikew@screaminet.com  Tue Jun 11 00:42:10 2002
From: mikew@screaminet.com (Tinman)
Date: Mon, 10 Jun 2002 18:42:10 -0500
Subject: [Tutor] loop problem
Message-ID: <3D053952.4090709@screaminet.com>

I've been reading Alan's book on learning to program with Python. I'm 
currently working with the chapter on loops. I have an idea for a loop 
that I can't quite figure out. This is what I want to do.

1.Multiply 1 by 2
2.Take the result and multiply by 2
3.So on and so on thirty times
4.Print the final result

I tried this:

for i in range(1,31):
		b = i * 2
		print b

This prints 1 -30 times 2 as I'm sure you can tell. I can't figure out 
how to take each result an double it. Can anyone help a hapless Python 
newbie?




From shalehperry@attbi.com  Tue Jun 11 06:26:52 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 10 Jun 2002 22:26:52 -0700 (PDT)
Subject: [Tutor] loop problem
In-Reply-To: <3D053952.4090709@screaminet.com>
Message-ID: <XFMail.20020610222652.shalehperry@attbi.com>

On 10-Jun-2002 Tinman wrote:
> I've been reading Alan's book on learning to program with Python. I'm 
> currently working with the chapter on loops. I have an idea for a loop 
> that I can't quite figure out. This is what I want to do.
> 
> 1.Multiply 1 by 2
> 2.Take the result and multiply by 2
> 3.So on and so on thirty times
> 4.Print the final result
> 
> I tried this:
> 
> for i in range(1,31):
>               b = i * 2
>               print b
> 
> This prints 1 -30 times 2 as I'm sure you can tell. I can't figure out 
> how to take each result an double it. Can anyone help a hapless Python 
> newbie?
> 

total = 2 # total starts at 1 * 2
for i in range(2,31): # start at 2
  total = total * 2
  print total

is this what you mean?




From dylan.belsey@baesystems.com  Tue Jun 11 06:35:08 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue, 11 Jun 2002 15:05:08 +0930
Subject: [Tutor] loop problem
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B963207C@wtntex1.baea.com.au>

	I don't have Alan's book to see what you are referring to but have a
look at the following.  I think it is a solution.  From what I can
ascertain, you are trying to find the result for 2^30 = 1073741824 ??  The
following code should do it.  You don't have to use the index of the for
loop and must reset "b" at the start.  Also, if you only want the final
result then print outside the loop.
	Hope this helps.

PS: just observed that Sean Perry had the same idea!!

>>> b = 1
>>> for i in range(1,31):
	b = b*2
	print b

	
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
>>> 

-----Original Message-----
From: Tinman [mailto:mikew@screaminet.com]
Sent: Tuesday, 11 June 2002 09:42
To: tutor@python.org
Subject: [Tutor] loop problem


I've been reading Alan's book on learning to program with Python. I'm 
currently working with the chapter on loops. I have an idea for a loop 
that I can't quite figure out. This is what I want to do.

1.Multiply 1 by 2
2.Take the result and multiply by 2
3.So on and so on thirty times
4.Print the final result

I tried this:

for i in range(1,31):
		b = i * 2
		print b

This prints 1 -30 times 2 as I'm sure you can tell. I can't figure out 
how to take each result an double it. Can anyone help a hapless Python 
newbie?



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



From pydan@danshafer.com  Tue Jun 11 09:02:33 2002
From: pydan@danshafer.com (Dan Shafer)
Date: Tue, 11 Jun 2002 01:02:33 -0700
Subject: [Tutor] Creating an Identifier or Object Name from a String?
Message-ID: <5.1.0.14.0.20020611005842.029526e0@mail.hurrah.com>

I have a need to refer to a number of objects which have been named field1, 
field2, field3, etc. I want to set a property in each object in a loop.

I thought this should work:

   for ct in range(1,4):
     objToUpdate = "field" + str(ct)
     objToChange = eval(objToUpdate) # seems like it should produce 
"field1" first time through the loop, etc.
     objToChange.text = inputList[ct] #inputList is generated prior to 
entering the loop and is a list of string values

This produces an error indicating that string objects don't have a text 
attribute. So clearly objToChange is still a string at this point.

I suspect this is tricky but if someone could help....

Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net




From dyoo@hkn.eecs.berkeley.edu  Tue Jun 11 09:10:04 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 11 Jun 2002 01:10:04 -0700 (PDT)
Subject: [Tutor] Creating an Identifier or Object Name from a String?
In-Reply-To: <5.1.0.14.0.20020611005842.029526e0@mail.hurrah.com>
Message-ID: <Pine.LNX.4.44.0206110102050.31687-100000@hkn.eecs.berkeley.edu>


On Tue, 11 Jun 2002, Dan Shafer wrote:

> I have a need to refer to a number of objects which have been named
> field1, field2, field3, etc. I want to set a property in each object in
> a loop.

Instead of having them as separate variables, is it possible to keep them
grouped together in a list or dictionary?  That way, it's easier to work
with them as a group, without the complexities of eval().


> I thought this should work:
>
>    for ct in range(1,4):
>      objToUpdate = "field" + str(ct)
>      objToChange = eval(objToUpdate) # seems like it should produce
> "field1" first time through the loop, etc.
>      objToChange.text = inputList[ct] #inputList is generated prior to
> entering the loop and is a list of string values


So since your inputList is already a list, that may be a good hint that
symmetry will help.  *grin* Try something like:

###
objects = [field1, field2, field3]  ### Add as many objects as you
                                    ### have
for i in range(len(objects)):
    objects[i].text = inputlist[i]
###


But I didn't see anything obviously wrong with your initial approach.
One suggestion would be to check the value of field1, field2, field3,
right before the loop.  Also, if you can show us the literal error
message, that may give more clues as to why it's doing weird things.




From glingl@aon.at  Tue Jun 11 09:35:47 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 11 Jun 2002 10:35:47 +0200
Subject: [Tutor] Creating an Identifier or Object Name from a String?
References: <5.1.0.14.0.20020611005842.029526e0@mail.hurrah.com>
Message-ID: <3D05B663.B87BF27@rg16.asn-wien.ac.at>

I Tried it and it worked (?!)

Python 2.2c1 (#27, Dec 14 2001, 13:15:16) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> class K:
        pass

>>> field1 = K()
>>> field2 = K()
>>> field3 = K()
>>> for ct in range(1,4):
        obj="field"+str(ct)
        objTC=eval(obj)
        objTC.text=['a','b',str(ct)]


>>> field1.text
['a', 'b', '1']
>>> field2.text
['a', 'b', '2']
>>> field3.text
['a', 'b', '3']
>>>

Gregor


Dan Shafer schrieb:

> I have a need to refer to a number of objects which have been named field1,
> field2, field3, etc. I want to set a property in each object in a loop.
>
> I thought this should work:
>
>    for ct in range(1,4):
>      objToUpdate = "field" + str(ct)
>      objToChange = eval(objToUpdate) # seems like it should produce
> "field1" first time through the loop, etc.
>      objToChange.text = inputList[ct] #inputList is generated prior to
> entering the loop and is a list of string values
>
> This produces an error indicating that string objects don't have a text
> attribute. So clearly objToChange is still a string at this point.
>
> I suspect this is tricky but if someone could help....
>
> Dan Shafer, Chief Scribe and Tablet Keeper
> PythonCard Open Source Project
> http://pythoncard.sourceforge.net
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From alex@gabuzomeu.net  Tue Jun 11 11:03:11 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Tue, 11 Jun 2002 12:03:11 +0200
Subject: [Tutor] parsing--is this right?
In-Reply-To: <20020611032902.22231.72658.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020611115152.00d80180@pop3.norton.antivirus>

Hi Paul,


At 23:29 10/06/2002 -0400, you wrote:
>Date: Mon, 10 Jun 2002 23:21:15 -0400
>From: Paul Tremblay <phthenry@earthlink.net>
>Subject: Re: [Tutor] parsing--is this right?

[Parsing RTF data:]
>Sean made a nice distinction between a parser and lexer. Derrick
>suggested I used a parser already written. In fact, I haven't
>been able to find a parser in python to parse rtf.

You may want to look at these references:

http://www.foretec.com/python/workshops/1998-11/tut_com.html
http://starship.python.net/crew/pirx/spam7/

There is a short RTF parser example in Python in the downloadable slideshow.


Cheers.

Alexandre




From alan.gauld@bt.com  Tue Jun 11 14:09:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 11 Jun 2002 14:09:36 +0100
Subject: [Tutor] Newbie Q's
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C644@mbtlipnt02.btlabs.bt.co.uk>

> I have two quick questions for you. First, if I have a
> list made up of integers, is there a simple command to
> let me find the sum of the integers (and assign the
> value to a variable)? 

The most direct way is with a loop:

result = 0
for num in numlist:
    result += num

Or using Pythons reduce function:

result = reduce(operator.add, numlist)

Which does the same thing.

> The biggest difficulty I'm having is dealing with
> aces, which can be valued at 1 or 11. I thought I had
> everything figured out, until a hand came up that had
> two aces in it :-) I'm sure many people have tried
> making this kind of a program. How did you (or would
> you) deal with this aspect of the program? 

Special cases need special code. For blackjack you would 
count the Ace as 11 if the total was <= 21 else count them 
as 1... 
So something like the following untested code:

def AddCards(cardlist):
    tot = reduce(operator.add, cardlist)
    if  tot > 21: #too high
       while 11 in cardlist:   #do we have high aces?
         if tot-10 <= 21:      # total too high so use low ace
           pos = cardist.index(11)
           cardlist[pos] = 1   # change from 11 to 1
           tot = reduce(operator.add, cardlist)
    return tot

Theres probably a neater way but that might help...

Alan g
    



From alan.gauld@bt.com  Tue Jun 11 14:16:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 11 Jun 2002 14:16:43 +0100
Subject: [Tutor] Re: Newbie OOP Question.
 (diff between function, modu le and class)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C645@mbtlipnt02.btlabs.bt.co.uk>

> > system doesn't have a syntax for referring to the current 
> module's parent
> > (no "..").
> Ahh. Now that may prove interesting. Would it be beneficial to make a
> reserved command like .. That pops you back into the parent namespace?

There is sort of its the global statement:

z = 42

def f(x):
   z = 2*x
   return z

This creates a new z with value twice x.
If we really want to access the external(global z) we can do 
so like this:

def f(x):
   global z
   z = 2*x
   return z

Now we modify the external z instead of creating a new one.
Generally this is a bad idea and you should pass the value 
into the function for modification:

def f(x,y):
   y = 2*x
   return y

But this still doesn't change the global z even if we pass 
it in as y, we have to assign the result:

z = f(5,z)

This now modifies global z asnd makes its value available 
to the function(as the parameter y).

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From marcolinux@linuxbr.com.br  Tue Jun 11 13:50:11 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Tue, 11 Jun 2002 09:50:11 -0300
Subject: [Tutor] Newbie Q's
In-Reply-To: <20020610215217.25441.qmail@web20505.mail.yahoo.com>
References: <20020610215217.25441.qmail@web20505.mail.yahoo.com>
Message-ID: <20020611095011.A11084@marcolab.proconet>

Alan Colburn (aicolburn@yahoo.com) wrote:


> Second, as a way to practice what I've started
> learning, I decided to try making a
> (non-graphical)Blackjack game. I've got it set up so
> that when cards are drawn from a deck, they go into a
> list (one for the player, one for the dealer). (That's
> where my question above comes from.)


Hi Alan.
This link might be of your interest:
http://www.ibiblio.org/obp/thinkCSpy/chap15.htm

Hope it helps.

.:: Marcolinux ::.



From lonetwin@subdimension.com  Tue Jun 11 14:28:05 2002
From: lonetwin@subdimension.com (lonetwin_SubD)
Date: Tue, 11 Jun 2002 18:58:05 +0530
Subject: [Tutor] Tk question
Message-ID: <20020611132805.B15372F4C6@mercury.sapatmt>

Hi ppl,
     For convenience sake, I wrote a wrapper around the 'cal' command on my 
linux box (and bound it to a shortcut keystroke on my Window manager). There 
is one problem tho', I just can't figure out how to get the first and last 
lines aligned properly. I tried passing anchor="w" while initialising the 
Label but that does not seem to help .....any pointers ??

Here's the code (maybe someone else might find it useful too :)). 

Note : I specifically set the font to "fixed" b'cos with variable width fonts 
spaces are "thinner" than characters and that screws up the display.

---------------------------------------
#!/usr/bin/python
import os

cal="/usr/bin/cal.orig"
args = ''.join(os.sys.argv[1:])
out = os.popen('%s %s' % (cal, args)).read()

if os.environ.has_key('DISPLAY'):
	from Tkinter import *
	Master = Frame()
	Master.master.title("Tkcal")
	Sub = Label(Master, font='fixed', text=out)
	Master.grid(ipadx=2, ipady=2)
	Sub.grid()
	Master.mainloop()
else:
	print out
----------------------------------------

Peace
Steve

PS: Maybe you are wondering why I did this, well I can only say that I find 
myself using the keyboard 95% of the time when in windowmaker (my preferred 
wm). Also, I've got a similar (shortcut) "front-end" to "ispell -a", I'll 
send it across if anybody is interested.

-- 
The prettiest women are almost always the most boring, and that is why
some people feel there is no God.
		-- Woody Allen, "Without Feathers"



From jeff@ccvcorp.com  Tue Jun 11 17:59:07 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 11 Jun 2002 09:59:07 -0700
Subject: [Tutor] Newbie Q's
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C644@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3D062C5B.58EE422E@ccvcorp.com>


alan.gauld@bt.com wrote:

> > The biggest difficulty I'm having is dealing with
> > aces, which can be valued at 1 or 11. I thought I had
> > everything figured out, until a hand came up that had
> > two aces in it :-)

> Special cases need special code. For blackjack you would
> count the Ace as 11 if the total was <= 21 else count them
> as 1...
> So something like the following untested code:
>
> def AddCards(cardlist):
>     tot = reduce(operator.add, cardlist)
>     if  tot > 21: #too high
>        while 11 in cardlist:   #do we have high aces?
>          if tot-10 <= 21:      # total too high so use low ace
>            pos = cardist.index(11)
>            cardlist[pos] = 1   # change from 11 to 1
>            tot = reduce(operator.add, cardlist)
>     return tot

It seems to me that this code will also cause problems if there are
two aces.  :)  This will reduce *all* aces in the hand to 1, not just
enough of them to drop the score just below 21.  Also, it's not really
necessary to check whether switching the ace from high to low will
drop the total below 21 -- ISTM that any high ace should be converted
to low before declaring the hand busted.  Perhaps something like this
would work better...

def AddCards(cardlist):
    tot = reduce(operator.add, cardlist)
    while tot > 21 and 11 in cardlist:
        pos = cardlist.index(11)
        cardlist[pos] = 1
        tot = reduce(operator.add, cardlist)
    return tot

This is still not terribly efficient ('value in list' and list.index()
are slow for large lists), but should be good enough for a blackjack
game (which would not have large lists or too terribly strict speed
requirements ;) ).  One thing that could speed it up would be to
combine the two searches:

def AddCards(cardlist):
    tot = reduce(operator.add, cardlist)
    while tot > 21:
        pos = cardlist.index(11)   # returns the index, or -1 if not
found
        if pos >= 0:
            cardlist[pos] = 1
            tot = reduce(operator.add, cardlist)
        else:
            break    # exit 'while' if there are no high aces
    return tot

I'm sure that further improvements are possible (such as eliminating
the multiple reduce() calls), but this should be good enough for now.
:)

Jeff Shannon
Technician/Programmer
Credit International






From alan.gauld@bt.com  Tue Jun 11 17:57:21 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 11 Jun 2002 17:57:21 +0100
Subject: [Tutor] loop problem
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C64C@mbtlipnt02.btlabs.bt.co.uk>

> 1.Multiply 1 by 2
> 2.Take the result and multiply by 2
> 3.So on and so on thirty times
> 4.Print the final result
> 

First, thanks for the well stated problem specification, 
it always helps :-)


> I tried this:
> 
  b = 1  # initialise b
> for i in range(1,31):
> 		b = i * 2   # replace this with

            b = b * 2

> 		print b

Should work.

Just use the range to count the number of iterations but the 
number to multiply is b not i. (Try renaming b to result and 
see if it becomes clearer - using variable names that match 
your problem statement is usally a good dea - check the 
chapter on Style.

BTW Your function just works out the 30th power of two so 
the same end result comes (faster) from:

print pow(2,30)

But that doesn't display intermediate values or teach you 
about loops ;-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From skip@pobox.com  Tue Jun 11 14:35:39 2002
From: skip@pobox.com (Skip Montanaro)
Date: Tue, 11 Jun 2002 08:35:39 -0500
Subject: [Tutor] Re: Newbie OOP Question.
 (diff between function, modu le and class)
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C645@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C645@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <15621.64683.637593.221998@12-248-41-177.client.attbi.com>

    skip> system doesn't have a syntax for referring to the current module's
    skip> parent (no "..").

    sa> Ahh. Now that may prove interesting. Would it be beneficial to make
    sa> a reserved command like .. That pops you back into the parent
    sa> namespace?

    alan> There is sort of its the global statement:

Not quite what I was referring to (I was equating module namespaces and file
system directories), but I agree, in the context of a function the global
statement does "pop you up" one level.

Skip



From dyoo@hkn.eecs.berkeley.edu  Tue Jun 11 18:19:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 11 Jun 2002 10:19:00 -0700 (PDT)
Subject: [Tutor] parsing--is this right?
In-Reply-To: <20020610232114.D26494@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0206102040030.26648-100000@hkn.eecs.berkeley.edu>


On Mon, 10 Jun 2002, Paul Tremblay wrote:


> I see that you pass a list of tokesn to the parser method in the class
> chunk.
>
[some text cut and moved around]
>
> (2) I don't understand why you don't have to create an object first to
> use this method.
>
> (3) I don't understand how you can call on the Chunk method, when
> it is the name of a class.


Hi Paul:

Actually, the parse() function is meant to be standalone: it's not a
method.  I'm only using Chunk()  to group the data together, and to make
it easier to extract the command type later on.


> (4) I don't understand how this code would work if the tokens were
> broken over lines. I guess you could read the file in as lines and set
> your example text to lines.

As long as we first do all of the tokenization before parsing, we should
be ok.  In many cases, we want to break down this parsing task into two
tasks:

     1. Breaking our text file into a bunch of recognizable tokens
     2. Figuring out the structure between those tokens.

By breaking it down this way, both tasks can become simpler.


The rtf parser I wrote only recognizes two categories of tokens: the
beginning of boundaries (brackets "{}"), and everything else.  Since it
groups these tokens into those two categories, it doesn't have to worry
about newlines.  That's why a lot of parsers are paired together with
tokenizers, so that the parser can avoid thinking about content, and
concentrate more on categories.


> (1)I don't understand how this method continues to read each item in the
> list.

This parser progressively eats more and more of the tokens by using the
pop() method of lists.  It simultaneously removes an element from our
tokens list, and returns that element back to us.  For example:

###
>>> tokens = ['hello', 'world', 'this', 'is', 'a', 'test']
>>> tokens.pop(0)
'hello'
>>> tokens.pop(0)
'world'
>>> tokens.pop(0)
'this'
>>> tokens.pop(0)
'is'
>>> tokens.pop(0)
'a'
>>> tokens.pop(0)
'test'
>>> tokens.pop(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IndexError: pop from empty list
###



If it helps, I can try simplifying the parser a little more for clarity.
We can get rid of Chunk() class stuff altogether, and break up that
parse()  function into two pieces to make its intent a little clearer.


###
import re

def parse(tokens):
    """Parses one thing, given a source of tokens.  That one thing can
    be either a single piece of text, or a bracketed list."""
    if tokens[0] == '{': return parseList(tokens)         ## Case 1
    else: return tokens.pop(0)                            ## Case 2


def parseList(tokens):
    """To parse a bracketed list, continue parsing the rest of the token
    stream until we hit the end of the bracketed list."""
    tokens.pop(0)                  ## Eat the leading bracket.
    collected_pieces = []
    while tokens[0] != '}':
        collected_pieces.append(parse(tokens))
    tokens.pop(0)                  ## Eat the closing bracket.
    return collected_pieces


def tokenize(text):
    def nonEmpty(thing):
        return len(thing.strip()) > 0
    return filter(nonEmpty, re.split(r'(\{|\}|\s)', text))
###


Please feel free to ask more questions!  Good luck to you.




From rickp@telocity.com  Tue Jun 11 18:44:07 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Tue, 11 Jun 2002 13:44:07 -0400
Subject: [Tutor] Tk question
In-Reply-To: <20020611132805.B15372F4C6@mercury.sapatmt>
References: <20020611132805.B15372F4C6@mercury.sapatmt>
Message-ID: <20020611174406.GA21236@tc.niof.net>

Add a justify option to your call to Label():

Sub = Label(Master, font='fixed', text=out, justify=LEFT)

On Tue, Jun 11, 2002 at 06:58:05PM +0530, lonetwin_SubD wrote:
> Hi ppl,
>      For convenience sake, I wrote a wrapper around the 'cal' command on my 
> linux box (and bound it to a shortcut keystroke on my Window manager). There 
> is one problem tho', I just can't figure out how to get the first and last 
> lines aligned properly. I tried passing anchor="w" while initialising the 
> Label but that does not seem to help .....any pointers ??
> 
> Here's the code (maybe someone else might find it useful too :)). 
> 
> Note : I specifically set the font to "fixed" b'cos with variable width fonts 
> spaces are "thinner" than characters and that screws up the display.
> 
> ---------------------------------------
> #!/usr/bin/python
> import os
> 
> cal="/usr/bin/cal.orig"
> args = ''.join(os.sys.argv[1:])
> out = os.popen('%s %s' % (cal, args)).read()
> 
> if os.environ.has_key('DISPLAY'):
> 	from Tkinter import *
> 	Master = Frame()
> 	Master.master.title("Tkcal")
> 	Sub = Label(Master, font='fixed', text=out)
> 	Master.grid(ipadx=2, ipady=2)
> 	Sub.grid()
> 	Master.mainloop()
> else:
> 	print out
> ----------------------------------------
> 
> Peace
> Steve
> 
> PS: Maybe you are wondering why I did this, well I can only say that I find 
> myself using the keyboard 95% of the time when in windowmaker (my preferred 
> wm). Also, I've got a similar (shortcut) "front-end" to "ispell -a", I'll 
> send it across if anybody is interested.
> 
> -- 
> The prettiest women are almost always the most boring, and that is why
> some people feel there is no God.
> 		-- Woody Allen, "Without Feathers"
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
"Life is like an over long drama through which we sit being nagged
by the vague memories of having read the reviews."
		-- John Updike
    Rick Pasotto    rickp@telocity.com    http://www.niof.net



From HaakJ@masirv.com  Tue Jun 11 19:30:06 2002
From: HaakJ@masirv.com (Jim Haak)
Date: Tue, 11 Jun 2002 11:30:06 -0700
Subject: [Tutor] retreiving email file attachments
Message-ID: <9C9781ADDB73C549BC4D8E837BF8450E08C5DD@mail-socal01>

Jeff,

Thanks very much.  That works great.  

Jim Haak 

*-----Original Message-----
*From: Jeff Shannon [mailto:jeff@ccvcorp.com]
*Sent: Monday, June 10, 2002 5:44 PM
*To: Jim Haak
*Cc: 'tutor@python.org'
*Subject: Re: [Tutor] retreiving email file attachments
*
*
*
*
*Jim Haak wrote:
*
*> Does anyone have an example of using poplib to read an Inbox and then
*> passing the messages to the email package?   I am trying to 
*parse zipped
*> attachments.  [...]
*>
*> Since the email module wants a file, I've tried writing all 
*the 'lines' to a
*> file, but that doesn't seem to work.
*
*I haven't done this myself, but here's some ideas for you to research.
*
*The POP3.retr() method returns a tuple, the second member of 
*which is (iirc) a
*list of lines.  You can probably safely discard the other two items.
*
*lines = pop.retr(n)[1]
*
*You need to feed a file to the email module, but saving all of 
*this to a file
*would be pointless.  The solution is the StringIO (or better 
*yet, cStringIO),
*which will convert a string into a file-like object.
*
*import cStringIO
*fakefile = cStringIO.StringIO( '\n'.join(lines) )
*
*I use '\n'.join() to convert the list of lines into a single 
*string with newline
*separators, then feed that to StringIO to create a file-like 
*object.  This
*object is (for most purposes) no different than the object returned by
*open(filename).  You should then be able to give this StringIO 
*object to the
*email package.
*
*Hope that this helps...
*
*Jeff Shannon
*Technician/Programmer
*Credit International
*
*
*



From phthenry@earthlink.net  Tue Jun 11 19:55:47 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Tue, 11 Jun 2002 14:55:47 -0400
Subject: [Tutor] parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206102040030.26648-100000@hkn.eecs.berkeley.edu>
References: <20020610232114.D26494@localhost.localdomain> <Pine.LNX.4.44.0206102040030.26648-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020611145546.A31120@localhost.localdomain>

On Tue, Jun 11, 2002 at 10:19:00AM -0700, Danny Yoo wrote:

> 
> Actually, the parse() function is meant to be standalone: it's not a
> method.  I'm only using Chunk()  to group the data together, and to make
> it easier to extract the command type later on.

Ah, I missed these lines in your original code:

new_chunk = Chunk('text', tokens.pop(0))
         return new_chunk

new_chunk is your object. Yes, the parser by itself is not part
of the Chunk class. 

(Part of the confusion has to do with how indentation marks
different parts of code in python, a feature that first caused me
to go "yuck," but one which I now love. When reading someone
else's code, there is a tendancy to miss what is nested.)

One of the confusing things for me is that in your code, a
function calls itself. This makes me really think. I doubt there
is another way to write this code, since the text being
tokenized has a nested structure. Let me repeat: this makes me
think! It is more complicated than the normal way I program
which is to  get a chunk of text, send it to some subroutine,
get another chunk, send it to another subroutine. Nonetheless,
looking at the code, I see exactly how it works.

>
> The rtf parser I wrote only recognizes two categories of tokens: the
> beginning of boundaries (brackets "{}"), and everything else.  Since it
> groups these tokens into those two categories, it doesn't have to worry
> about newlines.  That's why a lot of parsers are paired together with
> tokenizers, so that the parser can avoid thinking about content, and
> concentrate more on categories.
> 

Okay, so from here how would you change this text? I would want
it to look like this:

<footnote> <emph>an italicized word</emph> <emph>maybe another
italicized word</emph> text </footnote>


> 
> > (1)I don't understand how this method continues to read each item in the
> > list.


I understood how pop worked, but I didn't see how your code kept
using pop, because I didn't see how the routine called on itself.

Last question: How doe lexers (or parsers?) like plex or SPARK
fit into our model? In actuality, I simlified my problem, though
not by too much. A more represenative implementation of rtf colde 
looks like this:

1 \pard\plain This is normal text
2 \par
3 \pard\plain  
4 \pard\plain \s1\fi720 this text has an assigned style"\par


5 \pard\plain Now a footnote. As Schmoo said "Be 
6 great!"{\fs18\up6 \chftn {\footnote \pard\plain \s246 \fs20 
7 {\fs18\up6 \chftn }footnote at bottom of page}}\par

The above text uses the delimeters "\pard" to mark a paragraph
style. If the word documents has used a style, then the next bit
of information, the \s1 found in the fourth line, tells what
typye of informatin the paragraph contains. For example, in
microsoft word, you might have called all paragraphs that indent
1 inch a "block" style. You might call all paragrahs that contain
quotes a "quote" style. Microsoft word lables them \s1, and \s2,
or "style 1" , "style2."

Hence, the TYPE now becomes \pard \s1. 

We need to know when this style ends and a new one begins. Rtf
says that a new style begins when you encounter another \pard
delimter. There is an exception: if this \pard delimeter is
within a footnote, the previous style has not terminated.

So our model becomes more complicated. However, the plex lexer
would handle this simplified model easily. As you probably know
from using SPARK, you can set states in the lexer. Hence, once
the lexer is in the "footnote" state, it treats the delimeter
\pard totally different than it would if it found it outside of
the state.

I'm not necessarily looking for a specific solution here; I am
just trying to learn about parsers.

Thanks for your help!

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From phthenry@earthlink.net  Tue Jun 11 20:01:26 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Tue, 11 Jun 2002 15:01:26 -0400
Subject: [Tutor] parsing--is this right?
In-Reply-To: <4.3.2.7.2.20020611115152.00d80180@pop3.norton.antivirus>
References: <20020611032902.22231.72658.Mailman@mail.python.org> <4.3.2.7.2.20020611115152.00d80180@pop3.norton.antivirus>
Message-ID: <20020611150126.B31120@localhost.localdomain>

On Tue, Jun 11, 2002 at 12:03:11PM +0200, Alexandre Ratti wrote:

> You may want to look at these references:
> 
> http://www.foretec.com/python/workshops/1998-11/tut_com.html
> http://starship.python.net/crew/pirx/spam7/
> 
> There is a short RTF parser example in Python in the downloadable slideshow.

This web page states that COM can only be used on windows, which
does me no good because I use linux. . The slideshow is in
powerpoint, which I can't view. There is a self-executing
program which I downloaded, but this again only runs on
windows. 

It seems a bit odd that a python programmer would chose a
proprietary source to display his tutorial. Why not use html or
pdf? 

Thanks anyway

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From pythontutor@venix.com  Tue Jun 11 20:33:06 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Tue, 11 Jun 2002 15:33:06 -0400
Subject: [Tutor] parsing--is this right?
References: <20020611032902.22231.72658.Mailman@mail.python.org> <4.3.2.7.2.20020611115152.00d80180@pop3.norton.antivirus> <20020611150126.B31120@localhost.localdomain>
Message-ID: <3D065072.8000505@venix.com>

I saved the .PPT as an  RTF file.  Hopefully, that will work for
you.

http://www.tpk.net/~lkvam/xsuo9du4.rtf

Let me know when you have gotten it and I will clear it off the
server.


Paul Tremblay wrote:

> On Tue, Jun 11, 2002 at 12:03:11PM +0200, Alexandre Ratti wrote:
> 
> 
>>You may want to look at these references:
>>
>>http://www.foretec.com/python/workshops/1998-11/tut_com.html
>>http://starship.python.net/crew/pirx/spam7/
>>
>>There is a short RTF parser example in Python in the downloadable slideshow.
>>
> 
> This web page states that COM can only be used on windows, which
> does me no good because I use linux. . The slideshow is in
> powerpoint, which I can't view. There is a self-executing
> program which I downloaded, but this again only runs on
> windows. 
> 
> It seems a bit odd that a python programmer would chose a
> proprietary source to display his tutorial. Why not use html or
> pdf? 
> 
> Thanks anyway
> 
> Paul
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From dman@dman.ddts.net  Tue Jun 11 21:22:27 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue, 11 Jun 2002 15:22:27 -0500
Subject: [Tutor] Re: parsing--is this right?
In-Reply-To: <20020611145546.A31120@localhost.localdomain>
References: <20020610232114.D26494@localhost.localdomain> <Pine.LNX.4.44.0206102040030.26648-100000@hkn.eecs.berkeley.edu> <20020611145546.A31120@localhost.localdomain>
Message-ID: <20020611202227.GB28144@dman.ddts.net>

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

On Tue, Jun 11, 2002 at 02:55:47PM -0400, Paul Tremblay wrote:
=20
| One of the confusing things for me is that in your code, a
| function calls itself.

This is a programming style/technique known as recursion.  Recursion
is really effective when the problem can be defined in terms of
itself.  Parsing nested structures (the {} in your RTF) is well suited
for recursion (and hence the name 'recursive descent' parser).

Another example of recursion is the factorial operation.

n! =3D  n * n-1 * n-2 * ... * 2 * 1

The "..." can be shown with recursion :

def fact( n ) :
    if n =3D=3D 1 :
        return 1
    else:
        return n * fact( n-1 )

Of course, for factorial, a faster implementation can be devised, but
the most natural definition of it is recursive.

(don't try this fact() on anything other than an integer >=3D 1
otherwise you'll get some bad results :-))

-D

--=20

"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix
=20
Jabber ID : dman@dman.ddts.net
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg

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

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

iEYEARECAAYFAj0GXAMACgkQO8l8XBKTpRQYRACffh49CdNjFAz/blTkXxNx+Nm8
18EAnAl4gF1qSCBgBHXe6ACXDdmoOQxO
=OmJL
-----END PGP SIGNATURE-----

--JYK4vJDZwFMowpUq--



From dyoo@hkn.eecs.berkeley.edu  Tue Jun 11 22:06:57 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 11 Jun 2002 14:06:57 -0700 (PDT)
Subject: [Tutor] parsing--is this right?
In-Reply-To: <20020611145546.A31120@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0206111342220.13011-100000@hkn.eecs.berkeley.edu>


> Okay, so from here how would you change this text? I would want it to
> look like this:
>
> <footnote> <emph>an italicized word</emph> <emph>maybe another
> italicized word</emph> text </footnote>

Ah!  Let's say that the parsing went perfectly, and somehow we have a
function that transforms the string:

###
>>> EXAMPLE_TEXT = r"""{\footnote {\i an italicized word} {\i
... maybe another italicized word} text }""".replace('\n', ' ')
>>> parsed_doc = parse(tokenize(EXAMPLE_TEXT))
>>> parsed_doc
['\\footnote', ['\\i', 'an', 'italicized', 'word'], ['\\i', 'maybe',
'another', 'italicized', 'word'], 'text']
###


In our parsed document, each command is the first element in a list.
This representation is nice because it mirrors the nested nature of the
tags: lists can contain inner lists.


How do we go from EXAMPLE_TEXT to a marked-up string?  We might want to
add XML tags for whenever we see a list.  Here's an initial attempt to do
this:

###
def toXML(structure):
    if type(structure) == type([]):
        tag = structure[0][1:]  ## secondary slice removes leading '/'
        text_pieces = [str(s) for s in structure[1:]]
        return "<%(tag)s>%(text)s</%(tag)s>" % \
               { 'tag' : tag,
                 'text' : ''.join(text_pieces) }
    else:
        return str(structure)
###

Let's see how it works:

###
>>> print toXML(parsed_doc)
<footnote>['\\i', 'an', 'italicized', 'word']['\\i', 'maybe', 'another',
'italicized', 'word']text</footnote>
###

Almost.  The only problem is that it only transformed the very outer layer
of this onion, but we want to permeate the whole structure with tags.
Although we hate to hurt it's feelings, we have to say the truth: toXML()
is "shallow".



The section that transformed the stuff in between the tags was the
statement:

        text_pieces = [str(s) for s in structure[1:]]


And this is the source of the shallowness: we're just calling str().  But
instead of directly calling str() on each piece in between, the trick is
to apply toXML() again to each inner piece!  That way, we guarantee that
the inner lists are also transformed properly:

###
>>> def toXMLDeeply(structure):
...     if type(structure) == type([]):
...         tag = structure[0][1:]  ## secondary slice removes leading '/'
...         text_pieces = [toXML(s) for s in structure[1:]]
...         return "<%(tag)s>%(text)s</%(tag)s>" % \
...                { 'tag' : tag,
...                  'text' : ''.join(text_pieces) }
...     else:
...         return str(structure)
...
>>> print toXMLDeeply(parsed_doc)
<footnote><i>anitalicizedword</i><i>maybeanotheritalicizedword</i>text</footnote>
###


The transformation wasn't perfect, because my parsing step had wiped out
whitespace in my parsed_doc, so that needs to be fixed.  Still, it almost
works.  *grin*

This is another example of a recursive function, so this might seem like a
weird little function at first.


I have to go at the moment, but I'll try looking at your other question
later.  Talk to you soon!




From GBunting864@Worldsavings.com  Tue Jun 11 22:09:16 2002
From: GBunting864@Worldsavings.com (Bunting, Glen, IG)
Date: Tue, 11 Jun 2002 14:09:16 -0700
Subject: [Tutor] zipfile module
Message-ID: <3BD366A4D49B7D4FAD4E41E4C99784B9A90FD0@OK1EMS2.worldsavings.com>

Hi,=20

I am trying to figure out how to use the zipfile module so I can use it to =
unzip some text files and zip them back up again after some text processing=
 has happened.  The documentation that I have found is very minimal for thi=
s module.  Can someone show me how it is supposed to be used so I can unzip=
 files and zip them up again later.

TIA

Glen


***************************************************************************=
**
If you are not the intended recipient of this e-mail, please notify=20
the sender immediately. The contents of this e-mail do not amend=20
any existing disclosures or agreements unless expressly stated.
***************************************************************************=
**




From dyoo@hkn.eecs.berkeley.edu  Tue Jun 11 22:17:32 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 11 Jun 2002 14:17:32 -0700 (PDT)
Subject: [Tutor] parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206111342220.13011-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0206111412370.13011-100000@hkn.eecs.berkeley.edu>


On Tue, 11 Jun 2002, Danny Yoo wrote:

> And this is the source of the shallowness: we're just calling str().
> But instead of directly calling str() on each piece in between, the
> trick is to apply toXML() again to each inner piece!  That way, we
> guarantee that the inner lists are also transformed properly:
>

[code of toXML()]
> def toXML(structure):
>    if type(structure) == type([]):
>        tag = structure[0][1:]  ## secondary slice removes leading '/'
>        text_pieces = [str(s) for s in structure[1:]]
>        return "<%(tag)s>%(text)s</%(tag)s>" % \
>               { 'tag' : tag,
>                 'text' : ''.join(text_pieces) }
>    else:
>        return str(structure)

> ###
> >>> def toXMLDeeply(structure):
> ...     if type(structure) == type([]):
> ...         tag = structure[0][1:]  ## secondary slice removes leading '/'
> ...         text_pieces = [toXML(s) for s in structure[1:]]
> ...         return "<%(tag)s>%(text)s</%(tag)s>" % \
> ...                { 'tag' : tag,
> ...                  'text' : ''.join(text_pieces) }
> ...     else:
> ...         return str(structure)
> ...
> >>> print toXMLDeeply(parsed_doc)
> <footnote><i>anitalicizedword</i><i>maybeanotheritalicizedword</i>text</footnote>
> ###
>
>
> The transformation wasn't perfect, because my parsing step had wiped out
> whitespace in my parsed_doc, so that needs to be fixed.  Still, it almost
> works.  *grin*


But note that if you have three levels of nesting, you'll still get weird
output, because the third level won't be marked up properly.  Yikes!

Ummm... I'll pretend that I didn't goof up, and say that if you understand
what's happening, you'll know how to fix this bug.  *grin*




From pydan@danshafer.com  Tue Jun 11 23:13:11 2002
From: pydan@danshafer.com (Dan Shafer)
Date: Tue, 11 Jun 2002 15:13:11 -0700
Subject: [Tutor] Creating an Identifier or Object Name from a String?
In-Reply-To: <Pine.LNX.4.44.0206110102050.31687-100000@hkn.eecs.berkeley.edu>
References: <5.1.0.14.0.20020611005842.029526e0@mail.hurrah.com>
Message-ID: <5.1.0.14.0.20020611151236.02a9e218@mail.hurrah.com>

Thanks, Danny. With your code as a clue for a starting point, I got this 
working just fine for list and dictionaries.

Appreciate it.

At 01:10 AM 6/11/2002 -0700, Danny Yoo wrote:


>On Tue, 11 Jun 2002, Dan Shafer wrote:
>
> > I have a need to refer to a number of objects which have been named
> > field1, field2, field3, etc. I want to set a property in each object in
> > a loop.
>
>Instead of having them as separate variables, is it possible to keep them
>grouped together in a list or dictionary?  That way, it's easier to work
>with them as a group, without the complexities of eval().
>
>
> > I thought this should work:
> >
> >    for ct in range(1,4):
> >      objToUpdate = "field" + str(ct)
> >      objToChange = eval(objToUpdate) # seems like it should produce
> > "field1" first time through the loop, etc.
> >      objToChange.text = inputList[ct] #inputList is generated prior to
> > entering the loop and is a list of string values
>
>
>So since your inputList is already a list, that may be a good hint that
>symmetry will help.  *grin* Try something like:
>
>###
>objects = [field1, field2, field3]  ### Add as many objects as you
>                                     ### have
>for i in range(len(objects)):
>     objects[i].text = inputlist[i]
>###
>
>
>But I didn't see anything obviously wrong with your initial approach.
>One suggestion would be to check the value of field1, field2, field3,
>right before the loop.  Also, if you can show us the literal error
>message, that may give more clues as to why it's doing weird things.

Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net




From pydan@danshafer.com  Tue Jun 11 23:14:01 2002
From: pydan@danshafer.com (Dan Shafer)
Date: Tue, 11 Jun 2002 15:14:01 -0700
Subject: [Tutor] Creating an Identifier or Object Name from a String?
In-Reply-To: <3D05B663.B87BF27@rg16.asn-wien.ac.at>
References: <5.1.0.14.0.20020611005842.029526e0@mail.hurrah.com>
Message-ID: <5.1.0.14.0.20020611151320.02aa79d0@mail.hurrah.com>

I think I was putting the eval step in the wrong place or something. 
Anyway, thanks to your comment and Danny Yoo's feedback, I got my program 
working just fine so it does the right thing with lists and with dictionaries.

Thanks!

At 10:35 AM 6/11/2002 +0200, Gregor Lingl wrote:
>I Tried it and it worked (?!)
>
>Python 2.2c1 (#27, Dec 14 2001, 13:15:16) [MSC 32 bit (Intel)] on win32
>Type "copyright", "credits" or "license" for more information.
>IDLE 0.8 -- press F1 for help
> >>> class K:
>         pass
>
> >>> field1 = K()
> >>> field2 = K()
> >>> field3 = K()
> >>> for ct in range(1,4):
>         obj="field"+str(ct)
>         objTC=eval(obj)
>         objTC.text=['a','b',str(ct)]
>
>
> >>> field1.text
>['a', 'b', '1']
> >>> field2.text
>['a', 'b', '2']
> >>> field3.text
>['a', 'b', '3']
> >>>
>
>Gregor
>
>
>Dan Shafer schrieb:
>
> > I have a need to refer to a number of objects which have been named field1,
> > field2, field3, etc. I want to set a property in each object in a loop.
> >
> > I thought this should work:
> >
> >    for ct in range(1,4):
> >      objToUpdate = "field" + str(ct)
> >      objToChange = eval(objToUpdate) # seems like it should produce
> > "field1" first time through the loop, etc.
> >      objToChange.text = inputList[ct] #inputList is generated prior to
> > entering the loop and is a list of string values
> >
> > This produces an error indicating that string objects don't have a text
> > attribute. So clearly objToChange is still a string at this point.
> >
> > I suspect this is tricky but if someone could help....
> >
> > Dan Shafer, Chief Scribe and Tablet Keeper
> > PythonCard Open Source Project
> > http://pythoncard.sourceforge.net
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor

Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net




From terjeja@hotmail.com  Tue Jun 11 23:31:01 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Tue, 11 Jun 2002 22:31:01 +0000
Subject: [Tutor] Win32com/Excel
Message-ID: <F13aYwFRWrYmkF1VlNy00019cf4@hotmail.com>

I try to open Excel thru win32com. I write:
>>>from win32com.client import Dispatch
>>>xlApp = Dispatch("Excel.Application")
>>>xlApp.Visible = 1

I get the frame of Excel, but not the spreadsheet. Even if I write:
>>>xlApp.Workbooks.Add()
it doesn't give me the ability to look whats there. I get the frame around 
the spreadsheet, and the menues at the top, as well as the paperclip. The 
paperclip works, the menus are selectable, but does not work. And the space 
where the spreadsheet should have been gives me a "picture" of what is on 
the desktop. (Other open windows in the background and so forth). I can move 
the Excel frame around, and the background follows along. I use the newest 
version of both Python and Win32com, and have tried this on two computers. 1 
with Win98 and 1 with win2k. Same result... Anyone seen this before? And 
managed to solve it?

Thanks,
Terje

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




From pythontutor@venix.com  Wed Jun 12 00:29:36 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Tue, 11 Jun 2002 19:29:36 -0400
Subject: [Tutor] Win32com/Excel
References: <F13aYwFRWrYmkF1VlNy00019cf4@hotmail.com>
Message-ID: <3D0687E0.8040006@venix.com>

xlBook = xlApp.Workbooks.Add()
sheet = xlBook.Worksheets('Sheet1')
row1,col1,row2,col2 = 1,1,3,4	#3 rows, 4 cols
return sheet.Range(sheet.Cells(row1, col1), sheet.Cells(row2, col2)).Value

Terje Johan Abrahamsen wrote:

> I try to open Excel thru win32com. I write:
> 
>>>> from win32com.client import Dispatch
>>>> xlApp = Dispatch("Excel.Application")
>>>> xlApp.Visible = 1
>>>
> 
> I get the frame of Excel, but not the spreadsheet. Even if I write:
> 
>>>> xlApp.Workbooks.Add()
>>>
> it doesn't give me the ability to look whats there. I get the frame 
> around the spreadsheet, and the menues at the top, as well as the 
> paperclip. The paperclip works, the menus are selectable, but does not 
> work. And the space where the spreadsheet should have been gives me a 
> "picture" of what is on the desktop. (Other open windows in the 
> background and so forth). I can move the Excel frame around, and the 
> background follows along. I use the newest version of both Python and 
> Win32com, and have tried this on two computers. 1 with Win98 and 1 with 
> win2k. Same result... Anyone seen this before? And managed to solve it?
> 
> Thanks,
> Terje
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From seiji_funai@yahoo.com  Wed Jun 12 00:57:28 2002
From: seiji_funai@yahoo.com (Seiji Funai)
Date: Tue, 11 Jun 2002 16:57:28 -0700 (PDT)
Subject: [Tutor] Continuously slower program
Message-ID: <20020611235728.37878.qmail@web21310.mail.yahoo.com>

--0-1648986577-1023839848=:35018
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

This is a test for the beginning of a meter that I'm
writing for a GUI.  The application slows
continuously.  Does my computer just suck, or is there
something I can do?  Please let me know.

Thanks!

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
--0-1648986577-1023839848=:35018
Content-Type: text/plain; name="testMeter.py"
Content-Description: testMeter.py
Content-Disposition: inline; filename="testMeter.py"

from Tkinter import *
import math

class TestMeter:
  def __init__(self, master):
    testMeterFrame = Frame(master)
    testMeterFrame.pack()
    self.count = 0
    self.box = 8, 8, 57, 57
    self.testMeterCanvas = Canvas(testMeterFrame, bg = "gray", width = 65, height = 65)
    self.testMeterCanvas.grid(row = 1, column = 1)
    self.testMeterCanvas.create_oval(2, 2, 63, 63, fill = "black")
    self.testMeterCanvas.create_oval(5, 5, 60, 60, fill = "gray")
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
    self.testMeterCanvas.create_line(33, 33, 33, 8, fill = "red")
    self.testMeterCanvas.create_text(33, 47, text = "M1")
    self.testMeterCanvas.create_text(10, 38, text = "0")
    self.testMeterCanvas.create_text(55, 38, text = "1")
    self.startButton = Button(testMeterFrame, text = "Start", command = self.start)
    self.startButton.grid(row = 2, column = 1, sticky = W+E+N+S)

  def start(self):
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
    while 1:
      self.count = self.count + .1
      if self.count == 1000:
        self.count = 0
      self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
      self.x = 25 * math.sin(self.count) + 33
      self.y = -25 * math.fabs(math.cos(self.count)) + 33
      self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill = "red")      
      root.update()
    
  def stop(self):
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
    self.testMeterCanvas.create_line(33, 33, 33, 8, fill = "red")
    
root = Tk()
testMeter = TestMeter(root)
root.mainloop()

--0-1648986577-1023839848=:35018--



From dman@dman.ddts.net  Wed Jun 12 03:28:39 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue, 11 Jun 2002 21:28:39 -0500
Subject: [Tutor] Re: Continuously slower program
In-Reply-To: <20020611235728.37878.qmail@web21310.mail.yahoo.com>
References: <20020611235728.37878.qmail@web21310.mail.yahoo.com>
Message-ID: <20020612022838.GA3199@dman.ddts.net>

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

On Tue, Jun 11, 2002 at 04:57:28PM -0700, Seiji Funai wrote:
| This is a test for the beginning of a meter that I'm
| writing for a GUI.  The application slows
| continuously.  Does my computer just suck, or is there
| something I can do?  Please let me know.

I tried it out on my system ... and I noticed that the CPU was pegged
right when the meter started moving slower.  When I closed the window
I got an exception out of Tcl.  I don't know Tcl or Tk at all so I
can't really help you with this, but I can say it isn't a result of
your particular platform.

-D

--=20

After you install Microsoft Windows XP, you have the option to create
user accounts.  If you create user accounts, by default, they will have
an account type of administrator with no password.
                                                            -- bugtraq
=20
Jabber ID : dman@dman.ddts.net
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg

--VS++wcV0S1rZb1Fb
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0GsdYACgkQO8l8XBKTpRSKZgCfeTF6UJhF3328zPc6/uSMlaZO
vEYAoIC4fT1JA7Xnf7KHgi+CPaFij6yv
=sZG4
-----END PGP SIGNATURE-----

--VS++wcV0S1rZb1Fb--



From lonetwin@subdimension.com  Wed Jun 12 07:34:32 2002
From: lonetwin@subdimension.com (lonetwin_SubD)
Date: Wed, 12 Jun 2002 12:04:32 +0530
Subject: [Tutor] Tk question
In-Reply-To: <20020611174406.GA21236@tc.niof.net>
References: <20020611132805.B15372F4C6@mercury.sapatmt> <20020611174406.GA21236@tc.niof.net>
Message-ID: <20020612063433.0B5272F4C6@mercury.sapatmt>

Hey Rick,
    Thanx for the reply.....the thing with tkinter is that I don't know where 
to look for info ....not because there is a lack of it ...but because the 
resources that are there are so very detailed that one can easily get 
confused/lost (that's how I got to trying "anchor" to solve the text 
justification.).
       I have a copy of "Tkinter reference: A GUI for Python" on my system, 
don't remember where I got it from. I'm sure the option might be mentioned 
_somewhere-in-there_ .....but where was not too obvious. In any case I should 
be blaming my laziness. 
      BTW, are there any good resources for *lazy* ppl., like a quick indexed 
reference for tkinter (along the lines of Python Quick reference at 
http://www.brunningonline.net/simon/python/PQR.html )

Peace
Steve

On Tuesday 11 June 2002 11:14 pm, you wrote:
> Add a justify option to your call to Label():
>
> Sub = Label(Master, font='fixed', text=out, justify=LEFT)
>
> On Tue, Jun 11, 2002 at 06:58:05PM +0530, lonetwin_SubD wrote:
> > Hi ppl,
> >      For convenience sake, I wrote a wrapper around the 'cal' command on
> > my linux box (and bound it to a shortcut keystroke on my Window manager).
> > There is one problem tho', I just can't figure out how to get the first
> > and last lines aligned properly. I tried passing anchor="w" while
> > initialising the Label but that does not seem to help .....any pointers
> > ??
> >
> > Here's the code (maybe someone else might find it useful too :)).
> >
> > Note : I specifically set the font to "fixed" b'cos with variable width
> > fonts spaces are "thinner" than characters and that screws up the
> > display.
> >
> > ---------------------------------------
> > #!/usr/bin/python
> > import os
> >
> > cal="/usr/bin/cal.orig"
> > args = ''.join(os.sys.argv[1:])
> > out = os.popen('%s %s' % (cal, args)).read()
> >
> > if os.environ.has_key('DISPLAY'):
> > 	from Tkinter import *
> > 	Master = Frame()
> > 	Master.master.title("Tkcal")
> > 	Sub = Label(Master, font='fixed', text=out)
> > 	Master.grid(ipadx=2, ipady=2)
> > 	Sub.grid()
> > 	Master.mainloop()
> > else:
> > 	print out
> > ----------------------------------------
> >
> > Peace
> > Steve
> >
> > PS: Maybe you are wondering why I did this, well I can only say that I
> > find myself using the keyboard 95% of the time when in windowmaker (my
> > preferred wm). Also, I've got a similar (shortcut) "front-end" to "ispell
> > -a", I'll send it across if anybody is interested.
> >
> > --
> > The prettiest women are almost always the most boring, and that is why
> > some people feel there is no God.
> > 		-- Woody Allen, "Without Feathers"
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor

-- 
Kleeneness is next to Godelness.



From phthenry@earthlink.net  Wed Jun 12 03:38:14 2002
From: phthenry@earthlink.net (Paul Tremblay)
Date: Tue, 11 Jun 2002 22:38:14 -0400
Subject: [Tutor] parsing--is this right?
In-Reply-To: <Pine.LNX.4.44.0206111342220.13011-100000@hkn.eecs.berkeley.edu>
References: <20020611145546.A31120@localhost.localdomain> <Pine.LNX.4.44.0206111342220.13011-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020611223814.E31120@localhost.localdomain>

On Tue, Jun 11, 2002 at 02:06:57PM -0700, Danny Yoo wrote:

Thanks Derrick and Danny.

Recursion is both intuitive and counter-intuitive. For example,
Derrick showed a fairly simple example using a factorial. But what
happens to the return in this line?

return n * fact( n-1 )

You think of return as getting one value, but the return somehow
has to wait and build up a value. Also, how come the function
doesn't return 1? The first part of the function says that it
should return 1 if n is equal to one. At some point, n becomes 1.
So why don't we see 1, and why doesn't the function stop?

On the other hand, recusion is intuititve in a way that is just
beyond my reach. I say this because I have written so much
duplicate code, and I'm always thinking, "How can I re-use this
code?" Of course, not all of this code is an example of
recursion, but I bet if I went back and looked, some of the
problems would be.

Anyway, all this should give me a bit to think about for a while.

Paul


-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************



From mhammond@skippinet.com.au  Wed Jun 12 04:08:24 2002
From: mhammond@skippinet.com.au (Mark Hammond)
Date: Wed, 12 Jun 2002 13:08:24 +1000
Subject: [Tutor] RE: [python-win32] Win32com/Excel
In-Reply-To: <F13aYwFRWrYmkF1VlNy00019cf4@hotmail.com>
Message-ID: <LCEPIIGDJPKCOIHOBJEPKEIPFMAA.mhammond@skippinet.com.au>

> I try to open Excel thru win32com. I write:
> >>>from win32com.client import Dispatch
> >>>xlApp = Dispatch("Excel.Application")
> >>>xlApp.Visible = 1
>
> I get the frame of Excel, but not the spreadsheet. Even if I write:
> >>>xlApp.Workbooks.Add()
> it doesn't give me the ability to look whats there. I get the
> frame around
> the spreadsheet, and the menues at the top, as well as the paperclip. The
> paperclip works, the menus are selectable, but does not work. And
> the space
> where the spreadsheet should have been gives me a "picture" of what is on
> the desktop. (Other open windows in the background and so forth).
> I can move
> the Excel frame around, and the background follows along. I use
> the newest
> version of both Python and Win32com, and have tried this on two
> computers. 1
> with Win98 and 1 with win2k. Same result... Anyone seen this before? And
> managed to solve it?

On my machine, your code seems to work fine - excel repaints and is fully
responsive.  The new worksheet is created and can be interacted with.

This occasionally happens when an existing Excel instance is already
running.  If your program crashed the last time you ran it, you may need to
kill the Excel.exe process manually.

If you see this behaviour inside a more complex app only, then it may be
that you need to occasionally pump a message loop -
pythoncom.PumpWaitingMessages() is often suitable.

Mark.




From dyoo@hkn.eecs.berkeley.edu  Wed Jun 12 10:36:08 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 12 Jun 2002 02:36:08 -0700 (PDT)
Subject: [Tutor] parsing--is this right?   [function evaluation / errors
 for fun and profit]
In-Reply-To: <20020611223814.E31120@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0206120202260.30373-100000@hkn.eecs.berkeley.edu>


On Tue, 11 Jun 2002, Paul Tremblay wrote:

> Recursion is both intuitive and counter-intuitive. For example, Derrick
> showed a fairly simple example using a factorial. But what happens to
> the return in this line?
>
> return n * fact( n-1 )
>
> You think of return as getting one value, but the return somehow has to
> wait and build up a value.

Yes, it has to evaluate the value of 'n * fact(n-1)', but this is not so
different from other expressions that use functions as little helpers.



Let's take one example of how Python builds up values, a hypotenuse
calculator:

###
def hypotenuse(side1, side2):
    return math.sqrt(square(side1) + square(side2))

def square(x): return x * x
###

This hypotenuse() function tells us how long a diagonal to a right
triangle would be, if we knew the lengths of the other two sides.  In
order for hypotenuse() function to work, it has to pass off some of the
work over to the square() function.


In fact, we can actually see this delegation in action if we deliberately
put a bug into square():

###
>>> import math
>>> def hypotenuse(side1, side2):
...     return math.sqrt(square(side1) + square(side2))
...
>>> def square(x):
...     return a * b
...
>>> hypotenuse(3, 4)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in hypotenuse
  File "<stdin>", line 2, in square
NameError: global name 'a' is not defined
###

If we look at the traceback error, it actual says something like "While I
was trying to compute hypotenuse, to do that, I had to do a square()ing...
but while I was trying to compute square, I ran into a problem." So
hypotenuse() actually passes the torch to squares()  first.  Once
square()'s done, then square() can 'return' the torch back to
hypotenuse().  That's why both functions are listed in this "traceback".



Here's a more dramatic example of the way Python calculates: let's reuse
that factorial() example, but let's be mischevious again: we'll put in a
fatal flaw that makes factorial() break down if we try to calculate
factorial(0):

###
>>> def factorial(x):
...     if x == 0:
...         print "I'm going to break down."
...         print 0 / 0   ## This is deliberate.
...     return x * factorial(x-1)
...
>>> factorial(0)
I'm going to break down.
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in factorial
ZeroDivisionError: integer division or modulo by zero
###

Yup, it breaks down predictably.  But what happens if we put larger values
of 'x' in there?


###
>>> factorial(4)
I'm going to break down.
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 5, in factorial
  File "<stdin>", line 5, in factorial
  File "<stdin>", line 5, in factorial
  File "<stdin>", line 5, in factorial
  File "<stdin>", line 4, in factorial
ZeroDivisionError: integer division or modulo by zero
###

The error message is subtly different:  there's a bunch more lines of
Python complaining!  And that's because to calculate factorial(4), Python
sees that it has to calculate factorial(3)... but to calculate
factorial(3), it has to first calculate factorial (2)... etc.  So
factorial() shows up multiple times, once for every time it had to use
itself as a helper.


If you ever have time to browse through a bookstore, try flipping through
Douglas Hofstadter's book, "Godel Escher Bach".  There's a very cool
chapter called "Little Harmonic Labyrinth", and it captures the idea of
recursion very well.


Gotta sleep now.  Hope this was helpful!




From donni@melwestmarket.com  Wed Jun 12 12:15:19 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Wed, 12 Jun 2002 21:15:19 +1000 (AUS Eastern Standard Time)
Subject: [Tutor] Whats the module for sounds in dos and linux?
Message-ID: <3D072D47.000005.42785@athlon900.vic.optushome.com.au>

--------------Boundary-00=_J9BL6RO0000000000000
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Whats the module for sounds in dos and linux? i want to be able to use th=
e beep() and playsound() function in dos and linux....
thanx for the help
--------------Boundary-00=_J9BL6RO0000000000000
Content-Type: Text/HTML;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">
</head>

<BODY background=3D"" bgColor=3D#ffffff style=3D"BACKGROUND-POSITION: 0px=
 0px; FONT-SIZE: 10pt; MARGIN: 1px; FONT-FAMILY: Arial" scroll=3Dyes ORGY=
POS=3D"0">
<TABLE border=3D0 cellPadding=3D0 cellSpacing=3D0 id=3DINCREDIMAINTABLE w=
idth=3D"95%">
<TR>

<TD id=3DINCREDITEXTREGION width=3D"100%" style=3D"PADDING-RIGHT: 7px; PA=
DDING-LEFT: 7px; FONT-SIZE: 10pt; FONT-FAMILY: Arial"=20
   >
      <P>Whats the module for sounds in dos and linux? i want to be able =
to use=20
      the beep() and playsound() function in dos and linux....</P>
      <DIV>thanx for the help</DIV></TD>
</TR>

<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">

=09<TABLE cellPadding=3D0 cellSpacing=3D0 width=3D"100%">
=09<TR>
=09<TD width=3D"100%"></TD>
=09<TD align=3Dmiddle id=3DINCREDISOUND vAlign=3Dbottom></TD>
=09<TD align=3Dmiddle id=3DINCREDIANIM vAlign=3Dbottom></TD>
=09</TR>
=09</TABLE>

</TD>
</TR>

</TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>_________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><I>Bravenet IncrediMail</I> - <B>Email ha=
s finally=20
evolved</B> - </FONT><A href=3D"http://www.bravenet.com/out.php?id=3D768"=
><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT>
</BODY>
</html>
--------------Boundary-00=_J9BL6RO0000000000000--




From sarmstrong13@mac.com  Wed Jun 12 15:03:13 2002
From: sarmstrong13@mac.com (SA)
Date: Wed, 12 Jun 2002 09:03:13 -0500
Subject: [Tutor] Continuously slower program
In-Reply-To: <20020611235728.37878.qmail@web21310.mail.yahoo.com>
Message-ID: <B92CBED1.6DD0%sarmstrong13@mac.com>

On 6/11/02 6:57 PM, "Seiji Funai" <seiji_funai@yahoo.com> wrote:

> This is a test for the beginning of a meter that I'm
> writing for a GUI.  The application slows
> continuously.  Does my computer just suck, or is there
> something I can do?  Please let me know.
> 
> Thanks!
> 
I'm no expert on Tkinter, so I'll only give you the results from my running
of the program:

I ran this in Xdarwin on an Apple G4 Powerbook w/ 512 M of RAM running OSX.
I ran the script alongside top to gauge cpu usage. CPU usage by the user
(me), because top spits usage down amongst system and user, during the
running of this script jumped from roughly 30% to a rough average of 75%
with 85% being the maximum amount I saw.

So I would have to concur that it is NOT your sytem that is causing the
problem. Something in the app is draining CPU cycles.

If I had to guess, and I definitely could be wrong, I would say your problem
may lie in this section:

def start(self):
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill
= "white")
    while 1:
      self.count = self.count + .1
      if self.count == 1000:
        self.count = 0
      self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180,
fill = "white")
      self.x = 25 * math.sin(self.count) + 33
      self.y = -25 * math.fabs(math.cos(self.count)) + 33
      self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill = "red")
      root.update()

Good Luck.
SA




From arcege@speakeasy.net  Wed Jun 12 17:49:32 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 12 Jun 2002 12:49:32 -0400
Subject: [Tutor] Continuously slower program
In-Reply-To: <20020611235728.37878.qmail@web21310.mail.yahoo.com>
References: <20020611235728.37878.qmail@web21310.mail.yahoo.com>
Message-ID: <20020612164932.GD895@speakeasy.net>

On Tue, Jun 11, 2002 at 04:57:28PM -0700, Seiji Funai wrote:
> This is a test for the beginning of a meter that I'm
> writing for a GUI.  The application slows
> continuously.  Does my computer just suck, or is there
> something I can do?  Please let me know.

Your problem is that you continually create new canvas objects inside the
while loop.  You should be creating the objects once, and changing them
as needed.  That was increasing the processing of the Canvas object,
increasing the memory of it, and sucking up CPU time.

Below are the changes to your code.  (Lines starting with "-" are removed,
and lines starting with "+" have been added.)  You want to capture the
canvas id of the red line, then change its coordinates inside the loop with
the "coords" method to the Canvas object.

  -Arcege


  from Tkinter import *
  import math

  class TestMeter:
    def __init__(self, master):
      testMeterFrame = Frame(master)
      testMeterFrame.pack()
      self.count = 0
      self.box = 8, 8, 57, 57
      self.testMeterCanvas = Canvas(testMeterFrame, bg = "gray", width = 65, height = 65)
      self.testMeterCanvas.grid(row = 1, column = 1)
      self.testMeterCanvas.create_oval(2, 2, 63, 63, fill = "black")
      self.testMeterCanvas.create_oval(5, 5, 60, 60, fill = "gray")
      self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
      self.testMeterCanvas.create_line(33, 33, 33, 8, fill = "red")
      self.testMeterCanvas.create_text(33, 47, text = "M1")
      self.testMeterCanvas.create_text(10, 38, text = "0")
      self.testMeterCanvas.create_text(55, 38, text = "1")
      self.startButton = Button(testMeterFrame, text = "Start", command = self.start)
      self.startButton.grid(row = 2, column = 1, sticky = W+E+N+S)

    def start(self):
      self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
+     self.x = 25 * math.sin(self.count) + 33
+     self.y = -25 * math.fabs(math.cos(self.count)) + 33
+     self.c = self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill="red")

      while 1:
        self.count = self.count + .1
        if self.count == 1000:
          self.count = 0
-       self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
        self.x = 25 * math.sin(self.count) + 33
        self.y = -25 * math.fabs(math.cos(self.count)) + 33
-       self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill = "red")
+       self.testMeterCanvas.coords(self.c, 33, 33, self.x, self.y)
        root.update()

    def stop(self):
      self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
      self.testMeterCanvas.create_line(33, 33, 33, 8, fill = "red")

  root = Tk()
  testMeter = TestMeter(root)
  root.mainloop()




From alan.gauld@bt.com  Wed Jun 12 18:35:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 12 Jun 2002 18:35:31 +0100
Subject: [Tutor] Tk question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C650@mbtlipnt02.btlabs.bt.co.uk>

>       BTW, are there any good resources for *lazy* ppl., like 
> a quick indexed reference for tkinter 

I already mentioned Tcl/Tk in a Nutshell from O'Reilly which is Tcl based.

Also Grayson's book has a quick reference to all the widgets as an appendix.

Alan G.



From sarmstrong13@mac.com  Wed Jun 12 19:32:09 2002
From: sarmstrong13@mac.com (SA)
Date: Wed, 12 Jun 2002 13:32:09 -0500
Subject: [Tutor] Continuously slower program
In-Reply-To: <20020612164932.GD895@speakeasy.net>
Message-ID: <B92CFDD9.6DDC%sarmstrong13@mac.com>

On 6/12/02 11:49 AM, "Michael P. Reilly" <arcege@speakeasy.net> wrote:

> On Tue, Jun 11, 2002 at 04:57:28PM -0700, Seiji Funai wrote:
>> This is a test for the beginning of a meter that I'm
>> writing for a GUI.  The application slows
>> continuously.  Does my computer just suck, or is there
>> something I can do?  Please let me know.
> 
> Your problem is that you continually create new canvas objects inside the
> while loop.  You should be creating the objects once, and changing them
> as needed.  That was increasing the processing of the Canvas object,
> increasing the memory of it, and sucking up CPU time.
> 
I get the following error when I run the revamped script:
 File "./TestMeter2.py", line 35
    self.testMeterCanvas.coords(self.c, 33, 33, self.x, self.y)
    ^
SyntaxError: invalid syntax

What did I do wrong?

Thanks.
SA




From sarmstrong13@mac.com  Wed Jun 12 19:35:35 2002
From: sarmstrong13@mac.com (SA)
Date: Wed, 12 Jun 2002 13:35:35 -0500
Subject: [Tutor] Tk question
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C650@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <B92CFEA7.6DE0%sarmstrong13@mac.com>

On 6/12/02 12:35 PM, "alan.gauld@bt.com" <alan.gauld@bt.com> wrote:

>>       BTW, are there any good resources for *lazy* ppl., like
>> a quick indexed reference for tkinter
> 
Try:

http://www.pythonware.com/library/tkinter/introduction/index.htm

http://www.python.org/topics/tkinter/doc.html

http://www.python.org/topics/tkinter/

There are some good links here.

Good Luck.
SA




From jeff@ccvcorp.com  Wed Jun 12 20:13:02 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed, 12 Jun 2002 12:13:02 -0700
Subject: [Tutor] Continuously slower program
References: <B92CFDD9.6DDC%sarmstrong13@mac.com>
Message-ID: <3D079D3D.FE47AF78@ccvcorp.com>


SA wrote:

>
> I get the following error when I run the revamped script:
>  File "./TestMeter2.py", line 35
>     self.testMeterCanvas.coords(self.c, 33, 33, self.x, self.y)
>     ^
> SyntaxError: invalid syntax
>
> What did I do wrong?

Often when Python throws a SyntaxError at the beginning of a line, the problem
is really with the previous line.  Can you cut&paste the entire method that
this is from?  That way, we can see a bit more context, and and can probably
spot the error easier.

Jeff Shannon
Technician/Programmer
Credit International





From arcege@speakeasy.net  Wed Jun 12 20:16:49 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 12 Jun 2002 15:16:49 -0400
Subject: [Tutor] Continuously slower program
In-Reply-To: <B92CFDD9.6DDC%sarmstrong13@mac.com>
References: <20020612164932.GD895@speakeasy.net> <B92CFDD9.6DDC%sarmstrong13@mac.com>
Message-ID: <20020612191649.GF895@speakeasy.net>

--jI8keyz6grp/JLjh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Jun 12, 2002 at 01:32:09PM -0500, SA wrote:
> On 6/12/02 11:49 AM, "Michael P. Reilly" <arcege@speakeasy.net> wrote:
> 
> > On Tue, Jun 11, 2002 at 04:57:28PM -0700, Seiji Funai wrote:
> >> This is a test for the beginning of a meter that I'm
> >> writing for a GUI.  The application slows
> >> continuously.  Does my computer just suck, or is there
> >> something I can do?  Please let me know.
> > 
> > Your problem is that you continually create new canvas objects inside the
> > while loop.  You should be creating the objects once, and changing them
> > as needed.  That was increasing the processing of the Canvas object,
> > increasing the memory of it, and sucking up CPU time.
> > 
> I get the following error when I run the revamped script:
>  File "./TestMeter2.py", line 35
>     self.testMeterCanvas.coords(self.c, 33, 33, self.x, self.y)
>     ^
> SyntaxError: invalid syntax
> 
> What did I do wrong?

I'm not sure... the line looks correct.  Is the indentation correct?
The error suggests that it is not indented with the rest of the block.
(Don't align the line with the commented line, but with the other lines.)

I'm enclosing the changes that I had made; maybe it can help you.

  -Arcege


--jI8keyz6grp/JLjh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="testMeter.py"

from Tkinter import *
import math

class TestMeter:
  def __init__(self, master):
    testMeterFrame = Frame(master)
    testMeterFrame.pack()
    self.count = 0
    self.box = 8, 8, 57, 57
    self.testMeterCanvas = Canvas(testMeterFrame, bg = "gray", width = 65, height = 65)
    self.testMeterCanvas.grid(row = 1, column = 1)
    self.testMeterCanvas.create_oval(2, 2, 63, 63, fill = "black")
    self.testMeterCanvas.create_oval(5, 5, 60, 60, fill = "gray")
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
    self.testMeterCanvas.create_line(33, 33, 33, 8, fill = "red")
    self.testMeterCanvas.create_text(33, 47, text = "M1")
    self.testMeterCanvas.create_text(10, 38, text = "0")
    self.testMeterCanvas.create_text(55, 38, text = "1")
    self.startButton = Button(testMeterFrame, text = "Start", command = self.start)
    self.startButton.grid(row = 2, column = 1, sticky = W+E+N+S)

  def start(self):
    self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")

    self.x = 25 * math.sin(self.count) + 33
    self.y = -25 * math.fabs(math.cos(self.count)) + 33
    self.c = self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill="red")
    while 1:
      self.count = self.count + .1
      if self.count == 1000:
        self.count = 0
#     self.testMeterCanvas.create_arc(self.box, start = 0, extent = 180, fill = "white")
      self.x = 25 * math.sin(self.count) + 33
      self.y = -25 * math.fabs(math.cos(self.count)) + 33
#     self.testMeterCanvas.create_line(33, 33, self.x, self.y, fill = "red")      
      self.testMeterCanvas.coords(self.c, 33, 33, self.x, self.y)
      root.update()
    
  def stop(self):
    self.testMeterCanvas.coords(self.c, 33, 33, 33, 8)

root = Tk()
testMeter = TestMeter(root)
root.mainloop()

--jI8keyz6grp/JLjh--



From sarmstrong13@mac.com  Wed Jun 12 20:46:06 2002
From: sarmstrong13@mac.com (SA)
Date: Wed, 12 Jun 2002 14:46:06 -0500
Subject: [Tutor] Continuously slower program
In-Reply-To: <20020612191649.GF895@speakeasy.net>
Message-ID: <B92D0F2E.6DE6%sarmstrong13@mac.com>

On 6/12/02 2:16 PM, "Michael P. Reilly" <arcege@speakeasy.net> wrote:

> 
> I'm not sure... the line looks correct.  Is the indentation correct?
> The error suggests that it is not indented with the rest of the block.
> (Don't align the line with the commented line, but with the other lines.)
> 
> I'm enclosing the changes that I had made; maybe it can help you.
> 
> -Arcege
> 
> 
That did the trick. It works now without the speed dropoff and according to
top it is only taking between 65-73% of the CPU user cycles. Wher as before
it was between 75-83%.

Thanks.
SA




From glingl@aon.at  Wed Jun 12 22:08:24 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed, 12 Jun 2002 23:08:24 +0200
Subject: [Tutor] Continuously slower program
References: <20020612164932.GD895@speakeasy.net> <B92CFDD9.6DDC%sarmstrong13@mac.com> <20020612191649.GF895@speakeasy.net>
Message-ID: <009101c21255$4ae35dd0$1615a8c0@mega>

----- Original Message ----- 
From: "Michael P. Reilly" <arcege@speakeasy.net>
To: <tutor@python.org>
Sent: Wednesday, June 12, 2002 9:16 PM
Subject: Re: [Tutor] Continuously slower program


> 
> I'm enclosing the changes that I had made; maybe it can help you.
> 
>   -Arcege
> 

I downloaded and ran your program and it worked well. 
However, when looking at the running the meter one 
observes every 10 to 15 seconds (on my machine) a 
sudden slowdown for half a second approximately. So this,
I think, is a visualization of garbage collection - 
which could be problematic when programming for instance 
actino games or some sorts of animation.

There come the following questions to my mind:

- Is it possible to distribute garbage collection
  smoothely over the entire process or to control
  its occurence in some other way?
- Where comes this g.c. from? Which part of the program
  uses that memory, which has to be cleared up? (Maybe
  some repeatedly generated local variables in the
  math - stuff?)
- Does the g.c. come from the Python interpreter or
  from the underlying Tcl/Tk?

Thanks in advance for your insight creating remarks

Gregor

P.S.: I also observe, that there are Tkinter programs,
which produce really strange error messages when closed
properly (by clicking on the windows-closing icon 'X'):

....
  File "C:\Python22\lib\lib-tk\Tkinter.py", line 1927, in coords
    self.tk.splitlist(
TclError: invalid command name ".8642816.8647440"

whereas others don't do that. Who knows, which 
feature of a TKinter program is responsible
for this unfriendly behaviour and how to avoid it.





From lonrunr02@juno.com  Wed Jun 12 02:32:19 2002
From: lonrunr02@juno.com (john p kensin)
Date: Tue, 11 Jun 2002 21:32:19 -0400
Subject: [Tutor] about python
Message-ID: <20020611.213220.1376.0.lonrunr02@juno.com>

        i like python, but i cant get it to work, i have tried the help
files and stuff, but there is always an error, and when i write something
in notepad, save it as .txt, i import it, it says i have to save, i do,
then it says syntax error, or something else, im talking about the
examples in the guide.

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.



From sheila@thinkspot.net  Thu Jun 13 05:29:43 2002
From: sheila@thinkspot.net (Sheila King)
Date: Wed, 12 Jun 2002 21:29:43 -0700
Subject: [Tutor] about python
In-Reply-To: <20020611.213220.1376.0.lonrunr02@juno.com>
Message-ID: <736549652A2@kserver.org>

On Tue, 11 Jun 2002 21:32:19 -0400, john p kensin wrote:
> i like python, but i cant get it to work, i have tried the help
> files and stuff, but there is always an error, and when i write
> something in notepad, save it as .txt, i import it, it says i have
> to save, i do, then it says syntax error, or something else, im
> talking about the examples in the guide.

Don't save the files as .txt.

Save them as .py.

To do this in Notepad, when you click on the File Menu, choose "Save 
As..." and when you go to enter the file name in the box for that, 
type the file name in quotes like this:

"example.py"

Then Notepad will let you save with a file extension different from 
txt.

Hopefully that will help?

Have you tried using IDLE?

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






From sarmstrong13@mac.com  Thu Jun 13 18:35:01 2002
From: sarmstrong13@mac.com (SA)
Date: Thu, 13 Jun 2002 12:35:01 -0500
Subject: [Tutor] I'm tring to translate a Tcl/Tk program into Python.
Message-ID: <B92E41F5.6E3E%sarmstrong13@mac.com>

Hi Everyone-

    I am trying to translate a tcl program that use tk into python. I seem
to be going along fine until I get to the process that wants to "catch" the
results onto one text screen. Here is what I am looking at:

proc python {} {
    catch {exec /sw/bin/python -c [.t1 get 0.0 end]} output
    .t2 delete 0.0 end
    .t2 insert end $output
}

Basically, this process catches the output from running the code in the text
widget .t1 through python -c and places it into the variable ouput.
The text widget .t2 is then cleared and the contents of the variable $output
are displayed in the text widget .t2.

I can translate all of the widgets into python/tkinter code, but I'm not
sure about how to translate this process. Is there a function similar to
"catch" in Python?

Thanks.
SA




From ak@silmarill.org  Thu Jun 13 18:39:17 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Thu, 13 Jun 2002 13:39:17 -0400
Subject: [Tutor] Whats the module for sounds in dos and linux?
In-Reply-To: <3D072D47.000005.42785@athlon900.vic.optushome.com.au>
References: <3D072D47.000005.42785@athlon900.vic.optushome.com.au>
Message-ID: <20020613173917.GA5265@ak.silmarill.org>

On Wed, Jun 12, 2002 at 09:15:19PM +1000, Dimitrije Nikic wrote:
> Whats the module for sounds in dos and linux? i want to be able to use the beep() and playsound() function in dos and linux....
> thanx for the help

There isn't one. You can beep by doing "pring '\a'" and you can play
sounds from PyGame, I believe.

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From jeff@ccvcorp.com  Thu Jun 13 18:52:05 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 13 Jun 2002 10:52:05 -0700
Subject: [Tutor] I'm tring to translate a Tcl/Tk program into Python.
References: <B92E41F5.6E3E%sarmstrong13@mac.com>
Message-ID: <3D08DBC4.72A05446@ccvcorp.com>


SA wrote:

> Hi Everyone-
>
>     I am trying to translate a tcl program that use tk into python. I seem
> to be going along fine until I get to the process that wants to "catch" the
> results onto one text screen. Here is what I am looking at:
>
> proc python {} {
>     catch {exec /sw/bin/python -c [.t1 get 0.0 end]} output
>     .t2 delete 0.0 end
>     .t2 insert end $output
> }

Where you're doing catch {exec ...} in tcl, for Python you'll want to look into
using os.popen('command ...'), which will start a new process execute 'command',
and returns a file-object that represents the stdout of the new process.  You
can then get that output by calling out.readlines(), or whatever.  (Note that
reading more from this file than is currently available, can cause your program
to block.)

Of course, if the command that you're executing is another Python script, you
may be better off just importing it instead of spawning a new shell and
interpreter for it...  :)

Jeff Shannon
Technician/Programmer
Credit International





From terjeja@hotmail.com  Thu Jun 13 19:48:38 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Thu, 13 Jun 2002 18:48:38 +0000
Subject: [Tutor] Format columns in Excel
Message-ID: <F177DVdcbBicPFMD5ce000050f7@hotmail.com>

I am trying to change a column in Excel with Win32Com. So far I have tried 
this:

class chkxl:
    xlApp = Dispatch("Excel.Application")
    xlApp.Workbooks.Open("agent.xls")
    agent = xlApp.Workbooks("agent.xls").Sheets("Sheet1")
def __init__(self):
    chkxl.agent.Columns(10).Style.Name = "number"

(There is more to it, so for example chkxl.agent.Cells(2,2).Value = "Hello" 
works)

The style.Name = "number" I found with the helper in Excel. It is supposed 
to work in VBA, but doesn't seem to work in Python. What would I write to 
get it to make the column into numbers?

Thanks,
Terje



_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




From dyoo@hkn.eecs.berkeley.edu  Thu Jun 13 20:14:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 13 Jun 2002 12:14:03 -0700 (PDT)
Subject: [Tutor] I'm tring to translate a Tcl/Tk program into Python.
In-Reply-To: <B92E41F5.6E3E%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206131154550.12379-100000@hkn.eecs.berkeley.edu>


On Thu, 13 Jun 2002, SA wrote:

> Hi Everyone-
>
>     I am trying to translate a tcl program that use tk into python. I seem
> to be going along fine until I get to the process that wants to "catch" the
> results onto one text screen. Here is what I am looking at:
>
> proc python {} {
>     catch {exec /sw/bin/python -c [.t1 get 0.0 end]} output
>     .t2 delete 0.0 end
>     .t2 insert end $output
> }
>
> Basically, this process catches the output from running the code in the
> text widget .t1 through python -c and places it into the variable ouput.
> The text widget .t2 is then cleared and the contents of the variable
> $output are displayed in the text widget .t2.
>
> I can translate all of the widgets into python/tkinter code, but I'm not
> sure about how to translate this process. Is there a function similar to
> "catch" in Python?

Hi SA,

Yes, it sounds like the 'os.popen()' function: we can us os.popen to run
external commands.  What we get back from it a file object that can
capture the text output.

For example:


###
>>> dictionary = os.popen('cat /usr/share/dict/words')
>>> dictionary.readline()
'Aarhus\n'
>>> dictionary.readline()
'Aaron\n'
>>> dictionary.readline()
'Ababa\n'
>>> dictionary.readline()
'aback\n'
###


So it works almost exactly as if we were opening a regular file, except
this "file" comes from running a particular program.


Hope this helps!




From sarmstrong13@mac.com  Thu Jun 13 20:21:11 2002
From: sarmstrong13@mac.com (SA)
Date: Thu, 13 Jun 2002 14:21:11 -0500
Subject: [Tutor] Thank You.
Message-ID: <B92E5AD7.705D%sarmstrong13@mac.com>

Than You everyone for your help.

Thanks.
SA




From sarmstrong13@mac.com  Thu Jun 13 20:45:59 2002
From: sarmstrong13@mac.com (SA)
Date: Thu, 13 Jun 2002 14:45:59 -0500
Subject: [Tutor] Tkinter script error.
Message-ID: <B92E60A7.7060%sarmstrong13@mac.com>

Hi Everyone-

    I'm practicing Tkinter from
http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm.
When I run the following Python script:

from Tkinter import *

class MyDialog:

    def __init__(self, parent):

        top = self.top = Toplevel(parent)

        Label(top, text="Value").pack()

        self.e = Entry(top)
        self.e.pack(padx=5)

        b = Button(top, text="OK", command=self.ok)
        b.pack(pady=5)

    def ok(self):

        print "value is", self.e.get()

        self.top.destroy()

root = Tk()
Button(root, text="Hello!").pack()
root.update()

d = MyDialog(root)

root.wait_window(d.top)

I get the following error:

Traceback (most recent call last):
  File "(string)", line 22 in ?
  File "(string)", line 11 in __init__
  File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1817, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1756, in __init__
    self.tk.call(
TclError: unkown option "-test"


Any ideas what is causing this?
Thanks.
SA







From rickp@telocity.com  Thu Jun 13 21:16:37 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Thu, 13 Jun 2002 16:16:37 -0400
Subject: [Tutor] Tkinter script error.
In-Reply-To: <B92E60A7.7060%sarmstrong13@mac.com>
References: <B92E60A7.7060%sarmstrong13@mac.com>
Message-ID: <20020613201637.GF21236@tc.niof.net>

OK, now, confess. You didn't cut-n-paste, did you?

The line in your message:

>         b = Button(top, text="OK", command=self.ok)

in your code is probably:

>         b = Button(top, test="OK", command=self.ok)

On Thu, Jun 13, 2002 at 02:45:59PM -0500, SA wrote:
> Hi Everyone-
> 
>     I'm practicing Tkinter from
> http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm.
> When I run the following Python script:
> 
> from Tkinter import *
> 
> class MyDialog:
> 
>     def __init__(self, parent):
> 
>         top = self.top = Toplevel(parent)
> 
>         Label(top, text="Value").pack()
> 
>         self.e = Entry(top)
>         self.e.pack(padx=5)
> 
>         b = Button(top, text="OK", command=self.ok)
>         b.pack(pady=5)
> 
>     def ok(self):
> 
>         print "value is", self.e.get()
> 
>         self.top.destroy()
> 
> root = Tk()
> Button(root, text="Hello!").pack()
> root.update()
> 
> d = MyDialog(root)
> 
> root.wait_window(d.top)
> 
> I get the following error:
> 
> Traceback (most recent call last):
>   File "(string)", line 22 in ?
>   File "(string)", line 11 in __init__
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1817, in __init__
>     Widget.__init__(self, master, 'button', cnf, kw)
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1756, in __init__
>     self.tk.call(
> TclError: unkown option "-test"
> 
> 
> Any ideas what is causing this?
> Thanks.
> SA
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
"Love is much like a wild rose, beautiful and calm, but willing to draw
blood in its defense."
		-- Mark A. Overby
    Rick Pasotto    rickp@telocity.com    http://www.niof.net



From dyoo@hkn.eecs.berkeley.edu  Thu Jun 13 21:28:58 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 13 Jun 2002 13:28:58 -0700 (PDT)
Subject: [Tutor] Tkinter script error.
In-Reply-To: <B92E60A7.7060%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206131324040.14380-100000@hkn.eecs.berkeley.edu>


On Thu, 13 Jun 2002, SA wrote:

>     I'm practicing Tkinter from
> http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm.
> When I run the following Python script:
>
> from Tkinter import *
>
> class MyDialog:
>
>     def __init__(self, parent):
>
>         top = self.top = Toplevel(parent)
>
>         Label(top, text="Value").pack()
>
>         self.e = Entry(top)
>         self.e.pack(padx=5)
>
>         b = Button(top, text="OK", command=self.ok)
>         b.pack(pady=5)
>
>     def ok(self):
>
>         print "value is", self.e.get()
>
>         self.top.destroy()
>
> root = Tk()
> Button(root, text="Hello!").pack()
> root.update()
>
> d = MyDialog(root)
>
> root.wait_window(d.top)
>
> I get the following error:
>
> Traceback (most recent call last):
>   File "(string)", line 22 in ?
>   File "(string)", line 11 in __init__
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1817, in __init__
>     Widget.__init__(self, master, 'button', cnf, kw)
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1756, in __init__
>     self.tk.call(
> TclError: unkown option "-test"


Hmmm... This is a weird one!  I tested out your program on my computer,
and it looked ok.  The word 'test' looks awfully similar to the word
'text', so my first guess is that there might be a spelling error when the
program was typed in.  Can you check this again?




From ATrautman@perryjudds.com  Thu Jun 13 21:31:35 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Thu, 13 Jun 2002 15:31:35 -0500
Subject: [Tutor] Tkinter script error.
Message-ID: <75EDF89FDE81D511840D00A0C9AD25DD0261A2DF@CORP_EXCHANGE>


-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Thursday, June 13, 2002 3:29 PM
To: SA
Cc: tutor
Subject: Re: [Tutor] Tkinter script error.




On Thu, 13 Jun 2002, SA wrote:

>     I'm practicing Tkinter from
> http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm.
> When I run the following Python script:
>
> from Tkinter import *
>
> class MyDialog:
>
>     def __init__(self, parent):
>
>         top = self.top = Toplevel(parent)
>
>         Label(top, text="Value").pack()
>
>         self.e = Entry(top)
>         self.e.pack(padx=5)
>
>         b = Button(top, text="OK", command=self.ok)
>         b.pack(pady=5)
>
>     def ok(self):
>
>         print "value is", self.e.get()
>
>         self.top.destroy()
>
> root = Tk()
> Button(root, text="Hello!").pack()
> root.update()
>
> d = MyDialog(root)
>
> root.wait_window(d.top)
>
> I get the following error:
>
> Traceback (most recent call last):
>   File "(string)", line 22 in ?
>   File "(string)", line 11 in __init__
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1817, in __init__
>     Widget.__init__(self, master, 'button', cnf, kw)
>   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1756, in __init__
>     self.tk.call(
> TclError: unkown option "-test"


This script run well on my PC using IDLE are you using a command line
interface with this?



From sarmstrong13@mac.com  Thu Jun 13 23:54:15 2002
From: sarmstrong13@mac.com (SA)
Date: Thu, 13 Jun 2002 17:54:15 -0500
Subject: [Tutor] Tkinter script error.
In-Reply-To: <75EDF89FDE81D511840D00A0C9AD25DD0261A2DF@CORP_EXCHANGE>
Message-ID: <B92E8CC7.707D%sarmstrong13@mac.com>

Yes, I think this is my spelling error. Unfortunately I am a bad typer.
Thank you all for your patience.

Thanks.
SA




From flaxeater@yahoo.com  Fri Jun 14 00:41:29 2002
From: flaxeater@yahoo.com (Chad Crabtree)
Date: Thu, 13 Jun 2002 16:41:29 -0700 (PDT)
Subject: [Tutor] FTP Question
In-Reply-To: <20020613160005.2485.68960.Mailman@mail.python.org>
Message-ID: <20020613234129.10828.qmail@web11605.mail.yahoo.com>

I previously asked how one can get the IP address of
thier local machine  The information was very helpful
and I finaly wrote the script to do what I needed to.

I have also learned why the interactive interpreter is
so amazingly awesome.  However I have a question
when I was uploading the file I

f=open('file','rb')
#opened the ftpconnect and logged in
ftp.storbinary('STOR file',f)
f.close()

However it occured to me that I could do it
differently So I tried it on the Interpreter and it
did work however it brought up another question
I did this

#after connecting and logging in
ftp.storbinary('STOR file',open('file','rb))

and this method was successful which supprised me
however I'm wondering if this file is now just
floating around in memory, because I couldn't figure
out how to close it.  Hmmmm

Thank you so much for you time
I really Appreciate all the discusion on this List it
has been very illuminating

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From sheila@thinkspot.net  Fri Jun 14 00:50:08 2002
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 13 Jun 2002 16:50:08 -0700
Subject: [Tutor] FTP Question
In-Reply-To: <20020613234129.10828.qmail@web11605.mail.yahoo.com>
Message-ID: <B5CC957366E@kserver.org>

On Thu, 13 Jun 2002 16:41:29 -0700 (PDT), Chad Crabtree wrote:
> #after connecting and logging in ftp.storbinary('STOR
> file',open('file','rb))
>
>
> and this method was successful which supprised me however I'm
> wondering if this file is now just floating around in memory,
> because I couldn't figure out how to close it.  Hmmmm

The file closes itself.

Since you did not assign any "identifier" or variable name to 
reference the object, it will close as soon as you are done working 
with it.

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





From mico@cbn.net.id  Fri Jun 14 01:17:28 2002
From: mico@cbn.net.id (Mico Siahaan)
Date: Fri, 14 Jun 2002 07:17:28 +0700
Subject: [Tutor] Convert man file into readable text file
Message-ID: <5.1.0.14.0.20020614071008.00a704d0@pop.cbn.net.id>

I'm a newbie. I want to make a python script to convert a man file into a 
readable text file so I can edit it with a text editors.

So far, I made this:

import string
fin = open("wget.man","r")
fout = open("wget.test","w")

while 1:
         line = fin.readline()
         if line == "":
                 break
         for ch in line:
                 if ch not in string.printable:
                         idx = line.find(ch)
                         temp = line[:idx] + line[idx+1:]
                         newline = temp
                 else:
                         newline = line
         fout.write(newline)

fin.close()
fout.close()

And it gives a wrong result. I understand it is because I don't understand 
the structure of man files.
Can anyone give me a correct example, please? Thanks.


Mico Siahaan
---
E-mail  : mico at cbn dot net dot id





From dman@dman.ddts.net  Fri Jun 14 02:57:47 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 13 Jun 2002 20:57:47 -0500
Subject: [Tutor] Re: FTP Question
In-Reply-To: <B5CC957366E@kserver.org>
References: <20020613234129.10828.qmail@web11605.mail.yahoo.com> <B5CC957366E@kserver.org>
Message-ID: <20020614015747.GA28056@dman.ddts.net>

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

On Thu, Jun 13, 2002 at 04:50:08PM -0700, Sheila King wrote:
| On Thu, 13 Jun 2002 16:41:29 -0700 (PDT), Chad Crabtree wrote:
| > #after connecting and logging in ftp.storbinary('STOR
| > file',open('file','rb))
| >
| >
| > and this method was successful which supprised me however I'm
| > wondering if this file is now just floating around in memory,
| > because I couldn't figure out how to close it.  Hmmmm
|=20
| The file closes itself.
|=20
| Since you did not assign any "identifier" or variable name to=20
| reference the object, it will close as soon as you are done working=20
| with it.

This assumes that no dangling references exist.  It also assumes there
are no bugs in the interpreter that could crash it before that
happens.  I think it is better practice to assign it to a handle and
explicitly close() it when you are done.

-D

--=20

One OS to rule them all, one OS to find them,
One OS to bring them all and in the darkness bind them,
In the Land of Redmond, where the Shadows lie.
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0JTZsACgkQO8l8XBKTpRSngACfVKfQ8CeVrOcMiReNTX8OHkZK
/2cAn1EMZZ+7B0JUdav+QegXyZI+1NP8
=vr2N
-----END PGP SIGNATURE-----

--sm4nu43k4a2Rpi4c--



From dman@dman.ddts.net  Fri Jun 14 03:13:26 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 13 Jun 2002 21:13:26 -0500
Subject: [Tutor] Re: Convert man file into readable text file
In-Reply-To: <5.1.0.14.0.20020614071008.00a704d0@pop.cbn.net.id>
References: <5.1.0.14.0.20020614071008.00a704d0@pop.cbn.net.id>
Message-ID: <20020614021326.GB28056@dman.ddts.net>

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

On Fri, Jun 14, 2002 at 07:17:28AM +0700, Mico Siahaan wrote:
| I'm a newbie. I want to make a python script to convert a man file into a=
=20
| readable text file

$ man

It outputs text itself.

$ man | vim -

Ok, so it has backspace characters in it to achieve bold and
underline on terminals.

(in vim)

:%s/.^H//g

(where ^H is a literal Ctrl-H character, entered by pressing ^V^H)


Even better yet, in your .vimrc put this line :
    " enable the :Man command
    runtime ftplugin/man.vim

and in ~/.bashrc put this :
    function man()
    {
        vim -c 'set nolist' -c ":Man $@"
    }

then when you run 'man' in your shell you'll see the man page (in full
color!) in a vim buffer.  In addition, when you are in vim you can
type :Man <foo>  to get <foo>'s manpage in a buffer.  It's really
cool.

(note: this requires vim 6 or newer and the man.vim plugin distributed
with it)

| so I can edit it with a text editors.

If you want to edit a manpage you should learn troff.  Man pages are
written in troff format, and then troff (or groff) processes them to
generate the properly formatted output for your display.  Dumping out
plain ascii and editing that won't have any long-term effects.  (eg
the maintainer of the manpage isn't going to accept a patch from it)

| So far, I made this:
|=20
| import string
| fin =3D open("wget.man","r")
| fout =3D open("wget.test","w")
|=20
| while 1:
|         line =3D fin.readline()
|         if line =3D=3D "":
|                 break
|         for ch in line:
|                 if ch not in string.printable:
|                         idx =3D line.find(ch)
|                         temp =3D line[:idx] + line[idx+1:]
|                         newline =3D temp
|                 else:
|                         newline =3D line
|         fout.write(newline)
|=20
| fin.close()
| fout.close()
|=20
| And it gives a wrong result.

How is it wrong?  I'm not going to guess.  Actuall, I will.  It's
wrong because all the characters in the troff source are already
printable so you won't have changed anything.

| I understand it is because I don't understand the structure of man
| files.

groff does.  It is a troff processor.

| Can anyone give me a correct example, please? Thanks.

One way is using the existing tools on the shell.  It would require
less effort :
    $ man man | sed -e 's/.\x08//g' > man.text

(or the equivalent vim commands given above)
   =20
If you want to use python instead of vim or sed or somesuch existing
tool :

import os , re
input =3D os.popen( "man man" )
out =3D open( "output.text" , "w" )
for line in input :  # requires python 2.2
    out.write( re.sub( r'.\x08' , '' , line ) )
out.close()
in.close()
   =20

(it does the same thing as all the other solutions I presented, but is
clearly a lot more work/code)

HTH,
-D

--=20

The light of the righteous shines brightly,
but the lamp of the wicked is snuffed out.
        Proverbs 13:9
=20
http://dman.ddts.net/~dman/


--Bn2rw/3z4jIqBvZU
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0JUUYACgkQO8l8XBKTpRQACACfYZpCW3kHG5KVj1Osrr3V9tjP
VAAAoIPsc4WWeSIk5whzkMR2wfxpa4Q9
=2kMQ
-----END PGP SIGNATURE-----

--Bn2rw/3z4jIqBvZU--



From sheila@thinkspot.net  Fri Jun 14 03:17:22 2002
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 13 Jun 2002 19:17:22 -0700
Subject: [Tutor] Re: FTP Question
In-Reply-To: <20020614015747.GA28056@dman.ddts.net>
Message-ID: <BE39C713965@kserver.org>

On Thu, 13 Jun 2002 20:57:47 -0500, Derrick 'dman' Hudson wrote:
> | Since you did not assign any "identifier" or variable name to 
> | reference the object, it will close as soon as you are done 
> | working with it.
>
>
> This assumes that no dangling references exist.  It also assumes
> there are no bugs in the interpreter that could crash it before
> that happens.  I think it is better practice to assign it to a
> handle and explicitly close() it when you are done.

Personally, this is how I usually handle my file routines as well. 
However, I was recently had someone review code I'd written, where I 
did as you suggest (created a reference to the file, and then 
specifically closed it), and when this much more experienced and 
knowledgeable person reviewed my code, he wrote:

The following code:
        f = open(HTML_template_file, 'r')
        HTML_data = f.read()
        f.close()
 could just as easily be replace with:
         f = open(HTML_template_file[, 'r']).read()
 Matter of personal preference, I guess.

These comments were written by the author of the following software:
http://untroubled.org/

Now, your statements make good sense to me. <shrug>

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






From sarmstrong13@mac.com  Fri Jun 14 04:13:32 2002
From: sarmstrong13@mac.com (SA)
Date: Thu, 13 Jun 2002 22:13:32 -0500
Subject: [Tutor] More Tkinter Help Please
Message-ID: <B92EC98C.70F0%sarmstrong13@mac.com>

Hi Everyone-

    I have another Tkinter question for you. I'm still trying to translate
"that previously mentioned" Tcl/Tk program into Python/Tkinter. The
following is all of the code I've managed so far:

from Tkinter import *
import sys
import os

class PyShell:
    def __init__(self, top):
    
        f = Frame(top)
        f.pack()
        
        self.t1 = Text(f, height="12", width="84", font="Courier 12")
        self.t1.pack(side=TOP, pady=2)
        
        self.t2 = Text(f, height="12", width="84", bg="lightblue",
font="Courier 12")
        self.t2.pack(side=TOP, pady=2)
        
        self.b1 = Button(f, text="Execute", command=self.expyth)
        self.b1.pack(side=LEFT)
        
        self.b2 = Button(f, text="Clear Input", command=self.clearin)
        self.b2.pack(side=LEFT)
        
        self.b3 = Button(f, text="Clear Output", command=self.clearout)
        self.b3.pack(side=LEFT)
        
        self.b4 = Button(f, text="Save Input", command=self.savin)
        self.b4.pack(side=LEFT)
        
    def clearin(self):
        self.t1.delete(0,END)
        
    def clearout(self):
        self.t2.delete(0,END)
        
    def expyth(self):
        output = os.popen("python -c").t1()
        self.t2.delete(0,END)
        sys.stdout.write.t2(output)
        
    def savin(self):
        pass
        
root = Tk()

app = PyShell(root)

root.mainloop()

When I run this I get the following error:

Traceback (most recent call last):
  File "PyShell.py", line 45, in ?
    app = PyShell(root)
  File "PyShell.py", line 17, in __init__
    self.b1 = Button(f, text="Execute", command=self.expyth)
AttributeError: PyShell instance has no attribute 'expyth'


Any ideas on what I'm doing wrong here?

Thanks.
SA




From iumarumo@eidosnet.co.uk  Fri Jun 14 11:27:48 2002
From: iumarumo@eidosnet.co.uk (ibraheem umaru-mohammed)
Date: Fri, 14 Jun 2002 11:27:48 +0100
Subject: [Tutor] Re: Convert man file into readable text file
In-Reply-To: <20020614021326.GB28056@dman.ddts.net>
References: <5.1.0.14.0.20020614071008.00a704d0@pop.cbn.net.id> <20020614021326.GB28056@dman.ddts.net>
Message-ID: <20020614102748.GB20962@micromuse.com>

[Derrick 'dman' Hudson wrote...]
				.
				.
				.
-| | Can anyone give me a correct example, please? Thanks.
-| 
-| One way is using the existing tools on the shell.  It would require
-| less effort :
-|     $ man man | sed -e 's/.\x08//g' > man.text
-| 
-| (or the equivalent vim commands given above)
-|     

If you have the "col" command you can do the following:

	$ man man | col -b | vim -

Kindest regards,

			--ibs.

-- 
			ibraheem umaru-mohammed
			   www.micromuse.com
			         --0--



From alan.gauld@bt.com  Fri Jun 14 12:18:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 14 Jun 2002 12:18:13 +0100
Subject: [Tutor] Tkinter script error.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C657@mbtlipnt02.btlabs.bt.co.uk>

> When I run the following Python script:

Is this actually cut n paste or did you retype it?

> 
>     def __init__(self, parent):
>         ....
>         b = Button(top, text="OK", command=self.ok)
>         b.pack(pady=5)
> 
> I get the following error:
> 
> Traceback (most recent call last):
>   File "(string)", line 22 in ?
>   File "(string)", line 11 in __init__

Indicates the problem is with the button.

> TclError: unkown option "-test"

Suggests you are trying to set an attribute called test 
which doesn't exist.
Could it be you have a typo in the real code whereby you 
set "test" instead of "text" as shown in the code above?

Just a thought.

Alan G.





From alan.gauld@bt.com  Fri Jun 14 12:22:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 14 Jun 2002 12:22:20 +0100
Subject: [Tutor] Convert man file into readable text file
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C658@mbtlipnt02.btlabs.bt.co.uk>

> I'm a newbie. I want to make a python script to convert a man 
> file into a readable text file 

As an excercise fine but you could just do:

nroff -man foo.man > foo.txt

Its easier, faster and probably more useful since it will 
create the paragraphs and headings etc correctly....

Alan G.



From rob@uselesspython.com  Fri Jun 14 13:28:20 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Fri, 14 Jun 2002 07:28:20 -0500
Subject: [Tutor] [slightly OT?]  Python at Technipal.com
Message-ID: <3D09E164.4090806@uselesspython.com>

In a pleasant turn of events, a new site called Technipal.com (devoted 
to providing info and resources for novice and experienced programmers) 
has taken my suggestion and added a Python section:

http://www.technipal.com/directory/dlanguages/dpython/index.html

If anyone would consider taking a look and suggesting your own favorite 
link(s) to the webmaster there, it might help out.

BTW, Useless Python hasn't dropped back into dormancy these last few 
weeks. I'm just taking a C++ class that meets every day at nearby 
Belhaven College, so I have a little less time to manage at the moment.

Thanks to Python (and the Tutor List) helping me get a handle on so many 
important concepts, I'm currently holding steady at an A+ average in the 
class and helping the other students! Of course, I'm my usual Python 
Evangelist self in the class every day, and the instructor was impressed 
with the very size of Useless Python (a fact attibutable primarily to 
your source code submissions). "This is one BIG site!" he said.

peace,
Rob





From cheshire_cat_sf@yahoo.com  Fri Jun 14 15:21:59 2002
From: cheshire_cat_sf@yahoo.com (Britt Green)
Date: Fri, 14 Jun 2002 07:21:59 -0700 (PDT)
Subject: [Tutor] Python-based Blog Software?
In-Reply-To: <20020614020302.22138.4434.Mailman@mail.python.org>
Message-ID: <20020614142159.58018.qmail@web14107.mail.yahoo.com>

Anyone know if there's any Python-based weblog software, similiar
perhaps to Slashcode or Scoop? Google isn't returning anything....

Britt

=====
"The ocean, she is strange and wonderous, filled with animals that disturb even a Frenchman."

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From alan.gauld@bt.com  Fri Jun 14 17:05:50 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 14 Jun 2002 17:05:50 +0100
Subject: [Tutor] Re: FTP Question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C65E@mbtlipnt02.btlabs.bt.co.uk>

> specifically closed it), and when this much more experienced and 
> knowledgeable person reviewed my code, he wrote:
> 
> The following code:
>         f = open(HTML_template_file, 'r')
>         HTML_data = f.read()
>         f.close()
>  could just as easily be replace with:
>          f = open(HTML_template_file[, 'r']).read()
>  Matter of personal preference, I guess.

Then he was wrong... it should be:

          HTML_data = open(HTML_template_file[, 'r']).read()

and I assume the [, 'r'] bit is just to show its optionality...

Personally I use the specific assignment but I do suspect 
thats just left over paranoia from my C/C++ days :-)

Alan g.



From charlie@begeistert.org  Fri Jun 14 19:40:10 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Fri, 14 Jun 2002 18:40:10 +0000
Subject: [Tutor] re: Python based Blog software
In-Reply-To: <20020614160004.23404.72623.Mailman@mail.python.org>
References: <20020614160004.23404.72623.Mailman@mail.python.org>
Message-ID: <20020614184210.14143.17@bepc.1023995658.fake>

On 2002-06-14 at 16:00:04 [+0000], you wrote:
> Anyone know if there's any Python-based weblog software, similiar
> perhaps to Slashcode or Scoop? Google isn't returning anything....

Just in case nobody else has got round to it: look at Squishdot for Zope. 
Because Zope is so useful most people use Zope for CM in Python because 
they're good and, therefore, lazy programmers.

Charlie



From alan.gauld@bt.com  Fri Jun 14 17:46:35 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 14 Jun 2002 17:46:35 +0100
Subject: [Tutor] More Tkinter Help Please
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C660@mbtlipnt02.btlabs.bt.co.uk>

> class PyShell:
>     def __init__(self, top):
>         self.b1 = Button(f, text="Execute", command=self.expyth)
>         self.b1.pack(side=LEFT)
>
>     def expyth(self):
>         output = os.popen("python -c").t1()
>         self.t2.delete(0,END)
>         sys.stdout.write.t2(output)

> When I run this I get the following error:
> 
> Traceback (most recent call last):
> AttributeError: PyShell instance has no attribute 'expyth'

I think its because at the time that init is defined 
it can't see self.expyth because its not been defined yet. 
Try moving the init method after all the other methods?

However I'm not really happy with that answer because init 
shouldn't run till you  create an instance which is after 
you define the class, so I could very well be wrong!

Alan G.



From sarmstrong13@mac.com  Fri Jun 14 18:03:21 2002
From: sarmstrong13@mac.com (SA)
Date: Fri, 14 Jun 2002 12:03:21 -0500
Subject: [Tutor] Re: Translating Tcl/Tk code into Python/Tkinter help please...
In-Reply-To: <m3sn3qs0ba.fsf@fkogtsp1.bmc.uu.se>
References: <B92E4241.6F6B%sarmstrong13@mac.com> <m3sn3qs0ba.fsf@fkogtsp1.bmc.uu.se>
Message-ID: <B92F8C09.7161%sarmstrong13@mac.com>

On 6/14/02 3:59 AM, in article m3sn3qs0ba.fsf@fkogtsp1.bmc.uu.se, "Thomas
Sicheritz-Ponten" <thomas@cbs.dtu.dk> wrote:

> "try" and "exec" is used instead of "catch"
> but in this case you could use commands.getoutput
> 
> Untested code:
> 
> import commands
> from Tkinter import *
> 
> 
> def execute_python_code1():
>   global t1, t2
> 
>   txt = t1.get(0.0, END)
>   com = "/sw/bin/python -c %s" txt
>   
>   try: 
>       output = commands.getoutput(com)
>   except:
>       output = 'Error running command: %s' % com
> 
>   t2.delete(0.0, END)
>   t2.insert(END,output)
> 
> 
>   
> # getoutput returns errors as catch does, so there is no need to use
> try/except
> # IMHO, you should strip newlines from the command returned from the text
> widget
> 
> def execute_python_code2():
>   t2.delete(0.0, END)
>   output = commands.getoutput(com = "/sw/bin/python -c %s" % t1.get(0.0,
> END).strip())
>   t2.insert(END,output)
>       
>       
Thank You Everyone for your help.

I changed:

def execute_python_code2():
    t2.delete(0.0, END)
    output = commands.getoutput(com = "/sw/bin/python -c %s" % t1.get(0.0,
END).strip())
    t2.insert(END,output)
 to:

def execute_python_code2():
    t2.delete(0.0, END)
    output = commands.getoutput(t1.get(0.0,END)
    t2.insert(END,output)


This seems to do the trick. I can now enter a python command in t1 hit the
execute button and the result is printed in t2.

This seems to accomplish what I need. Once again, thank you everyone.

Thanks.
SA




From jeff@ccvcorp.com  Fri Jun 14 19:14:33 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 14 Jun 2002 11:14:33 -0700
Subject: [Tutor] Re: FTP Question
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C65E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3D0A3289.5AC57FFE@ccvcorp.com>


alan.gauld@bt.com wrote:

> > specifically closed it), and when this much more experienced and
> > knowledgeable person reviewed my code, he wrote:
> >
> > The following code:
> >         f = open(HTML_template_file, 'r')
> >         HTML_data = f.read()
> >         f.close()
> >  could just as easily be replace with:
> >          f = open(HTML_template_file[, 'r']).read()
>
> Then he was wrong... it should be:
>
>           HTML_data = open(HTML_template_file[, 'r']).read()
>
> and I assume the [, 'r'] bit is just to show its optionality...
>
> Personally I use the specific assignment but I do suspect
> thats just left over paranoia from my C/C++ days :-)

Actually, I think it's justified paranoia.  As I understand it, in
Jython timely finalization is not guaranteed (because it uses Java's
GC, which does not immediately clean up).  This means that the
re-coded example, with no explicit close(), leaves the file open for
some undefined length of time.  For files open for reading, this is
not so bad, but files that are written to in this way will not be
written to disk (because the buffer is never flushed) until the file
is closed, and there's no way to know when that might be (if ever -- a
program crash will kill your data without ever writing it out).

Allowing GC to implicitly close files does work in CPython, but....
while I don't envision my code running under Jython, I'd rather avoid
techniques that are known to be implementation-dependent (just as I
try to write platform-portable code as much as possible, despite that
I almost exclusively run under Windows).  And anyhow, explicit is
better than implicit.  ;)

Jeff Shannon
Technician/Programmer
Credit International





From jimmy_130@lycos.com  Fri Jun 14 22:13:00 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Fri, 14 Jun 2002 17:13:00 -0400
Subject: [Tutor] Question about sprites
Message-ID: <DMDEIFLJDPGEPAAA@mailcity.com>

I heard from a friend that in the videogame world that sprites are programmed by telling the computer or videogame console where each pixel or dot was. That sounds kinda tedious. Couldn't you just load a picture? Is that possible?


_______________________________________________________
WIN a first class trip to Hawaii.  Live like the King of Rock and Roll
on the big Island. Enter Now!
http://r.lycos.com/r/sagel_mail/http://www.elvis.lycos.com/sweepstakes



From jimmy_130@lycos.com  Fri Jun 14 22:13:00 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Fri, 14 Jun 2002 17:13:00 -0400
Subject: [Tutor] Question about sprites
Message-ID: <OIPJAPOJDPGEPAAA@mailcity.com>

I heard from a friend that in the videogame world that sprites are programmed by telling the computer or videogame console where each pixel or dot was. That sounds kinda tedious. Couldn't you just load a picture? Is that possible?


_______________________________________________________
WIN a first class trip to Hawaii.  Live like the King of Rock and Roll
on the big Island. Enter Now!
http://r.lycos.com/r/sagel_mail/http://www.elvis.lycos.com/sweepstakes



From shendric@arches.uga.edu  Fri Jun 14 23:18:56 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Fri, 14 Jun 2002 17:18:56 -0500
Subject: [Tutor] Runtime Errors
Message-ID: <1024089536.smmsdV1.1.1@mail.arches.uga.edu>

Hi all,

I've got a script I'm working on that is a kind of spreadsheet.  There 
are a fixed number of 4 cells in each row, but the idea would be to have 
as many rows as one wishes.  The algorithm for the spreadsheet works 
fine, but I get a RuntimeError when I try to load a tab-delimited text 
file into the cells.

The loading algorithm is this:

1. Open a text file
2. Read the lines of the text file into a list (readlines())
3. Take each line and do the following:
    a. create an instance of the TranscriptionCell class, which is a 
class that includes four Tkinter Pmw.ScrolledText widgets
    b. append that instance to a list
    c. put the contents of the first part of the line into the first 
text widget, then the second into the second, etc.
4.  close the file

I get the following error:
RuntimeError: maximum recursion depth exceeded

Now, I've gotten it to go just fine with only a few rows, but not if 
there are a lot of them.

Anyway, here's the code for the algorithm above.  Is it just simply too 
much to have that many instances of a class with that many scrolling 
textboxes?


def openTrans(self, event=None):
   ind = 0
   self.rowlist=[]
   file = askopenfile(title="Open Transcript File", filetypes=(("text 
files", "*.txt"),("All files", "*")))
   try:
      filetoread = open(file.name, 'r')
   except:
      print "file open error"
      pass
   try:
      filecontents = filetoread.readlines()
      filetoread.close()
      for x in filecontents:
             rowcontents = x.split("\t")
             self.rowlist.append(TranscriptionCell(self.inner, 
row=self.row))
             try:
                self.rowlist[ind].TTime.settext(rowcontents[0])
             except:
                 pass
             try:
                self.rowlist[ind].TSpeak.settext(rowcontents[1])
             except:
                 pass
             try:
                 
self.rowlist[ind].TTrans.textBox.settext(rowcontents[2])
             except:
                 pass
             try:
                 self.rowlist[ind].Comments.settext(rowcontents[3])
             except:
                 pass
             self.row = self.row + 1
             ind = ind + 1
   except:
      pass





From paulsid@shaw.ca  Fri Jun 14 22:34:52 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Fri, 14 Jun 2002 15:34:52 -0600
Subject: [Tutor] Question about sprites
References: <OIPJAPOJDPGEPAAA@mailcity.com>
Message-ID: <3D0A617C.75B9420@shaw.ca>

James M Lang wrote:

> I heard from a friend that in the videogame world that sprites are 
> programmed by telling the computer or videogame console where each 
> pixel or dot was. That sounds kinda tedious. Couldn't you just load 
> a picture? Is that possible?

I think perhaps some of the details might have got lost somewhere in the
description.  Sprites generally do indeed work by drawing a picture as
you suggested.

For simple games you just keep one coordinate in memory and draw the
entire picture at that point.  This coordinate is called the "hotspot". 
Regardless of whether the picture is a giant space ship or a tiny
projectile, you only need one coordinate for it.  The hotspot can be put
anywhere within the picture.  Popular choices are the top left (because
it's the easiest to manage) and the centre (because you can do simple
radius-based collision detection).

Fancier systems might define the hotspot differently for each sprite or
might have multiple hotspots for each sprite to allow for fancier
collision algorithms.  For example you might make each pixel on the edge
of the sprite (e.g. the spaceship) a hotspot; this would perfectly
define the boundary of the ship so your collisions would be very
accurate.  Of course this does take more computing power and does get
more tedious as you suggested.

If you're interested in doing stuff with sprites in Python, pygame now
comes with a really cool sprite module which will manage lots of things
for you.  The sprite module is written in Python itself so you can see
how it manages everything too - check sprite.py in your site-packages
directory.

BTW I'm not in the videogame industry by any means, I'm just a hobbyist
game programmer.  "Real game programmers" probably do things much more
sophisticatedly, especially nowadays.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From ponderor@lycos.com  Fri Jun 14 22:41:54 2002
From: ponderor@lycos.com (Dean Goodmanson)
Date: Fri, 14 Jun 2002 14:41:54 -0700
Subject: [Tutor] Python based blog software
Message-ID: <INHPAADCHINHGDAA@mailcity.com>

Are you looking to figure out the code or use a Python friendly blogger? 

Check out the latest source for PythonCard for Blog Client code samples.

There a few solutions for Python friendly blogger's from Python frienldy Zope. Closest to Slashcode is "Squishdot" at www.squishdot.org .  I'd suggest trying it out through a www.freezope.org account.  It's very customizable, here are a few implementations from My use as a blog : http://nomad.freezope.org/weblog  , to elegantly simple: ZopeNewbies: http://www.zopenewbies.net , or with consistent icons: http://www.pault.com/X and finally as a heavily used news/discussion site: http://dot.kde.org/
The source is primarily Zope related, so probably not the best arena for a Python newbie.

For a Blog Server in Python I believe there's an interesting project here: http://community.scriptmeridian.org/16433

Best Regards,

Dean




_______________________________________________________
WIN a first class trip to Hawaii.  Live like the King of Rock and Roll
on the big Island. Enter Now!
http://r.lycos.com/r/sagel_mail/http://www.elvis.lycos.com/sweepstakes



From urnerk@qwest.net  Sat Jun 15 00:41:14 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 14 Jun 2002 16:41:14 -0700
Subject: [Tutor] Python-based Blog Software?
Message-ID: <5.1.1.6.0.20020614164102.01fe6610@pop3.norton.antivirus>

At 07:21 AM 6/14/2002 -0700, Britt Green wrote:
 >Anyone know if there's any Python-based weblog software, similiar
 >perhaps to Slashcode or Scoop? Google isn't returning anything....
 >
 >Britt
 >

This might best come under the Zope category.  Most efforts
Pythonic are focussed on customizing this versatile flagship
web application server from Digital Creations (free to
download, many paid consultants to make it do whatever;
CMF design big these days).

Kirby 




From mico@cbn.net.id  Sat Jun 15 02:05:31 2002
From: mico@cbn.net.id (Mico Siahaan)
Date: Sat, 15 Jun 2002 08:05:31 +0700
Subject: [Tutor] Making Python modules with C
Message-ID: <5.1.0.14.0.20020615075405.00ad3010@pop.cbn.net.id>

I tried to make Python dynamic modules with C (pyd files). I followed the 
'Extending and Embedding the Python Interpreter' tutorial from ActiveState 
Python documentation, but failed. I guess the tutorial written for Linux 
user or Microsoft Visual C++ (as it mentioned in Chapter 4 of the 
Tutorial). The problem is: in my Window machine I don't have Visual C++ (I 
don't have money to buy it :( ). I only have lcc-win32 compiler. So, 
anybody ever used lcc-win32 compiler to build Python modules.


Mico Siahaan
---
E-mail  : mico at cbn dot net dot id






From mico@cbn.net.id  Sat Jun 15 01:53:59 2002
From: mico@cbn.net.id (Mico Siahaan)
Date: Sat, 15 Jun 2002 07:53:59 +0700
Subject: [Tutor] Convert man file into readable text file
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C658@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20020615075133.00acf200@pop.cbn.net.id>

At 12:22 PM 6/14/2002 +0100, alan.gauld@bt.com wrote:
> > I'm a newbie. I want to make a python script to convert a man
> > file into a readable text file
>
>As an excercise fine but you could just do:
>
>nroff -man foo.man > foo.txt
>
>Its easier, faster and probably more useful since it will
>create the paragraphs and headings etc correctly....
>
>Alan G.

Thanks. Actually I'm using Windows. I copied a man file into my Windows 
machine then tried to read that man file.
So, I guess I should process the file first with nroff before copy it into 
my Windows machine. :)


Mico Siahaan
---
E-mail  : mico at cbn dot net dot id





From dyoo@hkn.eecs.berkeley.edu  Sat Jun 15 07:23:10 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 14 Jun 2002 23:23:10 -0700 (PDT)
Subject: [Tutor] Making Python modules with C
In-Reply-To: <5.1.0.14.0.20020615075405.00ad3010@pop.cbn.net.id>
Message-ID: <Pine.LNX.4.44.0206142314170.19291-100000@hkn.eecs.berkeley.edu>

On Sat, 15 Jun 2002, Mico Siahaan wrote:

> I followed the 'Extending and Embedding the Python Interpreter' tutorial
> from ActiveState Python documentation, but failed. I guess the tutorial
> written for Linux user or Microsoft Visual C++ (as it mentioned in
> Chapter 4 of the Tutorial). The problem is: in my Window machine I don't
> have Visual C++ (I don't have money to buy it :( ). I only have
> lcc-win32 compiler. So, anybody ever used lcc-win32 compiler to build
> Python modules.

Hi Mico,

Yikes, this sounds like a really specialized question.  You might want to
ask your question on the 'comp.lang.python' newsgroup; there are a few
compiler gurus there who can probably help you with lcc.


I did a quick scan through the Python README file, and there's a chance
that cygwin will work for you.  Cygwin is a port of the GCC tools to
Windows, and you can find out more information here:

    http://sources.redhat.com/cygwin/


Ah!  Take a look at the "How to Debug Python Extensions on Windows with
Open Source Tools" HOWTO:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82826


Looks like there's no need to go for Visual C++ after all.  *grin* Anyway,
hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Sat Jun 15 07:53:18 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 14 Jun 2002 23:53:18 -0700 (PDT)
Subject: [Tutor] Runtime Errors
In-Reply-To: <1024089536.smmsdV1.1.1@mail.arches.uga.edu>
Message-ID: <Pine.LNX.4.44.0206142328030.19363-100000@hkn.eecs.berkeley.edu>


On Fri, 14 Jun 2002 shendric@arches.uga.edu wrote:

> I've got a script I'm working on that is a kind of spreadsheet.  There
> are a fixed number of 4 cells in each row, but the idea would be to have
> as many rows as one wishes.  The algorithm for the spreadsheet works
> fine, but I get a RuntimeError when I try to load a tab-delimited text
> file into the cells.
>
> The loading algorithm is this:
>
> 1. Open a text file
> 2. Read the lines of the text file into a list (readlines())
> 3. Take each line and do the following:
>     a. create an instance of the TranscriptionCell class, which is a
> class that includes four Tkinter Pmw.ScrolledText widgets
>     b. append that instance to a list
>     c. put the contents of the first part of the line into the first
> text widget, then the second into the second, etc.
> 4.  close the file

Sounds reasonable enough.  Yes, this should work.

>
> I get the following error:
> RuntimeError: maximum recursion depth exceeded


Hmmm... does the error message also give a clue in which function, and
around which line it goes bonkers?


> Now, I've gotten it to go just fine with only a few rows, but not if
> there are a lot of them.


We'll have to look through the code to see where the recursion's coming
from.  Reading... hmmm...  It might not be such a good idea to wrap every
statement with exception handling like:

###
             try:
                self.rowlist[ind].TTime.settext(rowcontents[0])
             except:
                 pass
             try:
                self.rowlist[ind].TSpeak.settext(rowcontents[1])
             except:
                 pass
###

Doing just a 'pass' when an exception occurs is like an ostrich that puts
its head in the sand:  We're ignoring any potentially bad problems!  If
the first row setting fails, it's probable that the whole rowcontents list
has some weirdness that should be reported to the user.



To make this function easier to debug, we can strip out some of the
exception handling code, and put a traceback.print_exc() call in the code:

###
def openTrans(self, event=None):
   file = askopenfile(title="Open Transcript File",
                      filetypes=(("text files", "*.txt"),
                                 ("All files", "*")))
   filetoread = open(file.name, 'r')
   filecontents = filetoread.readlines()
   filetoread.close()
   ind = 0
   self.rowlist=[]
   for x in filecontents:
       rowcontents = x.split("\t")
       self.rowlist.append(TranscriptionCell(self.inner,
                                             row=self.row))
       try:
           self.rowlist[ind].TTime.settext(rowcontents[0])
           self.rowlist[ind].TSpeak.settext(rowcontents[1])
           self.rowlist[ind].TTrans.textBox.settext(rowcontents[2])
           self.rowlist[ind].Comments.settext(rowcontents[3])
       except:
           traceback.print_exc()
       self.row = self.row + 1
       ind = ind + 1
###


The traceback.print_exc() should tell us if there's something else that's
going weird.  Hmmm.... but I don't see any obvious recursion here.  Can
you show the last few previous lines of the error message as well?  It'll
help us to find where exactly the recursion is occuring.


Sounds like a tricky bug, but don't worry, we're bound to squish it.
*grin* Talk to you later!




From dyoo@hkn.eecs.berkeley.edu  Sat Jun 15 07:56:36 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 14 Jun 2002 23:56:36 -0700 (PDT)
Subject: [Tutor] More Tkinter Help Please
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C660@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.44.0206142353540.19363-100000@hkn.eecs.berkeley.edu>


On Fri, 14 Jun 2002 alan.gauld@bt.com wrote:

> > class PyShell:
> >     def __init__(self, top):
> >         self.b1 = Button(f, text="Execute", command=self.expyth)
> >         self.b1.pack(side=LEFT)
> >
> >     def expyth(self):
> >         output = os.popen("python -c").t1()
> >         self.t2.delete(0,END)
> >         sys.stdout.write.t2(output)
>
> > When I run this I get the following error:
> >
> > Traceback (most recent call last): AttributeError: PyShell instance
> > has no attribute 'expyth'
>
> I think its because at the time that init is defined it can't see
> self.expyth because its not been defined yet.  Try moving the init
> method after all the other methods?
>
>
> However I'm not really happy with that answer because init shouldn't run
> till you create an instance which is after you define the class, so I
> could very well be wrong!


Hi SA,

Following up: did you find out what was causing this weird AttributeError?
I'm just curious to know.  *grin*


Talk to you later!




From alex@gabuzomeu.net  Sat Jun 15 12:26:30 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sat, 15 Jun 2002 13:26:30 +0200
Subject: [Tutor] Python-based Blog Software?
In-Reply-To: <20020614160004.23404.72623.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020615132349.00b23f00@pop3.norton.antivirus>

Hi Britt,


At 12:00 14/06/2002 -0400, tutor-request@python.org wrote:
>Date: Fri, 14 Jun 2002 07:21:59 -0700 (PDT)
>From: Britt Green <cheshire_cat_sf@yahoo.com>
>Subject: [Tutor] Python-based Blog Software?
>
>Anyone know if there's any Python-based weblog software, similiar
>perhaps to Slashcode or Scoop? Google isn't returning anything....

Take a look at pyBlog. "A blogging framework coded entirely in 
Python.  Highly customizable.  Both user and developer documentation are 
included in the file.  Just unpack in the directory where you want pyBlog 
to be kept."

http://www.ocf.berkeley.edu/~bac/Askewed_Thoughts/HTML/code/python.php3

>"The ocean, she is strange and wonderous, filled with animals that disturb 
>even a Frenchman."

Nope. We eat them. Bwa ha ha!


Alex




From dman@dman.ddts.net  Sat Jun 15 14:46:55 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 15 Jun 2002 08:46:55 -0500
Subject: [Tutor] Re: Convert man file into readable text file
In-Reply-To: <5.1.0.14.0.20020615075133.00acf200@pop.cbn.net.id>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C658@mbtlipnt02.btlabs.bt.co.uk> <5.1.0.14.0.20020615075133.00acf200@pop.cbn.net.id>
Message-ID: <20020615134655.GA16490@dman.ddts.net>

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

On Sat, Jun 15, 2002 at 07:53:59AM +0700, Mico Siahaan wrote:
| At 12:22 PM 6/14/2002 +0100, alan.gauld@bt.com wrote:
| >> I'm a newbie. I want to make a python script to convert a man
| >> file into a readable text file
| >
| >As an excercise fine but you could just do:
| >
| >nroff -man foo.man > foo.txt
| >
| >Its easier, faster and probably more useful since it will
| >create the paragraphs and headings etc correctly....
|
| Thanks. Actually I'm using Windows. I copied a man file into my Windows=
=20
| machine then tried to read that man file.
| So, I guess I should process the file first with nroff before copy it int=
o=20
| my Windows machine. :)

Install cygwin.  When you do, you'll get 'man', 'groff', 'sed', 'awk',
'vim', and all the other nice tools that are so essential to the
usability of any system.

-D

--=20

Do not be afraid of those who kill the body but cannot kill the soul.
Rather be afraid of the One who can destroy both soul and body in hell.
        Matthew 10:28
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0LRU4ACgkQO8l8XBKTpRTPUQCdEzuZ1/3Y7R76U2GxN7JC+yKL
hKkAnA3+Nze/agF2IGFQgPERZkTlOj3I
=lZvD
-----END PGP SIGNATURE-----

--UlVJffcvxoiEqYs2--



From mico@cbn.net.id  Sat Jun 15 09:55:25 2002
From: mico@cbn.net.id (Mico Siahaan)
Date: Sat, 15 Jun 2002 15:55:25 +0700
Subject: [Tutor] Making Python modules with C
In-Reply-To: <Pine.LNX.4.44.0206142314170.19291-100000@hkn.eecs.berkeley
 .edu>
References: <5.1.0.14.0.20020615075405.00ad3010@pop.cbn.net.id>
Message-ID: <5.1.0.14.0.20020615155207.00aded40@pop.cbn.net.id>

At 11:23 PM 6/14/2002 -0700, you wrote:

Thanks.

> > I followed the 'Extending and Embedding the Python Interpreter' tutorial
> > from ActiveState Python documentation, but failed. I guess the tutorial
> > written for Linux user or Microsoft Visual C++ (as it mentioned in
> > Chapter 4 of the Tutorial). The problem is: in my Window machine I don't
> > have Visual C++ (I don't have money to buy it :( ). I only have
> > lcc-win32 compiler. So, anybody ever used lcc-win32 compiler to build
> > Python modules.
>
>Hi Mico,
>
>Yikes, this sounds like a really specialized question.  You might want to
>ask your question on the 'comp.lang.python' newsgroup; there are a few
>compiler gurus there who can probably help you with lcc.

OK, I'll try it.



>I did a quick scan through the Python README file, and there's a chance
>that cygwin will work for you.  Cygwin is a port of the GCC tools to
>Windows, and you can find out more information here:
>
>     http://sources.redhat.com/cygwin/

I used gcc (cygwin) and got this error message:

In file included from include/Python.h:54, from spammodule.c:1:
include/pyport.h:422: #error "LONG_BIT definition appears wrong for 
platform (ba
d gcc/glibc config?)."

What does it mean? Ang how to solve it?


Mico Siahaan
---
E-mail  : mico at cbn dot net dot id





From dman@dman.ddts.net  Sat Jun 15 23:51:26 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 15 Jun 2002 17:51:26 -0500
Subject: [Tutor] Re: Making Python modules with C
In-Reply-To: <5.1.0.14.0.20020615155207.00aded40@pop.cbn.net.id>
References: <5.1.0.14.0.20020615075405.00ad3010@pop.cbn.net.id> <5.1.0.14.0.20020615155207.00aded40@pop.cbn.net.id>
Message-ID: <20020615225126.GA21248@dman.ddts.net>

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

On Sat, Jun 15, 2002 at 03:55:25PM +0700, Mico Siahaan wrote:
| At 11:23 PM 6/14/2002 -0700, you wrote:
=20
| >I did a quick scan through the Python README file, and there's a chance
| >that cygwin will work for you.  Cygwin is a port of the GCC tools to
| >Windows, and you can find out more information here:
| >
| >    http://sources.redhat.com/cygwin/
|=20
| I used gcc (cygwin) and got this error message:
|=20
| In file included from include/Python.h:54, from spammodule.c:1:
| include/pyport.h:422: #error "LONG_BIT definition appears wrong for=20
| platform (ba
| d gcc/glibc config?)."
|=20
| What does it mean? Ang how to solve it?

Last time I saw that error message, it was on a RH 7.0 machine and it
was caused by a buggy libc.

Here's the code that is causing that :

#if LONG_BIT !=3D 8 * SIZEOF_LONG
/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
 * 32-bit platforms using gcc.  We try to catch that here at compile-time
 * rather than waiting for integer multiplication to trigger bogus
 * overflows.
 */
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc confi=
g?)."
#endif


Python's build system is built to figure out what the limits of the
basic C data types are on your platform (because C isn't very precise
about it).  Python needs that information so it can properly detect
and handle overflows and stuff like that.

I have an x86 system (ia32), so for me the relvant sizes are :

    LONG_MAX    2147483647=20
    LONG_BIT    32=20
    SIZEOF_LONG 4=20

That RH 7.0 box I mentioned had LONG_BIT set to 64, which is why
python barfed ( 4*64 !=3D 2147483647 ).

The best solution is to get a fixed libc, but on that RH box I simply
modified /usr/include/bits/xopen_lim.h to set LONG_BIt to the correct
value. =20

HTH,
-D

--=20

Better a little with righteousness
than much gain with injustice.
        Proverbs 16:8
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0LxO4ACgkQO8l8XBKTpRTVnwCgm1/DysGxBmnP1TpJHJqrCIim
GtAAoJAl8T8Id8zbvoQbWeY3BppGuUWH
=sofc
-----END PGP SIGNATURE-----

--VbJkn9YxBvnuCH5J--



From sarmstrong13@mac.com  Sun Jun 16 02:57:03 2002
From: sarmstrong13@mac.com (SA)
Date: Sat, 15 Jun 2002 20:57:03 -0500
Subject: [Tutor] More Tkinter Help Please
In-Reply-To: <Pine.LNX.4.44.0206142353540.19363-100000@hkn.eecs.berkeley.edu>
Message-ID: <B9315A9F.71D5%sarmstrong13@mac.com>

On 6/15/02 1:56 AM, "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu> wrote:

> 
> 
> On Fri, 14 Jun 2002 alan.gauld@bt.com wrote:
> 
>>> class PyShell:
>>>     def __init__(self, top):
>>>         self.b1 = Button(f, text="Execute", command=self.expyth)
>>>         self.b1.pack(side=LEFT)
>>> 
>>>     def expyth(self):
>>>         output = os.popen("python -c").t1()
>>>         self.t2.delete(0,END)
>>>         sys.stdout.write.t2(output)
>> 
>>> When I run this I get the following error:
>>> 
>>> Traceback (most recent call last): AttributeError: PyShell instance
>>> has no attribute 'expyth'
>> 
>> I think its because at the time that init is defined it can't see
>> self.expyth because its not been defined yet.  Try moving the init
>> method after all the other methods?
>> 
>> 
>> However I'm not really happy with that answer because init shouldn't run
>> till you create an instance which is after you define the class, so I
>> could very well be wrong!
> 
> 
> Hi SA,
> 
> Following up: did you find out what was causing this weird AttributeError?
> I'm just curious to know.  *grin*
> 
> 
> Talk to you later!
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Sorry. I've been busy and have not had a chance to reply yet.

Yes I was able to figure the issue. It had to do with cut and pasting
between a vi file and a bbedit file. I messed up my tabs. I rewrote the
whole program with the correct tabs and everything runs now.(with a few
other changes.)

I'm now working on the "save" button and am having a bit of trouble. I think
it stems from my lack of OO understanding. Here is what I have so far:

from Tkinter import *
import os
import commands
import tkSimpleDialog

class PyShell:
    def clearin(self):
        self.t1.delete(0.0,END)
    def clearout(self):
        self.t2.delete(0.0,END)
    def expyth(self):
        self.t2.delete(0.0, END)
        self.output = commands.getoutput(self.t1.get(0.0, END))
        self.t2.insert(END, self.output)
    def __init__(self, top):
        self.t1 = Text(top, height="12", width="84", font="Courier 12")
        self.t1.pack(side=TOP, pady=2)
        f = Frame(top)
        f.pack()
        self.b1 = Button(f, text="Execute", command=self.expyth)
        self.b1.pack(side=LEFT)
        self.b2 = Button(f, text="Clear Input", command=self.clearin)
        self.b2.pack(side=LEFT)
        self.b3 = Button(f, text="Clear Output", command=self.clearout)
        self.b3.pack(side=LEFT)
        self.b4 = Button(f, text="Save Input", command=Saving)
        self.b4.pack(side=LEFT)
        self.t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
        self.t2.pack(side=TOP, pady=2)
        
class Saving(tkSimpleDialog.Dialog):
        def savin(self, question):
            Label(question, text="Directory:").grid(row=0)
            Label(question, text="Filename:").grid(row=1)
            self.e1 = Entry(question)
            self.e2 = Entry(question)
            self.e1.grid(row=0, column=1)
            self.e2.grid(row=1, column=1)
        def apply(self):
            dir = self.e1.get()
            fn = self.e2.get()
            sav = dir + fn
            savfile = open(sav, "w")
            for line in self.t1.readlines():
                savefile.write(line)
            osavefile.close()
            
root = Tk()
app = PyShell(root)
root.mainloop()

I think the problem is with:
class Saving(tkSimpleDialog.Dialog):

Since this is not a child of the PyShell class and therefore is not
inheriting? from this class? I think if I make PyShell inherit from
tkSimpleDialog.Dialog and Saving inherit from PyShell, this might work? What
do you think?

Thanks.
SA




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 16 19:33:43 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 16 Jun 2002 11:33:43 -0700 (PDT)
Subject: [Tutor] More Tkinter Help Please  [callbacks and embedded
 functions]
In-Reply-To: <B9315A9F.71D5%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206161105580.17853-100000@hkn.eecs.berkeley.edu>


> I'm now working on the "save" button and am having a bit of trouble. I
> think it stems from my lack of OO understanding. Here is what I have so
> far:
>
[code cut]
>
> I think the problem is with:
> class Saving(tkSimpleDialog.Dialog):
>
> Since this is not a child of the PyShell class and therefore is not
> inheriting? from this class? I think if I make PyShell inherit from
> tkSimpleDialog.Dialog and Saving inherit from PyShell, this might work?
> What do you think?

I'm not too familiar with tkSimpleDialog.Dialog, so I'm not quite sure if
there's a problem with inheritance.  Can you explain more what problems
you're running into with this code?


Ah!  I think that for this statement:

        self.b4 = Button(f, text="Save Input", command=Saving)


if 'tkSimpleDialog' is the tkSimpleDialog that's in the 'Introduction To
Tkinter' tutorial:

http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm


then we need to do a little extra: the dialog box needs to know its parent
window when it's being constructed!  Let's take a look at the definition
of tkSimpleDialog.Dialog again:


### Sample of tkSimpleDialog.py
# File: tkSimpleDialog.py

from Tkinter import *
import os

class Dialog(Toplevel):

    def __init__(self, parent, title = None):
###


So when we create a Dialog box, this dialog box must take in an additional
'parent' parameter.  However, back in your code:

        self.b4 = Button(f, text="Save Input", command=Saving)

When the fourth button is pressed, it tries to call the Saving dialog
constructor with no parameters: this may be the problem that you're
running into.  We'd like to be able to do something like:

        self.b4 = Button(f, text="Save Input", command=Saving(f))

since 'f' is the frame parent that we'd like to attach the Dialog to...
but the problem with this is that Python will actually call Saving(f). It
calls it too soon, because, to Python,

    Saving(f)

is a function call, so it just evaluates it straightaway.  We need a way
to create a callback function that knows about 'f', enough so that it can
do a 'Saving(f)' when our button is pressed.  What to do?





The solution actually isn't too bad:

###
        def saving_callback(): Saving(f)
        self.b4 = Button(f, text="Save Input", command=saving_callback)
###

That is, we can actually embed a small function called 'saving_callback',
and we can pass that off to as the button callback.  The miniature
function has access to all the local variables of its parent, which is why
saving_callback() can say 'f' without problems.


Functions within functions will be weird if you haven't seen it before, so
here's another example to demonstrate the idea:

###
>>> def suffixAppenderMaker(suffix):
...     def appender(word):
...         return word + '-' + suffix
...     return appender
...
>>> ed_maker = suffixAppenderMaker('ed')
>>> ed_maker('walk')
'walk-ed'
>>> ed_maker('dance')
'dance-ed'
>>> ed_maker('wick')
'wick-ed'
###


Please feel free to ask more questions on this.  (I'm getting over a cold,
so most of this may just be incoherant.  *grin*)




From mista2kool@yahoo.com  Sun Jun 16 19:39:36 2002
From: mista2kool@yahoo.com (mista kool)
Date: Sun, 16 Jun 2002 11:39:36 -0700 (PDT)
Subject: [Tutor] cdrw wroting
Message-ID: <20020616183936.13927.qmail@web21503.mail.yahoo.com>

how do you write your programs to cdr 

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Sun Jun 16 20:47:11 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 16 Jun 2002 12:47:11 -0700 (PDT)
Subject: [Tutor] cdrw wroting
In-Reply-To: <20020616183936.13927.qmail@web21503.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206161241110.19601-100000@hkn.eecs.berkeley.edu>


On Sun, 16 Jun 2002, mista kool wrote:

> how do you write your programs to cdr

Hi Mista,


Your question isn't really related to Python or programming, so we
probably aren't the best people to ask about this.  You may get better
help about CDR stuff by visiting:

    http://www.cdrfaq.org/

That page has a lot of information about recording CDR's, and may help you
find the information you're looking for.  Good luck to you!




From alan.gauld@bt.com  Sun Jun 16 22:43:45 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 16 Jun 2002 22:43:45 +0100
Subject: [Tutor] More Tkinter Help Please
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C661@mbtlipnt02.btlabs.bt.co.uk>

> Yes I was able to figure the issue. It had to do with cut and pasting
> between a vi file and a bbedit file. I messed up my tabs. 

Interesting. That usually gives rise to a more explicit error 
about indenting. Howwever so ong as yuou fixed it... :-)

> I'm now working on the "save" button and am having a bit of 
> trouble. 

> Here is what I have so far:
> class PyShell:
>     def clearin(self):
>         self.t1.delete(0.0,END)
>     def expyth(self):
>         self.t2.delete(0.0, END)
>         self.output = commands.getoutput(self.t1.get(0.0, END))
>         self.t2.insert(END, self.output)

Just a wee point but as your GUIs get bigger this styule of t1,t2 etc will
get really hard to maintain. Its much better to name the control variables
aftyer their function, thus the above might become:

     def clearin(self):
         self.tInput.delete(0.0,END)
     def expyth(self):
         self.tOutput.delete(0.0, END)
         self.output = commands.getoutput(self.tInput.get(0.0, END))
         self.tOutput.insert(END, self.output)

This makes it clearer whats happening while keeping the first letter 
prefix to indicate what kind of widget is involved.


>     def __init__(self, top):
>         ....
>         self.b1 = Button(f, text="Execute", command=self.expyth)
similarly:
          self.bExec = Button(....

etc.


> class Saving(tkSimpleDialog.Dialog):
>         def savin(self, question):
>             Label(question, text="Directory:").grid(row=0)
>             Label(question, text="Filename:").grid(row=1)
>             self.e1 = Entry(question)
>             self.e2 = Entry(question)

and here:
              self.eDir = Entry(...
              self.eFile = Entry(...

makes it easier later to remember which Entry you want to read/modify.

> I think the problem is with:
> class Saving(tkSimpleDialog.Dialog):
> 
> Since this is not a child of the PyShell class and therefore is not
> inheriting from this class? 

Inheriting means that your class is the "same kind of thing" that the 
parent is. PyShell is an Application not a Dialog. If your Saving 
class is a type of Dialog (which I assume it is) then you are 
inheriting correctly.

But your Saving class has no init method so the widgets etc are 
not created etc. The 'savin' method would need to be called from 
somewhere but isn't. (Danny has also discussed the need to pass 
in a parent when you call the constructor). Without an init the 
class will be constructed using the inherited init from tkSimpleDialog
but it doesn't know about your savin method...

At least I think that's the problem, I've never actually used 
tkSimpleDialog in anger but thats how I remembwer it working!

Alan g



From alan.gauld@bt.com  Sun Jun 16 22:50:27 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 16 Jun 2002 22:50:27 +0100
Subject: [Tutor] Python based blog software
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C662@mbtlipnt02.btlabs.bt.co.uk>

OK, I bite.

What the heck is a blog?!
This one obviously slipped by me somewhere....

Alan G



From alan.gauld@bt.com  Sun Jun 16 22:54:16 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 16 Jun 2002 22:54:16 +0100
Subject: [Tutor] Convert man file into readable text file
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C663@mbtlipnt02.btlabs.bt.co.uk>

> >nroff -man foo.man > foo.txt

> Thanks. Actually I'm using Windows. I copied a man file into 
> my Windows machine then tried to read that man file.

Well you could get a copy of GNU groff I guess but thats 
probably overkill :-)

OTOH You could install Cygwin (which every Windows user should have) 
which has man and groff etc available...

> So, I guess I should process the file first with nroff before 
> copy it into  my Windows machine. :)

Yeah, that would work too I suppose ;-)

Alan g



From ak@silmarill.org  Mon Jun 17 01:27:07 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sun, 16 Jun 2002 20:27:07 -0400
Subject: [Tutor] Python based blog software
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C662@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C662@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020617002707.GA808@ak.silmarill.org>

On Sun, Jun 16, 2002 at 10:50:27PM +0100, alan.gauld@bt.com wrote:
> OK, I bite.
> 
> What the heck is a blog?!
> This one obviously slipped by me somewhere....
> 
> Alan G

Something like slashdot or kuro5hin.org. A web discussion site..

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

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From sarmstrong13@mac.com  Mon Jun 17 04:25:57 2002
From: sarmstrong13@mac.com (SA)
Date: Sun, 16 Jun 2002 22:25:57 -0500
Subject: [Tutor] More Tkinter Help Please  [callbacks and embedded
 functions]
In-Reply-To: <Pine.LNX.4.44.0206161105580.17853-100000@hkn.eecs.berkeley.edu>
Message-ID: <B932C0F5.72DA%sarmstrong13@mac.com>

Ok.

So I guess my question is, if I have a program that has  these two calsses,
how do I call the second class(which would be a popup dialog box for saving
the test in e1 to a file) from a button that is defined and packed in the
first class?

Basically I have two text fields and four buttons. One button executes
whatever code is typed in the first text field and displays the out put in
the second text field. The next two buttons clear one of the text fields.
And the fourth button should popup a new dialog that has two entry fields.
When the Save button is pushed in the dialog box, the the second class will
take the entries from the dialog box as the absolute path to the save file
and save the text from the first text field in the first class to the user
designated savefile.

As for the naming conventions used in the book, I realize they are not very
readable. That is because they are carryovers from a Tcl/Tk program. When I
get everything working properly, I plan on changing them to more readable
terms.

Thanks.
SA




From purplebo@babylonia.flatirons.org  Mon Jun 17 05:15:19 2002
From: purplebo@babylonia.flatirons.org (Chris Avery)
Date: Sun, 16 Jun 2002 22:15:19 -0600
Subject: [Tutor] Files and Dictionaries
Message-ID: <20020616221519.A22437@babylonia.flatirons.org>

Hi all!
I was wondering if it were possible to write a dictionary to a user's home directory so that it could be called later.  For instance, I have a dictionary full of meat and wine that compliments that meat, I want to save a copy of all the meat and wine in the dictionary so I can append to it when I run the program again.

Hope that made sense.
-C
-- 
+++++++++++++++++++
Chris Avery, KC0KTH
+++++++++++++++++++



From ak@silmarill.org  Mon Jun 17 05:35:17 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Mon, 17 Jun 2002 00:35:17 -0400
Subject: [Tutor] Files and Dictionaries
In-Reply-To: <20020616221519.A22437@babylonia.flatirons.org>
References: <20020616221519.A22437@babylonia.flatirons.org>
Message-ID: <20020617043517.GA3301@ak.silmarill.org>

On Sun, Jun 16, 2002 at 10:15:19PM -0600, Chris Avery wrote:
> Hi all!
> I was wondering if it were possible to write a dictionary to a user's home directory so that it could be called later.  For instance, I have a dictionary full of meat and wine that compliments that meat, I want to save a copy of all the meat and wine in the dictionary so I can append to it when I run the program again.
> 
> Hope that made sense.

Sure, that's done by shelve module. If I remember right, here's how
you can use it:

sh = shelve.open("test.dict")  # that'll be the name of the file
sh["test"] = 2
sh.close()

# next time program is started
sh = shelve.open("test.dict")
print sh["test"]
> -C
> -- 
> +++++++++++++++++++
> Chris Avery, KC0KTH
> +++++++++++++++++++
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From ponderor@lycos.com  Mon Jun 17 05:59:36 2002
From: ponderor@lycos.com (Dean Goodmanson)
Date: Sun, 16 Jun 2002 21:59:36 -0700
Subject: [Tutor] Python based blog software
Message-ID: <OFBDHJOLHCOJABAA@mailcity.com>

>What the heck is a blog?!

Arg! I've carelessy used of jargon in this venue.

"blog" is short/jargon for a Web Logging system. weBLOGing. 

WhatIs.com Definition:
http://whatis.techtarget.com/definition/0,,sid9_gci213547,00.html
 
Here are some articles on the wonders of weblogging:
(in no particular order)
"Essential Blogging Public Review":
http://www.oreillynet.com/pub/wlg/1460

Others:
http://www.oreillynet.com/pub/a/javascript/2002/01/01/cory.html
http://www.oreillynet.com/pub/a/javascript/2002/06/13/megnut.html
http://www.oreillynet.com/pub/wlg/1460

On a personal note, Thanks for "Learn to Program Using Python". I didn't purchase it to learn programming, but to learn Python. The book (and language) appealed to my profesional ideals and I've been enjoying the wide world of Python for the last year or so. You're praise for "The Pragmatic Programmer" is my best example of this.
 
Best Regards,

Dean



_______________________________________________________
WIN a first class trip to Hawaii.  Live like the King of Rock and Roll
on the big Island. Enter Now!
http://r.lycos.com/r/sagel_mail/http://www.elvis.lycos.com/sweepstakes



From dyoo@hkn.eecs.berkeley.edu  Mon Jun 17 07:43:39 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 16 Jun 2002 23:43:39 -0700 (PDT)
Subject: [Tutor] cdrw writing
In-Reply-To: <20020617032942.73810.qmail@web21505.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206162336500.30297-100000@hkn.eecs.berkeley.edu>


> > Your question isn't really related to Python or programming, so we
> > probably aren't the best people to ask about this.  You may get better
> > help about CDR stuff by visiting:
> >
> >     http://www.cdrfaq.org/
> >
> > That page has a lot of information about recording CDR's, and may help
> > you find the information you're looking for.  Good luck to you!
>
> how do you write a python pro. to a cdr

I'm still not quite sure I understand: a Python program is just a text
file, so just saving the source file to a CDR should be enough to save it
permanently.

I'm very sure that I'm misinterpreting your question, so I have to ask for
clarification.  What do you plan to do after you write your program to
CDR?  Do you plan to share your programs with others afterwards?  Do you
want to make it run automatically if it's inserted into a Windows
computer?

Again, my apologies for my confusion!  Please make sure to send your
replies to 'tutor@python.org', and not just to me, so that the others can
bail me out when I make mistakes.




From alan.gauld@bt.com  Mon Jun 17 12:00:33 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 17 Jun 2002 12:00:33 +0100
Subject: [Tutor] More Tkinter Help Please
 [callbacks and embedded func tions]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C666@mbtlipnt02.btlabs.bt.co.uk>

> So I guess my question is, if I have a program that has  
> these two calsses, how do I call the second class
> from a button that is defined and packed in the
> first class?

Thats easy. The first class can see the second class definition.
Therefore you can use the solution Danny shopwed you, namely 
create an event handler that instantiates the second class, 
passing parameters to the constructor as required.

> When the Save button is pushed in the dialog box, the the 
> second class will take the entries from the dialog box as 
> the absolute path to the save file and save the text from 
> the first text field in the first class 

You could do this by passing the text as a parameter to the 
Saver class in the constructor. However the conventional 
way to do this (as in How MS Word, IDLE etc do it) is to 
use the SaveAs dialog to obtain and test for validity the 
path/filename then make that available to the parent class
to actually save the data(since that PyShell class owns the 
data - it is responsible. The responsibility of the dialog 
is to find out *where* to save it)

This the Save method looks something like this:

def Save(self):
   SaveDialog = Saver(self)
   filepath = SaveDialog.path 
   f = open(filepath,'w')
   f.write(tOutput)
   f.close

Usually there is a way to call the SaveAs dialog modally such that 
it treturns a boolean result indicating whether a valid filename 
has been created. Check the tkSimpleDialog docs to see if such exists.

However I seem to recall that Tk has a standard SaveAs type dialog 
already built that mimics the platform(Windows or Unix) SaveAs dialog
so maybe you could use it.

HTH,

Alan G



From shendric@arches.uga.edu  Mon Jun 17 16:36:57 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Mon, 17 Jun 2002 10:36:57 -0500
Subject: [Tutor] Runtime Errors
Message-ID: <1024324617.smmsdV1.1.1@mail.arches.uga.edu>

Hi, 

Thanks for the response.  Sorry to just be replying.  Been out of email 
range for the weekend.  Anyway, I took your advice and eliminated the 
try-except pairs, using the traceback function, instead.  I still get 
the error, but here's the full error output:

  File "C:\Documents and 
Settings\Administrator\Desktop\VTrans\AudioTranscriber2.py", line 239, 
in ?
    root.mainloop()
  File "C:\Python22\lib\lib-tk\Tkinter.py", line 929, in mainloop
    self.tk.mainloop(n)
  File "C:\PYTHON22\Pmw\Pmw_0_8_5\lib\PmwBase.py", line 1694, in 
__call__
    _reporterror(self.func, args)
  File "C:\PYTHON22\Pmw\Pmw_0_8_5\lib\PmwBase.py", line 1741, in 
_reporterror
    for tr in traceback.extract_tb(exc_traceback):
RuntimeError: maximum recursion depth exceeded

Sean

---------Included Message----------
>Date: Fri, 14 Jun 2002 23:53:18 -0700 (PDT)
>From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
>To: <shendric@ARCHES.UGA.EDU>
>Cc: "Python Tutor" <tutor@python.org>
>Subject: Re: [Tutor] Runtime Errors
>
>
>
>On Fri, 14 Jun 2002 shendric@arches.uga.edu wrote:
>
>> I've got a script I'm working on that is a kind of spreadsheet.  
There
>> are a fixed number of 4 cells in each row, but the idea would be to 
have
>> as many rows as one wishes.  The algorithm for the spreadsheet works
>> fine, but I get a RuntimeError when I try to load a tab-delimited 
text
>> file into the cells.
>>
>> The loading algorithm is this:
>>
>> 1. Open a text file
>> 2. Read the lines of the text file into a list (readlines())
>> 3. Take each line and do the following:
>>     a. create an instance of the TranscriptionCell class, which is a
>> class that includes four Tkinter Pmw.ScrolledText widgets
>>     b. append that instance to a list
>>     c. put the contents of the first part of the line into the first
>> text widget, then the second into the second, etc.
>> 4.  close the file
>
>Sounds reasonable enough.  Yes, this should work.
>
>>
>> I get the following error:
>> RuntimeError: maximum recursion depth exceeded
>
>
>Hmmm... does the error message also give a clue in which function, and
>around which line it goes bonkers?
>
>
>> Now, I've gotten it to go just fine with only a few rows, but not if
>> there are a lot of them.
>
>
>We'll have to look through the code to see where the recursion's 
coming
>from.  Reading... hmmm...  It might not be such a good idea to wrap 
every
>statement with exception handling like:
>
>###
>             try:
>                self.rowlist[ind].TTime.settext(rowcontents[0])
>             except:
>                 pass
>             try:
>                self.rowlist[ind].TSpeak.settext(rowcontents[1])
>             except:
>                 pass
>###
>
>Doing just a 'pass' when an exception occurs is like an ostrich that 
puts
>its head in the sand:  We're ignoring any potentially bad problems!  
If
>the first row setting fails, it's probable that the whole rowcontents 
list
>has some weirdness that should be reported to the user.
>
>
>
>To make this function easier to debug, we can strip out some of the
>exception handling code, and put a traceback.print_exc() call in the 
code:
>
>###
>def openTrans(self, event=None):
>   file = askopenfile(title="Open Transcript File",
>                      filetypes=(("text files", "*.txt"),
>                                 ("All files", "*")))
>   filetoread = open(file.name, 'r')
>   filecontents = filetoread.readlines()
>   filetoread.close()
>   ind = 0
>   self.rowlist=[]
>   for x in filecontents:
>       rowcontents = x.split("\t")
>       self.rowlist.append(TranscriptionCell(self.inner,
>                                             row=self.row))
>       try:
>           self.rowlist[ind].TTime.settext(rowcontents[0])
>           self.rowlist[ind].TSpeak.settext(rowcontents[1])
>           self.rowlist[ind].TTrans.textBox.settext(rowcontents[2])
>           self.rowlist[ind].Comments.settext(rowcontents[3])
>       except:
>           traceback.print_exc()
>       self.row = self.row + 1
>       ind = ind + 1
>###
>
>
>The traceback.print_exc() should tell us if there's something else 
that's
>going weird.  Hmmm.... but I don't see any obvious recursion here.  
Can
>you show the last few previous lines of the error message as well?  
It'll
>help us to find where exactly the recursion is occuring.
>
>
>Sounds like a tricky bug, but don't worry, we're bound to squish it.
>*grin* Talk to you later!
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
---------End of Included Message----------





From terjeja@hotmail.com  Mon Jun 17 17:54:35 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Mon, 17 Jun 2002 16:54:35 +0000
Subject: [Tutor] Library reference
Message-ID: <F593sllNY30kkZIhTrB0001eff8@hotmail.com>

I run PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on 
win32. (from first line when started) And I am now looking through the 
Python Library Referece release 2.2.1. On page 17-19 there are string 
methods. So, I assume that to get access, I write:
>>>import string
>>>from string import*

But, I can not use all the string methods that are described.
For example, string.istitle() doesn't work. It cannot find it. Encode() is 
not found either. How can I use these and others? Eg capitalize() does work. 
I can't see any note saying that you have to do something different to use 
capitalize() than title() in the library ref. What do I do wrong?

Thanks, Terje

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From jeff@ccvcorp.com  Mon Jun 17 19:09:10 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 17 Jun 2002 11:09:10 -0700
Subject: [Tutor] Library reference
References: <F593sllNY30kkZIhTrB0001eff8@hotmail.com>
Message-ID: <3D0E25C5.8F9172EF@ccvcorp.com>


Terje Johan Abrahamsen wrote:

> I run PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on
> win32. (from first line when started) And I am now looking through the
> Python Library Referece release 2.2.1. On page 17-19 there are string
> methods. So, I assume that to get access, I write:
> >>>import string
> >>>from string import*

First of all, there is a subtle but important distinction between "string
methods" and the "string module".  When you type 'import string', you're getting
access to the string module, and you use the functions in it by typing, for
instance,

>>> mylist = string.split(mystring)

The second line that you've typed ('from string import *') is unnecessary and
probably a bad idea.  What that does to take all the functions in the string
module's namespace and insert them into the current namespace.  This *might*
seem handy, because now instead of typing string.split() you only need to type
split() ... but this is often a trap.  :)  If you have any *other* function
named split() in your current namespace, then you'll only be able to access
*one* of them -- whichever was bound last.  The worst part of this is that you
don't really *know* what names the string module uses, so you're just hoping
that none of those names will conflict with any other names you're using.  And
if there *are* any conflicts, there's a chance that it will be subtle enough
that you'll never notice the difference until you're running a marathon
debugging session to track down some odd erratic behavior in your latest big
project...  In short, best to avoid using the 'from somemodule import *' idiom
unless you're *sure* that the module was designed for that.


> But, I can not use all the string methods that are described.
> For example, string.istitle() doesn't work. It cannot find it. Encode() is
> not found either. How can I use these and others? Eg capitalize() does work.
> I can't see any note saying that you have to do something different to use
> capitalize() than title() in the library ref. What do I do wrong?

Now, as I mentioned before, string *methods* are different from module string.
String methods are called just like other object methods -- by using an object
reference as a qualifier, and in this case, the object should be a string.

What you were doing is, I presume, something like this:

>>> import string
>>> string.istitle("I Am A String")
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'istitle'

...but istitle() is not part of the string module, it's a string method.  Try
this instead:

>>> "I Am A String".istitle()
1
>>> "I am a string".istitle()
0
>>> mystring = "I Am A String"
>>> mystring.istitle()
1
>>>

Does that make more sense now?  :)

Jeff Shannon
Technician/Programmer
Credit International





From ak@silmarill.org  Mon Jun 17 19:07:03 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Mon, 17 Jun 2002 14:07:03 -0400
Subject: [Tutor] Library reference
In-Reply-To: <F593sllNY30kkZIhTrB0001eff8@hotmail.com>
References: <F593sllNY30kkZIhTrB0001eff8@hotmail.com>
Message-ID: <20020617180703.GA4988@ak.silmarill.org>

On Mon, Jun 17, 2002 at 04:54:35PM +0000, Terje Johan Abrahamsen wrote:
> I run PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on 
> win32. (from first line when started) And I am now looking through the 
> Python Library Referece release 2.2.1. On page 17-19 there are string 
> methods. So, I assume that to get access, I write:
> >>>import string
> >>>from string import*
> 
> But, I can not use all the string methods that are described.
> For example, string.istitle() doesn't work. It cannot find it. Encode() is 
> not found either. How can I use these and others? Eg capitalize() does 
> work. I can't see any note saying that you have to do something different 
> to use capitalize() than title() in the library ref. What do I do wrong?
> 
> Thanks, Terje

They were moved to string methods - i.e. instead of doing
string.istitle("test") you have to do "test".istitle().

string module is going to be phased out some time in the future, iirc.

> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From sarmstrong13@mac.com  Mon Jun 17 21:22:25 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 17 Jun 2002 15:22:25 -0500
Subject: [Tutor] More Tkinter Help Please  [callbacks and embedded
 functions]
In-Reply-To: <Pine.LNX.4.44.0206161105580.17853-100000@hkn.eecs.berkeley.edu>
Message-ID: <B933AF31.737C%sarmstrong13@mac.com>

On 6/16/02 1:33 PM, "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu> wrote:


> 
> I'm not too familiar with tkSimpleDialog.Dialog, so I'm not quite sure if
> there's a problem with inheritance.  Can you explain more what problems
> you're running into with this code?
> 
> 
> Ah!  I think that for this statement:
> 
>       self.b4 = Button(f, text="Save Input", command=Saving)
> 
> 
> if 'tkSimpleDialog' is the tkSimpleDialog that's in the 'Introduction To
> Tkinter' tutorial:
> 
> http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm
> 
> 
> then we need to do a little extra: the dialog box needs to know its parent
> window when it's being constructed!  Let's take a look at the definition
> of tkSimpleDialog.Dialog again:
> 
> 
> ### Sample of tkSimpleDialog.py
> # File: tkSimpleDialog.py
> 
> from Tkinter import *
> import os
> 
> class Dialog(Toplevel):
> 
>   def __init__(self, parent, title = None):
> ###
> 
> 
> So when we create a Dialog box, this dialog box must take in an additional
> 'parent' parameter.  However, back in your code:
> 
>       self.b4 = Button(f, text="Save Input", command=Saving)
> 
> When the fourth button is pressed, it tries to call the Saving dialog
> constructor with no parameters: this may be the problem that you're
> running into.  We'd like to be able to do something like:
> 
>       self.b4 = Button(f, text="Save Input", command=Saving(f))
> 
> since 'f' is the frame parent that we'd like to attach the Dialog to...
> but the problem with this is that Python will actually call Saving(f). It
> calls it too soon, because, to Python,
> 
>   Saving(f)
> 
> is a function call, so it just evaluates it straightaway.  We need a way
> to create a callback function that knows about 'f', enough so that it can
> do a 'Saving(f)' when our button is pressed.  What to do?
> 
> 
> 
> 
> 
> The solution actually isn't too bad:
> 
> ###
>       def saving_callback(): Saving(f)
>       self.b4 = Button(f, text="Save Input", command=saving_callback)
> ###
> 
> That is, we can actually embed a small function called 'saving_callback',
> and we can pass that off to as the button callback.  The miniature
> function has access to all the local variables of its parent, which is why
> saving_callback() can say 'f' without problems.
> 


Ok. Now I get a different error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/Tkinter.py",
line 1292, in __call__
    return apply(self.func, args)
TypeError: saving_callback() takes no arguments (1 given)


Also where does the f come from? Is it from the f = Frame(top) in  the
__init__ portion of the PyShell calss? If so, how would this carry over the
saving_callback function? Would the Dialog Box be separate from the initial
frame?

Thanks in advance.
SA




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 17 21:44:40 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 17 Jun 2002 13:44:40 -0700 (PDT)
Subject: [Tutor] More Tkinter Help Please  [callbacks and embedded
 functions]
In-Reply-To: <B933AF31.737C%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206171333260.11067-100000@hkn.eecs.berkeley.edu>


> > The solution actually isn't too bad:
> >
> > ###
> >       def saving_callback(): Saving(f)
> >       self.b4 = Button(f, text="Save Input", command=saving_callback)
> > ###
> >
> > That is, we can actually embed a small function called
> > 'saving_callback', and we can pass that off to as the button callback.
> > The miniature function has access to all the local variables of its
> > parent, which is why saving_callback() can say 'f' without problems.
> >
>
>
> Ok. Now I get a different error:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/Tkinter.py",
> line 1292, in __call__
>     return apply(self.func, args)
> TypeError: saving_callback() takes no arguments (1 given)


Hmmm!  When does the error occur?  Also, can you show us the source code
of that Dialog box again?  I just want to check something quick.  The
error message doesn't make too much sense to me yet, because button
command callbacks shouldn't be sending any arguments over to us.

(Tkinter "event" callbacks, on the other hand, send off an 'event' object,
and are used for things like keyboard input.)




> Also where does the f come from? Is it from the f = Frame(top) in the
> __init__ portion of the PyShell calss? If so, how would this carry over
> the saving_callback function?

>From Python 2.1 onward, inner functions are allowed to carry the variables
of the outer function.  If you're running Python 2.1, you may need the
line:

###
from __future__ import nested_scopes
###

to get this to kick in, but in Python 2.2, this nesting functionality
comes for free.

Since saving_callback() is defined with the __init__ of our PyShell class,
it gets access to the local variables of PyShell.__init__, including that
'f' variable.



> Would the Dialog Box be separate from the initial frame?

That was my assumption --- I thought that dialog boxes open up a new
window.  Dialogs also prevent interactivity with the parent window until
the dialog window itself is closed, I think.


Good luck to you!




From sarmstrong13@mac.com  Mon Jun 17 22:06:23 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 17 Jun 2002 16:06:23 -0500
Subject: [Tutor] More Tkinter Help Please  [callbacks and embedded
 functions]
In-Reply-To: <Pine.LNX.4.44.0206171333260.11067-100000@hkn.eecs.berkeley.edu>
Message-ID: <B933B97F.73A2%sarmstrong13@mac.com>

Ok.

Here's the code:

from Tkinter import *
import os
import commands
import tkSimpleDialog


class PyShell:
    def saving_callback(): Saving(f)
    def clearin(self):
        self.t1.delete(0.0,END)
    def clearout(self):
        self.t2.delete(0.0,END)
    def expyth(self):
        self.t2.delete(0.0, END)
        self.output = commands.getoutput(self.t1.get(0.0, END))
        self.t2.insert(END, self.output)
    def __init__(self, top):
        self.t1 = Text(top, height="12", width="84", font="Courier 12")
        self.t1.pack(side=TOP, pady=2)
        f = Frame(top)
        f.pack()
        self.b1 = Button(f, text="Execute", command=self.expyth)
        self.b1.pack(side=LEFT)
        self.b2 = Button(f, text="Clear Input", command=self.clearin)
        self.b2.pack(side=LEFT)
        self.b3 = Button(f, text="Clear Output", command=self.clearout)
        self.b3.pack(side=LEFT)
        self.b4 = Button(f, text="Save Input", command=self.saving_callback)
        self.b4.pack(side=LEFT)
        self.t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
        self.t2.pack(side=TOP, pady=2)
        
class Saving(tkSimpleDialog.Dialog):
    def savin(self, question):
        Label(question, text="Directory:").grid(row=0)
        Label(question, text="Filename:").grid(row=1)
        self.e1 = Entry(question)
        self.e2 = Entry(question)
        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
    def apply(self):
        self.dir = self.e1.get()
        self.fn = self.e2.get()
        self.sav = self.dir + self.fn
        self.savfile = open(self.sav, "w")
        for line in self.t1.readlines():
            self.savefile.write(line)
        self.savefile.close()
        

            
root = Tk()
app = PyShell(root)
root.mainloop()


Now if I move def saving_callback(): Saving(f) within __init__, I get two
same windows when I launch the app. I then click the Save button, a Dialog
box pops up , but only with the OK and Cancel buttons and no entries. When I
click OK I get the following error:

Traceback (most recent call last):
  File "/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/Tkinter.py",
line 1292, in __call__
    return apply(self.func, args)
  File 
"/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/tkSimpleDialog.py",
line 126, in ok
    self.apply()
  File "PyShell.py", line 41, in apply
    self.dir = self.e1.get()
AttributeError: Saving instance has no attribute 'e1'


I'm assuming this is because the dialogbox is popping up without the entry
fields so there is no value to get. I think the problem may be solved by
using Toplevel, but I will have to investigate this further so that I
understand how to apply the Toplevel widget.

Thanks in advance.
SA




From scot@possum.in-berlin.de  Tue Jun 18 00:07:21 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Tue, 18 Jun 2002 01:07:21 +0200
Subject: [Tutor] More Tkinter Help Please
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C666@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C666@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <200206180107.21311.scot@possum.in-berlin.de>

Hello -=20

> However I seem to recall that Tk has a standard SaveAs type dialog
> already built that mimics the platform(Windows or Unix) SaveAs dialog
> so maybe you could use it.

It is called "asksaveasfilename" and lives in tkFileDialog. I used it in =
a=20
small program something like=20

    from tkFileDialog import *
    ...
    name =3D asksaveasfilename(initialfile=3Da_name)

where a_name is a suggestion that you give the user. Saves a lot of time,=
=20
it does.=20

Unfortunately, most of the beginner's Python books as well as "Python and=
=20
Tkinter Programming" don't give much documentation on these standard=20
dialogs; I ended up figuring out the parameters for asksaveasfilename by=20
giving fake versions (like "parrot=3Ddead") and reading the error message=
s.

Y, Scot

--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany




From adolfo158@yahoo.es  Mon Jun 17 22:59:48 2002
From: adolfo158@yahoo.es (=?iso-8859-1?q?Adolfo=20Aguirre?=)
Date: Mon, 17 Jun 2002 23:59:48 +0200 (CEST)
Subject: [Tutor] Search MS-Word
Message-ID: <20020617215948.94486.qmail@web21209.mail.yahoo.com>

Hi:

I am just starting to learn Python and I have a
practical need.

I need to search for strings in hundreds of .doc and
.txt documents. I am in W98 with Python 2.1.1 -

I figure if I you could tell me how to do a basic
string search, I can start from there to learn how to
do more sophisticated searches.

Appreciating any help on this subject,

Adolfo
Now in Mexico
Usually in santa Barbara, California

_______________________________________________________________
Copa del Mundo de la FIFA 2002
El único lugar de Internet con vídeos de los 64 partidos. 
¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/



From dyoo@hkn.eecs.berkeley.edu  Tue Jun 18 00:39:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 17 Jun 2002 16:39:38 -0700 (PDT)
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <B933B97F.73A2%sarmstrong13@mac.com>
Message-ID: <Pine.LNX.4.44.0206171628150.14672-100000@hkn.eecs.berkeley.edu>


On Mon, 17 Jun 2002, SA wrote:

> class Saving(tkSimpleDialog.Dialog):
>     def savin(self, question):
>         Label(question, text="Directory:").grid(row=0)
>         Label(question, text="Filename:").grid(row=1)
>         self.e1 = Entry(question)
>         self.e2 = Entry(question)
>         self.e1.grid(row=0, column=1)
>         self.e2.grid(row=1, column=1)
>     def apply(self):
>         self.dir = self.e1.get()
>         self.fn = self.e2.get()
>         self.sav = self.dir + self.fn
>         self.savfile = open(self.sav, "w")
>         for line in self.t1.readlines():
>             self.savefile.write(line)
>         self.savefile.close()

Hi SA,


I took another look at the tkSimpleDialog stuff on the Tkinter
Introduction page:

http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm

Are you sure that the 'savin' method is supposed to be named that way?  I
think you mean to call it 'body' instead!



The dialog layout assumes that it can call the body() and buttonbox()
methods to customize the dialog display.  Without customization, it'll
default to a simple yes/no dialog box.  To customize the appearance of the
Saving dialog box, you'll want to write your own versions of body() and
buttonbox().  The Tkinter Introduction above has an example for doing
this:


###
# File: dialog2.py

import tkSimpleDialog

class MyDialog(tkSimpleDialog.Dialog):

    def body(self, master):

        Label(master, text="First:").grid(row=0)
        Label(master, text="Second:").grid(row=1)

        self.e1 = Entry(master)
        self.e2 = Entry(master)

        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
        return self.e1 # initial focus

    def apply(self):
        first = string.atoi(self.e1.get())
        second = string.atoi(self.e2.get())
        print first, second # or something
###

(It doesn't override the buttonbar() method, so by default, it has the
"Ok" and "Cancel" buttons in there.  Using the right method names is
important when we inherit from parent classes, because the parent class
expects to call specific methods.



> Now if I move def saving_callback(): Saving(f) within __init__, I get two

Yes, this should be within.  Having it outside won't work because there
wouldn't be a context, a way of knowing what 'f' meant.



Hope this helps!




From sarmstrong13@mac.com  Tue Jun 18 04:11:00 2002
From: sarmstrong13@mac.com (SA)
Date: Mon, 17 Jun 2002 22:11:00 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <Pine.LNX.4.44.0206171628150.14672-100000@hkn.eecs.berkeley.edu>
Message-ID: <B9340EF4.7FD4%sarmstrong13@mac.com>

Ok.

The Dialog box is now popping up like it should. The only problem comes when
I click on OK in the dialog box. Instead of saving the text in t1 to the
file it gives an error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/Tkinter.py",
line 1292, in __call__
    return apply(self.func, args)
  File 
"/sw/src/root-python-2.2.1-6/sw/lib/python2.2/lib-tk/tkSimpleDialog.py",
line 126, in ok
    self.apply()
  File "PyShell.py", line 47, in apply
    for line in self.t1.readlines():
AttributeError: Saving instance has no attribute 't1'


I would of thought that t1 is still defined from PyShell when called in the
class Saving since it is being called in PyShell.__init__. Is this not
correct. See below:

from Tkinter import *
import os
import commands
import tkSimpleDialog

class PyShell:
    def clearin(self):
        self.t1.delete(0.0,END)
    def clearout(self):
        self.t2.delete(0.0,END)
    def expyth(self):
        self.t2.delete(0.0, END)
        self.output = commands.getoutput(self.t1.get(0.0, END))
        self.t2.insert(END, self.output)
    
    def __init__(self, top):
        def saving_callback(): Saving(top)
        t1 = Text(top, height="12", width="84", font="Courier 12")
        t1.pack(side=TOP, pady=2)
        f = Frame(top)
        f.pack()
        b1 = Button(f, text="Execute", command=self.expyth)
        b1.pack(side=LEFT)
        b2 = Button(f, text="Clear Input", command=self.clearin)
        b2.pack(side=LEFT)
        b3 = Button(f, text="Clear Output", command=self.clearout)
        b3.pack(side=LEFT)
        b4 = Button(f, text="Save Input", command=saving_callback)
        b4.pack(side=LEFT)
        t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
        t2.pack(side=TOP, pady=2)

class Saving(tkSimpleDialog.Dialog):
    def body(self, master):
        Label(master, text="Directory:").grid(row=0)
        Label(master, text="Filename:").grid(row=1)
        self.e1 = Entry(master)
        self.e2 = Entry(master)
        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
        return self.e1
    def apply(self):
        self.dir = self.e1.get()
        self.fn = self.e2.get()
        self.sav = self.dir + self.fn
        self.savfile = open(self.sav, "w")
        for line in self.t1.readlines():
            self.savefile.write(line)
        self.savefile.close()
                   
root = Tk()
app = PyShell(root)
root.mainloop()

Thanks in advance.
SA




From idiot1@netzero.net  Tue Jun 18 04:18:09 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon, 17 Jun 2002 23:18:09 -0400
Subject: [Tutor] mod python for apache
Message-ID: <3D0EA671.B7B9F7FA@netzero.net>

I can't find it. But it's out there. Looking over the site, not finding.
Grrrr...
OK, where do I go to find the module for apache to compile python into
it, like I can do for perl?



From idiot1@netzero.net  Tue Jun 18 04:33:57 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon, 17 Jun 2002 23:33:57 -0400
Subject: [Tutor] found it
Message-ID: <3D0EAA25.F03437B9@netzero.net>

http://www.modpython.org/



From beercanz@hotmail.com  Tue Jun 18 03:04:10 2002
From: beercanz@hotmail.com (Guess Who? Me)
Date: Tue, 18 Jun 2002 02:04:10 +0000
Subject: [Tutor] Help with functions
Message-ID: <F150bxfiIBFdtaFcFzr00001c64@hotmail.com>

<html><div style='background-color:'><DIV><FONT size=2>def area_square(side):<BR>&nbsp;&nbsp;&nbsp; return side*side</FONT></DIV>
<DIV><FONT size=2>def area_rectangle(length,width):<BR>&nbsp;&nbsp;&nbsp; return length*width</FONT></DIV>
<DIV><FONT size=2>def area_circle(radius):<BR>&nbsp;&nbsp;&nbsp; return radius*radius*3.14</FONT></DIV>
<DIV><FONT size=2>def print_options():<BR>&nbsp;&nbsp;&nbsp; print "Options:"<BR>&nbsp;&nbsp;&nbsp; print "'p' to print options."<BR>&nbsp;&nbsp;&nbsp; print "'as' for area of a square."<BR>&nbsp;&nbsp;&nbsp; print "'ar' for area of a rectangle."<BR>&nbsp;&nbsp;&nbsp; print "'ac' for area of a circle."<BR>&nbsp;&nbsp;&nbsp; print "'q' to quit."</FONT></DIV>
<DIV><FONT size=2>choice="p"<BR>while choice !="q":<BR>&nbsp;&nbsp;&nbsp; print_options()<BR>&nbsp;&nbsp;&nbsp; choice=raw_input("Option?:")<BR>&nbsp;&nbsp;&nbsp; if choice == "as":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; side=input("What is the length of a side?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_square(side)<BR>&nbsp;&nbsp;&nbsp; if choice=="ar":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length=input("What is the length?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width=input("What is the width?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_rectangle(length,width)<BR>&nbsp;&nbsp;&nbsp; if choice =="ac":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; radius=input("What is the radius?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_circle(radius)<BR>print "Thanks for using my program."</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>That is my source code so far. I'm following the tutorial at <A href="http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html">http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html</A></FONT></DIV>
<DIV><FONT size=2>and I had a question. Every time I try to get a function to ask for the input of the sides, lenght, width, whatever, it doesn't work. Something funny I found out is that it might work, but then when I quit python and open it again, it doesn't work, saying that ''length' is not defined'. Any thoughts??</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Thanks!</FONT></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM505401/44'>http://explorer.msn.com</a>.<br></html>



From alan.gauld@bt.com  Tue Jun 18 10:48:23 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jun 2002 10:48:23 +0100
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C668@mbtlipnt02.btlabs.bt.co.uk>

> The Dialog box is now popping up like it should. The only 
> problem comes when I click on OK in the dialog box. 
> Instead of saving the text in t1 to the file it gives 
> ...
> AttributeError: Saving instance has no attribute 't1'
> 
> 
> I would of thought that t1 is still defined from PyShell when 
> called in the class Saving since it is being called in PyShell

Nope, the new instance has no knoiwledge of whats in Pyshell 
- that's object encapsulation at work.

You will have to pass either a reference to PyShell to Saving
(Which you do already via the f constructor parameter) and 
then access t1 via that refe5rence or pass the t1 string 
directly to Saving.

However as I said in my message yesterday the conventional way 
to do this is for SAving to pass back the filename/path to 
PyShell and let it save the data - PyShell owns the t1 text 
so it should be responsible for saving it. The dialog's 
responsibility is limited to getting the right file location 
from the user - thats why its called a "dialog"!

Alan G.



From alan.gauld@bt.com  Tue Jun 18 11:03:26 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jun 2002 11:03:26 +0100
Subject: [Tutor] Search MS-Word
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C66A@mbtlipnt02.btlabs.bt.co.uk>

> I need to search for strings in hundreds of .doc and
> .txt documents. I am in W98 with Python 2.1.1 -

doc files may pose a problem because they are in a proprietary 
binary format. The only satisfactory way might be to use COM 
to access the files via Wordpad or something.

However for basic text searching it's much easier.

For an exact match just use the string find() function

import string

string.find("Some string here", txtfile.read())

Or use the new string methods:

txtfile.read().find("Some string here")

If you need to pattern matcvh then you need the re module 
which has a search() function much like the string modules 
find() function except instead of a string you pass in a 
regular expression. My advice would be: get it working 
with string first then move to re later

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From rob@uselesspython.com  Tue Jun 18 12:26:28 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Tue, 18 Jun 2002 06:26:28 -0500
Subject: [Tutor] Help with functions
References: <F150bxfiIBFdtaFcFzr00001c64@hotmail.com>
Message-ID: <3D0F18E4.8090104@uselesspython.com>

I saved your program as functionHelp.py and imported it into IDLE. It 
ran without any flaws that I noticed.

Rob
http://uselesspython.com

Guess Who? Me wrote:

> def area_square(side):
>     return side*side
> 
> def area_rectangle(length,width):
>     return length*width
> 
> def area_circle(radius):
>     return radius*radius*3.14
> 
> def print_options():
>     print "Options:"
>     print "'p' to print options."
>     print "'as' for area of a square."
>     print "'ar' for area of a rectangle."
>     print "'ac' for area of a circle."
>     print "'q' to quit."
> 
> choice="p"
> while choice !="q":
>     print_options()
>     choice=raw_input("Option?:")
>     if choice == "as":
>         side=input("What is the length of a side?:")
>         print area_square(side)
>     if choice=="ar":
>         length=input("What is the length?:")
>         width=input("What is the width?:")
>         print area_rectangle(length,width)
>     if choice =="ac":
>         radius=input("What is the radius?:")
>         print area_circle(radius)
> print "Thanks for using my program."
> 
>  
> 
> That is my source code so far. I'm following the tutorial at 
> http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html
> 
> and I had a question. Every time I try to get a function to ask for the 
> input of the sides, lenght, width, whatever, it doesn't work. Something 
> funny I found out is that it might work, but then when I quit python and 
> open it again, it doesn't work, saying that ''length' is not defined'. 
> Any thoughts??
> 
>  
> 
> Thanks!
> 
> 
> ------------------------------------------------------------------------
> Get your FREE download of MSN Explorer at http://explorer.msn.com 
> <http://g.msn.com/1HM505401/44>.
> _______________________________________________ Tutor maillist - 
> Tutor@python.org http://mail.python.org/mailman/listinfo/tutor






From sarmstrong13@mac.com  Tue Jun 18 14:28:01 2002
From: sarmstrong13@mac.com (SA)
Date: Tue, 18 Jun 2002 08:28:01 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C668@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <B9349F91.7FF0%sarmstrong13@mac.com>

On 6/18/02 4:48 AM, "alan.gauld@bt.com" <alan.gauld@bt.com> wrote:
> However as I said in my message yesterday the conventional way
> to do this is for SAving to pass back the filename/path to
> PyShell and let it save the data - PyShell owns the t1 text
> so it should be responsible for saving it. The dialog's
> responsibility is limited to getting the right file location
> from the user - thats why its called a "dialog"!
> 
> Alan G.
> 

Ok.

I'm trying this, but my question is still how do I pass the variable sav
from:
 def apply(self):
        dir = self.e1.get()
        fn = self.e2.get()
        sav = dir + fn
        return sav

In the class Saving to the class PyShell? Although my original question was
how to pas the variable t1 from PyShell to Saving, I now need to find out
how to pass the variable sav from Saving to PyShell. Now I do not expect you
all to do all the work for me, since the whole purpose of this exercise is
for my learning experience, so if you just want to point the way to specific
documentation or hint (real well) to where I need to look for this info,
that will also be fine. I do appreciate all of the help everyone has given
me in this exercise, I've gathered a lot of information that is sometimes
glossed over in tutorials because you are expected to know all of this stuff
already.

Thanks Again.
SA




From wolf_binary@hotmail.com  Tue Jun 18 16:18:16 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Tue, 18 Jun 2002 10:18:16 -0500
Subject: [Tutor] bits taken by variable type
Message-ID: <DAV61pshGfs60XxsXfx00003014@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0016_01C216B1.75CD3380
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

Coming from a C++ view point, how do you know if a variable in Python is =
unsigned long int or some other modified variable type?  How do you know =
how much precision a number is stored at? =20

Thanks,
Cameron Stoner

------=_NextPart_000_0016_01C216B1.75CD3380
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Coming from a C++ view point, how do =
you know if a=20
variable in Python is unsigned long int or some other modified variable=20
type?&nbsp; How do you know how much precision a number is stored =
at?&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0016_01C216B1.75CD3380--



From alan.gauld@bt.com  Tue Jun 18 17:07:33 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jun 2002 17:07:33 +0100
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C670@mbtlipnt02.btlabs.bt.co.uk>

> I'm trying this, but my question is still how do I pass the 
> variable sav
> from:
>  def apply(self):
>         dir = self.e1.get()
>         fn = self.e2.get()
>         sav = dir + fn
>         return sav

There are several options but I'd recommend writing a 
method of the Saving class to fetch the filename.
You also need to create a member attriobute of Saving 
to store the value of course...

     def apply(self):   #as above except last line
         dir = self.e1.get()
         fn = self.e2.get()
         self.name = dir + fn  # assign to instance variable

     def getName(self):   # inside Saving class
        return self.name  # return instance variable

Then when you create the Saving class you assign to 
a local variable.

     def doSave(self):		# inside Pyshell class
         saveDialog = Saving(f) # auto calls apply etc
         filename = saveDialog.getName()
         self.saveText(filename)
         del(saveDialog)

         
> how to pass the variable sav from Saving to PyShell. 

Don't pass the data - it belongs to the object. Get the 
object to give you the data on request. Thus when you 
create the instance of Saving you keep the reference 
and use it to ask for the filename.

Alan g.



From urnerk@qwest.net  Tue Jun 18 15:05:24 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 18 Jun 2002 10:05:24 -0400
Subject: [Tutor] bits taken by variable type
In-Reply-To: <DAV61pshGfs60XxsXfx00003014@hotmail.com>
References: <DAV61pshGfs60XxsXfx00003014@hotmail.com>
Message-ID: <20020618100524.75be5cb3.urnerk@qwest.net>

On Tue, 18 Jun 2002 10:18:16 -0500
"Cameron Stoner" <wolf_binary@hotmail.com> wrote:

> Hi all,
> 
> Coming from a C++ view point, how do you know if a variable in Python is unsigned long int or some other modified variable type?  How do you know how much precision a number is stored at?  
> 
> Thanks,
> Cameron Stoner
> 

I'm pretty sure Python's floats are implemented as C doubles.  Integers are ints.  
Obviously long integers (e.g. 9091023810283091283081209381092380192830129L) are 
special to Python (not native C).  

Python doesn't try to map its types to underlying C types, from the point of view 
of the user (of course it has to in code, as CPython's implementation).

Floats would seem to be the only type where there'd be a question of precision.  
With int, it's more a matter of limits, and these are spelled out in the
documentation (Python now auto-converts ints to long integers if they 
overflow).

Some extension modules let you work with decimal numbers of much greater 
precision, but, like Python long integers, these are not native C types (may 
be well-established in C libraries though).

Kirby



From urnerk@qwest.net  Tue Jun 18 15:09:39 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 18 Jun 2002 10:09:39 -0400
Subject: [Tutor] Help with functions
In-Reply-To: <F150bxfiIBFdtaFcFzr00001c64@hotmail.com>
References: <F150bxfiIBFdtaFcFzr00001c64@hotmail.com>
Message-ID: <20020618100939.02d07112.urnerk@qwest.net>

> That is my source code so far. I'm following the tutorial at http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html
> and I had a question. Every time I try to get a function to ask for the input of the sides, lenght, width, whatever, it doesn't work. Something funny I found out is that it might work, but then when I quit python and open it again, it doesn't work, saying that ''length' is not defined'. Any thoughts??
>  

If it works when you quit and go back into Python, it might be a reload issue.
If you're in the interpreter and make a change to a .py file in a text editor,
and save it, the interpreter will still operate with the old compiled .pyc
unless you force a recompile using reload(name_of_module).  

It's a little trickier if you don't import the module, but members of the 
module.  A workaround is to import the module as well, for the purpose of 
forcing a reload, and then reissuing the 'from xxx import a,b,c' command 
as before.  This can be done as a function itself.

Kirby



From alan.gauld@bt.com  Tue Jun 18 17:59:58 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jun 2002 17:59:58 +0100
Subject: [Tutor] bits taken by variable type
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C671@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C216E9.93F2D030
Content-type: text/plain; charset="iso-8859-1"

>  Coming from a C++ view point, how do you know if a variable in Python is

>  unsigned long int or some other modified variable type?   
 
In practice, why would you care?
 
> How do you know how much precision a number is stored at?   
 
For integers it is
 
import sys
print sys.maxint
 
If you need longer than maxint use long integers which are arbitrarily
large(effectively)
 
For floats, I'm not sure. Just assume they are big enough and catch
exceptions 
for when they aren't.
 
These are the kind of low level details that Python is trying to shield from
you.
 
Alan G.
 

------_=_NextPart_001_01C216E9.93F2D030
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>Coming from a C++ view 
point, how do you know if a variable in Python is&nbsp;<SPAN 
class=580310017-18062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>unsigned long int or 
some other modified variable type?&nbsp;&nbsp;<SPAN 
class=580310017-18062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>In practice, 
why would you care?</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002>&gt;</SPAN></FONT></FONT><FONT face=Arial><FONT 
size=2><SPAN class=580310017-18062002>&nbsp;</SPAN>How do you 
know&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2>how much precision a 
number is stored at?&nbsp;&nbsp;<SPAN class=580310017-18062002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>For integers 
it is</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>import 
sys</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>print 
sys.maxint</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>If you need 
longer than maxint use long integers which are arbitrarily 
large(effectively)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>For floats, 
I'm not sure. Just assume they are big enough and catch exceptions 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>for when they 
aren't.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>These are the 
kind of low level details that Python is trying to shield from 
you.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>Alan 
G.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C216E9.93F2D030--



From alan.gauld@bt.com  Tue Jun 18 18:03:34 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jun 2002 18:03:34 +0100
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C672@mbtlipnt02.btlabs.bt.co.uk>

Rep0lying to my own message!        
> > how to pass the variable sav from Saving to PyShell. 
> 
> Don't pass the data - it belongs to the object. Get the 
> object to give you the data on request. Thus when you 
> create the instance of Saving you keep the reference 
> and use it to ask for the filename.

I should add that this is complicated slightly because 
you are inheriting from tkSimpleDialog so we have to work 
within the constraints of the protocol which 
tkSimpleDialog defines. This is not such a bad thing 
but simply a price we pay for reusing the code and 
protocol of tkSimpleDialog. 

Alan G.



From dyoo@hkn.eecs.berkeley.edu  Tue Jun 18 18:13:08 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 18 Jun 2002 10:13:08 -0700 (PDT)
Subject: [Tutor] cdrw writing
In-Reply-To: <20020618114014.2810.qmail@web21506.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0206181002340.31777-100000@hkn.eecs.berkeley.edu>


> > I'm very sure that I'm misinterpreting your question, so I have to ask
> > for clarification.  What do you plan to do after you write your
> > program to CDR?  Do you plan to share your programs with others
> > afterwards?  Do you want to make it run automatically if it's inserted
> > into a Windows computer?
> >
> > Again, my apologies for my confusion!  Please make sure to send your
> > replies to 'tutor@python.org', and not just to me, so that the others
> > can bail me out when I make mistakes.
> >
> i want to save the programs so they can be ran on another pc with out
> useing the internet to open the file so it will autorun like any other
> program.


Hi Mista,

(It's much better to send replies back to 'tutor@python.org', so that the
other tutors can help answer your question too.  Why settle for one
person's hearsay, when you can have everyone's?  Seriously though, please
send to tutor@python.org.)


I think you mean: you want to allow others to run your program without
installing Python themselves.


If you plan to give your program to other people, you probably want to
"package" your program to make it work on other people's computers.
There's a program called 'py2exe' that creates executable files that your
friends can run directly.  Py2exe can be found here:

    http://py2exe.sourceforge.net/

This utility will take your program and bundle it together to make an EXE.


About getting your CD to autorun: I don't have Windows, so I can't help
too much here, but take a look at:

    http://www.pcnineoneone.com/howto/autorun1.html

Apparently, as long as there's a 'Autorun.inf' file that points to an EXE,
Windows will run it automatically when the CD is inserted.




From virketis@post.harvard.edu  Tue Jun 18 12:28:21 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Tue, 18 Jun 2002 14:28:21 +0300
Subject: [Tutor] Search MS-Word
In-Reply-To: <20020617215948.94486.qmail@web21209.mail.yahoo.com>
Message-ID: <ISPFE8CFMcrKpWdomJ80000b868@mail.takas.lt>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Adolfo, <br></div>
<div><br>
<FONT COLOR=3D"#000080">&gt;I need to search for strings in=
 hundreds of .doc and</FONT><br>
<FONT COLOR=3D"#000080">&gt;.txt documents. I am in W98 with Python=
 2.1.1 -</FONT><br>
<br></div>
<div>Lets take the two separately. <br></div>
<div>&nbsp;</div>
<div>Text files are relatively easy in principle. Depending on=
 how sophisticated a search you need to conduct, either the=
 standard Python string search capacities or regular expressions=
 will do the trick handily. Here is a very simple example using a=
 file &quot;trivial.txt&quot; containing &quot;My name is=
 Pijus.&quot;<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; source =3D open(&quot;c:\\trivial.txt&quot;,=
 &quot;r&quot;) #open the file for reading<br></div>
<div>&gt;&gt;&gt; text =3D source.readlines() #put all text into a=
 list<br></div>
<div>&gt;&gt;&gt; import string<br></div>
<div>&gt;&gt;&gt; for line in text:<br></div>
<div>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;if=
 string.find(line, &quot;Pijus&quot;) !=3D -1: #if=
 &quot;Pijus&quot; found anywhere<br></div>
<div>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;print line<br></div>
<div>&nbsp;</div>
<div>This will return the string &quot;My name is Pijus&quot;.=
 See the string module documentation for more information on=
 find().<br></div>
<div>&nbsp;</div>
<div>Word files are a bit more tricky, since Python cannot simply=
 open one up like it can a straight text file. If you need your=
 code to work only for Windows, use COM to access M$ Word=
 directly. You will need to install the win32all extensions=
 (check out the python.org Windows section to get them). Then,=
 something along the following lines will happen:<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; import win32com.client<br></div>
<div>&gt;&gt;&gt; wrdobj =3D=
 win32com.client.Dispatch(&quot;Word.Application&quot;)=
 <br></div>
<div>&gt;&gt;&gt; wrdobj.Visible =3D 1<br></div>
<div>&nbsp;</div>
<div>You should be looking at a nice Word session. This is where=
 Python sort of ends and the manipulation of the Word COM objects=
 begin. Off the top of my head, I can only remember how to open a=
 file:<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt;=
 wrdobj.Documents.Open(&quot;some_path&quot;)<br></div>
<div>&nbsp;</div>
<div>Check out the Word Object Browser and perhaps VBA=
 documentation to see what you need to do next in order to search=
 the file you just opened. It should take just one more line of=
 code to do something similar to the text example. <br></div>
<div>&nbsp;</div>
<div>Cheers, <br></div>
<div>&nbsp;</div>
<div>Pijus<br></div>
<div>&nbsp;</div>
<div>-- <br></div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann<br></div>
</body></html>




From idiot1@netzero.net  Tue Jun 18 18:50:14 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue, 18 Jun 2002 13:50:14 -0400
Subject: [Tutor] Bbbulk precedence email header
Message-ID: <3D0F72D6.50FB2E19@netzero.net>

Some MLM's reject mail with the header "Precedence: Bulk", to help break
mail loops. Good idea, so I decided to install it. 
Well, in the server I captured a email with a bulk precedence. Works
fine, TLpost.py exits properly. When I email to it precedence: Bulk, it
does not, and handles the message normally. ERG.

Anyone wanting to view the existing script can do so at this page:
http://www.tinylist.org/TLpost.shtml

This is a ssi include of the actual script, so if anything changes, it
is IMMEDIATELY reflected on the page.

Testing takes place on 'testlist3', so feel free to subscribe to it and
play with the thing. All other functions are working properly.

-- 

end

Respectfully,
             Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                           +--------+



From idiot1@netzero.net  Tue Jun 18 19:29:47 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue, 18 Jun 2002 14:29:47 -0400
Subject: [Tutor] Ah hah!
Message-ID: <3D0F7C1B.C21AF8E9@netzero.net>

Nutscrape sends it out with a X-Priority header, not as the book
discusses as a Precedence header- as is the case with most of my Ezines
and allmost all my spam.

F***ing nutscrape...

Gotta add another header detection snip of code...

-- 

end

Respectfully,
             Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                           +--------+



From mikew@screaminet.com  Tue Jun 18 12:34:22 2002
From: mikew@screaminet.com (mikew@screaminet.com)
Date: Tue, 18 Jun 2002 11:34:22 GMT
Subject: [Tutor] Help with functions
Message-ID: <200206181134.g5IBYMF52615@www.screaminetcorp.com>

One problem I found when I cut and pasted your code was the line that says if choice="as"; it should read if choice=="as". Another line below that is also wrong in the same way. After I fixed that it ran fine for me.

----- Original Message -----
From:  "Guess Who? Me" <beercanz@hotmail.com>
To:  tutor@python.org
Sent: Tue, 18 Jun 2002 02:04:10 +0000
Subject:  [Tutor] Help with functions
<div style='background-color:'><DIV><FONT size=2>def area_square(side):
    return side*side</FONT></DIV>
<DIV><FONT size=2>def area_rectangle(length,width):
    return length*width</FONT></DIV>
<DIV><FONT size=2>def area_circle(radius):
    return radius*radius*3.14</FONT></DIV>
<DIV><FONT size=2>def print_options():
    print "Options:"
    print "'p' to print options."
    print "'as' for area of a square."
    print "'ar' for area of a rectangle."
    print "'ac' for area of a circle."
    print "'q' to quit."</FONT></DIV>
<DIV><FONT size=2>choice="p"
while choice !="q":
    print_options()
    choice=raw_input("Option?:")
    if choice= "as":
        side=input("What is the length of a side?:")
        print area_square(side)
    if choice=="ar":
        length=input("What is the length?:")
        width=input("What is the width?:")
        print area_rectangle(length,width)
    if choice="ac":
        radius=input("What is the radius?:")
        print area_circle(radius)
print "Thanks for using my program."</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>That is my source code so far. I'm following the tutorial at <A href="http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html">http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html</A></FONT></DIV>
<DIV><FONT size=2>and I had a question. Every time I try to get a function to ask for the input of the sides, lenght, width, whatever, it doesn't work. Something funny I found out is that it might work, but then when I quit python and open it again, it doesn't work, saying that ''length' is not defined'. Any thoughts??</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Thanks!</FONT></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM505401/44'>http://explorer.msn.com</a>.



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








From sarmstrong13@mac.com  Tue Jun 18 20:50:34 2002
From: sarmstrong13@mac.com (SA)
Date: Tue, 18 Jun 2002 14:50:34 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C670@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <B934F93A.8030%sarmstrong13@mac.com>

On 6/18/02 11:07 AM, "alan.gauld@bt.com" <alan.gauld@bt.com> wrote:

>    def doSave(self):        # inside Pyshell class
>        saveDialog = Saving(f) # auto calls apply etc
>        filename = saveDialog.getName()
>        self.saveText(filename)
>        del(saveDialog)
A couple of things here:

    I can't use self in "def doSave(self):" because the doSave function is
actually inside PyShell.__iniT__. If I use self and place this function
inside PyShell but outside of __init__ I get an error claiming the function
is asking for on arument but none are given. If I place the function inside
__init__ everything works except for the "self.saveText(filename)" portion
because there is no instance of self inside the function?

So I tried to fiddle around with this function and have the following:

def doSave():
    SaveDialog = Saving(top)
    filename = SaveDialog.getName()
    outfile = t1()
    out = open(filename, 'w')
    inf = open(outfile, 'r')
    for line in inf.readlines():
        out.write(line)
    out.close()

Now this actually brings up the popup save dialog and allows the user to
chose the directory path and filename, even writes the correct file in the
correct place, but there is no data in the file. It is not placing the t1
object's data into the outfile as a string.

So I guess my final question is how do I coerce t1 to give its data to
outfile as a string?

Thanks.
SA




From sarmstrong13@mac.com  Tue Jun 18 22:36:49 2002
From: sarmstrong13@mac.com (SA)
Date: Tue, 18 Jun 2002 16:36:49 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <B934F93A.8030%sarmstrong13@mac.com>
Message-ID: <B9351221.803E%sarmstrong13@mac.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.

--B_3107263011_2114931
Content-type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable

On 6/18/02 2:50 PM, "SA" <sarmstrong13@mac.com> wrote:


>=20
> def doSave():
>   SaveDialog =3D Saving(top)
>   filename =3D SaveDialog.getName()
>   outfile =3D t1()
>   out =3D open(filename, 'w')
>   inf =3D open(outfile, 'r')
>   for line in inf.readlines():
>       out.write(line)
>   out.close()
>=20

Me very Dumb. Me go home now. Me sorry.

I can't believe I missed this. I figured it out. Well actually, the method
saving the text in t1 was already right before my eyes in the expyth method=
.
Now I use that and I get the following for the doSave method:

        def doSave():
            SaveDialog =3D Saving(top)
            filename =3D SaveDialog.getName()
            outfile =3D t1.get(0.0, END)
            out =3D open(filename, 'w')
            out.write(outfile)
            out.close()

I feel really stupid for missing that. Now all of the buttons work the way =
I
want them to. Below is a copy of the code for anyone who wishes to give it =
a
try. I like this in place of the command line idle which is all I really
have available for my OSX system. This allows you to write the code in the
top window and display it=B9s output in the bottom window, unless the output
is a gui(which is displayed as a gui window). For me it is cool, because I
can hammer away at different things and test them out before I click the
save button to save the code. It is a slight ripoff of a Tcl/Tk program I
came across that does the same thing for Perl scripts. I would like to
eventually come up with a final program that works on Tcl, Perl, or Python
(maybe even Ruby) depending on what is fed as the first line of code. If
anyone else has some suggestions for it please feel free, or if you have
some code to add, add it on and we can see where it goes from here. Thank
you very much Alan and Danny for all of your help and guidance.(and patienc=
e
with me). This has been a really cool learning experience and I find this
list very beneficial for my continued learning of Python.

Thanks.
SA

--B_3107263011_2114931
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Re: [Tutor] More Tkinter Help Please &nbsp;[Dialog windows]</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">On 6/18/02 2:50 PM, &quot;SA&quot; &lt;sarmstrong13@ma=
c.com&gt; wrote:<BR>
<BR>
<BR>
<FONT COLOR=3D"#0000FF">&gt; <BR>
&gt; def doSave():<BR>
&gt; &nbsp;&nbsp;SaveDialog =3D Saving(top)<BR>
&gt; &nbsp;&nbsp;filename =3D SaveDialog.getName()<BR>
&gt; &nbsp;&nbsp;outfile =3D t1()<BR>
&gt; &nbsp;&nbsp;out =3D open(filename, 'w')<BR>
&gt; &nbsp;&nbsp;inf =3D open(outfile, 'r')<BR>
&gt; &nbsp;&nbsp;for line in inf.readlines():<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.write(line)<BR>
&gt; &nbsp;&nbsp;out.close()<BR>
&gt; <BR>
</FONT><BR>
Me very Dumb. Me go home now. Me sorry.<BR>
<BR>
I can't believe I missed this. I figured it out. Well actually, the method =
saving the text in t1 was already right before my eyes in the expyth method.=
 Now I use that and I get the following for the doSave method:<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def doSave():<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sav=
eDialog =3D Saving(top)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fil=
ename =3D SaveDialog.getName()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out=
file =3D <U>t1.get(0.0, END)<BR>
</U> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out =
=3D open(filename, 'w')<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out=
.write(outfile)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out=
.close()<BR>
<BR>
I feel really stupid for missing that. Now all of the buttons work the way =
I want them to. Below is a copy of the code for anyone who wishes to give it=
 a try. I like this in place of the command line idle which is all I really =
have available for my OSX system. This allows you to write the code in the t=
op window and display it&#8217;s output in the bottom window, unless the out=
put is a gui(which is displayed as a gui window). For me it is cool, because=
 I can hammer away at different things and test them out before I click the =
save button to save the code. It is a slight ripoff of a Tcl/Tk program I ca=
me across that does the same thing for Perl scripts. I would like to eventua=
lly come up with a final program that works on Tcl, Perl, or Python (maybe e=
ven Ruby) depending on what is fed as the first line of code. If anyone else=
 has some suggestions for it please feel free, or if you have some code to a=
dd, add it on and we can see where it goes from here. Thank you very much Al=
an and Danny for all of your help and guidance.(and patience with me). This =
has been a really cool learning experience and I find this list very benefic=
ial for my continued learning of Python.<BR>
<BR>
Thanks.<BR>
SA</FONT>
</BODY>
</HTML>


--B_3107263011_2114931--




From sarmstrong13@mac.com  Tue Jun 18 22:37:59 2002
From: sarmstrong13@mac.com (SA)
Date: Tue, 18 Jun 2002 16:37:59 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <B934F93A.8030%sarmstrong13@mac.com>
Message-ID: <B9351267.8040%sarmstrong13@mac.com>

Sorry. Forgot to cut and paste the final code:

from Tkinter import *
import os
import commands
import tkSimpleDialog

class PyShell:
    
    def clearin(self):
        self.t1.delete(0.0,END)
    def clearout(self):
        self.t2.delete(0.0,END)
    def expyth(self):
        self.t2.delete(0.0, END)
        self.output = commands.getoutput(self.t1.get(0.0, END))
        self.t2.insert(END, self.output)
    def __init__(self, top):
        def doSave():
            SaveDialog = Saving(top)
            filename = SaveDialog.getName()
            outfile = t1.get(0.0, END)
            out = open(filename, 'w')
            out.write(outfile)
            out.close()
        t1 = Text(top, height="12", width="84", font="Courier 12")
        t1.pack(side=TOP, pady=2)
        f = Frame(top)
        f.pack()
        b1 = Button(f, text="Execute", command=self.expyth)
        b1.pack(side=LEFT)
        b2 = Button(f, text="Clear Input", command=self.clearin)
        b2.pack(side=LEFT)
        b3 = Button(f, text="Clear Output", command=self.clearout)
        b3.pack(side=LEFT)
        b4 = Button(f, text="Save Input", command=doSave)
        b4.pack(side=LEFT)
        t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
        t2.pack(side=TOP, pady=2)

class Saving(tkSimpleDialog.Dialog):
    
    def body(self, master):
        Label(master, text="Directory:").grid(row=0)
        Label(master, text="Filename:").grid(row=1)
        self.e1 = Entry(master)
        self.e2 = Entry(master)
        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
        return self.e1
    def apply(self):
        dir = self.e1.get()
        fn = self.e2.get()
        self.name = dir + fn
    def getName(self):
        return self.name

                   
root = Tk()
app = PyShell(root)
root.mainloop()




From sarmstrong13@mac.com  Tue Jun 18 22:55:13 2002
From: sarmstrong13@mac.com (SA)
Date: Tue, 18 Jun 2002 16:55:13 -0500
Subject: Corrected code for PyShell, was:(Re: [Tutor] More Tkinter Help
 Please  [Dialog windows])
In-Reply-To: <B9351267.8040%sarmstrong13@mac.com>
Message-ID: <B9351671.804E%sarmstrong13@mac.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.

--B_3107264114_2181541
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

Ok. I found a bug. I left off all of the self descriptors on the buttons.
Here is the corrected code that now works the way I intended (my Bad):
#!/usr/bin/env python
from Tkinter import *
import os
import commands
import tkSimpleDialog

class PyShell:

        def clearin(self):
                self.t1.delete(0.0,END)
        def clearout(self):
                self.t2.delete(0.0,END)
        def expyth(self):
                self.t2.delete(0.0, END)
                self.output = commands.getoutput(self.t1.get(0.0, END))
                self.t2.insert(END, self.output)
        def __init__(self, top):
                def doSave():
                        SaveDialog = Saving(top)
                        filename = SaveDialog.getName()
                        outfile = self.t1.get(0.0, END)
                        out = open(filename, 'w')
                        out.write(outfile)
                        out.close()
                self.t1 = Text(top, height="12", width="84", font="Courier
12")
                self.t1.pack(side=TOP, pady=2)
                f = Frame(top)
                f.pack()
                self.b1 = Button(f, text="Execute", command=self.expyth)
                self.b1.pack(side=LEFT)
                self.b2 = Button(f, text="Clear Input",
command=self.clearin)
                self.b2.pack(side=LEFT)
                self.b3 = Button(f, text="Clear Output",
command=self.clearout)
                self.b3.pack(side=LEFT)
                self.b4 = Button(f, text="Save Input", command=doSave)
                self.b4.pack(side=LEFT)
                self.t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
                self.t2.pack(side=TOP, pady=2)

class Saving(tkSimpleDialog.Dialog):


        def body(self, master):
                Label(master, text="Directory:").grid(row=0)
                Label(master, text="Filename:").grid(row=1)
                self.e1 = Entry(master)
                self.e2 = Entry(master)
                self.e1.grid(row=0, column=1)
                self.e2.grid(row=1, column=1)
                return self.e1
        def apply(self):
                dir = self.e1.get()
                fn = self.e2.get()
                self.name = dir + fn
        def getName(self):
                return self.name


root = Tk()
app = PyShell(root)
root.mainloop()


---
Thanks.
Sa

--B_3107264114_2181541
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Corrected code for PyShell, was:(Re: [Tutor] More Tkinter Help Pleas=
e &nbsp;[Dialog windows])</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">Ok. I found a bug. I left off all of the self descript=
ors on the buttons. Here is the corrected code that now works the way I inte=
nded (my Bad):<BR>
#!/usr/bin/env python<BR>
from Tkinter import *<BR>
import os<BR>
import commands<BR>
import tkSimpleDialog<BR>
<BR>
class PyShell:<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def clearin(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t1.delete(0.0,END)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def clearout(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t2.delete(0.0,END)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def expyth(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t2.delete(0.0, END)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.output =3D commands.getoutput(self.t1.get(0.0, END))=
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t2.insert(END, self.output)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, top):<BR=
>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;def doSave():<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SaveDia=
log =3D Saving(top)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filenam=
e =3D SaveDialog.getName()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outfile=
 =3D self.t1.get(0.0, END)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out =3D o=
pen(filename, 'w')<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.wri=
te(outfile)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.clo=
se()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t1 =3D Text(top, height=3D&quot;12&quot;, width=3D&quot;=
84&quot;, font=3D&quot;Courier 12&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t1.pack(side=3DTOP, pady=3D2)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;f =3D Frame(top)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;f.pack()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b1 =3D Button(f, text=3D&quot;Execute&quot;, command=3Ds=
elf.expyth)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b1.pack(side=3DLEFT)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b2 =3D Button(f, text=3D&quot;Clear Input&quot;, comma=
nd=3Dself.clearin)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b2.pack(side=3DLEFT)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b3 =3D Button(f, text=3D&quot;Clear Output&quot;, comm=
and=3Dself.clearout)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b3.pack(side=3DLEFT)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b4 =3D Button(f, text=3D&quot;Save Input&quot;, comman=
d=3DdoSave)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.b4.pack(side=3DLEFT)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t2 =3D Text(top, height=3D&quot;12&quot;, width=3D&quot;=
84&quot;, bg=3D&quot;lightblue&quot;, font=3D&quot;Courier 12&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.t2.pack(side=3DTOP, pady=3D2)<BR>
<BR>
class Saving(tkSimpleDialog.Dialog):<BR>
<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def body(self, master): <BR=
>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;Label(master, text=3D&quot;Directory:&quot;).grid(row=3D0)<=
BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;Label(master, text=3D&quot;Filename:&quot;).grid(row=3D1)<B=
R>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.e1 =3D Entry(master)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.e2 =3D Entry(master)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.e1.grid(row=3D0, column=3D1)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.e2.grid(row=3D1, column=3D1)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;return self.e1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def apply(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;dir =3D self.e1.get()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;fn =3D self.e2.get()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;self.name =3D dir + fn<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def getName(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;return self.name<BR>
<BR>
<BR>
root =3D Tk()<BR>
app =3D PyShell(root)<BR>
root.mainloop()<BR>
<BR>
<BR>
---<BR>
Thanks.<BR>
Sa</FONT>
</BODY>
</HTML>


--B_3107264114_2181541--




From marcolinux@linuxbr.com.br  Tue Jun 18 23:33:19 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Tue, 18 Jun 2002 19:33:19 -0300
Subject: [Tutor] Dynamic change of dictionaries
Message-ID: <20020618223319.GA7284@marcolab.proconet>

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi people,
I need to make a simple monitor for my network.
I need to monitor how much each machine is using the bandwidth.
The first tool that comes to mind is tcpdump. So far Im able to see how
much a given IP shows up with:
# tcpdump -nq -i eth0 dst host 10.15.50.3 and port 80
but i need to show it "graphically".

Some examples to show what I mean:

The following program fakes a tcpdump output for easy testing.
# fakeDump.py

18:57:28.1024437448 10.0.0.8.2279 > 10.0.0.3.80: tcp 0 (DF)
18:57:28.1024437448 10.0.0.19.1792 > 10.0.0.3.80: tcp 0 (DF)
18:57:29.1024437449 10.0.0.20.1570 > 10.0.0.3.80: tcp 0 (DF)
18:57:29.1024437449 10.0.0.22.2045 > 10.0.0.3.80: tcp 0 (DF)
18:57:30.1024437450 10.0.0.6.2114 > 10.0.0.3.80: tcp 0 (DF)
18:57:30.1024437450 10.0.0.8.1487 > 10.0.0.3.80: tcp 0 (DF)
18:57:31.1024437451 10.0.0.8.1653 > 10.0.0.3.80: tcp 0 (DF)
18:57:31.1024437451 10.0.0.14.2290 > 10.0.0.3.80: tcp 0 (DF)
18:57:32.1024437452 10.0.0.10.1523 > 10.0.0.3.80: tcp 0 (DF)
18:57:32.1024437452 10.0.0.9.2290 > 10.0.0.3.80: tcp 0 (DF)

The interesting part here is the ip number: 
I need is to tell how much 10.0.0.8 shows up.
And 10.0.0.6 .
And 10.0.0.22.
And .... You get the idea.
So I can show it like a gauge. Screenshots :)
Pay attention to 10.0.0.6 and how it "disappear" due to no traffic:

10.0.0.8   ######
10.0.0.6   ####
10.0.0.22  ##############
10.0.0.99  ########	


Some minutes later:

10.0.0.8   #######################################
10.0.0.6   #
10.0.0.22  #########
10.0.0.99  #########################	

Some minutes later:

10.0.0.8   #######################################
10.0.0.22  #########
10.0.0.99  #########################	



I was thinking about a dictionary.

'IP' : number of show up in X minutes
dict={'10.0.0.6':5,'10.0.0.22':33,'10.0.0.8':42} 


Given the code below, how do I change the dict dynamically with a output
like the command above?

Thanks in advance for _any_ help.


####################################################################
# simulates a traffic monitor
import time,os,random

header="\t\t\tTraffic Monitor(CTRL+C to exit)"
dict={'10.0.0.6':5,'10.0.0.22':33,'10.0.0.8':42} 

while (1):
	os.system('clear')
	print header
	print time.ctime(time.time())
	try:
		for item in dict:
			print item,'\t'+'#'*dict[item]
			dict[item]=dict[item]-1
			if dict[item]< 0: # delete idle IPs.
			   del( dict[item]) #  = random.randrange (1,65)
	except RuntimeError:
			pass
	time.sleep(1)
###################################################################


-- 
.:: MarcoLinux ::.

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="tcpdump.py"

#Fakes a tcpdump output
#tcpdump -nq -i eth0 dst host 10.0.0.3 and port 80 
#something like:
#18:31:27.854995 10.0.0.1.33209 > 10.0.0.3.80: tcp 0 (DF)

import time,random

while (1):
	print "%s 10.0.0.%s.%s > 10.0.0.3.80: tcp 0 (DF)"%(time.strftime('%X.%s'),random.randrange(1,25),random.randrange(1024,2500))
	time.sleep(0.5)
	

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="trafego.py"

import time,os,random
header="\t\t\t\tMonitor Traffic"
dict={'10.0.0.6':5,'10.0.0.22':3,'10.0.0.3':2}
while (1):
	os.system('clear')
	print header
	print time.ctime(time.time())
	try:
		for item in dict:
			print item,'\t'+'#'*dict[item]
			dict[item]=dict[item]-1
			if dict[item]< 0: 
			    dict[item] = random.randrange (1,65)
	except RuntimeError:
			pass
	time.sleep(1)

--fUYQa+Pmc3FrFX/N--



From shalehperry@attbi.com  Tue Jun 18 23:43:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 18 Jun 2002 15:43:55 -0700 (PDT)
Subject: [Tutor] Dynamic change of dictionaries
In-Reply-To: <20020618223319.GA7284@marcolab.proconet>
Message-ID: <XFMail.20020618154355.shalehperry@attbi.com>

> 
> Given the code below, how do I change the dict dynamically with a output
> like the command above?
> 

why not simply ignore 0 count items?

for item in dict:
  if dict[item] == 0: continue

  # print status bars

if you want to preen items, the del dict[item] method is reasonable.



From adolfo158@yahoo.es  Wed Jun 19 00:01:45 2002
From: adolfo158@yahoo.es (=?iso-8859-1?q?Adolfo=20Aguirre?=)
Date: Wed, 19 Jun 2002 01:01:45 +0200 (CEST)
Subject: [Tutor] Install failure
Message-ID: <20020618230145.16179.qmail@web21208.mail.yahoo.com>

HI:

I just installed 2.2.1 and the installation process
went fine.
 
Problem:
The Python command line works, but the Pythonw.exe
doesn´t.

No window prompts argumenting errors or anything. Just
Nothing happens when you click on it.

I have W98SE, on a HP PIII-700 laptop.

Any help will be appreciated.

Adolfo 

_______________________________________________________________
Copa del Mundo de la FIFA 2002
El único lugar de Internet con vídeos de los 64 partidos. 
¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/



From jeff@ccvcorp.com  Wed Jun 19 00:07:55 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 18 Jun 2002 16:07:55 -0700
Subject: [Tutor] Install failure
References: <20020618230145.16179.qmail@web21208.mail.yahoo.com>
Message-ID: <3D0FBD4B.B3FA7CB2@ccvcorp.com>

Adolfo Aguirre wrote:

> Problem:
> The Python command line works, but the Pythonw.exe
> doesn4t.
>
> No window prompts argumenting errors or anything. Just
> Nothing happens when you click on it.

The pythonw.exe is not intended to be used alone -- it's intended to
run other scripts, without opening a console window.  Typically, this
is for launching scripts that have their own GUI (such as Tkinter or
wxPython scripts) -- you can type (from a DOS prompt, or at
Start-->Run) 'pythonw myscript.py', or create a shortcut with that as
the target, and your script will run without the extra blank console
window that would appear if you used python.exe instead of
pythonw.exe.  I believe (though I haven't tried it) that pythonw.exe
should even work if you drag&drop a script file onto it in Explorer.
But, since pythonw.exe has no user interface of its own, it has no
apparent effect if you just double-click on it.  (You start
pythonw.exe, it has no script to run, so it exits -- without ever
opening a window that you can see.)

Hope this makes sense.

Jeff Shannon
Technician/Programmer
Credit International





From beercanz@hotmail.com  Wed Jun 19 04:23:34 2002
From: beercanz@hotmail.com (Guess Who? Me)
Date: Wed, 19 Jun 2002 03:23:34 +0000
Subject: [Tutor] List help...
Message-ID: <F58DovvQ0Puz63Bma4R0001c25c@hotmail.com>

<html><div style='background-color:'><DIV>I'm studying the python tutorial at <A href="http://www.honors.montana.edu/~jjc/easytut/easytut/node10.html">http://www.honors.montana.edu/~jjc/easytut/easytut/node10.html</A></DIV>
<DIV><PRE>and this came up...</PRE><PRE>## This program runs a test of knowledge

true = 1
false = 0

# First get the test questions
# Later this will be modified to use file io.
def get_questions():
    # notice how the data is stored as a list of lists
    return [["What color is the daytime sky on a clear day?","blue"],\
            ["What is the answer to life, the universe and everything?","42"],\
            ["What is a three letter word for mouse trap?","cat"]]
</PRE><PRE># This will test a single question
# it takes a single question in
# it returns true if the user typed the correct answer, otherwise false
def check_question(question_and_answer):
    #extract the question and the answer from the list
    question = question_and_answer[0]
    answer = question_and_answer[1]
    # give the question to the user
    given_answer = raw_input(question)
    # compare the user's answer to the testers answer
    if answer == given_answer:
        print "Correct"
        return true
    else:
        print "Incorrect, correct was:",answer
        return false
</PRE><PRE># This will run through all the questions
def run_test(questions):
    if len(questions) == 0:
        print "No questions were given."
        # the return exits the function
        return
    index = 0
    right = 0
    while index &lt; len(questions):
        #Check the question
        if check_question(questions[index]):
            right = right + 1
        #go to the next question
        index = index + 1
    #notice the order of the computation, first multiply, then divide
    print "You got ",right*100/len(questions),"% right out of",len(questions)

#now lets run the questions
run_test(get_questions())
</PRE><PRE>How is the information stored as a list for the questions and answers?</PRE><PRE>I don't get the form..a list inside a list. Then it took question_and_answer, and used [0] and [1]</PRE><PRE>to get the values stored at the first and second positions in the list right?</PRE><PRE>Basically - how is this structured to work the way it does? I can't seem to figure out</PRE><PRE>how the answer and question are extracted...</PRE><PRE>&nbsp;</PRE><PRE>Thanks!</PRE></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM505401/44'>http://explorer.msn.com</a>.<br></html>



From shalehperry@attbi.com  Wed Jun 19 04:53:14 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 18 Jun 2002 20:53:14 -0700 (PDT)
Subject: [Tutor] List help...
In-Reply-To: <F58DovvQ0Puz63Bma4R0001c25c@hotmail.com>
Message-ID: <XFMail.20020618205314.shalehperry@attbi.com>

first, please do not send html to mailing lists, not everyone wants to see html.

> How is the information stored as a list for the questions and
> answers? I don't get the form..a list inside a list. Then it took
> question_and_answer, and used [0] and [1] to get the values stored
> at the first and second positions in the list right? Basically -
> how is this structured to work the way it does? I can't seem to figure
> out how the answer and question are
> extracted... Thanks!

one of the best things about python is that you can run it interactively and
seek guidance directly from python itself.

$ python
>>> a_list = ['betty', 'veronica', 'sue']
>>> a_list
['betty', 'veronica', 'sue']
>>> len(a_list)
3
>>> a_list[0]
'betty'
>>> a_list[1]
'veronica'
>>> a_list[2]
'sue'
>>> a_list[3]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IndexError: list index out of range

In python a list is an indexed ordering of items.  The count starts at 0 and
goes to len(list) - 1.

A list can hold practically anything in python.  The example you had was
questions and answers.  Let's examine that now.

q_and_a = [['What is your name?', 'Sean'],
           ['What is your quest?', 'To seek the Holy Grail'],
           ['What is the air speed of a swallow?', 'African or European?']]

now, let's replace the questions and answers with numbers to make it easier to
see: [ [1,2], [3,4], [5,6] ].  As you can see we have here a list containing 3
lists.  So q_and_a[0] returns [1,2] in the numerical example or ['What is your
name?', 'Sean'] in the real example.

>>> q_and_a[0][0] # index the first item's first item
'What is your name?'
>>> q_and_a[0][1]
'Sean'

or

>>> block = q_and_a[0]
>>> block[1]
'Sean'

or

>>> answer = block[1]
>>> answer
'Sean'

or even

>>> question, answer = q_and_a[0]
>>> question
'What is your name?'
>>> answer
'Sean'

That last one translates as this:

(question, answer) = ['What is your name?', 'Sean']

and the first item goes to the first variable and the second to the second and
so on.

Hope this helps some.



From alan.gauld@bt.com  Wed Jun 19 10:29:11 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jun 2002 10:29:11 +0100
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C673@mbtlipnt02.btlabs.bt.co.uk>

First, I saw your message where you got it working - good, 
however there are some concepts obviously not quite 
clear yet so here is an attempt to pick up the 
loose ends....

> >    def doSave(self):        # inside Pyshell class
> 
>     I can't use self in "def doSave(self):" because the 
> doSave function is actually inside PyShell.__iniT__. 

You use self when defining the method at the class level.
You have chosen(as Danny suggested) to put the event handler 
inside init. Thats OK and you don't need the self parameter.

I suggeted putting the event handler at the class level, 
in which case you do neeed self. Its really a matter of 
personal preference.

> If I use self and place this function
> inside PyShell but outside of __init__ I get an error 
> claiming the function is asking for on arument but none 
> are given. 

Nope, you got that error when you put the method in the class 
but *did not* use self. It complained because the class passed 
it the object as self but the function didn't expect it!

class C:
  def ok(self):
    print 'ok'
  def bad():  # no self defined
    print 'oops!'
  def master(self):
    self.bad()  # class calls C.bad(self) get error message

c = C()
c.ok()
c.master()  # error here


> If I place the function inside
> __init__ everything works except for the 
> "self.saveText(filename)" portion
> because there is no instance of self inside the function?

Correct, that's why I prefer event handlers to be defined 
at the class level. This is about 'scoping' or 'namespaces'.

Inside a *function* (including one defined inside a method)
you can see local variables, parameters and module level 
names but not class level names. Inside a method you can see
the same but since one of the parameters is selfyou thus get 
access to the object attributes.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From pythontutor@venix.com  Wed Jun 19 13:18:52 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Wed, 19 Jun 2002 08:18:52 -0400
Subject: [Tutor] Dynamic change of dictionaries
References: <20020618223319.GA7284@marcolab.proconet>
Message-ID: <3D1076AC.9030104@venix.com>

Two non-python thoughts about what you are trying to do:

MRTG provides perl and C code to issue SNMP requests to collect traffic
statistics, graph the stats, and display the graphs in a web page.
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
MRTG: The Multi Router Traffic Grapher
This may be over-kill for your purposes.

If you are tracking web usage, the squid proxy server would collect stats
while also providing caching.
http://www.squid-cache.org/
Squid Web Proxy Cache

Marc wrote:

> Hi people,
> I need to make a simple monitor for my network.
> I need to monitor how much each machine is using the bandwidth.
> The first tool that comes to mind is tcpdump. So far Im able to see how
> much a given IP shows up with:
> # tcpdump -nq -i eth0 dst host 10.15.50.3 and port 80
> but i need to show it "graphically".
> 
> Some examples to show what I mean:
> 
> The following program fakes a tcpdump output for easy testing.
> # fakeDump.py
> 
> 18:57:28.1024437448 10.0.0.8.2279 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:28.1024437448 10.0.0.19.1792 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:29.1024437449 10.0.0.20.1570 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:29.1024437449 10.0.0.22.2045 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:30.1024437450 10.0.0.6.2114 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:30.1024437450 10.0.0.8.1487 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:31.1024437451 10.0.0.8.1653 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:31.1024437451 10.0.0.14.2290 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:32.1024437452 10.0.0.10.1523 > 10.0.0.3.80: tcp 0 (DF)
> 18:57:32.1024437452 10.0.0.9.2290 > 10.0.0.3.80: tcp 0 (DF)
> 
> The interesting part here is the ip number: 
> I need is to tell how much 10.0.0.8 shows up.
> And 10.0.0.6 .
> And 10.0.0.22.
> And .... You get the idea.
> So I can show it like a gauge. Screenshots :)
> Pay attention to 10.0.0.6 and how it "disappear" due to no traffic:
> 
> 10.0.0.8   ######
> 10.0.0.6   ####
> 10.0.0.22  ##############
> 10.0.0.99  ########	
> 
> 
> Some minutes later:
> 
> 10.0.0.8   #######################################
> 10.0.0.6   #
> 10.0.0.22  #########
> 10.0.0.99  #########################	
> 
> Some minutes later:
> 
> 10.0.0.8   #######################################
> 10.0.0.22  #########
> 10.0.0.99  #########################	
> 
> 
> 
> I was thinking about a dictionary.
> 
> 'IP' : number of show up in X minutes
> dict={'10.0.0.6':5,'10.0.0.22':33,'10.0.0.8':42} 
> 
> 
> Given the code below, how do I change the dict dynamically with a output
> like the command above?
> 
> Thanks in advance for _any_ help.
> 
> 
> ####################################################################
> # simulates a traffic monitor
> import time,os,random
> 
> header="\t\t\tTraffic Monitor(CTRL+C to exit)"
> dict={'10.0.0.6':5,'10.0.0.22':33,'10.0.0.8':42} 
> 
> while (1):
> 	os.system('clear')
> 	print header
> 	print time.ctime(time.time())
> 	try:
> 		for item in dict:
> 			print item,'\t'+'#'*dict[item]
> 			dict[item]=dict[item]-1
> 			if dict[item]< 0: # delete idle IPs.
> 			   del( dict[item]) #  = random.randrange (1,65)
> 	except RuntimeError:
> 			pass
> 	time.sleep(1)
> ###################################################################
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> #Fakes a tcpdump output
> #tcpdump -nq -i eth0 dst host 10.0.0.3 and port 80 
> #something like:
> #18:31:27.854995 10.0.0.1.33209 > 10.0.0.3.80: tcp 0 (DF)
> 
> import time,random
> 
> while (1):
> 	print "%s 10.0.0.%s.%s > 10.0.0.3.80: tcp 0 (DF)"%(time.strftime('%X.%s'),random.randrange(1,25),random.randrange(1024,2500))
> 	time.sleep(0.5)
> 	
> 
> 
> ------------------------------------------------------------------------
> 
> import time,os,random
> header="\t\t\t\tMonitor Traffic"
> dict={'10.0.0.6':5,'10.0.0.22':3,'10.0.0.3':2}
> while (1):
> 	os.system('clear')
> 	print header
> 	print time.ctime(time.time())
> 	try:
> 		for item in dict:
> 			print item,'\t'+'#'*dict[item]
> 			dict[item]=dict[item]-1
> 			if dict[item]< 0: 
> 			    dict[item] = random.randrange (1,65)
> 	except RuntimeError:
> 			pass
> 	time.sleep(1)
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From sarmstrong13@mac.com  Wed Jun 19 14:30:12 2002
From: sarmstrong13@mac.com (SA)
Date: Wed, 19 Jun 2002 08:30:12 -0500
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C673@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <B935F194.80AD%sarmstrong13@mac.com>

I see what you mean.

To get the method to work your way, I have to change a few things in
PyShell.__init__:

                self.f = Frame(top)
                self.f.pack()

Instead of:

                f = Frame(top)
                f.pack()

That would change your method to the following:

        def doSave(self):
                SaveDialog = Saving(self.f)
                filename = SaveDialog.getName()
                self.saveText(filename)
                del(saveDialog)

This works. If I do not change the items, I get and undefined f error when I
try to save.

Another question. SaveText in self.saveText is a user defined method
correct? It takes the text from the self.t1 object and loads it into the
filename object, correct? Or is selfText a method from another module I did
not import, because without the user defined method I get an error saying
PyShell instance has no attribute saveText.

One more cool thing I think I may have learned from this experience:

The def methods in the class are attributes to the object class.
Is this correct?

(He, He, he, he... This is so cool now.)(I love it when this stuff starts to
come together and make sense)

So self defines the variables inside the defined object attribute and allows
those variables to be used outside of the method and elsewhere in the class
object, correct? Does this also allow the variable to be used outside the
class, globally? Is this how we were able to pass the data inside the apply
class from MyDialog to PyShell by using the return command?


Thanks. This has been a wonderful and very big help.

SA




From alan.gauld@bt.com  Wed Jun 19 14:48:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jun 2002 14:48:24 +0100
Subject: [Tutor] More Tkinter Help Please  [Dialog windows]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C678@mbtlipnt02.btlabs.bt.co.uk>

> I see what you mean.
> 
> To get the method to work your way, I have to change a few things in
> PyShell.__init__:
> 
>                 self.f = Frame(top)
>                 self.f.pack()

Correct, looks like you have it now.

> Another question. SaveText in self.saveText is a user defined method
> correct? 

Correct.

> It takes the text from the self.t1 object and loads 
> it into the filename object

More specifically the *file* object created when you use 
the filename *string* to open the file. Pedantics.

> PyShell instance has no attribute saveText.

Not until you define the method.

> The def methods in the class are attributes to the object class.
> Is this correct?

Absolutely. Classes have attributes which are either methods 
or data. Since functions in Python are objects too the method 
*names* are just attributes pointing to function objects...
In exactly the same way as the other attribbute names just 
point to raw data items. At that level there is very little 
difference between a method and a member data variable

> (He, He, he, he... This is so cool now.)(I love it when this 
> stuff starts to come together and make sense)

:-)
Looks like the light it coming on.

> So self defines the variables inside the defined object 
> attribute and allows those variables to be used outside 
> of the method and elsewhere in the class

Correct.

> Does this also allow the variable to be used outside the
> class, globally? 

No, because self is only visible inside the class definition.
Of course if you write a method that passes self back as a return value then
the reciever can use it to access the class:

class C:
  def f(self):
     print 'I'm f'
     return self
  def spam(self): print 'boo!')

c = C()
d = c.f()  # prints message and returns self
d.spam()   # prints boo! coz d and c now point to the same C instance

> Is this how we were able to pass the data 
> inside the apply class from MyDialog to PyShell by 
> using the return command?

We didn't. We kept a reference to the dialog when we created it 
then used that reference to call the getName() method. There was 
no need to pass anything back to the PyShell, it was all done 
by the PyShell requesting the data from the dialog. This is all 
good client-server style programming where the server(dialog here) 
performs tasks on demand from the client(pyshell here).  
This ensures that the dialog is reusable by other clients since 
it doesn't know who/what created/called it.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From einarth@decode.is  Wed Jun 19 15:14:37 2002
From: einarth@decode.is (Einar Th. Einarsson)
Date: Wed, 19 Jun 2002 14:14:37 +0000
Subject: [Tutor] Font sizes in Idle
Message-ID: <200206191414.38649.einarth@decode.is>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hey y'all

Does anyone know how to make Idle run with larger fonts? Or have any tips i=
n=20
that general directions?

When I start Idle it displays the code in ca. 6-7pt letters, which basicall=
y=20
sucks as I can't read that small a print (which has frequently landed me in=
=20
legal troubles, but that's besides the point ;)

I'm using Python 2.2 on RedHat 7.2. Help would be greatly appreciated.

- --=20
A conclusion is simply the place where you got tired of thinking.

Yours etc.
    Einar Th.

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBPRCRzW1/ORZtyd/tEQLzyACbBRFLHrVIphGpk/E01BCfefXj6U0AoLH+
r3uyNeNcorPtu8RGK3ClTGp0
=3DkrbZ
-----END PGP SIGNATURE-----




From alan.gauld@bt.com  Wed Jun 19 17:07:59 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jun 2002 17:07:59 +0100
Subject: [Tutor] Font sizes in Idle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67C@mbtlipnt02.btlabs.bt.co.uk>

There is a FAQ entry on this someplace I think.

Basically you have to go into one of the IDLE source 
files(editor.py?) and change the fonts manually 
- they are hard coded!

Unless that's changed recently, I haven't had to do that for 
a few releases since I'm not using IDLE on Linux...

Alan g.

> Does anyone know how to make Idle run with larger fonts? Or 
> have any tips in that general directions?



From michael.williams@st-annes.oxford.ac.uk  Wed Jun 19 17:58:33 2002
From: michael.williams@st-annes.oxford.ac.uk (Michael Williams)
Date: Wed, 19 Jun 2002 17:58:33 +0100
Subject: [Tutor] Font sizes in Idle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67C@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67C@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020619165833.GA1674@st-annes.oxford.ac.uk>

On Wed, Jun 19, 2002 at 05:07:59PM +0100, alan.gauld@bt.com wrote:
> There is a FAQ entry on this someplace I think.

There's some documentation from a CVS log on this here:

http://mail.python.org/pipermail/idle-dev/2001-October/000718.html

> Unless that's changed recently, I haven't had to do that for 
> a few releases since I'm not using IDLE on Linux...

For anyone interested, you might prefer IDLEfork which is much more
aggresively developed and shaping up into quite a powerful Python editor
(it's no Vi but nothing is ;->). See:

<http://idlefork.sourceforge.net>

-- 
Michael



From urnerk@qwest.net  Wed Jun 19 18:10:31 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 19 Jun 2002 10:10:31 -0700
Subject: [Tutor] Font sizes in Idle
In-Reply-To: <200206191414.38649.einarth@decode.is>
Message-ID: <5.1.1.6.0.20020619100750.026d6b20@urnerk/pop.ptld.qwest.net>

At 02:14 PM 6/19/2002 +0000, Einar Th. Einarsson wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hey y'all
>
>Does anyone know how to make Idle run with larger fonts? Or have any tips in
>that general directions?

Hi Einar --

There are some config files in the IDLE directory.  For your setup,
I think config-unix is the right place to change font size.  I've blown
mine up to 14 or something huge like that.  I know what you mean
about the tiny defaults.

Alan must have used an older version, as font sizes are not hard coded
in a .py file.

Just the other day, I switched to the forked IDLE on my Mandrake 8.2
setup, but I know the config business with user-defined font sizes is
the same in the regular IDLE.

>When I start Idle it displays the code in ca. 6-7pt letters, which basically
>sucks as I can't read that small a print (which has frequently landed me in
>legal troubles, but that's besides the point ;)
>
>I'm using Python 2.2 on RedHat 7.2. Help would be greatly appreciated.
>
>- --
>A conclusion is simply the place where you got tired of thinking.
>
>Yours etc.
>     Einar Th.

Kirby





From dyoo@hkn.eecs.berkeley.edu  Wed Jun 19 18:03:15 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 19 Jun 2002 10:03:15 -0700 (PDT)
Subject: [Tutor] Font sizes in Idle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67C@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.44.0206191000040.29639-100000@hkn.eecs.berkeley.edu>


On Wed, 19 Jun 2002 alan.gauld@bt.com wrote:

> There is a FAQ entry on this someplace I think.
>
> Basically you have to go into one of the IDLE source
> files(editor.py?) and change the fonts manually
> - they are hard coded!
>
> Unless that's changed recently, I haven't had to do that for a few
> releases since I'm not using IDLE on Linux...

It's changed recently; the IDLE developers pushed out the configuration
stuff into a set of files called config-win.txt, config-unix.txt, or
config-mac.txt.  Einar is running on Red Hat, so config-unix.txt is the
file to fix.


Good luck!




From urnerk@qwest.net  Wed Jun 19 18:14:38 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 19 Jun 2002 10:14:38 -0700
Subject: [Tutor] Install failure
In-Reply-To: <20020618230145.16179.qmail@web21208.mail.yahoo.com>
Message-ID: <5.1.1.6.0.20020619101126.026d44d0@urnerk/pop.ptld.qwest.net>

The Windows installer should have created an icon link to IDLE
which is the graphical shell available out of the box.  This is
a great environment in which to first familiarize yourself with
Python programming, as the DOS shell is unsuitable as a
shell environment, and you certainly don't want to get stuck
with Notepad for editing your code (IDLE's text editor is color
coded -- gvim for Windows is another option, with syntax
files for way more languages than Python).

Pythonw.exe by itself is not a shell, but a way of invoking
other scripts without opening a console window (as was
noted above).

Kirby

At 01:01 AM 6/19/2002 +0200, you wrote:
>HI:
>
>I just installed 2.2.1 and the installation process
>went fine.
>
>Problem:
>The Python command line works, but the Pythonw.exe
>doesn=B4t.
>
>No window prompts argumenting errors or anything. Just
>Nothing happens when you click on it.
>
>I have W98SE, on a HP PIII-700 laptop.
>
>Any help will be appreciated.
>
>Adolfo





From flaxeater@yahoo.com  Wed Jun 19 19:29:49 2002
From: flaxeater@yahoo.com (Chad Crabtree)
Date: Wed, 19 Jun 2002 11:29:49 -0700 (PDT)
Subject: [Tutor] A Technical Question
In-Reply-To: <20020619160004.12742.50274.Mailman@mail.python.org>
Message-ID: <20020619182949.22017.qmail@web11602.mail.yahoo.com>

I have been playing around with TKinter.  I have done
pretty much what I have set about.  I made a little
text box thingy.  Any way I wanted to make a delete
button that would delete the last line of the text
box.
However I can not figure out how to interogate the
text box so that it tells me how many indexes it has.

Here is my Code right now.  Mind you it's just a toy,
with pretend levers and switches.

from Tkinter import *

class Application(Frame):

    def right(self):
        index=str(self.counter) + "\n"
        self.textArea.insert(END,index)
        self.counter=self.counter+1
        self.textArea.see(END)

    def addtotext(self,item):
        self.textArea.insert(END,item)
        

    def delete(self):
        self.textArea.insert("DELETE",END)

    def __init__(self, master=None):
        self.counter=3
        self.root=Frame.__init__(self,master)
        self.grid()
        self.main=Frame(self.root,relief="groove",
border=5)
        self.main.grid(row=0,column=0,columnspan=2)
        
        self.subF=Frame(self.main,
relief="raised",border=5)
       
self.subF2=Frame(self.subF,relief="sunken",border=3)
        
        self.subF.grid(row=0,column=0)
        self.subF2.grid(row=0,column=0)
        

self.textArea=Text(self.subF2,height="12",width="30",bg="blue",fg="yellow")
        self.textArea.grid(column=0,row=0)
        self.scrBar=Scrollbar(self.subF2)
        self.scrBar.grid(column=1,row=0,sticky=N+S)
       
self.scrBar.config(command=self.textArea.yview)
       
self.textArea.config(yscrollcommand=self.scrBar.set)
        
	self.output=['Hello World\n','How are you doing?\n. 
I am doing Very well.\n\n\nThere
hahahaha',str(8)+"\n",str(self.counter) + "\n"]
        self.textArea.insert(END,self.output[0])
        self.textArea.insert(END,self.output[1])
        self.textArea.insert(END,self.output[2])
        self.textArea.insert(END,self.output[3])

       
self.frmButton=Frame(self.root,border=2,relief="sunken")
       
self.frmButton.grid(row=1,column=0,columnspan=2,sticky=N+E+S+W)
        
                
        self.quitButton=Button(self.frmButton,text="
Quit ",command=self.quit)
       
self.quitButton.grid(column=0,row=0,sticky=N+E+S+W,padx=10)

 
        self.btnWrite=Button(self.frmButton,text="
Write",command=self.right)
       
self.btnWrite.grid(column=1,row=0,sticky=N+E+S+W,padx=10)

       
self.btnDel=Button(self.frmButton,text="Delete",command=self.delete)
       
self.btnDel.grid(column=2,row=0,sticky=N+E+S+W,padx=10)


            
app=Application()
app.master.title("Sample application")
app.mainloop()

Thank you.


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From einarth@decode.is  Wed Jun 19 19:37:45 2002
From: einarth@decode.is (Einar Th. Einarsson)
Date: Wed, 19 Jun 2002 18:37:45 +0000
Subject: [Tutor] Font sizes in Idle
Message-ID: <200206191837.45766.einarth@decode.is>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scratch that...just found it....


> Excellent, thnx. The config files was what I was looking for.  It's a bit=
=20
> unusual to keep the config files there (used to finding them in either /e=
tc
> or in ~/.progname :P)
>
> Since I'm rambling already I've got another one for you guys (propably ju=
st
> as simple once you know the answer):
>
>How do I pass cmd line args to a program I wan't to debug? I.e. something
> like 'debug with arguments'  or 'run with arguments'. Any debugger is fine
> (pdb or pydb (with or without ddd).  Preferably without manually editing =

> sys.argv each time I run it....
>

- --=20
Who's General Failure & why's he reading my disk?

Yours etc.
    Einar Th.

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBPRDPeW1/ORZtyd/tEQK5aACfQ37rcdCow3puLlmpvW5gv9sKFIMAn3AC
PEkl/zmYt19D2zb1zHhe3SVI
=3DvT9n
-----END PGP SIGNATURE-----




From einarth@decode.is  Wed Jun 19 19:30:34 2002
From: einarth@decode.is (Einar Th. Einarsson)
Date: Wed, 19 Jun 2002 18:30:34 +0000
Subject: [Tutor] Font sizes in Idle
In-Reply-To: <5.1.1.6.0.20020619100750.026d6b20@urnerk/pop.ptld.qwest.net>
References: <5.1.1.6.0.20020619100750.026d6b20@urnerk/pop.ptld.qwest.net>
Message-ID: <200206191830.36198.einarth@decode.is>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Excellent, thnx. The config files was what I was looking for.  It's a bit=20
unusual to keep the config files there (used to finding them in either /etc=
=20
or in ~/.progname :P)

Since I'm rambling already I've got another one for you guys (propably just=
 as=20
simple once you know the answer):

How do I pass cmd line args to a program I wan't to debug? I.e. something l=
ike=20
'debug with arguments'  or 'run with arguments'. Any debugger is fine (pdb =
or=20
pydb (with or without ddd).  Preferably without manually editing sys.argv=20
each time I run it....

- --=20
"The axiom 'An honest man has nothing to fear from the police'
is currently under review by the Axiom Review Board"
	-- Terry Prachett, "Men At Arms"

Yours etc.
    Einar Th.


On Wednesday 19 June 2002 17:10, Kirby Urner wrote:
> At 02:14 PM 6/19/2002 +0000, Einar Th. Einarsson wrote:
> >-----BEGIN PGP SIGNED MESSAGE-----
> >Hash: SHA1
> >
> >Hey y'all
> >
> >Does anyone know how to make Idle run with larger fonts? Or have any tips
> > in that general directions?
>
> Hi Einar --
>
> There are some config files in the IDLE directory.  For your setup,
> I think config-unix is the right place to change font size.  I've blown
> mine up to 14 or something huge like that.  I know what you mean
> about the tiny defaults.
>
> Alan must have used an older version, as font sizes are not hard coded
> in a .py file.
>
> Just the other day, I switched to the forked IDLE on my Mandrake 8.2
> setup, but I know the config business with user-defined font sizes is
> the same in the regular IDLE.
>
> >When I start Idle it displays the code in ca. 6-7pt letters, which
> > basically sucks as I can't read that small a print (which has frequently
> > landed me in legal troubles, but that's besides the point ;)
> >
> >I'm using Python 2.2 on RedHat 7.2. Help would be greatly appreciated.
> >
> >- --
> >A conclusion is simply the place where you got tired of thinking.
> >
> >Yours etc.
> >     Einar Th.
>
> Kirby


-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBPRDNym1/ORZtyd/tEQI1wwCglatPhyGatEQjk6cccdk4J92IwM4AoID3
xdGVOIXgOdaDTuUbxNYfmdMU
=3D+sdI
-----END PGP SIGNATURE-----




From marcolinux@linuxbr.com.br  Wed Jun 19 21:47:51 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Wed, 19 Jun 2002 17:47:51 -0300
Subject: [Tutor] Dynamic change of dictionaries
In-Reply-To: <XFMail.20020618154355.shalehperry@attbi.com>
References: <20020618223319.GA7284@marcolab.proconet> <XFMail.20020618154355.shalehperry@attbi.com>
Message-ID: <20020619204751.GA2675@marcolab.proconet>

--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Sean 'Shaleh' Perry (shalehperry@attbi.com) wrote:

> why not simply ignore 0 count items?
> 
> for item in dict:
>   if dict[item] == 0: continue
> 
>   # print status bars
> 
> if you want to preen items, the del dict[item] method is reasonable.

Thanks for reply.

(And thanks for Lloyd Kvam <pythontutor@venix.com>.The tools you cited
are overkill right now. Besides, I want to play with python a little
bit. I didn't received your mail, read it in tutor mail archive.
I wonder how much fun I have been missing lately :)

Hehe, no need to "preen" right now, but if u consider it have to be seem
from across the room, the bars are more than welcome :)
Your method of ignore item when 0 is nice and have a good side effect: I
know that an IP acessed the proxy, thus it is alive. However, it makes
a "graph" with too many lines. That's why I want to delete zeroed items, to
avoid clutter.

I've made a new version of the simulator. And the more I play with it,
the more I want to changeit.For example, do you guys know how to change
the color of terminal with codes?
I've tried (from /etc/rc.d/functions):
(SETCOLOR_FAILURE="echo -en \\033[1;31m")

$ python
>>> red='\\033[1;31m'
>>> print red,'supposed 2 b red'
\033[1;31m supposed 2 b red

:(. Im sure it's trivial to do , but I dont know how.
Sugestions? Thanks in advance.



--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="traffic.py"

"""
Show a network traffic gauges
"""
import random,time,os,sys

dict={}
cnt=100

#talkin'bout preen :)
lft='\n'*7+'\t\t\t\t'
splashscreen=lft+'  Traffic Monitor\n'+lft+'Python Powered (TM)'

def increment(item):	
	try:
		 dict[item] += 1
	except KeyError:
		 dict[item] = 1


def decrement():
	if not dict.__len__: return
	try:
		for item in dict:
	        	if dict[item] == 0: continue #del (dict[item])
	        	else: dict[item] -= 1
	except RuntimeError:
			pass


os.system('clear')
print splashscreen
time.sleep(2)
os.system('clear')

while cnt:
	os.system('clear')
	#print dict
	for item in dict:
		print item,'\t'+'#'*dict[item]
	ip ='10.15.50.%d' % random.randrange(1,12)
	increment(ip)
	if not (cnt % 10): 
		decrement()
		print cnt
		cnt=100
	cnt-=1
	time.sleep(1)

--uAKRQypu60I7Lcqm--



From glingl@aon.at  Thu Jun 20 00:21:38 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 20 Jun 2002 01:21:38 +0200
Subject: [Tutor] A Technical Question
References: <20020619182949.22017.qmail@web11602.mail.yahoo.com>
Message-ID: <006001c217e8$0fc7a970$1615a8c0@mega>

An interactive session with your app shows:

>>>
app.textArea.get(1.0,10000.0).split('\n')
['Hello World', 'How are you doing?', '. I am doing Very well.', '', '',
'Therehahahaha8', '3', '', '']
>>> # don't know if there is a better way than 10000.0 for length of text
>>> len(app.textArea.get(1.0,10000.0).split('\n'))
9
>>> app.textArea.delete(8.0,9.0)
>>> app.textArea.get(1.0,10000.0).split('\n')
['Hello World', 'How are you doing?', '. I am doing Very well.', '', '',
'Therehahahaha8', '3', '']
>>> len(app.textArea.get(1.0,10000.0).split('\n'))
8
>>> app.textArea.delete(7.0,8.0)
>>> app.textArea.get(1.0,10000.0).split('\n')
['Hello World', 'How are you doing?', '. I am doing Very well.', '', '',
'Therehahahaha8', '']
>>> len(app.textArea.get(1.0,10000.0).split('\n'))
7
>>> app.textArea.delete(6.0,7.0)
>>> # last newline seems undeletable
>>> app.textArea.get(1.0,10000.0).split('\n')
['Hello World', 'How are you doing?', '. I am doing Very well.', '', '', '']
>>>

So I can put this - with minor adaptions - into your delete method:

    def delete(self):
        l = len(self.textArea.get(1.0,10000.0).split('\n'))
        start = str(l-1)+'.0'
        end = str(l)+ '.0'
        print l, start, end  # comment out after testing!
        self.textArea.delete(start,end)

Sure, this is not very elegant, but it works.
In fact even this works:

    def delete(self):
        l = len(self.textArea.get(1.0,10000.0).split('\n'))
        self.textArea.delete(float(l-1),float(l))

... but it certainly reveals one of the less beautiful features of Tk(inter)

Gregor


----- Original Message -----
From: "Chad Crabtree" <flaxeater@yahoo.com>
To: <tutor@python.org>
Sent: Wednesday, June 19, 2002 8:29 PM
Subject: [Tutor] A Technical Question


> I have been playing around with TKinter.  I have done
> pretty much what I have set about.  I made a little
> text box thingy.  Any way I wanted to make a delete
> button that would delete the last line of the text
> box.
> However I can not figure out how to interogate the
> text box so that it tells me how many indexes it has.
>
> Here is my Code right now.  Mind you it's just a toy,
> with pretend levers and switches.
>
> from Tkinter import *
>
> class Application(Frame):
>
>     def right(self):
>         index=str(self.counter) + "\n"
>         self.textArea.insert(END,index)
>         self.counter=self.counter+1
>         self.textArea.see(END)
>
>     def addtotext(self,item):
>         self.textArea.insert(END,item)
>
>
>     def delete(self):
>         self.textArea.insert("DELETE",END)
>
>     def __init__(self, master=None):
>         self.counter=3
>         self.root=Frame.__init__(self,master)
>         self.grid()
>         self.main=Frame(self.root,relief="groove",
> border=5)
>         self.main.grid(row=0,column=0,columnspan=2)
>
>         self.subF=Frame(self.main,
> relief="raised",border=5)
>
> self.subF2=Frame(self.subF,relief="sunken",border=3)
>
>         self.subF.grid(row=0,column=0)
>         self.subF2.grid(row=0,column=0)
>
>
>
self.textArea=Text(self.subF2,height="12",width="30",bg="blue",fg="yellow")
>         self.textArea.grid(column=0,row=0)
>         self.scrBar=Scrollbar(self.subF2)
>         self.scrBar.grid(column=1,row=0,sticky=N+S)
>
> self.scrBar.config(command=self.textArea.yview)
>
> self.textArea.config(yscrollcommand=self.scrBar.set)
>
> self.output=['Hello World\n','How are you doing?\n.
> I am doing Very well.\n\n\nThere
> hahahaha',str(8)+"\n",str(self.counter) + "\n"]
>         self.textArea.insert(END,self.output[0])
>         self.textArea.insert(END,self.output[1])
>         self.textArea.insert(END,self.output[2])
>         self.textArea.insert(END,self.output[3])
>
>
> self.frmButton=Frame(self.root,border=2,relief="sunken")
>
> self.frmButton.grid(row=1,column=0,columnspan=2,sticky=N+E+S+W)
>
>
>         self.quitButton=Button(self.frmButton,text="
> Quit ",command=self.quit)
>
> self.quitButton.grid(column=0,row=0,sticky=N+E+S+W,padx=10)
>
>
>         self.btnWrite=Button(self.frmButton,text="
> Write",command=self.right)
>
> self.btnWrite.grid(column=1,row=0,sticky=N+E+S+W,padx=10)
>
>
> self.btnDel=Button(self.frmButton,text="Delete",command=self.delete)
>
> self.btnDel.grid(column=2,row=0,sticky=N+E+S+W,padx=10)
>
>
>
> app=Application()
> app.master.title("Sample application")
> app.mainloop()
>
> Thank you.
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From ak@silmarill.org  Thu Jun 20 01:31:33 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Wed, 19 Jun 2002 20:31:33 -0400
Subject: [Tutor] Dynamic change of dictionaries
In-Reply-To: <20020619204751.GA2675@marcolab.proconet>
References: <20020618223319.GA7284@marcolab.proconet> <XFMail.20020618154355.shalehperry@attbi.com> <20020619204751.GA2675@marcolab.proconet>
Message-ID: <20020620003133.GA1587@ak.silmarill.org>

On Wed, Jun 19, 2002 at 05:47:51PM -0300, Marc wrote:
> Sean 'Shaleh' Perry (shalehperry@attbi.com) wrote:
> 
> > why not simply ignore 0 count items?
> > 
> > for item in dict:
> >   if dict[item] == 0: continue
> > 
> >   # print status bars
> > 
> > if you want to preen items, the del dict[item] method is reasonable.
> 
> Thanks for reply.
> 
> (And thanks for Lloyd Kvam <pythontutor@venix.com>.The tools you cited
> are overkill right now. Besides, I want to play with python a little
> bit. I didn't received your mail, read it in tutor mail archive.
> I wonder how much fun I have been missing lately :)
> 
> Hehe, no need to "preen" right now, but if u consider it have to be seem
> from across the room, the bars are more than welcome :)
> Your method of ignore item when 0 is nice and have a good side effect: I
> know that an IP acessed the proxy, thus it is alive. However, it makes
> a "graph" with too many lines. That's why I want to delete zeroed items, to
> avoid clutter.

You can skip drawing the graph if it's 0:

if 0:
    continue
else:
    draw_bar()

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From adolfo158@yahoo.es  Thu Jun 20 02:32:47 2002
From: adolfo158@yahoo.es (=?iso-8859-1?q?Adolfo=20Aguirre?=)
Date: Thu, 20 Jun 2002 03:32:47 +0200 (CEST)
Subject: [Tutor] COM server not starting
Message-ID: <20020620013247.55480.qmail@web21203.mail.yahoo.com>

Hi:

I intalled Python 2.2.1 and followed instructions for
starting the COM server as found on a downloaded
manual. It did not work. 
Comments:

1. The pages listed on the manual to firt start, and
then test the COM Server where not located where the
manual placed them.

2.  The Manual I am using is called "Python and
ActiveX Scripting" and below I include the text (only
a page)with the instructions I followed.

Adolfo

======>>>>

Python and ActiveX Scripting 

Important: The installers install (not register) the
new implementation. See Installing the AXScript
Implementation for details on setting up the new
implementation. 

This documentation covers the following topics: 
•	What is ActiveX Scripting? 
•	Why a new implementation? 
•	Installing the AXScript Implementation. 
•	Using the AXScript Implementation 
•	Debugging PyScript Code 

What is ActiveX Scripting? 
ActiveX Scripting is a technology which allows for
"plug-in" languages to be used by a host application.
Currently, the only hosts which support this
technology are provided by Microsoft - the best known
ones being Internet Explorer (V3 or better), and
Active Server Pages (aka Denali). 
To test or play with ActiveX Scripting, you will need
one of these hosts. 

Installing the AXScript Implementation. 
Note 
Please see the README.HTM in the win32com directory.
It contains a link to the "AXScript Demos" page. This
page allows you to automatically install the engine 
But here are the "manual installation" instructions. 
Installing either win32com or Pythonwin will install
the new implementation. All you need to is register
it. Perform these steps: 

•	Locate the win32com directory in Windows Explorer.
Change to the "win32com\AXScript\Client" directory. 
•	Locate the file "pyscript.py", and double-click on
this file. This should cause a "Python.exe" window to
appear, and a message appear telling you the server is
being registered. (All that need be done here is to
run "python.exe pyscript.py", which is what the above
procedure will do. However, you can execute that
command how-ever you like!) 

Then test it: 
•	Locate the "win32com\AXScript\Demos\ie" directory. 
•	Double-click on the "foo2.htm" file. You should see
Internet Explorer start up, and all buttons with text.
If any buttons are blank, it is likely that the server
is not correctly registered. (NOTE: If a "Debug
Window" appears minimised on your task-bar, it means
you are running the old implementation.) 
•	Click on the buttons. 

Using the AXScript Implementation 
The language name is "Python". 
The object model provided to Python is very similar to
that provided by VBScript or JScript. All global
functions (such as "alert()" in IE) are available, and
all objects are available by name (eg "MyForm" is used
to reference the form defined with that name in the
HTML. 

Python and Internet Explorer 
Python and IE work very well together. However, a key
difference to the JScript/VBScript implementations is
in "local variables". All objects are able to be fully
referenced, but not all objects are available as
"local variables". For example, in an event handler
for a form, you would expect the forms objects (eg,
buttons, text boxes, etc.) to be visible locally - ie,
you would expect "Text1.Value = 'New Value'" to work -
it doesn't! However, the explicit
"FormName.Text1.Value" does. 
Python and Active Server Pages (Denali) 
To use Python in Active Server Pages (Denali) you must
ensure the .ASP files are installed in a location
known to the Internet Server. 
There is a significant limitation when using scripts
enclosed with <% tags. The current version of Denali
strips all white-space from this code, making it
impossible to write "if" (or any other block)
statements in this context. Code that uses the <SCRIPT
Language="Python" RunAt="Server"> tag works as
expected. 
It should be noted that a design decision in Denali
makes it hard to mix and match the 2 styles. All code
in <% tags is executed before <SCRIPT tags, regardless
of their position in the source file. 
Debugging PyScript Code 
Debugging this code can make life interesting! Future
releases will support the Active Script Debugging
interface, but for now we must use other means. (Note
that this release nearly supports AXDebugging - in
fact, it looks exactly like it does - don't be
fooled!) 
Neither Internet Explorer or Denali have a good place
for Python "print" statements to go! To make matters
worse, Denali is usually run in an environment where
creating a window for such output is not possible. 
To solve this problem, a module called win32trace has
been written. This module allows one Python process to
generate output via a "print" statement, and another
unrelated Python process to display the data. This
works even if the Python process generating the output
is running under the context of a service, as Denali
does. 
To enable this debugging, simply "import
win32traceutil" at the start of your script (ie, in
the .HTM or .ASP file) - thats it! To actually see the
output as it is produced, start a DOS prompt, and run
the file "win32traceutil.py" (eg, "python.exe
win32traceutil.py") This will print all output from
all other Python processes (that have imported
win32traceutil) until you kill it with Ctrl+Break!) 
For further details, please see the win32trace
documentation for more details. 
 
•	For questions about Python and ActiveX Scripting,
send email to MHammond@skippinet.com.au (Mark
Hammond). 
Installing the AXScript Implementation. 
Note 
Please see the README.HTM in the win32com directory.
It contains a link to the "AXScript Demos" page. This
page allows you to automatically install the engine 
But here are the "manual installation" instructions. 
Installing either win32com or Pythonwin will install
the new implementation. All you need to is register
it. Perform these steps: 
•	Locate the win32com directory in Windows Explorer.
Change to the "win32com\AXScript\Client" directory. 
•	Locate the file "pyscript.py", and double-click on
this file. This should cause a "Python.exe" window to
appear, and a message appear telling you the server is
being registered. (All that need be done here is to
run "python.exe pyscript.py", which is what the above
procedure will do. However, you can execute that
command how-ever you like!) 
Then test it: 
•	Locate the "win32com\AXScript\Demos\ie" directory. 
•	Double-click on the "foo2.htm" file. You should see
Internet Explorer start up, and all buttons with text.
If any buttons are blank, it is likely that the server
is not correctly registered. (NOTE: If a "Debug
Window" appears minimised on your task-bar, it means
you are running the old implementation.) 
•	Click on the buttons. 
Using the AXScript Implementation 
The language name is "Python". 
The object model provided to Python is very similar to
that provided by VBScript or JScript. All global
functions (such as "alert()" in IE) are available, and
all objects are available by name (eg "MyForm" is used
to reference the form defined with that name in the
HTML. 
Python and Internet Explorer 
Python and IE work very well together. However, a key
difference to the JScript/VBScript implementations is
in "local variables". All objects are able to be fully
referenced, but not all objects are available as
"local variables". For example, in an event handler
for a form, you would expect the forms objects (eg,
buttons, text boxes, etc.) to be visible locally - ie,
you would expect "Text1.Value = 'New Value'" to work -
it doesn't! However, the explicit
"FormName.Text1.Value" does. 
Python and Active Server Pages (Denali) 
To use Python in Active Server Pages (Denali) you must
ensure the .ASP files are installed in a location
known to the Internet Server. 
There is a significant limitation when using scripts
enclosed with <% tags. The current version of Denali
strips all white-space from this code, making it
impossible to write "if" (or any other block)
statements in this context. Code that uses the <SCRIPT
Language="Python" RunAt="Server"> tag works as
expected. 
It should be noted that a design decision in Denali
makes it hard to mix and match the 2 styles. All code
in <% tags is executed before <SCRIPT tags, regardless
of their position in the source file. 
Debugging PyScript Code 
Debugging this code can make life interesting! Future
releases will support the Active Script Debugging
interface, but for now we must use other means. (Note
that this release nearly supports AXDebugging - in
fact, it looks exactly like it does - don't be
fooled!) 
Neither Internet Explorer or Denali have a good place
for Python "print" statements to go! To make matters
worse, Denali is usually run in an environment where
creating a window for such output is not possible. 
To solve this problem, a module called win32trace has
been written. This module allows one Python process to
generate output via a "print" statement, and another
unrelated Python process to display the data. This
works even if the Python process generating the output
is running under the context of a service, as Denali
does. 
To enable this debugging, simply "import
win32traceutil" at the start of your script (ie, in
the .HTM or .ASP file) - thats it! To actually see the
output as it is produced, start a DOS prompt, and run
the file "win32traceutil.py" (eg, "python.exe
win32traceutil.py") This will print all output from
all other Python processes (that have imported
win32traceutil) until you kill it with Ctrl+Break!) 
For further details, please see the win32trace
documentation for more details. 


_______________________________________________________________
Copa del Mundo de la FIFA 2002
El único lugar de Internet con vídeos de los 64 partidos. 
¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/



From jimmy_130@lycos.com  Thu Jun 20 02:59:14 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Wed, 19 Jun 2002 21:59:14 -0400
Subject: [Tutor] Need help with binary notation
Message-ID: <HHGLDNLDJAAIBBAA@mailcity.com>

Okay, I've got an assignment from school for the summer. Some of the problems state to express the problem in binary notation. So basically, my question would be, could Python help me with my homework? Oh, and ah.., hehe, I forgot what binary notation is. Anyone know what it is?


_________________________________________
Communicate with others using Lycos Mail for FREE!
http://mail.lycos.com/



From wilson@visi.com  Thu Jun 20 05:13:17 2002
From: wilson@visi.com (Tim Wilson)
Date: Wed, 19 Jun 2002 23:13:17 -0500
Subject: [Tutor] Generating SWFs on the fly using Ming and Python CGI
Message-ID: <20020620041317.GB27644@isis.visi.com>

Hi everyone,

I've got an interesting problem here and I'm hoping someone will have
some hints.

I'm finishing up a course on building Flash animations and I discovered
Ming (http://ming.sourceforge.net/), "an SWF output library and PHP
module." There is also a Python wrapper that makes it possible to do all
this from python. I told the professor at the beginning of the course
that I'd like to find a way to generate SWF files without using
Macromedia's Flash software (love my Linux box).

I thought it would be interesting to try to build a Flash SWF on the fly
using input from a Web form. Here's the code I've got at this point.
The problem is at the very end.

#!/usr/bin/python

from ming import *
import sys

s = SWFShape()
s.setLine(4, 0x7f, 0, 0)
s.setRightFill(s.addFill(0xff, 0, 0))
s.movePenTo(10, 10)
s.drawLineTo(310, 10)
s.drawLineTo(310, 230)
s.drawCurveTo(10, 230, 10, 10)

m = SWFMovie()
m.setDimension(320, 240)
m.setRate(12.0)
m.add(s)
m.nextFrame()

print """Content-type: application/x-shockwave-flash\n\n"""
m.save(sys.stdout)

You can see what the SWF should look like at
http://qwerk.org/~wilson/cgi-bin/shape.swf

There's no HTML form input at this point, I'm just trying to get Python
to generate the SWF and return it to the Web browser. FWIW, there is
some documentation at http://ming.sourceforge.net/docs/index.php?mode=py
that lists the various methods. (I generated the working SWF by calling
the 'save()' method of my SWFMovie object.)

Anyone have any ideas here?

-Tim

-- 
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From ram@digitalmethod.org  Thu Jun 20 06:38:36 2002
From: ram@digitalmethod.org (Ram Smith)
Date: Thu, 20 Jun 2002 15:38:36 +1000
Subject: [Tutor] Generating SWFs on the fly using Ming and Python CGI
In-Reply-To: <20020620041317.GB27644@isis.visi.com>
References: <20020620041317.GB27644@isis.visi.com>
Message-ID: <20020620053836.GA12064@digitalmethod.org>

On Wed, 19 Jun 2002, Tim Wilson wrote:

__snip
> 
> There's no HTML form input at this point, I'm just trying to get Python
> to generate the SWF and return it to the Web browser. FWIW, there is
> some documentation at http://ming.sourceforge.net/docs/index.php?mode=py
> that lists the various methods. (I generated the working SWF by calling
> the 'save()' method of my SWFMovie object.)
> 
> Anyone have any ideas here?

I think what your looking for is m.output()

Here is the docs:

http://ming.sourceforge.net/docs/swfmovie.php?mode=
--
w  http://www.digitalmethod.org
m  0414 866 965
<blink>12:00</blink>



From dyoo@hkn.eecs.berkeley.edu  Thu Jun 20 06:46:32 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 19 Jun 2002 22:46:32 -0700 (PDT)
Subject: [Tutor] Need help with binary notation
In-Reply-To: <HHGLDNLDJAAIBBAA@mailcity.com>
Message-ID: <Pine.LNX.4.44.0206192243100.13969-100000@hkn.eecs.berkeley.edu>


On Wed, 19 Jun 2002, James M Lang wrote:

> Okay, I've got an assignment from school for the summer. Some of the
> problems state to express the problem in binary notation. So basically,
> my question would be, could Python help me with my homework? Oh, and
> ah.., hehe, I forgot what binary notation is. Anyone know what it is?

"Binary notation"?  Beats me.  *grin*

By "binary notation", are they referring to the way that integers can be
represented as ones and zeros?  Hmmm... This is one where you probably
should ask for clarification from your instructor.

Sorry, dunno about this one.




From mhammond@skippinet.com.au  Thu Jun 20 02:57:58 2002
From: mhammond@skippinet.com.au (Mark Hammond)
Date: Thu, 20 Jun 2002 11:57:58 +1000
Subject: [Tutor] RE: COM server not starting
In-Reply-To: <20020620013247.55480.qmail@web21203.mail.yahoo.com>
Message-ID: <LCEPIIGDJPKCOIHOBJEPIEFNFNAA.mhammond@skippinet.com.au>

> I intalled Python 2.2.1 and followed instructions for
> starting the COM server as found on a downloaded
> manual.

The "downloaded manual" is actually from the standard win32com
documentation.  If you find the PythonCOM readme, you will find more up to
date information.

> It did not work.

What did not work?  What version of win32all (or ActivePython) are you
using?

Mark.




From printers@sendme.cz  Thu Jun 20 09:12:20 2002
From: printers@sendme.cz (A)
Date: Thu, 20 Jun 2002 10:12:20 +0200
Subject: [Tutor] How to find all emails (on the same line)
Message-ID: <3D11AA84.4222.A8556@localhost>

Hi,
I need to find ALL emails in a file. I can use re module but I do not 
know how to find all emails if there are more emails on the same 
line because re module ( as far as I know )finds only one/first 
occurrence on that line.
Thanks for help.
Ladislav





From dyoo@hkn.eecs.berkeley.edu  Thu Jun 20 10:26:54 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 20 Jun 2002 02:26:54 -0700 (PDT)
Subject: [Tutor] Case study: an initial profiling and optimization of 4st attack 2
Message-ID: <Pine.LNX.4.44.0206200033520.15797-100000@hkn.eecs.berkeley.edu>

[warning: extremely long message.  This is a demonstration of a
"hackathon" session with Python.]



Hi everyone,

I've been playing with 4st attack 2, a game written by Jeroen Vloothuis
with the pygame toolkit; it's a pretty nicely written game!  Take a look:

    http://forcedattack.sourceforge.net/


One thing I noticed, though, was that, on single player games, there's a
noticable delay when the computer takes its turn.  I thought it might be
interesting to look at a real-life version of some code, and see how one
might begin...um... "improving" it.  *cough cough*

(Just to make sure this is ok, I'm putting Vloothuis in CC.)



I began by playing the game a few times.  Just to get a feel for the
algorithms, of course.  *grin*

It does no good to blindly guess where to start hunting for slowdown, so I
used a tool called a profiler: a profiler is a program that monitors the
running of another program, and gives a summary about what parts run
slowly.  Python comes with a very good one:

    http://www.python.org/doc/lib/profile.html



Here's my interactive session.  I will include my bugs on purpose, just to
show an example of what not to do.  *grin*:

###
Python 2.2.1 (#2, Apr 27 2002, 13:16:36)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import profile
>>> import 4stattack
  File "<stdin>", line 1
    import 4stattack
           ^
SyntaxError: invalid syntax
###


The main program for 4stattack is in the file '4stattack.py', so I'm
trying to import it.  But I run into an initial snag: variable names can't
start with numbers!



There is a workaround for this: we can manually import the module, but use
a different name for it, using the builtin '__import__()' function:

###
>>> m = __import__('4stattack')
>>> m
<module '4stattack' from '4stattack.py'>
###


Ok, now we have a way of calling parts of 4stattack from the interactive
interpreter.  Now let's try running the profiler.

###
>>> profile.run('m.main()')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.2/profile.py", line 71, in run
    prof = prof.run(statement)
  File "/usr/local/lib/python2.2/profile.py", line 404, in run
    return self.runctx(cmd, dict, dict)
  File "/usr/local/lib/python2.2/profile.py", line 410, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in ?
  File "4stattack.py", line 76, in main
    options = getOptions(sys.argv)
  File "4stattack.py", line 40, in getOptions
    if argv[0][0] == '-':
IndexError: string index out of range
###


Another snag!  This time, it's precisely because I'm running in the
interactive interpreter.  The error message is indicating that this
program expects to be run from the command prompt.  No problem: we can
trick it.

###
>>> import sys
>>> sys.argv
['']
>>> sys.argv=['foo']
###


Ok, let's try that one again.

###
>>> profile.run('m.main()')
###



Success!  At this point, the game pops up.  I play a single player game...
(and lose), and then finally quit the game.  As soon as m.main() returns
control back to the interactive interpreter, I receive a summary of the
execution:

###
>>> profile.run('m.main()')
         1263348 function calls (1197467 primitive calls) in 215.540 CPU
seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 4stattack.py:37(getOptions)
        1    0.030    0.030    0.030    0.030 4stattack.py:47(setDisplay)
       58    2.710    0.047    2.710    0.047 4stattack.py:60(loadGraphic)

[lots and lots of output flies by]
###


Not bad.  Slightly overwhelming, but not too much.  What we're interested
in are lines where both the cumtime "cumulative time" and the ncalls
"number of function calls" are high: these are the "hot" spots in a
program, and the places where we can do the most good or harm.

One of these report lines caught my eye:

###
       25    0.000    0.000    0.000    0.000 random.py:153(random)
    68960  123.910    0.002  123.910    0.002 rules.py:14(isWinner)
   300557    7.350    0.000    7.350    0.000 rules.py:4(isMoveLegal)
###


There's a function called isWinner() that determines if there are four
dots in a row on the game board.  This caught my eye because it's called
quite a bit, and also takes up a lot of time.


Here's a little bit of rules.isWinner():


###
# Checks if theres a winner
def isWinner(board, player):
	# Check vertical wins
	for x in range(7):
		sequence = 0
		for y in range(len(board.state[x])):
			if board.state[x][y] == player:
				sequence += 1
				if sequence == 4:
					# Whe've got a winner!!
					return sequence
			else: sequence = 0
[code cut]
###


One reason isWinner() is called so much is because the computer uses it to
imagine what would happen if it played certain scenarios: it can "imagine"
likely board positions, and then call isWinner() on these hypothetical
positions to see what to do next to maximize its chances.  isWinner() is a
critical function, and from casual study, it either returns 4 ('a winner
has been found') or 0 ('a winner has not been found').

So I broke it.

###
def isWinner(board, player):
    return 0   ## This is just to see if improving isWinner() might
               ## help make 4stattack faster
###


Now it will never run correctly, but at least it will run blazingly fast.
After doing this, I tried running 4stattack again, and the game ran, as
expected, like lightning.  But like lightning, it also just moved quite
sporatically and randomly.  But that's not the point.


We now know that if we can improve isWinner() (or figure out a way to
reduce isWinner's work altogether) then this will help 4stattack run
better.



Perhaps we can reduce isWinner()'s work.  isWinner() asks the question:
"Is there a chain of four successive positions on the board, anywhere?" To
figure this out, it has access to the whole board, and the player whose
perspective we're seeing from.  And it goes at it from all directions:
horizontally, vertically, and diagonally.

But we can take advantage of a few rules of the game of 4stattack:  We
already know that we don't have to look at the whole board to figure this
out: all we need to do is look at the neighborhood of the very last move
played.  That is, if there's been a winner declared, it must have been the
result of the very last move: if we're able to communicate this 'last
move' information to isWinner(), then our work can be greatly reduced!


Hey, what do you know!  We have that information!

###
### Within the Board class definition:

	def move(self, move, player):
		self.state[move].append(player)
		self.last_move = move
###

Wonderful!  We can just look at board.last_move.




I've done some preliminary work in rewriting rules.isWinner().  Jeroen,
forgive me: I got creative.  *grin*


###
## Within rules.py
def isWinner(board, player):
	if _isVerticalWin(board, player):
		return 4
	if _isHorizontalWin(board, player):
		return 4
	if _isDiagonalWin(board, player):
		return 4
	return 0


def _isVerticalWin(board, player):
	x = board.last_move
	four_in_a_row = [player, player, player, player]
	return board.state[x][-4:] == four_in_a_row


def _isHorizontalWin(board, player):
	x = board.last_move
	y = len(board.state[x]) - 1
	four_in_a_row = str(player) * 4
	row = []
	for i in range(-3, 4):
		try:
			if x+i < 0: continue
			row.append(str(board.state[x+i][y]))
		except IndexError:
			row.append('s')  # 's' stands for sentinel
	return ''.join(row).find(four_in_a_row) >= 0


def _isDiagonalWin(board, player):
	x = board.last_move
	y = len(board.state[x]) - 1
	four_in_a_row = str(player) * 4
	row = []
	for i in range(-3, 4):
		try:
			if x+i < 0: continue
			if y+i < 0: continue
			row.append(str(board.state[x+i][y+i]))
		except IndexError:
			row.append('s')  # 's' stands for sentinel
	if ''.join(row).find(four_in_a_row) >= 0:
		return 1
	row = []
	for i in range(-3, 4):
		try:
			if x+i < 0: continue
			if y-i < 0: continue
			row.append(str(board.state[x+i][y-i]))
		except IndexError:
			row.append('s')  # 's' stands for sentinel
	if ''.join(row).find(four_in_a_row) >= 0:
		return 1
	return 0
###

>From informal testing, I'm feeling that this is much faster than the
original version, but it might not be correct yet.  Still, I think it's a
beginning.  *grin*


I hope this was interesting or useful to people!




From dyoo@hkn.eecs.berkeley.edu  Thu Jun 20 10:28:28 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 20 Jun 2002 02:28:28 -0700 (PDT)
Subject: [Tutor] Need help with binary notation (fwd)
Message-ID: <Pine.LNX.4.44.0206200227320.15797-100000@hkn.eecs.berkeley.edu>

Hi Patrick,

You probably meant to send this to the main Tutor list as well as James.
I'm forwarding your message there.  Hope this helps!


---------- Forwarded message ----------
Date: Wed, 19 Jun 2002 23:42:55 -0700 (PDT)
From: The Patrick Brady <TheIMHLAR@goosemoose.com>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Need help with binary notation

On Wed, 19 Jun 2002, James M Lang wrote:

Okay, I've got an assignment from school for the summer. Some of the
problems state to express the problem in binary notation. So basically,
my question would be, could Python help me with my homework? Oh, and
ah.., hehe, I forgot what binary notation is. Anyone know what it is?

"Binary notation"?  Beats me.  *grin*

I have no idea about binary notation, but are you sure it wasn't scientific notation, such as 3.4 * 10^6. If not, at least what class is it for.

_____________________________________________________________
Get your free 20 MB website and 6MB email address at Http://signup.goosemoose.com

_____________________________________________________________
Promote your group and strengthen ties to your members with email@yourgroup.org by Everyone.net  http://www.everyone.net/?btn=tag





From lha2@columbia.edu  Thu Jun 20 12:07:00 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Thu, 20 Jun 2002 07:07:00 -0400
Subject: [Tutor] Need help with binary notation
References: <HHGLDNLDJAAIBBAA@mailcity.com>
Message-ID: <3D11B754.314327F7@mail.verizon.net>

It is dangerous to use Python to convert numbers from decimal to binary
and binary to decimal, if your instructor's point is for you to
understand the process. As a high school math teacher, I run into things
like this a lot, where students don't believe me that when they will be
tested on the homework, they won't be able to use their graphing
calculator, and then they don't bother to learn how to identify vertical
asymptotes and so can't recognize rational functions.

That said, here's a way to think about binary notation:

When we count, we /increment/ a number once each time, starting with
one. After we reach nine in the ones place, we don't have anywhere to
go, so we revert to zero in the ones place but increment the tens place.
One ten is equal to ten ones. This looks like this:

1
2
3
4
5
6
7
8
9
10  <--- we ran out of ones, and so threw them all out and added one to
the tens.

and then we keep counting, which I don't need to illustrate.

Binary is the same thing, except that instead of not having a "ten" that
fits in the ones place, we don't have a two. So it looks kind of like

  1
 10 <-- we ran out of ones
 11 <-- increment the ones
100 <-- we ran out of ones, and in incrementing the "twos", ran out
there, and so went out another digit.

And so on. Put your two columns of numbers next to each other in order
to translate small numbers. In order to translate large numbers,
recognize that just as 100==10**2 and 10==10**1 and 1==10**0 (each digit
of decimal is a power of ten) (** meaning exponentiation), so is each
digit of binary a power of two. 
Notice things about your chart. What is the ones digit in binary for
even numbers? How can you tell by looking at binary representation that
a number is one more than a multiple of four? What does it mean that
each digit of binary is a power of two, i.e., what does 256 look like?
1024?

So if you have to translate from binary to decimal, that's easy--

1001101 is 2**0 + 2**2 + 2**3 + 2**7 (reading from right to left)

going the other way is a tad bit more complicated; if someone gives you
141, you have to think, "hmm, the greatest power of two that is less
than or equal to 141 is 128, which is 2**7; so I should put a one in the
seventh place. Then 141-128==13. The greatest power of two that is less
than or equal to 13 is 8, which is 2**3, so I should put a one in the
third place. Then..." and keep going until you get to zero. 

Good luck.

(this part's not so much for Jimmy): Clearly this can be done in a loop,
where one first checks for zero and then takes the log base two of the
number, perhaps holding the places that get a one in a list. To take log
base two, do math.log(x)/math.log(2).

James M Lang wrote:
> 
> Okay, I've got an assignment from school for the summer. Some of the problems state to express the problem in binary notation. So basically, my question would be, could Python help me with my homework? Oh, and ah.., hehe, I forgot what binary notation is. Anyone know what it is?
> 
> _________________________________________
> Communicate with others using Lycos Mail for FREE!
> http://mail.lycos.com/
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From einarth@decode.is  Thu Jun 20 12:04:58 2002
From: einarth@decode.is (Einar Th. Einarsson)
Date: Thu, 20 Jun 2002 11:04:58 +0000
Subject: [Tutor] Types of instances
Message-ID: <200206201104.59388.einarth@decode.is>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hey folks.

How do I discover the type of an object at runtime?

For example if I have piece of code like:

try:
    raise AttributeException, "blah"
except Exception, e:
    print type(e)

python happily tells me that e is an instance....which is kinda bloody obvi=
ous=20
and utterly useless information.  I want to know if e is a AttributeError, =
or=20
a TypeError or something else alltogether.=20

The repr(object) function almost does what I want, and it's trivial to writ=
e a=20
wrapper function around that would serve my purposes, except that I'd also =

like to know the type of the parent class(es), if any, and thus potentially=
=20
discover the pedigree of the class in question at runtime.

So, is there something in the Python language or it's built-in stuff that d=
oes=20
this?

- --=20
Disclaimer: I'm not as smart as I think I am.

Yours etc.
    Einar Th.

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBPRG22m1/ORZtyd/tEQL3QgCeITKueiMGLqs2xraaF7rRDZ+xCyQAnAo1
ISHbcGvl6kB7hHX0g3wF0APH
=3Da345
-----END PGP SIGNATURE-----




From iumarumo@eidosnet.co.uk  Thu Jun 20 13:08:39 2002
From: iumarumo@eidosnet.co.uk (ibraheem umaru-mohammed)
Date: Thu, 20 Jun 2002 13:08:39 +0100
Subject: [Tutor] Need help with binary notation
In-Reply-To: <3D11B754.314327F7@mail.verizon.net>
References: <HHGLDNLDJAAIBBAA@mailcity.com> <3D11B754.314327F7@mail.verizon.net>
Message-ID: <20020620120839.GE25418@micromuse.com>

[Lloyd Hugh Allen wrote...]
-| 
-| So if you have to translate from binary to decimal, that's easy--
-| 
-| 1001101 is 2**0 + 2**2 + 2**3 + 2**7 (reading from right to left)
-| 

I believe this should be:

	1001101 = 2**0 + 2**2 + 2**3 + 2**6
				          ^
Kindest regards,

			--ibs.
-- 
			ibraheem umaru-mohammed
			   www.micromuse.com
			         --0--



From lha2@columbia.edu  Thu Jun 20 13:28:43 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Thu, 20 Jun 2002 08:28:43 -0400
Subject: [Tutor] Need help with binary notation
References: <HHGLDNLDJAAIBBAA@mailcity.com> <3D11B754.314327F7@mail.verizon.net> <20020620120839.GE25418@micromuse.com>
Message-ID: <3D11CA7B.2E7BDBF3@mail.verizon.net>

Oops. Thanks.

ibraheem umaru-mohammed wrote:
> 
> [Lloyd Hugh Allen wrote...]
> -|
> -| So if you have to translate from binary to decimal, that's easy--
> -|
> -| 1001101 is 2**0 + 2**2 + 2**3 + 2**7 (reading from right to left)
> -|
> 
> I believe this should be:
> 
>         1001101 = 2**0 + 2**2 + 2**3 + 2**6
>                                           ^
> Kindest regards,
> 
>                         --ibs.
> --
>                         ibraheem umaru-mohammed
>                            www.micromuse.com
>                                  --0--
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From alan.gauld@bt.com  Thu Jun 20 13:33:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 20 Jun 2002 13:33:13 +0100
Subject: [Tutor] Dynamic change of dictionaries
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67E@mbtlipnt02.btlabs.bt.co.uk>

> the color of terminal with codes?
> I've tried (from /etc/rc.d/functions):
> (SETCOLOR_FAILURE="echo -en \\033[1;31m")
> 
> $ python
> >>> red='\\033[1;31m'

I don't thinbk you need the double \
That says send the '\' character to the terminal. If you use 
a single '\' it should send ESCAPE(\033) which is what I 
assume should happen...

But I'm guessing, terminal control under *nix is frought 
with difficulties. If I knew more aboit termcap maybe theres 
a general way to do it there but I don't... I suspect 
ncurses may have ways and means too.

Alan G.



From alan.gauld@bt.com  Thu Jun 20 13:37:11 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 20 Jun 2002 13:37:11 +0100
Subject: [Tutor] COM server not starting
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67F@mbtlipnt02.btlabs.bt.co.uk>

> I intalled Python 2.2.1 and followed instructions for
> starting the COM server as found on a downloaded
> manual. It did not work. 

First things first. Did you install the Activestate 
Python(best for Windows work IMHO) or the generic python.org one?

If the latter you also need the matching winall extensions
(built into the Activestate build).

Otherwise, what exactly did you try to run, and what error 
did you get?

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From wilson@visi.com  Thu Jun 20 15:12:42 2002
From: wilson@visi.com (Tim Wilson)
Date: Thu, 20 Jun 2002 09:12:42 -0500
Subject: [Tutor] Generating SWFs on the fly using Ming and Python CGI
In-Reply-To: <20020620053836.GA12064@digitalmethod.org>
References: <20020620041317.GB27644@isis.visi.com> <20020620053836.GA12064@digitalmethod.org>
Message-ID: <20020620141242.GB12061@isis.visi.com>

On Thu, Jun 20, 2002 at 03:38:36PM +1000, Ram Smith wrote:
> On Wed, 19 Jun 2002, Tim Wilson wrote:
> 
> > There's no HTML form input at this point, I'm just trying to get Python
> > to generate the SWF and return it to the Web browser. FWIW, there is
> > some documentation at http://ming.sourceforge.net/docs/index.php?mode=py
> > that lists the various methods. (I generated the working SWF by calling
> > the 'save()' method of my SWFMovie object.)
> > 
> > Anyone have any ideas here?
> 
> I think what your looking for is m.output()

Yes, I know about m.output(). I'm having trouble figuring out how to use
it in a CGI environment. Just setting the Content-type header and
calling m.output() doesn't seem to do the trick.

-Tim

-- 
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From marcolinux@linuxbr.com.br  Thu Jun 20 15:46:02 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Thu, 20 Jun 2002 11:46:02 -0300
Subject: [Tutor] Dynamic change of dictionaries
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67E@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020620144602.GA5799@marcolab.proconet>

alan.gauld@bt.com (alan.gauld@bt.com) wrote:

> > $ python
> > >>> red='\\033[1;31m'
> 
> I don't thinbk you need the double \
> That says send the '\' character to the terminal. If you use 
> a single '\' it should send ESCAPE(\033) which is what I 
> assume should happen...

Thanks Alan!
Worked very well. Now I have a full rainbow to play with :)

> But I'm guessing, terminal control under *nix is frought 
> with difficulties. If I knew more aboit termcap maybe theres 
> a general way to do it there but I don't... I suspect 
> ncurses may have ways and means too.

You really hate *nix, dont u ? :)
No problem, all I need is to change color in some lines, linux only.
Your tip did the trick.
Thank you.

-- 
I SeE NeRD pEoPle.
.:: MarcoLinux ::.



From urnerk@qwest.net  Thu Jun 20 17:32:02 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 20 Jun 2002 09:32:02 -0700
Subject: [Tutor] Need help with binary notation
In-Reply-To: <3D11B754.314327F7@mail.verizon.net>
References: <HHGLDNLDJAAIBBAA@mailcity.com>
Message-ID: <5.1.1.6.0.20020620091907.02956570@urnerk/pop.ptld.qwest.net>

Lloyd Hugh Allen wrote:
>(this part's not so much for Jimmy): Clearly this can be done in a loop,
>where one first checks for zero and then takes the log base two of the
>number, perhaps holding the places that get a one in a list. To take log
>base two, do math.log(x)/math.log(2).


math.log is pretty intensive (slow) for this application.  Faster is
to just keep shift-lefting the decimal and grabbing the bits.  Since
the integer is already stored in binary, you don't need to recompute
anything, just convert it to a visible form e.g. a character string:

def base2(n,fill=0):
     """
     Convert a positive integer to base 2 string representation
     with optional 0-padding on left (2nd arg defines
     total width)
     """

     # screen for bogus input
     if n<0:
        # a better routine would accept negatives
        raise ValueError,"Must be positive"
     if type(n)<>type(1) and type(n)<>type(1L):
        raise ValueError,"Must be integer or long integer"

     outstr = ''
     while 1:
        if n&1: outstr = '%s%s' % ('1',outstr)
        else:   outstr = '%s%s' % ('0',outstr)
        n>>=1
        if n==0: break
     return string.zfill(outstr,fill)


 >>> base2(109019238)
'110011111111000000001100110'
 >>> base2(10)
'1010'
 >>> base2(2)
'10'
 >>> base2(1)
'1'
 >>> base2(0)
'0'

Kirby





From dman@dman.ddts.net  Thu Jun 20 19:53:24 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 20 Jun 2002 13:53:24 -0500
Subject: [Tutor] Re: How to find all emails (on the same line)
In-Reply-To: <3D11AA84.4222.A8556@localhost>
References: <3D11AA84.4222.A8556@localhost>
Message-ID: <20020620185324.GA15656@dman.ddts.net>

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

On Thu, Jun 20, 2002 at 10:12:20AM +0200, A wrote:
| Hi,
| I need to find ALL emails in a file.

$ cat the_file

<wink>

Oh, you want to find emails matching a certain pattern ... :-)

| I can use re module but I do not know how to find all emails if
| there are more emails on the same line because re module ( as far as
| I know )finds only one/first occurrence on that line.

The re module allows you to find matching sections of a string.  If
you read the file in as a single string, you can perform regex
searches on it.  The "search" method does return only the first match.
The "findall" (I think it's called) method returns a list of all
non-overlapping matches.

However, that isn't going to be a good way to search for email
messages matching a certain pattern.  Email messages are structured
data and can be encoded (eg quoted-printable or base64) which means
that the raw data in the file is not quite the same as what you see in
your mail reader.

If you want to write this yourself, then a place to begin is by
reading RFC 2822 (and RFC 822 for history and RFCs 2045-2049 for MIME
and some others for, eg PGP signed mail like this one) to understand
the structure of emails and what sort of data you might encounter in
the raw file.  Then look at the 'mailbox' and 'email' modules for
existing parsers you can use to parse the file into messages.  Then it
will take a fair amount of code to correctly implement a general
search over all the messages.

I think using existing tools is a better approach because the hard
work is already done for you.

Mutt (the mail reader I use) has the ability to open a mail folder (eg
mbox file, like you mentioned above), then perform pattern-based
limiting so that I only see matched messages in the display.  I've
never used Pegasus so I don't know how capable it is in that area.

There's another program called "grepmail" that is designed to to
take a pattern and an mbox file as input and output a new mbox file
that contains only matching messages (which you would then view with
your mail reader).

The advantage of using tools like these are that they already
implemented the parsers and iteration and all the little details for
handling mail messages and will achieve the results you requested.

HTH,
-D

--=20

[Perl] combines all the worst aspects of C and Lisp: a billion different
    sublanguages in one monolithic executable.
It combines the power of C with the readability of PostScript.
        -- Jamie Zawinski
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0SJKQACgkQO8l8XBKTpRSP+gCeMQSmS4NapZes7o825bxq9NuX
sw4AoI0Xeg63WVX8EA6pBXGRLVnVvxSr
=nbQ6
-----END PGP SIGNATURE-----

--UugvWAfsgieZRqgk--



From dman@dman.ddts.net  Thu Jun 20 20:34:18 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 20 Jun 2002 14:34:18 -0500
Subject: [Tutor] Re: Dynamic change of dictionaries
In-Reply-To: <20020620144602.GA5799@marcolab.proconet>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C67E@mbtlipnt02.btlabs.bt.co.uk> <20020620144602.GA5799@marcolab.proconet>
Message-ID: <20020620193418.GB15656@dman.ddts.net>

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

On Thu, Jun 20, 2002 at 11:46:02AM -0300, Marc wrote:
| alan.gauld@bt.com (alan.gauld@bt.com) wrote:

| > But I'm guessing, terminal control under *nix is frought=20
| > with difficulties. If I knew more aboit termcap maybe theres=20
| > a general way to do it there but I don't... I suspect=20
| > ncurses may have ways and means too.
|=20
| You really hate *nix, dont u ? :)

I don't think he does (based on other things he's said before), but
he's right.  There isn't a built-in "red()" function because there are
hundreds (probably literally) of different terminals that can be
connected to a unix system and each has a (potentially) different set
of escape codes for controlling it.

That's in large part why Bill Joy created the "curses" library (with
the associated "termcap" database) back in the '70s.  The termcap
database stores the escape codes necessary to achieve the desired
results.  The end effect is that programs using the curses (or the
newer ncurses) library can be terminal agnostic, yet still work on all
the terminals supported by the termcap (or terminfo, if using ncurses)
database.

| No problem, all I need is to change color in some lines, linux only.
| Your tip did the trick.

If you only need to support 1 particular terminal, then hard-coding
the escapes for it is manageable.

-D

--=20

"Wipe Info uses hexadecimal values to wipe files. This provides more=20
security than wiping with decimal values." -- Norton SystemWorks 2002 Manual
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0SLjoACgkQO8l8XBKTpRQl3gCcD2Q3Tj/q18E416fKAzjRXF9l
YZYAn0yyHoPfW1mAIrJOw68tWZblTCZG
=ZJBT
-----END PGP SIGNATURE-----

--pvezYHf7grwyp3Bc--



From dman@dman.ddts.net  Fri Jun 21 00:16:20 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 20 Jun 2002 18:16:20 -0500
Subject: [Tutor] Re: Types of instances
In-Reply-To: <200206201104.59388.einarth@decode.is>
References: <200206201104.59388.einarth@decode.is>
Message-ID: <20020620231620.GA18471@dman.ddts.net>

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


(this message is quick, short, and terse)

On Thu, Jun 20, 2002 at 11:04:58AM +0000, Einar Th. Einarsson wrote:
[determine the class of an object]

class Foo : pass
obj =3D Foo()
print obj.__class__

This is the general way to see the actual class of an object.  To find
out of an object is-a instance of a certain class (or subclass of it
-- subclassing maintains the is-a relationship) use

class SubFoo( Foo ) : pass
o2 =3D SubFoo()
print isinstane( o2 , Foo )


You brought up exception handling.  For that, use the language as it
is intended.  Example :

try :
    some_operation()
except AttributeError :
    print "handling for attribute errors"
except TypeError :
    print "handling for type errors"
except Exception :
    print "handling for other exceptions"


Don't have a single except block that uses isinstance() to branch.
Use the built-in exception handling mechanism to do the branching for
you.  It will be easier to maintain and easier for others to read the
code.

(if this is too terse, come back with more questions)

HTH,
-D

--=20

 "Piracy is not a technological issue. It's a behavior issue."  =20
                                                       --Steve Jobs
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0SYkQACgkQO8l8XBKTpRQp+gCcCC/g9tP8afeG1P78FO/GVeM+
uQoAnAsogPIJR7HrMxxI2zY8gsSNlFNM
=epuJ
-----END PGP SIGNATURE-----

--PNTmBPCT7hxwcZjr--



From ram@digitalmethod.org  Fri Jun 21 03:07:22 2002
From: ram@digitalmethod.org (Ram Smith)
Date: Fri, 21 Jun 2002 12:07:22 +1000
Subject: [Tutor] Generating SWFs on the fly using Ming and Python CGI
In-Reply-To: <20020620141242.GB12061@isis.visi.com>
References: <20020620041317.GB27644@isis.visi.com> <20020620053836.GA12064@digitalmethod.org> <20020620141242.GB12061@isis.visi.com>
Message-ID: <20020621020722.GA26452@digitalmethod.org>

On Thu, 20 Jun 2002, Tim Wilson wrote:

> On Thu, Jun 20, 2002 at 03:38:36PM +1000, Ram Smith wrote:
> > On Wed, 19 Jun 2002, Tim Wilson wrote:
> > 
> > > There's no HTML form input at this point, I'm just trying to get Python
> > > to generate the SWF and return it to the Web browser. FWIW, there is
> > > some documentation at http://ming.sourceforge.net/docs/index.php?mode=py
> > > that lists the various methods. (I generated the working SWF by calling
> > > the 'save()' method of my SWFMovie object.)
> > > 
> > > Anyone have any ideas here?
> > 
> > I think what your looking for is m.output()
> 
> Yes, I know about m.output(). I'm having trouble figuring out how to use
> it in a CGI environment. Just setting the Content-type header and
> calling m.output() doesn't seem to do the trick.
> 
> -Tim

Okay, 

Here we go... one way to get this to work is:

sys.stdout.write('Content-type: application/x-shockwave-flash\n\n')
sys.stdout.flush()
m.output()


It's a shame that there aren't many examples out there for using ming with python. 

If you find a site with examples in python let me know.

cheers,

ram.
--
w  http://www.digitalmethod.org
m  0414 866 965
<blink>12:00</blink>



From wilson@visi.com  Fri Jun 21 03:30:05 2002
From: wilson@visi.com (Tim Wilson)
Date: Thu, 20 Jun 2002 21:30:05 -0500
Subject: [Tutor] Generating SWFs on the fly using Ming and Python CGI
In-Reply-To: <20020621020722.GA26452@digitalmethod.org>
References: <20020620041317.GB27644@isis.visi.com> <20020620053836.GA12064@digitalmethod.org> <20020620141242.GB12061@isis.visi.com> <20020621020722.GA26452@digitalmethod.org>
Message-ID: <20020621023005.GA21767@isis.visi.com>

On Fri, Jun 21, 2002 at 12:07:22PM +1000, Ram Smith wrote:
> On Thu, 20 Jun 2002, Tim Wilson wrote:
> 
> > Yes, I know about m.output(). I'm having trouble figuring out how to use
> > it in a CGI environment. Just setting the Content-type header and
> > calling m.output() doesn't seem to do the trick.
> > 
> 
> Okay, 
> 
> Here we go... one way to get this to work is:
> 
> sys.stdout.write('Content-type: application/x-shockwave-flash\n\n')
> sys.stdout.flush()
> m.output()

Ram,

This works. Thanks!

Now I just need to find something interesting to do with it.

-Tim

-- 
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From printers@sendme.cz  Fri Jun 21 08:34:05 2002
From: printers@sendme.cz (A)
Date: Fri, 21 Jun 2002 09:34:05 +0200
Subject: [Tutor] How to find all emails (on the same line)
Message-ID: <3D12F30D.2071.204353@localhost>

Hi,
I need to find ALL emails in a file. I can use re module but I do not 
know how to find all emails if there are more emails on the same 
line because re module ( as far as I know )finds only one/first 
occurrence on that line.
Thanks for help.
Ladislav





From urnerk@qwest.net  Fri Jun 21 14:46:32 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 21 Jun 2002 09:46:32 -0400
Subject: [Tutor] Enhanced base 10 to base 2 converter
Message-ID: <20020621094632.5fe7f587.urnerk@qwest.net>

Here's a somewhat improved version of the convert-to-base2 function.  
It'll pad to the left with the sign bit (0 for positive, 1 for 
negative) up to the nearest word boundary, where wordsize is whatever.  
This way, if it's a long integer, you don't hit overflow conditions 
by exceeding the word size -- just keep eating words as needed.

Usage:




=============

def base2(n,wordsize=16):
    """
    Convert an integer to base 2 string representation using 
    as many words as needed (could be enhanced to flag overflow
    for ints of fixed maximum size, with this kind of indefinite 
    expansion for long ints only)

    Note: negative numbers are in two's complement representation

    """
    if (type(n) != type(1) and type(n) != type(1L)): 
       raise ValueError,"Needs int or long int"

    outstr = ''
    j=abs(n)

    fill=0  # fill is sign bit (0=pos, 1=neg)
    if n<0: fill=1

    while 1:
       if n&1: outstr = '%s%s' % ('1',outstr)
       else:   outstr = '%s%s' % ('0',outstr)
       n>>=1  # n is actual number to be converted
       j>>=1  # j is positive moving to 0 as shifted
       if j==0: break

    # positive number cannot have 1 in first position
    # note: n reached 0 only if it was positive to begin with
    if n==0 and outstr[0]=='1': outstr = "%s%s" % ('0',outstr)

    # pad left w/ sign bits from nearest word boundary
    while len(outstr) % wordsize > 0:  
       outstr = '%s%s' % (fill,outstr)

    return outstr



From dyoo@hkn.eecs.berkeley.edu  Fri Jun 21 20:46:23 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 21 Jun 2002 12:46:23 -0700 (PDT)
Subject: [Tutor] How to find all emails (on the same line)
In-Reply-To: <3D12F30D.2071.204353@localhost>
Message-ID: <Pine.LNX.4.44.0206210949310.20729-100000@hkn.eecs.berkeley.edu>


On Fri, 21 Jun 2002, A wrote:

> I need to find ALL emails in a file. I can use re module but I do not
> know how to find all emails if there are more emails on the same
> line because re module ( as far as I know )finds only one/first
> occurrence on that line.

Ah!  Try the findall() method from the 're' module:

###
>>> def findAllNumbers(line):
...     return re.findall(r'\d+', line)
...
>>> findAllNumbers("this is a test 42")
['42']
>>> findAllNumbers("this is a test 42 but 43 and 44 are also nice")
['42', '43', '44']
###


Hope this helps!





From flaxeater@yahoo.com  Fri Jun 21 21:27:19 2002
From: flaxeater@yahoo.com (Chad Crabtree)
Date: Fri, 21 Jun 2002 13:27:19 -0700 (PDT)
Subject: [Tutor] Re: Tutor digest, Vol 1 #1707 - 7 msgs
In-Reply-To: <20020621160005.16157.20564.Mailman@mail.python.org>
Message-ID: <20020621202719.40860.qmail@web11607.mail.yahoo.com>

Hey I'm wrote a few days ago about how to interogate 
A TKinter text box so that I could delete the last
line

I got a response that worked however I figured out a
slight improvement that might be usefull.  

The exampe I got was

    def delete(self):
        l =
len(self.textArea.get(1.0,10000.0).split('\n'))
        self.textArea.delete(float(l-1),float(l))
the person said that he/she (can't remember) couldn't
think of any way other than to go really deep on the
get

however  It just occured to me that

    def delete(self):
        l =
len(self.textArea.get(1.0,END).split('\n'))
        self.textArea.delete(float(l-1),float(l))

one could use the END on the second index to give
proper results.  The previous example was very helpful
as I would not have been able to figure out how to get
the number of indexes.  



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From gilbertr@vsnl.com  Sat Jun 22 02:31:06 2002
From: gilbertr@vsnl.com (gilbert)
Date: Sat, 22 Jun 2002 07:01:06 +0530
Subject: [Tutor] Doubt
Message-ID: <000801c2198c$7ce39280$13a8c7cb@rodrigues>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C219BA.94CEFDC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi everybody,
I am a beginner and have a small doubt.
How do we wite the programs in a text file and run it with an =
interpretor?
>From Osie

------=_NextPart_000_0005_01C219BA.94CEFDC0
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 everybody,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am a beginner and have a small=20
doubt.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>How do we wite the programs in a text =
file and run=20
it with an interpretor?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>From Osie</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C219BA.94CEFDC0--




From ak@silmarill.org  Sat Jun 22 03:11:25 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Fri, 21 Jun 2002 22:11:25 -0400
Subject: [Tutor] Doubt
In-Reply-To: <000801c2198c$7ce39280$13a8c7cb@rodrigues>
References: <000801c2198c$7ce39280$13a8c7cb@rodrigues>
Message-ID: <20020622021125.GA22348@ak.silmarill.org>

On Sat, Jun 22, 2002 at 07:01:06AM +0530, gilbert wrote:
> Hi everybody,
> I am a beginner and have a small doubt.
> How do we wite the programs in a text file and run it with an interpretor?
> >From Osie

Hi Gilbert,

I'll assume you have windows. Start notepad and enter your program.
Save it as test.py file. Go to windows explorer and double click that
file. It should run now. Note that sometimes it may run in a dos window
and close quickly, if that happens to you, simply add this line at the
end of your program:

raw_input()

HTH,

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From dyoo@hkn.eecs.berkeley.edu  Sat Jun 22 04:32:40 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 21 Jun 2002 20:32:40 -0700 (PDT)
Subject: [Tutor] Doubt
In-Reply-To: <000801c2198c$7ce39280$13a8c7cb@rodrigues>
Message-ID: <Pine.LNX.4.44.0206212030560.3871-100000@hkn.eecs.berkeley.edu>


On Sat, 22 Jun 2002, gilbert wrote:

> I am a beginner and have a small doubt.
> How do we wite the programs in a text file and run it with an interpretor?

Hi Gilbert,

When you install Python, it should come with a text editor called IDLE.
IDLE will allow you to edit Python code in a text file, and allow allows
easy access to the interpreter.  You may find:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

useful; it's a small introduction to IDLE.

If you have more questions, please feel free to ask.  Good luck!




From wolf_binary@hotmail.com  Sat Jun 22 19:08:17 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Sat, 22 Jun 2002 13:08:17 -0500
Subject: [Tutor] bits taken by variable type
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C671@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <DAV578JynCR34XtFT0D00000a12@hotmail.com>

This is a multi-part message in MIME format.

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

This is much what I expected.  I knew Python shielded you from a lot of =
the details.  I am interested in those details though.  If anyone has a =
C/C++ site that they recommend tell me if you would.  I was just doing =
some thinking that's all.  I like to compare the two so I know better =
which is better for some job than the other.  I keep seeing more an more =
how Python is great for cross platform programming. =20

You can make a program on a Windows machine then transfer it to a Linux =
machine and as long as it doesn't have any platform specific programming =
in it or has been resolved to not have any conflicts I would think you =
could just use it on both machines.

If I'm wrong let me know.
Thanks,
Cameron Stoner
  ----- Original Message -----=20
  From: alan.gauld@bt.com=20
  To: wolf_binary@hotmail.com ; tutor@python.org=20
  Sent: Tuesday, June 18, 2002 11:59 AM
  Subject: RE: [Tutor] bits taken by variable type


  >  Coming from a C++ view point, how do you know if a variable in =
Python is =20
  >  unsigned long int or some other modified variable type?  =20

  In practice, why would you care?

  > How do you know how much precision a number is stored at?  =20

  For integers it is

  import sys
  print sys.maxint

  If you need longer than maxint use long integers which are arbitrarily =
large(effectively)

  For floats, I'm not sure. Just assume they are big enough and catch =
exceptions=20
  for when they aren't.

  These are the kind of low level details that Python is trying to =
shield from you.

  Alan G.


------=_NextPart_000_001A_01C219ED.DFD95120
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is much what I expected.&nbsp; I =
knew Python=20
shielded you from a lot of the details.&nbsp; I am interested in those =
details=20
though.&nbsp; If anyone has a C/C++ site that they recommend tell me if =
you=20
would.&nbsp; I was just doing some thinking that's all.&nbsp; I like to =
compare=20
the two so I know better which is better for some job than the =
other.&nbsp; I=20
keep seeing more an more how Python is great for cross platform=20
programming.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You can make a program on a Windows =
machine then=20
transfer it to a Linux machine and as long as it doesn't have any =
platform=20
specific programming in it or has been resolved to not have any =
conflicts I=20
would think you could just use it on both machines.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If I'm wrong let me know.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron Stoner</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dalan.gauld@bt.com=20
  href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dwolf_binary@hotmail.com=20
  href=3D"mailto:wolf_binary@hotmail.com">wolf_binary@hotmail.com</A> ; =
<A=20
  title=3Dtutor@python.org =
href=3D"mailto:tutor@python.org">tutor@python.org</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, June 18, 2002 =
11:59=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] bits taken =
by=20
  variable type</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; &nbsp;</FONT></SPAN>Coming =
from a C++=20
  view point, how do you know if a variable in Python is&nbsp;<SPAN=20
  class=3D580310017-18062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; </FONT>&nbsp;</SPAN>unsigned =
long int or=20
  some other modified variable type?&nbsp;&nbsp;<SPAN=20
  class=3D580310017-18062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>In practice,=20
  why would you care?</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002>&gt;</SPAN></FONT></FONT><FONT =
face=3DArial><FONT=20
  size=3D2><SPAN class=3D580310017-18062002>&nbsp;</SPAN>How do you=20
  know&nbsp;</FONT></FONT><FONT face=3DArial><FONT size=3D2>how much =
precision a=20
  number is stored at?&nbsp;&nbsp;<SPAN class=3D580310017-18062002><FONT =

  face=3D"Courier New" =
color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>For integers=20
  it is</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>import=20
  sys</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>print=20
  sys.maxint</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>If you need=20
  longer than maxint use long integers which are arbitrarily=20
  large(effectively)</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>For floats,=20
  I'm not sure. Just assume they are big enough and catch exceptions=20
  </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>for when=20
  they aren't.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>These are=20
  the kind of low level details that Python is trying to shield from=20
  you.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D580310017-18062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D580310017-18062002>Alan=20
  G.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_001A_01C219ED.DFD95120--



From ak@silmarill.org  Sat Jun 22 20:10:26 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 22 Jun 2002 15:10:26 -0400
Subject: [Tutor] "complete number" algorithm
Message-ID: <20020622191026.GA28683@ak.silmarill.org>

Hello tutor crowd,

I'm working on a small algorithm that determines if a digit can be
added at the end of one number and it could still be equal to or less
than another number. This is for an on-screen list where you have to
pick an item, each of them is numbered like this:

1
2
...
120

And if you type in 115 it should immediately pick #115, but if you type
in 12, it should wait because you might mean 12 or may still be about
to enter 120.

Here's what I got so far:

def final_num(num, max):
"""Test if num is final in max.

12 is not final in 125
12 is final in 83
5 is not final in 83

This function returns True only if you can't add anything to
the num and still stay in bounds of max.
"""

n,m  = str(num), str(max)
if len(n) >= len(m):
    return 1
else:
    if int(n[:-1]) > int(m[:-1]):
	return 1
    else:
	return 0

Is this a good algorithm for this task? It feels a bit off. I feel like
I'm missing some quick and elegant way to do this in 2 or 3 lines..

One other thing.. if you enter 12, it should wait for half a second or
so (I'll tune the exact time), and then assume you mean 12. What's the
best way to do that? I'm thinking I could have a thread that grabs keys
and the main process sleeps 0.5 sec and then takes whatever that thread
grabbed and runs with it..

Again, is this the cleanest & nicest way to do this?

Thanks,

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From shalehperry@attbi.com  Sat Jun 22 21:39:21 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 22 Jun 2002 13:39:21 -0700 (PDT)
Subject: [Tutor] "complete number" algorithm
In-Reply-To: <20020622191026.GA28683@ak.silmarill.org>
Message-ID: <XFMail.20020622133921.shalehperry@attbi.com>

On 22-Jun-2002 Andrei Kulakov wrote:
> Hello tutor crowd,
> 
> I'm working on a small algorithm that determines if a digit can be
> added at the end of one number and it could still be equal to or less
> than another number. This is for an on-screen list where you have to
> pick an item, each of them is numbered like this:
> 

why not mark each item as the user types and let them choose?

1
2
3
4
5
6
6
8
9
10
11
12
...
...
...
122

if the user types '1' then 1 gets hilighted.  if the user then presses '2' the
hilight moves to 12.  If they then press '1' it ends up on 121.  You can have
the "mark an item" function check the delay between keypresses and if the delay
is longer than a chosen time assume they started over.

This would work like emacs' search (C-s).



From ak@silmarill.org  Sat Jun 22 22:28:19 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 22 Jun 2002 17:28:19 -0400
Subject: [Tutor] "complete number" algorithm
In-Reply-To: <XFMail.20020622133921.shalehperry@attbi.com>
References: <20020622191026.GA28683@ak.silmarill.org> <XFMail.20020622133921.shalehperry@attbi.com>
Message-ID: <20020622212819.GA29860@ak.silmarill.org>

On Sat, Jun 22, 2002 at 01:39:21PM -0700, Sean 'Shaleh' Perry wrote:
> 
> On 22-Jun-2002 Andrei Kulakov wrote:
> > Hello tutor crowd,
> > 
> > I'm working on a small algorithm that determines if a digit can be
> > added at the end of one number and it could still be equal to or less
> > than another number. This is for an on-screen list where you have to
> > pick an item, each of them is numbered like this:
> > 
> 
> why not mark each item as the user types and let them choose?
> 
> 1
> 2
> 3
> 4
> 5
> 6
> 6
> 8
> 9
> 10
> 11
> 12
> ...
> ...
> ...
> 122
> 
> if the user types '1' then 1 gets hilighted.  if the user then presses '2' the
> hilight moves to 12.  If they then press '1' it ends up on 121.  You can have
> the "mark an item" function check the delay between keypresses and if the delay
> is longer than a chosen time assume they started over.
> 
> This would work like emacs' search (C-s).
> 
> 

Well, the thing is, I'm not using curses, just plain terminal. Besides,
this would need some sort of termination keypress, I'd prefer this to
be just the number. This will choose songs out of playlist and
directories (albums) out of directory list, so it's something a user
may do very often, and even one saved keypress is significant, I think.

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From shalehperry@attbi.com  Sun Jun 23 00:18:46 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 22 Jun 2002 16:18:46 -0700 (PDT)
Subject: [Tutor] "complete number" algorithm
In-Reply-To: <20020622212819.GA29860@ak.silmarill.org>
Message-ID: <XFMail.20020622161846.shalehperry@attbi.com>

> 
> Well, the thing is, I'm not using curses, just plain terminal. Besides,
> this would need some sort of termination keypress, I'd prefer this to
> be just the number. This will choose songs out of playlist and
> directories (albums) out of directory list, so it's something a user
> may do very often, and even one saved keypress is significant, I think.
> 

1,2,3 enter does not seem too much to ask.



From donni@melwestmarket.com  Sun Jun 23 03:24:53 2002
From: donni@melwestmarket.com (Dimitrije Nikic)
Date: Sun, 23 Jun 2002 12:24:53 +1000
Subject: [Tutor] How to ping
Message-ID: <02062312245301.00901@NikiLinux>

Hey people,
How do you ping an IP address and then assign the ping to a variable?
Thx for your help...

------------------------
 Dimitrije Nikic
 http://donnigames.melwestmarket.com



From ak@silmarill.org  Sun Jun 23 03:50:59 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 22 Jun 2002 22:50:59 -0400
Subject: [Tutor] How to ping
In-Reply-To: <02062312245301.00901@NikiLinux>
References: <02062312245301.00901@NikiLinux>
Message-ID: <20020623025059.GA32371@ak.silmarill.org>

On Sun, Jun 23, 2002 at 12:24:53PM +1000, Dimitrije Nikic wrote:
> Hey people,
> How do you ping an IP address and then assign the ping to a variable?
> Thx for your help...

You could try doing my_var = commands.getoutput("ping ip")

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From urnerk@qwest.net  Sun Jun 23 05:38:48 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 22 Jun 2002 21:38:48 -0700
Subject: [Tutor] bits taken by variable type
In-Reply-To: <DAV578JynCR34XtFT0D00000a12@hotmail.com>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C671@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <5.1.1.6.0.20020622210812.02226810@urnerk/pop.ptld.qwest.net>

At 01:08 PM 6/22/2002 -0500, Cameron Stoner wrote:
>This is much what I expected.  I knew Python shielded you from a lot of 
>the details.  I am interested in those details
>though.  If anyone has a C/C++ site that they recommend tell me if you 
>would.  I was just doing some thinking that's
>all.  I like to compare the two so I know better which is better for some 
>job than the other.  I keep seeing more an
>more how Python is great for cross platform programming.
>
>You can make a program on a Windows machine then transfer it to a Linux 
>machine and as long as it doesn't have
>any platform specific programming in it or has been resolved to not have 
>any conflicts I would think you could just
>use it on both machines.
>
>If I'm wrong let me know.
>Thanks,
>Cameron Stoner

I think it's really excellent to use your understanding of Python as a 
jumping-off point to
explore other languages like C.

One of the top in-depth tutorials on C++ is Bruce Eckel's.  He generously 
provides full
text and source code online for free, even though his 'Thinking in C++' is 
also a bestseller.

http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

What you say about C/C++ being portable if written for portability is true 
enough -- and
Python is a great example, as it's a C program under the hood.  But then of 
course a
main point of C/C++ language *is* systems programming, wherein you *want* to
scrounge around with the operating system, or even write pieces of  the 
operating
system itself.

By the way, I'm currently playing with Jython on Linux again, and am 
pleasantly
surprised with how much of my Python code (much of it originally developed in
Windows) is now running without modifications in this 100% Java environment
(I use Sun's JVM version 1.4 for Linux).

Kirby





From lumbricus@gmx.net  Sun Jun 23 12:41:27 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Sun, 23 Jun 2002 13:41:27 +0200 (MEST)
Subject: [Tutor] How to ping
References: <20020623025059.GA32371@ak.silmarill.org>
Message-ID: <28051.1024832487@www42.gmx.net>

> On Sun, Jun 23, 2002 at 12:24:53PM +1000, Dimitrije Nikic wrote:
> > Hey people,
> > How do you ping an IP address and then assign the ping to a 
>> variable?

What do you mean with "the ping"
The output of the ping command is implementation dependend.
You may want to parse it.

> > Thx for your help...
> 
> You could try doing my_var = commands.getoutput("ping ip")

use the socket module  
And send an IPPROTO_ICMP packet with ECHO_REPLY set.

>  - Andrei

HTH,HAND
and Greetings, J"o!


-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 23 20:28:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 23 Jun 2002 12:28:45 -0700 (PDT)
Subject: [Tutor] bits taken by variable type
In-Reply-To: <5.1.1.6.0.20020622210812.02226810@urnerk/pop.ptld.qwest.net>
Message-ID: <Pine.LNX.4.44.0206231222400.14996-100000@hkn.eecs.berkeley.edu>

On Sat, 22 Jun 2002, Kirby Urner wrote:

> At 01:08 PM 6/22/2002 -0500, Cameron Stoner wrote:
>
> >This is much what I expected.  I knew Python shielded you from a lot of
> >the details.  I am interested in those details though.  If anyone has a
> >C/C++ site that they recommend tell me if you would.  I was just doing
> >some thinking that's all.  I like to compare the two so I know better
> >which is better for some job than the other.  I keep seeing more an
> >more how Python is great for cross platform programming.
> >
>
> I think it's really excellent to use your understanding of Python as a
> jumping-off point to explore other languages like C.
>
> One of the top in-depth tutorials on C++ is Bruce Eckel's.  He
> generously provides full text and source code online for free, even
> though his 'Thinking in C++' is also a bestseller.

And for C programming, the book "The C Programming Language", by Brian
Kernighan and Dennis Ritchie, is an excellent tutorial to C.  Not only
does it cover the language thoroughly, but the tutorial presentation
itself is written well.  I don't know if it's online or not though...

Good luck!




From python@rcn.com  Sun Jun 23 21:07:54 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 23 Jun 2002 16:07:54 -0400
Subject: [Tutor] "complete number" algorithm
References: <20020622191026.GA28683@ak.silmarill.org>
Message-ID: <007601c21af1$a9f5e460$bbb53bd0@othello>

From: "Andrei Kulakov" <ak@silmarill.org>
> I'm working on a small algorithm that determines if a digit can be
> added at the end of one number and it could still be equal to or less
> than another number. 

> And if you type in 115 it should immediately pick #115, but if you type
> in 12, it should wait because you might mean 12 or may still be about
> to enter 120.


def final_num(num, max):
    """Test if num is final in max.
    
    12 is not final in 125
    12 is final in 8
    5 is not final in 83
    
    This function returns True only if you can't add anything to
    the num and still stay in bounds of max. 
    """
    return num*10 > max


Raymond Hettinger   






From ak@silmarill.org  Sun Jun 23 21:55:28 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sun, 23 Jun 2002 16:55:28 -0400
Subject: [Tutor] "complete number" algorithm
In-Reply-To: <007601c21af1$a9f5e460$bbb53bd0@othello>
References: <20020622191026.GA28683@ak.silmarill.org> <007601c21af1$a9f5e460$bbb53bd0@othello>
Message-ID: <20020623205528.GA6542@ak.silmarill.org>

On Sun, Jun 23, 2002 at 04:07:54PM -0400, Raymond Hettinger wrote:
[snip]
>     return num*10 > max

That's perfect! thanks,

 - Andrei

> 
> 
> Raymond Hettinger   
> 
> 
> 
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From arosado@softhome.net  Sun Jun 23 23:00:58 2002
From: arosado@softhome.net (Andres Rosado)
Date: Sun, 23 Jun 2002 18:00:58 -0400
Subject: [Tutor] Doubt
Message-ID: <5.1.0.14.0.20020623180006.00bb05a8@mail.softhome.net>

At 12:00 PM 6/22/2002 -0400, you wrote:
>I'll assume you have windows. Start notepad and enter your program.
>Save it as test.py file.

For this trick to work, you need to surround the name with double quotes, 
ie "test.py".

>Go to windows explorer and double click that
>file. It should run now. Note that sometimes it may run in a dos window
>and close quickly, if that happens to you, simply add this line at the
>end of your program:
>
>raw_input()

-----------------------------------
Andres Rosado
Email: andresr@despammed.com
ICQ: 66750646
Homepage: http://andres980.tripod.com/

Never ask two questions in a business letter.  The reply will discuss
the one you are least interested, and say nothing about the other.




From gew75@uow.edu.au  Mon Jun 24 03:44:36 2002
From: gew75@uow.edu.au (Glen Edward Wheeler)
Date: Mon, 24 Jun 2002 12:44:36 +1000
Subject: [Tutor] quick query relating to globals (I think)
Message-ID: <002a01c21b29$174e1f00$b946dccb@uow.speedlink.com.au>

  Howdy all,

  I'm making a program with a whole bunch of modules in different files (as
you do) and I'm wondering if it's possible to make an instance of a class in
one of those modules accessible by all the other modules...how 'bout an
example to illustrate :-

main.py
one.py
two.py
thing.py -> has class thing in it

main calls one and two, main also initialises an instance of the class
thing.  Without passing the object thing to all the function calls in one
and two (which would turn out really really messy) how can they access it?

  Hmm...just a sec, if thing.py initialised it's own instance of thing, at
the global level, then could one.py and two.py do an 'import thing' and
access it with thing.thing?

  Thanks,
  Glen




From gew75@uow.edu.au  Mon Jun 24 03:47:13 2002
From: gew75@uow.edu.au (Glen Edward Wheeler)
Date: Mon, 24 Jun 2002 12:47:13 +1000
Subject: [Tutor] amendment to my previous msg
Message-ID: <003201c21b29$71db4600$b946dccb@uow.speedlink.com.au>

  Howdy,

  If I did what I proposed in the last message, would there be a copy for
one and two each of thing?  so I would have two different objects cruising
around?  That would be annoying...
  Any help?

  Thanks,
  Glen




From dylan.belsey@baesystems.com  Mon Jun 24 06:14:34 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Mon, 24 Jun 2002 15:14:34 +1000
Subject: [Tutor] File pointers
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B963208B@WTNTEX1>

Hi,
	I run the following code:

>>> x = open("script1.py", "r")
>>> exec x
In the script
>>> exec x
>>> 

	As you can see, the second exec() doesn't produce the same result.
I have deduced that this occurs because the "file pointer", after the first
call is now sitting at the EOF of the file and so if you make the call
again, it just sees the EOF.
	My question is whether there is a simple way to reset this pointer
to the beginning of the file again.  I could of course just close and
re-open the file again but unfortunately the exec() command is run in a loop
which is executed every 50 ms so I want to cut down on the number of file
ops.  Also, I am trying to avoid the execfile() command as I use a GUI to
dynamically select a file.
	If anyone has any ideas, I would be glad to hear them.  No doubt the
solution is a simple one, but I just can't find it.
	Thanks in advance,
		Dylan




From ak@silmarill.org  Mon Jun 24 06:31:19 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Mon, 24 Jun 2002 01:31:19 -0400
Subject: [Tutor] File pointers
In-Reply-To: <86C3892A0C52D411AF5000A0C9EAA3B963208B@WTNTEX1>
References: <86C3892A0C52D411AF5000A0C9EAA3B963208B@WTNTEX1>
Message-ID: <20020624053119.GA10780@ak.silmarill.org>

On Mon, Jun 24, 2002 at 03:14:34PM +1000, BELSEY, Dylan wrote:
> Hi,
> 	I run the following code:
> 
> >>> x = open("script1.py", "r")
> >>> exec x
> In the script
> >>> exec x
> >>> 
> 
> 	As you can see, the second exec() doesn't produce the same result.
> I have deduced that this occurs because the "file pointer", after the first
> call is now sitting at the EOF of the file and so if you make the call
> again, it just sees the EOF.
> 	My question is whether there is a simple way to reset this pointer
>
Yeah - f.seek(0)

> to the beginning of the file again.  I could of course just close and
> re-open the file again but unfortunately the exec() command is run in a loop
> which is executed every 50 ms so I want to cut down on the number of file
> ops.  Also, I am trying to avoid the execfile() command as I use a GUI to
> dynamically select a file.
> 	If anyone has any ideas, I would be glad to hear them.  No doubt the
> solution is a simple one, but I just can't find it.
> 	Thanks in advance,
> 		Dylan
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From dyoo@hkn.eecs.berkeley.edu  Mon Jun 24 06:52:42 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 23 Jun 2002 22:52:42 -0700 (PDT)
Subject: [Tutor] quick query relating to globals (I think)
In-Reply-To: <002a01c21b29$174e1f00$b946dccb@uow.speedlink.com.au>
Message-ID: <Pine.LNX.4.44.0206232245050.27894-100000@hkn.eecs.berkeley.edu>


On Mon, 24 Jun 2002, Glen Edward Wheeler wrote:

>   I'm making a program with a whole bunch of modules in different files
> (as you do) and I'm wondering if it's possible to make an instance of a
> class in one of those modules accessible by all the other modules...how
> 'bout an example to illustrate :-
>
> main.py
> one.py
> two.py
> thing.py -> has class thing in it
>
> main calls one and two, main also initialises an instance of the class
> thing.  Without passing the object thing to all the function calls in one
> and two (which would turn out really really messy) how can they access it?

It might be better to make have a separate module, call it "singleton.py"
or something like that, to hold your single class instance.


>   Hmm...just a sec, if thing.py initialised it's own instance of thing,
> at the global level, then could one.py and two.py do an 'import thing'
> and access it with thing.thing?

Yes!  That's how we'd access objects in other modules.  Python's modules
work really well as containers of variable names.  And since modules are
cached and loaded only once, we're guaranteed that that instance will be
instantiated only once.


The reason I think it might be better to pull your instance out into a
separate module is because 'main' is already importing the 'one' and 'two'
modules.  If 'one' or 'two' were to import 'main' as well, there'd be a
circularity.

Python often can handle import circularities usually, but it's still
confusing!  We should avoid them just to keep our brains from getting
dizzy.

Hope this helps!




From swdoughty@yahoo.com.au  Mon Jun 24 14:51:28 2002
From: swdoughty@yahoo.com.au (Stephen Doughty)
Date: Mon, 24 Jun 2002 06:51:28 -0700 (PDT)
Subject: [Tutor] newB Q: extracting common elements from 2 lists
Message-ID: <20020624135128.58910.qmail@web12401.mail.yahoo.com>

Hi

I've just discovered the tutor list, I'm hoping to
learn a lot more about Python by reading other peoples
querys/answers.

My question:
I'm writing an export script for blender and have
stuck a hitch. I'm trying to work through the problem
in IDLE, so the examples are from the command line.

I have two tuples where the values are lists,
eg :
>>> xmap
{1: [1, 3, 5, 7, 9]}
>>> ymap
{1: [1, 2, 3, 4, 5]}

what I want is to extract the common elements of the
two tuple values and put them in a new tuple 'list'

like:

xymap[1] = xmap[1] *something magic here* ymap[1]

so xymap[1] contains [1,3,5].

can it be done?  - as tuples or converted to lists and
done somehow?

I found that xymap[1] = xmap[1] and ymap[1] just
combined the list rather than binary anding them (and
& caused an error).

Any advice gratefully received.

Cheers Stephen



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From alan.gauld@bt.com  Mon Jun 24 15:01:39 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jun 2002 15:01:39 +0100
Subject: [Tutor] bits taken by variable type
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C68F@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C21B87.A97C0F50
Content-type: text/plain; charset="iso-8859-1"

>  You can make a program on a Windows machine then transfer it to a Linux  
>  machine and as long as it doesn't have any platform specific programming

>  in it or has been resolved to not have any conflicts I would think you
could  
>  just use it on both machines. 
 
You can do the same with C/C++  but there are more platform 
specifics to fall over. But if you write a sort routine or 
number crunching program they will work just fine on either
platform ONCE YOU HAVE COMPILED THEM.
 
But having a compiler on each platform is not so very 
different from having Python installed...
 
The differences are when you get into things like OS calls to files, sockets
etc.
Python masks many of those differences behind the os and socket modules
 
Which do you prefer, portable assembler or portable pseudo code?
 
Alan G. 

------_=_NextPart_001_01C21B87.A97C0F50
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>You can make a program 
on a Windows machine then transfer it to a Linux&nbsp;<SPAN 
class=670570014-24062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>machine and as long as 
it doesn't have any platform specific programming&nbsp;<SPAN 
class=670570014-24062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>in it or has been 
resolved to not have any conflicts I would think you could&nbsp;<SPAN 
class=670570014-24062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>just use it on both 
machines.<SPAN class=670570014-24062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=670570014-24062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>You can do the same with 
C/C++</FONT>&nbsp;<FONT face="Courier New" color=#0000ff> but there are more 
platform </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>specifics to fall over. But if you write a sort 
routine or </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=670570014-24062002><FONT 
face="Courier New" color=#0000ff>number crunching program they will work just 
fine on either</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=670570014-24062002>platform ONCE YOU HAVE COMPILED 
THEM.</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=670570014-24062002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=670570014-24062002>But having a compiler on each platform is not so very 
</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=670570014-24062002>different from having Python 
installed...</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=670570014-24062002></SPAN></FONT><FONT face=Arial 
size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=670570014-24062002>The differences are 
when you get into things like OS calls to files, sockets 
etc.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=670570014-24062002>Python masks many of 
those differences behind the os and socket modules</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=670570014-24062002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=670570014-24062002>Which do you prefer, 
portable assembler or portable pseudo code?</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=670570014-24062002></SPAN></FONT>&nbsp;</DIV>
<DIV><SPAN class=670570014-24062002></SPAN><FONT face=Arial><FONT size=2>A<SPAN 
class=670570014-24062002><FONT face="Courier New" color=#0000ff>lan 
G.&nbsp;</FONT></SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C21B87.A97C0F50--



From alan.gauld@bt.com  Mon Jun 24 16:32:40 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jun 2002 16:32:40 +0100
Subject: [Tutor] "complete number" algorithm
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C691@mbtlipnt02.btlabs.bt.co.uk>

> > why not mark each item as the user types and let them choose?

> Well, the thing is, I'm not using curses, just plain 
> terminal. 

So how are you reading the digits as they are typed?
curses is the normal way to do that from a terminal
(unless you are on a DOS 'terminal' of course?)

Alan g.



From jeff@ccvcorp.com  Mon Jun 24 17:41:11 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 24 Jun 2002 09:41:11 -0700
Subject: [Tutor] File pointers
References: <86C3892A0C52D411AF5000A0C9EAA3B963208B@WTNTEX1>
Message-ID: <3D174BA7.BF2B6998@ccvcorp.com>

"BELSEY, Dylan" wrote:

> Hi,
>         I run the following code:
>
> >>> x = open("script1.py", "r")
> >>> exec x
> In the script
> >>> exec x
> >>>
>
>         As you can see, the second exec() doesn't produce the same result.
> I have deduced that this occurs because the "file pointer", after the first
> call is now sitting at the EOF of the file and so if you make the call
> again, it just sees the EOF.

Hm, the code you've posted shouldn't do what you seem to expect/desire it to do,
even the first time.  After your first line 'x = open("script1.py", "r")', x now
holds a file pointer.  The next line, 'exec x', then execs that file pointer,
*not* the contents of the file.  (Perhaps you left off a read() call while
transcribing?)

In any case, this is probably *not* the best way to go about whatever it is that
you're trying to do -- exec and eval() are dangerous things to use, and should
only be done when you're *sure* that there's no other way to do what you want.
It's not completely clear what you're trying to accomplish, but since you seem
to be wanting to get at user-selected Python code, you should look into using
the __import__() function -- this will import (and thus run) an arbitrary
module, in a much cleaner way than exec-ing would (exec, among numerous other
issues, has a nasty habit of stomping all over your namespace in
unexpected/unpredictable ways).


>         My question is whether there is a simple way to reset this pointer
> to the beginning of the file again.  I could of course just close and
> re-open the file again but unfortunately the exec() command is run in a loop
> which is executed every 50 ms so I want to cut down on the number of file
> ops.  Also, I am trying to avoid the execfile() command as I use a GUI to
> dynamically select a file.

You're trying to run a user-selected *file* 20 times a second?  ISTM that you'd
be better off getting a function reference, and simply calling that function
each time through the loop.  How you get that function (dynamically
imported/selected from your GUI, or whatever) becomes immaterial to the looping
code.

mymodule = __import__('script1', globals(), {}, [])
function = mymodule.mainfunction

import time
while 1:
    result = function()
    if not result:
        break
    time.sleep(0.05)

Something like this ought to behave close to the way you want, though you would
probably want to use your GUI framework's timing systems instead of using
time.sleep().  (Warning -- I have not tested the __import__() statement above,
and have never needed to use __import__() myself, so research this before you
use it!  Start by typing 'help(__import__)' in the interpreter...)

Jeff Shannon
Technician/Programmer
Credit International





From alan.gauld@bt.com  Mon Jun 24 17:48:34 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jun 2002 17:48:34 +0100
Subject: [Tutor] quick query relating to globals (I think)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C694@mbtlipnt02.btlabs.bt.co.uk>

> you do) and I'm wondering if it's possible to make an 
> instance of a class in one of those modules accessible 
> by all the other modules

Thats a really really bad idea in most cases.
It leads to totally non reusable code and is the very 
opposite of good design principles whereby we should 
have high cohesion(within a moduule) and loose 
coupling(betweeen modules)

Your idea makes one and two tightly coupled to thing 
- in fact they won't work without it and neither 
will any code that tries to use them... Furthermore 
any changes to thing will also potentially break 
one and two.

> main calls one and two, main also initialises an instance of the class
> thing.  Without passing the object thing to all the function 
> calls in one and two (which would turn out really really messy) 

Really? It shouldn't. Its how most well designed programs work.
The other option is to encapsulate the functions in one and two
in a class and pass the thing instance to the constructor to 
store as an attribute.

You could also have a theThing variable in the one, two modules 
that you set from main:

# one.py-----

theThing = None

def foo(): 
    print theThing

# main.py----
import thing, one

t = thing.Thing()
one.theThing = t

>   Hmm...just a sec, if thing.py initialised it's own instance 
> of thing, at the global level, then could one.py and two.py 
> do an 'import thing' and access it with thing.thing?

Nope, the instantiation happens when you import the module.

Setting a module level variable is probably your best bet and 
keeps the coupling manageable.


Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From shalehperry@attbi.com  Mon Jun 24 17:53:13 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 24 Jun 2002 09:53:13 -0700 (PDT)
Subject: [Tutor] newB Q: extracting common elements from 2 lists
In-Reply-To: <20020624135128.58910.qmail@web12401.mail.yahoo.com>
Message-ID: <XFMail.20020624095313.shalehperry@attbi.com>

> 
> I have two tuples where the values are lists,
> eg :
>>>> xmap
> {1: [1, 3, 5, 7, 9]}
>>>> ymap
> {1: [1, 2, 3, 4, 5]}
> 

you have a dictionary, not a tuple.  A tuple is like a list but it is constant.

tup = (1,3,5,7,9) # make a tuple

> what I want is to extract the common elements of the
> two tuple values and put them in a new tuple 'list'
> 
> like:
> 
> xymap[1] = xmap[1] *something magic here* ymap[1]
> 
> so xymap[1] contains [1,3,5].
> 
> can it be done?  - as tuples or converted to lists and
> done somehow?
> 
> I found that xymap[1] = xmap[1] and ymap[1] just
> combined the list rather than binary anding them (and
> & caused an error).
> 
> Any advice gratefully received.
> 

def common_elements(list1, list2):
    common = []
    for item in list1:
        if item in list2:
            common.append(item)

xymap[1] = common_elements(xmap[1], ymap[1])

note for large lists this will be a little slow, but it should not be too bad.



From alan.gauld@bt.com  Mon Jun 24 17:53:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jun 2002 17:53:31 +0100
Subject: [Tutor] quick query relating to globals (I think)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C695@mbtlipnt02.btlabs.bt.co.uk>

> >   Hmm...just a sec, if thing.py initialised it's own 
> > instance of thing, at the global level, then could 
> > one.py and two.py do an 'import thing' and access 
> > it with thing.thing?
> 
> ...modules are cached and loaded only once, 
> we're guaranteed that that instance will be
> instantiated only once.

Oops, I'd forgotten about that little feature.
So yes you could do this. Its still a really bad idea to 
have code in one module dependant on the existence of 
an instance in another module however.

Alan g.



From ak@silmarill.org  Mon Jun 24 17:59:50 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Mon, 24 Jun 2002 12:59:50 -0400
Subject: [Tutor] "complete number" algorithm
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C691@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C691@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020624165950.GA4576@ak.silmarill.org>

On Mon, Jun 24, 2002 at 04:32:40PM +0100, alan.gauld@bt.com wrote:
> > > why not mark each item as the user types and let them choose?
> 
> > Well, the thing is, I'm not using curses, just plain 
> > terminal. 
> 
> So how are you reading the digits as they are typed?
> curses is the normal way to do that from a terminal
> (unless you are on a DOS 'terminal' of course?)
> 
> Alan g.
>
I have a small class Term that has member function getch() (along with
a few others):

http://silmarill.org/py_scripts/avk_util.py

> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From ak@silmarill.org  Mon Jun 24 18:04:27 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Mon, 24 Jun 2002 13:04:27 -0400
Subject: [Tutor] newB Q: extracting common elements from 2 lists
In-Reply-To: <20020624135128.58910.qmail@web12401.mail.yahoo.com>
References: <20020624135128.58910.qmail@web12401.mail.yahoo.com>
Message-ID: <20020624170427.GB4576@ak.silmarill.org>

On Mon, Jun 24, 2002 at 06:51:28AM -0700, Stephen Doughty wrote:
> Hi
> 
> I've just discovered the tutor list, I'm hoping to
> learn a lot more about Python by reading other peoples
> querys/answers.
> 
> My question:
> I'm writing an export script for blender and have
> stuck a hitch. I'm trying to work through the problem
> in IDLE, so the examples are from the command line.
> 
> I have two tuples where the values are lists,
> eg :
> >>> xmap
> {1: [1, 3, 5, 7, 9]}
> >>> ymap
> {1: [1, 2, 3, 4, 5]}
> 
> what I want is to extract the common elements of the
> two tuple values and put them in a new tuple 'list'
> 
> like:
> 
> xymap[1] = xmap[1] *something magic here* ymap[1]
> 
> so xymap[1] contains [1,3,5].
> 
> can it be done?  - as tuples or converted to lists and
> done somehow?
> 
> I found that xymap[1] = xmap[1] and ymap[1] just
> combined the list rather than binary anding them (and
> & caused an error).
> 
> Any advice gratefully received.
> 
> Cheers Stephen
>
One way is to do this:

>>> a = [1, 3, 5, 7, 9]
>>> b = [1, 2, 3, 4, 5]
>>> ab = [x for x in a if x in b]
>>> ab
[1, 3, 5]

Or as a loop:
ab = []
for x in a:
	if x in b:
		ab.append(x)

 - Andrei

> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From alan.gauld@bt.com  Mon Jun 24 18:04:12 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jun 2002 18:04:12 +0100
Subject: [Tutor] newB Q: extracting common elements from 2 lists
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C696@mbtlipnt02.btlabs.bt.co.uk>

> I've just discovered the tutor list, I'm hoping to
> learn a lot more about Python by reading other peoples
> querys/answers.

Welcome :-)

> I have two tuples where the values are lists,
> eg :
> >>> xmap
> {1: [1, 3, 5, 7, 9]}

To be pedantic that's a dictionary not a tuple.
But it doesn't make much difference to your question...

> what I want is to extract the common elements of the
> two tuple values and put them in a new tuple 'list'

You know how to get the lists out of the dictionary 
so lets ignore that part and talk about two lists 
L1 and L2.

Theres some clever code shortening can be done here 
but lets keep it simple first off. 

L3 = []
for item in L1:
   if item in L2:
      L3.append(item)

Using list comprehensions we can do it in oner line:

L3 = [item for item in L1 if item in L2]

HTH,

Alan G.




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 24 18:09:36 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 24 Jun 2002 10:09:36 -0700 (PDT)
Subject: [Tutor] quick query relating to globals (I think)
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C695@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.44.0206240958280.4796-100000@hkn.eecs.berkeley.edu>


On Mon, 24 Jun 2002 alan.gauld@bt.com wrote:

> > >   Hmm...just a sec, if thing.py initialised it's own instance of
> > > thing, at the global level, then could one.py and two.py do an
> > > 'import thing' and access it with thing.thing?
> >
> > ...modules are cached and loaded only once, we're guaranteed that that
> > instance will be instantiated only once.
>
> Oops, I'd forgotten about that little feature. So yes you could do this.
> Its still a really bad idea to have code in one module dependant on the
> existence of an instance in another module however.


In that case, then this 'singleton.py' module could have a factory
function that returns the instance itself:

###
## singleton.py

import time
class TimedObject:
    def __init__(self):
        self.instantiation_time = time.time()
    def __str__(self):
        t = time.localtime(self.instantiation_time)
        return "I was instantiated at %s" % \
            time.strftime("%I %M %p", t)

_singleInstance = TimedObject()

def grabSingleton():
    """A factory object that returns the singleton object."""
    return _singleInstance
###

This is nicer because all access to our "single" object is handled through
a grabSingleton() function.  Rather than rudely pulling the singleton out
of the module, we can now use grabSingleton() to nicely ask the module to
give us our instance.


Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Mon Jun 24 18:20:34 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 24 Jun 2002 10:20:34 -0700 (PDT)
Subject: [Tutor] newB Q: extracting common elements from 2 lists
In-Reply-To: <20020624170427.GB4576@ak.silmarill.org>
Message-ID: <Pine.LNX.4.44.0206241010340.4796-100000@hkn.eecs.berkeley.edu>


On Mon, 24 Jun 2002, Andrei Kulakov wrote:

> > >>> xmap
> > {1: [1, 3, 5, 7, 9]}
> > >>> ymap
> > {1: [1, 2, 3, 4, 5]}
> >
> > what I want is to extract the common elements

[some text cut]

> > like:
> >
> > xymap[1] = xmap[1] *something magic here* ymap[1]



We can do some magic if you'd like.  *grin* Let me take Andrei's code
snippet:

> >>> a = [1, 3, 5, 7, 9]
> >>> b = [1, 2, 3, 4, 5]
> >>> ab = [x for x in a if x in b]
> >>> ab
> [1, 3, 5]
>
> Or as a loop:
> ab = []
> for x in a:
> 	if x in b:
> 		ab.append(x)



and mix it into a class that looks a little bit like a map:

###
class IntersectedMap:
    """Returns a map-like object that tries to intersect two maps
in Steven's data structure."""
    def __init__(self, map1, map2):
        self.map1, self.map2 = map1, map2

    def __getitem__(self, index):
        l1 = self.map1[index]
        l2 = self.map2[index]
        return intersection(l1, l2)


def intersection(a, b):
    """Returns the intersection between two lists."""
    ab = []
    for x in a:
        if x in b: ab.append(x)
    return ab
###


Let's see how this might work:

###
>>> xmap = {1 : [1, 3, 5, 7, 9]}
>>> ymap = {1 : [1, 2, 3, 4, 5]}
>>> xymap = IntersectedMap(xmap, ymap)
>>> xymap[1]
[1, 3, 5]
>>> xmap[1].append(2)
>>> xmap
{1: [1, 3, 5, 7, 9, 2]}
>>> xymap[1]
[1, 3, 5, 2]
###



Hope this helps!




From jeff@ccvcorp.com  Mon Jun 24 18:35:33 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 24 Jun 2002 10:35:33 -0700
Subject: [Tutor] newB Q: extracting common elements from 2 lists
References: <20020624135128.58910.qmail@web12401.mail.yahoo.com> <20020624170427.GB4576@ak.silmarill.org>
Message-ID: <3D175865.713C3378@ccvcorp.com>


Andrei Kulakov wrote:

> On Mon, Jun 24, 2002 at 06:51:28AM -0700, Stephen Doughty wrote:
>
> > I have two tuples where the values are lists,
> > eg :
> > >>> xmap
> > {1: [1, 3, 5, 7, 9]}
> > >>> ymap
> > {1: [1, 2, 3, 4, 5]}
> >
> > what I want is to extract the common elements of the
> > two tuple values and put them in a new tuple 'list'
>
> One way is to do this:
>
> >>> a = [1, 3, 5, 7, 9]
> >>> b = [1, 2, 3, 4, 5]
> >>> ab = [x for x in a if x in b]
> >>> ab
> [1, 3, 5]

This works great as long as your lists are short, but if the lists that
you're comparing are large (dozens to hundreds of elements each, or
more), then this can get *very* slow, because the 'in' operator needs to
look at each element of the list -- the way this is constructed, you end
up searching len(a) * len(b) elements.  That's fine for these examples
(the above results in 25 compares), but if each list is 20 elements
long, you need 400 compares, and if they're 100 elements each, then
that's 10,000 compares!

An alternate way of doing this, that does *not* suffer from that
logarithmic slowdown, is to take advantage of the properties of Python
dictionaries -- a dictionary lookup takes constant time, no matter how
many elements are in the dictionary.  So, first we can convert list a
into a dictionary --

>>> tempdict = {}
>>> for item in a:
...     tempdict[item] = 1
...
>>>

(We're only worried about the existence of items, so we can just use 1
as the value for each element in the dictionary.)  Now, we go through
list b, and each item that's in list b *and* the dictionary gets added
to list ab --

>>> ab = []
>>> for item in b:
...     if tempdict.haskey(item):
...         ab.append(item)
...
>>>

This method takes a bit more overhead than the approach that Andrei and
Alan showed, but it takes time that's proportional to the *sum* of the
list lengths, instead of the *product* of the list lengths -- for the
above example, with lists of length 5, you have 10 operations (though
each one is possibly slower than each of the 25 operations for the other
method).  However, with lists of length 20, you only need 40 operations,
and for 100-element lists, you only need 200 operations -- a far cry
from the 10,000 that the other method needed!

Of course, this is all an optimization, and as such, we shouldn't be
*too* eager to make use of it -- premature optimization is a great
pitfall, and you should only optimize when you *know* that a particular
segment of code is a bottleneck.  I'm not saying that you *should* use
this dictionary-method (if you expect your lists to stay in the 5-10
element size range, the other method is probably clearer and thus
better), I'm just showing you that there's other options that might work
better depending on your circumstances/requirements.

Jeff Shannon
Technician/Programmer
Credit International





From kent@springfed.com  Mon Jun 24 19:31:41 2002
From: kent@springfed.com (kent@springfed.com)
Date: Mon, 24 Jun 2002 13:31:41 -0500
Subject: [Tutor] How to ping
In-Reply-To: <28051.1024832487@www42.gmx.net>
Message-ID: <200206241832.g5OIWDl6013732@bucky.airstreamcomm.net>

I'm having trouble getting this to work,
this is what I've tried;

>>>import socket
>>>s =3D socket.socket(socket.AF_INET,socket.IPPROTO_ICMP)
>>>target =3D ('192.168.1.20', 5813)
>>>s.connect(target)
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "<string>", line 1, in connect
error: (10061, 'Connection refused')

I clearly don't have a clue.
I've been wanting a working 'ping' in Python, any
help would be appreciated.

Thanks,
Kent





On Sun, 23 Jun 2002 13:41:27 +0200 (MEST), lumbricus@gmx.net=
 wrote:
>=A0On Sun, Jun 23, 2002 at 12:24:53PM +1000, Dimitrije Nikic=
 wrote:
>=A0>=A0Hey people,
>=A0>=A0How do you ping an IP address and then assign the ping to a
>>=A0variable?

What do you mean with "the ping"
The output of the ping command is implementation dependend.
You may want to parse it.

>=A0>=A0Thx for your help...
>
>=A0You could try doing my_var =3D commands.getoutput("ping ip")

use the socket module
And send an IPPROTO_ICMP packet with ECHO_REPLY set.

>=A0- Andrei

HTH,HAND
and Greetings, J"o!


--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net



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






From dman@dman.ddts.net  Mon Jun 24 21:33:29 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon, 24 Jun 2002 15:33:29 -0500
Subject: [Tutor] Re: How to ping
In-Reply-To: <200206241832.g5OIWDl6013732@bucky.airstreamcomm.net>
References: <28051.1024832487@www42.gmx.net> <200206241832.g5OIWDl6013732@bucky.airstreamcomm.net>
Message-ID: <20020624203329.GA19991@dman.ddts.net>

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

On Mon, Jun 24, 2002 at 01:31:41PM -0500, kent@springfed.com wrote:
| I'm having trouble getting this to work,
| this is what I've tried;
|=20
| >>>import socket
| >>>s =3D socket.socket(socket.AF_INET,socket.IPPROTO_ICMP)
| >>>target =3D ('192.168.1.20', 5813)
| >>>s.connect(target)
| Traceback (most recent call last):
|   File "<input>", line 1, in ?
|   File "<string>", line 1, in connect
| error: (10061, 'Connection refused')

Is there a server listening on that port on that machine?  Are there
any firewalls in the middle that would block the connection?  Those
are the usual causes of "Connection refused" messages.
=20
-D

--=20

Better a little with righteousness
than much gain with injustice.
        Proverbs 16:8
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0XghkACgkQO8l8XBKTpRTdbwCgkP7scLcSxrdrSX0S5T2zCpDp
/8AAmgLy2DikYihEGgY3/uQIsal75KqT
=ka9F
-----END PGP SIGNATURE-----

--mYCpIKhGyMATD0i+--



From kent@springfed.com  Mon Jun 24 21:44:58 2002
From: kent@springfed.com (kent@springfed.com)
Date: Mon, 24 Jun 2002 15:44:58 -0500
Subject: [Tutor] Re: How to ping
In-Reply-To: <20020624203329.GA19991@dman.ddts.net>
Message-ID: <200206242045.g5OKjWl6016943@bucky.airstreamcomm.net>

>Is there a server listening on that port on that machine?

Yes. If I use 'ping' from the command line I get success.

Is my code correct?
Does it work for you?
Is port 5813 the right port?

Thanks,
Kent



On Mon, 24 Jun 2002 15:33:29 -0500, Derrick 'dman' Hudson wrote:
On Mon, Jun 24, 2002 at 01:31:41PM -0500, kent@springfed.com=
 wrote:
| I'm having trouble getting this to work,
| this is what I've tried;
|
| >>>import socket
| >>>s =3D socket.socket(socket.AF_INET,socket.IPPROTO_ICMP)
| >>>target =3D ('192.168.1.20', 5813)
| >>>s.connect(target)
| Traceback (most recent call last):
| =A0 File "<input>", line 1, in ?
| =A0 File "<string>", line 1, in connect
| error: (10061, 'Connection refused')

Is there a server listening on that port on that machine? =A0Are=
 there
any firewalls in the middle that would block the connection?=
 =A0Those
are the usual causes of "Connection refused" messages.

-D

--

Better a little with righteousness
than much gain with injustice.
=A0=A0=A0=A0Proverbs 16:8

http://dman.ddts.net/~dman/








From gew75@uow.edu.au  Mon Jun 24 23:35:45 2002
From: gew75@uow.edu.au (Glen Edward Wheeler)
Date: Tue, 25 Jun 2002 08:35:45 +1000
Subject: [Tutor] quick query relating to globals (I think)
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C694@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <002601c21bcf$7e3e7d80$b946dccb@uow.speedlink.com.au>

> >... calls in one and two (which would turn out really really messy)
>
> Really? It shouldn't. Its how most well designed programs work.

  The reason I say the above is that one and two.py (there are more, about 8
different modules) are mainly classes grouped together that all do different
things, but are only called by the main module.  The object I want them all
to have access to is an instance of a class which handles the program's
output to the screen.  It would be easier in one class to just output
something if needed instead of having to be passed the instance of the
display class or have to return any output to the screen as well as other
data.

> The other option is to encapsulate the functions in one and two
> in a class and pass the thing instance to the constructor to
> store as an attribute.
>
> You could also have a theThing variable in the one, two modules
> that you set from main:
>
> # one.py-----
>
> theThing = None
>
> def foo():
>     print theThing
>
> # main.py----
> import thing, one
>
> t = thing.Thing()
> one.theThing = t
>

  This sort of idea looks almost exactly like what I'm looking for.  The
program I'm writing (happens to be a game) is pretty huge in scope (at least
for me, whose largest project to date is 20,000 lines of python...I know
this pales to you guys'), and the calls to the display module are mainly
there for debugging purposes...eventually when most of the logic of the game
is working I will use pygame for the UI and any graphic effects, and the
display module will be given a massive facelift from a text based game to
one with plenty of graphics...toying with the idea of an isometric engine,
but that's only toying.
  Anywho so eventually all this 'bad' coupling will go away, all my modules
will be fairly independent save for the main which manipulates everything
else, and all will be well...

  Thanks for your help!
  Glen




From swdoughty@yahoo.com.au  Tue Jun 25 00:01:05 2002
From: swdoughty@yahoo.com.au (Stephen Doughty)
Date: Mon, 24 Jun 2002 16:01:05 -0700 (PDT)
Subject: Thanks for the answers to newB Q: extracting common elements                            RE: [Tutor] newB Q: extracting common elements from 2 lists
Message-ID: <20020624230105.48952.qmail@web12405.mail.yahoo.com>

Hi

Thanks for the very quick answers everyone, I'll have
a go at the nested if statements tonight.

Thanks for pointing out I was talking about
dictionaries rather than tuples - I'm still getting
confused between lists, tuples and dictionaries.

Cheers Stephen

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From shalehperry@attbi.com  Tue Jun 25 00:19:38 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 24 Jun 2002 16:19:38 -0700 (PDT)
Subject: [Tutor] RE: Thanks for the answers to newB Q: extracting common elements
In-Reply-To: <20020624230105.48952.qmail@web12405.mail.yahoo.com>
Message-ID: <XFMail.20020624161938.shalehperry@attbi.com>

On 24-Jun-2002 Stephen Doughty wrote:
> Hi
> 
> Thanks for the very quick answers everyone, I'll have
> a go at the nested if statements tonight.
> 
> Thanks for pointing out I was talking about
> dictionaries rather than tuples - I'm still getting
> confused between lists, tuples and dictionaries.
> 

a list is a collection of items.  The common use of a list is just what its
name says.  Think of it like a bullet list or a shopping list.  Items in the
list are accessed either directly by index (list[3]) or are iterated over 'for
item in list'.

a tuple is basically a static (or constant) list.  list.append(foo) will add
foo to the list.  There is no way to add an item to a tuple.  So tuples get
used for anything that is created once and not changed.  In python any item
that is constant like this can be used as a dictionary key.  So you could have
a map of x,y coordinates to items.

Which leads us to dictionaries (C++ refers to them as maps, perl calls them
hashes).  Just like a paper dictionary they store a key and its data.  These
are great for address books, real dictionaries, or just about any mapping
structure.

coord = (2,5)
dict[coord] = my_image

for instance would store my image in the dictionary under the key (2,5) which
is a tuple.  This could be used in a graphing program.  dictionary keys are
unique -- there can only be one image at (2,5).  As Jeff Shannon pointed out,
this is used in some algorithms for getting unique values.  Another example is:

uniqs = {}
my_nums = [1, 2, 5, 7, 1, 3, 5]

for num in my_nums:
  uniqs[num] = 1

for num in uniqs.keys():
  print num

outputs:
1
2
5
7
3 (or something like that, you never know what order the keys are in).

When a problem presents itself you just need to ask how am i going to use the
data?  Do I need to access it by some value like a name or a coordinate?  Will
I always just walk the collection from beginning to end?  Does this represent a
map of thing -> other thing or is this more of a generic collection of things?



From tbrauch@mindless.com  Tue Jun 25 00:52:48 2002
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Mon, 24 Jun 2002 19:52:48 -0400
Subject: [Tutor] Web Based Form Question
Message-ID: <001901c21bda$3edbae00$9c21840a@tmbrau00>

There is a form I use on the internet that is written in Python.  Basically
I have to enter a number in the form to look up the data on something, then
pull the relevant data from the resulting page.

What I was wondering is if there was a way I could write a little script
that would help me do this.  If I could figure out how to get the results
page using Python, I could easily extract the important data.

Here is the relevant part of the web form...

<form method="post" action="cnvrprt.py">
<input name="idnumber" type="text">
<input name="" type="submit" value="Submit">
</form>

I just need to run through a file of id numbers using this form.

Any help?

 - Tim






From dyoo@hkn.eecs.berkeley.edu  Tue Jun 25 02:09:17 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 24 Jun 2002 18:09:17 -0700 (PDT)
Subject: [Tutor] Web Based Form Question
In-Reply-To: <001901c21bda$3edbae00$9c21840a@tmbrau00>
Message-ID: <Pine.LNX.4.44.0206241803020.14262-100000@hkn.eecs.berkeley.edu>


On Mon, 24 Jun 2002, Timothy M. Brauch wrote:

> There is a form I use on the internet that is written in Python.  Basically
> I have to enter a number in the form to look up the data on something, then
> pull the relevant data from the resulting page.
>
> What I was wondering is if there was a way I could write a little script
> that would help me do this.  If I could figure out how to get the results
> page using Python, I could easily extract the important data.
>
> Here is the relevant part of the web form...
>
> <form method="post" action="cnvrprt.py">
> <input name="idnumber" type="text">
> <input name="" type="submit" value="Submit">
> </form>


I think you can use 'urllib2' or 'httplib' to simulate a web browser doing
the submission, and then use a simple parser to extract the data.

For your script, you might be able to do something like:

###
import urllib2, urllib

def submit(url, id_number):
    """Given an url and an id_number, returns a file-like object that
holds the content of the server's response."""
    data = urllib.urlencode({'idnumber' : id_number})
    return urllib2.urlopen(url, data)
###


(I haven't tried this out though.  *grin*)  But it should be something
like that.  For more details, we can look at:

    http://www.python.org/doc/lib/module-urllib2.html



Hope this helps!




From dman@dman.ddts.net  Tue Jun 25 04:27:43 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon, 24 Jun 2002 22:27:43 -0500
Subject: [Tutor] Re: Re: How to ping
In-Reply-To: <200206242045.g5OKjWl6016943@bucky.airstreamcomm.net>
References: <20020624203329.GA19991@dman.ddts.net> <200206242045.g5OKjWl6016943@bucky.airstreamcomm.net>
Message-ID: <20020625032743.GA24328@dman.ddts.net>

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

On Mon, Jun 24, 2002 at 03:44:58PM -0500, kent@springfed.com wrote:
| >Is there a server listening on that port on that machine?
|=20
| Yes. If I use 'ping' from the command line I get success.

ping checks the Layer 3 connectivity.  It shows you that you have
a host<->host connection.  It doesn't check Layer 4, TCP.  You can
have host-host connectivity but still not have any programs (server)
listening on the TCP port.

| Is my code correct?

I don't know, I run /bin/ping when I need to, I don't try rewriting it
:-).

| Does it work for you?

No.  /bin/ping does, though.

| Is port 5813 the right port?

ping uses ICMP, not TCP.  ICMP doesn't have ports.

HTH,
-D

--=20

I can do all things through Christ who strengthens me.
        Philippians 4:13
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0X4y8ACgkQO8l8XBKTpRT2GwCeOgR6lX7EAsCTHxctJGSYXuRX
d4AAoLH6yAUGCDy9rd9VernTz4HDQm5z
=RSe7
-----END PGP SIGNATURE-----

--vkogqOf2sHV7VnPd--



From alex@gabuzomeu.net  Tue Jun 25 09:24:25 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Tue, 25 Jun 2002 10:24:25 +0200
Subject: [Tutor] newB Q: extracting common elements from 2 lists
Message-ID: <4.3.2.7.2.20020625102411.00e44c30@pop3.norton.antivirus>

At 18:41 24/06/2002 -0400, you wrote:
>Date: Mon, 24 Jun 2002 10:35:33 -0700
>From: "Jeff Shannon" <jeff@ccvcorp.com>
>Subject: Re: [Tutor] newB Q: extracting common elements from 2 lists

[Extracting common items from two lists]
>An alternate way of doing this, that does *not* suffer from that
>logarithmic slowdown, is to take advantage of the properties of Python
>dictionaries -- a dictionary lookup takes constant time, no matter how
>many elements are in the dictionary.  So, first we can convert list a
>into a dictionary --

>(We're only worried about the existence of items, so we can just use 1
>as the value for each element in the dictionary.)  Now, we go through
>list b, and each item that's in list b *and* the dictionary gets added
>to list ab --
>
> >>> ab = []
> >>> for item in b:
>...     if tempdict.haskey(item):
>...         ab.append(item)
>...
> >>>

I remember dictionaries support "in" in Python 2.2. We could also write:

 >>> a = {1:0, 2:0, 3:0, 4:0}
 >>> b = {3:0, 4:0, 5:0}
 >>> print  [x for x in a if x in b]
[3, 4]

or

 >>> a = [1, 2, 3, 4]
 >>> b = {3:0, 4:0, 5:0}
 >>> print  [x for x in a if x in b]
[3, 4]

Do we get the same speedup?

Is it useful to store the "a" values in a dictionary here, or is the 2nd 
form the optimal one? I guess we need to iterate over the values of a, 
hence a sequence is probably the best fit?


Cheers.

Alexandre




From dyoo@hkn.eecs.berkeley.edu  Tue Jun 25 10:14:37 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 25 Jun 2002 02:14:37 -0700 (PDT)
Subject: [Tutor] newB Q:   [does 'has_key()' and 'in' do the same things?]
In-Reply-To: <4.3.2.7.2.20020625102411.00e44c30@pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.44.0206250141260.24078-100000@hkn.eecs.berkeley.edu>


> I remember dictionaries support "in" in Python 2.2. We could also write:
>
>  >>> a = {1:0, 2:0, 3:0, 4:0}
>  >>> b = {3:0, 4:0, 5:0}
>  >>> print  [x for x in a if x in b]
> [3, 4]
>
> or
>
>  >>> a = [1, 2, 3, 4]
>  >>> b = {3:0, 4:0, 5:0}
>  >>> print  [x for x in a if x in b]
> [3, 4]
>
> Do we get the same speedup?


According to:

    http://www.python.org/doc/current/ref/comparisons.html

the 'in' operator is equivalent to calling the special method
'__contains__' of a Python object.


Hmmmm... this is interesting!  Ah!  The documentation says something about
dictionaries and 'in':


"""The operators in and not in test for set membership. x in s evaluates
to true if x is a member of the set s, and false otherwise. x not in s
returns the negation of x in s. The set membership test has traditionally
been bound to sequences; an object is a member of a set if the set is a
sequence and contains an element equal to that object. However, it is
possible for an object to support membership tests without being a
sequence. In particular, dictionaries support memership testing as a nicer
way of spelling key in dict; other mapping types may follow suit."""


So this implies that, yes, if we use 'has_key() or an 'in' with a
dictionary, like:

###
>>> b = {3:1, 4:1, 5:9}
>>> 3 in b
1
>>> b.has_key(3)
1
###

we should always get back the same answer in Python 2.2.  Hmmm...
dictionaries are getting downright casual!  *grin*


I also did a quick check through Python's source code to see how
__contains__ was implemented for dictionaries.  What I saw surprised me a
little bit;  but in a good way.  The code that does the 'is' check is
almost line-by-line identical to how has_key() does things.  (There are
minor, low-level differences due to what the Python/C API expects from a
'__contains__' implementation.)

My guess is that the performance difference by using 'key in dict' is the
same, as using has_key(), so we should get the same speedup from using
your version of the comparison.  Very cool!












[warning: skip this part if you haven't seen C code, and aren't interested
in looking at Python's guts.  But for those who like to glare mindlessly
at C code, here's the relevant section of dictobject.c:

/***/
/** Within Objects/dictobject.c **/

static PyObject *
dict_has_key(register dictobject *mp, PyObject *key)
{
        long hash;
        register long ok;
#ifdef CACHE_HASH
        if (!PyString_CheckExact(key) ||
            (hash = ((PyStringObject *) key)->ob_shash) == -1)
#endif
        {
                hash = PyObject_Hash(key);
                if (hash == -1)
                        return NULL;
        }
        ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
        return PyInt_FromLong(ok);
}


/** ... later in Objects/dictobject.c ... **/


static int
dict_contains(dictobject *mp, PyObject *key)
{
        long hash;

#ifdef CACHE_HASH
        if (!PyString_CheckExact(key) ||
            (hash = ((PyStringObject *) key)->ob_shash) == -1)
#endif
        {
                hash = PyObject_Hash(key);
                if (hash == -1)
                        return -1;
        }
        return (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
}
/***/

One difference is that dict_has_key() is exposed as a dictionary method
for us to use in Python, so it needs to generate real Python objects for
its return value.

dict_contains(), on the other hand, is only used internally by the Python
system, and is not called directly from us, so it can work straight with C
integers.  There is some duplication of code, but in this case, it's
probably worth it, as these functions should run at high speed.]


Good night!




From alan.gauld@bt.com  Tue Jun 25 11:04:16 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 25 Jun 2002 11:04:16 +0100
Subject: [Tutor] quick query relating to globals (I think)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C697@mbtlipnt02.btlabs.bt.co.uk>

>   The reason I say the above is that one and two.py (there 
> are more, about 8 different modules) are mainly classes 
> grouped together that all do different things, 
> but are only called by the main module.  

Yes, that's what I'd expect.

> The object I want them all to have access to is an instance 
> of a class which handles the program's output to the screen.  

OK, That's a fairly common requirement.

> It would be easier in one class to just output something 
> if needed instead of having to be passed the instance of the
> display class or have to return any output to the screen as 
> well as other data.

OK, thus is where if you draw the object model you get a star 
formation with the display in the middle and all the classes 
accessing it, ie having a relationship with it. 

Therefore they should all know about the display(sometimes 
called a view onbject in GUI terms) and use a standard protocol 
to talk to the view. This way you can easily change the view 
from a debugging view to a fastview to a GUIview etc so long 
as you keep the view interface.

Thats what I meant aboutreuse. If you pass the view object
(thing in your case) to reach class constructor you canlater 
use those classes in other projects with a totally diffeent 
view provoided it has the same protocol.

> program I'm writing (happens to be a game) is pretty huge in 
> scope (at least for me, whose largest project to date is 
> 20,000 lines of python

Thats pretty big for Python, certainly way bigger than anything 
I've tackled in Python(3000 lines I think?). It translates to 
something like 100,000 lines of Java or C++!

> the calls to the display module are mainly there for 
> debugging purposes...eventually when most of the 
> logic of the game is working I will use pygame for 
> the UI and any graphic effects

So can you write thing to have the same interface as the 
Pygame stuff thus making it easy to just instantiate a different 
object when debugging versus production use? Thats the whole 
point of OO design, to make that kind of change near transparent...

class Display:
   def f(s): pass

class DebugDisplay(Display):
   def f(s):
      print 'doing f now'
      Display.f(s)

class PyGameDisplay(Display):
   def f(s):
      # various PyGame calls implementing f() behaviour


Now, provided One etc only use the generic Display functions
you can instantiate One, Two etc with:

import display, one, two, ....
activeDisplay = DebugDisplay()
# activeDisplay = PyGameDisplay()

one.One(activeDisplay)
two.Two(activeDisplay)
etc...


And just comment/uncomment the display you want to use...

Just some thoughts,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From rob@uselesspython.com  Tue Jun 25 16:04:58 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Tue, 25 Jun 2002 10:04:58 -0500
Subject: [Tutor] imaginary number class
Message-ID: <3D18869A.8010602@uselesspython.com>

This is a multi-part message in MIME format.
--------------090102090307010709010902
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

For your enjoyment:

I'm staring down the barrel of a problem in my C++ class that has me 
scratching my head a bit. The professor said we could solicit help from 
any resource we wish, as long as that resource doesn't provide us the 
actual working C++ code for the answer. So, I turn to the tutor list 
with what should prove an interesting minor academic challenge.

If anyone can help me figure out how to do this in Python, that would 
very likely give me a much-appreciated assist. If nothing else, someone 
out there might think this is a really fun thing to do on its own merits.

We have been tasked with writing "a class for an imaginary number" using 
the attached Rational.h file as an example. I don't have any problems 
writing the code itself, but don't really have a comprehensive 
understanding of imaginary numbers. I'm at a bit of a loss as to how to 
perform common operations on them.

(By the way, I've been taking notes for the C++ class on my laptop and 
coding some of the assignments in both C++ and in Python. I plan to 
bundle all this up for Useless Python soon.)

Rob
http://uselesspython.com

--------------090102090307010709010902
Content-Type: text/plain;
 name="Rational.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Rational.h"

// rational.h: declaration of Rational ADT

#include <iostream>
#include <string>

using namespace std;

// Rational ADT: class description
class Rational {
	public: // member functions
		// default constructor
		Rational();
		// a second constructor
		Rational(int numer, int denom = 1);
		// some arithmetic and stream facilitators
		Rational Add(const Rational &r) const;
		Rational Subtract(const Rational &r) const;
		Rational Multiply(const Rational &r) const;
		Rational Divide(const Rational &r) const;
		void Insert(ostream &sout) const;
		void Extract(istream &sin);
	protected:
		// inspectors
		int getNumerator() const;
		int getDenominator() const;
		// mutators
		void setNumerator(int numer);
		void setDenominator(int denom);
	private:
		// data members
		int numeratorValue;
		int denominatorValue;
};

// Rational ADT: auxiliary operator description
Rational operator+(const Rational &r, const Rational &s);
Rational operator-(const Rational &r, const Rational &s);
Rational operator*(const Rational &r, const Rational &s);
Rational operator/(const Rational &r, const Rational &s);

ostream& operator<<(ostream &sout, const Rational &s);
istream& operator>>(istream &sin, Rational &r);


// default constructor
Rational::Rational() {
	setNumerator(0);
	setDenominator(1);
}

// (numer, denom) constructor
Rational::Rational(int numer, int denom) {
	setNumerator(numer);
	setDenominator(denom);
}

// get the numerator
int Rational::getNumerator() const {
	return numeratorValue;
}

// get the denominator
int Rational::getDenominator() const {
	return denominatorValue;
}

// set the numerator
void Rational::setNumerator(int numer) {
	numeratorValue = numer;
}

// set the denominator
void Rational::setDenominator(int denom) {
	if (denom != 0) {
		denominatorValue = denom;
	}
	else {
		cerr << "Illegal denominator: " << denom
		<< "using 1" << endl;
		denominatorValue = 1;
	}
}

// adding Rationals
Rational Rational::Add(const Rational &r) const {
	int a = getNumerator();
	int b = getDenominator();
	int c = r.getNumerator();
	int d = r.getDenominator();
	return Rational(a*d + b*c, b*d);
}

// subtracting Rationals
Rational Rational::Subtract(const Rational &r) const {
	int a = getNumerator();
	int b = getDenominator();
	int c = r.getNumerator();
	int d = r.getDenominator();
	return Rational(a*d - b*c, b*d);
}

// multiplying Rationals
Rational Rational::Multiply(const Rational &r) const {
	int a = getNumerator();
	int b = getDenominator();
	int c = r.getNumerator();
	int d = r.getDenominator();
	return Rational(a*c, b*d);
}

// dividing Rationals
Rational Rational::Divide(const Rational &r) const {
	int a = getNumerator();
	int b = getDenominator();
	int c = r.getNumerator();
	int d = r.getDenominator();
	return Rational(a*d, b*c);
}

// inserting a Rational
void Rational::Insert(ostream &sout) const {
	sout << getNumerator() << '/' << getDenominator();
	return;
}

// extracting a Rational
void Rational::Extract(istream &sin) {
	int numer;
	int denom;
	char slash;
	sin >> numer >> slash >> denom;
	setNumerator(numer);
	setDenominator(denom);
	return;
}

// adding Rationals
Rational operator+(const Rational &r, const Rational &s) {
	return r.Add(s);
}

// subtracting Rationals
Rational operator-(const Rational &r, const Rational &s) {
	return r.Subtract(s);
}

// multiplying Rationals
Rational operator*(const Rational &r, const Rational &s) {
	return r.Multiply(s);
}

// dividing Rationals
Rational operator/(const Rational &r, const Rational &s) {
	return r.Divide(s);
}

// inserting a Rational
ostream& operator<<(ostream &sout, const Rational &r) {
	r.Insert(sout);
	return sout;
}

// extracting a Rational
istream& operator>>(istream &sin, Rational &r) {
	r.Extract(sin);
	return sin;
}
--------------090102090307010709010902--





From gew75@uow.edu.au  Tue Jun 25 16:21:58 2002
From: gew75@uow.edu.au (Glen Edward Wheeler)
Date: Wed, 26 Jun 2002 01:21:58 +1000
Subject: [Tutor] quick query relating to globals (I think)
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C697@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <002d01c21c5c$0c835de0$b946dccb@uow.speedlink.com.au>

> > program I'm writing (happens to be a game) is pretty huge in
> > scope (at least for me, whose largest project to date is
> > 20,000 lines of python
>
> Thats pretty big for Python, certainly way bigger than anything
> I've tackled in Python(3000 lines I think?). It translates to
> something like 100,000 lines of Java or C++!
>

  I don't know much java, but have done quite a bit of C++...I shudder to
think about the C++ code I'd have to write to even do what I've already
done, let alone when it finally garners a pygame-enhanced UI...The other big
project happenned to be another game, which I wrote for this company in
tkinter (I'm a uni student and I work at this company in the breaks - this
game however is just for fun) ...it was initially just to show how versatile
the tkinter library was but when they saw the little pong-like game, they
wanted the game instead of anything else I was making.  Ended up growing to
silly proportions :).

> > the calls to the display module are mainly there for
> > debugging purposes...eventually when most of the
> > logic of the game is working I will use pygame for
> > the UI and any graphic effects
>
> So can you write thing to have the same interface as the
> Pygame stuff thus making it easy to just instantiate a different
> object when debugging versus production use? Thats the whole
> point of OO design, to make that kind of change near transparent...
>
> [.. cool code ..]
>
> And just comment/uncomment the display you want to use...
>

  Yep, sure can.  I was just fearing stepping into any namespace holes of
'well, there goes three hundred lines of coding...' and it turns out I
almost did...thanks alot for your help!




From glingl@aon.at  Tue Jun 25 17:17:38 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 25 Jun 2002 18:17:38 +0200
Subject: [Tutor] imaginary number class
Message-ID: <3D1897A2.6EC65A75@rg16.asn-wien.ac.at>


Dear Rob!
Unfortunately I haven't got much time to answer to
your interesting question at the moment. Nevertheless
a few remarks:

Rob Andrews schrieb:

> For your enjoyment:
>
> I'm staring down the barrel of a problem in my C++ class that has me
> scratching my head a bit. The professor said we could solicit help from
> any resource we wish, as long as that resource doesn't provide us the
> actual working C++ code for the answer. So, I turn to the tutor list
> with what should prove an interesting minor academic challenge.
>
> If anyone can help me figure out how to do this in Python, that would
> very likely give me a much-appreciated assist. If nothing else, someone
> out there might think this is a really fun thing to do on its own merits.
>
> We have been tasked with writing "a class for an imaginary number" using
> the attached Rational.h file as an example. I don't have any problems
> writing the code itself, but don't really have a comprehensive
> understanding of imaginary numbers. I'm at a bit of a loss as to how to
> perform common operations on them.

Unfortunately [ ;-) ] Python has this complex-type built in, so it would
be
useless - in the highest sense of the word - to implement it on your own
in Python.  So it's most appropriate for you. Just try it!

First you could use Python to explore complex numbers, e. g. this way:

>>> 1j+2j
3j
>>> 1j+2j  # imaginary
3j
>>> (1+3j) + (2-5j)  # complex
(3-2j)
>>> (1+3j) * (2-5j)  # complex
(17+1j)
>>> (1+3j) - (2-5j)  # complex
(-1+8j)
>>> (1+3j) / (2-5j)  # complex
(-0.44827586206896552+0.37931034482758624j)
>>> # Then import complex mathematics
>>> import cmath
>>> # to verify:
>>> cmath.sqrt(-1)
1j
>>> # play around
>>> z = 3+4j
>>> abs(z)
5.0
>>> z.conjugate()
(3-4j)
>>> z.real
3.0
>>> z.imag
4.0
>>>

You may find information about this at:

http://www.python.org/doc/current/lib/typesnumeric.html

An example of how to implement things like these in Python was
posted by Kirby several month ago. It's contained in:

http://mail.python.org/pipermail/tutor/2002-January/011021.html

(It's actually an implementatino of the rationals-class, which is
described in
your
rational.h)

Have fun! (And excuse, that I didn't talk more to you, but I'm sure
there are
lots
of people on this list, who will add ample contributions ....   (hooo,
... my
English!)

Gregor

>
>
> (By the way, I've been taking notes for the C++ class on my laptop and
> coding some of the assignments in both C++ and in Python. I plan to
> bundle all this up for Useless Python soon.)
>
> Rob
> http://uselesspython.com
>
>   ------------------------------------------------------------------------
> // rational.h: declaration of Rational ADT
>
> etc. etc.



From alan.gauld@bt.com  Tue Jun 25 17:34:35 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 25 Jun 2002 17:34:35 +0100
Subject: [Tutor] imaginary number class
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A0@mbtlipnt02.btlabs.bt.co.uk>

> writing the code itself, but don't really have a comprehensive 
> understanding of imaginary numbers. I'm at a bit of a loss as 
> to how to perform common operations on them.

One thing to do is play with Python complex numbers

>>> a = 3+4j
>>> b = 5+6j
>>> a+b
8+10j

pretty straightforward add the components...
>>> a-b
-2-2j
yep just subtract the components...

>>> a*b
-9+38j

Hmmm, bit strange.
Think of the numbers like algebraic expressions:

(3+4j)(5+6j) = 3*5+4j*5+3*6j+4j*6j

And recalling that j*j = -1:

= 15 + 20j + 18j + -1(24)

= 15-24 + 38j

= -9+38j

voila

>>> a/b
0.6393...+0.0327...j

Uh oh. This is a bit harder.

Here we have to multiply top and bottom by the 
inverse of the denomoninator: (which mathematically 
is like multiplying by one!)

(a+bj)/(c+dj) = (a+bj)(c-dj)/(c+dj)(c-dj)

The reason is that the inverse multiplier turns 
the bottom line into a real number:

(c+dj)(c-dj) = c*c + c*dj - c*dj - dj*dj

= c*c - -1(d*d) = c*c + d*d  = X which is real.

So now we get:
(a+bj)(c-dj)/X

So do the multiplication then divide each term by X.

(3+4j)(5-j6)/(25+36) = (15 + 20j - 18j - -1(24))/61

= 39/61 + 2j/61 = 0.6393...+0.0327...j

Conversion between complex and polar is done by thinking 
of the real axis as horizontal, the imaginary one as vertical 
and using trigonometry... Magnitude is determined by pythagorus.

HTH

Alan G.



From terjeja@hotmail.com  Tue Jun 25 18:40:03 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Tue, 25 Jun 2002 17:40:03 +0000
Subject: [Tutor] or
Message-ID: <F193Qu0216Aha0jCaXj00006d49@hotmail.com>

I have the following:
>>>ffac.xlpol =u'NAB02658508'

Then I try:
>>>if ffac.xlpol[0] == u's' or u'S':
... 	print"yes"
...
yes

This is clearly wrong. If I remove the or and the last u'S' it works. How 
can I get it to do the if statement if either u's' or u'S' is correct?

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From rickp@telocity.com  Tue Jun 25 18:48:03 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Tue, 25 Jun 2002 13:48:03 -0400
Subject: [Tutor] or
In-Reply-To: <F193Qu0216Aha0jCaXj00006d49@hotmail.com>
References: <F193Qu0216Aha0jCaXj00006d49@hotmail.com>
Message-ID: <20020625174803.GA27728@tc.niof.net>

On Tue, Jun 25, 2002 at 05:40:03PM +0000, Terje Johan Abrahamsen wrote:
> I have the following:
> >>>ffac.xlpol =u'NAB02658508'
> 
> Then I try:
> >>>if ffac.xlpol[0] == u's' or u'S':
> ... 	print"yes"
> ...
> yes
> 
> This is clearly wrong. If I remove the or and the last u'S' it works. How 
> can I get it to do the if statement if either u's' or u'S' is correct?

It is clearly *correct*. u'S' is always true.

What you probably meant to write was 

>>> if ffac.xlpol[0] == u's' or ffac.slpol[0] == u'S':

or perhaps

>>> if ffac.xlpol[0] in (u's',u'S'):

-- 
"One of the symptoms of an approaching nervous breakdown is the
belief that one's work is terribly important."
		-- Bertrand Russell
    Rick Pasotto    rickp@telocity.com    http://www.niof.net



From urnerk@qwest.net  Tue Jun 25 17:41:27 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 25 Jun 2002 12:41:27 -0400
Subject: [Tutor] imaginary number class
In-Reply-To: <3D18869A.8010602@uselesspython.com>
References: <3D18869A.8010602@uselesspython.com>
Message-ID: <20020625124127.76e5610c.urnerk@qwest.net>


As others have pointed out, Python includes a complex number facility, but not
a rational number facility, so you find more people writing the latter in 
Python than the former.  But you could do complex numbers if you wanted.

Like a Rational class, with a,b as numerator,denominator, you'd want to
define instance members a,b for complex number (a,b), which is the same
as a + bj (using j in place of i).  The structure of the Python class 
would look something like:

   class Complex:

      self.__init__(self,a,b):
         self.a = a
         self.b = b

      self __add__(self,other):
         return Complex(self.a + other.a, self.b + other.b)

      self __sub__(self,other):
         # etc. etc.

      self __mul__(self,other):
        # using Alan's (3+4j)(5+6j) = 3*5+4j*5+3*6j+4j*6j        
        return Complex(self.a*other.a - self.b*other.b,
                       self.b*other.a + self.a*other.b)

      self __div__(self,other):
        # check Alan's other example
        # etc. etc.

You could write these methods in Python, and then translate them to 
a C++ class (don't worry, only the standard framework provided, with
no working guts):

=====
// complex.h
#ifndef COMPLEX_H
#define COMPLEX_H

// the class (defines the API)

   class Complex {
          double a,b; // private variables
       public:          
          Complex(double s, double t){a=s;b=t;};  //e.g. Python __init__
          Complex operator+(const Complex& other) const; // __add__
          Complex operator*(const Complex& other) const; // __mul__
          etc. etc.
   };

#endif

=====
// complex.cpp
#include "complex.h"

/* implementations (may actually be hidden in compiled source)
   -- in any case distinct from the header
*/

Complex Complex::operator+(const Complex& other) const { etc. } 
Complex Complex::operator*(const Complex& other) const { etc. }

=====
// test.cpp
#include "complex.h"

int main(){
  Complex c1(3.0 , 5.0); // same as c1 = Complex(3.0, 5.0) in Python
  Complex c2(4.0 ,-9.0);
  Complex c3 = c1 + c2;
}

=====

Note that in C++, unlike in Python, the guts of a class are typically 
defined in a file separate from the class, which is put in the header
with prototypes only (as a guide to client programmers).  

Both allow Python and C++ support operator overriding (not Java).  
Python has just the one constructor (__init__) whereas in C++, like 
in Java, you can overload functions (including the constructor) 
simply by changing the signature (args and return type).  

Also, in Python, we typically don't put so much emphasis on making 
variable properties private (using name mangling), although we might 
define __setattr__ in some cases (to protect how/what data goes in):

 >>> class Test(object):
	def __init__(self,a):
		self.__dict__['a'] = a
	def __setattr__(self,attr,b):
		print "Wow!"
		self.__dict__[attr] = b

 >>> ot = Test(1)
 >>> ot.a
 1
 >>> ot.a = 2
 Wow!
 >>> ot.a
 2

Lots of web pages on complex numbers out there.  You need to decide
what the list of methods you want to implement might be, e.g. do you
want to be able to raise Complex numbers to powers?  How about to 
complex powers? (yech).  Can Python raise complex numbers to complex
powers?  Indeed it can:

 >>> from cmath import *
 >>> pow(1j,1j)
 (0.20787957635076193+0j)  # note that j to the j is a real number!

Kirby

On Tue, 25 Jun 2002 10:04:58 -0500
"Rob Andrews" <rob@uselesspython.com> wrote:

> For your enjoyment:
> 
> I'm staring down the barrel of a problem in my C++ class that has me 
> scratching my head a bit. The professor said we could solicit help from 
> any resource we wish, as long as that resource doesn't provide us the 
> actual working C++ code for the answer. So, I turn to the tutor list 
> with what should prove an interesting minor academic challenge.
> 
> If anyone can help me figure out how to do this in Python, that would 
> very likely give me a much-appreciated assist. If nothing else, someone 
> out there might think this is a really fun thing to do on its own merits.
> 
> We have been tasked with writing "a class for an imaginary number" using 
> the attached Rational.h file as an example. I don't have any problems 
> writing the code itself, but don't really have a comprehensive 
> understanding of imaginary numbers. I'm at a bit of a loss as to how to 
> perform common operations on them.
> 
> (By the way, I've been taking notes for the C++ class on my laptop and 
> coding some of the assignments in both C++ and in Python. I plan to 
> bundle all this up for Useless Python soon.)
> 
> Rob
> http://uselesspython.com
> 



From glingl@aon.at  Tue Jun 25 21:36:18 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 25 Jun 2002 22:36:18 +0200
Subject: [Tutor] or
References: <F193Qu0216Aha0jCaXj00006d49@hotmail.com> <20020625174803.GA27728@tc.niof.net>
Message-ID: <001001c21c87$f5db7c40$1615a8c0@mega>

> 
> What you probably meant to write was 
> 
> >>> if ffac.xlpol[0] == u's' or ffac.slpol[0] == u'S':
> 
> or perhaps
> 
> >>> if ffac.xlpol[0] in (u's',u'S'):
> 

or perhaps

>>> if ffac.xlpol[0].lower() == u's':

...

Gregor




From trivas7@rawbw.com  Tue Jun 25 22:07:37 2002
From: trivas7@rawbw.com (Thomas Rivas)
Date: Tue, 25 Jun 2002 14:07:37 -0700
Subject: [Tutor] changes in Python 2.2
Message-ID: <200206252056.g5PKu3C94393@mail0.rawbw.com>

Hi folks--

Trying to learn Python on top of Java and a few other languages has been to 
say the least a breath of fresh whilespace--if you'll pardon the mixed 
metaphor; I love the simplicity of Python's orthography -- I hate braces-- 
and its readeability.

But now having read A.M Kuchling's excellent "What's New in Python 2.2", a 
few of the PEPs like 252, 253  that deal with new type of class and those 
dealing with the new iterators and generators --PEPs 234 and 255, Python is 
looking to me more and more like --well--,  another language.

My question is as a newbie how concerned should I be about what seem to me to 
be major additions/ complexity to the language?  Or are these best seen as 
evolutionary changes that have been brewing and finally risen to the top?  I 
can certainly understand the impetus for class/type unifiication but at last 
count at least 4 new words with special meaning [object, iter(), tp-iter, 
StopIteration, yield, and generator] have been added. Then yesterday I came 
across an article at www.informIT.com/deitel on Properties. Part of my 
problem might be just I don't know how much to try to absorb  as a newbie to 
programming; after all Kuching's article doesn't strike me as aimed at a 
newbie. And I haven't seen much mentioned about all these changes on this 
mailing list. Now I certainly won't be implementing any Python subclasses in 
C for a long time to come, but I sure want to use the new iterators on 
dictionaries and such!

Tom Rivas



From rob@uselesspython.com  Tue Jun 25 22:04:14 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Tue, 25 Jun 2002 16:04:14 -0500
Subject: [Tutor] changes in Python 2.2
References: <200206252056.g5PKu3C94393@mail0.rawbw.com>
Message-ID: <3D18DACE.30203@uselesspython.com>

You probably don't need to worry about language changes, really. The 
fundamental skills you pick up as you learn this stuff will not all flip 
over on you overnight by any far stretch of the imagination. And as new 
things do come up, they are phased in as older features are phased out. 
This process is glacial compared with the speed at which you can learn 
the language.

I speak as a student who has learned from experience, not as an expert 
or academic.

Rob Andrews
http://uselesspython.com

Thomas Rivas wrote:

> Hi folks--
> 
> Trying to learn Python on top of Java and a few other languages has been to 
> say the least a breath of fresh whilespace--if you'll pardon the mixed 
> metaphor; I love the simplicity of Python's orthography -- I hate braces-- 
> and its readeability.
> 
> But now having read A.M Kuchling's excellent "What's New in Python 2.2", a 
> few of the PEPs like 252, 253  that deal with new type of class and those 
> dealing with the new iterators and generators --PEPs 234 and 255, Python is 
> looking to me more and more like --well--,  another language.
> 
> My question is as a newbie how concerned should I be about what seem to me to 
> be major additions/ complexity to the language?  Or are these best seen as 
> evolutionary changes that have been brewing and finally risen to the top?  I 
> can certainly understand the impetus for class/type unifiication but at last 
> count at least 4 new words with special meaning [object, iter(), tp-iter, 
> StopIteration, yield, and generator] have been added. Then yesterday I came 
> across an article at www.informIT.com/deitel on Properties. Part of my 
> problem might be just I don't know how much to try to absorb  as a newbie to 
> programming; after all Kuching's article doesn't strike me as aimed at a 
> newbie. And I haven't seen much mentioned about all these changes on this 
> mailing list. Now I certainly won't be implementing any Python subclasses in 
> C for a long time to come, but I sure want to use the new iterators on 
> dictionaries and such!
> 
> Tom Rivas
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 






From shalehperry@attbi.com  Tue Jun 25 22:04:47 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 25 Jun 2002 14:04:47 -0700 (PDT)
Subject: [Tutor] changes in Python 2.2
In-Reply-To: <200206252056.g5PKu3C94393@mail0.rawbw.com>
Message-ID: <XFMail.20020625140447.shalehperry@attbi.com>

On 25-Jun-2002 Thomas Rivas wrote:
> Hi folks--
> 
> Trying to learn Python on top of Java and a few other languages has been to 
> say the least a breath of fresh whilespace--if you'll pardon the mixed 
> metaphor; I love the simplicity of Python's orthography -- I hate braces-- 
> and its readeability.
> 
> But now having read A.M Kuchling's excellent "What's New in Python 2.2", a 
> few of the PEPs like 252, 253  that deal with new type of class and those 
> dealing with the new iterators and generators --PEPs 234 and 255, Python is 
> looking to me more and more like --well--,  another language.
> 

python 1.5.2 level python code still works in 2.2.  Many of us still code this
way.  If you feel like playing with generators, or properties, or list
comprehensions, try them.  Perhaps add them to your toolbox.  But you are not
forced to use them.



From i_killed_barry@hotmail.com  Tue Jun 25 22:30:09 2002
From: i_killed_barry@hotmail.com (dan mason)
Date: Tue, 25 Jun 2002 21:30:09 +0000
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp
Message-ID: <F144VMgTzRKlvjhbaYf00000005@hotmail.com>


its all very well typing everything into a notepad but how do you run it? 
wot is the command in the python box?


plz reply

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




From urnerk@qwest.net  Tue Jun 25 22:54:28 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 25 Jun 2002 14:54:28 -0700
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp
In-Reply-To: <F144VMgTzRKlvjhbaYf00000005@hotmail.com>
Message-ID: <5.1.1.6.0.20020625145136.028d04b0@urnerk/pop.ptld.qwest.net>

At 09:30 PM 6/25/2002 +0000, dan mason wrote:


>its all very well typing everything into a notepad but how do you run it? 
>wot is the command in the python box?
>
>
>plz reply

If you installed using the standard Windows installer, then you should have 
IDLE available
(Snake icon).  That provides a much better editor than notepad, plus access 
to the Python
shell in a GUI window (vs. a silly DOS box, which is harder to use).

But if you want to use Notepad, just save with a .py extension (except 
Notepad will
probably save it as .py.txt -- silly), and double-click.  Or open a DOS box 
and go
C:\program files\python22> python myfile.py

Stuff like that.

Kirby





From urnerk@qwest.net  Tue Jun 25 22:54:28 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 25 Jun 2002 14:54:28 -0700
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp
In-Reply-To: <F144VMgTzRKlvjhbaYf00000005@hotmail.com>
Message-ID: <5.1.1.6.0.20020625145136.028d04b0@urnerk/pop.ptld.qwest.net>

At 09:30 PM 6/25/2002 +0000, dan mason wrote:


>its all very well typing everything into a notepad but how do you run it? 
>wot is the command in the python box?
>
>
>plz reply

If you installed using the standard Windows installer, then you should have 
IDLE available
(Snake icon).  That provides a much better editor than notepad, plus access 
to the Python
shell in a GUI window (vs. a silly DOS box, which is harder to use).

But if you want to use Notepad, just save with a .py extension (except 
Notepad will
probably save it as .py.txt -- silly), and double-click.  Or open a DOS box 
and go
C:\program files\python22> python myfile.py

Stuff like that.

Kirby





From glingl@aon.at  Tue Jun 25 22:50:50 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 25 Jun 2002 23:50:50 +0200
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp
References: <F144VMgTzRKlvjhbaYf00000005@hotmail.com>
Message-ID: <001701c21c92$5f69b000$1615a8c0@mega>

----- Original Message -----
From: "dan mason" <i_killed_barry@hotmail.com>
To: <tutor@python.org>
Sent: Tuesday, June 25, 2002 11:30 PM
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp


>
>
> its all very well typing everything into a notepad but how do you run it?

Type it into IDLE and click Edit/Run Script (or type Ctrl-F5)
Who was barry?

Gregor


> wot is the command in the python box?
>
>
> plz reply
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From Mike_White@isl-3com.com  Mon Jun 24 17:37:35 2002
From: Mike_White@isl-3com.com (White, Mike)
Date: Mon, 24 Jun 2002 11:37:35 -0500
Subject: [Tutor] python 2.2 configuration question
Message-ID: <95D05F3FD1EBD311AE8B00508B5A9685073B5981@gvlexch4.gvl.esys.com>

I've got a question about Python configuration.  I am running Red Hat 7.3
and Gnome 1.4.  Red Hat installs version 1.5.2 and version 2.2 of Python.  I
have found that when I want to run a Python script, Red Hat will start up
version 1.5.2 by default.  If I start the script with 2.2, Python does not
see all of the modules it needs.  For instance, I have been trying to run
rpcalc, which requires Python 2.2, PyQT, and QT to be installed.  I have all
of that, but the QT stuff was installed in the 1.5.2 directory.  I copied
all of the QT stuff into the 2.2 directory and Python 2.2 sees the QT
modules ok, but stops when QT tries to call another module that I can't find
in the 1.5.2 directories.  What I'm wondering is can I configure 2.2 to see
all modules, even the ones in the 1.5.2 directories, and will they work?
Red Hat installed both Pythons at install time.  Should I delete 2.2 and
reinstall a tar ball and configure it there or is there an easier way?

Mike White





From rick@niof.net  Mon Jun 24 21:47:36 2002
From: rick@niof.net (Rick Pasotto)
Date: Mon, 24 Jun 2002 16:47:36 -0400
Subject: [Tutor] os.getlogin()
Message-ID: <20020624204736.GA28126@tc.niof.net>

This is probably not actually a python problem but it's under python
that I encountered it.

>>> import os
>>> name = os.getlogin()

I'm running debian woody and gnome. This code works in the console and
gnome-terminal but it returns 

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 2] No such file or directory

when I run it in multi-gnome-terminal.

What has the author of multi-gnome-terminal done differently? Is there a
python work-around?

-- 
"Blaming 'society' makes it awfully easy for a person of weak
character to shrug off his own responsibility for his actions."
		-- Stanley Schmidt
    Rick Pasotto    rickp@telocity.com    http://www.niof.net



From tbrauch@tbrauch.com  Tue Jun 25 00:40:20 2002
From: tbrauch@tbrauch.com (Timothy M. Brauch)
Date: Mon, 24 Jun 2002 19:40:20 -0400
Subject: [Tutor] Web Based Form Question
Message-ID: <000d01c21bd8$81427fa0$9c21840a@tmbrau00>

There is a form I use on the internet that is written in Python.  Basically
I have to enter a number in the form to look up the data on something, then
pull the relevant data from the resulting page.

What I was wondering is if there was a way I could write a little script
that would help me do this.  If I could figure out how to get the results
page using Python, I could easily extract the important data.

Here is the relevant part of the web form...

<form method="post" action="cnvrprt.py">
<input name="idnumber" type="text">
<input name="" type="submit" value="Submit">
</form>

I just need to run through a file of id numbers using this form.

Any help?

 - Tim




From dyoo@hkn.eecs.berkeley.edu  Tue Jun 25 23:20:47 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 25 Jun 2002 15:20:47 -0700 (PDT)
Subject: [Tutor] heeeeeeeeeeeellllllllllpppppp
In-Reply-To: <F144VMgTzRKlvjhbaYf00000005@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206251519060.10559-100000@hkn.eecs.berkeley.edu>


On Tue, 25 Jun 2002, dan mason wrote:

> its all very well typing everything into a notepad but how do you run
> it?  wot is the command in the python box?

Hi Dan,

Try IDLE; it's easier to edit and run Python code from it than from
Notepad.  IDLE comes prepackaged with Python, so you don't need to install
anything extra.

I have a small tutorial that shows how to run programs with it here:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

If you have questions, please feel free to ask them on Tutor.  We'll do
our best to help!




From pythontutor@venix.com  Tue Jun 25 23:24:34 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Tue, 25 Jun 2002 18:24:34 -0400
Subject: [Tutor] win32serviceutil.StartService bug??
Message-ID: <3D18EDA2.1050106@venix.com>

I am writing a Python script to start MySQL with alternative databases.  This
seemed fairly easy until I couldn't get the StartService function to work with
an argument.  Hopefully, someone will have a suggestion.  I am enclosing my
python stream which fails, and the results of using a command-line utility.
The command-line utility works, so I know the MySQL setup is OK.

 >>> import win32serviceutil
 >>> win32serviceutil.QueryServiceStatus('mysql')
(16, 1, 0, 0, 0, 0, 0)		# tuple[1] is current status.  1 == STOPPED
 >>> win32serviceutil.StartService('mysql', '--datadir=f:\\mysql\\data_playpark')
 >>> win32serviceutil.QueryServiceStatus('mysql')
(16, 1, 0, 1067, 0, 0, 0)		# tuple[1] is current status.  1 == STOPPED
					# 1067 is a MySQL path/directory problem
 >>> win32serviceutil.StartService('mysql')
 >>> win32serviceutil.QueryServiceStatus('mysql')
(16, 4, 7, 0, 0, 0, 0)		# tuple[1] is current status.  4 == RUNNING


F:\MySQL>sc stop mysql

SERVICE_NAME: mysql
         TYPE               : 10  WIN32_OWN_PROCESS
         STATE              : 3  STOP_PENDING
                                 (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN)
         WIN32_EXIT_CODE    : 0  (0x0)
         SERVICE_EXIT_CODE  : 0  (0x0)
         CHECKPOINT         : 0x1
         WAIT_HINT          : 0x3a98

F:\MySQL>sc query mysql

SERVICE_NAME: mysql
         TYPE               : 10  WIN32_OWN_PROCESS
         STATE              : 1  STOPPED
                                 (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
         WIN32_EXIT_CODE    : 0  (0x0)
         SERVICE_EXIT_CODE  : 0  (0x0)
         CHECKPOINT         : 0x0
         WAIT_HINT          : 0x0

F:\MySQL>sc start mysql --datadir=f:\\mysql\\data_playpark

SERVICE_NAME: mysql
         TYPE               : 10  WIN32_OWN_PROCESS
         STATE              : 4  RUNNING
                                 (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN)
         WIN32_EXIT_CODE    : 0  (0x0)
         SERVICE_EXIT_CODE  : 0  (0x0)
         CHECKPOINT         : 0x0
         WAIT_HINT          : 0x0

F:\MySQL>sc query mysql

SERVICE_NAME: mysql
         TYPE               : 10  WIN32_OWN_PROCESS
         STATE              : 4  RUNNING
                                 (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN)
         WIN32_EXIT_CODE    : 0  (0x0)
         SERVICE_EXIT_CODE  : 0  (0x0)
         CHECKPOINT         : 0x0
         WAIT_HINT          : 0x0

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From ajs@ix.netcom.com  Tue Jun 25 23:35:15 2002
From: ajs@ix.netcom.com (Arthur Siegel)
Date: Tue, 25 Jun 2002 18:35:15 -0400
Subject: [Tutor] changes in Python 2.2
References: <200206252056.g5PKu3C94393@mail0.rawbw.com>
Message-ID: <001501c21c98$96ce3ba0$0334fea9@carol>

> But now having read A.M Kuchling's excellent "What's New in Python 2.2", a
> few of the PEPs like 252, 253  that deal with new type of class and those
> dealing with the new iterators and generators --PEPs 234 and 255, Python
is
> looking to me more and more like --well--,  another language.

To give a inclusive view, there are those of us who have been around Python
for
a while who do feel that the pace and the nature of changes in Python have
hurt
Python as a learning language.

As pointed out, there is nothing stopping one from continuing to use Python
in
1.5.2 mode. But reading and learning from the code of someone else who may
be working in 2.2 mode becomes problematic. And that code is probably
accomplishing
nothing that could not be accomplished in 1.5.2 mode, and at no better
execution
speed. Which is preferred?  Which is "better".

Reporting second-hand (overhead discussion):

Generators (and probably type/class) seem to be a full fledged innovations
in the language
 - much the rest I have heard characterized by a major Python contributor
(who seems
totally unbothered by the changes) as furniture moving.

On the other hand...

My impression is that the concept of many of the new features are adopted
from enviable
features of other languages - and that the effort is to have the best
convenience features
of other languages available in Python. In that sense, Python 2.2 I guess
can be viewed as a broader
introduction to state of the art programming than 1.5.2.

Something has been gained, but I am afraid - much also lost.

But its a definite sore point topic in the community - at all levels of
involvement.

I am not meaning to bring the discussion here.

But I do think a "rounded" answer to the question is appropriate.

Art





From pythontutor@venix.com  Tue Jun 25 23:48:57 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Tue, 25 Jun 2002 18:48:57 -0400
Subject: [Tutor] python 2.2 configuration question
References: <95D05F3FD1EBD311AE8B00508B5A9685073B5981@gvlexch4.gvl.esys.com>
Message-ID: <3D18F359.1010902@venix.com>

You may need to do some cleanup to get your Python modules working right.
Python2.2 uses some different C coding conventions, so compiled C modules
are different between the versions.

I dealt with the 1.5.2 by renaming (mv) /usr/bin/python to /usr/bin/rhpython.
This left /usr/local/bin/python (version 2.2) as my default.  That made it easy
to install other modules.  It also allowed idle to work.

The problem is that some of the redhat utilities REQUIRE 1.5.2, so they will
fail (often quietly, with no error messages) unless you mv rhpython back to
/usr/bin/python

White, Mike wrote:

> I've got a question about Python configuration.  I am running Red Hat 7.3
> and Gnome 1.4.  Red Hat installs version 1.5.2 and version 2.2 of Python.  I
> have found that when I want to run a Python script, Red Hat will start up
> version 1.5.2 by default.  If I start the script with 2.2, Python does not
> see all of the modules it needs.  For instance, I have been trying to run
> rpcalc, which requires Python 2.2, PyQT, and QT to be installed.  I have all
> of that, but the QT stuff was installed in the 1.5.2 directory.  I copied
> all of the QT stuff into the 2.2 directory and Python 2.2 sees the QT
> modules ok, but stops when QT tries to call another module that I can't find
> in the 1.5.2 directories.  What I'm wondering is can I configure 2.2 to see
> all modules, even the ones in the 1.5.2 directories, and will they work?
> Red Hat installed both Pythons at install time.  Should I delete 2.2 and
> reinstall a tar ball and configure it there or is there an easier way?
> 
> Mike White
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From ccampbell@ede.org  Wed Jun 26 00:02:19 2002
From: ccampbell@ede.org (Colin Campbell)
Date: Tue, 25 Jun 2002 17:02:19 -0600
Subject: [Tutor] "Generic" GetUser
Message-ID: <5.1.0.14.0.20020625165252.00a7e6a8@mail.ede.org>

G'day, eh!

I have an Excel workbook containing many tabs of financial reports. An 
autorun macro looks up the user login in a table and hides the sheets they 
are not allowed to see. There are 2 obvious problems: I can't guarantee 
that the macro is run, and since it makes and API call to Windows, my Mac 
users are doomed.

I have found the win32wnet.WNetGetUser() in ActivePython, so that I don't 
have to trust users to enable macros. This in turn means that my next trick 
is to write a Python front end which handles the security, perhaps even by 
copying the allowed sheets into a temporary workbook or even creating HTML, 
depending on the level of my ambition.

My question is this: is there a more generic method or property that is 
available across all platforms/python implementations, which will return 
the network login of the person running the program?

TIA,

Colin

--
I believe that the first test of a truly great man is his humility. I do 
not mean by humility, doubt of his own powers. But really great men have a 
curious feeling that the greatness is not in them, but through them. And 
they see something divine in every other man and are endlessly, foolishly, 
incredibly merciful.
  -John Ruskin, author, art critic, and social reformer (1819-1900)




From ak@silmarill.org  Wed Jun 26 03:08:47 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Tue, 25 Jun 2002 22:08:47 -0400
Subject: [Tutor] find is confusing..?
Message-ID: <20020626020847.GA19484@ak.silmarill.org>

Hello snake eaters..

I just realized that "string".find('str') is very counter-intuitive.. 

if "string".find("str"):
    print "found str!" # won't work

Wouldn't it be much nicer if find returned true if something was found,
and false if it wasn't, and you'd use index() to find the position,
which would return -1 if it wasn't found?

The reason I ask is that I thought.. maybe there's a good reason for
this that I'm missing. Is there?

Thanks,

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From urnerk@qwest.net  Wed Jun 26 05:55:46 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 25 Jun 2002 21:55:46 -0700
Subject: [Tutor] find is confusing..?
In-Reply-To: <20020626020847.GA19484@ak.silmarill.org>
Message-ID: <5.1.1.6.0.20020625214422.02d286b0@urnerk/pop.ptld.qwest.net>

Some languages have such an operator, e.g. in xBase we say

"str"$"string"

to get a boolean T or F (just let us know if it's in there, we don't
care where exactly).

To actually get the position of a substring, we'd use:

pos = AT("str","string")

-- and here, since indexing is 1-based instead of 0-based, returning
0 means "not found". (pos would be 1 after the above).

But I can well understand a design philosophy that says "if you go
to all the trouble to ascertain whether a substring is contained in a
string, it's wasteful to just say 'yes', as you've obviously done the
work to also know the starting position".  To have find() return 0 or 1
is actually withholding information which the computer must have.

find() has the ability to come up empty handed (-1) whereas index()
is a command to return an index, so it's designed to really signal
a problem (returns an exception) if, in fact, there is no such index.
The intent is you shouldn't be asking for the index unless you know
it's there; use find() if you're not so sure (but either way, if it's there,
you get the starting position without any further instructions, which
is getting a full return for your clock cycles (imagine running find on
a string of 10000 characters and just getting back 1 for true, and
then needing to start over with index() to get the position -- that'd be
frustratingly redundant).

It's very easy to package either index() or find() to make new
functions that work however you like though.

Kirby

At 10:08 PM 6/25/2002 -0400, Andrei Kulakov wrote:
>Hello snake eaters..
>
>I just realized that "string".find('str') is very counter-intuitive..
>
>if "string".find("str"):
>     print "found str!" # won't work
>
>Wouldn't it be much nicer if find returned true if something was found,
>and false if it wasn't, and you'd use index() to find the position,
>which would return -1 if it wasn't found?
>
>The reason I ask is that I thought.. maybe there's a good reason for
>this that I'm missing. Is there?
>
>Thanks,
>
>  - Andrei





From urnerk@qwest.net  Wed Jun 26 06:41:46 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 25 Jun 2002 22:41:46 -0700
Subject: [Tutor] changes in Python 2.2
In-Reply-To: <001501c21c98$96ce3ba0$0334fea9@carol>
References: <200206252056.g5PKu3C94393@mail0.rawbw.com>
Message-ID: <5.1.1.6.0.20020625221025.02d292b0@urnerk/pop.ptld.qwest.net>

[Warning to the reader:  the remarks below reflect my current understanding
of where Python is going which may be inaccurately or misleadingly
expressed in some details.  Corrections welcome.]

Just responding to this thread about new features in more recent
Pythons (and did you read about the boolean type? -- sounds good
to me)....

 > Something has been gained, but I am afraid - much also lost.
 >
 > But its a definite sore point topic in the community - at all
 > levels of involvement.
 >
 > I am not meaning to bring the discussion here.
 >
 > But I do think a "rounded" answer to the question is appropriate.
 >
 > Art

I think we should also recognize that the designers have the
challenge of evolving the language in ways that aren't too
disruptive of working code, so that people who choose to upgrade
aren't overly penalized.

It's healthy for the language if the most experienced users don't
feel too stuck in the older versions.

But this incremental approach means streamlining simplifications
can't be implemented as cleanly as if this were a blank slate
situation. So in some respects, the 2.x versions are messier
than the final result, because they're transitioning between
paradigms in a rather subtle way (so as to not lose too many
people by breaking a lot of code all at once).

Being able to subclass builtin classes like lists is actually a
simplification, adds consistency to the "everything is an object"
abstraction.  When I found you could go:

  >>> 3 .__add__(5)  # note: a space before the .
  8

my appreciation for the internal consistency of the emerging model
increased.  This makes Python easier to teach (  I can say to kids:
"see, the built-in int type has an __add__ method just like a user-
defined class might, and we'd normally trigger it using the + operator).

But in order to be able to subclass builtins, a base object (mother of
all objects) had to be introduced at the root of the class hierarchy.
In recent versions, this root class (named object) has to be inherited
from explicitly, as in:

  >>> class Newclass(object):
         pass

# lets look at the methods the Mother of all Objects supports:

  >>> o = Newclass()    # make an instance

  >>> dir(o)
  ['__class__', '__delattr__', '__dict__', '__getattribute__',
  '__hash__', '__init__', '__module__',  '__new__', '__reduce__',
  '__repr__', '__setattr__', '__str__', '__weakref__']

Some familiar methods there (__add__ comes in further down in the
tree).

And what's the base class of a primitive type?

  >>> list.__base__
  <type 'object'>
  >>> int.__base__
  <type 'object'>

Same as my Newclass.

This design approach, of anchoring the class hierarchy to a single
top-level object is not unusual.  It's what Java and SmallTalk both do
(but not C++).  Builtins and user-defined classes will all inherit
from a single root (even if multiple inheritance is supported
further down on the tree).  Types and classes unify (to define a
class is to define a type).

  >>> type(o)  # not just an "instance type"
  <class '__main__.Newclass'>

In contrast (old style class):

  >>> class Oldclass:  # not inheriting from object
         pass

  >>> o = Oldclass()

  >>> dir(o)  # not much to inherit
  ['__doc__', '__module__']

  >>> type(o)  # not very explicit about type, either
  <type 'instance'>

Eventually, in later versions, you won't need to explicitly subclass the
Mother Object to inherit her properties -- that'll be presumed.  But given
the incremental approach, there's an interim period when both old and
new styles of classes need to be supported.

Likewise, they can't just drop the L from long integers overnight -- some
code still expects to find it:

  >>> 1834091830981093401834018304918340123  # note L appended below
  1834091830981093401834018304918340123L
                                       ^
                                   going away

Kirby





From scot@possum.in-berlin.de  Wed Jun 26 09:22:30 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Wed, 26 Jun 2002 10:22:30 +0200
Subject: [Tutor] changes in Python 2.2
In-Reply-To: <200206252056.g5PKu3C94393@mail0.rawbw.com>
References: <200206252056.g5PKu3C94393@mail0.rawbw.com>
Message-ID: <200206261022.31002.scot@possum.in-berlin.de>

Hello -=20

> But now having read A.M Kuchling's excellent "What's New in Python 2.2"=
,
> a few of the PEPs like 252, 253  that deal with new type of class and
> those dealing with the new iterators and generators --PEPs 234 and 255,
> Python is looking to me more and more like --well--,  another language.

I would like to second this (again). This is going to be somewhat of a=20
rant, but I remember complaining a few months ago about Python's rate of=20
change, and tho I have made lots of progress with the language since then=
=20
(with a lot of help from this list), switching to 2.2 does make me feel=20
like the road I was following has dwindled from a four-lane highway (or=20
rather /Autobahn/ in my case) to a packed-earth path thru the forest. I a=
m=20
not sure if the real computer people here realize how disorientating thes=
e=20
changes are for people who are struggling with the basic concepts.=20

Part of this is that Python has almost completely left behind the printed=
,=20
book-form documentation: Lutz' "Programming Python" is a fantastic book,=20
but it is becoming more and more useless, and frankly I couldn't recommen=
d=20
the "Python Standard Library" by Lundh to anybody anymore. I had emailed=20
O'Reilly about a new version of "Programming Python" and their response=20
was "not in the next few months", without the "but we're working on it" I=
=20
had hoped for. I can't blame them - at this rate of change, why would=20
anybody want to write a book that will be outdated before it is even set,=
=20
let alone printed?=20

Obviously this was a problem even with "Programming Python", as GvR says=20
himself in the foreward:

    Every time I add a feature to Python, another patch of Mark's hair
    turns grey -- there goes another chapter out of date!

It doesn't look like this trend is going to stop anytime soon, either. In=
=20
PEP 279 (http://www.python.org/peps/pep-0279.html) we find these ominous=20
words from GvR:=20

    "[F]ilter and map should die and be subsumed into list comprehensions=
,
     not grow more variants."

Which is a really motivating thing to read if you have just understood=20
filters by working thru examples. List comprehensions are, as we have=20
discussed here before, very intuitive if you have a background in set=20
theory (so I'm told), but for the rest of us, they are not exactly easy o=
n=20
the eyes, and I still think the syntax looks very un-Pythonic. They are=20
not exactly the simplicity that Python has been famous for, and certainly=
=20
not "executable pseudocode".

Kuchling does address some of these complaints:=20
   =20
    Some users have voiced concern about all these changes. Sure, they sa=
y,
    the new features are neat and lend themselves to all sorts of tricks
    that weren't possible in previous versions of Python, but they also
    make the language more complicated. Some people have said that they'v=
e
    always recommended Python for its simplicity, and feel that its
    simplicity is being lost.=20

Which are my feelings exactly. He answers:

    Many of the new features are quite esoteric, and you can write a lot =
of
    Python code without ever needed to be aware of them. Writing a simple
    class is no more difficult than it ever was, so you don't need to
    bother learning or teaching them unless they're actually needed.=20

I don't agree with this for a couple of reasons.=20

First, division is about as basic as you can get, and at this rate of=20
change, we're going to hit Python 3.0 before anybody gets around to=20
writing those new books. Take a look at how many division examples that i=
s=20
going to break - starting on page 33 of "Learning Python", which is about=
=20
as close to the start of learning the language as you can get. This is=20
going to really get the next generation of newbies.

Second, I might not have to /write/ the new forms, but I have to understa=
nd=20
them to be able to /read/ Python code. Which means that if I want to=20
continue, say, to use the module code as a learning example, I'm going to=
=20
have to figure out how "yield" works, or (soon enough) what "enumerate"=20
does, since PEP 279 tells me: "The response to the enumerate() proposal=20
has been close to 100% favorable. Almost everyone loves the idea." That=20
sounds like a lot of important people are going to be using it all over=20
the place.

Third, I was under the impression that one of the ideas behind Python was=
=20
to create an easy to learn, easy to use, easy to maintain programming=20
language that avoids "esoteric" features in the first place. So what is=20
Kuchling telling me here about the Python philosophy? Or, to rephrase=20
that: If these features are "esoteric", why were they included at all?

Fourth, when you add new keywords (like "yield"), it isn't esoteric=20
anymore. GvR tells us the following about "enumerate" (note this is not i=
n=20
2.2 that Kuchling is talking about):=20

    Like zip(), it is expected to become a commonly used looping idiom.

In other words, after Python 2.3, he expects lots of code to use enumerat=
e.=20
These are core changes and affect the way the language is used at a basic=
=20
level. And PEP 283 tells me that Python 2.3 is due to be out before the=20
end of the year...and I bet 2.4 is planned for Summer 2003...and 2.5 for=20
the end of 2003...

Again, I am not opposed to the changes as such. Having "real" division=20
instead of C-like computer science division is a great idea and in my min=
d=20
will be a great plus for Python. Enumerate, if I understood the PEP=20
correctly, is a cool idea, and "yield" seems to be nice, too. And yes,=20
universal newline support should have be included in from the start, and =
I=20
agree that major changes should be made sooner rather than later. There i=
s=20
no question that these changes make Python a better language.=20

The problem is that the rate of change has far outstripped the ability (o=
r=20
interest) of the people writing documentation to keep up, especially=20
documentation in book form. This is obviously not a problem for people wh=
o=20
have lots of time to play around with the new features and/or have such a=
=20
firm computer science background that they can just say "oh yeah, this is=
=20
just like Icon" and carry on. For the rest of us, learning Python 2.2=20
means piecing together bits from outdated books (like "Programming=20
Python"), short online texts (like "What's new in Python 2.2.?", which, a=
s=20
Thomas pointed out, is not aimed at newbies), and comments from more=20
advanced users (like the Python Tutor list here).=20

This is not fun, and learning Python used to be, first of all, fun.

Also, there is no end in sight. Things would be different if we all knew=20
that there was going to be a lot of hectic change for a while before=20
"Python 3000" comes out with a "keyword freeze" or whatever you call it.=20
But reading thru the PEP proposals, you get the feeling that Python has a=
=20
sort of computer scientist feeding frenzy on its hands, were everybody ha=
s=20
a pet cool idea for a computer language and sees a chance of getting it i=
n=20
Python - with good reason.=20

(Say - wouldn't it be easier for all involved just to freeze Python at, f=
or=20
example, 3.0, and then have all of these people with these great new idea=
s=20
sit down and design a new language from scratch, one that has all their=20
cool features, is stackless, doesn't have a global interpreter lock, is=20
great for numeric computation, etc. pp.? And leave the rest of us with a=20
stable language that doesn't take a step forwards every time you try to=20
throw your saddle on its back.)

As much as I have gotten to love Python, I am beginning to ask myself why=
 I=20
don't just quit the language for a while until the mutation rate has=20
dropped to an acceptable level. Say, for about two or three years, then=20
buy a book and start all over again. For all their disadvantages, Java an=
d=20
C don't see major changes every few months and the paper documentation=20
doesn't depreciate the way Python's does...like, I could actually sit dow=
n=20
with the Second Edition of Kernighan and Richie, 1988, and get to the=20
point where I can at least read the C of the Linux Kernel.=20

Y, Scot
Who does feel a lot better now, thank you...

--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany




From scot@possum.in-berlin.de  Wed Jun 26 09:35:08 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Wed, 26 Jun 2002 10:35:08 +0200
Subject: [Tutor] changes in Python 2.2 (Correction)
In-Reply-To: <200206261022.31002.scot@possum.in-berlin.de>
References: <200206252056.g5PKu3C94393@mail0.rawbw.com> <200206261022.31002.scot@possum.in-berlin.de>
Message-ID: <200206261035.08132.scot@possum.in-berlin.de>

Because I hit the "send" button too fast, I wrote:=20

> documentation doesn't depreciate the way Python's does...like, I could
> actually sit down with the Second Edition of Kernighan and Richie, 1988=
,

- the correct spelling, of course, is "Ritchie" (with a "t").  Sorry.

Y, Scot

--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany




From alan.gauld@bt.com  Wed Jun 26 11:01:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 26 Jun 2002 11:01:01 +0100
Subject: [Tutor] or
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A2@mbtlipnt02.btlabs.bt.co.uk>

> >>>ffac.xlpol =u'NAB02658508'
> >>>if ffac.xlpol[0] == u's' or u'S':
> ... 	print"yes"
> ...
> yes
> 
> This is clearly wrong. 

No, its only apoparently wrong. It is in fact cprrect.

Python seeeds your test like:

if ffac.xlpol[0] == (u's' or u'S'):

and ('s' or 'S') is always true.

ffac.xlpol[0] is 'N' which in boolean terms is also 
true so far as Python is concerned.

thus tru == true so it prints yes!

What you need to do is break the test out like so:

if (ffac.xlpol[0] == u's') or (ffac.xlpol[0] == u'S'):
  print 'yes'

> If I remove the or and the last u'S' it works. 

Because now you are comparing letters with letters not 
letters with booleans.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From alan.gauld@bt.com  Wed Jun 26 11:21:34 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 26 Jun 2002 11:21:34 +0100
Subject: [Tutor] changes in Python 2.2
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A3@mbtlipnt02.btlabs.bt.co.uk>

> Trying to learn Python on top of Java and a few other 
> languages has been to say the least a breath of fresh 
> whilespace

I know the feeling.

> But now having read A.M Kuchling's excellent "What's New in 
> Python 2.2", ....new classes, iterators, generators....
> Python is looking to me more and more like --well--,  another language.

That was my initial feeling on 2.2 too.

Python might be heading in a dangerous direction of trying to be 
too universal. I have an uneasy feeling having seen C++ go down 
the same route and become so infested with dark corners that it 
has become almost unusable for anyone but a guru.

The good news is that so far Pythons changes are optional and can 
be safely ignored if you don't need them (except that the bloat 
inevitably slows the interpreter down and makes it bigger!).

> My question is as a newbie how concerned should I be about 
> what seem to me to be major additions/ complexity to the language?  

As a newbie just ignore them.
When you suddenly find a need for one or more of them thats 
when to read up the docs and start playing.
For me the new classes are interesting in an acedemic sense.
Generators I might use occasionally. Iterators I don't like in 
principle although they are a popular fashion in languages 
these days(C++, Java, Ruby etc)

> evolutionary changes that have been brewing and finally risen 
> to the top?

They are pretty revolutionary IMHO representing a fairly 
fundamental change in approach. But they are being implemented 
in an evolutionary way so you don't really need to worry 
about them for now.

> across an article at www.informIT.com/deitel on Properties. 

Properties are one of the things I like - as are static methods.

> problem might be just I don't know how much to try to absorb  
> as a newbie to programming; 

All you need to start are sequences, loopps and branches, I/O 
and some data types/operations.

Once you have those sorted you can program in any language, 
learn the more advanced features as you need them....

> Now I certainly won't be implementing any 
> Python subclasses in C for a long time to come, 
> but I sure want to use the new iterators on 
> dictionaries and such!

You've just answered your own question.
Investigate iterators ignore the rest for now.
Read about them so you know they exist by all means but 
don't lose sleep over them...

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From alex@gabuzomeu.net  Wed Jun 26 11:40:38 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Wed, 26 Jun 2002 12:40:38 +0200
Subject: [Tutor] changes in Python 2.2
In-Reply-To: <20020626082636.1274.40159.Mailman@mail.python.org>
Message-ID: <4.3.2.7.2.20020626114154.00b83100@pop3.norton.antivirus>

At 04:26 26/06/2002 -0400, tutor-request@python.org wrote:
>From: "Scot W. Stevenson" <scot@possum.in-berlin.de>
>Subject: Re: [Tutor] changes in Python 2.2
>Date: Wed, 26 Jun 2002 10:22:30 +0200

[rate of changes in Python]
>I remember complaining a few months ago about Python's rate of
>change, and tho I have made lots of progress with the language since then
>(with a lot of help from this list), switching to 2.2 does make me feel
>like the road I was following has dwindled from a four-lane highway (or
>rather /Autobahn/ in my case) to a packed-earth path thru the forest. I am
>not sure if the real computer people here realize how disorientating these
>changes are for people who are struggling with the basic concepts.

Well, obviously in Python we have a tension between being a learner's 
language and an "advanced" language for experienced programmers. So far, I 
believe the designers have found an acceptable balance, though I admit 
there were a lot of changes in the last months.

>List comprehensions are, as we have discussed here before, very intuitive 
>if you have a background in set theory (so I'm told),  but for the rest of 
>us, they are not exactly easy on the eyes, and I still think the syntax 
>looks very un-Pythonic. They are not exactly the simplicity that Python 
>has been famous for, and certainly not "executable pseudocode".

Frankly, there are all kind of people here. I don't have any formal 
background in computer science, let alone set theory (the first language I 
messed with was called WordBasic - believe me, you don't want to use it). 
However, list comprehensions somehow fit my brain. I use them all the time; 
they feel natural, whereas I have a hard time with lambda, reduce, 
recursive stuff, etc.

>division is about as basic as you can get, and at this rate of change, 
>we're going to hit Python 3.0 before anybody gets around to writing those 
>new books. Take a look at how many division examples that is going to 
>break - starting on page 33 of "Learning Python", which is about as close 
>to the start of learning the language as you can get. This is doing to 
>really get the next generation of newbies.

>Again, I am not opposed to the changes as such. Having "real" division
>instead of C-like computer science division is a great idea and in my mind
>will be a great plus for Python.

Yes, a lot of people were worried about this change.  I also believe it is 
a improvement, because integer division is not very intuitive for new 
learners.

>The problem is that the rate of change has far outstripped the ability (or
>interest) of the people writing documentation to keep up, especially
>documentation in book form.

However, I think many news Python books were published in the last months. 
This is a positive trend for Python. I feel there is a growing interest in 
the language.

>For the rest of us, learning Python 2.2 means piecing together bits from 
>outdated books (like "Programming Python"), short online texts (like 
>"What's new in Python 2.2.?", which, as Thomas pointed out, is not aimed 
>at newbies), and comments from more advanced users (like the Python Tutor 
>list here).

You may have a point here. Maybe we need a tutorial for new features, eg. a 
new leaners' guide to new features. Anyone?

>As much as I have gotten to love Python, I am beginning to ask myself why
>I don't just quit the language for a while until the mutation rate has 
>dropped to an acceptable level.

I'm not sure how you use Python (eg. do you use it in your job, etc.) I use 
it both for fun and to automate tasks in my work (but I'm not a 
programmer). The new Python features do not prevent me from using Python 
(actually, I'm still using 2.1 a lot).

Also, I don't feel I have to learn new features immediately. Usually, I can 
wait until they are better understood and better documented (or until I 
really need them and I have an incentive for learning them).

 > Y, Scot
>Who does feel a lot better now, thank you...

:-)


Cheers.

Alexandre




From alan.gauld@bt.com  Wed Jun 26 11:34:17 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 26 Jun 2002 11:34:17 +0100
Subject: [Tutor] find is confusing..?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A4@mbtlipnt02.btlabs.bt.co.uk>

> I just realized that "string".find('str') is very counter-intuitive.. 
> 
> if "string".find("str"):
>     print "found str!" # won't work
> 
> Wouldn't it be much nicer if find returned true if something 
> was found,

No, coz find is not a boolean expression.
What might be better is if strings had an 'includes' operator so 
your code becomes:

if "string".includes('str'):
    print 'contains "str"'

and find() continues to return the index as it currently does 
- which seems like what I'd want from a find command.

You could of course extend string (userstring?) to have an 
includes() method...

> The reason I ask is that I thought.. maybe there's a good reason for
> this that I'm missing. Is there?

Coz if you want to extract the search string its more convenient 
to fetch the index via the find(). Using find then index would be 
slow unless find set an internal state variable used by index but 
then we increase the size of every string...

but using

if "str".find('foo') >= 0:
   print 'found'

doesn't seem too unintuitive to me...

Alan G.



From alan.gauld@bt.com  Wed Jun 26 11:57:12 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 26 Jun 2002 11:57:12 +0100
Subject: [Tutor] changes in Python 2.2
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A5@mbtlipnt02.btlabs.bt.co.uk>

> This is not fun, and learning Python used to be, first of all, fun.

I think this is a valid point once you get beyond the basics.

Oddly enough a complete programming novice can still pick 
up Python (division changes apart) pretty much without change 
since Python 1.3(when dictionaries got 'fixed').

The guys who are hurt most are those with say, one previous 
programming language, especially something like BASIC or JScript,
and who learn the real baics quickly but then hit a wall with 
the mass of more advanced techniques.

Its no longer true that in Python "there's only one way to do it"
we now have to choose between basic loops, iterators, comprehensions, 
enumerators etc...

> As much as I have gotten to love Python, I am beginning to 
> ask myself why I don't just quit the language for a while 

I won't be quitting - I'm not that masochistic - but I am 
slow to upgrade. Just freeze your Python version for a while. 
There are still a lot of folks on this list still using Python1.5
and I only have 2.2 on one of my machines even yet (the others 
are still at 2.1).

I have no intention of upgrading to 2.3 when it comes out and 
may stay at 2.2 until 3000 comes out! (I'm hoping to do a 
second edition of my book based on 3000 someday!)

> with the Second Edition of Kernighan and Richie, 1988, and get to the 
> point where I can at least read the C of the Linux Kernel. 

Actually the change rate on C is suvch that you could probanbly 
use the original 1978 edition! I still use that rather than fork 
out for the ANSI edition and rarely get stung. But then I still 
use Guido et al's original 1996 Internet Programming with Python
which is written for version 1.3 too... 

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From dman@dman.ddts.net  Wed Jun 26 13:33:55 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Wed, 26 Jun 2002 07:33:55 -0500
Subject: [Tutor] Re: "Generic" GetUser
In-Reply-To: <5.1.0.14.0.20020625165252.00a7e6a8@mail.ede.org>
References: <5.1.0.14.0.20020625165252.00a7e6a8@mail.ede.org>
Message-ID: <20020626123355.GB9886@dman.ddts.net>

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

On Tue, Jun 25, 2002 at 05:02:19PM -0600, Colin Campbell wrote:
=20
| I have an Excel workbook containing many tabs of financial reports. An=20
| autorun macro looks up the user login in a table and hides the sheets the=
y=20
| are not allowed to see. There are 2 obvious problems: I can't guarantee=
=20
| that the macro is run, and since it makes and API call to Windows, my Mac=
=20
| users are doomed.

Yep.
=20
| I have found the win32wnet.WNetGetUser() in ActivePython, so that I don't=
=20
| have to trust users to enable macros. This in turn means that my next tri=
ck=20
| is to write a Python front end which handles the security, perhaps even b=
y=20
| copying the allowed sheets into a temporary workbook or even creating HTM=
L,=20
| depending on the level of my ambition.

What I would suggest is not giving the users data they aren't supposed
to have in the first place.  Once you've given them the data, there is
no robust way to prevent them from "having" it.

A better system would be to store all the accounting information where
the accounting folks can get to it.  From that complete source, you
can generate the reports that the users are allowed to see.  The only
remaining issue to decide is how to distribute the resultant reports. =20

Where I work we are presently transitioning from MUMPS to Solomon IV
as the accounting package.  The other admin already has a collection
of tools (Crystal Reports and some php/perl scripts) to generate CSV
and HTML versions of each person's individual financial reports.  I
created a zope interface backed by postgresql for users to access
their reports through a web browser.  Some people, depending on their
position, are allowed to view other peoples' reports.  This is all
managed by some ACLs (Access Control Lists) in the postgres database.
The zope front-end requires password-based authentication and then
dynamically builds an index of all the reports that user is allowed to
view.  The user can then select a report to retrieve it in either HTML
or CSV form.

Some of the advantages of handling it this way are :
    1)  all the code runs on one chosen platform and can be tested
    2)  users don't need to learn anything new -- they already know
        how to use a web browser
    3)  the data is all kept on a server, not distributed around
        (except as allowed by the ACLs)
    4)  providing the CSV format of the data allows a user to import
        it into excel or whatever other program they want to, if they
        want to
    5)  each report only has one copy stored in the database
        regardless of how many users are allowed to view it
=20
| My question is this: is there a more generic method or property that is=
=20
| available across all platforms/python implementations, which will return=
=20
| the network login of the person running the program?

No.  UNIX, Windows, and Mac are all different in how they handle
users.  MacOS (prior to X) didn't even have "users" -- it was a
single-user desktop system.

HTH,
-D

--=20

Emacs is a nice operating system, it lacks a decent editor though
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0ZtLMACgkQO8l8XBKTpRTFPACgtLUkPsspu3O1Lnr+eyWFhbwd
7zcAoKjt1Lo56LiCmJQBG4ciaDQ7v+5H
=7j1d
-----END PGP SIGNATURE-----

--K8nIJk4ghYZn606h--



From rob@uselesspython.com  Wed Jun 26 13:48:37 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Wed, 26 Jun 2002 07:48:37 -0500
Subject: [Tutor] changes in Python 2.2
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6A5@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3D19B825.7010007@uselesspython.com>

I started with Python in the middle of a game of Diablo that had become 
tedious one night. I think Python was at 1.5 at the time. I had so much 
fun playing around with IDLE while going through the Tutorial that I got 
hooked. It was indeed fun!

Since then I've upgraded systematically pretty much every time a new 
version comes out, just on general principle. I've used almost every 
different Python distribution out there, and have even started using 
Jython. During this time, the python I learned at 1.5 has worked just 
fine through all the changes that have taken place, and the 
entertainment value is still there. (I seem to recall running into a bit 
of a stumble on something leaping from 1.5 to 2.0, but that's about it.)

My CS background? Not much, really. I took a semester of Pascal back in 
the spring of '92 and felt like I was in the middle of a really slow 
train wreck for all of about 15 straight weeks.

But that was *before* Python!

Now I'm in a C++ class at a nearby university, and the course moves at 
such a pace that we made it from "hello world" to introduction of 
pointers in 11 class days, discussing OOP all the while. Thanks to what 
I've learned at the mercies of Python's ease-of-use and helpful 
community, I'm holding down a solid A+ in that class. I'm even able to 
help other students by showing them how to do things that they're stuck 
on by showing them equivalent Python code.

I don't want to down-play legitimate concerns, especially since the 
expression of such concern does seem to have an impact on decisions made 
by the BDFL & Co. But without Python I just might still be looking at 
the not-always-entirely-illuminating documentation available for Perl, 
Java, etc. and thinking I just don't "have what it takes" to program.

Rob
http://uselesspython.com

alan.gauld@bt.com wrote:

>>This is not fun, and learning Python used to be, first of all, fun.
>>
> 
> I think this is a valid point once you get beyond the basics.
> 
> Oddly enough a complete programming novice can still pick 
> up Python (division changes apart) pretty much without change 
> since Python 1.3(when dictionaries got 'fixed').
> 
> The guys who are hurt most are those with say, one previous 
> programming language, especially something like BASIC or JScript,
> and who learn the real baics quickly but then hit a wall with 
> the mass of more advanced techniques.
> 
> Its no longer true that in Python "there's only one way to do it"
> we now have to choose between basic loops, iterators, comprehensions, 
> enumerators etc...
> 
> 
>>As much as I have gotten to love Python, I am beginning to 
>>ask myself why I don't just quit the language for a while 
>>
> 
> I won't be quitting - I'm not that masochistic - but I am 
> slow to upgrade. Just freeze your Python version for a while. 
> There are still a lot of folks on this list still using Python1.5
> and I only have 2.2 on one of my machines even yet (the others 
> are still at 2.1).
> 
> I have no intention of upgrading to 2.3 when it comes out and 
> may stay at 2.2 until 3000 comes out! (I'm hoping to do a 
> second edition of my book based on 3000 someday!)
> 
> 
>>with the Second Edition of Kernighan and Richie, 1988, and get to the 
>>point where I can at least read the C of the Linux Kernel. 
>>
> 
> Actually the change rate on C is suvch that you could probanbly 
> use the original 1978 edition! I still use that rather than fork 
> out for the ANSI edition and rarely get stung. But then I still 
> use Guido et al's original 1996 Internet Programming with Python
> which is written for version 1.3 too... 
> 
> Alan g.
> Author of the 'Learning to Program' web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 






From wolf_binary@hotmail.com  Wed Jun 26 15:13:35 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 26 Jun 2002 09:13:35 -0500
Subject: [Tutor] Tkinter events
Message-ID: <DAV36Ykwn9Wgtc2S6AA0000045f@hotmail.com>

This is a multi-part message in MIME format.

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

Hi all,

I wanted to know what the Gravity event does when you bind it to a =
widget.  I tryied it but it doesn't work or at least it does seem so to =
me.  I found a reference to it in Sams Teach Yourself Python in 24 =
Hours.  The only answer I can come up with, as far as it not working, is =
that it got changed since Python 1.7 which is what was around when the =
book was made. =20

Thanks,
Cameron Stoner

------=_NextPart_000_002B_01C21CF1.C01FC9C0
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I wanted to know what the =
<EM>Gravity</EM> event=20
does when you bind it to a widget.&nbsp; I tryied it but it doesn't work =
or at=20
least it does seem so to me.&nbsp; I found a reference to it in Sams =
Teach=20
Yourself Python in 24 Hours.&nbsp; The only answer I can come up with, =
as far as=20
it not working, is that it got changed since Python 1.7 which is what =
was around=20
when the book was made.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_002B_01C21CF1.C01FC9C0--



From wolf_binary@hotmail.com  Wed Jun 26 15:40:32 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 26 Jun 2002 09:40:32 -0500
Subject: [Tutor] bits taken by variable type
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C68F@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <DAV19hAj5p1Fjxe0ymQ0000045e@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_003E_01C21CF5.83E6C720
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



I guess I would prefer portable psuedo code, because I would be able to =
work on it without being on a computer.  Its a tough call for me to =
make.  If you have a protable assembler then you don't have to write it =
all again.  Say you format a floppy on a Win machine, can you then use =
it in a Linux machine or a Mac?  I was under the imprecion that the =
machines would recognize the format.  I used to be that way on a Mac in =
the late 90's.  I haven't used a Mac since though.

Thanks everyone,
Cameron Stoner
  ----- Original Message -----=20
  From: alan.gauld@bt.com=20
  To: wolf_binary@hotmail.com ; alan.gauld@bt.com ; tutor@python.org=20
  Sent: Monday, June 24, 2002 9:01 AM
  Subject: RE: [Tutor] bits taken by variable type


  >  You can make a program on a Windows machine then transfer it to a =
Linux =20
  >  machine and as long as it doesn't have any platform specific =
programming =20
  >  in it or has been resolved to not have any conflicts I would think =
you could =20
  >  just use it on both machines.=20

  You can do the same with C/C++  but there are more platform=20
  specifics to fall over. But if you write a sort routine or=20
  number crunching program they will work just fine on either
  platform ONCE YOU HAVE COMPILED THEM.

  But having a compiler on each platform is not so very=20
  different from having Python installed...

  The differences are when you get into things like OS calls to files, =
sockets etc.
  Python masks many of those differences behind the os and socket =
modules

  Which do you prefer, portable assembler or portable pseudo code?

  Alan G.=20

------=_NextPart_000_003E_01C21CF5.83E6C720
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 6.00.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I guess I would prefer portable psuedo =
code,=20
because I would be able to work on it without being on a computer.&nbsp; =
Its a=20
tough call for me to make.&nbsp; If you have a protable assembler then =
you don't=20
have to write it all again.&nbsp; Say you format a floppy on a Win =
machine, can=20
you then use it in a Linux machine or a Mac?&nbsp; I was under the =
imprecion=20
that the machines would recognize the format.&nbsp; I used to be that =
way on a=20
Mac in the late 90's.&nbsp; I haven't used a Mac since =
though.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks everyone,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron Stoner</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dalan.gauld@bt.com=20
  href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dwolf_binary@hotmail.com=20
  href=3D"mailto:wolf_binary@hotmail.com">wolf_binary@hotmail.com</A> ; =
<A=20
  title=3Dalan.gauld@bt.com =
href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A>=20
  ; <A title=3Dtutor@python.org=20
  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, June 24, 2002 =
9:01 AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] bits taken =
by=20
  variable type</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; &nbsp;</FONT></SPAN>You can =
make a=20
  program on a Windows machine then transfer it to a Linux&nbsp;<SPAN=20
  class=3D670570014-24062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; </FONT>&nbsp;</SPAN>machine =
and as long=20
  as it doesn't have any platform specific programming&nbsp;<SPAN=20
  class=3D670570014-24062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; </FONT>&nbsp;</SPAN>in it or =
has been=20
  resolved to not have any conflicts I would think you could&nbsp;<SPAN=20
  class=3D670570014-24062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&gt; </FONT>&nbsp;</SPAN>just use =
it on both=20
  machines.<SPAN class=3D670570014-24062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D670570014-24062002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>You can do the same with=20
  C/C++</FONT>&nbsp;<FONT face=3D"Courier New" color=3D#0000ff> but =
there are more=20
  platform </FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>specifics to fall over. But if =
you write a=20
  sort routine or </FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D670570014-24062002><FONT=20
  face=3D"Courier New" color=3D#0000ff>number crunching program they =
will work just=20
  fine on either</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
  class=3D670570014-24062002>platform ONCE YOU HAVE COMPILED=20
  THEM.</SPAN></FONT></DIV>
  <DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
  class=3D670570014-24062002></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
  class=3D670570014-24062002>But having a compiler on each platform is =
not so very=20
  </SPAN></FONT></DIV>
  <DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
  class=3D670570014-24062002>different from having Python=20
  installed...</SPAN></FONT></DIV>
  <DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
  class=3D670570014-24062002></SPAN></FONT><FONT face=3DArial=20
  size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN class=3D670570014-24062002>The =
differences=20
  are when you get into things like OS calls to files, sockets=20
  etc.</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN =
class=3D670570014-24062002>Python masks many=20
  of those differences behind the os and socket =
modules</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D670570014-24062002></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN =
class=3D670570014-24062002><SPAN=20
  class=3D670570014-24062002>Which do you prefer, portable assembler or =
portable=20
  pseudo code?</SPAN></SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D670570014-24062002></SPAN></FONT>&nbsp;</DIV>
  <DIV><SPAN class=3D670570014-24062002></SPAN><FONT face=3DArial><FONT=20
  size=3D2>A<SPAN class=3D670570014-24062002><FONT face=3D"Courier New"=20
  color=3D#0000ff>lan=20
G.&nbsp;</FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_003E_01C21CF5.83E6C720--



From glingl@aon.at  Wed Jun 26 16:30:32 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed, 26 Jun 2002 17:30:32 +0200
Subject: [Tutor] Tkinter events
References: <DAV36Ykwn9Wgtc2S6AA0000045f@hotmail.com>
Message-ID: <009101c21d26$696c6770$1615a8c0@mega>

This is a multi-part message in MIME format.

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


----- Original Message -----=20
From: Cameron Stoner=20
To: python tutor=20
Sent: Wednesday, June 26, 2002 4:13 PM
Subject: [Tutor] Tkinter events


Hi all,

I wanted to know what the Gravity event does when you bind it to a =
widget.  I tryied it but it doesn't work or at least it does seem so to =
me.  I found a reference to it in Sams Teach Yourself Python in 24 =
Hours. =20

---> In the German edition of this book, one reads:=20
---> Dar=FCber brauchen Sie sich keine Gedanken zu machen
...which means (approx.) : You don't need to think about this one
In Grayson's Python and Tkinter book a Gravity event is *mentioned*  =
only once as
a configuration event without any further explanation.
Frederik Lundh's online-document Introduction to Tkinter doesn't mention =
a Gravity-Event
at all (only some methods like mark_gravity of the text_widget)

So, if you still want to know what it is, perhaps you should search the
original Tcl/Tk docs - if you feel familiar enough with this. And let me =
know your results,
please.

Gregor=20


------=_NextPart_000_008E_01C21D37.2CAD5900
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 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV style=3D"FONT: 10pt arial">----- Original Message -----=20
<DIV style=3D"BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A=20
title=3Dwolf_binary@hotmail.com =
href=3D"mailto:wolf_binary@hotmail.com">Cameron=20
Stoner</A> </DIV>
<DIV><B>To:</B> <A title=3Dtutor@python.org =
href=3D"mailto:tutor@python.org">python=20
tutor</A> </DIV>
<DIV><B>Sent:</B> Wednesday, June 26, 2002 4:13 PM</DIV>
<DIV><B>Subject:</B> [Tutor] Tkinter events</DIV></DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I wanted to know what the =
<EM>Gravity</EM> event=20
does when you bind it to a widget.&nbsp; I tryied it but it doesn't work =
or at=20
least it does seem so to me.&nbsp; I found a reference to it in Sams =
Teach=20
Yourself Python in 24 Hours.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>---&gt; In the German edition of this =
book, one=20
reads: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>---&gt; Dar=FCber brauchen Sie sich =
keine Gedanken zu=20
machen</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>...which means (approx.) : You don't =
need to think=20
about this one</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>In Grayson's Python and Tkinter book a =
Gravity=20
event is *mentioned* &nbsp;only once as</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>a configuration event without any =
further=20
explanation.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Frederik Lundh's online-document =
Introduction to=20
Tkinter doesn't mention a Gravity-Event</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>at all (only some&nbsp;methods like =
mark_gravity of=20
the text_widget)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So, if you still want to know what it =
is, perhaps=20
you should search the</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>original Tcl/Tk docs - if you feel =
familiar enough=20
with this. And let me know your results,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>please.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Gregor</FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_008E_01C21D37.2CAD5900--




From alan.gauld@bt.com  Wed Jun 26 17:12:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 26 Jun 2002 17:12:02 +0100
Subject: [Tutor] bits taken by variable type
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6AA@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C21D2C.34DD9AA0
Content-type: text/plain; charset="iso-8859-1"

>  I guess I would prefer portable psuedo code, because I would be able to
work on it  
>  without being on a computer.  Its a tough call for me to make.  If you
have a protable  
>  assembler then you don't have to write it all again.   
 
If its portable the only difference is how much code you need to write to do
the same thing
or how fast you need it to run. C claims to be portable assembler, Python
claims to be 
executable pseudo code and portable...
 
> Say you format a floppy on a Win machine, can you then use it in a Linux
machine or a Mac?   
>  I was under the imprecion that the machines would recognize the format.

 
Ah but that's a different question because to format a floppy for an OS you
would use the 
OS formats which are already written and by definition different. So you are
not doing the 
same thing at an asembler level you are writing two completely different
sets of data.
 
If OTOH you were writing a *driver* for a particular floppy drive on an
Intel chip or on 
a Motorola chip bypassing the OS functions then you could get close to the
same code(in C) 
because you would be writing raw bytes to specific ports in a specific order
using 
C's in(), out() functions etc. When you compile the C for the different
chips you wind 
up with a common set of APIs for the floppy. The OS device driver then gets
written 
to map the OS I/O calls to the floppy API.
 
Maybe the best example is the Unix kernel (and Linux by extension) where
90%+ of 
the source code is identical regardless of the hardware (Intel, powerPC,
Alpha, Sparc etc)
 
Alan g.

------_=_NextPart_001_01C21D2C.34DD9AA0
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>I guess I would prefer 
portable psuedo code, because I would be able to work on it&nbsp;<SPAN 
class=740240716-26062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>without being on a 
computer.&nbsp; Its a tough call for me to make.&nbsp; If you have a 
protable&nbsp;<SPAN class=740240716-26062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>assembler then you 
don't have to write it all again.&nbsp;&nbsp;<SPAN 
class=740240716-26062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>If its 
portable the only difference is how much code you need to write to do the same 
thing</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>or how fast 
you need it to run. C claims to be portable assembler, Python claims to be 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>executable 
pseudo code and portable...</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT></SPAN>Say you format a floppy on a 
Win machine, can you then use it in a Linux machine or a Mac?&nbsp;&nbsp;<SPAN 
class=740240716-26062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>&gt; 
&nbsp;</SPAN>I was under the imprecion that the machines would recognize the 
format.&nbsp;&nbsp;<SPAN class=740240716-26062002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>Ah but that's 
a different question because to format a floppy for an OS you would use the 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002>OS&nbsp;formats which are already written and by 
definition different. So you are not doing the </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>same thing at 
an asembler level you are writing two completely different sets of 
data.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>If OTOH you 
were writing </SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002>a *driver* for a particular floppy drive on an Intel 
chip or on </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>a Motorola 
chip&nbsp;bypassing the&nbsp;OS&nbsp;functions then you could 
</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002>get close to the same code(in C) 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>because you 
would be writing raw bytes to specific </SPAN></FONT></FONT><FONT 
face=Arial><FONT size=2><SPAN class=740240716-26062002>ports in a specific order 
using </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>C's in(), 
out() functions etc. When you compile the C for the different chips you wind 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>up with a 
common set of APIs for the floppy. The OS device driver then gets written 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>to map the OS 
I/O calls to the floppy API.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>Maybe the best 
example is the Unix kernel (and Linux by extension) where 90%+ of 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=740240716-26062002>the source 
</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002>code is identical regardless of the hardware (Intel, 
powerPC, Alpha, Sparc etc)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=740240716-26062002></SPAN></FONT></FONT><FONT face=Arial><FONT 
size=2><SPAN class=740240716-26062002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=670570014-24062002><FONT face="Courier New" color=#0000ff 
size=2><SPAN class=740240716-26062002>Alan 
g.</SPAN></FONT></SPAN></DIV></BODY></HTML>

------_=_NextPart_001_01C21D2C.34DD9AA0--



From terjeja@hotmail.com  Wed Jun 26 17:32:49 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Wed, 26 Jun 2002 16:32:49 +0000
Subject: [Tutor] Excel
Message-ID: <F51LAX3cf3ednHM3SOl0000000f@hotmail.com>

I am trying to change the numberformat on a collumn in Excel.

>>>xl = xlApp.Workbooks(1).Sheets(1)

So when I type
>>>xl.Columns(5).Style.NumberFormat
>>>u'General'

So far so good.

Then I type:
>>>ffac.xl.Columns(5).Style.NumberFormat = "##.##"
>>>ffac.xl.Columns(5).Style.NumberFormat
u'$00.00'

So, I assume that the value in the cells should have changed to number, but 
it hasn't. They are still formated as "general" if I check in Excel. If I 
write ffac.xl.Range("E5").Value I get up the correct value, so I must be 
working with the correct sheet.

How can I change the format of the cells?

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From ccampbell@ede.org  Wed Jun 26 17:40:32 2002
From: ccampbell@ede.org (Colin Campbell)
Date: Wed, 26 Jun 2002 10:40:32 -0600
Subject: [Tutor] Re: "Generic" GetUser
In-Reply-To: <20020626123355.GB9886@dman.ddts.net>
References: <5.1.0.14.0.20020625165252.00a7e6a8@mail.ede.org>
 <5.1.0.14.0.20020625165252.00a7e6a8@mail.ede.org>
Message-ID: <5.1.0.14.0.20020626103111.00a8a1b8@mail.ede.org>

--=====================_4125609==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 06:33 AM 6/26/02, you wrote:
>On Tue, Jun 25, 2002 at 05:02:19PM -0600, Colin Campbell wrote:
>
>| I have an Excel workbook containing many tabs of financial reports. An
>| autorun macro looks up the user login in a table and hides the sheets they
>| are not allowed to see. There are 2 obvious problems: I can't guarantee
>| that the macro is run, and since it makes and API call to Windows, my Mac
>| users are doomed.
>
>Yep.
>
>| <snip>.
>
>What I would suggest is not giving the users data they aren't supposed
>to have in the first place.  Once you've given them the data, there is
>no robust way to prevent them from "having" it.
>
>A better system would be to store all the accounting information where
>the accounting folks can get to it.  From that complete source, you
>can generate the reports that the users are allowed to see.  The only
>remaining issue to decide is how to distribute the resultant reports.
>
>Where I work we are presently transitioning from MUMPS to Solomon IV
>as the accounting package.  The other admin already has a collection
>of tools (Crystal Reports and some php/perl scripts) to generate CSV
>and HTML versions of each person's individual financial reports.  I
>created a zope interface backed by postgresql for users to access
>their reports through a web browser.

Good idea, solves the cross-platform issues nicely.

>  Some people, depending on their
>position, are allowed to view other peoples' reports.  This is all
>managed by some ACLs (Access Control Lists) in the postgres database.
>The zope front-end requires password-based authentication and then
>dynamically builds an index of all the reports that user is allowed to
>view.  The user can then select a report to retrieve it in either HTML
>or CSV form.
>
>Some of the advantages of handling it this way are :
>     1)  all the code runs on one chosen platform and can be tested
>     2)  users don't need to learn anything new -- they already know
>         how to use a web browser
>     3)  the data is all kept on a server, not distributed around
>         (except as allowed by the ACLs)
>     4)  providing the CSV format of the data allows a user to import
>         it into excel or whatever other program they want to, if they
>         want to
>     5)  each report only has one copy stored in the database
>         regardless of how many users are allowed to view it
>
>| My question is this: is there a more generic method or property that is
>| available across all platforms/python implementations, which will return
>| the network login of the person running the program?
>
>No.  UNIX, Windows, and Mac are all different in how they handle
>users.  MacOS (prior to X) didn't even have "users" -- it was a
>single-user desktop system.
>
>HTH,

Yes, it is useful. What you describe is very close to what I am doing 
inside the Excel workbook with an ACL and VBA. I agree, though, that I'm 
going to have to pull the security out into a more controllable tool. The 
big benefit is that I'll have built a more general tool I can use to manage 
many kinds of reports. It's not as elegant as I would have liked, but if 
you've got a lot of nails, you might as well build a hammer!
Thanks, Derrick

Colin


--
One of the symptoms of an approaching nervous breakdown is the belief that 
one's work is terribly important.
-- Bertrand Russell

--=====================_4125609==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<font size=3>At 06:33 AM 6/26/02, you wrote:<br>
<blockquote type=cite class=cite cite>On Tue, Jun 25, 2002 at 05:02:19PM
-0600, Colin Campbell wrote:<br>
&nbsp;<br>
| I have an Excel workbook containing many tabs of financial reports. An
<br>
| autorun macro looks up the user login in a table and hides the sheets
they <br>
| are not allowed to see. There are 2 obvious problems: I can't guarantee
<br>
| that the macro is run, and since it makes and API call to Windows, my
Mac <br>
| users are doomed.<br><br>
Yep.<br>
&nbsp;<br>
| &lt;snip&gt;.<br><br>
What I would suggest is not giving the users data they aren't
supposed<br>
to have in the first place.&nbsp; Once you've given them the data, there
is<br>
no robust way to prevent them from &quot;having&quot; it.<br><br>
A better system would be to store all the accounting information
where<br>
the accounting folks can get to it.&nbsp; From that complete source,
you<br>
can generate the reports that the users are allowed to see.&nbsp; The
only<br>
remaining issue to decide is how to distribute the resultant
reports.&nbsp; <br><br>
Where I work we are presently transitioning from MUMPS to Solomon 
IV<br>
as the accounting package.&nbsp; The other admin already has a
collection<br>
of tools (Crystal Reports and some php/perl scripts) to generate 
CSV<br>
and HTML versions of each person's individual financial reports.&nbsp;
I<br>
created a zope interface backed by postgresql for users to access<br>
their reports through a web browser. </font></blockquote><br>
Good idea, solves the cross-platform issues nicely.<br><br>
<blockquote type=cite class=cite cite><font size=3>&nbsp;Some people,
depending on their<br>
position, are allowed to view other peoples' reports.&nbsp; This is
all<br>
managed by some ACLs (Access Control Lists) in the postgres
database.<br>
The zope front-end requires password-based authentication and then<br>
dynamically builds an index of all the reports that user is allowed
to<br>
view.&nbsp; The user can then select a report to retrieve it in either
HTML<br>
or CSV form.<br><br>
Some of the advantages of handling it this way are :<br>
&nbsp;&nbsp;&nbsp; 1)&nbsp; all the code runs on one chosen platform and
can be tested<br>
&nbsp;&nbsp;&nbsp; 2)&nbsp; users don't need to learn anything new --
they already know<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; how to use a web browser<br>
&nbsp;&nbsp;&nbsp; 3)&nbsp; the data is all kept on a server, not
distributed around<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (except as allowed by the
ACLs)<br>
&nbsp;&nbsp;&nbsp; 4)&nbsp; providing the CSV format of the data allows a
user to import<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it into excel or whatever
other program they want to, if they<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; want to<br>
&nbsp;&nbsp;&nbsp; 5)&nbsp; each report only has one copy stored in the
database<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; regardless of how many users
are allowed to view it<br>
&nbsp;<br>
| My question is this: is there a more generic method or property that is
<br>
| available across all platforms/python implementations, which will
return <br>
| the network login of the person running the program?<br><br>
No.&nbsp; UNIX, Windows, and Mac are all different in how they
handle<br>
users.&nbsp; MacOS (prior to X) didn't even have &quot;users&quot; -- it
was a<br>
single-user desktop system.<br><br>
HTH,<br>
</font></blockquote><br>
Yes, it is useful. What you describe is very close to what I am doing
inside the Excel workbook with an ACL and VBA. I agree, though, that I'm
going to have to pull the security out into a more controllable tool. The
big benefit is that I'll have built a more general tool I can use to
manage many kinds of reports. It's not as elegant as I would have liked,
but if you've got a lot of nails, you might as well build a hammer!<br>
Thanks, Derrick<br><br>
Colin<br><br>
<x-sigsep><p></x-sigsep>
<font size=3>--<br>
One of the symptoms of an approaching nervous breakdown is the belief
that one's work is terribly important.<br>
-- Bertrand Russell<br>
</font></html>

--=====================_4125609==_.ALT--




From jeff@ccvcorp.com  Wed Jun 26 17:58:28 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed, 26 Jun 2002 09:58:28 -0700
Subject: [Tutor] changes in Python 2.2
References: <200206252056.g5PKu3C94393@mail0.rawbw.com> <200206261022.31002.scot@possum.in-berlin.de>
Message-ID: <3D19F2B4.82AC9B62@ccvcorp.com>

I do understand the concern about the rate of change in Python lately, however
I must say that I haven't really seen it as a problem yet.  I've been using
Python since 2.0, and the scripts that I wrote for 2.0 work just fine under
2.2.  Most of my newer scripts use 2.1 features but nothing more (even since
upgrading to 2.2).  Despite all this talk about how quickly the language is
changing...  it really seems to be mostly the same, to me.

With that in mind, I have a few specific comments....


"Scot W. Stevenson" wrote:

> Third, I was under the impression that one of the ideas behind Python was
> to create an easy to learn, easy to use, easy to maintain programming
> language that avoids "esoteric" features in the first place. So what is
> Kuchling telling me here about the Python philosophy? Or, to rephrase
> that: If these features are "esoteric", why were they included at all?

Well, *one* of the ideas behind Python is that it be easy to learn.  One of the
*other* ideas behind Python is that it be a powerful, flexible general purpose
language.  Sometimes the needs of these two ideas conflict with each other, and
Guido and the rest of the Pythonlabs team have put quite a bit of effort to
resolve those conflicts as best they can.  Usually this means that the advanced
features can be safely ignored until you need them.


>  And PEP 283 tells me that Python 2.3 is due to be out before the
> end of the year...and I bet 2.4 is planned for Summer 2003...and 2.5 for
> the end of 2003...

Meanwhile, a new version of Visual Basic is out only once every few years, but
none of the code written for old(/current) versions will work with the new
version.  I'd rather have lots of little incremental changes, which gives me
time to slowly update my code, improve my programming methods, etc.  It's a
philosophical difference -- Python is following the open-source dictum of
"Release early and often", which allows much more chance to fix bugs and
misfeatures in the interpreter.  This does create an issue with the language
itself being something of a moving target, but at least it's a *stable* moving
target.  ;)  And GvR & Co are aware of the difficulties this poses, and they
*do* go to great efforts to avoid breaking old code, and to provide plenty of
time to upgrade code when the old style *does* break.


> The problem is that the rate of change has far outstripped the ability (or
> interest) of the people writing documentation to keep up, especially
> documentation in book form.

This is (sort of) true -- there *is* a lack of documentation, especially books,
that cover the new features and changes of the most recent version(s) of
Python.

However, it's also *not* true -- if you sit down with a 1.5-era book in front
of a 2.2 interpreter, and work through the samples, you'll find almost nothing
that doesn't work as you expect it.


> (Say - wouldn't it be easier for all involved just to freeze Python at, for
> example, 3.0, and then have all of these people with these great new ideas
> sit down and design a new language from scratch, one that has all their
> cool features, is stackless, doesn't have a global interpreter lock, is
> great for numeric computation, etc. pp.? And leave the rest of us with a
> stable language that doesn't take a step forwards every time you try to
> throw your saddle on its back.)

No, it wouldn't be easier.

Besides, you can do that anyhow, at any version -- just stop upgrading your
interpreter.  You'll never have to worry about learning new features.  Yes,
eventually, there will be people writing new libraries and packages that use
newer features, and you won't be able to use those -- but then, if you froze
Python and started a new language, those people would be writing those
libraries and packages for the new language, and wouldn't bother re-writing
them for the now-stagnant Python.  And all the new users would be a lot more
interested in that new language, so you wouldn't have any fresh ideas and
idioms coming into Python.  Before long, Python would be... well, about like
ABC or Icon or Snobol, known only for what grew out of it, but pretty much
pointless on its own.

I recognize the difficulties of the current path, but I think it's better than
the alternatives.

Jeff Shannon
Technician/Programmer
Credit International





From jeff@ccvcorp.com  Wed Jun 26 18:09:30 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed, 26 Jun 2002 10:09:30 -0700
Subject: [Tutor] Excel
References: <F51LAX3cf3ednHM3SOl0000000f@hotmail.com>
Message-ID: <3D19F54A.1008C779@ccvcorp.com>


Terje Johan Abrahamsen wrote:

> Then I type:
> >>>ffac.xl.Columns(5).Style.NumberFormat = "##.##"
> >>>ffac.xl.Columns(5).Style.NumberFormat
> u'$00.00'
>
> So, I assume that the value in the cells should have changed to number, but
> it hasn't. They are still formated as "general" if I check in Excel. If I
> write ffac.xl.Range("E5").Value I get up the correct value, so I must be
> working with the correct sheet.
>
> How can I change the format of the cells?

My own excel-code changes formats for a range of cells, rather than for an
entire column, but it looks like this:

        # [...]
        sh = self.xlBook.Worksheets(sheet)
        r = sh.Range(sh.Cells(row1, col1), sh.Cells(row2, col2) )
        r.NumberFormat = '$#,##0.00;[Red]-$#,##0.00'

The particular format shown is currency, with negative values displaying in
red.  (I actually retrieve the proper format string from a dictionary,
depending on the type of data I'm writing, but trimmed that to just show the
Excel-manipulating code.)

It's been a long time since I wrote this, however, so my memories of how and
why it works are a bit hazy.  :)

Jeff Shannon
Technician/Programmer
Credit International






From lkvam@venix.com  Wed Jun 26 17:49:29 2002
From: lkvam@venix.com (Lloyd Kvam)
Date: Wed, 26 Jun 2002 12:49:29 -0400
Subject: [Tutor] win32serviceutil.StartService bug??
References: <3D18EDA2.1050106@venix.com>
Message-ID: <3D19F099.6070606@venix.com>

I found the C sourcecode for the module that handles the service requests.
It expects a list of arguments. So this works:
win32serviceutil.StartService('mysql', ['--datadir=f:\\mysql\\data_playpark'])

I found some win32serviceutil sample code in the Python cookbook, but the
examples were too simple.  I intend to post my example there when I am done.
Are there any other good sites for this kind of win32 code?

Lloyd Kvam wrote:

> I am writing a Python script to start MySQL with alternative databases.  
> This
> seemed fairly easy until I couldn't get the StartService function to 
> work with
> an argument.  Hopefully, someone will have a suggestion.  I am enclosing my
> python stream which fails, and the results of using a command-line utility.
> The command-line utility works, so I know the MySQL setup is OK.

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From virketis@post.harvard.edu  Wed Jun 26 18:36:36 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Wed, 26 Jun 2002 20:36:36 +0300
Subject: [Tutor] ftp file size puzle
Message-ID: <200206261759.g5QHxW918570@smtp1.fas.harvard.edu>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Dear all, </div>
<div>&nbsp;</div>
<div>I am running into an FTP problem. Basically, I am just=
 trying to work out the very basics of ftplib, and store a file=
 on a server running on my own machine. Here's an example of a=
 typical session, with the problem at the end.</div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; from ftplib import FTP</div>
<div>&gt;&gt;&gt; ftp =3D FTP(&quot;localhost&quot;)</div>
<div>&gt;&gt;&gt; ftp.login(&quot;foo&quot;,=
 &quot;password&quot;)</div>
<div>'230 User logged in.'</div>
<div>&gt;&gt;&gt; ftp.cwd(&quot;upload&quot;)</div>
<div>'250 &quot;/upload&quot; is current directory.'</div>
<div>&gt;&gt;&gt; file =3D open(&quot;foo.pdf&quot;)</div>
<div>&gt;&gt;&gt; ftp.storbinary(&quot;STOR foo.pdf&quot;, file,=
 8192)</div>
<div>'226 Transfer complete. 1200 bytes in 0 sec. (0.00=
 Kb/s).'</div>
<div>&nbsp;</div>
<div>Right, so I get an &quot;all OK&quot; message. Except that=
 the foo.pdf file is actually 500KB big, not 1KB! This has been=
 hounding me for a while now, I have tried varying the buffer=
 size and the files I am sending. The file is indeed placed in=
 the ftp root directory, but it is always a fraction of the size=
 of the real thing: not much good at all, unfortunately. I am=
 using Windows XP, Python 2.2.1 and GuildFTP as my server. But I=
 am sure this has little to do with the tools, and much to do=
 with some glaring error I make in my ignorance. I am pretty sure=
 I have set all the permissions correctly, because I can use a=
 proper FTP client with the same account to upload any file=
 successfully. </div>
<div>&nbsp;</div>
<div>Thanks for all help, </div>
<div>&nbsp;</div>
<div>Pijus </div>
<div>&nbsp;</div>
<div>-- </div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann</div>
</body></html>




From dyoo@hkn.eecs.berkeley.edu  Wed Jun 26 19:56:50 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 26 Jun 2002 11:56:50 -0700 (PDT)
Subject: [Tutor] ftp file size puzle
In-Reply-To: <200206261759.g5QHxW918570@smtp1.fas.harvard.edu>
Message-ID: <Pine.LNX.4.44.0206261144470.1743-100000@hkn.eecs.berkeley.edu>


On Wed, 26 Jun 2002, Pijus Virketis wrote:

> I am running into an FTP problem. Basically, I am just trying to work
> out the very basics of ftplib, and store a file on a server running on
> my own machine. Here's an example of a typical session, with the problem
> at the end.
>
> >>> from ftplib import FTP
> >>> ftp = FTP("localhost")
> >>> ftp.login("foo", "password")
> '230 User logged in.'
> >>> ftp.cwd("upload")
> '250 "/upload" is current directory.'
> >>> file = open("foo.pdf")
             ^^^^^^^^^^^^^^^

Ah!  Adobe PDF files are binary --- they're not organized into lines
separated by newline characters.

Many operating systems treat text files differently from binary files.
One consequence is that text files using a special character called 'EOF'
to indicate the end of the file.  As soon as we hit 'EOF' in a text-mode
file, the system will think that it's the end of the road, and stop
reading.

(Binary files, too, contain this EOF character, but in a binary file's
case, it's just another byte.  FTP needs to then actually take in the
file's length before downloading the file, which is why FTP makes a
distinction between "ASCII" (text) and binary mode.)



> Right, so I get an "all OK" message. Except that the foo.pdf file is
> actually 500KB big, not 1KB! This has been hounding me for a while now,

There's one fix you'll want to make: you'll want to open the file in
binary mode:

    file = open("some_file_name", "b")

Hopefully, that should fix things.  Good luck!




From terjeja@hotmail.com  Wed Jun 26 21:16:56 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Wed, 26 Jun 2002 20:16:56 +0000
Subject: [Tutor] Pythonwin
Message-ID: <F213dhNzW3l1GM3h3vL00000648@hotmail.com>

I am using ActiveState PythonWin for Win2k. I have a few questions about 
this program. 1) Lets say I want to use the function string.atof('55.4'). 
Then I start typing String. when I have typed the . a box comes up with what 
is possible to type further. ascii_letters is the first one. Which key do I 
press to get that filled in automatically. I have read something with the \ 
key if I don't remember wrong, but I never got that to work.

2) If I write a program:
while 1 == 1:
   print"hello"

It will print hello forever. How do I stop it without stopping the PythonWin 
program? Ctrl-c and ctrl-break doesn't work. Is there anything that will 
work?

Thanks,
Terje


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From virketis@post.harvard.edu  Wed Jun 26 19:34:41 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Wed, 26 Jun 2002 21:34:41 +0300
Subject: [Tutor] ftp file size puzle
In-Reply-To: <Pine.LNX.4.44.0206261144470.1743-100000@hkn.eecs.berkeley.edu>
Message-ID: <ISPFE7ZDgC81TbdkSmL0000cbb7@mail.takas.lt>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Danny,<br></div>
<div><br>
<FONT COLOR=3D"#000080">&gt;There's one fix you'll want to make:=
 you'll want to open the file in</FONT><br>
<FONT COLOR=3D"#000080">&gt;binary mode:</FONT><br>
<FONT COLOR=3D"#000080">&gt;</FONT><br>
<FONT COLOR=3D"#000080">&gt;file =3D open(&quot;some_file_name&quot;,=
 &quot;b&quot;)</FONT><br>
<br>
Your suggestion was right on! One little detail. It seems that in=
 order to open up a file in binary, the modifier should actually=
 be &quot;rb&quot; or &quot;wb&quot;, because &quot;b&quot; on=
 its own gives an IOError in P2.2.1. Just in case someone else=
 wants to try this at home. :)<br></div>
<div>&nbsp;</div>
<div>Thanks for a quick reply, <br></div>
<div>&nbsp;</div>
<div>Pijus<br></div>
<div>&nbsp;</div>
<div>-- <br></div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann<br></div>
</body></html>




From dyoo@hkn.eecs.berkeley.edu  Wed Jun 26 21:41:56 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 26 Jun 2002 13:41:56 -0700 (PDT)
Subject: [Tutor] ftp file size puzle
In-Reply-To: <ISPFE7ZDgC81TbdkSmL0000cbb7@mail.takas.lt>
Message-ID: <Pine.LNX.4.44.0206261338590.4509-100000@hkn.eecs.berkeley.edu>


On Wed, 26 Jun 2002, Pijus Virketis wrote:

> Danny,
>
> >There's one fix you'll want to make: you'll want to open the file in
> >binary mode:
> >
> >file = open("some_file_name", "b")
>
> Your suggestion was right on! One little detail. It seems that in order
> to open up a file in binary, the modifier should actually be "rb" or
> "wb", because "b" on its own gives an IOError in P2.2.1. Just in case
> someone else wants to try this at home. :)

I knew I should have tested that before writing it.  *grin* Thanks for the
correction.



(Pijus, by the way, your email server is doing weird things; when I send
messages to you, I get the following error message:

###
451 4.4.1 reply: read error from mail.virketis.com.
553 5.3.5 smtp.virketis.com. config error: mail loops back to me (MX
problem?)
554 5.3.5 Local configuration error
###

You may want to check smtp.virketis.com's mail settings; it looks wacky.
Someone else ran into this problem when replying to one of your messages.)




From pythontutor@venix.com  Wed Jun 26 22:31:48 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Wed, 26 Jun 2002 17:31:48 -0400
Subject: [Tutor] Pythonwin
References: <F213dhNzW3l1GM3h3vL00000648@hotmail.com>
Message-ID: <3D1A32C4.8030008@venix.com>

Use the TAB key to "autocomplete" your typing.

right-click on the Python ICON in the sys-tray and choose:
	Break into running code
to break a loop

Terje Johan Abrahamsen wrote:

> I am using ActiveState PythonWin for Win2k. I have a few questions about 
> this program. 1) Lets say I want to use the function 
> string.atof('55.4'). Then I start typing String. when I have typed the . 
> a box comes up with what is possible to type further. ascii_letters is 
> the first one. Which key do I press to get that filled in automatically. 
> I have read something with the \ key if I don't remember wrong, but I 
> never got that to work.
> 
> 2) If I write a program:
> while 1 == 1:
>   print"hello"
> 
> It will print hello forever. How do I stop it without stopping the 
> PythonWin program? Ctrl-c and ctrl-break doesn't work. Is there anything 
> that will work?
> 
> Thanks,
> Terje
> 
> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From glingl@aon.at  Wed Jun 26 22:35:51 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed, 26 Jun 2002 23:35:51 +0200
Subject: [Tutor] Pythonwin
References: <F213dhNzW3l1GM3h3vL00000648@hotmail.com>
Message-ID: <003001c21d59$71b0eb30$1615a8c0@mega>

----- Original Message -----
From: "Terje Johan Abrahamsen" <terjeja@hotmail.com>
To: <tutor@python.org>
Sent: Wednesday, June 26, 2002 10:16 PM
Subject: [Tutor] Pythonwin


> I am using ActiveState PythonWin for Win2k. I have a few questions about
> this program. 1) Lets say I want to use the function string.atof('55.4').
> Then I start typing String. when I have typed the . a box comes up with
what
> is possible to type further. ascii_letters is the first one. Which key do
I
> press to get that filled in automatically.

You have to press the Tab-key.

If you want to use the atof function, you have to type a then t - and
now atof is selected and Tab-key completes the function name.

I have read something with the \
> key if I don't remember wrong, but I never got that to work.
>
> 2) If I write a program:
> while 1 == 1:
>    print"hello"
>
> It will print hello forever. How do I stop it without stopping the
PythonWin
> program? Ctrl-c and ctrl-break doesn't work. Is there anything that will
> work?

As far as I know, its impossible to stop this loop - a fact which proves
especially problematic in eduacational settings - say in a classroom -
where infinite loops use to happen not too seldom.

I would be very glad, if I were wrong in this respect.

Gregor


>
> Thanks,
> Terje
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From glingl@aon.at  Wed Jun 26 22:40:06 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed, 26 Jun 2002 23:40:06 +0200
Subject: [Tutor] Pythonwin
References: <F213dhNzW3l1GM3h3vL00000648@hotmail.com> <3D1A32C4.8030008@venix.com>
Message-ID: <003701c21d5a$0a0ea7f0$1615a8c0@mega>

----- Original Message ----- 
From: "Lloyd Kvam" <pythontutor@venix.com>
To: "Terje Johan Abrahamsen" <terjeja@hotmail.com>
Cc: <tutor@python.org>
Sent: Wednesday, June 26, 2002 11:31 PM
Subject: Re: [Tutor] Pythonwin


> Use the TAB key to "autocomplete" your typing.
> 
> right-click on the Python ICON in the sys-tray and choose:
> Break into running code
> to break a loop
> 

INDEED THIS WORKS! VERY GOOD NEWS! THANKS

Gregor

> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
> 
> voice: 
> 603-443-6155
> fax: 
> 801-459-9582
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




From flaxeater@yahoo.com  Wed Jun 26 22:44:33 2002
From: flaxeater@yahoo.com (Chad Crabtree)
Date: Wed, 26 Jun 2002 14:44:33 -0700 (PDT)
Subject: [Tutor] Re: Tkinter Gravity event
In-Reply-To: <20020626160005.26320.56543.Mailman@mail.python.org>
Message-ID: <20020626214433.63560.qmail@web11605.mail.yahoo.com>

The only gravity that I can think of is for a text box
widget which after you place a mark tells which way
the test goeas after that.  therefore the two values
are left and right, I believe the default is right
meaning that any text inserted at the mark will move
right.  I found this reference 

.mark_gravity ( mark, gravity=None )
Changes or queries the gravity of an existing mark;
see Marks in text widgets, above,
for an explanation of gravity. To set the gravity,
pass in the name of the mark, followed by
either LEFT or RIGHT. To find the gravity of an
existing mark, omit the second argument
and the method returns LEFT or RIGHT.

which is a method for the textbox widget

the complete Tkinter Reference is found here:

http://www.nmt.edu/tcc/help/lang/python/

I have used it and found it even better than the
Reference available at pythonware




__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From jeff@ccvcorp.com  Wed Jun 26 23:02:48 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed, 26 Jun 2002 15:02:48 -0700
Subject: [Tutor] Pythonwin
References: <F213dhNzW3l1GM3h3vL00000648@hotmail.com> <003001c21d59$71b0eb30$1615a8c0@mega>
Message-ID: <3D1A3A07.9DE22B5C@ccvcorp.com>

Gregor Lingl wrote:

> From: "Terje Johan Abrahamsen" <terjeja@hotmail.com>
> Subject: [Tutor] Pythonwin
>
> > I am using ActiveState PythonWin for Win2k. I have a few questions about
> > this program. 1) Lets say I want to use the function string.atof('55.4').
> > Then I start typing String. when I have typed the . a box comes up with
> what
> > is possible to type further. ascii_letters is the first one. Which key do
> I
> > press to get that filled in automatically.
>
> You have to press the Tab-key.
>
> If you want to use the atof function, you have to type a then t - and
> now atof is selected and Tab-key completes the function name.

You can also navigate within the listbox by using the up and down arrow keys.
When the correct item is highlighted, then press Tab.

Jeff Shannon
Technician/Programmer
Credit International





From ak@silmarill.org  Wed Jun 26 23:34:37 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Wed, 26 Jun 2002 18:34:37 -0400
Subject: [Tutor] pair programming.
Message-ID: <20020626223437.GA28191@ak.silmarill.org>

Hello pythoneers,

Does anyone wanna try pair programming over the net, using screen and
irc, with me? I never tried that, but it sounds interesting.

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From rob@uselesspython.com  Thu Jun 27 00:28:08 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Wed, 26 Jun 2002 18:28:08 -0500
Subject: [Tutor] pair programming.
References: <20020626223437.GA28191@ak.silmarill.org>
Message-ID: <3D1A4E08.6050300@uselesspython.com>

Oh, how I wish I had the time to do some of that right now. If I wasn't 
staring down the barrel of C++ exams & final project at school, I'd jump 
at it. I've been curious about the experience of extreme programming 
with interactive interpreters for a while now.

Rob
http://uselesspython.com

Andrei Kulakov wrote:

> Hello pythoneers,
> 
> Does anyone wanna try pair programming over the net, using screen and
> irc, with me? I never tried that, but it sounds interesting.
> 
>  - Andrei
> 
> 






From ak@silmarill.org  Thu Jun 27 00:32:02 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Wed, 26 Jun 2002 19:32:02 -0400
Subject: [Tutor] pair programming.
In-Reply-To: <3D1A4E08.6050300@uselesspython.com>
References: <20020626223437.GA28191@ak.silmarill.org> <3D1A4E08.6050300@uselesspython.com>
Message-ID: <20020626233202.GA29257@ak.silmarill.org>

On Wed, Jun 26, 2002 at 06:28:08PM -0500, Rob Andrews wrote:
> Oh, how I wish I had the time to do some of that right now. If I wasn't 
> staring down the barrel of C++ exams & final project at school, I'd jump 
> at it. I've been curious about the experience of extreme programming 
> with interactive interpreters for a while now.
> 
> Rob
> http://uselesspython.com
>

Well, write down my email and get in touch when you have time :-).

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From e.kotyk@shaw.ca  Wed Jun 26 23:17:15 2002
From: e.kotyk@shaw.ca (Eve Kotyk)
Date: Wed, 26 Jun 2002 22:17:15 +0000
Subject: [Tutor] pair programming.
In-Reply-To: <20020626223437.GA28191@ak.silmarill.org>
References: <20020626223437.GA28191@ak.silmarill.org>
Message-ID: <20020626221715.62712738.e.kotyk@shaw.ca>

--=.OQZH14zgTe),(4
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Wed, 26 Jun 2002 18:34:37 -0400
Andrei Kulakov <ak@silmarill.org> wrote:

> Hello pythoneers,
> 
> Does anyone wanna try pair programming over the net, using screen and
> irc, with me? I never tried that, but it sounds interesting.

My son who is a programmer for a company in Ottawa does this.  He tells
me it is a very exciting and successful process.  

E

-- 

ekotyk

http://members.shaw.ca/e.kotyk/virtualstudio.htm

--=.OQZH14zgTe),(4
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE9Gj1uyxm8dPG0oMIRAlMmAJ9ZwFmOil7VHslPBWvllA+zQcAsKACggdqV
UweGA2Rab5tqJ7eU6+LYv1U=
=SCxX
-----END PGP SIGNATURE-----

--=.OQZH14zgTe),(4--




From printers@sendme.cz  Thu Jun 27 07:24:37 2002
From: printers@sendme.cz (A)
Date: Thu, 27 Jun 2002 08:24:37 +0200
Subject: [Tutor] How to find out operating system
Message-ID: <3D1ACBC5.22482.D4313A4@localhost>

Hi,
What is the best way of  finding out the kind operating system?
I can use os.name but if the system is Windows I would like also 
know if the system is Windows98 or Windows ME or W2K or 
Windows XP.
Thanks for help.
Ladislav





From printers@sendme.cz  Thu Jun 27 07:24:37 2002
From: printers@sendme.cz (A)
Date: Thu, 27 Jun 2002 08:24:37 +0200
Subject: [Tutor] How to find out operating system
Message-ID: <3D1ACBC5.22482.D4313A4@localhost>

Hi,
What is the best way of  finding out the kind operating system?
I can use os.name but if the system is Windows I would like also 
know if the system is Windows98 or Windows ME or W2K or 
Windows XP.
Thanks for help.
Ladislav


_______________________________________________
ActivePython mailing list
ActivePython@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython




From alan.gauld@bt.com  Thu Jun 27 11:41:07 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 27 Jun 2002 11:41:07 +0100
Subject: [Tutor] ftp file size puzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6B0@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C21DC7.24AED450
Content-type: text/plain; charset="ISO-8859-1"

 >  I am running into an FTP problem.  
>  Basically, I am just trying to work out the very basics of ftplib,  
 
Caveat, I've no experience of ftplib...
 
>>> ftp.storbinary("STOR foo.pdf", file, 8192) 
 '226 Transfer complete. 1200 bytes in 0 sec. (0.00 Kb/s).'

Right, so I get an "all OK" message. Except that the foo.pdf file is
actually 500KB big,  
not 1KB!  
 

I know you used strorbinary as a method but is there any possibility 
it still used ASCII? Thats the usual ftp reason for truncating files...
Are there flags you can use to set binary/ASCII as the 'mode' or something?
 
Just guessing...
 
Alan G.
 

------_=_NextPart_001_01C21DC7.24AED450
Content-type: text/html; charset="ISO-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=280124310-27062002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>I am running into an FTP 
problem.&nbsp;<SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=280124310-27062002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>Basically, I am just trying to work out the very 
basics of ftplib,&nbsp;<SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=280124310-27062002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=280124310-27062002><FONT face="Courier New" color=#0000ff 
size=2>Caveat, I've no experience of ftplib...</FONT></SPAN></DIV>
<DIV><SPAN class=280124310-27062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; ftp.storbinary("STOR foo.pdf", file, 8192)<SPAN 
class=280124310-27062002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=280124310-27062002>&nbsp;</SPAN>'226 Transfer complete. 1200 
bytes in 0 sec. (0.00 Kb/s).'</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV>Right, so I get an "all OK" message. Except that the foo.pdf file is 
  actually 500KB big,&nbsp;<SPAN class=280124310-27062002><FONT 
  face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV>not 1KB!&nbsp;<SPAN class=280124310-27062002><FONT face="Courier New" 
  color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV><SPAN class=280124310-27062002><FONT face="Courier New" color=#0000ff 
  size=2></FONT></SPAN>&nbsp;</DIV></BLOCKQUOTE>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>I know you used strorbinary as a method but is there any 
possibility </FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>it still used ASCII? Thats the usual ftp reason for 
truncating files...</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>Are there flags you can use to set binary/ASCII as the 
'mode' or something?</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>Just guessing...</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr><SPAN class=280124310-27062002><FONT face="Courier New" 
color=#0000ff size=2>Alan G.</FONT></SPAN></DIV>
<DIV dir=ltr>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C21DC7.24AED450--



From terjeja@hotmail.com  Thu Jun 27 15:08:23 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Thu, 27 Jun 2002 14:08:23 +0000
Subject: [Tutor] Curses
Message-ID: <F225DIRWYBXv6ZWY6r600001625@hotmail.com>

I need the module curses.ascii.isdigit and have included the following in my 
program:

import curses
from curses import ascii
from curses.ascii import isdigit

When I try to run it, I get this response:
Traceback (most recent call last):
  File 
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", 
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\ff\ffac.py", line 6, in ?
    import curses
  File "C:\Python22\lib\curses\__init__.py", line 15, in ?
    from _curses import *
ImportError: No module named _curses

But, then I write >>>import curses and run it again. Then everything works 
perfect? What is wrong? Why isn't it imported the first time by the program?

Thanks,
Terje

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




From alan.gauld@bt.com  Thu Jun 27 15:53:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 27 Jun 2002 15:53:24 +0100
Subject: [Tutor] Curses
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6B6@mbtlipnt02.btlabs.bt.co.uk>

> When I try to run it, I get this response:
> Traceback (most recent call last):
>   File 
> "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scrip
> tutils.py", 

Hmm, you are using curses on Windows?
Which version are you using? Where did you get it from?
So far I've failed to find a curses version that would 
work on MS platforms.

> ImportError: No module named _curses
> 
> But, then I write >>>import curses and run it again. 

Unfortunately, never having got curses working on Win32 
I can't help!

Sorry,

Alan g.

PS Why not just use: 

def isdigit(d): return d in string.digits

What does the curses version do????



From virketis@post.harvard.edu  Thu Jun 27 15:12:02 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Thu, 27 Jun 2002 17:12:02 +0300
Subject: [Tutor] drag-and-drop argument passing
Message-ID: <200206271513.g5RFDA002723@smtp3.fas.harvard.edu>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Dear all, </div>
<div>&nbsp;</div>
<div>I have a script that takes an arbitrary number of paths to=
 files as a command line argument, and manipulates the said=
 files. Now, I would like to be able to execute the script and=
 pass the arguments to it by drag-and-dropping the target files=
 on the script icon in Windows. How should such inputs be=
 handled? I have looked through the tutor and win32 list archives=
 on ASPN, but could not find an answer to this question. </div>
<div>&nbsp;</div>
<div>Thanks for your help, </div>
<div>&nbsp;</div>
<div>Pijus</div>
<div>&nbsp;</div>
<div>-- </div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann</div>
</body></html>




From whenpigsfly06@hotmail.com  Thu Jun 27 17:02:17 2002
From: whenpigsfly06@hotmail.com (Dont Know Tell Me Plz)
Date: Thu, 27 Jun 2002 16:02:17 +0000
Subject: [Tutor] Cant get "print "hello world"" to work
Message-ID: <F130ad2VqKwRPQIWDO30000192f@hotmail.com>

<html><div style='background-color:'><DIV>Whenever i try to run anything it always tells me...</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File "C:\Python22\hello.py", line 3</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hello world</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^</DIV>
<DIV>It always points at the 1 of the last numbers digits or " 's</DIV>
<DIV>&nbsp;</DIV>
<DIV>Plz Help Me</DIV></div><br clear=all><hr>Send and receive Hotmail on your mobile device: <a href='http://g.msn.com/1HM505401/45'>Click Here</a><br></html>



From jeff@ccvcorp.com  Thu Jun 27 17:26:43 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 27 Jun 2002 09:26:43 -0700
Subject: [Tutor] Curses
References: <F225DIRWYBXv6ZWY6r600001625@hotmail.com>
Message-ID: <3D1B3CC2.EFACCBAD@ccvcorp.com>


Terje Johan Abrahamsen wrote:

> I need the module curses.ascii.isdigit ....

Are you *sure* that you need that??  ;)

>>> "123".isdigit()
1
>>> "A23".isdigit()
0
>>> "6fg".isdigit()
0
>>>

There is now a string method isdigit(), that's available anywhere (Python 2.0+,
IIRC).  The curses package, on the other hand, is a Unix-only thing.  There may
be some ports of curses for Win32, but they're not included in the standard
Python distribution.  Besides, the point of curses is to manipulate the terminal
-- if you simply need to find out information about a string, without affecting
the terminal itself, then you're much better off using the lighter-weight string
module, or better yet the built-in string methods.


> import curses
> from curses import ascii
> from curses.ascii import isdigit

By the way, if you *are* trying to import something from within a nested package
like this, the first two lines are unnecessary.  If you use "from curses.ascii
import isdigit", the interpreter will automatically import the higher levels for
you.  The only reason to use the first two lines, would be if you need access to
other items in, say, the curses.ascii namespace.  (In which case, though, you'd
be better off just using "from curses import ascii", and then
"ascii.isdigit(mystring)" or whatever.)

Jeff Shannon
Technician/Programmer
Credit International






From alan.gauld@bt.com  Thu Jun 27 17:17:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 27 Jun 2002 17:17:36 +0100
Subject: [Tutor] drag-and-drop argument passing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6BA@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C21DF6.265218B0
Content-type: text/plain; charset="iso-8859-1"

>  I have a script that takes an arbitrary number of paths to files as a  
>  command line argument, and manipulates the said files. Now, I would  
>  like to be able to execute the script and pass the arguments to it by  
>  drag-and-dropping the target files on the script icon in Windows.  
 
OK, Just do it. It should just work.
 
Windows passes dragged files in as command line args.
I'm not so sure about multiple files tho' but try a 
single file to see if that works first.
 
Get it to log sys.args and see what Windows passes 
to it...
 
Alan g.
 
 

------_=_NextPart_001_01C21DF6.265218B0
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>&gt; &nbsp;</FONT></SPAN>I have a script that takes an arbitrary number 
of paths to files as a&nbsp;<SPAN class=830281916-27062002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>command line argument, and manipulates the said 
files. Now, I would&nbsp;<SPAN class=830281916-27062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>like to be able to execute the script and pass 
the arguments to it by&nbsp;<SPAN class=830281916-27062002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>drag-and-dropping the target files on the script 
icon in Windows.&nbsp;<SPAN class=830281916-27062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>OK, Just do it. It should just work.</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>Windows passes dragged files in as command line args.</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>I'm not so sure about multiple files tho' but try a </FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>single file to see if that works first.</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>Get it to log sys.args and see what Windows passes </FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>to it...</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2>Alan g.</FONT></SPAN></DIV>
<DIV><SPAN class=830281916-27062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff 
size=2></FONT>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C21DF6.265218B0--



From dyoo@hkn.eecs.berkeley.edu  Thu Jun 27 17:50:52 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 27 Jun 2002 09:50:52 -0700 (PDT)
Subject: [Tutor] Cant get "print "hello world"" to work
In-Reply-To: <F130ad2VqKwRPQIWDO30000192f@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206270946060.20916-100000@hkn.eecs.berkeley.edu>


On Thu, 27 Jun 2002, Dont Know Tell Me Plz wrote:

> Whenever i try to run anything it always tells me...
>        File "C:\Python22\hello.py", line 3
>              hello world
>                             ^
> It always points at the 1 of the last numbers digits or " 's

Hello!

Hmmm... can you show us what hello.py looks like?  It sounds like there
might be a small syntax error that's causing Python to get confused.
Please feel free to cut and paste verbatim, so that we can see what the
program looks like.


Also, there are often a few extra lines of error message that show up.
Here's an example of an error message;

###
>>> the sampo!
  File "<stdin>", line 1
    the sampo!
            ^
SyntaxError: invalid syntax
###


Python tries to be helpful by saying exactly why it's getting confused,
and approximately where it got lost.  So that very last line is also
useful for us.


Good luck to you!




From printers@sendme.cz  Thu Jun 27 18:03:34 2002
From: printers@sendme.cz (A)
Date: Thu, 27 Jun 2002 19:03:34 +0200
Subject: [Tutor] How to find out DNS ?
Message-ID: <3D1B6186.3142.295959@localhost>

Hi,
Is there a way how to find out, from Python , what primary or 
secondary DNS I use when connecting to internet?
Thanks for help
Ladislav




From printers@sendme.cz  Thu Jun 27 18:03:34 2002
From: printers@sendme.cz (A)
Date: Thu, 27 Jun 2002 19:03:34 +0200
Subject: [Tutor] How to find out DNS ?
Message-ID: <3D1B6186.3142.295959@localhost>

Hi,
Is there a way how to find out, from Python , what primary or 
secondary DNS I use when connecting to internet?
Thanks for help
Ladislav

_______________________________________________
ActivePython mailing list
ActivePython@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython




From dman@dman.ddts.net  Thu Jun 27 18:55:20 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 27 Jun 2002 12:55:20 -0500
Subject: [Tutor] Re: How to find out DNS ?
In-Reply-To: <3D1B6186.3142.295959@localhost>
References: <3D1B6186.3142.295959@localhost>
Message-ID: <20020627175520.GA3547@dman.ddts.net>

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

On Thu, Jun 27, 2002 at 07:03:34PM +0200, A wrote:

| Is there a way how to find out, from Python , what primary or=20
| secondary DNS I use when connecting to internet?

f =3D open( "/etc/resolv.conf" , "r" )
nameservers =3D []
for line in f.xreadlines() :
    line =3D line.strip()
    if line.startswith( "nameserver" ) :
        _ , ip =3D line.split()
        nameservers.append( ip )
f.close()
for ns in nameserver :
    print "nameserver" , ns


Of course, this only works on a UNIX-like system where
/etc/resolv.conf is used to list the nameservers.  A common setup (on
unix systems) is for some entries to be in /etc/hosts which takes
precedence over DNS lookups.  Any given application can also do its
own thing too, if it wants.  For example, the 'host' command can be
told to contact any arbitrary host and submit a DNS query to it.  Some
setups will have LDAP (or maybe NIS) also serving host information, in
which case DNS isn't involved for those hosts.

Why do you want to know what the nameserver(s) are?  Usually it is
better to not know that and just let the underlying libresolv handle
name resolution for you.  (program to the interface, not the
implementation ...)

-D

--=20

Microsoft is to operating systems & security ....
                                     .... what McDonald's is to gourmet coo=
king
=20
http://dman.ddts.net/~dman/


--8t9RHnE3ZwKMSgU+
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0bUYcACgkQO8l8XBKTpRR4cgCdHiTyTTOJrHT/0Da5+TbhUJUE
cBoAoKi8bnhEQkRUOdTwi8BQ2bW48/7r
=e7GP
-----END PGP SIGNATURE-----

--8t9RHnE3ZwKMSgU+--



From marcolinux@linuxbr.com.br  Thu Jun 27 19:04:08 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Thu, 27 Jun 2002 15:04:08 -0300
Subject: [Tutor] Re: How to find out DNS ?
In-Reply-To: <20020627175520.GA3547@dman.ddts.net>
References: <3D1B6186.3142.295959@localhost> <20020627175520.GA3547@dman.ddts.net>
Message-ID: <20020627180408.GA2663@marcolab.proconet>

Derrick 'dman' Hudson (dman@dman.ddts.net) wrote:

> f =3D open( "/etc/resolv.conf" , "r" )
> nameservers =3D []
> for line in f.xreadlines() :

Nice code Dman. But there are some lines I didnt understand.
Why r u using xreadlines? What's wrong with good, old readlines?

>     line =3D line.strip()
>     if line.startswith( "nameserver" ) :
>         _ , ip =3D line.split()

I did not understand the thing with _ . Can u explain?
Thanks in advance and sorry If my questions are too dumb.

--=20
I SeE NeRD pEoPle.
=2E:: MarcoLinux ::.



From dman@dman.ddts.net  Thu Jun 27 21:19:29 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Thu, 27 Jun 2002 15:19:29 -0500
Subject: [Tutor] Re: Re: How to find out DNS ?
In-Reply-To: <20020627180408.GA2663@marcolab.proconet>
References: <3D1B6186.3142.295959@localhost> <20020627175520.GA3547@dman.ddts.net> <20020627180408.GA2663@marcolab.proconet>
Message-ID: <20020627201929.GA6342@dman.ddts.net>

--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Jun 27, 2002 at 03:04:08PM -0300, Marc wrote:
| Derrick 'dman' Hudson (dman@dman.ddts.net) wrote:
|=20
| > f =3D open( "/etc/resolv.conf" , "r" )
| > nameservers =3D []
| > for line in f.xreadlines() :
|=20
| Nice code Dman. But there are some lines I didnt understand.
| Why are you using xreadlines? What's wrong with good, old readlines?

readlines reads the whole file into one (potentially big) list in
memory at once.  xreadlines instead reads the lines one-by-one as you
ask for them.  If the file is large, readlines() will be slow and use
lots of memory, and could even DoS the system if the file is large
enough.  xreadlines doesn't have that potential problem.  (hmm,
actually, any line reading method could have that problem if a really
large file with no linebreaks are given.  oh well, deal with it if you
think you might get such data :-))  Even though I don't expect
anyone's resolv.conf to be large, there's no reason not to use
xreadlines.  (actually, if I was using 2.2, a file object is iterable
so there's no need to call any methods on it)

| >     line =3D line.strip()
| >     if line.startswith( "nameserver" ) :
| >         _ , ip =3D line.split()
|=20
| I did not understand the thing with _ . Can you explain?

The line looks like
    nameserver  192.168.0.154
I can split() it on the space and get back a 2-element list containing
"nameserver" and "192.168.0.154".  I can conveniently use tuple
unpacking to assign each element to a different name.  That's great,
but I really only want the "192.168.0.154" part of the data.  So
instead of trying to find a descriptive name for data I don't want, I
used '_' as the name.  That variable is never used anywhere, so it
really doesn't matter, except that syntactically and semantically it
is required on that line.  Any other name would have worked just as
well, but '_' is easy to type and doesn't bear any other meaning.
(however, if I was going to use it, I would choose a descriptive name
for it instead).

| Thanks in advance

You're welcome.

| and sorry If my questions are too dumb.
=20
Those sorts of questions are expected on a 'tutor' list :-).

-D

--=20

A wise servant will rule over a disgraceful son,
and will share the inheritance as one of the brothers.
        Proverbs 17:2
=20
http://dman.ddts.net/~dman/


--ikeVEW9yuYc//A+q
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0bc1EACgkQO8l8XBKTpRTLBACgnSzaHX0b3VfDA5tdFS9ifg78
7ngAniXffnhn7FB5L6Ga9MzpbV8HaTby
=k/er
-----END PGP SIGNATURE-----

--ikeVEW9yuYc//A+q--



From kalle@lysator.liu.se  Thu Jun 27 20:03:45 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Thu, 27 Jun 2002 21:03:45 +0200
Subject: [Tutor] Re: How to find out DNS ?
In-Reply-To: <20020627180408.GA2663@marcolab.proconet>
References: <3D1B6186.3142.295959@localhost> <20020627175520.GA3547@dman.ddts.net> <20020627180408.GA2663@marcolab.proconet>
Message-ID: <20020627190345.GG11208@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Derrick 'dman' Hudson (dman@dman.ddts.net) wrote:
> 
> > f = open( "/etc/resolv.conf" , "r" )
> > nameservers = []
> > for line in f.xreadlines() :

[Marc]
> Nice code Dman. But there are some lines I didnt understand.
> Why r u using xreadlines? What's wrong with good, old readlines?

If the file is large, readlines will consume very much memory.
Admittedly, this is unlikely when the file in question is
/etc/resolv.conf, but it's a good habit to use xreadlines.

> >     line = line.strip()
> >     if line.startswith( "nameserver" ) :
> >         _ , ip = line.split()
> 
> I did not understand the thing with _ . Can u explain?
> Thanks in advance and sorry If my questions are too dumb.

line.split() returns a two-element tuple,

("nameserver", "10.0.0.1")

but we're only interested in the IP address.
Note that this is a valid form of assignment:

_, ip = ("nameserver", "10.0.0.1")

I would perhaps have written it as

if line.startswith("nameserver"):
    ip = line.split()[1]

instead.  Also, the use of _ as the "throw-away" variable name is
perhaps a bit unfortunate, considering that the interactive
interpreter uses _ to save the result of the last expression:

>>> 3 * 15
45
>>> _
45

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE9G2GKdNeA1787sd0RAuWnAJwPquq8/L1foCQtIN0gu3UFtoDv0wCfSxob
0FyuwO0h+XjSJrHoNvMQpbo=
=ow3b
-----END PGP SIGNATURE-----



From flaxeater@yahoo.com  Thu Jun 27 21:54:49 2002
From: flaxeater@yahoo.com (Chad Crabtree)
Date: Thu, 27 Jun 2002 13:54:49 -0700 (PDT)
Subject: [Tutor] Curses for Windows
In-Reply-To: <20020627160004.29420.4496.Mailman@mail.python.org>
Message-ID: <20020627205449.86909.qmail@web11607.mail.yahoo.com>

I have found a curses library for Win32 0s/2 and
others I believe including OS/X it is called
PDCurses for PublicDomainCurses I found it on
sourceforge. just look it up.  However I'm not sure if
it's compatible with ncurses which makes me wonder if
it'll work with the exsisting curses.py module.  I
have thought of writing a module for this however I do
not know any C.  Maybe in the future.

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



From glingl@aon.at  Thu Jun 27 23:24:39 2002
From: glingl@aon.at (Gregor Lingl)
Date: Fri, 28 Jun 2002 00:24:39 +0200
Subject: [Tutor] Question concerning VPython
Message-ID: <000f01c21e29$6dc9f680$1615a8c0@mega>

This is a multi-part message in MIME format.

------=_NextPart_000_000C_01C21E3A.30EF70D0
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi!
I'm just beginning to play around a little=20
with VPython. So I even don't know if the following=20
question is appropriate.

In VPython

>>> sphere()

creates a display-object and a sphere-object

but sphere() doesn't seem to be a constructor,
but rather:

>>> sphere
<built-in method sphere of tuple object at 0x0127C190>

Moreover:

>>> sphere()
<Primitive object at 0x01D830F4>

Should I conclude, that VPython is object-oriented only in a=20
rather weak sense, in so far as it is impossible to=20
subclass spheres, cylinders etc. (i. e.  to derive new
classes from these, which inherit their attributes ...)

And what does <Primitive object ...> exactly mean?
Is this like the built in classes before Python2.2?

Shortly I'd like to know how to write VPython programs
using as far as possible its OO capabilities.

Thanks

Gregor




------=_NextPart_000_000C_01C21E3A.30EF70D0
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 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi!</FONT></DIV>
<DIV><FONT size=3D2>I'm just beginning to play around a little =
</FONT></DIV>
<DIV><FONT size=3D2>with VPython. So I even don't know if the following=20
</FONT></DIV>
<DIV><FONT size=3D2>question is appropriate.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>In VPython</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; sphere()</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>creates a display-object and a =
sphere-object</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>but sphere() doesn't seem to be a =
constructor,</FONT></DIV>
<DIV><FONT size=3D2>but rather</FONT><FONT size=3D2>:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; sphere<BR>&lt;built-in method sphere of =
tuple=20
object at 0x0127C190&gt;<BR></FONT></DIV>
<DIV><FONT size=3D2>Moreover:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; sphere()<BR>&lt;Primitive object at=20
0x01D830F4&gt;<BR></FONT></DIV>
<DIV><FONT size=3D2>Should I conclude, that VPython is object-oriented =
only in a=20
</FONT></DIV>
<DIV><FONT size=3D2>rather weak sense, in so far as it is impossible to=20
</FONT></DIV>
<DIV><FONT size=3D2>subclass spheres, cylinders etc. (i. e.&nbsp; to =
derive=20
new</FONT></DIV>
<DIV><FONT size=3D2>classes from these, which inherit their attributes=20
...)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>And what does &lt;Primitive object ...&gt; exactly=20
mean?</FONT></DIV>
<DIV><FONT size=3D2>Is this like the built in classes before=20
Python2.2?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Shortly I'd like to know how to write VPython=20
programs</FONT></DIV>
<DIV><FONT size=3D2>using as far as possible its OO =
capabilities.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Thanks</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Gregor</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_000C_01C21E3A.30EF70D0--




From HaakJ@masirv.com  Thu Jun 27 23:45:26 2002
From: HaakJ@masirv.com (Jim Haak)
Date: Thu, 27 Jun 2002 15:45:26 -0700
Subject: [Tutor] Decoding email attahments
Message-ID: <9C9781ADDB73C549BC4D8E837BF8450E08C636@mail-socal01>

Trying to extract attachments from E-mail.  
Appended below are my code and its output.
I can't get email to consistently give me just the attached file.
As shown, if the message is multipart or has a mime version in the header,
then I get the payload.  But if the message is not multipart and has no mime
version, then the payload has some header info which prevents me from
decoding it.  I can't figure out how to get rid of this header info (using
email tools). 
Adding to my confusion, I tried to parse the same messages with mimetools.
But, as shown, the mimetools output for every message is the same and of no
use. 
The 'HAS MIME VERSION' test below is probably not the best way to detect
those nasty X-mailer headers, but it seems to work. Some E-mail with the
X-mailer headers have almost no header information.    
The 'FUNKY PAYLOAD' test doesn't work. I was trying to identify payload that
is actually a file attachment. MSG 4 trapped the funky payload, but MSG 3
failed to do so.

Thanks in advance.

Jim


-----------------  C O D E   ---------------------
import poplib, email, cStringIO, mimetools
inbox = poplib.POP3(mailservername)
inbox.user(username)
inbox.pass_(mypassword)
for message_number in range(1, 5):#len(inbox.list()[1])+1):
    lines = inbox.retr(message_number)[1] 
    fakefile = cStringIO.StringIO( '\n'.join(lines) )  
    message = email.message_from_file(fakefile)
    if message.is_multipart():
        payload = message.get_payload()
        for part in payload:
            part_payload = part.get_payload()
            if part_payload[1] <> '\n':
                print "\nMSG NUMBER", message_number,"IS MULTIPART.
PAYLOAD[:100] OF PART", payload.index(part), "IS:", part_payload[:100]
            else:
                print "\nMSG NUMBER", message_number,"IS MULTIPART.  FUNKY
PAYLOAD[:100] OF PART", payload.index(part), "IS:", part_payload[:100]
    else:
        if ('MIME-Version', '1.0') not in message.items():
            payload = message.get_payload()
            print "\nMSG NUMBER", message_number,"HAS NO MIME VESION.
PAYLOAD[:100] IS:", payload[:100]
            print "\n"
            print type(payload)
        else:
            payload = message.get_payload()
            print "\nMSG NUMBER", message_number,"IS NOT MULTIPART BUT HAS
MIME VESION.  PAYLOAD[:100] IS:", payload[:100]

    msg = mimetools.Message(fakefile)
    print "\nMIMETOOLS:", msg.gettype(), msg.getplist(), msg.getencoding()

-----------------  O U T P U T   ---------------------

MSG NUMBER 1 IS NOT MULTIPART BUT HAS MIME VESION.  PAYLOAD[:100] IS:
UEsDBBQAAAAIANeZqSyQc8wMsAEAAHgJAAAJAAwAQ08wNjUuYTAxVVgIABYt2zwWLds8rZbBbsIw
DIbvSLyDJbQzthM7CadJ2yP

MIMETOOLS: text/plain [] 7bit

MSG NUMBER 2 HAS NO MIME VESION.  PAYLOAD[:100] IS: See attached file





begin 600 AA066.ZIP
M4$L#!!0````(`'V<J2P%"32V;0(``"T0```)``P`04$P-C8N83`Q55@(


<type 'str'>

MIMETOOLS: text/plain [] 7bit

MSG NUMBER 3 IS MULTIPART.  PAYLOAD[:100] OF PART 0 IS:   
 
 9V-SMV.ZIP



MSG NUMBER 3 IS MULTIPART.  PAYLOAD[:100] OF PART 1 IS:
UEsDBBQAAAAIAHkmqiwcT6ZaqgkAAKZEAAAKAAwAOVYtU01WLmEwMVVYCABWtNs8VrTbPL1cy47l
thHdG/A/CDC8NossvmYVIPm

MIMETOOLS: text/plain [] 7bit

MSG NUMBER 4 IS MULTIPART.  FUNKY PAYLOAD[:100] OF PART 0 IS:  



MSG NUMBER 4 IS MULTIPART.  PAYLOAD[:100] OF PART 1 IS:
UEsDBBQAAAAIAJ00qixzU4bXUQMAANsYAAAJAAwAQ08wNjUuYTAxVVgIAPrM2zz6zNs8rZjNihsx
DIDvgbyDYel5LVmS7ZwK7SP

MIMETOOLS: text/plain [] 7bit



From urnerk@qwest.net  Fri Jun 28 00:24:49 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 27 Jun 2002 16:24:49 -0700
Subject: [Tutor] Question concerning VPython
In-Reply-To: <000f01c21e29$6dc9f680$1615a8c0@mega>
Message-ID: <5.1.1.6.0.20020627161919.02694070@urnerk/pop.ptld.qwest.net>

>
>Should I conclude, that VPython is object-oriented only in a
>rather weak sense, in so far as it is impossible to
>subclass spheres, cylinders etc. (i. e.  to derive new
>classes from these, which inherit their attributes ...)
>

I'm pretty sure this is right.  VPython is mostly a C++ project
and wraps libraries which interface to OpenGL.  Its primitives
are not subclassable.

>And what does <Primitive object ...> exactly mean?
>Is this like the built in classes before Python2.2?
>
>Shortly I'd like to know how to write VPython programs
>using as far as possible its OO capabilities.
>
>Thanks
>
>Gregor

I recommend you download and study Arthur Siegel's PyGeo,
a sophisticated projective geometry application built on VPython.
You could learn quite a bit from eyeballing his source code I
should think.

See:  http://pw1.netcom.com/~ajs/

Kirby





From urnerk@qwest.net  Fri Jun 28 00:32:37 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 27 Jun 2002 16:32:37 -0700
Subject: [Tutor] Cant get "print "hello world"" to work
In-Reply-To: <F130ad2VqKwRPQIWDO30000192f@hotmail.com>
Message-ID: <5.1.1.6.0.20020627162836.026ba020@urnerk/pop.ptld.qwest.net>

At 04:02 PM 6/27/2002 +0000, Dont Know Tell Me Plz wrote:
>Whenever i try to run anything it always tells me...
>        File "C:\Python22\hello.py", line 3
>              hello world
>                             ^
>It always points at the 1 of the last numbers digits or " 's
>
>Plz Help Me

You should post the source code -- what code are you trying to run?

The one liner:

print "Hello world"

should work if you put hello.py in your python22 subdirectory and go:

  c:\python22:> python hello.py

at the DOS prompt.

Why do you have 3 lines?

Kirby





From urnerk@qwest.net  Fri Jun 28 00:32:37 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 27 Jun 2002 16:32:37 -0700
Subject: [Tutor] Cant get "print "hello world"" to work
In-Reply-To: <F130ad2VqKwRPQIWDO30000192f@hotmail.com>
Message-ID: <5.1.1.6.0.20020627162836.026ba020@urnerk/pop.ptld.qwest.net>

At 04:02 PM 6/27/2002 +0000, Dont Know Tell Me Plz wrote:
>Whenever i try to run anything it always tells me...
>        File "C:\Python22\hello.py", line 3
>              hello world
>                             ^
>It always points at the 1 of the last numbers digits or " 's
>
>Plz Help Me

You should post the source code -- what code are you trying to run?

The one liner:

print "Hello world"

should work if you put hello.py in your python22 subdirectory and go:

  c:\python22:> python hello.py

at the DOS prompt.

Why do you have 3 lines?

Kirby





From whisper@oz.net  Thu Jun 27 08:12:43 2002
From: whisper@oz.net (David LeBlanc)
Date: Thu, 27 Jun 2002 00:12:43 -0700
Subject: [Tutor] RE: How to find out operating system
In-Reply-To: <3D1ACBC5.22482.D4313A4@localhost>
Message-ID: <GCEDKONBLEFPPADDJCOECEHEDMAA.whisper@oz.net>

You might try os.environ:

os.environ['WINOS'] -> WIN2000

I don't know if WINOS is defined on '98 or ME, but it should be good for NT,
2K and XP

os.environ.has_key('WINOS') will tell you that. However, MS os's are so
stupid that there must be some env variable to tell themselves what they
are.

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin@python.org
> [mailto:python-list-admin@python.org]On Behalf Of A
> Sent: Wednesday, June 26, 2002 23:25
> To: python-list@python.org; tutor@python.org;
> activepython@listserv.activestate.com; python-help@python.org
> Subject: How to find out operating system
>
>
> Hi,
> What is the best way of  finding out the kind operating system?
> I can use os.name but if the system is Windows I would like also
> know if the system is Windows98 or Windows ME or W2K or
> Windows XP.
> Thanks for help.
> Ladislav
>
>
> _______________________________________________
> ActivePython mailing list
> ActivePython@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> Other options:
> http://listserv.ActiveState.com/mailman/listinfo/ActivePython
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list




From virketis@post.harvard.edu  Thu Jun 27 17:51:17 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Thu, 27 Jun 2002 19:51:17 +0300
Subject: [Tutor] drag-and-drop argument passing
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6BA@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <ISPFE8liW9ueBp7rZeB000083f5@mail.takas.lt>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Alan,<br></div>
<div><br>
<FONT COLOR=3D"#000080">&gt;OK, Just do it. It should just=
 work.</FONT><br></div>
<div><FONT COLOR=3D"#000080">&gt;</FONT><br></div>
<div><FONT COLOR=3D"#000080">&gt;Windows passes dragged files in as=
 command line args.</FONT><br>
<FONT COLOR=3D"#000080">&gt;I'm not so sure about multiple files=
 tho' but try a</FONT><br>
<FONT COLOR=3D"#000080">&gt;single file to see if that works=
 first.</FONT><br></div>
<div><FONT COLOR=3D"#000080"><br>
</FONT>I did try to do it before wailing for help, and I just=
 can't ... I am using Windows XP, and I am just not allowed to=
 drop anything onto .py files. I even set the PATHEXT so that .py=
 files are recognised as executable, but that did no good.=
 <br></div>
<div>&nbsp;</div>
<div>&gt;Get it to log sys.args and see what Windows passes=
 <br></div>
<div>&gt;to it...<br></div>
<div>&nbsp;</div>
<div>Funny, I had a script just like that ready. :) Something's=
 keeping me from using it, though. Perhaps it's something=
 specific to XP? How else can I tell the system .py files are=
 executable besides setting PATHEXT? I looked at file properties,=
 but I see no equivalent to the Unix &quot;execute&quot;=
 tag.<br>
<br>
<br>
<br></div>
<div>-- <br></div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann<br></div>
</body></html>




From miracle@paradise.net.nz  Thu Jun 27 21:50:16 2002
From: miracle@paradise.net.nz (Matthew Sherborne)
Date: Fri, 28 Jun 2002 08:50:16 +1200
Subject: [Tutor] Re: How to find out DNS ?
References: <3D1B6186.3142.295959@localhost>
Message-ID: <3D1B7A88.7030705@paradise.net.nz>

A wrote:

>Hi,
>Is there a way how to find out, from Python , what primary or 
>secondary DNS I use when connecting to internet?
>Thanks for help
>Ladislav
>
>_______________________________________________
>ActivePython mailing list
>ActivePython@listserv.ActiveState.com
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
>
>
>
>  
>
    def getServersFromOS(self):
        if sys.platform in ('win32', 'nt'): return 
self.getServersFromWin32()
        elif sys.platform == 'posix': return self.getServersFromPosix()
        else: return []
       
    def getServersFromWin32(self):
        import _winreg
        servers = []
        x = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
        try:
            y = _winreg.OpenKey(x, 
r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters')
        except EnvironmentError: # so it isn't NT/2000/XP
            # windows ME, perhaps?
            try: # for Windows ME
                y = _winreg.OpenKey(x, 
r'SYSTEM\CurrentControlSet\Services\VxD\MSTCP')
            nameserver = _winreg.QueryValueEx(y, 'NameServer')[0]
            if nameserver and not (nameserver in servers):
                servers += nameserver.split(',')
        except EnvironmentError: pass
        return servers

    def getServersFromPosix(self):
        """"Parses the /etc/resolv.conf file and sets defaults for name 
servers""""
        lines = open('/etc/resolv.conf').readlines()
        servers = []
        for line in lines:
            line = line.strip()
            if not line or line[0] == ';' or line[0] == '#': continue
            fields=string.split(line)
            if fields[0] == 'domain': defaults['domain'] = fields[1]
            elif fields[0] == 'search': pass
            elif fields[0] == 'options': pass
            elif fields[0] == 'sortlist': pass
            elif fields[0] == 'nameserver': servers.append(fields[1])
        return servers

GBU
Matthew Sherborne






From dyoo@hkn.eecs.berkeley.edu  Fri Jun 28 04:50:50 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 27 Jun 2002 20:50:50 -0700 (PDT)
Subject: [Tutor] pair programming.
In-Reply-To: <20020626223437.GA28191@ak.silmarill.org>
Message-ID: <Pine.LNX.4.44.0206272049120.22550-100000@hkn.eecs.berkeley.edu>


On Wed, 26 Jun 2002, Andrei Kulakov wrote:

> Hello pythoneers,
>
> Does anyone wanna try pair programming over the net, using screen and
> irc, with me? I never tried that, but it sounds interesting.

Hi Andrei,

This sounds interesting!  Can 'screen' be used collaboratively?  I'm not
familiar enough with it yet.

Will this pair programming be for Cymbaline then?


Talk to you later!




From ak@silmarill.org  Fri Jun 28 05:26:28 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Fri, 28 Jun 2002 00:26:28 -0400
Subject: [Tutor] pair programming.
In-Reply-To: <Pine.LNX.4.44.0206272049120.22550-100000@hkn.eecs.berkeley.edu>
References: <20020626223437.GA28191@ak.silmarill.org> <Pine.LNX.4.44.0206272049120.22550-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020628042628.GA9506@ak.silmarill.org>

On Thu, Jun 27, 2002 at 08:50:50PM -0700, Danny Yoo wrote:
> 
> 
> On Wed, 26 Jun 2002, Andrei Kulakov wrote:
> 
> > Hello pythoneers,
> >
> > Does anyone wanna try pair programming over the net, using screen and
> > irc, with me? I never tried that, but it sounds interesting.
> 
> Hi Andrei,
> 
> This sounds interesting!  Can 'screen' be used collaboratively?  I'm not
> familiar enough with it yet.
>
Yeah, you can easily try it out to see how it works.. start two xterms,
type "screen" in one, type screen -x in the other. Now try using both
terminals. Voila!

> 
> Will this pair programming be for Cymbaline then?
>
Any of my projects (silmarill.org/projects.shtml) or yours or something
new alltogether. I'm open to suggestions :-).

I have a few ideas I've been thinking about but without code yet:
1. ViWM. A window manager with two modes, like vi: command mode and
   entry. In command mode you use hjkl, etc to switch windows,
workspaces, resize, start programs; to use the current window you hit
'i', to get back to command mode you hit ctrl-O (for cOmmand).

2. nethack-like fully python game. Curses or, even better, pygame.

3. an integrated email/newsreader, like mutt and slrn.

4. an irc client, like xchat, but 100% python.

5. "python for non-programmers" story for kuro5hin. 

A lot of other stuff I don't remember right now..

 - Andrei
> 
> 
> Talk to you later!
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From shalehperry@attbi.com  Fri Jun 28 06:47:56 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 27 Jun 2002 22:47:56 -0700 (PDT)
Subject: [Tutor] pair programming.
In-Reply-To: <20020628042628.GA9506@ak.silmarill.org>
Message-ID: <XFMail.20020627224756.shalehperry@attbi.com>

>> 
>> Will this pair programming be for Cymbaline then?
>>
> Any of my projects (silmarill.org/projects.shtml) or yours or something
> new alltogether. I'm open to suggestions :-).
> 
> I have a few ideas I've been thinking about but without code yet:
> 1. ViWM. A window manager with two modes, like vi: command mode and
>    entry. In command mode you use hjkl, etc to switch windows,
> workspaces, resize, start programs; to use the current window you hit
> 'i', to get back to command mode you hit ctrl-O (for cOmmand).
> 

one of the blackbox authors here ...

Intriguing idea.  One of the issues with vi traditionally has been the user
loses track of which mode they are in.  Combating this for a wm would be
interesting.

> 2. nethack-like fully python game. Curses or, even better, pygame.
> 

have heard good things about pygame .....

> 3. an integrated email/newsreader, like mutt and slrn.
> 

my big wish would be a mailer that allows gui access but still lets people have
a console as well.  I have really been spoiled by gui mailer's ability to show
me all of my folders at once (I have 30+) and let me know where new mail is
waiting.

> 4. an irc client, like xchat, but 100% python.
> 

interesting, you need to choose whether to go 100% irc or also support all of
the IM clients of the world

> 5. "python for non-programmers" story for kuro5hin. 
> 

not sure about non-programmers but a python for VB or BASIC would be
interesting.  Especially now that 2.2 has properties and what not.



From jgregorio@ultrasw.com  Fri Jun 28 07:28:27 2002
From: jgregorio@ultrasw.com (Josh Gregorio)
Date: Thu, 27 Jun 2002 23:28:27 -0700
Subject: [Tutor] drag-and-drop argument passing
References: <ISPFE8liW9ueBp7rZeB000083f5@mail.takas.lt>
Message-ID: <002e01c21e6d$04715540$90f1b542@computer>

This is a multi-part message in MIME format.

------=_NextPart_000_002B_01C21E32.5716B820
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

In windows, I don't think you can make scripts executable. You can set =
up a file association so that .py files are opened (ran) by python.exe =
(if you double click on a .py file and it opens a dos box, this is =
already setup--the installer sets it up for you). But when you drag and =
drop a file as an argument, windows doesn't know to run "python.exe =
script.py argument".  So it just sits there.=20

On both my machines, drag and drop only works with files that run =
themselves (exe, com, etc).=20

I used the py2exe tool to make an exe for my python scripts, and then I =
could drag and drop arguments. See http://py2exe.sourceforge.net/ It is =
really easy to use, and very cool=20

Josh

----- Original Message -----=20
  From: Pijus Virketis=20
  To: alan.gauld@bt.com=20
  Cc: Tutor=20
  Sent: Thursday, June 27, 2002 9:51 AM
  Subject: RE: [Tutor] drag-and-drop argument passing


  Alan,


  >OK, Just do it. It should just work.

  >

  >Windows passes dragged files in as command line args.
  >I'm not so sure about multiple files tho' but try a
  >single file to see if that works first.


  I did try to do it before wailing for help, and I just can't ... I am =
using Windows XP, and I am just not allowed to drop anything onto .py =
files. I even set the PATHEXT so that .py files are recognised as =
executable, but that did no good.=20


  >Get it to log sys.args and see what Windows passes=20

  >to it...


  Funny, I had a script just like that ready. :) Something's keeping me =
from using it, though. Perhaps it's something specific to XP? How else =
can I tell the system .py files are executable besides setting PATHEXT? =
I looked at file properties, but I see no equivalent to the Unix =
"execute" tag.




  --=20

  "Anyone attempting to generate random numbers by deterministic means =
is, of course, living in a state of sin." -- John Von Neumann

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

------=_NextPart_000_002B_01C21E32.5716B820
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><BASEFONT=20
color=3D#000000 face=3DArial size=3D2>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>In windows, I don't think you can make scripts =
executable. You=20
can set up a file association so that .py files are opened (ran) by =
python.exe=20
(if you double click on a .py file and it opens a dos box, this is =
already=20
setup--the installer sets it up for you). But when you drag and drop a =
file as=20
an argument, windows doesn't know to run "python.exe script.py =
argument".&nbsp;=20
So it just sits there. </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>On both my machines, drag and drop only works with files that run=20
themselves (exe, com, etc). </DIV>
<DIV>&nbsp;</DIV>
<DIV>I used the py2exe tool to make an exe for my python scripts, and =
then I=20
could drag and drop arguments. See <A=20
href=3D"http://py2exe.sourceforge.net/">http://py2exe.sourceforge.net/</A=
>&nbsp;It=20
is really easy to use, and very cool </DIV>
<DIV>&nbsp;</DIV>
<DIV>Josh</DIV>
<DIV>&nbsp;</DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:pijus@virketis.com" title=3Dpijus@virketis.com>Pijus =

  Virketis</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:alan.gauld@bt.com"=20
  title=3Dalan.gauld@bt.com>alan.gauld@bt.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A =
href=3D"mailto:tutor@python.org"=20
  title=3Dtutor@python.org>Tutor</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Thursday, June 27, 2002 =
9:51=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] =
drag-and-drop=20
  argument passing</DIV>
  <DIV><BR></DIV>
  <DIV>Alan,<BR></DIV>
  <DIV><BR><FONT color=3D#000080>&gt;OK, Just do it. It should just=20
  work.</FONT><BR></DIV>
  <DIV><FONT color=3D#000080>&gt;</FONT><BR></DIV>
  <DIV><FONT color=3D#000080>&gt;Windows passes dragged files in as =
command line=20
  args.</FONT><BR><FONT color=3D#000080>&gt;I'm not so sure about =
multiple files=20
  tho' but try a</FONT><BR><FONT color=3D#000080>&gt;single file to see =
if that=20
  works first.</FONT><BR></DIV>
  <DIV><FONT color=3D#000080><BR></FONT>I did try to do it before =
wailing for=20
  help, and I just can't ... I am using Windows XP, and I am just not =
allowed to=20
  drop anything onto .py files. I even set the PATHEXT so that .py files =
are=20
  recognised as executable, but that did no good. <BR></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&gt;Get it to log sys.args and see what Windows passes <BR></DIV>
  <DIV>&gt;to it...<BR></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Funny, I had a script just like that ready. :) Something's =
keeping me=20
  from using it, though. Perhaps it's something specific to XP? How else =
can I=20
  tell the system .py files are executable besides setting PATHEXT? I =
looked at=20
  file properties, but I see no equivalent to the Unix "execute"=20
  tag.<BR><BR><BR><BR></DIV>
  <DIV>-- <BR></DIV>
  <DIV>"Anyone attempting to generate random numbers by deterministic =
means is,=20
  of course, living in a state of sin." -- John Von=20
  Neumann<BR></DIV>_______________________________________________ Tutor =

  maillist - Tutor@python.org=20
http://mail.python.org/mailman/listinfo/tutor</BLOCKQUOTE></BODY></BASEFO=
NT></HTML>

------=_NextPart_000_002B_01C21E32.5716B820--




From ak@silmarill.org  Fri Jun 28 07:25:34 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Fri, 28 Jun 2002 02:25:34 -0400
Subject: [Tutor] pair programming.
In-Reply-To: <XFMail.20020627224756.shalehperry@attbi.com>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com>
Message-ID: <20020628062534.GA10890@ak.silmarill.org>

On Thu, Jun 27, 2002 at 10:47:56PM -0700, Sean 'Shaleh' Perry wrote:
> >> 
> >> Will this pair programming be for Cymbaline then?
> >>
> > Any of my projects (silmarill.org/projects.shtml) or yours or something
> > new alltogether. I'm open to suggestions :-).
> > 
> > I have a few ideas I've been thinking about but without code yet:
> > 1. ViWM. A window manager with two modes, like vi: command mode and
> >    entry. In command mode you use hjkl, etc to switch windows,
> > workspaces, resize, start programs; to use the current window you hit
> > 'i', to get back to command mode you hit ctrl-O (for cOmmand).
> > 
> 
> one of the blackbox authors here ...
> 
> Intriguing idea.  One of the issues with vi traditionally has been the user
> loses track of which mode they are in.  Combating this for a wm would be
> interesting.
>
I never understood why don't vi or vim have a colored or a highlighted
bar on top or bottom that toggle between command/entry mode. In ViWM,
there'd be a color cue. There'd be a bar somewhere that'd change colors
between blue and red or something and it could be used for something
else, too, like maybe windows-type bar? Or Wmaker dock?

> 
> > 2. nethack-like fully python game. Curses or, even better, pygame.
> > 
> 
> have heard good things about pygame .....
> 
> > 3. an integrated email/newsreader, like mutt and slrn.
> > 
> 
> my big wish would be a mailer that allows gui access but still lets people have
> a console as well.  I have really been spoiled by gui mailer's ability to show
> me all of my folders at once (I have 30+) and let me know where new mail is
> waiting.
> 
Well, I think there should be a basic working useful app that other
people would come in and extend for their needs..

> > 4. an irc client, like xchat, but 100% python.
> > 
> 
> interesting, you need to choose whether to go 100% irc or also support all of
> the IM clients of the world

Same as my comment for (3).

> 
> > 5. "python for non-programmers" story for kuro5hin. 
> > 
> 
> not sure about non-programmers but a python for VB or BASIC would be
> interesting.  Especially now that 2.2 has properties and what not.
>
I meant a k5 discussion forum story that introduces non-programmers to
the python language, with a short tutorial.. I've been working on one
for a while but I always stop in the middle and then begin rewriting it
again in a few days or weeks..

> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From gjlee@seri.co.uk  Fri Jun 28 09:15:36 2002
From: gjlee@seri.co.uk (Geonjae Lee)
Date: Fri, 28 Jun 2002 09:15:36 +0100
Subject: [Tutor] question about OOP (or just grammer thing) ?
Message-ID: <341710540F08E34498A057DEE04DAAD71295AB@ex1.seri.co.uk>

Hi I'm a python newbie.
I'm studying Tkinter.
And All I know about programming language was C.
That means I'm also not used to the OOP concept.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

from Tkinter import *

class HelloButton(Button):
    def __init__(self, parent=3DNone, **config):
        Button.__init__(self, parent, config)
        self.pack()
        self.config(command=3Dself.callback)

    def callback(self):
        print 'Goodbye world...'
        self.quit()

if __name__ =3D=3D '__main__':
    HelloButton(text=3D'Hello subclass world').mainloop()

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

I'm reading Programming Python 2nd edition published by O'reilly and
also struggle to understand concept of class.=20

1. In the above example, variable named 'config' is used in 3 places.=20
Are they all same or different?

2. I guess they're not all same.=20
    def __init__(self, parent=3DNone, **config):
        Button.__init__(self, parent, config)

I guess variable config in above 2 lines are same one.
If then, why '**config' is used in __init__ method ?=20
And I tried to use just 'config' instead of '**config', but that caused
a error.


Thanks in advance.
ThomasLee (KJ Lee)









From abli@freemail.hu  Fri Jun 28 12:04:56 2002
From: abli@freemail.hu (Abel Daniel)
Date: Fri, 28 Jun 2002 13:04:56 +0200
Subject: [Tutor] pair programming.
In-Reply-To: <20020628062534.GA10890@ak.silmarill.org>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org>
Message-ID: <20020628110456.GB648@hooloovoo>

On Fri, Jun 28, 2002 at 02:25:34AM -0400 Andrei Kulakov (ak@silmarill.org) wrote
> I never understood why don't vi or vim have a colored or a highlighted
> bar on top or bottom that toggle between command/entry mode. In ViWM,
> there'd be a color cue. There'd be a bar somewhere that'd change colors
> between blue and red or something and it could be used for something
> else, too, like maybe windows-type bar? Or Wmaker dock?
I use vim and in the last line it shows stuff like "-- INSERT --" or
"-- VISUAL BLOCK -- " for different modes. (The default mode, ex-mode if
i am right is indicated by an empty line.) I think
set nocompatible
and/or
set showmode
will turn it on

abli
abli@freemail.hu



From alan.gauld@bt.com  Fri Jun 28 14:03:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 28 Jun 2002 14:03:01 +0100
Subject: [Tutor] drag-and-drop argument passing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6BB@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C21EA4.22412640
Content-type: text/plain; charset="iso-8859-1"

> >  Windows passes dragged files in as command line args.
> >  I'm not so sure about multiple files tho' but try a
> >  single file to see if that works first.
>  I did try to do it before wailing for help, and I just can't ...  
 
OK, Time to 'fess up... I've only done this with a Delphi app 
which of course produces exes.
 
>  I am using Windows XP, and I am just not allowed to drop anything onto
.py files.  
 
Yes, the .py file is the command line argument to Python.
The file association says run python with this sript as 
argument. What you need to do is somehow tell Windows 
to run python taking this script plus whatever I dropped 
as arguments, hmmm...
 
I just checked and the association is:
 
D:\Python20\python.exe "%1" %*
 
So the other args should pass thru'... strange.
 
 >  properties, but I see no equivalent to the Unix "execute" tag.

Its all in the file association stuff I think not the 
security settings... 

Now I'm interested, I'll need to do some digging. 
Hopefully somebody else meantime knows the answer! 
 
Not as easy as I thought.
 
Alan G.

------_=_NextPart_001_01C21EA4.22412640
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT color=#000080>&gt;<SPAN class=410153612-28062002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>Windows 
passes dragged files in as command line args.</FONT><BR><FONT 
color=#000080>&gt;<SPAN class=410153612-28062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>I'm not so sure about 
multiple files tho' but try a</FONT><BR><FONT color=#000080>&gt;<SPAN 
class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>single file to see if that works 
first.</FONT><BR><SPAN class=410153612-28062002><FONT face="Courier New" 
color=#0000ff size=2><FONT face="Times New Roman" color=#000080 size=3>&gt; 
</FONT>&nbsp;</FONT></SPAN>I did try to do it before wailing for help, and I 
just can't ...&nbsp;<SPAN class=410153612-28062002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>OK, Time to 'fess up... I've only done this with a Delphi app 
</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>which of course produces exes.</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002>&gt; &nbsp;</SPAN>I am using Windows XP, and 
I am just not allowed to drop anything onto .py files.&nbsp;<SPAN 
class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>Yes, the .py file is the command line argument to 
Python.</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>The file association says run python&nbsp;with this sript as 
</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>argument. What you need to do is somehow tell Windows 
</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>to run python taking this script plus whatever I dropped 
</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>as arguments, hmmm...</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>I just checked and the association is:</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>D:\Python20\python.exe "%1" %*</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>So the other args should pass thru'... strange.</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>properties, but I see no equivalent to the 
Unix "execute" tag.<BR><BR><SPAN class=410153612-28062002><FONT 
face="Courier New" color=#0000ff size=2>Its all in the file association stuff I 
think not the </FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>security settings...&nbsp;</FONT></SPAN><BR><BR><SPAN 
class=410153612-28062002><FONT face="Courier New" color=#0000ff size=2>Now I'm 
interested, I'll need to do some digging. </FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>Hopefully somebody else meantime knows the 
answer!&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>Not as easy as I thought.</FONT></SPAN></DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=410153612-28062002><FONT face="Courier New" color=#0000ff 
size=2>Alan G.</FONT></SPAN></DIV></BODY></HTML>

------_=_NextPart_001_01C21EA4.22412640--



From pythontutor@venix.com  Fri Jun 28 14:20:12 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Fri, 28 Jun 2002 09:20:12 -0400
Subject: [Tutor] question about OOP (or just grammer thing) ?
References: <341710540F08E34498A057DEE04DAAD71295AB@ex1.seri.co.uk>
Message-ID: <3D1C628C.1090608@venix.com>

def myfunc( **kwargs)
is the python syntax (grammar) for collecting all of the key word arguments.

myfunc(len=1,width=3,units='cm') specifies three keyword (labeled) arguments.

The actual function will receive those arguments as a dictionary with the
name kwargs.  The ** signals python to collect the keyword arguments into a
dictionary.

I can't say much about the Tkinter processing specifics, but you can see that this
provides a convenient mechanism for packaging long "lists" of arguments.

Geonjae Lee wrote:

> Hi I'm a python newbie.
> I'm studying Tkinter.
> And All I know about programming language was C.
> That means I'm also not used to the OOP concept.
> 
> ==================================================================
> 
> from Tkinter import *
> 
> class HelloButton(Button):
>     def __init__(self, parent=None, **config):
>         Button.__init__(self, parent, config)
>         self.pack()
>         self.config(command=self.callback)
> 
>     def callback(self):
>         print 'Goodbye world...'
>         self.quit()
> 
> if __name__ == '__main__':
>     HelloButton(text='Hello subclass world').mainloop()
> 
> ===================================================================
> 
> I'm reading Programming Python 2nd edition published by O'reilly and
> also struggle to understand concept of class. 
> 
> 1. In the above example, variable named 'config' is used in 3 places. 
> Are they all same or different?
> 
> 2. I guess they're not all same. 
>     def __init__(self, parent=None, **config):
>         Button.__init__(self, parent, config)
> 
> I guess variable config in above 2 lines are same one.
> If then, why '**config' is used in __init__ method ? 
> And I tried to use just 'config' instead of '**config', but that caused
> a error.
> 
> 
> Thanks in advance.
> ThomasLee (KJ Lee)
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582




From alan.gauld@bt.com  Fri Jun 28 14:49:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 28 Jun 2002 14:49:31 +0100
Subject: [Tutor] pair programming.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6BC@mbtlipnt02.btlabs.bt.co.uk>

> I never understood why don't vi or vim have a colored or a highlighted
> bar on top or bottom that toggle between command/entry mode. 

Because vi was written in the days when you only had 24 (green and black, 
fixed font) lines on your console and every one was precious! If you 
have room to spare you can switch on 'show mode' which displays when 
you are in an 'insertion' mode on the bottom line.

This waste of space was one of the old arguments vi users used to 
bash emacs - it wasted 2 lines, one for the info display line and 
one for the command line - scandalous!

Alan g.
(who is just about old enough to remember...)



From alan.gauld@bt.com  Fri Jun 28 14:58:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 28 Jun 2002 14:58:02 +0100
Subject: [Tutor] question about OOP (or just grammer thing) ?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6BD@mbtlipnt02.btlabs.bt.co.uk>

> And All I know about programming language was C.
> That means I'm also not used to the OOP concept.

OK, You might like to have a quck look at my OOP page 
in my tutor....

> class HelloButton(Button):
>     def __init__(self, parent=None, **config):
>         Button.__init__(self, parent, config)
>         self.pack()
>         self.config(command=self.callback)

> 1. In the above example, variable named 'config' is used in 3 places. 
> Are they all same or different?

The nmame config is used 3 times.

The first is to specify a parameter to the init method. 
The ** bit means it can actually be multiple arguments which will 
all be treated as one by init.

The second is the use of that same config parameter being passed 
to the Button's init method. If multiple args are passed in to 
your init they will all be passed as part of config to Button.init

The 3rd is a method call to the inherited config method of Button.
config as a method takes keyword style argument ansd sets the 
value within its class. Thus in this case you asre setting the 
command property ogf your Button to be the callback method.

> 
> 2. I guess they're not all same. 

One and Two are virtually the same, the third is entirely different.


>     def __init__(self, parent=None, **config):
>         Button.__init__(self, parent, config)
> I guess variable config in above 2 lines are same one.

Correct
> If then, why '**config' is used in __init__ method ? 

When we call MyButton construvctor like:

b = MyButton(tk, text="Hello", width=45, height=50)

everything after tk gets passed as the config argument.
It treats the 3 arguments as a single argument to init.

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From terjeja@hotmail.com  Fri Jun 28 15:25:54 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Fri, 28 Jun 2002 14:25:54 +0000
Subject: [Tutor] addition
Message-ID: <F4260wcP2dIulddm2ps00000992@hotmail.com>

Hello,

    I have to make a program that compares policies for an accounting 
department. It uses two different systems, AS/400 and Win Excel. I have 
built all the surounding code moving numbers back and forth, formatting and 
so forth, but the main calculations are missing. Here is the problem:

In Excel up to 7 accounts can have the same policynumber, while up to 3 
policies in the AS/400 system can have the same policynumber. Any number of 
policies in either system can match any number of policies in the other 
system. So, therefore for example 5 Excel amounts can add up to the 
approximate amount (+-$5) of 2 AS/400 accounts. If this is the case, these 
amounts should be marked. If I haven't forgotten all my statistics skills, 
that should equal up to (7!=5040 * 3!=6)=30240 calculations. How can I do 
this? There is no way I can use my normal way of doing this (with less 
numbers) by writing in the possibilities, as in if a+b=c:print yes, elif a+c 
= d: print yes and so forth until I have used all the possibilities. I need 
the computer to do this part this time. (I am a beginner, so please keep it 
simple.)

Thanks,
Terje



_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




From shalehperry@attbi.com  Fri Jun 28 15:51:34 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 28 Jun 2002 07:51:34 -0700 (PDT)
Subject: [Tutor] question about OOP (or just grammer thing) ?
In-Reply-To: <341710540F08E34498A057DEE04DAAD71295AB@ex1.seri.co.uk>
Message-ID: <XFMail.20020628075134.shalehperry@attbi.com>

> I'm reading Programming Python 2nd edition published by O'reilly and
> also struggle to understand concept of class. 
> 
> 1. In the above example, variable named 'config' is used in 3 places. 
> Are they all same or different?
> 
> 2. I guess they're not all same. 
>     def __init__(self, parent=None, **config):
>         Button.__init__(self, parent, config)
> 
> I guess variable config in above 2 lines are same one.
> If then, why '**config' is used in __init__ method ? 
> And I tried to use just 'config' instead of '**config', but that caused
> a error.
> 

I wanted to add on to what the others had said.

class MyClass:
    def __init__(var):
        self.var = var

in this example we have two variables named 'var'.  When the interpreter does
its work it sees that 'self.var' is part of 'self' which is an instance of
MyClass whereas 'var' is only in the local scope.



From curtis.larsen@covance.com  Fri Jun 28 16:25:44 2002
From: curtis.larsen@covance.com (Curtis Larsen)
Date: Fri, 28 Jun 2002 10:25:44 -0500
Subject: [Tutor] Python Cookbook?
Message-ID: <sd1c39ce.051@madis2.truax.covance.com>

Last I heard, O'Reilly was planning on releasing the "Python Cookbook"
in June or July.  Is it out yet?  Has anyone heard about a firm release
date?

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 kalle@lysator.liu.se  Fri Jun 28 17:12:30 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Fri, 28 Jun 2002 18:12:30 +0200
Subject: [Tutor] Python Cookbook?
In-Reply-To: <sd1c39ce.051@madis2.truax.covance.com>
References: <sd1c39ce.051@madis2.truax.covance.com>
Message-ID: <20020628161230.GA16188@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Curtis Larsen]
> Last I heard, O'Reilly was planning on releasing the "Python Cookbook"
> in June or July.  Is it out yet?  Has anyone heard about a firm release
> date?

Not very firm, but in the recent interview on the EuroPython website
(http://europython.zope.nl/interviews/entries/alex_martelli) Alex
Martelli says:
"""
(it's at the printers as we chat, and will be launched at O'Reilly's
OSCON, a few days after Europython)
"""

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE9HIrodNeA1787sd0RAoIcAJ9YxmEeQbc0a2j/XoXfVmw1kw6tDACgihCI
HJEB8m3rNDObGORmOevIA3c=
=r72U
-----END PGP SIGNATURE-----



From terjeja@hotmail.com  Fri Jun 28 20:14:19 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Fri, 28 Jun 2002 19:14:19 +0000
Subject: [Tutor] Dictionaries
Message-ID: <F149Wtjik38dWMJ69ik00000c52@hotmail.com>

I have two dictionaries consisting of numbers. Eg (1:2,2:4,3:6) and 
(1:5,2:6,3:9). Then I want to add the entries together in all possible ways, 
to see if the numbers in dictionary 1 equals the numbers in dictionary 2. 
(Eg, here entry 1 & 2 equals entry 2 in dictionary 2. Both equals 6). There 
can be a random number of entries in each dictionary. (However, less than 7 
in each). How can I perform this task? Thanks in advance...



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




From scott@zenplex.com  Fri Jun 28 20:19:07 2002
From: scott@zenplex.com (Scott Comboni)
Date: 28 Jun 2002 15:19:07 -0400
Subject: [Tutor] Progress Bar Help.
Message-ID: <1025291948.3126.7.camel@scott.zenplex.com>

I recently wrote a simple python script to install a bunch of software
apps and would like to jazz it up with some sort of graphical progress
bar.  Is there some URL someone can point me too to get some ideas on
how to code/create something like this?

Thanks All.
Scott

--                
____________________________________________________________




From linuxconsult@yahoo.com.br  Fri Jun 28 21:25:54 2002
From: linuxconsult@yahoo.com.br (=?iso-8859-1?Q?Rog=E9rio?= Brito)
Date: Fri, 28 Jun 2002 17:25:54 -0300
Subject: [Tutor] Dictionaries
In-Reply-To: <F149Wtjik38dWMJ69ik00000c52@hotmail.com>
References: <F149Wtjik38dWMJ69ik00000c52@hotmail.com>
Message-ID: <20020628202554.GA1658@ime.usp.br>

On Jun 28 2002, Terje Johan Abrahamsen wrote:
> I have two dictionaries consisting of numbers. Eg (1:2,2:4,3:6) and 
> (1:5,2:6,3:9). Then I want to add the entries together in all possible 
> ways, to see if the numbers in dictionary 1 equals the numbers in 
> dictionary 2. (Eg, here entry 1 & 2 equals entry 2 in dictionary 2. Both 
> equals 6).

	Humm... This is getting interesting.

	By saying "in all possible ways", do you mean that you want to
	know if, for each key:value pair from the second dictionary,
	there is a subset of key:value pairs from the first dictionary
	such that the sum of values of the pairs from the subset
	equals the value of the key of the given pair from the second
	dictionary?

	In other words, do you want the following (in pseudocode):

	for (k, v) in dict_2.items():
	    for each subset of items from dict_1:
	        if v = sum_of_values(subset):
		   # print item (k, v) is "present" on dict_1
		else:
		   pass

	If this is what you want, then there are bad news for you, as
	this is a very hard (and classic) problem in computer science.
	This problem is called the "Subset Sum" and it is a
	NP-complete problem. This means that nobody knows an efficient
	algorithm to solve it besides "trying everything"
	(essentially).

	In fact, you are looking for many times the "Subset Sum"
	problem (one for each item from dict2).

	So, you will probably have to do an exhaustive search.

	If this is not what you meant, then please rephrase it and we
	can try to help you another way.

	BTW, I am a newbie in Python.


	[]s, Roger...

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rogério Brito - linuxconsult@yahoo.com.br - http://www.ime.usp.br/~rbrito
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



From terjeja@hotmail.com  Fri Jun 28 21:50:55 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Fri, 28 Jun 2002 20:50:55 +0000
Subject: [Tutor] Dictionaries
Message-ID: <F36oiB5ANH2cv0aGltF00000fa1@hotmail.com>



>From: Rogério Brito <linuxconsult@yahoo.com.br>
>To: tutor@python.org
>Subject: Re: [Tutor] Dictionaries
>Date: Fri, 28 Jun 2002 17:25:54 -0300
>
>On Jun 28 2002, Terje Johan Abrahamsen wrote:
> > I have two dictionaries consisting of numbers. Eg (1:2,2:4,3:6) and
> > (1:5,2:6,3:9). Then I want to add the entries together in all possible
> > ways, to see if the numbers in dictionary 1 equals the numbers in
> > dictionary 2. (Eg, here entry 1 & 2 equals entry 2 in dictionary 2. Both
> > equals 6).
>
>	Humm... This is getting interesting.
>
>	By saying "in all possible ways", do you mean that you want to
>	know if, for each key:value pair from the second dictionary,
>	there is a subset of key:value pairs from the first dictionary
>	such that the sum of values of the pairs from the subset
>	equals the value of the key of the given pair from the second
>	dictionary?
>
>	In other words, do you want the following (in pseudocode):
>
>	for (k, v) in dict_2.items():
>	    for each subset of items from dict_1:
>	        if v = sum_of_values(subset):
>		   # print item (k, v) is "present" on dict_1
>		else:
>		   pass
>
>	If this is what you want, then there are bad news for you, as
>	this is a very hard (and classic) problem in computer science.
>	This problem is called the "Subset Sum" and it is a
>	NP-complete problem. This means that nobody knows an efficient
>	algorithm to solve it besides "trying everything"
>	(essentially).
>
>	In fact, you are looking for many times the "Subset Sum"
>	problem (one for each item from dict2).
>
>	So, you will probably have to do an exhaustive search.
>
>	If this is not what you meant, then please rephrase it and we
>	can try to help you another way.
>
>	BTW, I am a newbie in Python.

I think I am even newer in Python than you, so I can't really for sure tell 
if the pseudocode actually is what I want. But, I can explain a little more 
detailed:

dict1 = (1:2,2:4)
dict2 = (1:5,2:6)

Then dict1 can have the following sums:
2,4 and 6
While dict2 can have the following sums:
5,6 and 11

Then I want to find out if some of these sums are common in both 
dictionaries. Here there are a common sum, 6. That equals both entries in 
dict 1 and the second entry in dict2. (In the problem I try to solve, dict1 
can, but does not have to have up to 3 entries, while dict2 can but does not 
have to have up to 7 entries. Dict1 I can calculate manualy which I have 
done. Dict2 however, I cannot, since that will make the code way too long, 
and will take way to long to write.)

What I have started on doing, is the following: Calculate all the 
possibilities for dict1. That gives me 7 variables if it is 3 entries. Then 
I can make some function that calculates one by one of the sums for dict2 
and then compare it to the 7 sums. It is this second part that is stopping 
me now. I do not want to write out everything as with dict1. (As pasted in 
below, for specially interested..)


----------------------------------------------------------

    def fimuex(self):
        aa = len(ffac.exdict)       #ffac.exdict is the dictionary
        if aa == 3:
            ffac.ex1 = str(ffac.exdict[1])   #ex1..7 is the variables
            ffac.ex2 = str(ffac.exdict[2])   #to store the sums and
            ffac.ex3 = str(ffac.exdict[3])   #to be compared with
            ffac.ex4 = str(ffac.exdict[1] + ffac.exdict[2])
            ffac.ex5 = str(ffac.exdict[1] + ffac.exdict[3])
            ffac.ex6 = str(ffac.exdict[2] + ffac.exdict[3])
            ffac.ex7 = str(ffac.exdict[1]+ffac.exdict[2]+ffac.exdict[3])

        if aa == 2:
            ffac.ex1 = str(ffac.exdict[1])
            ffac.ex2 = str(ffac.exdict[2])
            ffac.ex3 = str(ffac.exdict[1] + ffac.exdict[2])

        if aa == 1:
            ffac.ex1 = str(ffac.exdict[1])

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From marcolinux@linuxbr.com.br  Fri Jun 28 22:18:27 2002
From: marcolinux@linuxbr.com.br (Marc)
Date: Fri, 28 Jun 2002 18:18:27 -0300
Subject: [Tutor] Progress Bar Help.
In-Reply-To: <1025291948.3126.7.camel@scott.zenplex.com>
References: <1025291948.3126.7.camel@scott.zenplex.com>
Message-ID: <20020628211827.GB12819@marcolab.proconet>

Scott Comboni (scott@zenplex.com) wrote:

> I recently wrote a simple python script to install a bunch of software
> apps and would like to jazz it up with some sort of graphical progress
> bar.  Is there some URL someone can point me too to get some ideas on
> how to code/create something like this?

You may find this module useful:
http://www.chrisarndt.de/software/python/#xdialog

It's a wrapper for the great Xdialog program ,that, among other
things, have a progress bar example.
Hope that helps.

-- 
I SeE NeRD pEoPle.
.:: MarcoLinux ::.



From dyoo@hkn.eecs.berkeley.edu  Fri Jun 28 22:54:53 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 28 Jun 2002 14:54:53 -0700 (PDT)
Subject: [Tutor] Dictionaries    [lists]
In-Reply-To: <F36oiB5ANH2cv0aGltF00000fa1@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206281424420.10456-100000@hkn.eecs.berkeley.edu>

> I think I am even newer in Python than you, so I can't really for sure
> tell if the pseudocode actually is what I want. But, I can explain a
> little more detailed:
>
> dict1 = (1:2,2:4)
> dict2 = (1:5,2:6)
>
> Then dict1 can have the following sums:
>
> 2,4 and 6
>
> While dict2 can have the following sums:
> 5,6 and 11


Ah!  If I understand your problem correctly, I think that the dictionary
is not an appropriate structure for what you're doing.  It might be better
just to keep the summing numbers in a list:

###
first_numbers = [2, 4]
second_numbers = [5, 6]
###

If your keys are always going to be sequential numbers starting from 0 or
1, then your problem probably should use lists, not dictionaries.




> What I have started on doing, is the following: Calculate all the
> possibilities for dict1. That gives me 7 variables if it is 3 entries.
> Then I can make some function that calculates one by one of the sums for
> dict2 and then compare it to the 7 sums. It is this second part that is
> stopping me now. I do not want to write out everything as with dict1.
> (As pasted in below, for specially interested..)

Sounds good; if we have a list of numbers, we can calculate all the
possible sums of those numbers.  Let's call this function 'allSums()'.
We can imagine that allSums([2, 4]) returns the list: [2, 4, 6], and we
can also imagine that allSums([5, 6]) returns the list [5, 6, 11].

There is a nice solution to this problem that uses a technique called
"dynamic programming" --- we try to find the solution for the smallest
version of the problem, and then work our way up, improving things until
we get the correct answer.



For example, if we wanted to find allSums([3, 4, 5, 6]), a "dynamic
programming" approach would ask the following questions:

    Question 1: What's allSums([3])?
    Question 2: What's allSums([3, 4])?
    Question 3: What's allSums([3, 4, 5])?
    Question 4: What's allSums([3, 4, 5, 6])?

(We're interested in the answer to Question 4.)

The trick that makes dynamic programming neat is that the answer to
Question 1 actually is useful when we do Question 2.  Likewise, the answer
to Question 2 can make Question 3 really easy to answer.  For those who
have seen recursion before, this will seem very familiar, although the
flow of the questions goes in reverse!

I'll post one possible way of doing this at the bottom of this message.
Skip if you don't want to be spoiled.  *grin*

*** Spoiler space ahead ***
















*** Spoiler space ***

###
def allSums(numbers):
    """Returns all possible sums of any nonempty subset of elements
in 'numbers'."""
    possible_sums = [numbers[0]]
    for n in numbers[1:]:
        possible_sums.extend([n + sum for sum in possible_sums])
        possible_sums.append(n)
    return possible_sums
###


How would this calculate allSums([3, 4, 5])?

It first tries to figure out allSums([3]), and this one is really easy.

    allSums([3]) == [3]

There's only one sum involved here, so we can just say that if we're
trying to find all possible sums from [3], that just comes out to [3].


The second answer ia also pretty easy: if we know allSums([3]), then we
can either add 4, or not add 4, or start off a new sum by using 4:

    allSums([3, 4]) ==
        ... Just the values of allSums([3])

        ... plus all the results of:  [(4 + sum)
                                       for sum in allSums([3])]
        ... plus just plain "4".


The third answer is also pretty easy: if we know allSums([3, 4]), then we
can either add 5, or not add 5, or start off a new sum by using 5:

    allSums([3, 4, 5]) ==
        ... Just the values of allSums([3, 4])

        ... plus all the results of:  [(4 + sum)
                                       for sum in allSums([3, 4])]
        ... plus just plain "5".



Hope this helps!




From ak@silmarill.org  Fri Jun 28 23:05:44 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Fri, 28 Jun 2002 18:05:44 -0400
Subject: [Tutor] pair programming.
In-Reply-To: <20020628110456.GB648@hooloovoo>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org> <20020628110456.GB648@hooloovoo>
Message-ID: <20020628220544.GA16802@ak.silmarill.org>

On Fri, Jun 28, 2002 at 01:04:56PM +0200, Abel Daniel wrote:
> On Fri, Jun 28, 2002 at 02:25:34AM -0400 Andrei Kulakov (ak@silmarill.org) wrote
> > I never understood why don't vi or vim have a colored or a highlighted
> > bar on top or bottom that toggle between command/entry mode. In ViWM,
> > there'd be a color cue. There'd be a bar somewhere that'd change colors
> > between blue and red or something and it could be used for something
> > else, too, like maybe windows-type bar? Or Wmaker dock?
> I use vim and in the last line it shows stuff like "-- INSERT --" or
> "-- VISUAL BLOCK -- " for different modes. (The default mode, ex-mode if
> i am right is indicated by an empty line.) I think
> set nocompatible
> and/or
> set showmode
> will turn it on
>
Yeah I know but some people apparently still get confused.. If there
was a colored bar, you'd see it in the corner of your eye even if you
were looking at the middle of screen where you're typing..

> 
> abli
> abli@freemail.hu
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From dman@dman.ddts.net  Sat Jun 29 06:14:53 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 29 Jun 2002 00:14:53 -0500
Subject: [Tutor] Re: pair programming.
In-Reply-To: <20020628220544.GA16802@ak.silmarill.org>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org> <20020628110456.GB648@hooloovoo> <20020628220544.GA16802@ak.silmarill.org>
Message-ID: <20020629051453.GA19603@dman.ddts.net>

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

On Fri, Jun 28, 2002 at 06:05:44PM -0400, Andrei Kulakov wrote:
| On Fri, Jun 28, 2002 at 01:04:56PM +0200, Abel Daniel wrote:
| > On Fri, Jun 28, 2002 at 02:25:34AM -0400 Andrei Kulakov (ak@silmarill.o=
rg) wrote
| > > I never understood why don't vi or vim have a colored or a highlighted
| > > bar on top or bottom that toggle between command/entry mode.

| > I use vim and in the last line it shows stuff like "-- INSERT --" or
| > "-- VISUAL BLOCK -- " for different modes.

| Yeah I know but some people apparently still get confused.. If there
| was a colored bar, you'd see it in the corner of your eye even if you
| were looking at the middle of screen where you're typing..

If there was a white line with ALL CAPS TEXT it you'd see it out of
the corner of your eye ... oh wait, it does have that.  My point is
just that no matter what you will do, _some_ user will find a way to
be confused.  My desktop has enough color on it already to obscure
such a bar.  (xpenguin is cool too)

If you forget where you're at, just hit ESC repeatedly and when the
computer beeps (or the screen flashes, or you've hit it a few times)
you're guaranteed to be in command mode :-).

-D

--=20

If we claim we have not sinned, we make Him out to be a liar and His
Word has no place in our lives.
        I John 1:10
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0dQk0ACgkQO8l8XBKTpRRL4wCffUrWivHbl56EsjFwcJJjwV94
WMUAn0WhncsL1TCg2Z0KGx8T0BxVKutc
=NlQe
-----END PGP SIGNATURE-----

--uAKRQypu60I7Lcqm--



From dman@dman.ddts.net  Sat Jun 29 06:18:33 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 29 Jun 2002 00:18:33 -0500
Subject: [Tutor] Re: Question concerning VPython
In-Reply-To: <000f01c21e29$6dc9f680$1615a8c0@mega>
References: <000f01c21e29$6dc9f680$1615a8c0@mega>
Message-ID: <20020629051833.GB19603@dman.ddts.net>

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

On Fri, Jun 28, 2002 at 12:24:39AM +0200, Gregor Lingl wrote:
| Hi!
| I'm just beginning to play around a little=20
| with VPython. So I even don't know if the following=20
| question is appropriate.
|=20
| In VPython
|=20
| >>> sphere()
|=20
| creates a display-object and a sphere-object
|=20
| but sphere() doesn't seem to be a constructor,

Right.  VPython is coded in C++ and uses the CXX library for
interacting with python.  The python part of it is basically just some
wrapper functions around the C++ ctors.  It is unfortunate, but
hopefully they'll recode it differently when python 2.2 is the norm
(since starting in python 2.2 it is possible to create subclassable
types in C/C++).

-D

--=20

Your beauty should not come from outward adornment, such as braided hair
and the wearing of gold jewelry and fine clothes.  Instead, it should be
that of your inner self, the unfading beauty of a gentle and quiet
spirit, which is of GREAT WORTH in God's sight.  For this is the way the
holy women of the past used to make themselves beautiful.
        I Peter 3:3-5
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0dQykACgkQO8l8XBKTpRTZggCeJoQ3qs2QqLOIETgCD2vkWy5M
uW4AniPLIot+pXe/kcHhBqwQP4Aw3JM9
=nOac
-----END PGP SIGNATURE-----

--DBIVS5p969aUjpLe--



From ak@silmarill.org  Sat Jun 29 06:35:01 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 29 Jun 2002 01:35:01 -0400
Subject: [Tutor] Re: pair programming.
In-Reply-To: <20020629051453.GA19603@dman.ddts.net>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org> <20020628110456.GB648@hooloovoo> <20020628220544.GA16802@ak.silmarill.org> <20020629051453.GA19603@dman.ddts.net>
Message-ID: <20020629053501.GA20456@ak.silmarill.org>

On Sat, Jun 29, 2002 at 12:14:53AM -0500, Derrick 'dman' Hudson wrote:
> On Fri, Jun 28, 2002 at 06:05:44PM -0400, Andrei Kulakov wrote:
> | On Fri, Jun 28, 2002 at 01:04:56PM +0200, Abel Daniel wrote:
> | > On Fri, Jun 28, 2002 at 02:25:34AM -0400 Andrei Kulakov (ak@silmarill.org) wrote
> | > > I never understood why don't vi or vim have a colored or a highlighted
> | > > bar on top or bottom that toggle between command/entry mode.
> 
> | > I use vim and in the last line it shows stuff like "-- INSERT --" or
> | > "-- VISUAL BLOCK -- " for different modes.
> 
> | Yeah I know but some people apparently still get confused.. If there
> | was a colored bar, you'd see it in the corner of your eye even if you
> | were looking at the middle of screen where you're typing..
> 
> If there was a white line with ALL CAPS TEXT it you'd see it out of
> the corner of your eye ... oh wait, it does have that.  My point is
> just that no matter what you will do, _some_ user will find a way to

That's true for any feature that is user-friendly. The reason for these
features is not to help all users (which is impossible) but to help
most :-)

> be confused.  My desktop has enough color on it already to obscure
> such a bar.  (xpenguin is cool too)
> 
> If you forget where you're at, just hit ESC repeatedly and when the
> computer beeps (or the screen flashes, or you've hit it a few times)
> you're guaranteed to be in command mode :-).
>
The biggest problem with modality in vi*'s is that you may be in
command mode but think you're in insert and type some stuff which
will garble your text in a scary random-looking manner. This was a much
worse problem in vi with no multi-undo, but in vim it's still bad for
newbies because it's a very distressing behavior, from a psychological
point of view.

I myself never found this to be much of a problem, but I know some
people do..

> 
> -D
> 
> -- 
> 
> If we claim we have not sinned, we make Him out to be a liar and His
> Word has no place in our lives.
>         I John 1:10
>  
> http://dman.ddts.net/~dman/
> 



-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From glingl@aon.at  Sat Jun 29 09:24:08 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sat, 29 Jun 2002 10:24:08 +0200
Subject: [Tutor] Dictionaries    [lists]
References: <Pine.LNX.4.44.0206281424420.10456-100000@hkn.eecs.berkeley.edu>
Message-ID: <004501c21f46$57001470$1615a8c0@mega>

----- Original Message -----
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: "Terje Johan Abrahamsen" <terjeja@hotmail.com>
Cc: <tutor@python.org>

I'll post below one small correction of a type in Danny's explanation
- and a slightly different version of his code. Therefore do also

> Skip if you don't want to be spoiled.  *grin*
>
> *** Spoiler space ahead ***
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *** Spoiler space ***
>
> ###
> def allSums(numbers):
>     """Returns all possible sums of any nonempty subset of elements
> in 'numbers'."""
>     possible_sums = [numbers[0]]
>     for n in numbers[1:]:
>         possible_sums.extend([n + sum for sum in possible_sums])
>         possible_sums.append(n)
>     return possible_sums
> ###
>
>
> How would this calculate allSums([3, 4, 5])?
>
> It first tries to figure out allSums([3]), and this one is really easy.
>
>     allSums([3]) == [3]
>
> There's only one sum involved here, so we can just say that if we're
> trying to find all possible sums from [3], that just comes out to [3].
>
>
> The second answer ia also pretty easy: if we know allSums([3]), then we
> can either add 4, or not add 4, or start off a new sum by using 4:
>
>     allSums([3, 4]) ==
>         ... Just the values of allSums([3])
>
>         ... plus all the results of:  [(4 + sum)
>                                        for sum in allSums([3])]
>         ... plus just plain "4".
>
>
> The third answer is also pretty easy: if we know allSums([3, 4]), then we
> can either add 5, or not add 5, or start off a new sum by using 5:
>
>     allSums([3, 4, 5]) ==
>         ... Just the values of allSums([3, 4])

##################################
>         ... plus all the results of:  [(5 + sum)   ## correction: here 5
instead of 4

##################################
>                                        for sum in allSums([3, 4])]
>         ... plus just plain "5".
>

If you don't mind to include 0 as the sum of the empty list, you may code
it - slightly more compact - this way:

def allSums(numbers):
    """Returns all possible sums of any subset of elements in 'numbers'."""
    possible_sums = [0]
    for n in numbers:
        possible_sums.extend([n + sum for sum in possible_sums])
    return possible_sums

    # However, if you don't like this first "0", you should
    # return possible_sums[1:]







From ajs@ix.netcom.com  Fri Jun 28 01:19:54 2002
From: ajs@ix.netcom.com (Arthur Siegel)
Date: Thu, 27 Jun 2002 20:19:54 -0400
Subject: [Tutor] Question concerning VPython
References: <5.1.1.6.0.20020627161919.02694070@urnerk/pop.ptld.qwest.net>
Message-ID: <000001c21f6d$ef363a40$0334fea9@carol>

> You could learn quite a bit from eyeballing his source >code I
> should think.
>
> See:  http://pw1.netcom.com/~ajs/
>
> Kirby

Appreciate the plug.  But understand that I am very much
myself a learner.

PyGeo is constantly being refractored as I come to
understand more of Python in particular and programming
in general.

And the tutor list has certainly been a help.

I will be putting up a new version soon.  I have learned enough in the
meantime to be a bit embarrassed by the version up there now.  Though it
does basically work - which is a decent part of the battle.

And yes VPython is C++/ using SIP libraries. As such
its primitives are not subclassable in Python.  But
PyGeo is itself quite OOP in design, and how I
used VPython with PyGeo might in fact be useful to
look at.

A Holy Grail is the C++ class sub-classable in Python.

Is that where the Boost project is heading?

Anybody know?

Art




From ajs@ix.netcom.com  Sat Jun 29 15:02:44 2002
From: ajs@ix.netcom.com (Arthur Siegel)
Date: Sat, 29 Jun 2002 10:02:44 -0400
Subject: [Tutor] Re: Question concerning VPython
References: <000f01c21e29$6dc9f680$1615a8c0@mega> <20020629051833.GB19603@dman.ddts.net>
Message-ID: <003401c21f75$a57c0bc0$0334fea9@carol>

Dman writes -

>Right.  VPython is coded in C++ and uses the CXX >library for interacting
with python.  The python part of it is >basically just some wrapper
functions around the C++ .

That's correct. I had written SIP instead of CXX by mistake.

>It is unfortunate, but hopefully they'll recode it differently >when python
2.2 is the norm (since starting in python 2.2 >it is possible to create
subclassable
>types in C/C++).

As it happens I am studying the VPython C++ code and
beginning to make small enhancements (customized to the needs of PyGeo.)

The creator of CXX, in the best tradition of OpenSource openness(?),
acknowledges at  http://cxx.sourceforge.net/ that in fresh
projects, Boost is quite possibly a better alternative to CXX.

So I do have the hope/intention of eventually taking a stab at porting
VPython to use the Boost extensions, and hopefully thereby making its
primitive sub-classable in Python.

Waiting for the new version of Boost to hit the stands before I dig into to
far.

Certainly someone like David Scherer, the creator of VPython (I consider it
to be truly creative programming) would be in a *much* better position to do
this than myself.  But, he does not seem to be involved very much in the
project any more, I am not sure if there is much likelihood of it being
undertaken unless a heavy VPython user and fan like myself at least shows
some keen interest and a willingness to participate.

Also a great opportunity for myself to begin to get up to speed in C++ and
Python extension building.

I should have paid more attention to Danny Yoo's tutorial offer on Python
extension writing, but the timing wasn't right for me.

Art





From dman@dman.ddts.net  Sat Jun 29 19:38:42 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 29 Jun 2002 13:38:42 -0500
Subject: [Tutor] [OT] fun with vi(m) (was Re: Re: pair programming.)
In-Reply-To: <20020629053501.GA20456@ak.silmarill.org>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org> <20020628110456.GB648@hooloovoo> <20020628220544.GA16802@ak.silmarill.org> <20020629051453.GA19603@dman.ddts.net> <20020629053501.GA20456@ak.silmarill.org>
Message-ID: <20020629183842.GA24478@dman.ddts.net>

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

On Sat, Jun 29, 2002 at 01:35:01AM -0400, Andrei Kulakov wrote:
| On Sat, Jun 29, 2002 at 12:14:53AM -0500, Derrick 'dman' Hudson wrote:

| > If you forget where you're at, just hit ESC repeatedly and when the
| > computer beeps (or the screen flashes, or you've hit it a few times)
| > you're guaranteed to be in command mode :-).
|
| The biggest problem with modality in vi*'s is that you may be in
| command mode but think you're in insert and type some stuff which
| will garble your text in a scary random-looking manner.

Just press 'u' a few times :-).

| This was a much worse problem in vi with no multi-undo,

True.

| but in vim it's still bad for newbies because it's a very
| distressing behavior, from a psychological point of view.

Newbies?

"...In the UNIX world, people tend to interpret `non-technical user' as
meaning someone who's only ever written one device driver."
    --Daniel Pead


Sure, it could cause permament psychological damage.  For me the
damage has already been done ;-).
=20
| I myself never found this to be much of a problem, but I know some
| people do..
=20
When I forget, I tend to forget I'm already in insert mode and thus
get an extra 'a' or 'i' in my buffer, which I promptly delete.

The absolute worst mistake, though, is forgetting other programs
aren't vi and pressing '<ESC>' so that I can edit what I just typed.
In particular, my previous employer used MS VSS as the source
repository, and in the checkin log message dialog, ESC means "cancel"!
I don't know how many times I had to retype the log message because I
pressed ESC to edit it.

(BTW, I also set readline to work in vi-mode, so I get vi in bash and
python too!)

-D

--=20

Whoever loves discipline loves knowledge,
but he who hates correction is stupid.
        Proverbs 12:1
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0d/rEACgkQO8l8XBKTpRSX5gCfelttim+pPfWN7cIA60vdT+Gu
G74An3WPvm4rAg8oR60nkcYiV4wXozO6
=HxUL
-----END PGP SIGNATURE-----

--vtzGhvizbBRQ85DL--



From dman@dman.ddts.net  Sat Jun 29 19:43:56 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sat, 29 Jun 2002 13:43:56 -0500
Subject: [Tutor] Re: Question concerning VPython
In-Reply-To: <000001c21f6d$ef363a40$0334fea9@carol>
References: <5.1.1.6.0.20020627161919.02694070@urnerk/pop.ptld.qwest.net> <000001c21f6d$ef363a40$0334fea9@carol>
Message-ID: <20020629184356.GA24864@dman.ddts.net>

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

On Thu, Jun 27, 2002 at 08:19:54PM -0400, Arthur Siegel wrote:

| A Holy Grail is the C++ class sub-classable in Python.

Another one is a python type coded in C that is sub-classable in
Python.  (eg 'list', 'str', 'dict', 'file')

| Is that where the Boost project is heading?

AFAIK that is one of the goals of the project.  I also believe it is
designed to provide a more C++-ish API for extending python.  The C
API is directly usable in C++ programs, but while it is OO, it is
still C.

BTW, Both "Holy Grail"s are now possible in CPython >=3D 2.2.  I don't
expect that Boost will go away now, but I do expect that it's
implementation will change (and probably be streamlined some) for
CPython >=3D 2.2.

-D

--=20

Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10
=20
http://dman.ddts.net/~dman/


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

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

iEYEARECAAYFAj0d/+wACgkQO8l8XBKTpRSgDgCgx3nuaxqvsZcV9tVltHwqFreD
6C0An352i+ZP1/GyLWL1wjobgOff7Zh8
=D8UD
-----END PGP SIGNATURE-----

--mYCpIKhGyMATD0i+--



From ppkelly@nyc.rr.com  Sat Jun 29 22:28:59 2002
From: ppkelly@nyc.rr.com (Paul Kelly)
Date: Sat, 29 Jun 2002 16:28:59 -0500
Subject: [Tutor] mailing list
Message-ID: <001401c21fb3$fe7ce440$0702a8c0@dnsart.com.PIPE>

This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C21F8A.12505E40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi , please remove me from your mailing list or tell me how to do so. =
This programming is over my head so and don't know where to start. =
Thanks Paul

------=_NextPart_000_0010_01C21F8A.12505E40
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 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi , please remove me from your mailing =
list or=20
tell me how to do so. This programming is over my head so and don't know =
where=20
to start. Thanks Paul</FONT></DIV></BODY></HTML>

------=_NextPart_000_0010_01C21F8A.12505E40--




From ak@silmarill.org  Sun Jun 30 00:09:04 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sat, 29 Jun 2002 19:09:04 -0400
Subject: [Tutor] [OT] fun with vi(m) (was Re: Re: pair programming.)
In-Reply-To: <20020629183842.GA24478@dman.ddts.net>
References: <20020628042628.GA9506@ak.silmarill.org> <XFMail.20020627224756.shalehperry@attbi.com> <20020628062534.GA10890@ak.silmarill.org> <20020628110456.GB648@hooloovoo> <20020628220544.GA16802@ak.silmarill.org> <20020629051453.GA19603@dman.ddts.net> <20020629053501.GA20456@ak.silmarill.org> <20020629183842.GA24478@dman.ddts.net>
Message-ID: <20020629230904.GA26976@ak.silmarill.org>

On Sat, Jun 29, 2002 at 01:38:42PM -0500, Derrick 'dman' Hudson wrote:
> The absolute worst mistake, though, is forgetting other programs
> aren't vi and pressing '<ESC>' so that I can edit what I just typed.
> In particular, my previous employer used MS VSS as the source
> repository, and in the checkin log message dialog, ESC means "cancel"!
> I don't know how many times I had to retype the log message because I
> pressed ESC to edit it.
>
I hate the way slrn and mutt are *almost* identical. Even thought both
shortcuts can be edited, their atomicity is different, in one of them,
I forget which, there's the same key that exit split panel mode, and
when pressed again, quits the program.. yeah, that's mutt. No way to
set up slrn to do the same.

> 
> (BTW, I also set readline to work in vi-mode, so I get vi in bash and
> python too!)
>
Yeah, me too..

>

> 
> -D
> 
> -- 
> 
> Whoever loves discipline loves knowledge,
> but he who hates correction is stupid.
>         Proverbs 12:1
>  
> http://dman.ddts.net/~dman/
> 



-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From beercanz@hotmail.com  Sun Jun 30 04:14:07 2002
From: beercanz@hotmail.com (Guess Who? Me)
Date: Sun, 30 Jun 2002 03:14:07 +0000
Subject: [Tutor] Help with duplicates using for...
Message-ID: <F216QiZij0w4TPnhur800002561@hotmail.com>

<html><div style='background-color:'><DIV>list = [4, 5, 7, 8, 9, 1,0,7,10]<BR>list.sort()<BR>prev = list[0]<BR>del list[0]<BR>for item in list:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if prev == item:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Duplicate of ",prev," Found"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prev = item<BR></DIV>
<DIV>I don't understand this piece of code. I don't get why you have to remove the first list value. Could somebody please explain it some ? I almost have it.</DIV>
<DIV>Thanks,</DIV>
<DIV>Travis</DIV></div><br clear=all><hr>Send and receive Hotmail on your mobile device: <a href='http://g.msn.com/1HM1ENUS/c152??PI=44364'>Click Here</a><br></html>



From idiot1@netzero.net  Sun Jun 30 04:27:31 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sat, 29 Jun 2002 23:27:31 -0400
Subject: [Tutor] mailing list
References: <001401c21fb3$fe7ce440$0702a8c0@dnsart.com.PIPE>
Message-ID: <3D1E7AA3.D369CB49@netzero.net>

Start here:
	http://www.python.org/doc/Newbies.html

Then when grokking the IS-ness, go here:
	http://www.python.org/doc/


> Paul Kelly wrote:
> 
> Hi , please remove me from your mailing list or tell me how to do so.
> This programming is over my head so and don't know where to start.
> Thanks Paul

-- 

end

Respectfully,
             Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                           +--------+



From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 09:03:07 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 01:03:07 -0700 (PDT)
Subject: [Tutor] mailing list
In-Reply-To: <001401c21fb3$fe7ce440$0702a8c0@dnsart.com.PIPE>
Message-ID: <Pine.LNX.4.44.0206300052050.20096-100000@hkn.eecs.berkeley.edu>


On Sat, 29 Jun 2002, Paul Kelly wrote:

> Hi , please remove me from your mailing list or tell me how to do so.
> This programming is over my head so and don't know where to start.

Hi Paul,

If you want to unsubscribe, you can go to the Tutor Options mailing page
here:

    http://mail.python.org/mailman/listinfo/tutor

Go down to the bottom, and you can see an Edit Options form, and you can
unsubscribe from there.  If you run into any problems while unsubscribing,
please feel free to send mail to tutor-admin@python.org, and the
administrators can help unsubscribe you manually.


But, by the way, if you feel overwhelmed by what we're talking about on
Tutor, please ask us to explain ourselves!  If you ask a question that
we're not answering, that's something we need to fix.  And if you see
messages that seem over your head, you can just ignore them; all messages
are broadcast to all subscribers, so that all can learn from what's being
discussed.

Tutor is something of a mix of all sorts of people --- both tutors and
tutees --- and it can be a little disorienting at first.  And to tell the
truth, if we're talking about stuff that seems like nonsense, that's
probably because it is.  *grin*

But if you ask questions, that should snap us out of our mumbling, so that
we can address you.


Best of wishes to you!




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 09:23:12 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 01:23:12 -0700 (PDT)
Subject: [Tutor] Help with duplicates using for...
In-Reply-To: <F216QiZij0w4TPnhur800002561@hotmail.com>
Message-ID: <Pine.LNX.4.44.0206300111020.20096-100000@hkn.eecs.berkeley.edu>


On Sun, 30 Jun 2002, Guess Who? Me wrote:

> list = [4, 5, 7, 8, 9, 1,0,7,10]
> list.sort()
> prev = list[0]
> del list[0]
> for item in list:
>         if prev == item:
>                 print "Duplicate of ",prev," Found"
>         prev = item

> I don't understand this piece of code. I don't get why you have to
> remove the first list value. Could somebody please explain it some ? I
> almost have it.


Hi Travis,

Actually, we don't have to delete the first element from our list ---
that's just how this particular way is doing it.



Sorting the list brings similar values together, so if there are any
duplicates, there'll be adjacent to each other.  The code keeps a "prev"
variable to keep track of the very last "previous" value that it has seen,
and to start the whole thing off, it says that last thing it's seen so far
is list[0].

    prev = list[0]

Now, what we'd like to do is march over the rest of the list, and scan our
eye across the list, one by one.  Since potential duplicates are right
next to each other, this "scanning" should do the trick.

###
for item in list:
    if prev == item:
        print "Duplicate of ",prev," Found"
    prev = item
###


But there's one subtle point: we've got to make sure that we're not
looking at the first element of the list when we start scanning forward!


If it helps, think of two fingers on our list, like this:


###
[0 1 4 5 7 7 8 9 10]
 ^
 |
 |
 |
finger 1
"prev"
###


What we want to avoid is this situation:

###
[ 0    1 4 5 7 7 8 9 10]
 ^ ^
 | |
 | +-------+
 |         |
finger 1   |
"prev"     |
         finger 2
         "next"
##

... where both fingers are pointing at the same first element.  If that
happens, the code will always say there's a duplicate, even when there
isn't one.


The writer of the code thought that deleting the first element would be a
good way to avoid this problem, but it's not the only way.  The delete
itself isn't the only way to solve this problem, but we do have to deal
with the situation somehow.



Hope that makes some sort of sense... *grin* Please feel free to ask more
questions about this.




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 09:34:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 01:34:38 -0700 (PDT)
Subject: [Tutor] Help with duplicates using for...
In-Reply-To: <Pine.LNX.4.44.0206300111020.20096-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0206300126320.20096-100000@hkn.eecs.berkeley.edu>


> If it helps, think of two fingers on our list, like this:
>
>
> ###
> [0 1 4 5 7 7 8 9 10]
>  ^
>  |
>  |
>  |
> finger 1
> "prev"
> ###

Doh.  Sorry about that: there were supposed to be two fingers there.  Let
me rewrite that:

###
[0 1 4 5 7 7 8 9 10]
 ^ ^
 | |
 | +--------+
 |          |
finger 1   finger 2
"prev"     "item"
###

Hmmm... writing this is getting awkward.  Is it ok if I write the
situation above like this instead?


###
[0 1 4 5 7 7 8 9 10]
 p i
###

('p' will stand for 'previous', and 'i' will stand for 'item')  That way,
it's a little shorter and easier to write.



During duplicate finding finger 1 and finger 2 should be right next to
each other, scanning across like this:

###
[0 1 4 5 7 7 8 9 10]
 p i

[0 1 4 5 7 7 8 9 10]
   p i

[0 1 4 5 7 7 8 9 10]
     p i

[0 1 4 5 7 7 8 9 10]
       p i

[0 1 4 5 7 7 8 9 10]
         p i              ## Duplicate found!
###

and if 'p' and 'i' point to the same numbers, that must mean that we see a
duplicate.


The problem that we want to avoid is overlapping the fingers on top of
each other:

###
[0 1 4 5 7 7 8 9 10]
 p
 i
[0 1 4 5 7 7 8 9 10]
   p
   i
[0 1 4 5 7 7 8 9 10]
   p
   i
###

because then that's just plain silly.  *grin*

Hope this helps!




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 10:32:29 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 02:32:29 -0700 (PDT)
Subject: [Tutor] drag-and-drop argument passing
In-Reply-To: <200206271513.g5RFDA002723@smtp3.fas.harvard.edu>
Message-ID: <Pine.LNX.4.44.0206300213040.20096-100000@hkn.eecs.berkeley.edu>


On Thu, 27 Jun 2002, Pijus Virketis wrote:

> I have a script that takes an arbitrary number of paths to files as a
> command line argument, and manipulates the said files. Now, I would like
> to be able to execute the script and pass the arguments to it by
> drag-and-dropping the target files on the script icon in Windows. How
> should such inputs be handled? I have looked through the tutor and win32
> list archives on ASPN, but could not find an answer to this question.

Looks like someone else asked this on python-win32 a while back:

    http://mail.python.org/pipermail/python-win32/2002-April/000323.html

but no one responded!  You might want to check with Ian Bicking and see if
he found a good solution to this problem.


Hunting...

    http://www.planetquake.com/gg/tutorial/code/parms.html

Hmmm... that only mentions the first argument....


>From a totally unrelated message:

    http://srfi.schemers.org/srfi-22/mail-archive/msg00022.html

it sounds like the batch file argument '%*' might not work --- otherwise,
the Schemers would have used it.  *grin*


Microsoft's documentation on batch files:

http://www.microsoft.com/technet/treeview/default.asp?url=/TechNet/prodtechnol/winxppro/proddocs/batch.asp

does mention %*, so this is really weird...



Let's try this.  Can you try modify the association that Alan recommends
from:

    D:\Python20\python.exe "%1" %*

to something like:

    D:\Python20\python.exe "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"

Yes, I know this is ugly, but let's double check to see if '%*' works on
Windows.




From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 10:49:23 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 02:49:23 -0700 (PDT)
Subject: [Tutor] drag-and-drop argument passing
In-Reply-To: <Pine.LNX.4.44.0206300213040.20096-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0206300238070.20096-100000@hkn.eecs.berkeley.edu>


> Microsoft's documentation on batch files:
>
> http://www.microsoft.com/technet/treeview/default.asp?url=/TechNet/prodtechnol/winxppro/proddocs/batch.asp
>
> does mention %*, so this is really weird...

... still searching... *grin*


FAQTS has a little something about this:

    http://www.faqts.com/knowledge_base/view.phtml/aid/4153/fid/245

where they mention that, on NT or Win2k, the PATHEXT environmental
variable controls if Windows thinks some file is executable or not, so
perhaps this might have something to do with things.

    http://www.reportlab.com/ftp/talks/PythonWindowsTutorial.doc

is another Python page that mentions setting PATHEXT to make Windows think
of '.py' files as ".exe"'s.


Good night!




From yduppen@xs4all.nl  Sun Jun 30 11:50:09 2002
From: yduppen@xs4all.nl (Yigal Duppen)
Date: Sun, 30 Jun 2002 12:50:09 +0200
Subject: [Tutor] Coercion of user-defined numeric types - when does it happen?
Message-ID: <200206301050.g5UAo9rH053543@smtpzilla3.xs4all.nl>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm trying to emulate a numeric type by implementing a Fraction class. I've 
followed chapter 3.3.6 of the reference manual, but I can't get 'mixed-mode' 
numeric arithmetic to work -- the interpreter does not automatically coerce 
the arguments.

To compress the problem a bit: my Fraction class has an __add__ and a 
__coerce__ method. __add__ works perfectly with other Fractions:

>>> print Fraction(1,3) + Fraction(1,4)
7/12

>>> print Fraction(1,4) + 1
????

What I _expect_ to happen is the following:
1) the interpreter calls Fraction.__add__ and realizes this does not work
2) the interpreter applies the different coercion rules specified in chap 
3.3.6
3) following the __coerce__ method, the interpreter then tries to print 
Fraction(1,4) + Fraction(1,1)

Unfortunately, step 1 is not fully specified -- how do I tell the interpreter 
that it should start coercing? 

For your convenience, I've inlined (a condensed version of) the Fraction 
class, together with a small test.

=================

def _gcd(a, b): 
    while b != 0:
        a, b = b, a%b
    return a

class Fraction(object):

    def __init__(self, numerator, denominator):
        # normalize values
        gcd = _gcd(numerator, denominator)
        self.num = numerator/gcd
        self.den = denominator/gcd

    def __add__(self, other):
        try:
            num = self.num * other.den + self.den * other.num
            den = self.den * other.den
            return Fraction(num, den)
        except AttributeError:
            # no fraction, other should be coerced... How do I tell
            # the interpreter to do this??? 
            pass

    def __coerce__(self, other):
        if type(other) is int:
            return (self, Fraction(other, 1))

        if type(other) is long:
            return (self, Fraction(other, 1))

        # Auto-convert self to type of other
        return None

    def __str__(self):
        return "%d/%d" % (self.num, self.den)


if __name__ == "__main__":
    print Fraction(1,3) + Fraction(2,1)
    print Fraction(1,3) + 2

===================

So how would I get the second line to work? (apart from implementing the 
entire coercion algorithm myself).

Thanks in advance,

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

iD8DBQE9HuJhLsKMuCf5EdwRAiqxAKCEIj9mPz+A/1VmyJFT8aCRjB1BeACeN+49
artL21ggSOwwWv5xBxQ1XEs=
=/KrX
-----END PGP SIGNATURE-----



From slime@vsnl.net  Sun Jun 30 14:01:54 2002
From: slime@vsnl.net (Prahlad Vaidyanathan)
Date: Sun, 30 Jun 2002 18:31:54 +0530
Subject: [Tutor] Matrix class problems
Message-ID: <20020630130154.GA1420@localhost.localdomain>

Hi,

    I have recently got back to exploring python, and, being a Maths
student, I decided to test my skills on a simple Matrix class. Now, I
came across some questions which I hope you will help clear.

    Firstly, I would like to know what exactly repr() does. I read the
docs, and this is what I got :

"""
>>> help(repr)
Help on built-in function repr:

repr(...)
repr(object) -> string

Return the canonical string representation of the object.
For most object types, eval(repr(object)) == object.
"""

What does this mean and how is this different from str() ?

Also, I wrote a __mul__() function, which looks like so :

"""
    def __mul__ (self, other) :
        if type(other) == type(0) :
            return self._scalar_multiply(other)
        else :
            return self._matrix_multiply(other)
"""

Now, this works, but like this :

"""
>>> import matrix
>>> m = matrix.Matrix([[1,0,0],[0,1,0],[0,0,1]])
>>> print (m*2)
[ 2, 0, 0 ]
[ 0, 2, 0 ]
[ 0, 0, 2 ]
>>> print (2*m)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for *: 'int' and 'instance'

"""

    I understand that, in the first case, I am calling the function I
wrote, but in the second case I am calling the equivalent __mul__
function of an 'int' object. My question is, how do I make the latter
point to the former ? Although this is not a major issue, it bugs me
because I tend to write the number first, and the matrix later by habit.

    I hope I have been clear enough.

pv.

ps. For those of you who study Maths, I have been racking my brains as
to how to get the determinant of a Matrix, and have been unsuccessful.

How do I find the minor matrix ? Aaaarggghhh !!

-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

When things go well, expect something to explode, erode, collapse or
just disappear.



From Sk8ersrockall999@aol.com  Sun Jun 30 14:07:13 2002
From: Sk8ersrockall999@aol.com (Sk8ersrockall999@aol.com)
Date: Sun, 30 Jun 2002 09:07:13 EDT
Subject: [Tutor] help on makin a prog
Message-ID: <190.916fa9b.2a505c81@aol.com>

Hey im really really new to this stuff and i would like some help so could 
any1 try teach me? i know a few things raw_input("Hello, world") and 
print"hello world so cud u teach me how to make a proper program?



From ak@silmarill.org  Sun Jun 30 17:08:43 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sun, 30 Jun 2002 12:08:43 -0400
Subject: [Tutor] help on makin a prog
In-Reply-To: <190.916fa9b.2a505c81@aol.com>
References: <190.916fa9b.2a505c81@aol.com>
Message-ID: <20020630160843.GA3414@ak.silmarill.org>

On Sun, Jun 30, 2002 at 09:07:13AM -0400, Sk8ersrockall999@aol.com wrote:
> Hey im really really new to this stuff and i would like some help so could 
> any1 try teach me? i know a few things raw_input("Hello, world") and 
> print"hello world so cud u teach me how to make a proper program?

What kind of program do you want to make?

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

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



From trivas7@rawbw.com  Sun Jun 30 17:49:46 2002
From: trivas7@rawbw.com (Thomas Rivas)
Date: Sun, 30 Jun 2002 09:49:46 -0700
Subject: [Tutor] rep() and str(0
Message-ID: <200206301637.g5UGbmO58726@mail0.rawbw.com>

On Sun Jun 30 2002 you wrote:

>>Firstly, I would like to know what exactly repr() does. 

My understanding is that rep() is a built-in function that  does the same 
thing as the `` operator --  converts an object x to an expression string 
(think REPResentation) that can be evaluated as a valid expression using the 
eval() built-in function. The str() function (think STRing) converts an 
object that is human-friendly that is usually used by the print statement. 
I.e,:

>>>str(4.53-2j)
'(4.53-2j)'
>>>
>>>str(1)
'1'
>>>
>>>str(2e10)
'20000000000.0'
>>>
>>>repr([0, 5, 9, 9])
'[0, 5, 9, 9]'
>>>
>>>`[0, 5, 9, 9]`
'[0, 5, 9, 9]'

In my experience all three usually return the exact same string.

Tom Rivas



From dyoo@hkn.eecs.berkeley.edu  Sun Jun 30 19:53:36 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 30 Jun 2002 11:53:36 -0700 (PDT)
Subject: [Tutor] rep() and str(0
In-Reply-To: <200206301637.g5UGbmO58726@mail0.rawbw.com>
Message-ID: <Pine.LNX.4.44.0206301147060.27079-100000@hkn.eecs.berkeley.edu>


On Sun, 30 Jun 2002, Thomas Rivas wrote:

> >>>str(4.53-2j)
> '(4.53-2j)'
> >>>
> >>>str(1)
> '1'
> >>>
> >>>str(2e10)
> '20000000000.0'
> >>>
> >>>repr([0, 5, 9, 9])
> '[0, 5, 9, 9]'
> >>>
> >>>`[0, 5, 9, 9]`
> '[0, 5, 9, 9]'
>
> In my experience all three usually return the exact same string.


Here's one place where repr() and str() return different kinds of strings:

###
>>> x = 1 - .1
>>> print str(x)
0.9
>>> print repr(x)
0.90000000000000002
###

Since repr() is meant to be more "truthful" than str(), it shows us that
floating point can't hold this value precisely.

We can see another small difference when we do str() and repr() on
strings:

###
>>> story = """Mars was empty before we came.
... That's not to say that nothing had ever happened."""
>>> print repr(story)
"Mars was empty before we came.\nThat's not to say that nothing had ever
happened."
>>> print str(story)
Mars was empty before we came.
That's not to say that nothing had ever happened.
###



Hope this helps!




From virketis@post.harvard.edu  Sun Jun 30 21:05:08 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Sun, 30 Jun 2002 23:05:08 +0300
Subject: [Tutor] drag-and-drop argument passing
Message-ID: <ISPFE8z0b4djKMQzfyB0002120c@mail.takas.lt>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Danny,</div>
<div> </div>
<div>&gt; PATHEXT environmental variable controls if Windows=
 thinks some file</div>
<div>&gt; is executable or not, so perhaps this might have=
 something to do</div>
<div>&gt; with things.</div>
<div> </div>
<div>Setting PATHEXT does not do the trick. However, I turned my=
 script into an .exe with py2exe, and - voila - I could=
 drag-and-drop anything I pleased on it. So, I guess that's how=
 one can go about </div>
<div>it.:) The arguments get passed on as you might expect, with=
 the sys.argv[] containing the paths to all the files that were=
 dropped.</div>
<div> </div>
<div>Now, there is only one thing left in my way, but it is very=
 vexing. I don't know how to generate raw strings on the fly. For=
 example: this path would choke my script, because &quot;\f&quot;=
 is a token:</div>
<div> </div>
<div>&gt;&gt;&gt; &quot;c:\ftp\test.txt&quot;</div>
<div>'c:\x0ctp\test.txt'</div>
<div>&nbsp;</div>
<div>Interactively, I can get around this by making it=
 raw:</div>
<div> </div>
<div>&gt;&gt;&gt; r&quot;c:\ftp\test.txt&quot;</div>
<div>'c:\\ftp\\test.txt'</div>
<div> </div>
<div>But how do I turn a string in a list, like sys.argv[], into=
 a raw string? Is there a conversion function between the two or=
 something?</div>
<div>Then, I could do (pseudocode):</div>
<div> </div>
<div>for path in sys.argv[1:]:</div>
<div>&nbsp;&nbsp;&nbsp; make_raw(path)</div>
<div> </div>
<div>Thanks,</div>
<div> </div>
<div>Pijus</div>
<div>-- </div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann</div>
</body></html>




From alan.gauld@bt.com  Sun Jun 30 23:30:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 30 Jun 2002 23:30:36 +0100
Subject: [Tutor] Re: pair programming.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6C3@mbtlipnt02.btlabs.bt.co.uk>

> The biggest problem with modality in vi*'s is that you may be in
> command mode but think you're in insert and type some stuff which
> will garble your text in a scary random-looking manner. 

> I myself never found this to be much of a problem, but I know some
> people do..

Those folks obviously never used Tico... ;-)

The standard programmers game in Tico was to type your name and 
try to guess what the effect would be on your code(*)! The only good 
thing I can say about Tico is that it was so bad it drove 
James Gosling to invent the original Emacs!

Alan G.

(*)Actually on your computer since it was entirely possible to 
accidentally delete files, format disks etc by typing seemingly 
inoccuous character strings into Ticos command line interface...

PS Anyone on a Vax running VMS can still experience Tico by typing
EDIT/TICO at a DCL prompt - Good luck!!



From alan.gauld@bt.com  Sun Jun 30 23:59:56 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 30 Jun 2002 23:59:56 +0100
Subject: [Tutor] help on makin a prog
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C6C6@mbtlipnt02.btlabs.bt.co.uk>

> Hey im really really new to this stuff and i would like some 
> help so could 
> any1 try teach me? i know a few things raw_input("Hello, world") and 
> print"hello world so cud u teach me how to make a proper program?


Go to the Beginners page on the python web site and work through one of 
the tutorials there. Everytime you hit something yuou don't understand 
send the question to this list. A whole bunch of folks will then spring 
into action trying to answer it. Try to be as specific as possible and 
if you get error messages include them in the mail.

Thats how the list works, have fun.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From retvet2@netins.net  Sun Jun 30 18:42:26 2002
From: retvet2@netins.net (David & Sheri Early)
Date: Sun, 30 Jun 2002 12:42:26 -0500
Subject: [Tutor] game help
Message-ID: <002f01c2205d$80368820$264bf8d8@davidearly>

This is a multi-part message in MIME format.

------=_NextPart_000_002B_01C22033.96A7DE80
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_002C_01C22033.96A7DE80"


------=_NextPart_001_002C_01C22033.96A7DE80
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

hello my name is chris and am trying to use python to start creating a =
game but everywhere i look for resources i come up at a dead end. help!

~Chris~

------=_NextPart_001_002C_01C22033.96A7DE80
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 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Comic Sans MS" size=3D4>hello my name is chris and am =
trying to=20
use python to start creating a game but everywhere i look for resources =
i come=20
up at a dead end. help!</FONT></DIV>
<DIV><FONT face=3D"Comic Sans MS" size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Comic Sans MS" =
size=3D4>~Chris~</FONT></DIV></BODY></HTML>

------=_NextPart_001_002C_01C22033.96A7DE80--

------=_NextPart_000_002B_01C22033.96A7DE80
Content-Type: text/x-vcard;
	name="Sharnee.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="Sharnee.vcf"

BEGIN:VCARD
VERSION:2.1
N:;Sharnee
FN:Sharnee
EMAIL;PREF;INTERNET:retvet2@netins.net
REV:20020630T174226Z
END:VCARD

------=_NextPart_000_002B_01C22033.96A7DE80--




From val@vtek.com  Sun Jun 30 20:14:09 2002
From: val@vtek.com (val)
Date: Sun, 30 Jun 2002 15:14:09 -0400
Subject: [Tutor] installing/starting vPython
Message-ID: <02af01c2206a$515ff2e0$0193fea9@vt1000>

Hi The List,
    i downloaded and installed vPython for Python22.
    i'm trying to run demos from the Demos dir by double-
    clicking on *.py files.  It works impressively fine 
    on my job (same win2k, both Py21 and Py22 are             installed).
    At home i have a standard message from vPython
    and then just an empty window (or two or three
    depending on the demo to be run).

    Any help/advice would be very appreciated.
thanx,
val




From virketis@post.harvard.edu  Sun Jun 30 19:51:38 2002
From: virketis@post.harvard.edu (Pijus Virketis)
Date: Sun, 30 Jun 2002 21:51:38 +0300
Subject: [Tutor] drag-and-drop argument passing
In-Reply-To: <Pine.LNX.4.44.0206300213040.20096-100000@hkn.eecs.berkeley.edu>
Message-ID: <ISPFE8V1EetVoMDrxxn00020cd1@mail.takas.lt>

<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Danny, <br></div>
<div>&nbsp;</div>
<div>&gt; PATHEXT environmental variable controls if Windows=
 thinks some file &gt; is executable or not, so perhaps this=
 might have something to do <br></div>
<div>&gt; with things.<br></div>
<div>&nbsp;</div>
<div>Setting PATHEXT does not do the trick. However, I turned my=
 script into an .exe with py2exe, and - voila - I could=
 drag-and-drop anything I pleased on it. So, I guess that's how=
 one can go about it.:) The arguments get passed on as you might=
 expect, with the sys.argv[] containing the paths to all the=
 files that were dropped. <br></div>
<div>&nbsp;</div>
<div>Now, there is only one thing left in my way, but it is very=
 vexing. I don't know how to generate raw strings on the fly. For=
 example: this path would choke my script, because &quot;\f&quot;=
 is a token:<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; &quot;c:\ftp\test.txt&quot;<br></div>
<div>'c:\x0ctp\test.txt'<br>
<br></div>
<div>Interactively, I can get around this by making it=
 raw:<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; r&quot;c:\ftp\test.txt&quot;<br></div>
<div>'c:\\ftp\\test.txt'<br></div>
<div>&nbsp;</div>
<div>But how do I turn a string in a list, like sys.argv[], into=
 a raw string? Is there a conversion function between the two or=
 something?<br></div>
<div>Then, I could do (pseudocode):<br></div>
<div>&nbsp;</div>
<div>for path in sys.argv[1:]:<br></div>
<div>&nbsp; &nbsp;&nbsp;make_raw(path)<br></div>
<div>&nbsp;</div>
<div>Thanks, <br></div>
<div>&nbsp;</div>
<div>Pijus<br></div>
<div>&nbsp;</div>
<div>-- <br></div>
<div>&quot;Anyone attempting to generate random numbers by=
 deterministic means is, of course, living in a state of=
 sin.&quot; -- John Von Neumann<br></div>
</body></html>