python path example

Example 1: file path in python for windows

outputFileName = 'Destination/With/Forward/Slash/filename.txt'

Example 2: windows how to store filepath as variabley python

from pathlib import Path

docs_folder = Path("some_folder/some_folder/")
text_file = docs_folder / "some_file.txt"
f = open(text_file)

#note must use forward slashes as pathlib will convert these to \\ for windows

Example 3: what does filename = path(file).stem python

from pathlib import Path

Path('/root/dir/sub/file.ext').stem

# returns 'file'