Skip to content

Commit a5efcc7

Browse files
authored
Merge pull request #40 from jimbarrett27/self-reference-example
Add self-referential example
2 parents 03139ed + 3433701 commit a5efcc7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

examples/selfreferential.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import re
3+
from pathlib import Path
4+
5+
from wrdcld import make_word_cloud
6+
7+
FOLDER_PATH = Path("wrdcld")
8+
9+
all_text = ""
10+
for filename in os.listdir(FOLDER_PATH):
11+
if filename.endswith(".py"):
12+
with open(FOLDER_PATH / filename, "r", encoding="utf-8") as f:
13+
all_text += f.read()
14+
15+
cleaned_text = re.sub(r"[^a-zA-Z0-9_\s]", " ", all_text)
16+
all_words = cleaned_text.split()
17+
18+
19+
img = make_word_cloud(
20+
all_words=all_words,
21+
minimum_font_size=5,
22+
word_padding=3,
23+
)
24+
25+
img.show()

0 commit comments

Comments
 (0)