Re: [Tutor] Please review my code - a simple iterator thingy to make round-robin pairings

2005-12-12 Thread Pekka Karjalainen
Thank you for the response, Danny!

On 12/12/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
> One thing you can add is unit tests to see that your program is doing what
> you expect.  There's a great example of how unit tests work in Mark
> Pilgrim's "Dive into Python":
>
> http://diveintopython.org/unit_testing/index.html
>
> and the things they talk about there can be applied to your program.
> Have you played with 'unittest' before?

It's time I started. I'll look there first and work on it.

> We might want to interchange the list copying with the code that ensures
> len(players) is even. Otherwise, the caller can see mutation of their
> input list, which goes contrary to doing the list copy in the first place.
> *grin*

That's a very good point. Noted.

> Otherwise, the main thing I'd recommend is to back the algorithm with unit
> tests;  the implementation has some subtle details (like interchanging
> colors) that has enough special cases to make me a little hesitant.  Unit
> testing would help us to have more confidence in those special cases.
> Otherwise, looks good!

I have an informal, but to my mind solid, proof for it working
elsewhere. But being aware of what even Don Knuth thinks of
correctness proofs wrt to programs ("I've only proved it correct..."),
I'm not going to disregard testing. Time to think of good test cases
now and do some reading. Thanks for the heads up.

(Also, I should check how to handle empty lists.)

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


Re: [Tutor] Editors

2005-12-12 Thread Ismael Garrido
Will Harris wrote:

> Any of you familar with SPE 
>  
> ? I found this just recently on freshmeat and was curious if anyone 
> had used it? If so how well it works and what not. This caught my 
> attention because its cross platform (written in python).

Try it. :)

I don't like that it's not able to run all that IDLE can run... Things 
like pygame don't go well with SPE.

BTW: Does anyone know how to change the color configuration? I really 
like IDLE's one.. Kinda grew up with that one, I'd love to see it in SPE

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


[Tutor] (no subject)

2005-12-12 Thread moparfan90
hello. i want to mke a program that will do a couple of things that are hard to do:
 -keep track of what it does.. and learn from what the user does in a sense
 -be in a nice looking setup.. like Tkinter or something similar
 -and always know that uptodate time and weather if possible
 
 
i know this seem crazy but ill start it and when someone replys ill email it to you. 
 
 
thanks
~ moparfan90
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Editors

2005-12-12 Thread Will Harris
Any of you familar with SPE
? I found this just recently on freshmeat and was curious if anyone had
used it? If so how well it works and what not. This caught my attention
because its cross platform (written in python).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please review my code - a simple iterator thingy to make round-robin pairings

2005-12-12 Thread Danny Yoo


On Mon, 12 Dec 2005, Pekka Karjalainen wrote:

> I hope my code and comments are clear enough for you to work out what I
> want to do. Please review my code, my commenting and give some advice on
> how to use the testing module. This is a fairly trivial example, but I'd
> like to learn how to make & run tests properly, so as to use them with
> Real Code. I'm looking forward to your replies.


Hi Pekka,

One thing you can add is unit tests to see that your program is doing what
you expect.  There's a great example of how unit tests work in Mark
Pilgrim's "Dive into Python":

http://diveintopython.org/unit_testing/index.html

and the things they talk about there can be applied to your program.
Have you played with 'unittest' before?


Some casual comments so far:

> # the constructor
> def __init__ (self,players,empty="empty"):
> if len(players)%2: players.insert(0,empty)
> self.players = players[:] # copy, so can modify
> self.times = 0

We might want to interchange the list copying with the code that ensures
len(players) is even. Otherwise, the caller can see mutation of their
input list, which goes contrary to doing the list copy in the first place.
*grin*


Otherwise, the main thing I'd recommend is to back the algorithm with unit
tests;  the implementation has some subtle details (like interchanging
colors) that has enough special cases to make me a little hesitant.  Unit
testing would help us to have more confidence in those special cases.
Otherwise, looks good!

Good luck!

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


Re: [Tutor] Currency conversion

2005-12-12 Thread Michael Janssen
On 12/12/05, David Holland <[EMAIL PROTECTED]> wrote:

> wouldn't it be better to change :-
> "def rupees_from_dollars(d_doll):
> return 43*(d_doll)
>
> etc to" :-
> "def conversiond_doll, x):
> return x*(d_doll)
> "

> You can then have one function for all currencies and
> would be less code and easier to maintain.

Having just one function instead of several is fine, perhaps even for
the cost of one additional function argument. Good to maintain, nice
flexibility. OTOH usability is important, too. Eg. I'm always driven
crazy by concurrency conversions, never can imaging what to take and
what to get, so I prefer a single pretty clear named function for my
use case like "rupees_from_dollars" instead of a "conversion(d_doll,
dollar_exchange_rate)" (the hard thing for me is to remember, if it
must be dollar_exchange_rate or 1/dollar_exchange_rate)

What you can often/sometimes find in code is an all purpose
function/class with full flexibility and additionally some easy-to-use
functions provided for the common case. As in the email package with
it's message_from_string and message_from_file functions. You can read
about them and their relationship to the package in:
http://docs.python.org/lib/node584.html

regards
Michael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Please review my code - a simple iterator thingy to make round-robin pairings

