import osmain_dir = '/code/'sub_dir = 'project/sub/'filename = 'README.md'# /code/project/sub/README.mdos.path.join(main_dir, sub_dir, filename)
NOTE: Becareful if sub_dir is /project/sub/
, the output will be /project/sub/README.md
instead.
You could use pathlib
as well, which comes with useful file operations
from pathlib import Pathmain_dir = '/code/'sub_dir = 'project/sub/'filename = 'README.md'path = Path(main_dir, sub_dir, filename)path.is_file()
References: