Test File Path in Python on Mac - VicPhanDevOps/mac GitHub Wiki

• Press the command key and spacebar to launch Spotlight Search, type “terminal” and select the “Terminal” application.
image

• Type python3 and press the return key to launch the Python interactive shell.
image

• Type import os and press the return key to import the os module.
image

• Type from pathlib import Path and press the return key to import the Path object from the pathlib module.
image

• Type variable = Path(“< file path >”) and press the return key to declare a variable and set its value as the file path you wish to test.
image

• Type os.path.exists(< variable >) and press the return key to test the file path and it will return either True or False.
image

• Type exit() or quit() and press the return key to exit the Python interactive shell and return to the UNIX-like shell.
image

⚠️ **GitHub.com Fallback** ⚠️