Path managment, read files in both Windows and Mac with the same code
Path in a Windows system looks like
my_data\\train\\
Path in a Mac system looks like
my_data/train/
I have been hard coded the path every time I want to use my code on a different system. A way to make things easier:
pathlib
from pathlib import Path
import glob
# Write path with forward slashes to create path, this will generate a path working in your current system
train_folder = Path("my_data/train")
# To combine with a file
train_file = train_folder / "data1.txt"
f = open(train_file)
# To use glob
files = glob.glob(str(train_folder/"*"))