parvaneh
parvaneh

Reputation: 530

Why does re.sub return None?

I have seen this function in some code on github, I think its aim is to clean up these signs from the input text, but I do not know why every string that is fed into this the output becomes None. Any help is appreciated.

def clean(self, text):
    text = re.sub('[^\w\s\d\'\-\"]','', text)
    text = text.lower()

Upvotes: 1

Views: 2040

Answers (1)

gilch
gilch

Reputation: 11681

Python functions that lack an explicit return statement implicilty return None. Your clean function does not have a return statement. You could try adding return text.

Upvotes: 3

Related Questions