"os" — 雑多なオペレーティングシステムインタフェース
***************************************************

このモジュールは、 OS 依存の機能を利用するポータブルな方法を提供します
。単純なファイルの読み書きについては、 "open()" を参照してください。パ
ス操作については、 "os.path" モジュールを参照してください。コマンドラ
インに与えられたすべてのファイルから行を読み込んでいくには、
"fileinput" モジュールを参照してください。一時ファイルや一時ディレクト
リの作成については、 "tempfile" モジュールを参照してください。高水準の
ファイルとディレクトリの操作については、 "shutil" モジュールを参照して
ください。

利用可能性に関する注意 :

* Python の、すべての OS 依存モジュールの設計方針は、可能な限り同一
  の インタフェースで同一の機能を利用できるようにする、というものです
  。例 えば、 "os.stat(path)" は *path* に関する stat 情報を、 (POSIX
  を元 にした ) 同じフォーマットで返します。

* 特定のオペレーティングシステム固有の拡張も "os" を介して利用するこ
  と ができますが、これらの利用はもちろん、可搬性を脅かします。

* 「利用できる環境 : Unix 」の意味はこの関数が Unix システムにあるこ
  と が多いということです。このことは特定の OS における存在を主張する
  もの ではありません。

* 特に記述がない場合、「利用できる環境 : Unix 」と書かれている関数は
  、 Unix をコアにしている Mac OS X でも利用することができます。

注釈: このモジュール内のすべての関数は、間違った、あるいはアクセス出
  来ない ファイル名やファイルパス、その他型が合っていても OS が受理し
  ない引数 に対して、 "OSError" を送出します。

exception os.error

   組み込みの "OSError" 例外に対するエイリアスです。

os.name

   The name of the operating system dependent module imported.  The
   following names have currently been registered: "'posix'", "'nt'",
   "'os2'", "'ce'", "'java'", "'riscos'".

   参考: "sys.platform" はより細かな粒度を持っています。
     "os.uname()" はシ ステム依存のバージョン情報を提供します。

     "platform" モジュールはシステムの詳細な識別情報をチェックする機能
     を提供しています。


プロセスのパラメーター
======================

これらの関数とデータアイテムは、現在のプロセスおよびユーザーに対する情
報提供および操作のための機能を提供しています。

os.environ

   文字列の環境を表す *マップ型* オブジェクトです。例えば、
   "environ['HOME']" は (一部のプラットフォームでは) ホームディレクト
   リのパス名であり、 C における "getenv("HOME")" と等価です。

   このマップ型の内容は、 "os" モジュールの最初の import の時点、通常
   は Python の起動時に "site.py" が処理される中で取り込まれます。それ
   以後に変更された環境変数は "os.environ" を直接変更しない限り
   "os.environ" には反映されません。

   プラットフォーム上で "putenv()" がサポートされている場合、このマッ
   プ型オブジェクトは環境変数に対する変更に使うこともできます。
   "putenv()" はマップ型オブジェクトが修正される時に、自動的に呼ばれる
   ことになります。

   注釈: "putenv()" を直接呼び出しても "os.environ" の内容は変わらな
     いので 、 "os.environ" を直接変更する方が良いです。

   注釈: FreeBSD と Mac OS X を含む一部のプラットフォームでは、
     "environ" の値を変更するとメモリリークの原因になる場合があります
     。システム の "putenv()" に関するドキュメントを参照してください。

   "putenv()" が提供されていない場合、このマップ型オブジェクトに変更を
   加えたコピーを適切なプロセス生成機能に渡すことで、生成された子プロ
   セスが変更された環境変数を利用するようにできます。

   プラットフォームが "unsetenv()" 関数をサポートしている場合、このマ
   ップ型オブジェクトからアイテムを削除することで環境変数を消すことが
   できます。 "unsetenv()" は "os.environ" からアイテムが取り除かれた
   時に自動的に呼ばれます。 "pop()" または "clear()" が呼ばれた時も同
   様です。

   バージョン 2.6 で変更: Also unset environment variables when
   calling "os.environ.clear()" and "os.environ.pop()".

os.chdir(path)
os.fchdir(fd)
os.getcwd()

   これらの関数は、 ファイルとディレクトリ 節で説明されています。

os.ctermid()

   プロセスの制御端末に対応するファイル名を返します。

   利用できる環境 : Unix 。

os.getegid()

   現在のプロセスの実効グループ id を返します。この id は現在のプロセ
   スで実行されているファイルの 「set id」 ビットに対応します。

   利用できる環境 : Unix 。

os.geteuid()

   現在のプロセスの実効ユーザー id を返します。

   利用できる環境 : Unix 。

os.getgid()

   現在のプロセスの実グループ id を返します。

   利用できる環境 : Unix 。

os.getgroups()

   現在のプロセスに関連付けられた従属グループ id のリストを返します。

   利用できる環境 : Unix 。

   注釈: Mac OS X では "getgroups()" の挙動は他の Unix プラットフォ
     ームと はいくぶん異なります。 Python のインタープリタが "10.5" 以
     前の Deployment Target でビルドされている場合、 "getgroups()" は
     現在の ユーザープロセスに関連付けられている実効グループ id を返し
     ます。 このリストはシステムで定義されたエントリ数 ( 通常は 16) に
     制限さ れ、適切な特権があれば "setgroups()" の呼び出しによって変
     更するこ とができます。 "10.5" より新しい Deployment Target でビ
     ルドされて いる場合、 "getgroups()" はプロセスの実効ユーザー id
     に関連付けら れたユーザーの現在のグループアクセスリストを返します
     。このグルー プアクセスリストは、プロセスのライフタイムで変更され
     る可能性があ り、 "setgroups()" の呼び出しの影響を受けず、長さ 16
     の制限を受け ません。 Deployment Target の値
     "MACOSX_DEPLOYMENT_TARGET" は、 "sysconfig.get_config_var()" で取
     得することができます。

os.initgroups(username, gid)

   システムの initgroups() を呼び出し、指定された *username* がメンバ
   ーである全グループと *gid* で指定されたグループでグループアクセスリ
   ストを初期化します。

   利用できる環境 : Unix 。

   バージョン 2.7 で追加.

os.getlogin()

   Return the name of the user logged in on the controlling terminal
   of the process.  For most purposes, it is more useful to use the
   environment variable "LOGNAME" to find out who the user is, or
   "pwd.getpwuid(os.getuid())[0]" to get the login name of the
   process’s real user id.

   利用できる環境 : Unix 。

os.getpgid(pid)

   プロセス id *pid* のプロセスのプロセスグループ id を返します。
   *pid* が 0 の場合、現在のプロセスのプロセスグループ id を返します。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.getpgrp()

   現在のプロセスグループの id を返します。

   利用できる環境 : Unix 。

os.getpid()

   現在のプロセス id を返します。

   利用できる環境 : Unix 、 Windows 。

os.getppid()

   Return the parent’s process id.

   利用できる環境 : Unix 。

os.getresuid()

   現在のプロセスの実ユーザー id 、実効ユーザー id 、および保存ユーザ
   ー id を示す、 (ruid, euid, suid) のタプルを返します。

   利用できる環境 : Unix 。

   バージョン 2.7 で追加.

os.getresgid()

   現在のプロセスの実グループ id 、実効グループ id 、および保存グルー
   プ id を示す、 (rgid, egid, sgid) のタプルを返します。

   利用できる環境 : Unix 。

   バージョン 2.7 で追加.

os.getuid()

   現在のプロセスの実ユーザー id を返します。

   利用できる環境 : Unix 。

os.getenv(varname[, value])

   Return the value of the environment variable *varname* if it
   exists, or *value* if it doesn’t.  *value* defaults to "None".

   利用できる環境 : 主な Unix 互換環境、 Windows 。

os.putenv(varname, value)

   Set the environment variable named *varname* to the string *value*.
   Such changes to the environment affect subprocesses started with
   "os.system()", "popen()" or "fork()" and "execv()".

   利用できる環境 : 主な Unix 互換環境、 Windows 。

   注釈: FreeBSD と Mac OS X を含む一部のプラットフォームでは、
     "environ" の値を変更するとメモリリークの原因になる場合があります
     。システム の putenv に関するドキュメントを参照してください。

   "putenv()" がサポートされている場合、 "os.environ" のアイテムに対す
   る代入を行うと、自動的に "putenv()" の対応する呼び出しに変換されま
   す。直接 "putenv()" を呼び出した場合 "os.environ" は更新されないた
   め、実際には "os.environ" のアイテムに代入する方が望ましい操作です
   。

os.setegid(egid)

   現在のプロセスに実効グループ id をセットします。

   利用できる環境 : Unix 。

os.seteuid(euid)

   現在のプロセスに実効ユーザー id をセットします。

   利用できる環境 : Unix 。

os.setgid(gid)

   現在のプロセスにグループ id をセットします。

   利用できる環境 : Unix 。

os.setgroups(groups)

   現在のグループに関連付けられた従属グループ id のリストを *groups*
   に設定します。 *groups* はシーケンス型でなくてはならず、各要素はグ
   ループを特定する整数でなくてはなりません。通常、この操作はスーパユ
   ーザーしか利用できません。

   利用できる環境 : Unix 。

   バージョン 2.2 で追加.

   注釈: Mac OS X では、 *groups* の長さはシステムで定義された実効グ
     ループ id の最大数 ( 通常は 16) を超えない場合があります。
     setgroups() 呼び出しで設定されたものと同じグループリストが返され
     ないケースに ついては、 "getgroups()" のドキュメントを参照してく
     ださい。

os.setpgrp()

   システムコール "setpgrp()" か "setpgrp(0, 0)" のどちらか(実装されて
   いるもの)を呼び出します。機能については UNIX マニュアルを参照して下
   さい。

   利用できる環境 : Unix 。

os.setpgid(pid, pgrp)

   システムコール "setpgid()" を呼び出してプロセス id *pid* のプロセス
   のプロセスグループ id を *pgrp* に設定します。この動作に関しては
   Unix のマニュアルを参照してください。

   利用できる環境 : Unix 。

