Skip to content

Commit

Permalink
Fix minor formatting glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
rafrafavi authored May 6, 2024
1 parent 5219275 commit 8e77a1f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions assessments/prj/carpark-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ Create a new local branch named `feature/log-car-activity`. You can do this eith
#### Log cars entering and leaving in a file called `log.txt`
**Detour – Python file handling:**
Python is a multi-platform language. This means that it can run on different operating systems. However, different operating systems have different ways of representing files and paths. We therefore want to _abstract_ this representation away from our code. We can do this using the `pathlib` module. This module provides a platform-independent way to represent files and paths. We can use it to create a `Path` object representing a file or directory. We can then use this object to create, read, write, and delete files and directories.
Python is a multi-platform language. This means that it can run on different operating systems. However, different operating systems have different ways of representing files and paths. We, therefore, want to _abstract_ this representation away from our code. We can do this using the `pathlib` module. This module provides a platform-independent way to represent files and paths. We can use it to create a `Path` object representing a file or directory. We can then use this object to create, read, write, and delete files and directories.
Typically, we import the `Path` class from the `pathlib` module. We can then use the `Path` class to create a `Path` object. For example, `Path("log.txt")` creates a `Path` object that represents a file called `log.txt`. We can then use the `Path` object to create, read, write, and delete files and directories.
Expand Down Expand Up @@ -862,11 +862,14 @@ When a test creates a file, it is **not** cleaned up automatically. So, we want
Path("new_log.txt").unlink(missing_ok=True)
```
--------
**Bonus:**
---
:bulb:
Unlink? What does that mean? It turns out that when you delete files on most operating systems, you unlink the file from a directory entry. The data is still there but can now be overwritten. When we program, we often use the more precise and explicit terms.
--------
---
Notice how we have inadvertently made our test code hard to maintain (if we change the log file's name, we have to change it in two places). Can you think of a way to improve this code? Hint: consider using a class attribute or new instance variable in the `setUp` method.
Expand Down

0 comments on commit 8e77a1f

Please sign in to comment.