回答編集履歴
1
説明追加
answer
CHANGED
@@ -6,4 +6,43 @@
|
|
6
6
|
```python
|
7
7
|
from pathlib import Path
|
8
8
|
```
|
9
|
-
に変更しましょう。
|
9
|
+
に変更しましょう。
|
10
|
+
|
11
|
+
原因説明
|
12
|
+
|
13
|
+
import pathlib as Path
|
14
|
+
|
15
|
+
は以下とほぼ同等です。
|
16
|
+
```python
|
17
|
+
import pathlib
|
18
|
+
Path = pathlib
|
19
|
+
```
|
20
|
+
|
21
|
+
一方で、
|
22
|
+
|
23
|
+
from pathlib import Path
|
24
|
+
|
25
|
+
は以下とほぼ同等です。
|
26
|
+
```python
|
27
|
+
import pathlib
|
28
|
+
Path = pathlib.Path
|
29
|
+
```
|
30
|
+
import pathlib as Pathの場合、Pathはmoduleです。
|
31
|
+
|
32
|
+
```python
|
33
|
+
>>> import pathlib as Path
|
34
|
+
>>> print(Path)
|
35
|
+
<module 'pathlib' from 'C:\Users\myname\anaconda3\lib\pathlib.py'>
|
36
|
+
```
|
37
|
+
そのため
|
38
|
+
|
39
|
+
TypeError: 'module' object is not callable
|
40
|
+
|
41
|
+
となります。
|
42
|
+
|
43
|
+
```python
|
44
|
+
>>> from pathlib import Path
|
45
|
+
>>> print(Path)
|
46
|
+
<class 'pathlib.Path'>
|
47
|
+
```
|
48
|
+
だとPathはclass ですのでcallableとなります。
|