teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

__path__ではなく__file__による方法に修正

2017/08/14 12:56

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  `time`モジュールはPython(インタプリタ)内部に[標準モジュール](https://docs.python.jp/3/tutorial/modules.html#standard-modules)として組み込まれています。よって、ファイル検索などしても見つかりません。
2
2
  標準モジュールの一覧は[sys.builtin_module_names](https://docs.python.jp/3/library/sys.html#sys.builtin_module_names)で確認表示できます。
3
3
 
4
- 標準モジュール以外であれば`__path__`でモジュール(パッケージ)パスが確認できます。
4
+ 標準モジュール以外であれば`__file__`でモジュール(パッケージ)ファイルパスが確認できます。
5
5
  参考:[Python Tips:ライブラリ・モジュールの場所を調べたい](http://www.lifewithpython.com/2014/07/python-get-location-of-libraries-modules-packages.html)
6
6
 
7
7
  ```Python

2

__path__について追記

2017/08/14 12:55

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -1,12 +1,20 @@
1
1
  `time`モジュールはPython(インタプリタ)内部に[標準モジュール](https://docs.python.jp/3/tutorial/modules.html#standard-modules)として組み込まれています。よって、ファイル検索などしても見つかりません。
2
2
  標準モジュールの一覧は[sys.builtin_module_names](https://docs.python.jp/3/library/sys.html#sys.builtin_module_names)で確認表示できます。
3
3
 
4
+ 標準モジュール以外であれば`__path__`でモジュール(パッケージ)のパスが確認できます。
5
+ 参考:[Python Tips:ライブラリ・モジュールの場所を調べたい](http://www.lifewithpython.com/2014/07/python-get-location-of-libraries-modules-packages.html)
4
6
 
5
7
  ```Python
6
8
  import sys
7
9
  print(sys.builtin_module_names)
10
+ import os
11
+ print(os.__file__)
12
+ import http
13
+ print(http.__file__)
8
14
  ```
9
15
  結果例
10
16
  ```
11
17
  ('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_collections', '_csv', '_datetime', '_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5', '_multibytecodec', '_opcode', '_operator', '_pickle', '_random', '_sha1', '_sha256', '_sha512', '_signal', '_sre', '_stat', '_string', '_struct', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', '_winapi', 'array', 'atexit', 'audioop', 'binascii', 'builtins', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'math', 'mmap', 'msvcrt', 'nt', 'parser', 'sys', 'time', 'winreg', 'xxsubtype', 'zipimport', 'zlib')
18
+ C:\Program Files\Anaconda3\lib\os.py
19
+ C:\Program Files\Anaconda3\lib\http\__init__.py
12
20
  ```

1

誤字修正

2017/08/14 12:54

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -1,4 +1,4 @@
1
- `time`モジュールはPython(インタプリタ)内部に[標準モジュール](https://docs.python.jp/3/tutorial/modules.html#standard-modules)として組み込まれています。よって、ファイル検索などしても見つかりません。
1
+ `time`モジュールはPython(インタプリタ)内部に[標準モジュール](https://docs.python.jp/3/tutorial/modules.html#standard-modules)として組み込まれています。よって、ファイル検索などしても見つかりません。
2
2
  標準モジュールの一覧は[sys.builtin_module_names](https://docs.python.jp/3/library/sys.html#sys.builtin_module_names)で確認表示できます。
3
3
 
4
4