mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-15 20:48:00 +01:00
add --debug option to print words as they're loaded
This commit is contained in:
parent
645b5eeb3b
commit
36e05b8285
1 changed files with 9 additions and 2 deletions
|
@ -39,6 +39,8 @@ def mkParser():
|
|||
help = 'sort output by ASCII or COUNT')
|
||||
parser.add_argument('--enc', dest = 'ENC', type = str, default = 'utf8',
|
||||
help = 'encoding')
|
||||
parser.add_argument('--debug', dest = 'DEBUG', default = False,
|
||||
action = 'store_true', help = 'turn on logging')
|
||||
return parser
|
||||
|
||||
def main():
|
||||
|
@ -51,20 +53,25 @@ def main():
|
|||
letterCount = 0
|
||||
|
||||
sys.stdin.reconfigure(encoding=args.ENC)
|
||||
|
||||
|
||||
lineNo = 0
|
||||
for line in sys.stdin.readlines():
|
||||
line = line.strip()
|
||||
|
||||
if args.DEBUG: print( 'word {}: {}'.format(lineNo, line))
|
||||
|
||||
length = len(line)
|
||||
wordSizeCounts[length] += 1
|
||||
wordCount += 1
|
||||
|
||||
for letter in line:
|
||||
ii = ord(letter)
|
||||
assert ii > 32 or ii < 4 or ii == 0, 'letter {} in word {} out of range'.format(ii, line)
|
||||
assert ii > 32 or ii < 4 or ii == 0, \
|
||||
'letter[{}] ("{}") in word "{}" out of range'.format(ii, letter, line)
|
||||
if not letter in letters: letters[letter] = Letter(letter)
|
||||
letters[letter].increment()
|
||||
letterCount += 1
|
||||
lineNo += 1
|
||||
|
||||
print( 'Number of words: {}'.format(wordCount))
|
||||
print( 'Number of letters: {}'.format(letterCount))
|
||||
|
|
Loading…
Add table
Reference in a new issue