LoginSignup
2
1

More than 5 years have passed since last update.

Python > help(): Runtime error | builtin module namesを表示する > sys.builtin_module_names | mathはbuiltinなのかどうか問題 (macOS + homebrew | CentOS | Ubuntu)

Last updated at Posted at 2018-01-25
動作環境
ideone (Python 3.5)

Python3.7のmathの場所
を見て、help()を使ってFILEの位置以降を表示しようとした。

以下を試みたが、Runtime errorになる。

import math

res = help(math)
for elem in res:
    print(elem)

help()を使わない方法を検討した。
別途以下を見つけた。
https://stackoverflow.com/questions/8370206/how-to-get-a-list-of-built-in-modules-in-python

import sys

print(sys.builtin_module_names)

実行結果は以下のようになった。


('_ast', '_bisect', '_codecs', '_collections', '_datetime', '_elementtree', '_functools', '_heapq', '_imp', '_io', '_locale', '_md5', '_operator', '_pickle', '_posixsubprocess', '_random', '_sha1', '_sha256', '_sha512', '_signal', '_socket', '_sre', '_stat', '_string', '_struct', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', 'array', 'atexit', 'binascii', 'builtins', 'errno', 'faulthandler', 'fcntl', 'gc', 'grp', 'itertools', 'marshal', 'math', 'posix', 'pwd', 'pyexpat', 'select', 'spwd', 'sys', 'syslog', 'time', 'unicodedata', 'xxsubtype', 'zipimport', 'zlib')

Python 3.5でもmathはbuiltinのようだ。

(追記 2018/01/25)
別途、Mac OS X + homebrew + Python3.6(@knoguchi さんのコメント)やCentOS6.8+Python3.6.4ではmathはbuiltinではないようです。

関連

検索用キーワード

@knoguchi さんとのコメントで登場したキーワードです。
コメントは検索できないので。

2
1
9

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1