Python 读txt 获取行数
Python 读txt 获取行数
def getTxtlinesNum(): count = -1 ThreeWordList = [] for count, line in enumerate(open(r"mydatabases.txt", 'rU', encoding="utf-8")): newline = line.replace('\t','') newline = newline.replace('\n','') newline = newline.replace('”', '') newline = newline.replace('”', '') newline = newline.replace("'", '') newline = newline.replace('"', '') newline = newline.replace('?', '') newline = newline.replace('?', '') ThreeWordList.append(newline) count = count + 1 return ThreeWordList[np.random.randint(count)]