[Tutor] Script Crashing in Windows 2000

alan.gauld@bt.com alan.gauld@bt.com
Wed, 16 Oct 2002 17:20:08 +0100


> after he enters a search criteria and hits enter.  The whole screen
> disappears.  

Dunno whats causing that but one point is that you can make 
your code much more readable and faster by using format 
strings instead of that horrible space multiplication/subtraction trick:

        print "NAME" + (" " * (21 - len("NAME"))),

# force 21 character left justified string
print "%21s", % "NAME"	  


>  print player_split[0] + ", " + player_split[1] + 
>   (" " * (20 - len(player_split[0] + " " + player_split[1]))),

nm = "%s %s" % (player_split[0],player_split[1])  #names with a space
print "%-21s" % nm    # left justify to desired length.
  
Or combining those:

print "%21s" % ("%s %s" % (player_split[0],player_split[1]))

But the latter is just as obscure IMHO as all the 
arithmetic(albeit faster!)

I suspect the next set of prints could maybe be parameterized 
into a loop too...

Sorry to be picky but all those parens were hurting my head!

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld