Test File Path in Python on Mac - DevPops-Inc/python GitHub Wiki
• Press the command key and spacebar to launch Spotlight Search, type “terminal” and select the “Terminal” application.
•
• Type python3
and press the return key to launch the Python interactive shell.
•
• Type import os
and press the return key to import the os
module.
•
• Type from pathlib import Path
and press the return key to import the Path
object from the pathlib
module.
•
• 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.
•
• Type os.path.exists(< variable >)
and press the return key to test the file path and it will return either True
or False
.
•
• Type exit()
or quit()
and press the return key to exit the Python interactive shell and return to the UNIX-like shell.
•