David Broadwell | 1 Apr 08:53 2004

Advice; Pointers Needed

I'm trying to get a handle on a pet project.

What I'm trying to build is a basic 'dice' server to send and receive dice
rolls with multiple internet clients.

The 'dice' in this case is just a rolling algorithm to simulate different
types of dice depending on what the 'game master' wants. Luckily the game
master IS the programmer that will be at the server, and until it goes the
only dice schema will be rock, paper, scissors OR d10 or d10. Also luckily
is the fact there is only one client (for now), and that is the machine that
the player (who is also the programmer) can get to via rotating his seat.
Also luckily is the fact that both machines in question while in differing
subnets (forcing internet communication) are one hub away from each other.

The server will need to be able to roll dice, request dice roll from client,
wait for die roll, evaluate success or failure, display result of roll, send
message success/fail message to client, handle a client login, handle a
client logout, forcibly log a client out.

The client will need to read a incoming request for a die roll, roll die of
the type requested, send the result to the server, wait for the response
from the server and tell the player a success or fail message, login to
server, logout from server.

For a first pass, (Hardcode server and client) simply having the server send
a client the succeeded or failed message will be a good starting success.


I'm guessing that I'll be needing threads in there somewhere. But as far as
(Continue reading)

Maxim Ryan | 1 Apr 13:50 2004


