You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,14 +8,14 @@ Handling file and directory Paths
8
8
</base-title>
9
9
10
10
There are two main modules in Python that deal with path manipulation.
11
-
One is the `os.path` module and the other is the `pathlib` module.
11
+
One is the <router-linkto="/modules/os-module">os.path</router-link> module and the other is the <router-linkto="/modules/pathlib-module">pathlib</router-link> module.
12
12
13
13
<base-disclaimer>
14
14
<base-disclaimer-title>
15
-
os.path VS pathlib
15
+
Pathlib vs Os Module
16
16
</base-disclaimer-title>
17
17
<base-disclaimer-content>
18
-
The `pathlib` module was added in Python 3.4, offering an object-oriented way to handle file system paths.
18
+
<code>pathlib</code> provides a lot more functionality than the ones listed above, like getting file name, getting file extension, reading/writing a file without manually opening it, etc. See the <a target="_blank" href="https://docs.python.org/3/library/pathlib.html">official documentation</a> if you intend to know more.
19
19
</base-disclaimer-content>
20
20
</base-disclaimer>
21
21
@@ -26,19 +26,9 @@ folder names. On Unix based operating system such as macOS, Linux, and BSDs,
26
26
the forward slash (`/`) is used as the path separator. Joining paths can be
27
27
a headache if your code needs to work on different platforms.
28
28
29
-
Fortunately, Python provides easy ways to handle this. We will showcase
30
-
how to deal with both, `os.path.join` and `pathlib.Path.joinpath`
31
-
32
-
Using `os.path.join` on Windows:
33
-
34
-
```python
35
-
>>>import os
36
-
37
-
>>> os.path.join('usr', 'bin', 'spam')
38
-
# 'usr\\bin\\spam'
39
-
```
29
+
Fortunately, Python's `pathlib` module provides an easy way to handle this.
40
30
41
-
And using`pathlib` on \*nix:
31
+
Using`pathlib` on \*nix:
42
32
43
33
```python
44
34
>>>from pathlib import Path
@@ -57,25 +47,12 @@ And using `pathlib` on \*nix:
57
47
```
58
48
59
49
Notice the path separator is different between Windows and Unix based operating
60
-
system, that's why you want to use one of the above methods instead of
50
+
system, that's why you want to use `pathlib` instead of
61
51
adding strings together to join paths together.
62
52
63
53
Joining paths is helpful if you need to create different file paths under
`pathlib` provides a lot more functionality than the ones listed above, like getting file name, getting file extension, reading/writing a file without manually opening it, etc. See the <a target="_blank" href="https://docs.python.org/3/library/pathlib.html">official documentation</a> if you intend to know more.
528
-
</base-disclaimer-content>
529
-
</base-disclaimer>
530
-
531
-
<see-also>
532
-
<see-also-title>
533
-
See also
534
-
</see-also-title>
535
-
<see-also-content>
536
-
<ul>
537
-
<li><router-link to="/modules/os-module">Python Os Module</router-link></li>
0 commit comments