我想將一個可以正常使用Python 2.7.2的程序轉換爲Python 3.1.4。str對象無法調用
我越來越
TypeError: Str object not callable for the following code on the line "for line in lines:"
代碼:
in_file = "INPUT.txt"
out_file = "OUTPUT.txt"
##The following code removes creates frequencies of words
# create list of lower case words, \s+ --> match any whitespace(s)
d1=defaultdict(int)
f1 = open(in_file,'r')
lines = map(str.strip(' '),map(str.lower,f1.readlines()))
f1.close()
for line in lines:
s = re.sub(r'[0-9#$?*><@\(\)&;:,.!-+%=\[\]\-\/\^]', " ", line)
s = s.replace('\t',' ')
word_list = re.split('\s+',s)
unique_word_list = [word for word in word_list]
for word in unique_word_list:
if re.search(r"\b"+word+r"\b",s):
if len(word)>1:
d1[word]+=1