-
Notifications
You must be signed in to change notification settings - Fork 1
/
path_manipulation.Rmd
43 lines (33 loc) · 1.21 KB
/
path_manipulation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
jupyter:
orphan: true
jupytext:
text_representation:
extension: .Rmd
format_name: rmarkdown
format_version: '1.2'
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
# Making and breaking file paths in Python
## Pathnames
A pathname is a string that identifies a particular file or directory on a
computer filesystem.
For example, we can ask the pathname of the directory containing this notebook, using the `getcwd` function from the `os` module.
```{python}
import os
os.getcwd()
```
## Two ways of manipulating pathnames
There are two standard ways of manipulating pathnames in Python.
* [The pathlib module](pathlib.Rmd)
* [The os.path module](os_path.Rmd)
Of the two techniques, the `os.path` way is rather simpler, but it covers a
smaller range of tasks. It can also be more verbose. `pathlib` does more, and
can give you nice-looking, concise code, but it does rely on a particularly
Python way of thinking. You will see examples of both in lots of modern code,
but we will use `pathlib` in this textbook, because it will likely be the
method you end up using when you are more experienced writing Python code.