can u help me fininish this program? as you run it u will see that afer the blanks are filled  the prog. doesnot end and i also need to subtract the used letters from the alphabet and count how many turns are left.(i am giving the user 6 turns to guess the word

Protect your PC - Click here for McAfee.com VirusScan Online
import random
import string

def getlist():
    return split

def pickword(split):
    print b
    return b


def unguessed(let,alphabet):
    print "unguessed:"+alphabet
    return alphabet

def question(b,alphabet):
    question=raw_input("press A to guess one letter at a time or B to guess 
the word: ")
    while question<>"a" and question<>"A" and question<>"b" and 
        print " please enter a or b  "
        question=raw_input("press A to guess one letter at a time or B to 
guess the whole word: ")
    if question=="a" or question=="A":
    elif question=="b" or question=="B":
        playgame(b,alphabet)#return #getguess(b)

givenletters = []

def underscores(b):
    output = []
    for letter in b:
        if letter in givenletters:

    print "Word:"
    print string.join(output, ' ')

def safeinput(b):
    let= raw_input("enter a letter: ")
    if let== "":
        print "please enter a value"
        return safeinput(b)
    if len(let)>1:
        print" please enter a single lowercase letter"
        return safeinput(b)
    for char in let:
        if string.find(string.lowercase,char) == -1:
            print "please enter a single lowercase letter"
            return safeinput(b)
    return let

def printlet(let,b,alphabet):
    if let not in b:
        print"wrong guess"
    if let in b:
        print"good guess"

def getguess(b):
    ask=raw_input("try to guess the word: ")
    if ask=="":
        print "please enter a value"
        return getguess(b)
    for char in ask:
            if string.find(string.lowercase,char)==-1:
                print "please enter a lowercase letter"
                return getguess(b)
    return ask

def testword(ask,b,alphabet):
    if ask ==b:
        return loop(alphabet)
        print" better luck next time"
        print "the word was" +" " + b
        return loop(alphabet)

def win(b,alphabet):
    for char in b:
        return b
    for char in givenletters:
        return givenletters
    if b==givenletters:

def loop(alphabet):
    play=raw_input("DO YOU WANNA PLAY AGAIN? y/n: ")
    while play<>"y" and play<>"Y" and play<>"n" and play<>"N":
        print " please enter y or n  "
        play=raw_input("DO YOU WANNA PLAY AGAIN? y/n: ")
    if play=="y" or play=="Y":
        print "THE END"

def playgame(b,alphabet):
    guess=getguess(b)           #you guesses the entire word
    testword(guess,b,alphabet)           #compares word with guess

def partone(b,alphabet):
    printlet(safe,b,alphabet)    #display entered letters in underscores

def choice(b,alphabet):
    underscores(b)               #print underscores
    question(b,alphabet)                  #choice between guessing word or 
each letter

def start(alphabet):

start(alphabet)                         #start

Tutor maillist  -  Tutor <at> python.org
kbond | 1 Apr 20:20 2004

Re: Python exes

If you are looking for a way to convert py to exe I will advise you to 
have a look at the following link:


Magnus Lycka wrote:

>Brandon wrote:
>>I've tried all I can about creating a .exe file in python. I've googled, searched, and found everything I
could, but I still can not get anything to work. Can someone point me in the right direction?
>You're not very explicit with what you tried, and what
>your problems were, but I've had memory errors with 
>py2exe and McMillan installer that disappeared when 
>I used cx_Freeze instead. See

Tutor maillist  -  Tutor <at> python.org

Danny Yoo | 1 Apr 21:55 2004

Re: unfininished [please don't ask us to do your homework]

On Thu, 1 Apr 2004, Maxim Ryan wrote:

> can u help me finish this program? as you run it u will see that after
> the blanks are filled the prog. does not end

[text cut]

Hi Ryan,

If you have particular questions on Python programming, we can help with
that.  And if you're running into a particular problem in your program,
and you don't understand the error message that Python is giving, then we
can talk about that.

But if you just want us to do the program for you, then please read:


You mentioned that the program does not end.  Can you give us more details
what you mean?  What part of your program doesn't end, or what part seems
to repeat?

Good luck.

Tutor maillist  -  Tutor <at> python.org

R. Alan Monroe | 2 Apr 02:47 2004

Re: Off Topic: Revision control system

>> vi testfile.py
>> ./testfile.py
>> cp testfile.py testfile2.py
>> vi testfile2.py
>> ./testfile2.py
>> cp testfile2.py testfile3.py
>> vi testfile3.py
>> etc
>> I keep copying so I don't destroy something that works.
>> Now my question is, do you folks use any sort of revision control system
>> on linux ? I've had a look at CVS and RCS but both seem a bit over the
>> top for my needs.

Makes you wish for the good old VMS way of life. For those that
haven't used it, when you save with the same filename, the filesystem
automatically makes file.py;1, file.py;2, etc. You could set the
number of versions to keep (I think) per directory.


Tutor maillist  -  Tutor <at> python.org

Karl Pflästerer | 2 Apr 02:41 2004

Re: first steps

On 28 Mar 2004, peter hodgson <- py <at> humnet.ucla.edu wrote:


> Here is another example of variable usage:

> a = 1
> print a
> a = a + 1

> Even if it is the same variable on both sides [OF THE '='] the
> computer still reads it as: First find out the data to store [RIGHT
> SIDE OF THE '='?] and than [THEN] find out where the data goes [PRINT

The `=' sign is misleading; most people who have a feeling for
mathematics stumble first on this.  Some languages use for assignment a
different sign to not confuse people.

You uses the right words.  If you assign a value you have a left hand
side (lhs) and a right hand side (rhs).  First the interpreter evaluates
the rhs and after that it assigns the returned value to the lhs.

So if you write
   a      =   a + 1
   ^          ^
   |          |  
   lhs        rhs

the interprter first evaluates a+1, stores that value somewhere and
assigns then a to that value.  From now on the old value of a is

> ----------------------
> -----------------------
> #while 1 == 1: would perpetuate the printing of "help..."
> #l3 - l6 [extracted from another program] should limit it to five times
> count = 0
> max_count = 5
> while count > max_count:
>       count = count + 1
>       print "help, i'm caught in a loop"

> #but the program won't run

A while loop runs as long as the test in its head returns True.  Now
look at your test condition: what does it return?

> -----------------------------
> -----------------------------
> #values into/out of a pail;	#this is l1
> a = 1                   #this means a = non-zero, that it is;
> s = 0			#empty pail
> print "enter numbers to add to the sum"	#plus or minus
> print "enter 0 to quit"			#end the game
> while a != 0:		#i.e., you're still playing the game;
>       print "current sum:", s  #so we start at 0
>       a = input("nmber? ")     #and we alter s by a, superceding a = 1
>       s = s + a		       #and a is the increment
> 			       #reducing s to 0 won't close program
> print "total sum = ", s  #not indented cause it only runs at the end

> #l2, l3 provide the contents and the pail;


> #l5, l6 provide for a way to end the game;

IMO no. line 5 prints only a message to the screen. line 6 is the line
which holds the test condition.

> #playing the game is l4, plus the indented lines l7 - l9;

Maybe.  I wouldn't know which line should not belong to the game (except
line 1 since it's only a comment).  If you deleted any other line the
game wouldn't run the way it does now.


Please do *not* send copies of replies to me.
I read the list

Tutor maillist  -  Tutor <at> python.org

Karl Pflästerer | 2 Apr 02:55 2004

Re: embedding an if

On 29 Mar 2004, peter hodgson <- py <at> humnet.ucla.edu wrote:

> tutorial assignment; what am i doing wrong? thanks

I think that password programm is one of the most often mentioned
programs here :-)

> #Modify the password guessing program to keep track of how many times
> # the user has entered the password wrong. If it is more than 3 times,
> # print "you're screwed, buddy!", or something like that;

> passwd = "foobar"		#a dummy passwd
> count = 3
> current_count = 0
> while passwd != "unicorn":
>       current_count = current_count + 1
>       passwd = raw_input("Passwd: ")	
>          if current_count < count:
>              print "no, stupid! try again;"
>          else print "three times, you're out!"
> print "welcome in"

(you include tabs in your e-mails; that may result in wrong indentation
in some e-mail clients or programs if someone tries your code)

Did you try that program?  It won't run.

If you want to wite an else clause it's written like that:

if foo == bar:
    print 'Python'

Even if you program ran it wouldn't run in the way you probably
expected; after printing the message you need a way to break the loop:
the statement is called `break' (surprise).

But then your program will process the code after the loop so a user
would always see the welcome message.  If you don't want that you need a
way to stop the whole program; you must import the sys module and


Please do *not* send copies of replies to me.
I read the list

Tutor maillist  -  Tutor <at> python.org

Karl Pflästerer | 2 Apr 03:09 2004

Re: checking variable types

On 22 Mar 2004, Marie Robichon <- robichon <at> esrf.fr wrote:

> How in my python script do I test whether it is a list or a string
> before I do my processing ?

You could either use try ... except and simply try a list method; if the
value is a list no exception gets raised.  But I must say I don't really
like that approach since you know in advance what types your values may
be so you could use the `types' module.

>>> import types
>>> s = 'string'
>>> if type(s) == types.ListType:
...     print 'A list'
... else:
...     print 'A string'
A string

If your code can be written that it always assumes a list you could

def string_to_list_maybe (s):
    if type(s) == types.StringType:
        return [s]
    else: return s

>>> v = 'a string'
>>> v = string_to_list_maybe(v)
>>> v
['a string']
>>> L = range(10)
>>> L = string_to_list_maybe(L)
>>> L
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


Please do *not* send copies of replies to me.
I read the list

Tutor maillist  -  Tutor <at> python.org

Danny Yoo | 2 Apr 03:50 2004

Re: checking variable types

On Fri, 2 Apr 2004, [iso-8859-1] Karl Pflsterer wrote:

> If your code can be written that it always assumes a list

[some text cut]

Yes, it might be easier to always assume that the parameter values from
the CGI program is a list, if you're reading from that multiple-value

The CGI documentation at:


talks about a high-level function called getlist() that should be useful.
It should return a list --- even a list of one element --- so that your
processing of that data should be uniform.

Hope this helps!

Tutor maillist  -  Tutor <at> python.org

Alex Newby | 2 Apr 08:28 2004

Simple profile of cx_Freeze and py2exe

Given the discussion on converting Py to Exe, I tried both cx_Freeze and
py2exe. I created a simple,

print "hello world"

and, applied both utilities. Gordon MacMillan's site appears to be
off-line, so his installer is excluded.

1. cx_Freeze ~ 3 files

hello.exe 207kb
dist is 1.18mb
memory usage is 3,160K

2. py2exe ~ 5 files

hello.exe 20kb
library.zip 204kb
dist is 1.21mb
memory usage is 2,948K

cx_Freeze seems tidier and easier to initially use (no setup.py) than
py2exe. Perhaps, py2exe has other advantages that I'm not aware of. I'm
curious why cx_Freeze receives relatively little press. Before it was
discussed here I was completely unaware of its existence.  

Alex Newby

Tutor maillist  -  Tutor <at> python.org