logo       

Re: How to debug?: msg#00143

python.apple

Subject: Re: How to debug?

Le 27 mai 2004, à 06:33, Michael Hudson a écrit :

What kind of app are you debugging? That impacts the answer quite a
lot...


I usually program small app. I use Python as a multipurpose language. For me, it is a replacement of the good old BASIC. I'm using it to apply some of the concept that I am learning at school.

I am expecting a debugger. I want to be able to run my code line by line and I want to be able to see the value of my variables as they change.

Last monday, I was sick. So I made a little Python app to solve "mots cachés" to spare time. I don't know how you are calling this in English "hidden words"?

Here is the code. This is an example of the small apps I do. I gives the letters not found in capital.

-------------------------------------------------------------------------------------------------
import copy

class CrossWordSolver(object):
def __init__( self , letters = [""], words = [""]):
self.letters = letters # Mutable sequence of string
self.words = words # Mutable sequence of string


def getLetters( self ):
return copy.deepcopy( self._letters )


def setLetters( self, letters ): # letters is a mutable sequence a string
self._letters = copy.deepcopy( letters )
self._width = len( self._letters[0] )
self._height = len ( self._letters )
self._letters = [i.upper() for i in self._letters]


letters = property( getLetters, setLetters, doc = "Letters of the crossword")


def getWords( self ):
return copy.deepcopy( self._words )


def setWords( self, words ): # words is a mutable sequence of word
self._words = copy.deepcopy( words )
self._words = [i.upper() for i in self._words]


words = property( getWords, setWords, doc = "Words to find")

def solve( self ):
for word in self._words:
for dx in -1, 0, 1:
for dy in -1, 0, 1:
if dx+dy:
for x in xrange( self._width ):
for y in xrange( self. _height ):
wX, wY = x, y
for letter in word:
if wX >= self._width or wY >= self._height : break
if self._letters[wY][wX].upper() != letter.upper() : break
wX += dx
wY += dy
else:
for i in xrange( len( word ) ):
i = x+dx*i
line = self._letters[y]
self._letters[y] = line[0:i]+line[i].lower()+line[i+1:]
y += dy
return self._letters

if __name__ == "__main__":
crossWordSolver = CrossWordSolver()
crossWordSolver.letters = ["tnpevideoenmyheros", "hcoehfdnairfaveuru", "oeorrtgauchepmarco", "relnegnrertitapism", "amsbspoesignergite", "xiosmuplmehcuabedr", "urnjaelaatlmollets", "eaiatisannasunisoe", "scmrnrmntaarroboti", "aloraoecerdmtsiloc", "vedeiuiriremoeanth", "omilftreneaxirrore", "tuvlniuvohcbasmyur", "raaioecaunauotorqe", "apnmcrepitiratibut", "fdouzeuqsidaesrmep", "iertilombricrmeero", "cgaufreevuafngorge"]
crossWordSolver.words = ["admis", "armoire", "colis", "confiant", "consulat", "crampe", "debauche", "disque", "divan", "domino", "douze", "ecurie", "embryon", "ensemble", "errant", "essaim", "fauve", "faveur", "friand", "gauche", "gaufre", "gorge", "grain", "harem", "heros", "hymne", "inoui", "jarre", "litre", "lombric", "mante", "menthe", "mille", "miracle", "mollet", "napperon", "opter", "paume", "paver", "pergola", "rabot", "remous", "repit", "robot", "roman", "routier", "sauce", "seiche", "signe", "sinus", "tapis", "tarte", "taxer", "thorax", "tigre", "titrer", "trafic", "truquer", "vaseux", "video"]
print crossWordSolver.solve()

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

I really like to do this in Python because it is so easy to do nice things with few code. Is it helping?

Regards.

---------------------
Pierre_______________________________________________
Pythonmac-SIG maillist - Pythonmac-SIG@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/pythonmac-sig
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise