Skip to content

Commit a4d3340

Browse files
committed
Remove punctuation
1 parent ec5a280 commit a4d3340

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

make_structure.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
4 Testing lab
2626
"""
2727
import subprocess
28+
import string
2829
import sys
2930
import os
3031

32+
# https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string
33+
def remove_punctuation(s):
34+
return s.translate(str.maketrans('', '', string.punctuation))
35+
3136
def main():
3237
with open('outline.txt', 'r') as f:
3338
text = f.read().strip().strip('\n')
@@ -36,7 +41,7 @@ def main():
3641
chapter_num, chapter_name = line.split('\t')
3742

3843
# Convert casing: "Example code" to "example-code"
39-
normalized_chapter_name = chapter_name.replace(' ', '-').lower()
44+
normalized_chapter_name = remove_punctuation(chapter_name).replace(' ', '-').lower()
4045
# Make directories
4146
dir_name = "r" + chapter_num.strip() + '-' + normalized_chapter_name.strip()
4247
subprocess.run(["mkdir", "-p", os.path.join(os.getcwd(), dir_name)])

0 commit comments

Comments
 (0)