os.setregid(rgid, egid)

   現在のプロセスの実グループ id および実効グループ id を設定します。

   利用できる環境 : Unix 。

os.setresgid(rgid, egid, sgid)

   現在のプロセスの、実グループ id 、実効グループ id 、および保存グル
   ープ id を設定します。

   利用できる環境 : Unix 。

   バージョン 2.7 で追加.

os.setresuid(ruid, euid, suid)

   現在のプロセスの実ユーザー id 、実効ユーザー id 、および保存ユーザ
   ー id を設定します。

   利用できる環境 : Unix 。

   バージョン 2.7 で追加.

os.setreuid(ruid, euid)

   現在のプロセスの実ユーザー id および実効ユーザー id を設定します。

   利用できる環境 : Unix 。

os.getsid(pid)

   "getsid()" システムコールを呼び出します。機能については Unix のマニ
   ュアルを参照してください。

   利用できる環境 : Unix 。

   バージョン 2.4 で追加.

os.setsid()

   "setsid()" システムコールを呼び出します。機能については Unix のマニ
   ュアルを参照してください。

   利用できる環境 : Unix 。

os.setuid(uid)

   現在のプロセスのユーザー id を設定します。

   利用できる環境 : Unix 。

os.strerror(code)

   エラーコード *code* に対応するエラーメッセージを返します。未知のエ
   ラーコードの対して "strerror()" が "NULL" を返すプラットフォームで
   は、 "ValueError" が送出されます。

   利用できる環境 : Unix 、 Windows 。

os.umask(mask)

   現在の数値 umask を設定し、以前の umask 値を返します。

   利用できる環境 : Unix 、 Windows 。

os.uname()

   Return a 5-tuple containing information identifying the current
   operating system.  The tuple contains 5 strings: "(sysname,
   nodename, release, version, machine)".  Some systems truncate the
   nodename to 8 characters or to the leading component; a better way
   to get the hostname is "socket.gethostname()"  or even
   "socket.gethostbyaddr(socket.gethostname())".

   利用できる環境 : Unix 互換環境。

os.unsetenv(varname)

   Unset (delete) the environment variable named *varname*. Such
   changes to the environment affect subprocesses started with
   "os.system()", "popen()" or "fork()" and "execv()".

   "unsetenv()" がサポートされている場合、 "os.environ" のアイテムの削
   除を行うと、自動的に "unsetenv()" の対応する呼び出しに変換されます
   。直接 "unsetenv()" を呼び出した場合 "os.environ" は更新されないた
   め、実際には "os.environ" のアイテムを削除する方が望ましい操作です
   。

   利用できる環境 : 主な Unix 互換環境、 Windows 。


ファイルオブジェクトの生成
==========================

These functions create new file objects. (See also "open()".)

os.fdopen(fd[, mode[, bufsize]])

   Return an open file object connected to the file descriptor *fd*.
   The *mode* and *bufsize* arguments have the same meaning as the
   corresponding arguments to the built-in "open()" function.  If
   "fdopen()" raises an exception, it leaves *fd* untouched
   (unclosed).

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.3 で変更: When specified, the *mode* argument must now
   start with one of the letters "'r'", "'w'", or "'a'", otherwise a
   "ValueError" is raised.

   バージョン 2.5 で変更: On Unix, when the *mode* argument starts
   with "'a'", the *O_APPEND* flag is set on the file descriptor
   (which the "fdopen()" implementation already does on most
   platforms).

os.popen(command[, mode[, bufsize]])

   Open a pipe to or from *command*.  The return value is an open file
   object connected to the pipe, which can be read or written
   depending on whether *mode* is "'r'" (default) or "'w'". The
   *bufsize* argument has the same meaning as the corresponding
   argument to the built-in "open()" function.  The exit status of the
   command (encoded in the format specified for "wait()") is available
   as the return value of the "close()" method of the file object,
   except that when the exit status is zero (termination without
   errors), "None" is returned.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.6 で撤廃: This function is obsolete.  Use the
   "subprocess" module.  Check especially the 古い関数を subprocess モ
   ジュールで置き換える section.

   バージョン 2.0 で変更: This function worked unreliably under
   Windows in earlier versions of Python. This was due to the use of
   the "_popen()" function from the libraries provided with Windows.
   Newer versions of Python do not use the broken implementation from
   the Windows libraries.

os.tmpfile()

   Return a new file object opened in update mode ("w+b").  The file
   has no directory entries associated with it and will be
   automatically deleted once there are no file descriptors for the
   file.

   利用できる環境 : Unix 、 Windows 。

There are a number of different "popen*()" functions that provide
slightly different ways to create subprocesses.

バージョン 2.6 で撤廃: All of the "popen*()" functions are obsolete.
Use the "subprocess" module.

For each of the "popen*()" variants, if *bufsize* is specified, it
specifies the buffer size for the I/O pipes. *mode*, if provided,
should be the string "'b'" or "'t'"; on Windows this is needed to
determine whether the file objects should be opened in binary or text
mode.  The default value for *mode* is "'t'".

Also, for each of these variants, on Unix, *cmd* may be a sequence, in
which case arguments will be passed directly to the program without
shell intervention (as with "os.spawnv()"). If *cmd* is a string it
will be passed to the shell (as with "os.system()").

These methods do not make it possible to retrieve the exit status from
the child processes.  The only way to control the input and output
streams and also retrieve the return codes is to use the "subprocess"
module; these are only available on Unix.

For a discussion of possible deadlock conditions related to the use of
these functions, see フロー制御の問題.

os.popen2(cmd[, mode[, bufsize]])

   Execute *cmd* as a sub-process and return the file objects
   "(child_stdin, child_stdout)".

   バージョン 2.6 で撤廃: This function is obsolete.  Use the
   "subprocess" module.  Check especially the 古い関数を subprocess モ
   ジュールで置き換える section.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.0 で追加.

os.popen3(cmd[, mode[, bufsize]])

   Execute *cmd* as a sub-process and return the file objects
   "(child_stdin, child_stdout, child_stderr)".

   バージョン 2.6 で撤廃: This function is obsolete.  Use the
   "subprocess" module.  Check especially the 古い関数を subprocess モ
   ジュールで置き換える section.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.0 で追加.

os.popen4(cmd[, mode[, bufsize]])

   Execute *cmd* as a sub-process and return the file objects
   "(child_stdin, child_stdout_and_stderr)".

   バージョン 2.6 で撤廃: This function is obsolete.  Use the
   "subprocess" module.  Check especially the 古い関数を subprocess モ
   ジュールで置き換える section.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.0 で追加.

(Note that "child_stdin, child_stdout, and child_stderr" are named
from the point of view of the child process, so *child_stdin* is the
child’s standard input.)

This functionality is also available in the "popen2" module using
functions of the same names, but the return values of those functions
have a different order.


ファイル記述子の操作
====================

これらの関数は、ファイル記述子を使って参照されている I/O ストリームを
操作します。

ファイル記述子とは現在のプロセスで開かれたファイルに対応する小さな整数
です。例えば、標準入力のファイル記述子は通常 0 で、標準出力は 1 、標準
エラーは 2 です。プロセスから開かれたその他のファイルには 3 、 4 、 5
と割り振られていきます。「ファイル記述子」という名称は少し誤解を与える
ものかもしれません。Unix プラットフォームでは、ソケットやパイプもファ
イル記述子によって参照されます。

The "fileno()" method can be used to obtain the file descriptor
associated with a file object when required.  Note that using the file
descriptor directly will bypass the file object methods, ignoring
aspects such as internal buffering of data.

os.close(fd)

   ファイル記述子 *fd* をクローズします。

   利用できる環境 : Unix 、 Windows 。

   注釈: この関数は低水準の I/O 向けのもので、 "os.open()" や
     "pipe()" が 返すファイル記述子に対して使用しなければなりません。
     組み込み関数 "open()" や "popen()" 、 "fdopen()" が返す 「ファイ
     ルオブジェクト 」 を閉じるには、オブジェクトの "close()" メソッド
     を使用してくだ さい。

os.closerange(fd_low, fd_high)

   Close all file descriptors from *fd_low* (inclusive) to *fd_high*
   (exclusive), ignoring errors. Equivalent to:

      for fd in xrange(fd_low, fd_high):
          try:
              os.close(fd)
          except OSError:
              pass

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.6 で追加.

os.dup(fd)

   Return a duplicate of file descriptor *fd*.

   利用できる環境 : Unix 、 Windows 。

os.dup2(fd, fd2)

   Duplicate file descriptor *fd* to *fd2*, closing the latter first
   if necessary.

   利用できる環境 : Unix 、 Windows 。

os.fchmod(fd, mode)

   Change the mode of the file given by *fd* to the numeric *mode*.
   See the docs for "chmod()" for possible values of *mode*.

   利用できる環境 : Unix 。

   バージョン 2.6 で追加.

os.fchown(fd, uid, gid)

   Change the owner and group id of the file given by *fd* to the
   numeric *uid* and *gid*.  To leave one of the ids unchanged, set it
   to -1.

   利用できる環境 : Unix 。

   バージョン 2.6 で追加.

os.fdatasync(fd)

   ファイル記述子 *fd* を持つファイルのディスクへの書き込みを強制しま
   す。メタデータの更新は強制しません。

   利用できる環境 : Unix 。

   注釈: この関数は MacOS では利用できません。

os.fpathconf(fd, name)

   開いているファイルに関連するシステム設定情報を返します。 *name* は
   取得する設定名を指定します。これは、いくつかの標準 (POSIX.1 、 Unix
   95 、 Unix 98 その他 ) で定義された定義済みのシステム値名の文字列で
   ある場合があります。プラットフォームによっては別の名前も定義されて
   います。ホストオペレーティングシステムの関知する名前は
   "pathconf_names" 辞書で与えられています。このマップ型オブジェクトに
   含まれていない構成変数については、 *name* に整数を渡してもかまいま
   せん。

   *name* が不明の文字列である場合、 "ValueError" を送出します。
   *name* の特定の値がホストシステムでサポートされていない場合、
   "pathconf_names" に含まれていたとしても、 "errno.EINVAL" をエラー番
   号として "OSError" を送出します。

   利用できる環境 : Unix 。

os.fstat(fd)

   Return status for file descriptor *fd*, like "stat()".

   利用できる環境 : Unix 、 Windows 。

os.fstatvfs(fd)

   Return information about the filesystem containing the file
   associated with file descriptor *fd*, like "statvfs()".

   利用できる環境 : Unix 。

os.fsync(fd)

   ファイル記述子 *fd* を持つファイルのディスクへの書き込みを強制しま
   す。 Unix では、ネイティブの "fsync()" 関数を、 Windows では
   "_commit()" 関数を呼び出します。

   If you’re starting with a Python file object *f*, first do
   "f.flush()", and then do "os.fsync(f.fileno())", to ensure that all
   internal buffers associated with *f* are written to disk.

   Availability: Unix, and Windows starting in 2.2.3.

os.ftruncate(fd, length)

   Truncate the file corresponding to file descriptor *fd*, so that it
   is at most *length* bytes in size.

   利用できる環境 : Unix 。

os.isatty(fd)

   ファイル記述子 *fd* がオープンされていて、 tty (のような) デバイス
   に接続されている場合、 "True" を返します。そうでない場合は "False"
   を返します。

os.lseek(fd, pos, how)

   ファイル記述子 *fd* の現在の位置を *pos* に設定します。 *pos* の意
   味は *how* で次のように修飾されます。ファイルの先頭からの相対位置に
   は "SEEK_SET" か "0" を、現在の位置からの相対位置には "SEEK_CUR" か
   "1" を、ファイルの末尾からの相対位置には "SEEK_END" か "2" を設定し
   ます。戻り値は、新しいカーソル位置のファイルの先頭からのバイト数で
   す。

   利用できる環境 : Unix 、 Windows 。

os.SEEK_SET
os.SEEK_CUR
os.SEEK_END

   "lseek()" 関数に渡すパラメーター。値は順に 0, 1, 2 です。

   Availability: Windows, Unix.

   バージョン 2.5 で追加.

os.open(file, flags[, mode])

   Open the file *file* and set various flags according to *flags* and
   possibly its mode according to *mode*. The default *mode* is "0777"
   (octal), and the current umask value is first masked out.  Return
   the file descriptor for the newly opened file.

   For a description of the flag and mode values, see the C run-time
   documentation; flag constants (like "O_RDONLY" and "O_WRONLY") are
   defined in this module too (see open() flag constants).  In
   particular, on Windows adding "O_BINARY" is needed to open files in
   binary mode.

   利用できる環境 : Unix 、 Windows 。

   注釈: This function is intended for low-level I/O.  For normal
     usage, use the built-in function "open()", which returns a 「file
     object 」 with "read()" and "write()" methods (and many more).
     To wrap a file descriptor in a 「file object」, use "fdopen()".

os.openpty()

   Open a new pseudo-terminal pair. Return a pair of file descriptors
   "(master, slave)" for the pty and the tty, respectively. For a
   (slightly) more portable approach, use the "pty" module.

   利用できる環境 : 一部の Unix 互換環境。

os.pipe()

   Create a pipe.  Return a pair of file descriptors "(r, w)" usable
   for reading and writing, respectively.

   利用できる環境 : Unix 、 Windows 。

os.read(fd, n)

   Read at most *n* bytes from file descriptor *fd*. Return a string
   containing the bytes read.  If the end of the file referred to by
   *fd* has been reached, an empty string is returned.

   利用できる環境 : Unix 、 Windows 。

   注釈: この関数は低水準の I/O 向けのもので、 "os.open()" や
     "pipe()" が 返すファイル記述子に対して使用されなければなりません
     。 組み込み関 数 "open()" や "popen()" 、 "fdopen()" 、あるいは
     "sys.stdin" が 返す 「ファイルオブジェクト」 を読み込むには、オブ
     ジェクトの "read()" か "readline()" メソッドを使用してください。

os.tcgetpgrp(fd)

   *fd* ("os.open()" が返すオープンしたファイル記述子 ) で与えられる端
   末に関連付けられたプロセスグループを返します。

   利用できる環境 : Unix 。

os.tcsetpgrp(fd, pg)

   *fd* ("os.open()" が返すオープンしたファイル記述子 ) で与えられる端
   末に関連付けられたプロセスグループを *pg* に設定します。

   利用できる環境 : Unix 。

os.ttyname(fd)

   ファイル記述子 *fd* に関連付けられている端末デバイスを特定する文字
   列を返します。 *fd* が端末に関連付けられていない場合、例外が送出さ
   れます。

   利用できる環境 : Unix 。

os.write(fd, str)

   Write the string *str* to file descriptor *fd*. Return the number
   of bytes actually written.

   利用できる環境 : Unix 、 Windows 。

   注釈: この関数は低水準の I/O 向けのもので、 "os.open()" や
     "pipe()" が 返すファイル記述子に対して使用しなければなりません。
     組み込み関数 "open()" や "popen()" 、 "fdopen()" 、あるいは
     "sys.stdout" や "sys.stderr" が返す 「ファイルオブジェクト」 に書
     き込むには、オブ ジェクトの "write()" メソッドを使用してください
     。


"open()" flag constants
-----------------------

The following constants are options for the *flags* parameter to the
"open()" function.  They can be combined using the bitwise OR operator
"|".  Some of them are not available on all platforms.  For
descriptions of their availability and use, consult the *open(2)*
manual page on Unix or the MSDN on Windows.

os.O_RDONLY
os.O_WRONLY
os.O_RDWR
os.O_APPEND
os.O_CREAT
os.O_EXCL
os.O_TRUNC

   上記の定数は Unix および Windows で利用可能です。

os.O_DSYNC
os.O_RSYNC
os.O_SYNC
os.O_NDELAY
os.O_NONBLOCK
os.O_NOCTTY

   上記の定数は Unix でのみ利用可能です。

os.O_BINARY
os.O_NOINHERIT
os.O_SHORT_LIVED
os.O_TEMPORARY
os.O_RANDOM
os.O_SEQUENTIAL
os.O_TEXT

   上記の定数は Windows でのみ利用可能です。

os.O_ASYNC
os.O_DIRECT
os.O_DIRECTORY
os.O_NOFOLLOW
os.O_NOATIME
os.O_SHLOCK
os.O_EXLOCK

   上記の定数は拡張仕様であり、Cライブラリで定義されていない場合は利用
   できません。


ファイルとディレクトリ
======================

os.access(path, mode)

   実 uid/gid を使って *path* に対するアクセスが可能か調べます。ほとん
   どのオペレーティングシステムは実効 uid/gid を使うため、このルーチン
   は suid/sgid 環境において、プログラムを起動したユーザーが *path* に
   対するアクセス権をもっているかを調べるために使われます。 *path* が
   存在するかどうかを調べるには *mode* を "F_OK" にします。ファイルア
   クセス権限 ( パーミッション ) を調べるには、 "R_OK", "W_OK", "X_OK"
   から一つまたはそれ以上のフラグを論理和指定でとることもできます。ア
   クセスが許可されている場合 "True" を、そうでない場合 "False" を返し
   ます。詳細は *access(2)* の Unix マニュアルページを参照してください
   。

   利用できる環境 : Unix 、 Windows 。

   注釈: ユーザーが、例えばファイルを開く権限を持っているかどうかを
     調べる ために実際に "open()" を行う前に "access()" を使用すること
     はセキ ュリティホールの原因になります。なぜなら、調べた時点とオー
     プンし た時点との時間差を利用してそのユーザーがファイルを不当に操
     作して しまうかもしれないからです。その場合は *EAFP* テクニックを
     利用す るのが望ましいやり方です。例えば

        if os.access("myfile", os.R_OK):
            with open("myfile") as fp:
                return fp.read()
        return "some default data"

     このコードは次のように書いたほうが良いです

        try:
            fp = open("myfile")
        except IOError as e:
            if e.errno == errno.EACCES:
                return "some default data"
            # Not a permission error.
            raise
        else:
            with fp:
                return fp.read()

   注釈: I/O 操作は "access()" が成功を示した時でも失敗することがあ
     ります 。特にネットワークファイルシステムが通常の POSIX のパーミ
     ッション ビットモデルをはみ出すアクセス権限操作を備える場合にはそ
     のような ことが起こりえます。

os.F_OK

   Value to pass as the *mode* parameter of "access()" to test the
   existence of *path*.

os.R_OK

   Value to include in the *mode* parameter of "access()" to test the
   readability of *path*.

os.W_OK

   Value to include in the *mode* parameter of "access()" to test the
   writability of *path*.

os.X_OK

   Value to include in the *mode* parameter of "access()" to determine
   if *path* can be executed.

os.chdir(path)

   現在の作業ディレクトリを *path* に設定します。

   利用できる環境 : Unix 、 Windows 。

os.fchdir(fd)

   Change the current working directory to the directory represented
   by the file descriptor *fd*.  The descriptor must refer to an
   opened directory, not an open file.

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.getcwd()

   現在の作業ディレクトリを表す文字列を返します。

   利用できる環境 : Unix 、 Windows 。

os.getcwdu()

   Return a Unicode object representing the current working directory.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.3 で追加.

os.chflags(path, flags)

   *path* のフラグを *flags* に変更します。 *flags* は、以下の値
   ("stat" モジュールで定義されているもの ) をビット単位の論理和で組み
   合わせることができます :

   * "stat.UF_NODUMP"

   * "stat.UF_IMMUTABLE"

   * "stat.UF_APPEND"

   * "stat.UF_OPAQUE"

   * "stat.UF_NOUNLINK"

   * "stat.UF_COMPRESSED"

   * "stat.UF_HIDDEN"

   * "stat.SF_ARCHIVED"

   * "stat.SF_IMMUTABLE"

   * "stat.SF_APPEND"

   * "stat.SF_NOUNLINK"

   * "stat.SF_SNAPSHOT"

   利用できる環境 : Unix 。

   バージョン 2.6 で追加.

os.chroot(path)

   Change the root directory of the current process to *path*.
   Availability: Unix.

   バージョン 2.2 で追加.

os.chmod(path, mode)

   *path* のモードを数値 *mode* に変更します。 *mode* は、 ("stat" モ
   ジュールで定義されている ) 以下の値のいずれかまたはビット単位の論理
   和で組み合わせた値を取り得ます :

   * "stat.S_ISUID"

   * "stat.S_ISGID"

   * "stat.S_ENFMT"

   * "stat.S_ISVTX"

   * "stat.S_IREAD"

   * "stat.S_IWRITE"

   * "stat.S_IEXEC"

   * "stat.S_IRWXU"

   * "stat.S_IRUSR"

   * "stat.S_IWUSR"

   * "stat.S_IXUSR"

   * "stat.S_IRWXG"

   * "stat.S_IRGRP"

   * "stat.S_IWGRP"

   * "stat.S_IXGRP"

   * "stat.S_IRWXO"

   * "stat.S_IROTH"

   * "stat.S_IWOTH"

   * "stat.S_IXOTH"

   利用できる環境 : Unix 、 Windows 。

   注釈: Although Windows supports "chmod()", you can only  set the
     file’s read-only flag with it (via the "stat.S_IWRITE"  and
     "stat.S_IREAD" constants or a corresponding integer value).  All
     other bits are ignored.

os.chown(path, uid, gid)

   Change the owner and group id of *path* to the numeric *uid* and
   *gid*. To leave one of the ids unchanged, set it to -1.

   利用できる環境 : Unix 。

os.lchflags(path, flags)

   Set the flags of *path* to the numeric *flags*, like "chflags()",
   but do not follow symbolic links.

   利用できる環境 : Unix 。

   バージョン 2.6 で追加.

os.lchmod(path, mode)

   Change the mode of *path* to the numeric *mode*. If path is a
   symlink, this affects the symlink rather than the target. See the
   docs for "chmod()" for possible values of *mode*.

   利用できる環境 : Unix 。

   バージョン 2.6 で追加.

os.lchown(path, uid, gid)

   Change the owner and group id of *path* to the numeric *uid* and
   *gid*. This function will not follow symbolic links.

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.link(source, link_name)

   Create a hard link pointing to *source* named *link_name*.

   利用できる環境 : Unix 。

os.listdir(path)

   Return a list containing the names of the entries in the directory
   given by *path*.  The list is in arbitrary order.  It does not
   include the special entries "'.'" and "'..'" even if they are
   present in the directory.

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.3 で変更: On Windows NT/2k/XP and Unix, if *path* is a
   Unicode object, the result will be a list of Unicode objects.
   Undecodable filenames will still be returned as string objects.

os.lstat(path)

   Perform the equivalent of an "lstat()" system call on the given
   path. Similar to "stat()", but does not follow symbolic links.  On
   platforms that do not support symbolic links, this is an alias for
   "stat()".

os.mkfifo(path[, mode])

   Create a FIFO (a named pipe) named *path* with numeric mode *mode*.
   The default *mode* is "0666" (octal).  The current umask value is
   first masked out from the mode.

   利用できる環境 : Unix 。

   FIFO は通常のファイルのようにアクセスできるパイプです。 FIFO は (
   例えば "os.unlink()" を使って ) 削除されるまで存在しつづけます。一
   般的に、 FIFO は 」 クライアント 」 と 」 サーバー 」 形式のプロセ
   ス間でランデブーを行うために使われます : この時、サーバーは FIFO を
   読み込み用に、クライアントは書き出し用にオープンします。 "mkfifo()"
   は FIFO をオープンしない — 単にランデブーポイントを作成するだけ —
   なので注意してください。

os.mknod(filename[, mode=0600[, device=0]])

   Create a filesystem node (file, device special file or named pipe)
   named *filename*. *mode* specifies both the permissions to use and
   the type of node to be created, being combined (bitwise OR) with
   one of "stat.S_IFREG", "stat.S_IFCHR", "stat.S_IFBLK", and
   "stat.S_IFIFO" (those constants are available in "stat"). For
   "stat.S_IFCHR" and "stat.S_IFBLK", *device* defines the newly
   created device special file (probably using "os.makedev()"),
   otherwise it is ignored.

   バージョン 2.3 で追加.

os.major(device)

   RAW デバイス番号から、デバイスのメジャー番号を取り出します ( 通常
   "stat" の "st_dev" か "st_rdev" フィールドです ) 。

   バージョン 2.3 で追加.

os.minor(device)

   RAW デバイス番号から、デバイスのマイナー番号を取り出します ( 通常
   "stat" の "st_dev" か "st_rdev" フィールドです ) 。

   バージョン 2.3 で追加.

os.makedev(major, minor)

   メジャーおよびマイナーデバイス番号から、新しく RAW デバイス番号を作
   成します。

   バージョン 2.3 で追加.

os.mkdir(path[, mode])

   Create a directory named *path* with numeric mode *mode*. The
   default *mode* is "0777" (octal).  If the directory already exists,
   "OSError" is raised.

   いくつかのシステムにおいては *mode* は無視されます。それが使われる
   時には、最初に現在の umask 値でマスクされます。もし最後の 9 ビット
   (つまり *mode* の8進法表記の最後の3桁) を除いたビットが設定されてい
   たら、それらの意味はプラットフォームに依存します。いくつかのプラッ
   トフォームではそれらは無視され、それらを設定するためには明示的に
   "chmod()" を呼ぶ必要があるでしょう。

   一時ディレクトリを作成することもできます : "tempfile" モジュールの
   "tempfile.mkdtemp()" 関数を参照してください。

   利用できる環境 : Unix 、 Windows 。

os.makedirs(path[, mode])

   Recursive directory creation function.  Like "mkdir()", but makes
   all intermediate-level directories needed to contain the leaf
   directory.  Raises an "error" exception if the leaf directory
   already exists or cannot be created.  The default *mode* is "0777"
   (octal).

   *mode* パラメータは "mkdir()" に渡されます; それがどのように解釈さ
   れるかは mkdir() の説明 を見てください。

   注釈: "makedirs()" will become confused if the path elements to
     create include "os.pardir".

   バージョン 1.5.2 で追加.

   バージョン 2.3 で変更: This function now handles UNC paths
   correctly.

os.pathconf(path, name)

   名前付きファイルに関連するシステム設定情報を返します。 *name* には
   取得したい設定名を指定します ; これは定義済みのシステム値名の文字列
   で、多くの標準 (POSIX.1 、 Unix 95 、 Unix 98 その他 ) で定義されて
   います。プラットフォームによっては別の名前も定義しています。ホスト
   オペレーティングシステムの関知する名前は "pathconf_names" 辞書で与
   えられています。このマップ型オブジェクトに入っていない設定変数につ
   いては、 *name* に整数を渡してもかまいません。

   *name* が不明の文字列である場合、 "ValueError" を送出します。
   *name* の特定の値がホストシステムでサポートされていない場合、
   "pathconf_names" に含まれていたとしても、 "errno.EINVAL" をエラー番
   号として "OSError" を送出します。

   利用できる環境 : Unix 。

os.pathconf_names

   Dictionary mapping names accepted by "pathconf()" and "fpathconf()"
   to the integer values defined for those names by the host operating
   system.  This can be used to determine the set of names known to
   the system. Availability: Unix.

os.readlink(path)

   シンボリックリンクが指しているパスを表す文字列を返します。返される
   値は絶対パスにも、相対パスにもなり得ます ; 相対パスの場合、
   "os.path.join(os.path.dirname(path), result)" を使って絶対パスに変
   換することができます。

   バージョン 2.6 で変更: If the *path* is a Unicode object the result
   will also be a Unicode object.

   利用できる環境 : Unix 。

os.remove(path)

   Remove (delete) the file *path*.  If *path* is a directory,
   "OSError" is raised; see "rmdir()" below to remove a directory.
   This is identical to the "unlink()" function documented below.  On
   Windows, attempting to remove a file that is in use causes an
   exception to be raised; on Unix, the directory entry is removed but
   the storage allocated to the file is not made available until the
   original file is no longer in use.

   利用できる環境 : Unix 、 Windows 。

os.removedirs(path)

   再帰的なディレクトリ削除関数です。 "rmdir()" と同じように動作します
   が、末端ディレクトリがうまく削除できるかぎり、 "removedirs()" は
   *path* に現れる親ディレクトリをエラーが送出されるまで ( このエラー
   は通常、指定したディレクトリの親ディレクトリが空でないことを意味す
   るだけなので無視されます ) 順に削除することを試みます。例えば、
   "os.removedirs('foo/bar/baz')" では最初にディレクトリ
   "'foo/bar/baz'" を削除し、次に "'foo/bar'" さらに "'foo'" をそれら
   が空ならば削除します。末端のディレクトリが削除できなかった場合には
   "OSError" が送出されます。

   バージョン 1.5.2 で追加.

os.rename(src, dst)

   Rename the file or directory *src* to *dst*.  If *dst* is a
   directory, "OSError" will be raised.  On Unix, if *dst* exists and
   is a file, it will be replaced silently if the user has permission.
   The operation may fail on some Unix flavors if *src* and *dst* are
   on different filesystems.  If successful, the renaming will be an
   atomic operation (this is a POSIX requirement).  On Windows, if
   *dst* already exists, "OSError" will be raised even if it is a
   file; there may be no way to implement an atomic rename when *dst*
   names an existing file.

   利用できる環境 : Unix 、 Windows 。

os.renames(old, new)

   再帰的にディレクトリやファイル名を変更する関数です。 "rename()" の
   ように動作しますが、新たなパス名を持つファイルを配置するために必要
   な途中のディレクトリ構造をまず作成しようと試みます。名前変更の後、
   元のファイル名のパス要素は "removedirs()" を使って右側から順に削除
   されます。

   バージョン 1.5.2 で追加.

   注釈: この関数はコピー元の末端のディレクトリまたはファイルを削除
     する権 限がない場合には失敗します。

os.rmdir(path)

   ディレクトリ *path* を削除します。ディレクトリが空の場合にだけ正常
   に動作します。そうでなければ "OSError" が送出されます。ディレクトリ
   ツリー全体を削除するには "shutil.rmtree()" を使います。

   利用できる環境 : Unix 、 Windows 。

os.stat(path)

   Perform the equivalent of a "stat()" system call on the given path.
   (This function follows symlinks; to stat a symlink use "lstat()".)

   The return value is an object whose attributes correspond to the
   members of the "stat" structure, namely:

   * "st_mode" - protection bits,

   * "st_ino" - inode number,

   * "st_dev" - device,

   * "st_nlink" - number of hard links,

   * "st_uid" - user id of owner,

   * "st_gid" - group id of owner,

   * "st_size" - size of file, in bytes,

   * "st_atime" - time of most recent access,

   * "st_mtime" - time of most recent content modification,

   * "st_ctime" - platform dependent; time of most recent metadata
     change on Unix, or the time of creation on Windows)

   バージョン 2.3 で変更: If "stat_float_times()" returns "True", the
   time values are floats, measuring seconds. Fractions of a second
   may be reported if the system supports that. See
   "stat_float_times()" for further discussion.

   (Linux のような ) 一部の Unix システムでは、以下の属性が利用できる
   場合があります :

   * "st_blocks" - number of 512-byte blocks allocated for file

   * "st_blksize" - filesystem blocksize for efficient file system
     I/O

   * "st_rdev" - type of device if an inode device

   * "st_flags" - user defined flags for file

   他の (FreeBSD のような ) Unix システムでは、以下の属性が利用できる
   場合があります ( ただし root ユーザ以外が使うと値が入っていない場合
   があります ):

   * "st_gen" - file generation number

   * "st_birthtime" - time of file creation

   On RISCOS systems, the following attributes are also available:

   * "st_ftype" (file type)

   * "st_attrs" (attributes)

   * "st_obtype" (object type).

   注釈: "st_atime" 、 "st_mtime" 、および "st_ctime" 属性の厳密な意
     味や精 度はオペレーティングシステムやファイルシステムによって変わ
     ります 。例えば、 FAT や FAT32 ファイルシステムを使用している
     Windows シ ステムでは、 "st_mtime" の精度は 2 秒であり、
     "st_atime" の精度は 1 日に過ぎません。詳しくはお使いのオペレーテ
     ィングシステムのドキ ュメントを参照してください。

   For backward compatibility, the return value of "stat()" is also
   accessible as a tuple of at least 10 integers giving the most
   important (and portable) members of the "stat" structure, in the
   order "st_mode", "st_ino", "st_dev", "st_nlink", "st_uid",
   "st_gid", "st_size", "st_atime", "st_mtime", "st_ctime". More items
   may be added at the end by some implementations.

   標準モジュール "stat" は "stat" 構造体からの情報の取り出しに役立つ
   関数と定数を定義しています。 (Windows では、一部のアイテムにダミー
   値が入ります )

   以下はプログラム例です:

      >>> import os
      >>> statinfo = os.stat('somefile.txt')
      >>> statinfo
      (33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)
      >>> statinfo.st_size
      926

   利用できる環境 : Unix 、 Windows 。

   バージョン 2.2 で変更: Added access to values as attributes of the
   returned object.

   バージョン 2.5 で変更: Added "st_gen" and "st_birthtime".

os.stat_float_times([newvalue])

   "stat_result" がタイムスタンプに浮動小数点オブジェクトを使うかどう
   かを決定します。 *newvalue* が "True" の場合、以後の "stat()" 呼び
   出しは浮動小数点を返し、 "False" の場合には以後整数を返します。
   *newvalue* が省略された場合、現在の設定どおりの返り値になります。

   古いバージョンの Python と互換性を保つため、 "stat_result" にタプル
   としてアクセスすると、常に整数が返されます。

   バージョン 2.5 で変更: Python は現在デフォルトで浮動小数点値を返し
   ます。タイムスタンプが浮動小数点では正常に動作しないアプリケーショ
   ンは、この関数で古い挙動を利用できます。

   タイムスタンプの精度 (すなわち最小の小数部分) はシステム依存です。
   システムによっては秒単位の精度しかサポートしません。そういったシス
   テムでは小数部分は常に 0 です。

   この設定の変更は、プログラムの起動時に、 *__main__* モジュールの中
   でのみ行うことを推奨します。ライブラリは決してこの設定を変更すべき
   ではありません。浮動小数点型のタイムスタンプを処理すると不正確な動
   作をするようなライブラリを使う場合、ライブラリが修正されるまで、そ
   の機能を停止させておくべきです。

os.statvfs(path)

   与えられたパスに対して "statvfs()" システムコールを実行します。返り
   値はオブジェクトで、その属性は与えられたパスが格納されているファイ
   ルシステムについて記述したものです。各属性は "statvfs" 構造体のメン
   バーに対応します : "f_bsize", "f_frsize", "f_blocks", "f_bfree",
   "f_bavail", "f_files", "f_ffree", "f_favail", "f_flag", "f_namemax"
   。

   For backward compatibility, the return value is also accessible as
   a tuple whose values correspond to the attributes, in the order
   given above. The standard module "statvfs" defines constants that
   are useful for extracting information from a "statvfs" structure
   when accessing it as a sequence; this remains useful when writing
   code that needs to work with versions of Python that don’t support
   accessing the fields as attributes.

   利用できる環境 : Unix 。

   バージョン 2.2 で変更: Added access to values as attributes of the
   returned object.

os.symlink(source, link_name)

   Create a symbolic link pointing to *source* named *link_name*.

   利用できる環境 : Unix 。

os.tempnam([dir[, prefix]])

   Return a unique path name that is reasonable for creating a
   temporary file. This will be an absolute path that names a
   potential directory entry in the directory *dir* or a common
   location for temporary files if *dir* is omitted or "None".  If
   given and not "None", *prefix* is used to provide a short prefix to
   the filename.  Applications are responsible for properly creating
   and managing files created using paths returned by "tempnam()"; no
   automatic cleanup is provided. On Unix, the environment variable
   "TMPDIR" overrides *dir*, while on Windows "TMP" is used.  The
   specific behavior of this function depends on the C library
   implementation; some aspects are underspecified in system
   documentation.

   警告: Use of "tempnam()" is vulnerable to symlink attacks;
     consider using "tmpfile()" (section ファイルオブジェクトの生成)
     instead.

   利用できる環境 : Unix 、 Windows 。

os.tmpnam()

   Return a unique path name that is reasonable for creating a
   temporary file. This will be an absolute path that names a
   potential directory entry in a common location for temporary files.
   Applications are responsible for properly creating and managing
   files created using paths returned by "tmpnam()"; no automatic
   cleanup is provided.

   警告: Use of "tmpnam()" is vulnerable to symlink attacks;
     consider using "tmpfile()" (section ファイルオブジェクトの生成)
     instead.

   Availability: Unix, Windows.  This function probably shouldn’t be
   used on Windows, though: Microsoft’s implementation of "tmpnam()"
   always creates a name in the root directory of the current drive,
   and that’s generally a poor location for a temp file (depending on
   privileges, you may not even be able to open a file using this
   name).

os.TMP_MAX

   The maximum number of unique names that "tmpnam()" will generate
   before reusing names.

os.unlink(path)

   Remove (delete) the file *path*.  This is the same function as
   "remove()"; the "unlink()" name is its traditional Unix name.

   利用できる環境 : Unix 、 Windows 。

os.utime(path, times)

   Set the access and modified times of the file specified by *path*.
   If *times* is "None", then the file’s access and modified times are
   set to the current time. (The effect is similar to running the Unix
   program **touch** on the path.)  Otherwise, *times* must be a
   2-tuple of numbers, of the form "(atime, mtime)" which is used to
   set the access and modified times, respectively. Whether a
   directory can be given for *path* depends on whether the operating
   system implements directories as files (for example, Windows does
   not).  Note that the exact times you set here may not be returned
   by a subsequent "stat()" call, depending on the resolution with
   which your operating system records access and modification times;
   see "stat()".

   バージョン 2.0 で変更: Added support for "None" for *times*.

   利用できる環境 : Unix 、 Windows 。

