Stack Overflow Asked on February 1, 2021
I am wanting to read the contents of a text file and filter out the bad word from it.
{UPDATED} So I updated my python file after what you told me but right now I am getting a no module error. When I run pip3 install profanity_filter it gives me a big error.
I researched and found Profanity but it is not working
from profanity_filter import ProfanityFilter
pf = ProfanityFilter()
with open(input("Enter the name Of Your File"), "r") as myFile:
j = myFile.read()
filtered = pf.censor(j)
print(filtered)
You need to create an instance of the class, and then call its censor()
method.
And the argument has to be a string, not a list of strings. Call read()
instead of readlines()
to get the entire file as a single string.
from profanity_filter import ProfanityFilter
pf = ProfanityFilter()
with open(input("Enter the name Of Your File"), "r") as myFile:
j = myFile.read()
filtered = pf.censor(j)
print(filtered)
Answered by Barmar on February 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP