boB

boB

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

Where Next?

Popular Pragmatic Bookshelf topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
Mmm
Hi, build fails on: bracket-lib = “~0.8.1” when running on Mac Mini M1 Rust version 1.5.0: Compiling winit v0.22.2 error[E0308]: mi...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New

Sub Categories: