Python > osパッケージのfunctionリストを取得してみる

```txt:動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)
```

http://qiita.com/7of9/items/526e8707ae6e7c4f3583#comment-b368d7b7ded184b4d7b6
> os.readlink() でシンボリックリンクが指しているファイル名を参照できます。

osパッケージにどんなfunctionがあるか気になりました。

https://docs.python.org/3/library/os.html
に記載がありますが、名前だけの一覧が欲しいと思い、functionリストを表示する実装を探しました。

### 実装

参考 http://stackoverflow.com/questions/1911281/how-do-i-get-list-of-methods-in-a-python-class

```test_python_170325b.py
import os
import inspect
#res = inspect.getmembers(os, predicate=inspect.isfunction)
res = inspect.getmembers(os)
for elem in res:
	print(elem)
```

```txt:実行
$ python test_python_170325b.py | grep function > res.function
```

```txt:res.function
('WCOREDUMP', <built-in function WCOREDUMP>)
('WEXITSTATUS', <built-in function WEXITSTATUS>)
('WIFCONTINUED', <built-in function WIFCONTINUED>)
('WIFEXITED', <built-in function WIFEXITED>)
('WIFSIGNALED', <built-in function WIFSIGNALED>)
('WIFSTOPPED', <built-in function WIFSTOPPED>)
('WSTOPSIG', <built-in function WSTOPSIG>)
('WTERMSIG', <built-in function WTERMSIG>)
('__builtins__', {'bytearray': <type 'bytearray'>, 'IndexError': <type 'exceptions.IndexError'>, 'all': <built-in function all>, 'help': Type help() for interactive help, or help(object) for help about object., 'vars': <built-in function vars>, 'SyntaxError': <type 'exceptions.SyntaxError'>, 'unicode': <type 'unicode'>, 'UnicodeDecodeError': <type 'exceptions.UnicodeDecodeError'>, 'memoryview': <type 'memoryview'>, 'isinstance': <built-in function isinstance>, 'copyright': Copyright (c) 2001-2014 Python Software Foundation.
All Rights Reserved., 'NameError': <type 'exceptions.NameError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'dict': <type 'dict'>, 'input': <built-in function input>, 'oct': <built-in function oct>, 'bin': <built-in function bin>, 'SystemExit': <type 'exceptions.SystemExit'>, 'StandardError': <type 'exceptions.StandardError'>, 'format': <built-in function format>, 'repr': <built-in function repr>, 'sorted': <built-in function sorted>, 'False': False, 'RuntimeWarning': <type 'exceptions.RuntimeWarning'>, 'list': <type 'list'>, 'iter': <built-in function iter>, 'reload': <built-in function reload>, 'Warning': <type 'exceptions.Warning'>, '__package__': None, 'round': <built-in function round>, 'dir': <built-in function dir>, 'cmp': <built-in function cmp>, 'set': <type 'set'>, 'bytes': <type 'str'>, 'reduce': <built-in function reduce>, 'intern': <built-in function intern>, 'issubclass': <built-in function issubclass>, 'Ellipsis': Ellipsis, 'EOFError': <type 'exceptions.EOFError'>, 'locals': <built-in function locals>, 'BufferError': <type 'exceptions.BufferError'>, 'slice': <type 'slice'>, 'FloatingPointError': <type 'exceptions.FloatingPointError'>, 'sum': <built-in function sum>, 'getattr': <built-in function getattr>, 'abs': <built-in function abs>, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'print': <built-in function print>, 'True': True, 'FutureWarning': <type 'exceptions.FutureWarning'>, 'ImportWarning': <type 'exceptions.ImportWarning'>, 'None': None, 'hash': <built-in function hash>, 'ReferenceError': <type 'exceptions.ReferenceError'>, 'len': <built-in function len>, 'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information., 'frozenset': <type 'frozenset'>, '__name__': '__builtin__', 'ord': <built-in function ord>, 'super': <type 'super'>, 'TypeError': <type 'exceptions.TypeError'>, 'license': See http://www.python.org/2.7/license.html, 'KeyboardInterrupt': <type 'exceptions.KeyboardInterrupt'>, 'UserWarning': <type 'exceptions.UserWarning'>, 'filter': <built-in function filter>, 'range': <built-in function range>, 'staticmethod': <type 'staticmethod'>, 'SystemError': <type 'exceptions.SystemError'>, 'BaseException': <type 'exceptions.BaseException'>, 'pow': <built-in function pow>, 'RuntimeError': <type 'exceptions.RuntimeError'>, 'float': <type 'float'>, 'MemoryError': <type 'exceptions.MemoryError'>, 'StopIteration': <type 'exceptions.StopIteration'>, 'globals': <built-in function globals>, 'divmod': <built-in function divmod>, 'enumerate': <type 'enumerate'>, 'apply': <built-in function apply>, 'LookupError': <type 'exceptions.LookupError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'basestring': <type 'basestring'>, 'UnicodeError': <type 'exceptions.UnicodeError'>, 'zip': <built-in function zip>, 'hex': <built-in function hex>, 'long': <type 'long'>, 'next': <built-in function next>, 'ImportError': <type 'exceptions.ImportError'>, 'chr': <built-in function chr>, 'xrange': <type 'xrange'>, 'type': <type 'type'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'Exception': <type 'exceptions.Exception'>, 'tuple': <type 'tuple'>, 'UnicodeTranslateError': <type 'exceptions.UnicodeTranslateError'>, 'reversed': <type 'reversed'>, 'UnicodeEncodeError': <type 'exceptions.UnicodeEncodeError'>, 'IOError': <type 'exceptions.IOError'>, 'hasattr': <built-in function hasattr>, 'delattr': <built-in function delattr>, 'setattr': <built-in function setattr>, 'raw_input': <built-in function raw_input>, 'SyntaxWarning': <type 'exceptions.SyntaxWarning'>, 'compile': <built-in function compile>, 'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'str': <type 'str'>, 'property': <type 'property'>, 'GeneratorExit': <type 'exceptions.GeneratorExit'>, 'int': <type 'int'>, '__import__': <built-in function __import__>, 'KeyError': <type 'exceptions.KeyError'>, 'coerce': <built-in function coerce>, 'PendingDeprecationWarning': <type 'exceptions.PendingDeprecationWarning'>, 'file': <type 'file'>, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, 'unichr': <built-in function unichr>, 'id': <built-in function id>, 'OSError': <type 'exceptions.OSError'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'min': <built-in function min>, 'UnicodeWarning': <type 'exceptions.UnicodeWarning'>, 'execfile': <built-in function execfile>, 'any': <built-in function any>, 'complex': <type 'complex'>, 'bool': <type 'bool'>, 'ValueError': <type 'exceptions.ValueError'>, 'NotImplemented': NotImplemented, 'map': <built-in function map>, 'buffer': <type 'buffer'>, 'max': <built-in function max>, 'object': <type 'object'>, 'TabError': <type 'exceptions.TabError'>, 'callable': <built-in function callable>, 'ZeroDivisionError': <type 'exceptions.ZeroDivisionError'>, 'eval': <built-in function eval>, '__debug__': True, 'IndentationError': <type 'exceptions.IndentationError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'classmethod': <type 'classmethod'>, 'UnboundLocalError': <type 'exceptions.UnboundLocalError'>, 'NotImplementedError': <type 'exceptions.NotImplementedError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'OverflowError': <type 'exceptions.OverflowError'>})
('__doc__', "OS routines for Mac, NT, or Posix depending on what system we're on.\n\nThis exports:\n  - all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.\n  - os.path is one of the modules posixpath, or ntpath\n  - os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos'\n  - os.curdir is a string representing the current directory ('.' or ':')\n  - os.pardir is a string representing the parent directory ('..' or '::')\n  - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\\\')\n  - os.extsep is the extension separator ('.' or '/')\n  - os.altsep is the alternate pathname separator (None or '/')\n  - os.pathsep is the component separator used in $PATH etc\n  - os.linesep is the line separator in text files ('\\r' or '\\n' or '\\r\\n')\n  - os.defpath is the default search path for executables\n  - os.devnull is the file path of the null device ('/dev/null', etc.)\n\nPrograms that import and use 'os' stand a better chance of being\nportable between different platforms.  Of course, they must then\nonly use functions that are defined by all platforms (e.g., unlink\nand opendir), and leave all pathname manipulation to os.path\n(e.g., split and join).\n")
('_execvpe', <function _execvpe at 0x7f5e90835140>)
('_exists', <function _exists at 0x7f5e907b5230>)
('_exit', <built-in function _exit>)
('_get_exports_list', <function _get_exports_list at 0x7f5e908656e0>)
('_make_stat_result', <function _make_stat_result at 0x7f5e907b5d70>)
('_make_statvfs_result', <function _make_statvfs_result at 0x7f5e907b5e60>)
('_pickle_stat_result', <function _pickle_stat_result at 0x7f5e907b5de8>)
('_pickle_statvfs_result', <function _pickle_statvfs_result at 0x7f5e907b5ed8>)
('_spawnvef', <function _spawnvef at 0x7f5e907b52a8>)
('abort', <built-in function abort>)
('access', <built-in function access>)
('chdir', <built-in function chdir>)
('chmod', <built-in function chmod>)
('chown', <built-in function chown>)
('chroot', <built-in function chroot>)
('close', <built-in function close>)
('closerange', <built-in function closerange>)
('confstr', <built-in function confstr>)
('ctermid', <built-in function ctermid>)
('dup', <built-in function dup>)
('dup2', <built-in function dup2>)
('execl', <function execl at 0x7f5e90838de8>)
('execle', <function execle at 0x7f5e90838e60>)
('execlp', <function execlp at 0x7f5e90838ed8>)
('execlpe', <function execlpe at 0x7f5e90838f50>)
('execv', <built-in function execv>)
('execve', <built-in function execve>)
('execvp', <function execvp at 0x7f5e90835050>)
('execvpe', <function execvpe at 0x7f5e908350c8>)
('fchdir', <built-in function fchdir>)
('fchmod', <built-in function fchmod>)
('fchown', <built-in function fchown>)
('fdatasync', <built-in function fdatasync>)
('fdopen', <built-in function fdopen>)
('fork', <built-in function fork>)
('forkpty', <built-in function forkpty>)
('fpathconf', <built-in function fpathconf>)
('fstat', <built-in function fstat>)
('fstatvfs', <built-in function fstatvfs>)
('fsync', <built-in function fsync>)
('ftruncate', <built-in function ftruncate>)
('getcwd', <built-in function getcwd>)
('getcwdu', <built-in function getcwdu>)
('getegid', <built-in function getegid>)
('getenv', <function getenv at 0x7f5e907bdb18>)
('geteuid', <built-in function geteuid>)
('getgid', <built-in function getgid>)
('getgroups', <built-in function getgroups>)
('getloadavg', <built-in function getloadavg>)
('getlogin', <built-in function getlogin>)
('getpgid', <built-in function getpgid>)
('getpgrp', <built-in function getpgrp>)
('getpid', <built-in function getpid>)
('getppid', <built-in function getppid>)
('getresgid', <built-in function getresgid>)
('getresuid', <built-in function getresuid>)
('getsid', <built-in function getsid>)
('getuid', <built-in function getuid>)
('initgroups', <built-in function initgroups>)
('isatty', <built-in function isatty>)
('kill', <built-in function kill>)
('killpg', <built-in function killpg>)
('lchown', <built-in function lchown>)
('link', <built-in function link>)
('listdir', <built-in function listdir>)
('lseek', <built-in function lseek>)
('lstat', <built-in function lstat>)
('major', <built-in function major>)
('makedev', <built-in function makedev>)
('makedirs', <function makedirs at 0x7f5e90838c08>)
('minor', <built-in function minor>)
('mkdir', <built-in function mkdir>)
('mkfifo', <built-in function mkfifo>)
('mknod', <built-in function mknod>)
('nice', <built-in function nice>)
('open', <built-in function open>)
('openpty', <built-in function openpty>)
('pathconf', <built-in function pathconf>)
('pipe', <built-in function pipe>)
('popen', <built-in function popen>)
('popen2', <function popen2 at 0x7f5e907b56e0>)
('popen3', <function popen3 at 0x7f5e907b5758>)
('popen4', <function popen4 at 0x7f5e907b57d0>)
('putenv', <built-in function putenv>)
('read', <built-in function read>)
('readlink', <built-in function readlink>)
('remove', <built-in function remove>)
('removedirs', <function removedirs at 0x7f5e90838c80>)
('rename', <built-in function rename>)
('renames', <function renames at 0x7f5e90838cf8>)
('rmdir', <built-in function rmdir>)
('setegid', <built-in function setegid>)
('seteuid', <built-in function seteuid>)
('setgid', <built-in function setgid>)
('setgroups', <built-in function setgroups>)
('setpgid', <built-in function setpgid>)
('setpgrp', <built-in function setpgrp>)
('setregid', <built-in function setregid>)
('setresgid', <built-in function setresgid>)
('setresuid', <built-in function setresuid>)
('setreuid', <built-in function setreuid>)
('setsid', <built-in function setsid>)
('setuid', <built-in function setuid>)
('spawnl', <function spawnl at 0x7f5e907b5500>)
('spawnle', <function spawnle at 0x7f5e907b5578>)
('spawnlp', <function spawnlp at 0x7f5e907b55f0>)
('spawnlpe', <function spawnlpe at 0x7f5e907b5668>)
('spawnv', <function spawnv at 0x7f5e907b5320>)
('spawnve', <function spawnve at 0x7f5e907b5398>)
('spawnvp', <function spawnvp at 0x7f5e907b5410>)
('spawnvpe', <function spawnvpe at 0x7f5e907b5488>)
('stat', <built-in function stat>)
('stat_float_times', <built-in function stat_float_times>)
('statvfs', <built-in function statvfs>)
('strerror', <built-in function strerror>)
('symlink', <built-in function symlink>)
('sysconf', <built-in function sysconf>)
('system', <built-in function system>)
('tcgetpgrp', <built-in function tcgetpgrp>)
('tcsetpgrp', <built-in function tcsetpgrp>)
('tempnam', <built-in function tempnam>)
('times', <built-in function times>)
('tmpfile', <built-in function tmpfile>)
('tmpnam', <built-in function tmpnam>)
('ttyname', <built-in function ttyname>)
('umask', <built-in function umask>)
('uname', <built-in function uname>)
('unlink', <built-in function unlink>)
('unsetenv', <built-in function unsetenv>)
('urandom', <built-in function urandom>)
('utime', <built-in function utime>)
('wait', <built-in function wait>)
('wait3', <built-in function wait3>)
('wait4', <built-in function wait4>)
('waitpid', <built-in function waitpid>)
('walk', <function walk at 0x7f5e90838d70>)
('write', <built-in function write>)
```

途中に関係ない文字列もありますが、だいたいfunctionをリスト化できていそうです。

気になったfunctionの詳細は以下で確認できる。

```
>>> import os
>>> help(os.access)
Help on built-in function access in module posix:

access(...)
    access(path, mode) -> True if granted, False otherwise
    
    Use the real uid/gid to test for access to a path.  Note that most
    operations will use the effective uid/gid, therefore this routine can
    be used in a suid/sgid environment to test if the invoking user has the
    specified access to the path.  The mode argument can be F_OK to test
    existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
(END)
```

### dir()

以前教えていただいたdir()を使うのも一覧性の参照性の高さから良いかもしれない。
http://qiita.com/7of9/items/1b78423cce1e75607195

```
>>> import os
>>> dir(os)
```

`
['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR', 'EX_NOHOST', 'EX_NOINPUT', 'EX_NOPERM', 'EX_NOUSER', 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL', 'EX_SOFTWARE', 'EX_TEMPFAIL', 'EX_UNAVAILABLE', 'EX_USAGE', 'F_OK', 'NGROUPS_MAX', 'O_APPEND', 'O_ASYNC', 'O_CREAT', 'O_DIRECT', 'O_DIRECTORY', 'O_DSYNC', 'O_EXCL', 'O_LARGEFILE', 'O_NDELAY', 'O_NOATIME', 'O_NOCTTY', 'O_NOFOLLOW', 'O_NONBLOCK', 'O_RDONLY', 'O_RDWR', 'O_RSYNC', 'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'P_NOWAIT', 'P_NOWAITO', 'P_WAIT', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'ST_APPEND', 'ST_MANDLOCK', 'ST_NOATIME', 'ST_NODEV', 'ST_NODIRATIME', 'ST_NOEXEC', 'ST_NOSUID', 'ST_RDONLY', 'ST_RELATIME', 'ST_SYNCHRONOUS', 'ST_WRITE', 'TMP_MAX', 'UserDict', 'WCONTINUED', 'WCOREDUMP', 'WEXITSTATUS', 'WIFCONTINUED', 'WIFEXITED', 'WIFSIGNALED', 'WIFSTOPPED', 'WNOHANG', 'WSTOPSIG', 'WTERMSIG', 'WUNTRACED', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list', '_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', '_spawnvef', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'chown', 'chroot', 'close', 'closerange', 'confstr', 'confstr_names', 'ctermid', 'curdir', 'defpath', 'devnull', 'dup', 'dup2', 'environ', 'errno', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fchdir', 'fchmod', 'fchown', 'fdatasync', 'fdopen', 'fork', 'forkpty', 'fpathconf', 'fstat', 'fstatvfs', 'fsync', 'ftruncate', 'getcwd', 'getcwdu', 'getegid', 'getenv', 'geteuid', 'getgid', 'getgroups', 'getloadavg', 'getlogin', 'getpgid', 'getpgrp', 'getpid', 'getppid', 'getresgid', 'getresuid', 'getsid', 'getuid', 'initgroups', 'isatty', 'kill', 'killpg', 'lchown', 'linesep', 'link', 'listdir', 'lseek', 'lstat', 'major', 'makedev', 'makedirs', 'minor', 'mkdir', 'mkfifo', 'mknod', 'name', 'nice', 'open', 'openpty', 'pardir', 'path', 'pathconf', 'pathconf_names', 'pathsep', 'pipe', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'readlink', 'remove', 'removedirs', 'rename', 'renames', 'rmdir', 'sep', 'setegid', 'seteuid', 'setgid', 'setgroups', 'setpgid', 'setpgrp', 'setregid', 'setresgid', 'setresuid', 'setreuid', 'setsid', 'setuid', 'spawnl', 'spawnle', 'spawnlp', 'spawnlpe', 'spawnv', 'spawnve', 'spawnvp', 'spawnvpe', 'stat', 'stat_float_times', 'stat_result', 'statvfs', 'statvfs_result', 'strerror', 'symlink', 'sys', 'sysconf', 'sysconf_names', 'system', 'tcgetpgrp', 'tcsetpgrp', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'ttyname', 'umask', 'uname', 'unlink', 'unsetenv', 'urandom', 'utime', 'wait', 'wait3', 'wait4', 'waitpid', 'walk', 'write']
`