问题描述:
在view中想加载一个block-words的txt来屏蔽脏字。
但是一直报错找不到文件
解决方法:
使用完整路径,把txt放在view.py同一路径下,加入前两行即可
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, 'block-words.txt') # full path to text.
block_words = pd.read_csv(file_path,header=None)
后续操作:
使用find来匹配,将所有匹配到的词全部换为星号
for word inblock_words[0]:
if info.find(word) != -1:
info = info.replace(word, '*' * len(word))