Skip to content

Commit a0c4531

Browse files
committed
📝 Switch from os.path to pathlib
1 parent c1846fb commit a0c4531

File tree

7 files changed

+458
-756
lines changed

7 files changed

+458
-756
lines changed

docs/appendix/checks.rst

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -981,22 +981,20 @@ Checks
981981
You can find a complete example at `github.com/veit/items
982982
<https://github.com/veit/items/>`_.
983983

984-
:doc:`/save-data/files`
985-
-----------------------
984+
:doc:`/save-data/files-directories`
985+
-----------------------------------
986986

987-
* Uses the functions of the :mod:`python3:os` module to take a path to a file
988-
named :file:`example.log` and create a new file path in the same directory for
989-
a file named :file:`example.log1`.
987+
* Use the functions of the :mod:`python3:pathlib` module to take a path to a
988+
file named :file:`example.log` and create a new file path in the same
989+
directory for a file named :file:`example.log1`.
990990

991991
.. code-block:: pycon
992992
993-
>>> import os
994-
>>> path = os.path.abspath("example.log")
995-
>>> print(path)
996-
/Users/veit/python-basics-tutorial-de/example.log
997-
>>> new_path = f"{path}2"
998-
>>> print(new_path)
999-
/Users/veit/python-basics-tutorial-de/example.log2
993+
>>> from pathlib import Path
994+
>>> l = Path("logs", "instance.log")
995+
>>> l1 = Path("logs", "instance.log1")
996+
>>> l.rename(l1)
997+
PosixPath('logs/instance.log1')
1000998
1001999
* What is the significance of adding ``b`` as a :term:`parameter` to
10021000
:func:`python3:open`?
@@ -1010,31 +1008,12 @@ Checks
10101008

10111009
.. code-block:: pycon
10121010
1013-
>>> with open("my_file", "a") as f:
1014-
... f.write("Hi, Pythinistas!\n")
1015-
...
1011+
>>> from pathlib import Path
1012+
>>> p = Path("docs", "save-data", "myfile.txt")
1013+
>>> p.write_text("Hi, Pythonistas!\n")
10161014
17
1017-
>>> with open("my_file") as f:
1018-
... print(f.readlines())
1019-
...
1020-
['Hi, Pythinistas!\n', 'Hi, Pythinistas!\n']
1021-
1022-
* What use cases can you imagine in which the :mod:`python3:struct` module would
1023-
be useful for reading or writing binary data?
1024-
1025-
* when reading and writing a binary file
1026-
* when reading from an external interface, where the data should be stored
1027-
exactly as it was transmitted
1028-
1029-
* Why :doc:`pickle <python3:library/pickle>` may or may not be suitable for the
1030-
following use cases:
1031-
1032-
#. Saving some state variables from one run to the next ✅
1033-
#. Storing evaluation results ❌, as pickle is dependent on the respective
1034-
Python version
1035-
#. Saving user names and passwords ❌, as pickles are not secure
1036-
#. Saving a large dictionary with English terms ❌, as the entire pickle would
1037-
have to be loaded into memory
1015+
>>> p.read_text()
1016+
'Hi, Pythonistas!\n'
10381017
10391018
* If you look at the `man page for the wc utility
10401019
<https://linux.die.net/man/1/wc>`_, you will see two command line options:
@@ -1099,3 +1078,23 @@ Checks
10991078
writes the current file to the ZIP file.
11001079
Line 13
11011080
removes the current file from the working directory.
1081+
1082+
:doc:`/save-data/modules`
1083+
-------------------------
1084+
1085+
* What use cases can you imagine in which the :mod:`python3:struct` module would
1086+
be useful for reading or writing binary data?
1087+
1088+
* when reading and writing a binary file
1089+
* when reading from an external interface, where the data should be stored
1090+
exactly as it was transmitted
1091+
1092+
* Why :doc:`pickle <python3:library/pickle>` may or may not be suitable for the
1093+
following use cases:
1094+
1095+
#. Saving some state variables from one run to the next ✅
1096+
#. Storing evaluation results ❌, as pickle is dependent on the respective
1097+
Python version
1098+
#. Saving user names and passwords ❌, as pickles are not secure
1099+
#. Saving a large dictionary with English terms ❌, as the entire pickle would
1100+
have to be loaded into memory

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"sphinx.ext.autodoc",
4646
"sphinx.ext.graphviz",
4747
"sphinx.ext.intersphinx",
48-
"sphinx.ext.intersphinx",
4948
"sphinx.ext.viewcode",
5049
"sphinx_copybutton",
5150
"sphinx_inline_tabs",
@@ -60,6 +59,7 @@
6059

6160
intersphinx_mapping = {
6261
"python3": ("https://docs.python.org/3/", None),
62+
"python3.14": ("https://docs.python.org/3.14/", None),
6363
"jupyter-tutorial": ("https://jupyter-tutorial.readthedocs.io/en/latest/", None),
6464
"Python4DataScience": ("https://www.python4data.science/en/latest/", None),
6565
"pytest": ("https://docs.pytest.org/en/latest/", None),

0 commit comments

Comments
 (0)