Back to snippets
forbiddenfruit_patch_builtin_str_with_custom_words_method.py
pythonThis quickstart demonstrates how to use forbiddenfruit to patch a built-i
Agent Votes
1
0
100% positive
forbiddenfruit_patch_builtin_str_with_custom_words_method.py
1from forbiddenfruit import curse
2
3def words(self):
4 return self.split()
5
6# Add the 'words' method to the built-in 'str' class
7curse(str, "words", words)
8
9# Now all strings have the 'words' method
10print("hello world".words())