-3
파이썬 2.7x를 사용하고 있으며 디버깅하는 데 문제가 있습니다. 내가 뭘 할 수 있는지 잘 모르겠다. 어떤 도움을 주셔서 감사합니다. 감사.파이썬 코드를 디버깅하는 데 도움이 필요합니다. 난파선입니다.
import re
import sys
# Grab parameters from the command line
(filename, threshold) = sys.argv[1:3]
# Validate arguments
if (re.match("\D", threshold)):
print "The threshold must be a number."
sys.exit(1)
# Read file and tally word frequencies
fh = open(filename)
file = fh.read()
words = []
for line in file.split('\n'):
found = 0
for word in words:
if word[0] == line.lower():
found = 1
word[1] += 1
# initialize a new word with a frequency of 1
if found == 0:
words.append([line, 1])
# Print words and their frequencies, sorted alphabetically by word. Only print a word if its frequency is greater than or equal to the threshold.
for word in sorted(words):
if word[0] < threshold: continue
print "%4d %s" % (word[1], word[0])
작동하지 않는 것에 대한 정보를 입력해야합니다. –
"디버깅하는 데 문제가 있습니다." 디버거와 관련된 특정 문제가 있습니까? 작동하지 않는 것은 무엇입니까? – David
이것이 닫혀 있어야한다고 생각하지 마십시오. 질문이 잘못 제기되었지만 유효하지 않습니다. @ user1100031, 내가 추측해야만한다면, 단어 목록에 아무 것도 추가하지 않는다는 것이 문제라고 말할 수 있습니다. 빈 상태로 시작하기 때문에'for word in words '루프를 입력하지 마십시오. –