os.walk(top, topdown=True, onerror=None, followlinks=False)

   ディレクトリツリー以下のファイル名を、ツリーをトップダウンもしくは
   ボトムアップに走査することで作成します。ディレクトリ *top* を根に持
   つディレクトリツリーに含まれる、各ディレクトリ (*top* 自身を含む )
   ごとに、タプル "(dirpath, dirnames, filenames)" を yield します。

   *dirpath* は文字列で、ディレクトリへのパスです。 *dirnames* は
   *dirpath* 内のサブディレクトリ名のリスト ("'.'" と "'..'" は除く）
   です。 *filenames* は *dirpath* 内の非ディレクトリ・ファイル名のリ
   ストです。このリスト内の名前にはファイル名までのパスが含まれません
   。 *dirpath* 内のファイルやディレクトリへの (*top* からたどった )
   フルパスを得るには、 "os.path.join(dirpath, name)" を使用してくださ
   い。

   オプション引数 *topdown* が "True" であるか、指定されなかった場合、
   各ディレクトリからタプルを生成した後で、サブディレクトリからタプル
   を生成します。 ( ディレクトリはトップダウンで生成 ) 。 *topdown* が
   "False" の場合、ディレクトリに対応するタプルは、そのディレクトリ以
   下の全てのサブディレクトリに対応するタプルの後で ( ボトムアップで )
   生成されます。 *topdown* の値によらず、サブディレクトリのリストは、
   ディレクトリとそのサブディレクトリのタプルを生成する前に取り出され
   ます。

   *topdown* が "True" のとき、呼び出し側は *dirnames* リストを、イン
   プレースで ( たとえば、 "del" やスライスを使った代入で ) 変更でき、
   "walk()" は *dirnames* に残っているサブディレクトリ内のみを再帰しま
   す。これにより、検索を省略したり、特定の訪問順序を強制したり、呼び
   出し側が "walk()" を再開する前に、呼び出し側が作った、または名前を
   変更したディレクトリを、 "walk()" に知らせたりすることができます。
   *topdown* が "False" のときに *dirnames* を変更しても効果はありませ
   ん。ボトムアップモードでは *dirpath* 自身が生成される前に
   *dirnames* 内のディレクトリの情報が生成されるからです。

   デフォルトでは、 "listdir()" 呼び出しからのエラーは無視されます。オ
   プション引数の *onerror* を指定する場合は関数でなければなりません ;
   この関数は単一の引数として "OSError" インスタンスを伴って呼び出され
   ます。この関数でエラーを報告して走査を継続したり、例外を送出して走
   査を中止したりできます。ファイル名は例外オブジェクトの "filename"
   属性として利用できます。

   デフォルトでは、 "walk()" はディレクトリへのシンボリックリンクをた
   どりません。 *followlinks* に "True" を指定すると、ディレクトリへの
   シンボリックリンクをサポートしているシステムでは、シンボリックリン
   クの指しているディレクトリを走査します。

   バージョン 2.6 で追加: The *followlinks* parameter.

   注釈: *followlinks* に "True" を指定すると、シンボリックリンクが
     親ディ レクトリを指していた場合に、無限ループになることに注意して
     くださ い。 "walk()" はすでにたどったディレクトリを管理したりはし
     ません 。

   注釈: 相対パスを渡した場合、 "walk()" が再開されるまでの間に現在
     の作業 ディレクトリを変更しないでください。 "walk()" はカレントデ
     ィレク トリを変更しませんし、呼び出し側もカレントディレクトリを変
     更しな いと仮定しています。

   以下の例では、最初のディレクトリ以下にある各ディレクトリに含まれる
   、非ディレクトリファイルのバイト数を表示します。ただし、 CVS サブデ
   ィレクトリ以下は見に行きません

      import os
      from os.path import join, getsize
      for root, dirs, files in os.walk('python/Lib/email'):
          print root, "consumes",
          print sum(getsize(join(root, name)) for name in files),
          print "bytes in", len(files), "non-directory files"
          if 'CVS' in dirs:
              dirs.remove('CVS')  # don't visit CVS directories

   次の例では、ツリーをボトムアップで走査することが不可欠になります ;
   "rmdir()" はディレクトリが空になるまで削除を許さないからです

      # Delete everything reachable from the directory named in "top",
      # assuming there are no symbolic links.
      # CAUTION:  This is dangerous!  For example, if top == '/', it
      # could delete all your disk files.
      import os
      for root, dirs, files in os.walk(top, topdown=False):
          for name in files:
              os.remove(os.path.join(root, name))
          for name in dirs:
              os.rmdir(os.path.join(root, name))

   バージョン 2.3 で追加.


プロセス管理
============

以下の関数はプロセスの生成や管理に利用できます。

さまざまな "exec*" 関数は、プロセス内にロードされる新しいプログラムに
与えるための、引数のリストを取ります。どの関数の場合でも、新しいプログ
ラムに渡されるリストの最初の引数は、ユーザがコマンドラインで入力する引
数ではなく、そのプログラム自体の名前です。 C プログラマならば、プログ
ラムの "main()" に渡される "argv[0]" だと考えれば良いでしょう。たとえ
ば、 "os.execv('/bin/echo', ['foo', 'bar'])" が標準出力に出力するのは
"bar" だけで、 "foo" は無視されたかのように見えることになります。

os.abort()

   "SIGABRT" シグナルを現在のプロセスに対して生成します。 Unix では、
   デフォルトの動作はコアダンプの生成です ; Windows では、プロセスは即
   座に終了コード "3" を返します。この関数の呼び出しは
   "signal.signal()" を使って "SIGABRT" に対し登録された Python シグナ
   ルハンドラーを呼び出さないことに注意してください。

   利用できる環境 : Unix 、 Windows 。

os.execl(path, arg0, arg1, ...)
os.execle(path, arg0, arg1, ..., env)
os.execlp(file, arg0, arg1, ...)
os.execlpe(file, arg0, arg1, ..., env)
os.execv(path, args)
os.execve(path, args, env)
os.execvp(file, args)
os.execvpe(file, args, env)

   これらの関数はすべて、現在のプロセスを置き換える形で新たなプログラ
   ムを実行します ; 現在のプロセスは返り値を返しません。 Unix では、新
   たに実行される実行コードは現在のプロセス内に読み込まれ、呼び出し側
   と同じプロセス ID を持つことになります。エラーは "OSError" 例外とし
   て報告されます。

   現在のプロセスは瞬時に置き換えられます。開かれているファイルオブジ
   ェクトやファイル記述子はフラッシュされません。そのため、バッファ内
   にデータが残っているかもしれない場合、 "exec*" 関数を実行する前に
   "sys.stdout.flush()" か "os.fsync()" を利用してバッファをフラッシュ
   しておく必要があります。

   「l」 および 「v」 のついた "exec*" 関数は、コマンドライン引数をど
   のように渡すかが異なります。 「l」 型は、コードを書くときにパラメタ
   数が決まっている場合に、おそらくもっとも簡単に利用できます。個々の
   パラメタは単に "execl*()" 関数の追加パラメタとなります。 「v」 型は
   、パラメタの数が可変の時に便利で、リストかタプルの引数が *args* パ
   ラメタとして渡されます。どちらの場合も、子プロセスに渡す引数は動作
   させようとしているコマンドの名前から始まるべきですが、これは強制さ
   れません。

   末尾近くに 「p」 をもつ型 ("execlp()", "execlpe()", "execvp()", お
   よび "execvpe()") は、プログラム *file* を探すために環境変数 "PATH"
   を利用します。環境変数が ( 次の段で述べる "exec*e" 型関数で ) 置き
   換えられる場合、環境変数は "PATH" を決定する上の情報源として使われ
   ます。その他の型、 "execl()", "execle()", "execv()", および
   "execve()" では、実行コードを探すために "PATH" を使いません。
   *path* には適切に設定された絶対パスまたは相対パスが入っていなくては
   なりません。

   "execle()" 、 "execlpe()" 、 "execve()" 、および "execvpe()" (すべ
   て末尾に 「e」 がついています) では、 *env* 引数は新たなプロセスで
   利用される環境変数を定義するためのマップ型でなくてはなりません ( 現
   在のプロセスの環境変数の代わりに利用されます ); "execl()" 、
   "execlp()" 、 "execv()" 、および "execvp()" では、すべて新たなプロ
   セスは現在のプロセスの環境を引き継ぎます。

   利用できる環境 : Unix 、 Windows 。

os._exit(n)

   終了ステータス *n* でプロセスを終了します。この時クリーンアップハン
   ドラーの呼び出しや、標準入出力バッファのフラッシュなどは行いません
   。

   利用できる環境 : Unix 、 Windows 。

   注釈: 終了する標準的な方法は "sys.exit(n)" です。 "_exit()" は通
     常、 "fork()" された後の子プロセスでのみ使われます。

以下の終了コードは必須ではありませんが "_exit()" で使うことができます
。一般に、メールサーバーの外部コマンド配送プログラムのような、 Python
で書かれたシステムプログラムに使います。

注釈: いくつかのバリエーションがあって、これらのすべてがすべての
  Unix プラ ットフォームで使えるわけではありません。以下の定数は下層の
  プラットフ ォームで定義されていれば定義されます。

os.EX_OK

   エラーが起きなかったことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_USAGE

   誤った個数の引数が渡された時など、コマンドが間違って使われたことを
   表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_DATAERR

   入力データが誤っていたことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_NOINPUT

   入力ファイルが存在しなかった、または、読み込み不可だったことを表す
   終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_NOUSER

   指定されたユーザーが存在しなかったことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_NOHOST

   指定されたホストが存在しなかったことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_UNAVAILABLE

   要求されたサービスが利用できないことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_SOFTWARE

   内部ソフトウェアエラーが検出されたことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_OSERR

   fork できない、 pipe の作成ができないなど、オペレーティングシステム
   のエラーが検出されたことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_OSFILE

   システムファイルが存在しなかった、開けなかった、あるいはその他のエ
   ラーが起きたことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_CANTCREAT

   ユーザーには作成できない出力ファイルを指定したことを表す終了コード
   。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_IOERR

   ファイルの I/O を行っている途中にエラーが発生した時の終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_TEMPFAIL

   一時的な失敗が発生したことを表す終了コード。これは、再試行可能な操
   作の途中に、ネットワークに接続できないというような、実際にはエラー
   ではないかも知れないことを意味します。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_PROTOCOL

   プロトコル交換が不正、不適切、または理解不能なことを表す終了コード
   。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_NOPERM

   操作を行うために十分な許可がなかった（ファイルシステムの問題を除く
   ）ことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_CONFIG

   設定エラーが起こったことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.EX_NOTFOUND

   「an entry was not found」 のようなことを表す終了コード。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.fork()

   子プロセスを fork します。子プロセスでは "0" が返り、親プロセスでは
   子プロセスの id が返ります。エラーが発生した場合は、 "OSError" を送
   出します。

   Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2
   EMX have known issues when using fork() from a thread.

   警告: SSL モジュールを fork() とともに使うアプリケーションについ
     て、 "ssl" を参照して下さい。

   利用できる環境 : Unix 。

os.forkpty()

   子プロセスを fork します。この時新しい擬似端末を子プロセスの制御端
   末として使います。親プロセスでは "(pid, fd)" からなるペアが返り、
   *fd* は擬似端末のマスター側のファイル記述子となります。可搬性のある
   アプローチを取るには、 "pty" モジュールを利用してください。エラーが
   発生した場合は、 "OSError" を送出します。

   利用できる環境 : 一部の Unix 互換環境。

os.kill(pid, sig)

   プロセス *pid* にシグナル *sig* を送ります。ホストプラットフォーム
   で利用可能なシグナルを特定する定数は "signal" モジュールで定義され
   ています。

   Windows: "signal.CTRL_C_EVENT" と "signal.CTRL_BREAK_EVENT" は、同
   じコンソールウィンドウを共有しているコンソールプロセス ( 例 : 子プ
   ロセス ) にだけ送ることができる特別なシグナルです。その他の値を
   *sig* に与えると、そのプロセスが無条件に TerminateProcess API によ
   って kill され、終了コードが *sig* に設定されます。 Windows の
   "kill()" は kill するプロセスのハンドルも受け取ります。

   バージョン 2.7 で追加: Windows support

os.killpg(pgid, sig)

   プロセスグループ *pgid* にシグナル *sig* を送ります。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.nice(increment)

   プロセスの 「nice 値 」 に *increment* を加えます。新たな nice 値を
   返します。

   利用できる環境 : Unix 。

os.plock(op)

   プログラムのセグメントをメモリ内にロックします。 *op*
   ("<sys/lock.h>" で定義されています ) にはどのセグメントをロックする
   かを指定します。

   利用できる環境 : Unix 。

os.popen(...)
os.popen2(...)
os.popen3(...)
os.popen4(...)

   Run child processes, returning opened pipes for communications.
   These functions are described in section ファイルオブジェクトの生成
   .

os.spawnl(mode, path, ...)
os.spawnle(mode, path, ..., env)
os.spawnlp(mode, file, ...)
os.spawnlpe(mode, file, ..., env)
os.spawnv(mode, path, args)
os.spawnve(mode, path, args, env)
os.spawnvp(mode, file, args)
os.spawnvpe(mode, file, args, env)

   新たなプロセス内でプログラム *path* を実行します。

   ("subprocess" モジュールが、新しいプロセスを実行して結果を取得する
   ための、より強力な機能を提供しています。この関数の代わりに
   "subprocess" モジュールを利用することが推奨されています。
   "subprocess" モジュールのドキュメントの、 古い関数を subprocess モ
   ジュールで置き換える セクションを参照してください )

   *mode* が "P_NOWAIT" の場合、この関数は新たなプロセスのプロセス ID
   を返します ; *mode* が "P_WAIT" の場合、子プロセスが正常に終了する
   とその終了コードが返ります。そうでない場合にはプロセスを kill した
   シグナル *signal* に対して "-signal" が返ります。 Windows では、プ
   ロセス ID は実際にはプロセスハンドル値になるので、 "waitpid()" 関数
   で使えます。

   「l」 および 「v」 のついた "spawn*" 関数は、コマンドライン引数をど
   のように渡すかが異なります。 「l」 型は、コードを書くときにパラメタ
   数が決まっている場合に、おそらくもっとも簡単に利用できます。個々の
   パラメタは単に "spawnl*()" 関数の追加パラメタとなります。 「v」 型
   は、パラメタの数が可変の時に便利で、リストかタプルの引数が *args*
   パラメタとして渡されます。どちらの場合も、子プロセスに渡す引数は動
   作させようとしているコマンドの名前から始まらなければなりません。

   末尾近くに 「p」 をもつ型 ("spawnlp()", "spawnlpe()", "spawnvp()",
   "spawnvpe()") は、プログラム *file* を探すために環境変数 "PATH" を
   利用します。環境変数が ( 次の段で述べる "spawn*e" 型関数で ) 置き換
   えられる場合、環境変数は "PATH" を決定する上の情報源として使われま
   す。その他の型、 "spawnl()", "spawnle()", "spawnv()", および
   "spawnve()" では、実行コードを探すために "PATH" を使いません。
   *path* には適切に設定された絶対パスまたは相対パスが入っていなくては
   なりません。

   "spawnle()", "spawnlpe()", "spawnve()", および "spawnvpe()" (すべて
   末尾に 「e」 がついています) では、 *env* 引数は新たなプロセスで利
   用される環境変数を定義するためのマップ型でなくてはなりません ;
   "spawnl()" 、 "spawnlp()" 、 "spawnv()" 、および "spawnvp()" では、
   すべて新たなプロセスは現在のプロセスの環境を引き継ぎます。 *env* 辞
   書のキーと値はすべて文字列である必要があります。不正なキーや値を与
   えると関数が失敗し、 "127" を返します。

   例えば、以下の "spawnlp()" および "spawnvpe()" 呼び出しは等価です

      import os
      os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')

      L = ['cp', 'index.html', '/dev/null']
      os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)

   利用できる環境 : Unix 、 Windows "spawnlp()" 、 "spawnlpe()" 、
   "spawnvp()" 、および "spawnvpe()" は Windows では利用できません。
   "spawnle()" および "spawnve()" は Windows においてスレッドセーフで
   はありません ; 代わりに "subprocess" モジュールの利用を推奨します。

   バージョン 1.6 で追加.

