8.2 Moving around the file system
If you have used a command line in Windows, macOS, or Linux, you know about the idea of the “current working directory” and how to move to another directory. Python has the same concept and functionality.
Figure 8.3 is another partial view of the directory tree for the files that make up this book.
If I am in the src
directory, I can issue pwd
on
the operating system command line and see something like
Path
----
C:\src
on Windows, or
/src
on macOS or Linux. “pwd
” is an abbreviation for
“print working directory.” The corresponding
Python function is getcwd, which is short for “get the
current working directory,”
import os
os.getcwd()
'C:\\src'
I issue cd code
on the command...