Practical Programming, Third Edition: Statement about current working directory on p. 177 is incorrect.

On page 177 the authors state: “…When you run a Python program, the current working directory is the directory where that program is saved…” This is incorrect. The current working directory will be whatever the current directory is from which the program is started. For instance the following demonstrates this:


import os

print(“Testing!”)
print("Current working directory: ", os.getcwd())
print("Source code file: ", file)
with open(‘test_text.txt’) as f:
print(f.read())

PS C:> Users\boB\Practical_Programming\testing.py # NOT the
program directory.
Testing!
Current working directory: C:
Source code file: C:\Users\boB\Practical_Programming\testing.py
Traceback (most recent call last):
File “C:\Users\boB\Practical_Programming\testing.py”, line 6, in
with open(‘test_text.txt’) as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘test_text.txt’
PS C:> cd .\Users\boB\Practical_Programming
PS C:\Users\boB\Practical_Programming> .\testing.py # Now in the
program’s folder.
Testing!
Current working directory: C:\Users\boB\Practical_Programming
Source code file: C:\Users\boB\Practical_Programming\testing.py
This is just a plain text file of no import.
This is the second line of a boring file.

Cheers!
boB Stepp