2005-12-12 Thread Pekka Karjalainen
I hope my code and comments are clear enough for you to work out what
I want to do. Please review my code, my commenting and give some
advice on how to use the testing module. This is a fairly trivial
example, but I'd like to learn how to make & run tests properly, so as
to use them with Real Code. I'm looking forward to your replies.

Pekka (first posting, I hope the code doesn't break in transit)

# rrobin.py - Round-robin pairing algorithm

# Implementation of the standard Round-robin pairing algorithm. See:
# http://en.wikipedia.org/wiki/Round-robin_tournament
#
# The algorithm works as follows. Assume an even number of
# participants, since with odd numbers a dummy player can be added.
# (Drawing the dummy as opponent means having a free round.) Let there be
# n players, with n even.
#
# Initially the players are in a list ordered by their number from 1 to
# n. Pair each players number k from 0 to n/2-1 with number n-k-1 in the
# first round. Then modify the list as follows for all successive
# rounds. There are total of n-1 rounds. (NB: k starts from 0 as in
# Python list indices.)
#
# To modify the list for further rounds, first fix player 1. Then place
# the last player in the list after player 1, which causes the other
# players' positions to move higher by one step each. After this the
# pairing proceeds as in the first round, using the player's current
# position in the list.
#
# Additionally, colors are often important, e.g. in chess. However, it is
# not possible to assign colors perfectly fairly.
#
# The fairest possible color assignment follows from fixing the colors
# by playing position in all tables except where player 1 plays. Have
# player 1 draw alternating colors on alternating rounds. In this
# program the colors are indicated by the pairing order, so
#
# ("player1", "player2") implies player 1 has white and
# ("player2", "player1") implies player 1 has black (v.v. for pl. 2)
#
# This program creates an iterator that returns a list of tuples
# indicating the pairings for each round in order. Its input is a list
# of players. Passing a list of players' names as strings works well.
#
# Written by Pekka Karjalainen December 2005
# This code is in the public domain.

class RoundRobinPairs (object):
"""Iterator for Round-robin pairing. The constructor takes a list of
players (strings recommended) and an optional argument indicating the
possible empty player needed to round up to even players. By default
this is the string 'empty', and it is placed in the beginning of the
list.
"""

# the constructor
def __init__ (self,players,empty="empty"):
if len(players)%2: players.insert(0,empty)
self.players = players[:] # copy, so can modify
self.times = 0

# the iterator protocol
def __iter__ (self):
return self

# next()
def next(self):
"Returns the next pairing."
self.times += 1
n = len(self.players)
if self.times == n:
# max number of rounds is len -1
raise StopIteration
# only modify list on later passes
if self.times > 1:
mover=self.players.pop()
self.players.insert(1,mover)
# build pairings
pairings = []
for k in range(n/2):
playwhite = self.players[k]
playblack = self.players[n-k-1]
# switch colors on every odd table and on first table
# every other round for balanced colors
if (self.times%2 and k==0) or (k%2):
playblack,playwhite = playwhite,playblack
pairings.append( (playwhite,playblack) ) # parens make tuple
return pairings

# End of class defn

def main():
   # default small odd pairing
   mylist = ["player1","player2","player3","player4","player5"]
   pairs = RoundRobinPairs (mylist)
   for pairing in pairs:
   print pairing

if __name__=="__main__":
main()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Currency conversion

2005-12-12 Thread David Holland
Apologies if anyone has said this and I missed it, but
wouldn't it be better to change :-
"def rupees_from_dollars(d_doll):
return 43*(d_doll)

etc to" :-
"def conversiond_doll, x):
return x*(d_doll)
"
And in the main for eg dollars to 
dollar_amount = conversionsion(doll, dollarexchange
rate) etc

You can then have one function for all currencies and
would be less code and easier to maintain.



___ 
Yahoo! Exclusive Xmas Game, help Santa with his celebrity party - 
http://santas-christmas-party.yahoo.net/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] information needed to make a connection between computers

2005-12-12 Thread Kent Johnson
John Walton wrote:
> please tell me what information of the computer you want to connect with 
> the you actually need for a connection? In other words (or plain 
> english), what information do I need to get a connection with another 
> computer (IP address, name, IP name)? Also, could you tell me how to 
> find it on a computer?

You need the IP address or domain name. On Windows you can find out the 
IP address by typing the command
  > ipconfig
in a command window.

Kent

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


Re: [Tutor] information needed to make a connection between computers

2005-12-12 Thread Pujo Aji
yes you can do that in python.But I recommend to use pyro.http://pyro.sourceforge.net/pujoOn 12/11/05, 
John Walton <[EMAIL PROTECTED]> wrote:
 Hello again! I'm still working on that  instant messenger (for science fair), and I have been reading about  networking in some Java tutorials. In one part of it, it said to have a  connection with another computer, you need to know the IP name of the  computer you want to connect with. I don't know whether or not this is  the same for Python, but could someone please tell me what information  of the computer you want to connect with the you actually need for a  connection? In other words (or plain english), what information do I  need to get a connection with another computer (IP address, name, IP  name)? Also, could you tell me how to find it on a computer? Since I'll  be testing the instant messenger on the three computers in my house, I  just need to know how to find the information on the computer I'd  currently be on (not from any remote location). Thanks!  :)
  -John  
	
		Yahoo! Shopping 
Find Great Deals on Holiday Gifts at 
Yahoo! Shopping 
___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor