Skip to content

Commit

Permalink
Fix weird linebreak in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
dostuffthatmatters committed Feb 11, 2024
1 parent a9428eb commit c3ab98e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
26 changes: 12 additions & 14 deletions docs/pages/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,22 @@ def read_last_n_lines(file_path: str,

Read the last `n` lines of a file.

The function returns less than `n` lines if the file has less than `n` lines.
The last element in the list is the last line of the file.
The function returns less than `n` lines if the file has less than `n` lines.
The last element in the list is the last line of the file.

This function uses seeking in order not to read the full file. The simple
approach of reading the last n lines would be:
This function uses seeking in order not to read the full file. The simple
approach of reading the last 10 lines would be:

```python
# read the last 10 lines
with open(path, "r") as f:
return f.read().split("
")[:-10]
```
```python
with open(path, "r") as f:
return f.read().split("\n")[:-10]
```

However, this would read the full file and if we only need to read 10 lines
out of a 2GB file, this would be a big waste of resources.
However, this would read the full file and if we only need to read 10 lines
out of a 2GB file, this would be a big waste of resources.

The `ignore_trailing_whitespace` option to crop off trailing whitespace, i.e.
only return the last `n` lines that are not empty or only contain whitespace.
The `ignore_trailing_whitespace` option to crop off trailing whitespace, i.e.
only return the last `n` lines that are not empty or only contain whitespace.


## `tum_esm_utils.github`
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tum_esm_utils"
version = "1.9.0"
version = "1.9.1"
description = "Python utilities by the Professorship of Environmental Sensing and Modeling at the Technical University of Munich"
authors = [{ name = "Moritz Makowski", email = "[email protected]" }]
dependencies = [
Expand Down
5 changes: 2 additions & 3 deletions tum_esm_utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,11 @@ def read_last_n_lines(
The last element in the list is the last line of the file.
This function uses seeking in order not to read the full file. The simple
approach of reading the last n lines would be:
approach of reading the last 10 lines would be:
```python
# read the last 10 lines
with open(path, "r") as f:
return f.read().split("\n")[:-10]
return f.read().split("\\n")[:-10]
```
However, this would read the full file and if we only need to read 10 lines
Expand Down

0 comments on commit c3ab98e

Please sign in to comment.