os.P_NOWAIT
os.P_NOWAITO

   "spawn*" 関数ファミリに対する *mode* パラメタとして取れる値です。こ
   の値のいずれかを *mode* として与えた場合、 "spawn*()" 関数は新たな
   プロセスが生成されるとすぐに、プロセスの ID を戻り値として返ります
   。

   利用できる環境 : Unix 、 Windows 。

   バージョン 1.6 で追加.

os.P_WAIT

   "spawn*" 関数ファミリに対する *mode* パラメタとして取れる値です。こ
   の値を *mode* として与えた場合、 "spawn*()" 関数は新たなプロセスを
   起動して完了するまで返らず、プロセスがうまく終了した場合には終了コ
   ードを、シグナルによってプロセスが kill された場合には "-signal" を
   返します。

   利用できる環境 : Unix 、 Windows 。

   バージョン 1.6 で追加.

os.P_DETACH
os.P_OVERLAY

   Possible values for the *mode* parameter to the "spawn*" family of
   functions.  These are less portable than those listed above.
   "P_DETACH" is similar to "P_NOWAIT", but the new process is
   detached from the console of the calling process. If "P_OVERLAY" is
   used, the current process will be replaced; the "spawn*()" function
   will not return.

   利用できる環境 : Windows.

   バージョン 1.6 で追加.

os.startfile(path[, operation])

   ファイルを関連付けられたアプリケーションを使ってスタートします。

   *operation* が指定されないか、または "'open'" である時、この動作は
   、 Windows の Explorer 上でのファイルをダブルクリックした、あるいは
   コマンドプロンプト上でファイル名を **start** コマンドの引数としての
   実行した場合と等価です : ファイルは拡張子が関連付けされているアプリ
   ケーション ( が存在する場合 ) を使って開かれます。

   他の *operation* が与えられる場合、それはファイルに対して何がなされ
   るべきかを表す 「command verb」 ( コマンドを表す動詞 ) でなければな
   りません。 Microsoft が文書化している動詞は、 "'print'" と "'edit'"
   ( ファイルに対して ) および "'explore'" と "'find'" ( ディレクトリ
   に対して ) です。

   "startfile()" は関連付けされたアプリケーションが起動すると同時に返
   ります。アプリケーションが閉じるまで待機させるためのオプションはな
   く、アプリケーションの終了状態を取得する方法もありません。引数
   *path* はカレントディレクトリからの相対パスです。絶対パスで指定した
   い場合は、最初の文字はスラッシュ ("'/'") ではないので注意してくださ
   い。最初の文字がスラッシュの場合、下層の Win32 "ShellExecute()" 関
   数は動作しません。 "os.path.normpath()" 関数を使って、 Win32 用に正
   しくコード化されたパスになるようにしてください。

   利用できる環境 : Windows.

   バージョン 2.0 で追加.

   バージョン 2.5 で追加: The *operation* parameter.

os.system(command)

   Execute the command (a string) in a subshell.  This is implemented
   by calling the Standard C function "system()", and has the same
   limitations. Changes to "sys.stdin", etc. are not reflected in the
   environment of the executed command.

   Unix では、返り値はプロセスの終了ステータスで、 "wait()" で定義され
   ている書式にコード化されています。 POSIX は "system()" 関数の返り値
   の意味について定義していないので、 Python の "system()" における返
   り値はシステム依存となることに注意してください。

   On Windows, the return value is that returned by the system shell
   after running *command*, given by the Windows environment variable
   "COMSPEC": on **command.com** systems (Windows 95, 98 and ME) this
   is always "0"; on **cmd.exe** systems (Windows NT, 2000 and XP)
   this is the exit status of the command run; on systems using a non-
   native shell, consult your shell documentation.

   "subprocess" モジュールは、新しいプロセスを実行して結果を取得するた
   めのより強力な機能を提供しています。この関数の代わりに "subprocess"
   モジュールを利用することが推奨されています。 "subprocess" モジュー
   ルのドキュメントの 古い関数を subprocess モジュールで置き換える 節
   のレシピを参考にして下さい。

   利用できる環境 : Unix 、 Windows 。

os.times()

   Return a 5-tuple of floating point numbers indicating accumulated
   (processor or other) times, in seconds.  The items are: user time,
   system time, children’s user time, children’s system time, and
   elapsed real time since a fixed point in the past, in that order.
   See the Unix manual page *times(2)* or the corresponding Windows
   Platform API documentation. On Windows, only the first two items
   are filled, the others are zero.

   利用できる環境 : Unix, Windows

os.wait()

   子プロセスの実行完了を待機し、子プロセスの pid と終了コードインジケ
   ーター — 16 ビットの数値で、下位バイトがプロセスを kill したシグナ
   ル番号、上位バイトが終了ステータス ( シグナル番号がゼロの場合 ) —
   の入ったタプルを返します ; コアダンプファイルが生成された場合、下位
   バイトの最上桁ビットが立てられます。

   利用できる環境 : Unix 。

