Skip to content

Commit 5889cf4

Browse files
committed
Use Path.cwd() instead of Path.home()
1 parent 5ccdff7 commit 5889cf4

7 files changed

+11
-20
lines changed

ch12-file-input-and-output/4-challenge-move-all-image-files-to-a-new-directory.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
from pathlib import Path
55

66
# Change this path to match the location on your computer
7-
documents_dir = (
8-
Path.home() /
9-
"python-basics-exercises" /
10-
"ch11-file-input-and-output" /
11-
"practice_files" /
12-
"documents"
13-
)
7+
documents_dir = Path.cwd() / "practice_files" / "documents"
148

159
# Create an images/ directory in your home directory
1610
images_dir = Path.home() / "images"

ch12-file-input-and-output/7-challenge-create-a-high-scores-list.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
# Change the path below to match the location on your computer
88
scores_csv_path = (
9-
Path.home()
10-
/ "github/realpython"
11-
/ "python-basics-exercises"
12-
/ "ch12-file-input-and-output"
9+
Path.cwd()
1310
/ "practice_files"
14-
"scores.csv"
11+
/ "scores.csv"
1512
)
1613

1714
with scores_csv_path.open(mode="r", encoding="utf-8") as file:
@@ -35,7 +32,7 @@
3532
# The high_scores dictionary now contains one key for each name that was
3633
# in the scores.csv file, and each value is that player's highest score.
3734

38-
output_csv_file = Path.home() / "high_scores.csv"
35+
output_csv_file = Path.cwd() / "high_scores.csv"
3936
with output_csv_file.open(mode="w", encoding="utf-8") as file:
4037
writer = csv.DictWriter(file, fieldnames=["name", "high_score"])
4138
writer.writeheader()

ch14-interact-with-pdf-files/1-extract-text-from-a-pdf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from PyPDF2 import PdfFileReader
1616

1717
# To create a PdfFileReader instance, you need to path to the PDF file.
18-
# We'll assume you downloaded the solutions folder and extracted it into
19-
# the home directory on your computer. If this is not the case, you'll
18+
# We'll assume you downloaded the solutions folder and are running this
19+
# program from the solutions folder. If this is not the case, you'll
2020
# need to update the path below.
21-
pdf_path = Path.home() / "python-basics-exercises/ch14-interact-with-pdf-files/practice_files/zen.pdf"
21+
pdf_path = Path.cwd() / "practice_files" / "zen.pdf"
2222

2323
# Now you can create the PdfFileReader instance. Remember that
2424
# PdfFileReader objects can only be instantiated with path strings, not

ch14-interact-with-pdf-files/4-concatenating-and-merging-pdfs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from PyPDF2 import PdfFileMerger
1616

1717

18-
BASE_PATH = Path.home() / "python-basics-exercises/ch14-interact-with-pdf-files/practice_files"
18+
BASE_PATH = Path.cwd() / "practice_files"
1919

2020
pdf_paths = [BASE_PATH / "merge1.pdf", BASE_PATH / "merge2.pdf"]
2121
pdf_merger = PdfFileMerger()

ch14-interact-with-pdf-files/5-rotating-and-cropping-pdf-pages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from PyPDF2 import PdfFileReader, PdfFileWriter
1616

1717

18-
pdf_path = Path.home() / "python-basics-exercises/ch14-interact-with-pdf-files/practice_files/split_and_rotate.pdf"
18+
pdf_path = Path.cwd() / "practice_files" / "split_and_rotate.pdf"
1919

2020
pdf_reader = PdfFileReader(str(pdf_path))
2121
pdf_writer = PdfFileWriter()

ch14-interact-with-pdf-files/6-encrypting-and-decrypting-pdfs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from PyPDF2 import PdfFileReader, PdfFileWriter
1616

1717

18-
pdf_path = Path.home() / "python-basics-exercises/ch14-interact-with-pdf-files/practice_files/top_secret.pdf"
18+
pdf_path = Path.cwd() / "practice_files" / "top_secret.pdf"
1919

2020
pdf_reader = PdfFileReader(str(pdf_path))
2121
pdf_writer = PdfFileWriter()

ch14-interact-with-pdf-files/7-challenge-unscramble-a-pdf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_page_text(page):
1010
return page.extractText()
1111

1212

13-
pdf_path = Path.home() / "python-basics-exercises/ch14-interact-with-pdf-files/practice_files/scrambled.pdf"
13+
pdf_path = Path.cwd() / "practice_files" / "scrambled.pdf"
1414

1515
pdf_reader = PdfFileReader(str(pdf_path))
1616
pdf_writer = PdfFileWriter()

0 commit comments

Comments
 (0)