os.waitpid(pid, options)

   この関数の詳細は Unix と Windows で異なります。

   Unix の場合 : プロセス id *pid* で与えられた子プロセスの完了を待機
   し、子プロセスのプロセス id と ("wait()" と同様にコード化された )
   終了ステータスインジケーターからなるタプルを返します。この関数の動
   作は *options* によって変わります。通常の操作では "0" にします。

   *pid* が "0" よりも大きい場合、 "waitpid()" は特定のプロセスのステ
   ータス情報を要求します。 *pid* が "0" の場合、現在のプロセスグルー
   プ内の任意の子プロセスの状態に対する要求です。 *pid* が "-1" の場合
   、現在のプロセスの任意の子プロセスに対する要求です。 *pid* が "-1"
   よりも小さい場合、プロセスグループ "-pid" ( すなわち *pid* の絶対値
   ) 内の任意のプロセスに対する要求です。

   システムコールが -1 を返した時、 "OSError" を errno と共に送出しま
   す。

   Windows では、プロセスハンドル *pid* を指定してプロセスの終了を待っ
   て、 *pid* と、終了ステータスを 8bit 左シフトした値のタプルを返しま
   す。 ( シフトは、この関数をクロスプラットフォームで利用しやすくする
   ために行われます ) "0" 以下の *pid* は Windows では特別な意味を持っ
   ておらず、例外を発生させます。 *options* の値は効果がありません。
   *pid* は、子プロセスで無くても、プロセス ID を知っているどんなプロ
   セスでも参照することが可能です。 "spawn*" 関数を "P_NOWAIT" と共に
   呼び出した場合、適切なプロセスハンドルが返されます。

os.wait3(options)

   "waitpid()" に似ていますが、プロセス id を引数に取らず、子プロセス
   id 、終了ステータスインジケータ、リソース使用情報の 3 要素からなる
   タプルを返します。リソース使用情報の詳しい情報は "resource".
   "getrusage()" を参照してください。 オプション引数は "waitpid()" お
   よび "wait4()" と同じです。

   利用できる環境 : Unix 。

   バージョン 2.5 で追加.

os.wait4(pid, options)

   "waitpid()" に似ていますが、子プロセス id 、終了ステータスインジケ
   ータ、リソース使用情報の 3 要素からなるタプルを返します。リソース使
   用情報の詳しい情報は "resource". "getrusage()" を参照してください。
   "wait4()" の引数は "waitpid()" に与えられるものと同じです。

   利用できる環境 : Unix 。

   バージョン 2.5 で追加.

os.WNOHANG

   子プロセス状態がすぐに取得できなかった場合に直ちに終了するようにす
   るための "waitpid()" のオプションです。この場合、関数は "(0, 0)" を
   返します。

   利用できる環境 : Unix 。

os.WCONTINUED

   このオプションによって子プロセスは前回状態が報告された後にジョブ制
   御による停止状態から実行を再開された場合に報告されるようになります
   。

   Availability: Some Unix systems.

   バージョン 2.3 で追加.

os.WUNTRACED

   このオプションによって子プロセスは停止されていながら停止されてから
   状態が報告されていない場合に報告されるようになります。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

以下の関数は "system()" 、 "wait()" 、あるいは "waitpid()" が返すプロ
セス状態コードを引数にとります。これらの関数はプロセスの配置を決めるた
めに利用できます。

os.WCOREDUMP(status)

   プロセスに対してコアダンプが生成されていた場合には "True" を、それ
   以外の場合は "False" を返します。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.WIFCONTINUED(status)

   プロセスがジョブ制御による停止状態から実行を再開された (continue)
   場合に "True" を、それ以外の場合は "False" を返します。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.WIFSTOPPED(status)

   プロセスが停止された (stop) 場合に "True" を、それ以外の場合は
   "False" を返します。

   利用できる環境 : Unix 。

os.WIFSIGNALED(status)

   プロセスがシグナルによって終了した (exit) 場合に "True" を、それ以
   外の場合は "False" を返します。

   利用できる環境 : Unix 。

os.WIFEXITED(status)

   プロセスが *exit(2)* システムコールで終了した場合に "True" を、それ
   以外の場合は "False" を返します。

   利用できる環境 : Unix 。

os.WEXITSTATUS(status)

   "WIFEXITED(status)" が真の場合、 *exit(2)* システムコールに渡された
   整数の引数を返します。そうでない場合、返り値に意味はありません。

   利用できる環境 : Unix 。

os.WSTOPSIG(status)

   プロセスを停止させたシグナル番号を返します。

   利用できる環境 : Unix 。

os.WTERMSIG(status)

   プロセスを終了させたシグナル番号を返します。

   利用できる環境 : Unix 。


雑多なシステム情報
==================

os.confstr(name)

   システム設定値を文字列で返します。 *name* には取得したい設定名を指
   定します ; この値は定義済みのシステム値名を表す文字列にすることがで
   きます ; 名前は多くの標準 (POSIX.1 、 Unix 95 、 Unix 98 その他 )
   で定義されています。ホストオペレーティングシステムの関知する名前は
   "confstr_names" 辞書のキーとして与えられています。このマップ型オブ
   ジェクトに入っていない設定変数については、 *name* に整数を渡しても
   かまいません。

   *name* に指定された設定値が定義されていない場合、 "None" を返します
   。

   *name* が文字列で、かつ不明の場合、 "ValueError" を送出します。
   *name* の指定値がホストシステムでサポートされておらず、
   "confstr_names" にも入っていない場合、 "errno.EINVAL" をエラー番号
   として "OSError" を送出します。

   利用できる環境 : Unix

os.confstr_names

   "confstr()" が受理する名前を、ホストオペレーティングシステムで定義
   されている整数値に対応付けている辞書です。この辞書はシステムでどの
   設定名が定義されているかを決定するために利用できます。

   利用できる環境 : Unix 。

os.getloadavg()

   過去 1 分、 5 分、および 15 分間の、システムの実行キューの平均プロ
   セス数を返します。平均負荷が得られない場合には "OSError" を送出しま
   す。

   利用できる環境 : Unix 。

   バージョン 2.3 で追加.

os.sysconf(name)

   整数値のシステム設定値を返します。 *name* で指定された設定値が定義
   されていない場合、 "-1" が返されます。 *name* に関するコメントとし
   ては、 "confstr()" で述べた内容が同様に当てはまります ; 既知の設定
   名についての情報を与える辞書は "sysconf_names" で与えられています。

   利用できる環境 : Unix 。

os.sysconf_names

   "sysconf()" が受理する名前を、ホストオペレーティングシステムで定義
   されている整数値に対応付けている辞書です。この辞書はシステムでどの
   設定名が定義されているかを決定するために利用できます。

   利用できる環境 : Unix 。

以下のデータ値はパス名編集操作をサポートするために利用されます。これら
の値はすべてのプラットフォームで定義されています。

パス名に対する高水準の操作は "os.path" モジュールで定義されています。

os.curdir

   現在のディレクトリ参照するためにオペレーティングシステムで使われる
   文字列定数です。 POSIX と Windows では "'.'" になります。 "os.path"
   からも利用できます。

os.pardir

   親ディレクトリを参照するためにオペレーティングシステムで使われる文
   字列定数です。 POSIX と Windows では "'..'" になります。 "os.path"
   からも利用できます。

os.sep

   パス名を要素に分割するためにオペレーティングシステムで利用されてい
   る文字です。例えば POSIX では "'/'" で、 Windows では "'\\'" です。
   しかし、このことを知っているだけではパス名を解析したり、パス名同士
   を結合したりするには不十分です — こうした操作には "os.path.split()"
   や "os.path.join()" を使用してください — が、たまに便利なこともあり
   ます。 "os.path" からも利用できます。

os.altsep

   文字パス名を要素に分割する際にオペレーティングシステムで利用される
   もう一つの文字で、分割文字が一つしかない場合には "None" になります
   。この値は "sep" がバックスラッシュとなっている DOS や Windows シス
   テムでは "'/'" に設定されています。 "os.path" からも利用できます。

os.extsep

   ベースのファイル名と拡張子を分ける文字です。例えば、 "os.py" であれ
   ば "'.'" です。 "os.path" からも利用できます。

   バージョン 2.2 で追加.

os.pathsep

   ("PATH" のような ) サーチパス内の要素を分割するためにオペレーティン
   グシステムが慣習的に用いる文字で、 POSIX における "':'" や DOS およ
   び Windows における "';'" に相当します。 "os.path" からも利用できま
   す。

os.defpath

   "exec*p*" や "spawn*p*" において、環境変数辞書内に "'PATH'" キーが
   ない場合に使われる標準設定のサーチパスです。 "os.path" からも利用で
   きます。

os.linesep

   現在のプラットフォーム上で行を分割 ( あるいは終端 ) するために用い
   られている文字列です。この値は例えば POSIX での "'\n'" や Mac OS で
   の "'\r'" のように、単一の文字にもなりますし、例えば Windows での
   "'\r\n'" のように複数の文字列にもなります。テキストモードで開いたフ
   ァイルに書き込む時には、 *os.linesep* を利用しないでください。すべ
   てのプラットフォームで、単一の "'\n'" を使用してください。

os.devnull

   ヌルデバイスのファイルパスです。例えば POSIX では "'/dev/null'" で
   、 Windows では "'nul'" です。この値は "os.path" からも利用できます
   。

   バージョン 2.4 で追加.


Miscellaneous Functions
=======================

os.urandom(n)

   Return a string of *n* random bytes suitable for cryptographic use.

   This function returns random bytes from an OS-specific randomness
   source.  The returned data should be unpredictable enough for
   cryptographic applications, though its exact quality depends on the
   OS implementation.  On a UNIX-like system this will query
   "/dev/urandom", and on Windows it will use "CryptGenRandom()".  If
   a randomness source is not found, "NotImplementedError" will be
   raised.

   For an easy-to-use interface to the random number generator
   provided by your platform, please see "random.SystemRandom".

   バージョン 2.4 で追加.
