pytho****@googl*****
pytho****@googl*****
2011年 4月 17日 (日) 20:32:31 JST
4 new revisions: Revision: c02c8df9d54e Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:14:26 2011 Log: added the original texts http://code.google.com/p/python-doc-ja/source/detail?r=c02c8df9d54e Revision: ecd21dd19a90 Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:14:36 2011 Log: 2.6.6: library/inspect.rst http://code.google.com/p/python-doc-ja/source/detail?r=ecd21dd19a90 Revision: c04b5677625d Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:19:33 2011 Log: 長い行の折り返しと空白の調整 http://code.google.com/p/python-doc-ja/source/detail?r=c04b5677625d Revision: a55592ac50bc Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:19:44 2011 Log: revised: library/inspect.rst http://code.google.com/p/python-doc-ja/source/detail?r=a55592ac50bc ============================================================================== Revision: c02c8df9d54e Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:14:26 2011 Log: added the original texts http://code.google.com/p/python-doc-ja/source/detail?r=c02c8df9d54e Modified: /library/inspect.rst ======================================= --- /library/inspect.rst Mon May 31 01:54:01 2010 +++ /library/inspect.rst Sun Apr 17 04:14:26 2011 @@ -10,10 +10,23 @@ .. versionadded:: 2.1 + +.. The :mod:`inspect` module provides several useful functions to help get +.. information about live objects such as modules, classes, methods, functions, +.. tracebacks, frame objects, and code objects. For example, it can help you +.. examine the contents of a class, retrieve the source code of a method, extract +.. and format the argument list for a function, or get all the information you need +.. to display a detailed traceback. + :mod:`inspect` は、モジュール・クラス・メソッド・関数・トレースバック・フ レームオブジェクト・コードオブジェクトなどのオブジェクトから情報を取得 する関数を定義しており、クラスの内容を調べる、メソッドのソースコードを取得 する、関数の引数リストを取得して整形する、トレースバックから必要な情報 だけを取得して表示する、などの処理を行う場合に利用します。 + +.. There are four main kinds of services provided by this module: type checking, +.. getting source code, inspecting classes and functions, and examining the +.. interpreter stack. + このモジュールの機能は、型チェック・ソースコードの取得・クラス/関数から情 報を取得・インタープリタのスタック情報の調査、の4種類に分類する事ができま す。 @@ -22,9 +35,194 @@ 型とメンバ ---------- +.. The :func:`getmembers` function retrieves the members of an object such as a +.. class or module. The sixteen functions whose names begin with "is" are mainly +.. provided as convenient choices for the second argument to :func:`getmembers`. +.. They also help you determine when you can expect to find the following special +.. attributes: + :func:`getmembers` は、クラスやモジュールなどのオブジェクトからメンバを取得 します。名前が"is"で始まる 16 個の関数は、 :func:`getmembers` の2番目の引数として利用する事ができますし、 以下のような特殊属性を参照できるかどうか調べる時にも使えます。 + +.. +-----------+-----------------+---------------------------+-------+ +.. | Type | Attribute | Description | Notes | +.. +===========+=================+===========================+=======+ +.. | module | __doc__ | documentation string | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __file__ | filename (missing for | | +.. | | | built-in modules) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | class | __doc__ | documentation string | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __module__ | name of module in which | | +.. | | | this class was defined | | +.. +-----------+-----------------+---------------------------+-------+ +.. | method | __doc__ | documentation string | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __name__ | name with which this | | +.. | | | method was defined | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | im_class | class object that asked | \(1) | +.. | | | for this method | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | im_func or | function object | | +.. | | __func__ | containing implementation | | +.. | | | of method | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | im_self or | instance to which this | | +.. | | __self__ | method is bound, or | | +.. | | | ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | function | __doc__ | documentation string | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __name__ | name with which this | | +.. | | | function was defined | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | func_code | code object containing | | +.. | | | compiled function | | +.. | | | :term:`bytecode` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | func_defaults | tuple of any default | | +.. | | | values for arguments | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | func_doc | (same as __doc__) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | func_globals | global namespace in which | | +.. | | | this function was defined | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | func_name | (same as __name__) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | generator | __iter__ | defined to support | | +.. | | | iteration over container | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | close | raises new GeneratorExit | | +.. | | | exception inside the | | +.. | | | generator to terminate | | +.. | | | the iteration | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | gi_code | code object | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | gi_frame | frame object or possibly | | +.. | | | None once the generator | | +.. | | | has been exhausted | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | gi_running | set to 1 when generator | | +.. | | | is executing, 0 otherwise | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | next | return the next item from | | +.. | | | the container | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | send | resumes the generator and | | +.. | | | "sends" a value that | | +.. | | | becomes the result of the | | +.. | | | current yield-expression | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | throw | used to raise an | | +.. | | | exception inside the | | +.. | | | generator | | +.. +-----------+-----------------+---------------------------+-------+ +.. | traceback | tb_frame | frame object at this | | +.. | | | level | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | tb_lasti | index of last attempted | | +.. | | | instruction in bytecode | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | tb_lineno | current line number in | | +.. | | | Python source code | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | tb_next | next inner traceback | | +.. | | | object (called by this | | +.. | | | level) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | frame | f_back | next outer frame object | | +.. | | | (this frame's caller) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_builtins | built-in namespace seen | | +.. | | | by this frame | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_code | code object being | | +.. | | | executed in this frame | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_exc_traceback | traceback if raised in | | +.. | | | this frame, or ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_exc_type | exception type if raised | | +.. | | | in this frame, or | | +.. | | | ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_exc_value | exception value if raised | | +.. | | | in this frame, or | | +.. | | | ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_globals | global namespace seen by | | +.. | | | this frame | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_lasti | index of last attempted | | +.. | | | instruction in bytecode | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_lineno | current line number in | | +.. | | | Python source code | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_locals | local namespace seen by | | +.. | | | this frame | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_restricted | 0 or 1 if frame is in | | +.. | | | restricted execution mode | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | f_trace | tracing function for this | | +.. | | | frame, or ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ +.. | code | co_argcount | number of arguments (not | | +.. | | | including \* or \*\* | | +.. | | | args) | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_code | string of raw compiled | | +.. | | | bytecode | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_consts | tuple of constants used | | +.. | | | in the bytecode | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_filename | name of file in which | | +.. | | | this code object was | | +.. | | | created | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_firstlineno | number of first line in | | +.. | | | Python source code | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_flags | bitmap: 1=optimized ``|`` | | +.. | | | 2=newlocals ``|`` 4=\*arg | | +.. | | | ``|`` 8=\*\*arg | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_lnotab | encoded mapping of line | | +.. | | | numbers to bytecode | | +.. | | | indices | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_name | name with which this code | | +.. | | | object was defined | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_names | tuple of names of local | | +.. | | | variables | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_nlocals | number of local variables | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_stacksize | virtual machine stack | | +.. | | | space required | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | co_varnames | tuple of names of | | +.. | | | arguments and local | | +.. | | | variables | | +.. +-----------+-----------------+---------------------------+-------+ +.. | builtin | __doc__ | documentation string | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __name__ | original name of this | | +.. | | | function or method | | +.. +-----------+-----------------+---------------------------+-------+ +.. | | __self__ | instance to which a | | +.. | | | method is bound, or | | +.. | | | ``None`` | | +.. +-----------+-----------------+---------------------------+-------+ + +-----------+-----------------+-----------------------------------------------------+-------+ | Type | Attribute | Description | Notes | +===========+=================+=====================================================+=======+ @@ -155,22 +353,32 @@ | | __self__ | メソッドが結合しているインスタンス、または ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ + Note: (1) + + .. .. versionchanged:: 2.2 + .. :attr:`im_class` used to refer to the class that defined the method. + .. versionchanged:: 2.2 :attr:`im_class` 従来、メソッドを定義しているクラスを参照するために使 用していた. .. function:: getmembers(object[, predicate]) + .. Return all the members of an object in a list of (name, value) pairs sorted by + .. name. If the optional *predicate* argument is supplied, only members for which + .. the predicate returns a true value are included. + オブジェクトの全メンバを、(名前, 値)の組み合わせのリストで返します。リス トはメンバ名でソートされています。 *predicate* が指定されている場 合、predicateの戻り値が真となる値のみを返します。 + .. note:: .. :func:`getmembers` does not return metaclass attributes when the argument - is a class (this behavior is inherited from the :func:`dir` function). + .. is a class (this behavior is inherited from the :func:`dir` function). :func:`getmembers` は、引数がクラスの場合にメタクラス属性を返さない。 (この動作は :func:`dir` 関数に合わせてあります。) @@ -178,42 +386,69 @@ .. function:: getmoduleinfo(path) + .. Return a tuple of values that describe how Python will interpret the file + .. identified by *path* if it is a module, or ``None`` if it would not be + .. identified as a module. The return tuple is ``(name, suffix, mode, mtype)``, + .. where *name* is the name of the module without the name of any enclosing + .. package, *suffix* is the trailing part of the file name (which may not be a + .. dot-delimited extension), *mode* is the :func:`open` mode that would be used + .. (``'r'`` or ``'rb'``), and *mtype* is an integer giving the type of the + .. module. *mtype* will have a value which can be compared to the constants + .. defined in the :mod:`imp` module; see the documentation for that module for + .. more information on module types. + *path* で指定したファイルがモジュールであればそのモジュールがPython でど のように解釈されるかを示す``(name, suffix, mode, mtype)``のタプルを返し、モジュールでなければ `` None``を返します。 *name* はパッケージ名を含まないモジュール 名、 *suffix* はファイル名からモジュール名を除いた残りの部分(ドットによ る拡張子とは限らない)、 *mode* は :func:`open` で指定されるフ ァイルモード(``'r'`` または ``'rb'``)、 *mtype* は :mod:`imp` で定義して いる整定数のいずれかが指定されます。モジュール タイプに付いては :mod:`imp` を参照してください。 + + .. .. versionchanged:: 2.6 + .. Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode, + .. module_type)``. + .. versionchanged:: 2.6 - .. Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode, - module_type)``. 名前付きタプル(:term:`named tuple`) の ``ModuleInfo(name, suffix, mode, module_type)`` を返します。 .. function:: getmodulename(path) + .. Return the name of the module named by the file *path*, without including the + .. names of enclosing packages. This uses the same algorithm as the interpreter + .. uses when searching for modules. If the name cannot be matched according to the + .. interpreter's rules, ``None`` is returned. + *path* で指定したファイルの、パッケージ名を含まないモジュール名を返しま す。この処理は、インタープリタがモジュールを検索する時と同じアルゴ リズムで行われます。ファイルがこのアルゴリズムで見つからない場合には ``None`` が返ります。 .. function:: ismodule(object) + .. Return true if the object is a module. + オブジェクトがモジュールの場合は真を返します。 .. function:: isclass(object) + .. Return true if the object is a class. + オブジェクトがクラスの場合は真を返します。 .. function:: ismethod(object) + .. Return true if the object is a method. + オブジェクトがメソッドの場合は真を返します。 .. function:: isfunction(object) + .. Return true if the object is a Python function or unnamed (:term:`lambda`) function. + オブジェクトがPythonの関数、または無名関数(:term:`lambda`)の場合は真を返 します。 @@ -223,40 +458,55 @@ *object* がPythonのジェネレータ関数であるときに真を返します。 + .. versionadded:: 2.6 + .. function:: isgenerator(object) .. Return true if the object is a generator. *object* がジェネレータであるときに真を返します。 + .. versionadded:: 2.6 + .. function:: istraceback(object) + .. Return true if the object is a traceback. + オブジェクトがトレースバックの場合は真を返します。 .. function:: isframe(object) + .. Return true if the object is a frame. + オブジェクトがフレームの場合は真を返します。 .. function:: iscode(object) + .. Return true if the object is a code. + オブジェクトがコードの場合は真を返します。 .. function:: isbuiltin(object) + .. Return true if the object is a built-in function. + オブジェクトが組み込み関数の場合は真を返します。 .. function:: isroutine(object) + .. Return true if the object is a user-defined or built-in function or method. + オブジェクトがユーザ定義か組み込みの関数・メソッドの場合は真を返します。 + .. function:: isabstract(object) .. Return true if the object is an abstract base class. @@ -268,14 +518,29 @@ .. function:: ismethoddescriptor(object) + .. Return true if the object is a method descriptor, but not if :func:`ismethod` + .. or :func:`isclass` or :func:`isfunction` are true. + オブジェクトがメソッドデスクリプタの場合に真を返します が、 :func:`ismethod`, :func:`isclass` または :func:`isfunction` が真の場合には真を返しません。 + + .. This is new as of Python 2.2, and, for example, is true of + .. ``int.__add__``. An object passing this test has a :attr:`__get__` attribute + .. but not a :attr:`__set__` attribute, but beyond that the set of attributes + .. varies. :attr:`__name__` is usually sensible, and :attr:`__doc__` often is. + この機能は Python 2.2 から新たに追加されたもので、例えば ``int.__add__`` は真になります。このテストをパスするオブジェクトは :attr:`__get__` 属性を持ちますが :attr:`__set__` 属性を持ちません。 それ以外の属性を持っているかもしれません。 通常 :attr:`__name__` を持っていますし、しばしば :attr:`__doc__` も持っ ています。 + + .. Methods implemented via descriptors that also pass one of the other tests + .. return false from the :func:`ismethoddescriptor` test, simply because the + .. other tests promise more -- you can, e.g., count on having the + .. :attr:`im_func` attribute (etc) when an object passes :func:`ismethod`. + デスクリプタを使って実装されたメソッドで、上記のいずれかのテストもパスし ているものは、 :func:`ismethoddescriptor` では偽を返します。これは単に他のテストの方がもっと確実だからです -- 例えば、 :func:`ismethod` をパスしたオブジェクトは :attr:`im_func` 属性 などを持っていると期待できます。 @@ -283,34 +548,62 @@ .. function:: isdatadescriptor(object) + .. Return true if the object is a data descriptor. + オブジェクトがデータデスクリプタの場合に真を返します。 + + .. Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute. + .. Examples are properties (defined in Python), getsets, and members. The + .. latter two are defined in C and there are more specific tests available for + .. those types, which is robust across Python implementations. Typically, data + .. descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes + .. (properties, getsets, and members have both of these attributes), but this is + .. not guaranteed. + データデスクリプタは :attr:`__get__` および :attr:`__set__` 属性の両方を 持ちます。 データデスクリプタの例は (Python 上で定義された) プロパティや getset や メンバです。 後者のふたつは C で定義されており、個々の型に特有のテストも行います。そ のため、Python の実装よりもより確実です。 通常、データデスクリプタは :attr:`__name__` や :attr:`__doc__` 属性を持 ちます (プロパティ、 getset 、メンバは両方の属性を持っています) が、保証されているわけではありませ ん。 + .. versionadded:: 2.3 .. function:: isgetsetdescriptor(object) + .. Return true if the object is a getset descriptor. + オブジェクトがgetsetデスクリプタの場合に真を返します。 + + .. getsets are attributes defined in extension modules via ``PyGetSetDef`` + .. structures. For Python implementations without such types, this method will + .. always return ``False``. + getsetとは ``PyGetSetDef`` 構造体を用いて拡張モジュールで定義されてい る属性のことです。Pythonの実装の場合はそのような型はないので、このメソッ ドは常に ``False`` を返します。 + .. versionadded:: 2.5 .. function:: ismemberdescriptor(object) + .. Return true if the object is a member descriptor. + オブジェクトがメンバデスクリプタの場合に真を返します。 + + .. Member descriptors are attributes defined in extension modules via + .. ``PyMemberDef`` structures. For Python implementations without such types, + .. this method will always return ``False``. + メンバデスクリプタとは ``PyMemberDef`` 構造体を用いて拡張モジュールで定 義されている属性のことです。Pythonの実装の場合はそのような型はないの で、このメソッドは常に ``False`` を返します。 + .. versionadded:: 2.5 @@ -319,37 +612,59 @@ ソース参照 ---------- - .. function:: getdoc(object) + .. Get the documentation string for an object, cleaned up with :func:`cleandoc`. + :func:`cleandoc` でクリーンアップされた、オブジェクトのドキュメンテーシ ョン文字列を取得します。 .. function:: getcomments(object) + .. Return in a single string any lines of comments immediately preceding the + .. object's source code (for a class, function, or method), or at the top of the + .. Python source file (if the object is a module). + オブジェクトがクラス・関数・メソッドの何れかの場合は、オブジェクトのソー スコードの直後にあるコメント行(複数行)を、単一の文字列として返し ます。オブジェクトがモジュールの場合、ソースファイルの先頭にあるコメント を返します。 .. function:: getfile(object) + .. Return the name of the (text or binary) file in which an object was defined. + .. This will fail with a :exc:`TypeError` if the object is a built-in module, + .. class, or function. + オブジェクトを定義している(テキストまたはバイナリの)ファイルの名前を返 します。オブジェクトが組み込みモジュール・クラス・関数の場合は :exc:`TypeError` 例外が発生します。 .. function:: getmodule(object) + .. Try to guess which module an object was defined in. + オブジェクトを定義しているモジュールを推測します。 .. function:: getsourcefile(object) + .. Return the name of the Python source file in which an object was defined. This + .. will fail with a :exc:`TypeError` if the object is a built-in module, class, or + .. function. + オブジェクトを定義しているPythonソースファイルの名前を返します。オブジェ クトが組み込みのモジュール、クラス、関数の場合には、 :exc:`TypeError` 例外が発生します。 .. function:: getsourcelines(object) + .. Return a list of source lines and starting line number for an object. The + .. argument may be a module, class, method, function, traceback, frame, or code + .. object. The source code is returned as a list of the lines corresponding to the + .. object and the line number indicates where in the original source file the first + .. line of code was found. An :exc:`IOError` is raised if the source code cannot + .. be retrieved. + オブジェクトのソース行のリストと開始行番号を返します。引数にはモジュー ル・クラス・メソッド・関数・トレースバック・フレーム・コードオブジェク トを指定する事ができます。戻り値は指定したオブジェクトに対応するソース コードのソース行リストと元のソースファイル上での開始行となります。ソー スコードを取得できない場合は :exc:`IOError` が発生します。 @@ -357,31 +672,44 @@ .. function:: getsource(object) + .. Return the text of the source code for an object. The argument may be a module, + .. class, method, function, traceback, frame, or code object. The source code is + .. returned as a single string. An :exc:`IOError` is raised if the source code + .. cannot be retrieved. + オブジェクトのソースコードを返します。引数にはモジュール・クラス・メソッ ド・関数・トレースバック・フレーム・コードオブジェクトを指定する事が できます。ソースコードは単一の文字列で返します。ソースコードを取得できな い場合は :exc:`IOError` が発生します。 + .. function:: cleandoc(doc) .. Clean up indentation from docstrings that are indented to line up with blocks - of code. Any whitespace that can be uniformly removed from the second line - onwards is removed. Also, all tabs are expanded to spaces. + .. of code. Any whitespace that can be uniformly removed from the second line + .. onwards is removed. Also, all tabs are expanded to spaces. インデントされた docstring から、コードブロックまでのインデントを削除し ます。 2行目以降では行頭の空白は一様に削除されます。 全てのタブはスペースに展開されます。 + .. versionadded:: 2.6 - .. _inspect-classes-functions: クラスと関数 ------------ - .. function:: getclasstree(classes[, unique]) + .. Arrange the given list of classes into a hierarchy of nested lists. Where a + .. nested list appears, it contains classes derived from the class whose entry + .. immediately precedes the list. Each entry is a 2-tuple containing a class and a + .. tuple of its base classes. If the *unique* argument is true, exactly one entry + .. appears in the returned structure for each class in the given list. Otherwise, + .. classes using multiple inheritance and their descendants will appear multiple + .. times. + リストで指定したクラスの継承関係から、ネストしたリストを作成します。ネス トしたリストには、直前の要素から派生したクラスが格納されます。各要素 は長さ2のタプルで、クラスと基底クラスのタプルを格納しています。 *unique* が真の場合、各クラスは戻り値のリスト内に一つだけしか格納 されません。真でなければ、多重継承を利用したクラスとその派生クラスは複数 回格納される場合があります。 @@ -389,43 +717,76 @@ .. function:: getargspec(func) + .. Get the names and default values of a function's arguments. A tuple of four + .. things is returned: ``(args, varargs, varkw, defaults)``. *args* is a list of + .. the argument names (it may contain nested lists). *varargs* and *varkw* are the + .. names of the ``*`` and ``**`` arguments or ``None``. *defaults* is a tuple of + .. default argument values or None if there are no default arguments; if this tuple + .. has *n* elements, they correspond to the last *n* elements listed in *args*. + 関数の引数名とデフォルト値を取得します。戻り値は長さ4のタプルで、次の値 を返します:``(args, varargs, varkw, defaults)`` 。 *args* は引数名のリストです(ネストしたリストが格納される場合があります ) *varargs* と *varkw* は ``*`` 引数と ``**`` 引数の名前で、引数がなけれ ば ``None`` となります。 *defaults* は引数のデフォルト値のタプルか、デフォルト値がない場合は ``None`` です。 このタプルに *n* 個の要素があれば、各要素は *args* の後ろから *n* 個分の 引数のデフォルト値となります。 + + .. .. versionchanged:: 2.6 + .. Returns a :term:`named tuple` ``ArgSpec(args, varargs, keywords, + .. defaults)``. + .. versionchanged:: 2.6 - .. Returns a :term:`named tuple` ``ArgSpec(args, varargs, keywords, - defaults)``. ``ArgSpec(args, varargs, keywords, defaults)`` 形式の名前付きタプル (:term:`named tuple`)を返します。 .. function:: getargvalues(frame) + .. Get information about arguments passed into a particular frame. A tuple of four + .. things is returned: ``(args, varargs, varkw, locals)``. *args* is a list of the + .. argument names (it may contain nested lists). *varargs* and *varkw* are the + .. names of the ``*`` and ``**`` arguments or ``None``. *locals* is the locals + .. dictionary of the given frame. + 指定したフレームに渡された引数の情報を取得します。戻り値は長さ4のタプル で、次の値を返します:``(args, varargs, varkw, locals)``。 *args* は引数名のリストです(ネストしたリストが格納される場 合があります)。 *varargs* と *varkw* は``*``引数と ``**`` 引数の名前で、引数がなければ ``None`` となります。 * locals*は指 定したフレームのローカル変数の辞書です。 + + .. .. versionchanged:: 2.6 + .. Returns a :term:`named tuple` ``ArgInfo(args, varargs, keywords, + .. locals)``. + .. versionchanged:: 2.6 - .. Returns a :term:`named tuple` ``ArgInfo(args, varargs, keywords, - locals)``. ``ArgInfo(args, varargs, keywords, locals)`` 形式の名前付きタプル (:term:`named tuple`)を返します。 + .. function:: formatargspec(args[, varargs, varkw, defaults, formatarg, formatvarargs, formatvarkw, formatvalue, join]) + .. Format a pretty argument spec from the four values returned by + .. :func:`getargspec`. The format\* arguments are the corresponding optional + .. formatting functions that are called to turn names and values into strings. + :func:`getargspec` で取得した4つの値を読みやすく整形します。 format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定する事ができ ます。 .. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue, join]) + .. Format a pretty argument spec from the four values returned by + .. :func:`getargvalues`. The format\* arguments are the corresponding optional + .. formatting functions that are called to turn names and values into strings. + :func:`getargvalues` で取得した4つの値を読みやすく整形します。 format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定する事ができ ます。 .. function:: getmro(cls) + .. Return a tuple of class cls's base classes, including cls, in method resolution + .. order. No class appears more than once in this tuple. Note that the method + .. resolution order depends on cls's type. Unless a very peculiar user-defined + .. metatype is in use, cls will be the first element of the tuple. + *cls* クラスの基底クラス( *cls* 自身も含む)を、メソッドの優先順位順に 並べたタプルを返します。結果のリスト内で各クラスは一度だけ格納さ れます。メソッドの優先順位はクラスの型によって異なります。非常に特殊な ユーザ定義のメタクラスを使用していない限り、 *cls* が戻り値の先頭要素となり ます。 @@ -435,18 +796,41 @@ インタープリタスタック ----------------------- +.. When the following functions return "frame records," each record is a tuple of +.. six items: the frame object, the filename, the line number of the current line, +.. the function name, a list of lines of context from the source code, and the +.. index of the current line within that list. + 以下の関数には、戻り値として"フレームレコード"を返す関数があります。" フ レームレコード"は長さ6のタプルで、以下の値を格納しています:フレームオ ブジェクト・ファイル名・実行中の行番号・関数名・コンテキストのソース行のリ スト・ソース行リストの実行中行のインデックス。 + .. warning:: + .. Keeping references to frame objects, as found in the first element of the frame + .. records these functions return, can cause your program to create reference + .. cycles. Once a reference cycle has been created, the lifespan of all objects + .. which can be accessed from the objects which form the cycle can become much + .. longer even if Python's optional cycle detector is enabled. If such cycles must + .. be created, it is important to ensure they are explicitly broken to avoid the + .. delayed destruction of objects and increased memory consumption which occurs. + フレームレコードの最初の要素などのフレームオブジェクトへの参照を保存する と、循環参照になってしまう場合があります。循環参照ができると、Pythonの循 環参照検出機能を有効にしていたとしても関連するオブジェクトが参照している すべてのオブジェクトが解放されにくくなり、明示的に参照を削除しないとメモ リ消費量が増大する恐れがあります。 + + .. Though the cycle detector will catch these, destruction of the frames (and local + .. variables) can be made deterministic by removing the cycle in a + .. :keyword:`finally` clause. This is also important if the cycle detector was + .. disabled when Python was compiled or using :func:`gc.disable`. For example: + 参照の削除をPythonの循環参照検出機能にまかせる事もできます が、 :keyword:`finally` 節で循環参照を解除すれば確実にフレーム(とそのローカ ル 変数)は削除されます。また、循環参照検出機能はPythonのコンパイルオプショ ンや :func:`gc. disable` で無効とされている場合があります - ので注意が必要です。例: :: + ので注意が必要です。例: + + + :: def handle_stackframe_without_leak(): frame = inspect.currentframe() @@ -455,22 +839,39 @@ finally: del frame + +.. The optional *context* argument supported by most of these functions specifies +.. the number of lines of context to return, which are centered around the current +.. line. + 以下の関数でオプション引数 *context* には、戻り値のソース行リストに何行分の ソースを含めるかを指定します。ソース行リストには、実行中の行を中心 として指定された行数分のリストを返します。 .. function:: getframeinfo(frame[, context]) + .. Get information about a frame or traceback object. A 5-tuple is returned, the + .. last five elements of the frame's frame record. + フレーム又はトレースバックオブジェクトの情報を取得します。フレームレコー ドの先頭要素を除いた、長さ5のタプルを返します。 + + .. .. versionchanged:: 2.6 + .. Returns a :term:`named tuple` ``Traceback(filename, lineno, function, + .. code_context, index)``. + .. versionchanged:: 2.6 - .. Returns a :term:`named tuple` ``Traceback(filename, lineno, function, - code_context, index)``. ``Traceback(filename, lineno, function, code_context, index)`` 形式の名前付きタプル(:term:`named tuple`)を返します。 + .. function:: getouterframes(frame[, context]) + .. Get a list of frame records for a frame and all outer frames. These frames + .. represent the calls that lead to the creation of *frame*. The first entry in the + .. returned list represents *frame*; the last entry represents the outermost call + .. on *frame*'s stack. + 指定したフレームと、その外側の全フレームのフレームレコードを返します。外 側のフレームとは *frame* が生成されるまでのすべての関数呼び出しを 示します。戻り値のリストの先頭は *frame* のフレームレコードで、末尾の要 素は *frame* のスタックにあるもっとも外側のフレームのフレームレ コードとなります。 @@ -478,23 +879,39 @@ .. function:: getinnerframes(traceback[, context]) + .. Get a list of frame records for a traceback's frame and all inner frames. These + .. frames represent calls made as a consequence of *frame*. The first entry in the + .. list represents *traceback*; the last entry represents where the exception was + .. raised. + 指定したフレームと、その内側の全フレームのフレームレコードを返します。内 のフレームとは *frame* から続く一連の関数呼び出しを示します。戻り 値のリストの先頭は *traceback* のフレームレコードで、末尾の要素は例外が 発生した位置を示します。 .. function:: currentframe() + .. Return the frame object for the caller's stack frame. + 呼び出し元のフレームオブジェクトを返します。 .. function:: stack([context]) + .. Return a list of frame records for the caller's stack. The first entry in the + .. returned list represents the caller; the last entry represents the outermost + .. call on the stack. + 呼び出し元スタックのフレームレコードのリストを返します。最初の要素は呼び 出し元のフレームレコードで、末尾の要素はスタックにあるもっとも外側の フレームのフレームレコードとなります。 .. function:: trace([context]) + .. Return a list of frame records for the stack between the current frame and the + .. frame in which an exception currently being handled was raised in. The first + .. entry in the list represents the caller; the last entry represents where the + .. exception was raised. + 実行中のフレームと処理中の例外が発生したフレームの間のフレームレコードの リストを返します。最初の要素は呼び出し元のフレームレコードで、末尾の 要素は例外が発生した位置を示します。 ============================================================================== Revision: ecd21dd19a90 Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:14:36 2011 Log: 2.6.6: library/inspect.rst http://code.google.com/p/python-doc-ja/source/detail?r=ecd21dd19a90 Modified: /library/inspect.rst ======================================= --- /library/inspect.rst Sun Apr 17 04:14:26 2011 +++ /library/inspect.rst Sun Apr 17 04:14:36 2011 @@ -138,7 +138,7 @@ .. | frame | f_back | next outer frame object | | .. | | | (this frame's caller) | | .. +-----------+-----------------+---------------------------+-------+ -.. | | f_builtins | built-in namespace seen | | +.. | | f_builtins | builtins namespace seen | | .. | | | by this frame | | .. +-----------+-----------------+---------------------------+-------+ .. | | f_code | code object being | | @@ -578,12 +578,14 @@ オブジェクトがgetsetデスクリプタの場合に真を返します。 - .. getsets are attributes defined in extension modules via ``PyGetSetDef`` - .. structures. For Python implementations without such types, this method will - .. always return ``False``. - - getsetとは ``PyGetSetDef`` 構造体を用いて拡張モジュールで定義されてい - る属性のことです。Pythonの実装の場合はそのような型はないので、このメソッ ドは常に ``False`` を返します。 + .. impl-detail:: + + .. getsets are attributes defined in extension modules via + .. :ctype:`PyGetSetDef` structures. For Python implementations without such + .. types, this method will always return ``False``. + + getsetとは :ctype:`PyGetSetDef` 構造体を用いて拡張モジュールで定義さ れてい + る属性のことです。Pythonの実装の場合はそのような型はないので、このメ ソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -596,12 +598,14 @@ オブジェクトがメンバデスクリプタの場合に真を返します。 - .. Member descriptors are attributes defined in extension modules via - .. ``PyMemberDef`` structures. For Python implementations without such types, - .. this method will always return ``False``. - - メンバデスクリプタとは ``PyMemberDef`` 構造体を用いて拡張モジュールで定 義されている属性のことです。Pythonの実装の場合はそのような型はないの - で、このメソッドは常に ``False`` を返します。 + .. impl-detail:: + + .. Member descriptors are attributes defined in extension modules via + .. :ctype:`PyMemberDef` structures. For Python implementations without such + .. types, this method will always return ``False``. + + メンバデスクリプタとは :ctype:`PyMemberDef` 構造体を用いて拡張モジ ュールで定義されている属性のことです。Pythonの実装の場合はそのような型はない の + で、このメソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -717,14 +721,14 @@ .. function:: getargspec(func) - .. Get the names and default values of a function's arguments. A tuple of four + .. Get the names and default values of a Python function's arguments. A tuple of four .. things is returned: ``(args, varargs, varkw, defaults)``. *args* is a list of .. the argument names (it may contain nested lists). *varargs* and *varkw* are the .. names of the ``*`` and ``**`` arguments or ``None``. *defaults* is a tuple of .. default argument values or None if there are no default arguments; if this tuple .. has *n* elements, they correspond to the last *n* elements listed in *args*. - 関数の引数名とデフォルト値を取得します。戻り値は長さ4のタプルで、次の値 を返します:``(args, varargs, varkw, defaults)`` 。 + Python 関数の引数名とデフォルト値を取得します。戻り値は長さ4のタプルで、 次の値を返します:``(args, varargs, varkw, defaults)`` 。 *args* は引数名のリストです(ネストしたリストが格納される場合があります ) *varargs* と *varkw* は ``*`` 引数と ``**`` 引数の名前で、引数がなけれ ば ``None`` となります。 *defaults* は引数のデフォルト値のタプルか、デフォルト値がない場合は ``None`` です。 @@ -805,7 +809,7 @@ ブジェクト・ファイル名・実行中の行番号・関数名・コンテキストのソース行のリ スト・ソース行リストの実行中行のインデックス。 -.. warning:: +.. note:: .. Keeping references to frame objects, as found in the first element of the frame .. records these functions return, can cause your program to create reference @@ -895,6 +899,18 @@ 呼び出し元のフレームオブジェクトを返します。 + .. impl-detail:: + + .. This function relies on Python stack frame support in the interpreter, + .. which isn't guaranteed to exist in all implementations of Python. If + .. running in an implementation without Python stack frame support this + .. function returns ``None``. + + この関数はインタプリタの Python スタックフレームサポートに依存しま す。 + これは Python のすべての実装に存在している保証はありません。 + Python スタックフレームサポートのない実装で動作している場合、この関数 は ``None`` を返します。 + + .. function:: stack([context]) .. Return a list of frame records for the caller's stack. The first entry in the ============================================================================== Revision: c04b5677625d Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:19:33 2011 Log: 長い行の折り返しと空白の調整 http://code.google.com/p/python-doc-ja/source/detail?r=c04b5677625d Modified: /library/inspect.rst ======================================= --- /library/inspect.rst Sun Apr 17 04:14:36 2011 +++ /library/inspect.rst Sun Apr 17 04:19:33 2011 @@ -18,16 +18,18 @@ .. and format the argument list for a function, or get all the information you need .. to display a detailed traceback. -:mod:`inspect` は、モジュール・クラス・メソッド・関数・トレースバック・フ レームオブジェクト・コードオブジェクトなどのオブジェクトから情報を取得 -する関数を定義しており、クラスの内容を調べる、メソッドのソースコードを取得 する、関数の引数リストを取得して整形する、トレースバックから必要な情報 -だけを取得して表示する、などの処理を行う場合に利用します。 +:mod:`inspect` は、モジュール・クラス・メソッド・関数・トレースバック・ +フレームオブジェクト・コードオブジェクトなどのオブジェクトから情報を取得す る関数を定義しており、 +クラスの内容を調べる、メソッドのソースコードを取得する、関数の引数リストを 取得して整形する、 +トレースバックから必要な情報だけを取得して表示する、などの処理を行う場合に 利用します。 .. There are four main kinds of services provided by this module: type checking, .. getting source code, inspecting classes and functions, and examining the .. interpreter stack. -このモジュールの機能は、型チェック・ソースコードの取得・クラス/関数から情 報を取得・インタープリタのスタック情報の調査、の4種類に分類する事ができま す。 +このモジュールの機能は、型チェック・ソースコードの取得・クラス/関数から情 報を取得・ +インタープリタのスタック情報の調査、の4種類に分類する事ができます。 .. _inspect-types: @@ -41,8 +43,9 @@ .. They also help you determine when you can expect to find the following special .. attributes: -:func:`getmembers` は、クラスやモジュールなどのオブジェクトからメンバを取得 します。名前が"is"で始まる 16 -個の関数は、 :func:`getmembers` の2番目の引数として利用する事ができますし、 以下のような特殊属性を参照できるかどうか調べる時にも使えます。 +:func:`getmembers` は、クラスやモジュールなどのオブジェクトからメンバを取得 します。 +名前が"is"で始まる16個の関数は、 :func:`getmembers` の2番目の引数として利用 する事ができますし、 +以下のような特殊属性を参照できるかどうか調べる時にも使えます。 .. +-----------+-----------------+---------------------------+-------+ @@ -228,7 +231,7 @@ +===========+=================+=====================================================+=======+ | module | __doc__ | ドキュメント文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | __file__ | ファイル名(組み込みモジュールには存在しな い | | +| | __file__ | ファイル名 (組み込みモジュールには存在しな い) | | +-----------+-----------------+-----------------------------------------------------+-------+ | class | __doc__ | ドキュメント文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -250,7 +253,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | __name__ | 関数が定義された時の名 前 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | func_code | 関数をコンパイルしたバイトコード (:term:`bytecode`) | | +| | func_code | 関数をコンパイルしたバイトコード (:term:`bytecode`) | | | | | を格納するコードオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ | | func_defaults | 引数のデフォルト値のタプ ル | | @@ -283,26 +286,26 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | traceback | tb_frame | このレベルのフレームオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | tb_lasti | 最後に実行しようとしたバイトコード中のイン ストラク | | -| | | ションを示すインデック ス。 | | +| | tb_lasti | 最後に実行しようとしたバイトコード中 の | | +| | | インストラクションを示すインデック ス。 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | tb_lineno | 現在のPythonソースコードの行番 号 | | +| | tb_lineno | 現在の Python ソースコードの行番 号 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | tb_next | このオブジェクトの内側(このレベルから呼び出 された) | | +| | tb_next | このオブジェクトの内側 (このレベルから呼び 出された) | | | | | のトレースバックオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ -| frame | f_back | 外側 (このフレームを呼び出した)のフレームオ ブジ | | -| | | ェク ト | | +| frame | f_back | 外側 (このフレームを呼び出した) の | | +| | | フレームオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_builtins | このフレームで参照している組み込み名前空 間 | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_code | このフレームで実行しているコードオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_exc_traceback | このフレームで例外が発生した場合にはト レー | | -| | | スバックオブジェクト。それ以外なら ``None`` | | +| | f_exc_traceback | このフレームで例外が発生した場合に は | | +| | | トレースバックオブジェクト。それ以外なら ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_exc_type | このフレームで例外が発生した場合には例外 型。それ | | -| | | 以外なら ``None`` | | +| | f_exc_type | このフレームで例外が発生した場合には例外 型。 | | +| | | それ以外なら ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_exc_value | このフレームで例外が発生した場合には例外の 値。 | | | | | それ以外なら ``None`` | | @@ -311,7 +314,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | f_lasti | 最後に実行しようとしたバイトコードのインデ ックス。 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_lineno | 現在のPythonソースコードの行番 号 | | +| | f_lineno | 現在の Python ソースコードの行番 号 | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_locals | このフレームで参照しているローカル名前空 間 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -319,7 +322,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | f_trace | このフレームのトレース関数、または ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ -| code | co_argcount | 引数の数(\*、\*\*引数は含まない ) | | +| code | co_argcount | 引数の数 (\*、\*\*引数は含まない ) | | +-----------+-----------------+-----------------------------------------------------+-------+ | | co_code | コンパイルされたバイトコードそのままの文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -327,7 +330,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | co_filename | コードオブジェクトを生成したファイルのファ イル名 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | co_firstlineno | Pythonソースコードの先頭 行 | | +| | co_firstlineno | Python ソースコードの先頭 行 | | +-----------+-----------------+-----------------------------------------------------+-------+ | | co_flags | 以下の値の組み合わせ: 1=optimized | | | | | ``|`` 2=newlocals ``| `` | | @@ -371,8 +374,8 @@ .. name. If the optional *predicate* argument is supplied, only members for which .. the predicate returns a true value are included. - オブジェクトの全メンバを、(名前, 値)の組み合わせのリストで返します。リス トはメンバ名でソートされています。 *predicate* が指定されている場 - 合、predicateの戻り値が真となる値のみを返します。 + オブジェクトの全メンバを、 (名前, 値) の組み合わせのリストで返します。リ ストはメンバ名でソートされています。 + *predicate* が指定されている場合、 predicate の戻り値が真となる値のみを 返します。 .. note:: @@ -397,11 +400,12 @@ .. defined in the :mod:`imp` module; see the documentation for that module for .. more information on module types. - *path* で指定したファイルがモジュールであればそのモジュールがPython でど のように解釈されるかを示す``(name, suffix, mode, - mtype)``のタプルを返し、モジュールでなければ `` None``を返します。 *name* はパッケージ名を含まないモジュール - 名、 *suffix* はファイル名からモジュール名を除いた残りの部分(ドットによ る拡張子とは限らない)、 *mode* は :func:`open` で指定されるフ - ァイルモード(``'r'`` または ``'rb'``)、 *mtype* は :mod:`imp` で定義して いる整定数のいずれかが指定されます。モジュール - タイプに付いては :mod:`imp` を参照してください。 + *path* で指定したファイルがモジュールであればそのモジュールが Python で どのように解釈されるかを示す + ``(name, suffix, mode, mtype)`` のタプルを返し、モジュールでなければ ``None`` を返します。 + *name* はパッケージ名を含まないモジュール名、 *suffix* はファイル名から モジュール名を除いた残りの部分 (ドットによる拡張子とは限らない)、 + *mode* は :func:`open` で指定されるファイルモード (``'r'`` または ``'rb'``)、 + *mtype* は :mod:`imp` で定義している整定数のいずれかが指定されます。 + モジュールタイプに付いては :mod:`imp` を参照してください。 .. .. versionchanged:: 2.6 @@ -409,8 +413,7 @@ .. module_type)``. .. versionchanged:: 2.6 - 名前付きタプル(:term:`named tuple`) の ``ModuleInfo(name, suffix, mode, module_type)`` - を返します。 + 名前付きタプル (:term:`named tuple`) の ``ModuleInfo(name, suffix, mode, module_type)`` を返します。 .. function:: getmodulename(path) @@ -420,8 +423,9 @@ .. uses when searching for modules. If the name cannot be matched according to the .. interpreter's rules, ``None`` is returned. - *path* で指定したファイルの、パッケージ名を含まないモジュール名を返しま す。この処理は、インタープリタがモジュールを検索する時と同じアルゴ - リズムで行われます。ファイルがこのアルゴリズムで見つからない場合には ``None`` が返ります。 + *path* で指定したファイルの、パッケージ名を含まないモジュール名を返しま す。 + この処理は、インタープリタがモジュールを検索する時と同じアルゴリズムで行 われます。 + ファイルがこのアルゴリズムで見つからない場合には ``None`` が返ります。 .. function:: ismodule(object) @@ -449,14 +453,14 @@ .. Return true if the object is a Python function or unnamed (:term:`lambda`) function. - オブジェクトがPythonの関数、または無名関数(:term:`lambda`)の場合は真を返 します。 + オブジェクトが Python の関数、または無名関数 (:term:`lambda`) の場合は真 を返します。 .. function:: isgeneratorfunction(object) .. Return true if the object is a Python generator function. - *object* がPythonのジェネレータ関数であるときに真を返します。 + *object* が Python のジェネレータ関数であるときに真を返します。 .. versionadded:: 2.6 @@ -511,7 +515,7 @@ .. Return true if the object is an abstract base class. - *object* が抽象規定型(ABC)であるときに真を返します。 + *object* が抽象規定型 (ABC) であるときに真を返します。 .. versionadded:: 2.6 @@ -521,8 +525,8 @@ .. Return true if the object is a method descriptor, but not if :func:`ismethod` .. or :func:`isclass` or :func:`isfunction` are true. - オブジェクトがメソッドデスクリプタの場合に真を返します が、 :func:`ismethod`, :func:`isclass` または :func:`isfunction` - が真の場合には真を返しません。 + オブジェクトがメソッドデスクリプタの場合に真を返しますが、 + :func:`ismethod`, :func:`isclass` または :func:`isfunction` が真の場合に は真を返しません。 .. This is new as of Python 2.2, and, for example, is true of @@ -530,8 +534,8 @@ .. but not a :attr:`__set__` attribute, but beyond that the set of attributes .. varies. :attr:`__name__` is usually sensible, and :attr:`__doc__` often is. - この機能は Python 2.2 から新たに追加されたもので、例えば ``int.__add__`` は真になります。このテストをパスするオブジェクトは - :attr:`__get__` 属性を持ちますが :attr:`__set__` 属性を持ちません。 + この機能は Python 2.2 から新たに追加されたもので、例えば ``int.__add__`` は真になります。 + このテストをパスするオブジェクトは :attr:`__get__` 属性を持ちます が :attr:`__set__` 属性を持ちません。 それ以外の属性を持っているかもしれません。 通常 :attr:`__name__` を持っていますし、しばしば :attr:`__doc__` も持っ ています。 @@ -541,8 +545,8 @@ .. other tests promise more -- you can, e.g., count on having the .. :attr:`im_func` attribute (etc) when an object passes :func:`ismethod`. - デスクリプタを使って実装されたメソッドで、上記のいずれかのテストもパスし ているものは、 :func:`ismethoddescriptor` - では偽を返します。これは単に他のテストの方がもっと確実だからです -- + デスクリプタを使って実装されたメソッドで、上記のいずれかのテストもパスし ているものは、 + :func:`ismethoddescriptor` では偽を返します。これは単に他のテストの方が もっと確実だからです -- 例えば、 :func:`ismethod` をパスしたオブジェクトは :attr:`im_func` 属性 などを持っていると期待できます。 @@ -563,9 +567,10 @@ データデスクリプタは :attr:`__get__` および :attr:`__set__` 属性の両方を 持ちます。 データデスクリプタの例は (Python 上で定義された) プロパティや getset や メンバです。 - 後者のふたつは C で定義されており、個々の型に特有のテストも行います。そ のため、Python の実装よりもより確実です。 - 通常、データデスクリプタは :attr:`__name__` や :attr:`__doc__` 属性を持 ちます (プロパティ、 getset - 、メンバは両方の属性を持っています) が、保証されているわけではありませ ん。 + 後者のふたつは C で定義されており、個々の型に特有のテストも行います。 + そのため、Python の実装よりもより確実です。 + 通常、データデスクリプタは :attr:`__name__` や :attr:`__doc__` 属性を持 ちます + (プロパティ、 getset 、メンバは両方の属性を持っています) が、保証されて いるわけではありません。 .. versionadded:: 2.3 @@ -575,7 +580,7 @@ .. Return true if the object is a getset descriptor. - オブジェクトがgetsetデスクリプタの場合に真を返します。 + オブジェクトが getset デスクリプタの場合に真を返します。 .. impl-detail:: @@ -584,8 +589,8 @@ .. :ctype:`PyGetSetDef` structures. For Python implementations without such .. types, this method will always return ``False``. - getsetとは :ctype:`PyGetSetDef` 構造体を用いて拡張モジュールで定義さ れてい - る属性のことです。Pythonの実装の場合はそのような型はないので、このメ ソッドは常に ``False`` を返します。 + getsetとは :ctype:`PyGetSetDef` 構造体を用いて拡張モジュールで定義さ れている属性のことです。 + Python の実装の場合はそのような型はないので、このメソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -604,8 +609,8 @@ .. :ctype:`PyMemberDef` structures. For Python implementations without such .. types, this method will always return ``False``. - メンバデスクリプタとは :ctype:`PyMemberDef` 構造体を用いて拡張モジ ュールで定義されている属性のことです。Pythonの実装の場合はそのような型はない の - で、このメソッドは常に ``False`` を返します。 + メンバデスクリプタとは :ctype:`PyMemberDef` 構造体を用いて拡張モジ ュールで定義されている属性のことです。 + Python の実装の場合はそのような型はないので、このメソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -629,8 +634,9 @@ .. object's source code (for a class, function, or method), or at the top of the .. Python source file (if the object is a module). - オブジェクトがクラス・関数・メソッドの何れかの場合は、オブジェクトのソー スコードの直後にあるコメント行(複数行)を、単一の文字列として返し - ます。オブジェクトがモジュールの場合、ソースファイルの先頭にあるコメント を返します。 + オブジェクトがクラス・関数・メソッドの何れかの場合は、 + オブジェクトのソースコードの直後にあるコメント行 (複数行) を、単一の文字 列として返します。 + オブジェクトがモジュールの場合、ソースファイルの先頭にあるコメントを返し ます。 .. function:: getfile(object) @@ -639,8 +645,8 @@ .. This will fail with a :exc:`TypeError` if the object is a built-in module, .. class, or function. - オブジェクトを定義している(テキストまたはバイナリの)ファイルの名前を返 します。オブジェクトが組み込みモジュール・クラス・関数の場合は - :exc:`TypeError` 例外が発生します。 + オブジェクトを定義している (テキストまたはバイナリの) ファイルの名前を返 します。 + オブジェクトが組み込みモジュール・クラス・関数の場合は :exc:`TypeError` 例外が発生します。 .. function:: getmodule(object) @@ -656,8 +662,8 @@ .. will fail with a :exc:`TypeError` if the object is a built-in module, class, or .. function. - オブジェクトを定義しているPythonソースファイルの名前を返します。オブジェ クトが組み込みのモジュール、クラス、関数の場合には、 - :exc:`TypeError` 例外が発生します。 + オブジェクトを定義している Python ソースファイルの名前を返します。 + オブジェクトが組み込みのモジュール、クラス、関数の場合に は、 :exc:`TypeError` 例外が発生します。 .. function:: getsourcelines(object) @@ -669,9 +675,10 @@ .. line of code was found. An :exc:`IOError` is raised if the source code cannot .. be retrieved. - オブジェクトのソース行のリストと開始行番号を返します。引数にはモジュー ル・クラス・メソッド・関数・トレースバック・フレーム・コードオブジェク - トを指定する事ができます。戻り値は指定したオブジェクトに対応するソース コードのソース行リストと元のソースファイル上での開始行となります。ソー - スコードを取得できない場合は :exc:`IOError` が発生します。 + オブジェクトのソース行のリストと開始行番号を返します。 + 引数にはモジュール・クラス・メソッド・関数・トレースバック・フレーム・ コードオブジェクトを指定する事ができます。 + 戻り値は指定したオブジェクトに対応するソースコードのソース行リストと元の ソースファイル上での開始行となります。 + ソースコードを取得できない場合は :exc:`IOError` が発生します。 .. function:: getsource(object) @@ -681,8 +688,9 @@ .. returned as a single string. An :exc:`IOError` is raised if the source code .. cannot be retrieved. - オブジェクトのソースコードを返します。引数にはモジュール・クラス・メソッ ド・関数・トレースバック・フレーム・コードオブジェクトを指定する事が - できます。ソースコードは単一の文字列で返します。ソースコードを取得できな い場合は :exc:`IOError` が発生します。 + オブジェクトのソースコードを返します。 + 引数にはモジュール・クラス・メソッド・関数・トレースバック・フレーム・ コードオブジェクトを指定する事ができます。 + ソースコードは単一の文字列で返します。ソースコードを取得できない場合 は :exc:`IOError` が発生します。 .. function:: cleandoc(doc) @@ -692,8 +700,7 @@ .. onwards is removed. Also, all tabs are expanded to spaces. インデントされた docstring から、コードブロックまでのインデントを削除し ます。 - 2行目以降では行頭の空白は一様に削除されます。 - 全てのタブはスペースに展開されます。 + 2行目以降では行頭の空白は一様に削除されます。全てのタブはスペースに展開 されます。 .. versionadded:: 2.6 @@ -714,9 +721,11 @@ .. classes using multiple inheritance and their descendants will appear multiple .. times. - リストで指定したクラスの継承関係から、ネストしたリストを作成します。ネス トしたリストには、直前の要素から派生したクラスが格納されます。各要素 - は長さ2のタプルで、クラスと基底クラスのタプルを格納しています。 *unique* が真の場合、各クラスは戻り値のリスト内に一つだけしか格納 - されません。真でなければ、多重継承を利用したクラスとその派生クラスは複数 回格納される場合があります。 + リストで指定したクラスの継承関係から、ネストしたリストを作成します。 + ネストしたリストには、直前の要素から派生したクラスが格納されます。 + 各要素は長さ2のタプルで、クラスと基底クラスのタプルを格納しています。 + *unique* が真の場合、各クラスは戻り値のリスト内に一つだけしか格納されま せん。 + 真でなければ、多重継承を利用したクラスとその派生クラスは複数回格納される 場合があります。 .. function:: getargspec(func) @@ -728,8 +737,8 @@ .. default argument values or None if there are no default arguments; if this tuple .. has *n* elements, they correspond to the last *n* elements listed in *args*. - Python 関数の引数名とデフォルト値を取得します。戻り値は長さ4のタプルで、 次の値を返します:``(args, varargs, varkw, defaults)`` 。 - *args* は引数名のリストです(ネストしたリストが格納される場合があります ) + Python 関数の引数名とデフォルト値を取得します。戻り値は長さ4のタプルで、 次の値を返します: ``(args, varargs, varkw, defaults)`` 。 + *args* は引数名のリストです (ネストしたリストが格納される場合があります )。 *varargs* と *varkw* は ``*`` 引数と ``**`` 引数の名前で、引数がなけれ ば ``None`` となります。 *defaults* は引数のデフォルト値のタプルか、デフォルト値がない場合は ``None`` です。 このタプルに *n* 個の要素があれば、各要素は *args* の後ろから *n* 個分の 引数のデフォルト値となります。 @@ -740,7 +749,7 @@ .. defaults)``. .. versionchanged:: 2.6 - ``ArgSpec(args, varargs, keywords, defaults)`` 形式の名前付きタプル (:term:`named tuple`)を返します。 + ``ArgSpec(args, varargs, keywords, defaults)`` 形式の名前付きタプル (:term:`named tuple`) を返します。 .. function:: getargvalues(frame) @@ -751,9 +760,10 @@ .. names of the ``*`` and ``**`` arguments or ``None``. *locals* is the locals .. dictionary of the given frame. - 指定したフレームに渡された引数の情報を取得します。戻り値は長さ4のタプル で、次の値を返します:``(args, varargs, varkw, - locals)``。 *args* は引数名のリストです(ネストしたリストが格納される場 合があります)。 *varargs* と *varkw* は``*``引数と - ``**`` 引数の名前で、引数がなければ ``None`` となります。 * locals*は指 定したフレームのローカル変数の辞書です。 + 指定したフレームに渡された引数の情報を取得します。戻り値は長さ4のタプル で、次の値を返します: ``(args, varargs, varkw, locals)`` 。 + *args* は引数名のリストです (ネストしたリストが格納される場合があります )。 + *varargs* と *varkw* は ``*`` 引数と ``**`` 引数の名前で、引数がなけれ ば ``None`` となります。 + *locals* は指定したフレームのローカル変数の辞書です。 .. .. versionchanged:: 2.6 @@ -761,7 +771,7 @@ .. locals)``. .. versionchanged:: 2.6 - ``ArgInfo(args, varargs, keywords, locals)`` 形式の名前付きタプル (:term:`named tuple`)を返します。 + ``ArgInfo(args, varargs, keywords, locals)`` 形式の名前付きタプル (:term:`named tuple`) を返します。 .. function:: formatargspec(args[, varargs, varkw, defaults, formatarg, formatvarargs, formatvarkw, formatvalue, join]) @@ -770,8 +780,8 @@ .. :func:`getargspec`. The format\* arguments are the corresponding optional .. formatting functions that are called to turn names and values into strings. - :func:`getargspec` で取得した4つの値を読みやすく整形します。 format\* - 引数はオプションで、名前と値を文字列に変換する整形関数を指定する事ができ ます。 + :func:`getargspec` で取得した4つの値を読みやすく整形します。 + format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す る事ができます。 .. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue, join]) @@ -780,8 +790,8 @@ .. :func:`getargvalues`. The format\* arguments are the corresponding optional .. formatting functions that are called to turn names and values into strings. - :func:`getargvalues` で取得した4つの値を読みやすく整形します。 format\* - 引数はオプションで、名前と値を文字列に変換する整形関数を指定する事ができ ます。 + :func:`getargvalues` で取得した4つの値を読みやすく整形します。 + format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す る事ができます。 .. function:: getmro(cls) @@ -791,8 +801,9 @@ .. resolution order depends on cls's type. Unless a very peculiar user-defined .. metatype is in use, cls will be the first element of the tuple. - *cls* クラスの基底クラス( *cls* 自身も含む)を、メソッドの優先順位順に 並べたタプルを返します。結果のリスト内で各クラスは一度だけ格納さ - れます。メソッドの優先順位はクラスの型によって異なります。非常に特殊な ユーザ定義のメタクラスを使用していない限り、 *cls* が戻り値の先頭要素となり ます。 + *cls* クラスの基底クラス (*cls* 自身も含む) を、メソッドの優先順位順に並 べたタプルを返します。 + 結果のリスト内で各クラスは一度だけ格納されます。メソッドの優先順位はクラ スの型によって異なります。 + 非常に特殊なユーザ定義のメタクラスを使用していない限り、 *cls* が戻り値 の先頭要素となります。 .. _inspect-stack: @@ -805,8 +816,9 @@ .. the function name, a list of lines of context from the source code, and the .. index of the current line within that list. -以下の関数には、戻り値として"フレームレコード"を返す関数があります。" フ レームレコード"は長さ6のタプルで、以下の値を格納しています:フレームオ -ブジェクト・ファイル名・実行中の行番号・関数名・コンテキストのソース行のリ スト・ソース行リストの実行中行のインデックス。 +以下の関数には、戻り値として"フレームレコード"を返す関数があります。 +"フレームレコード"は長さ6のタプルで、以下の値を格納しています: +フレームオブジェクト・ファイル名・実行中の行番号・関数名・コンテキストの ソース行のリスト・ソース行リストの実行中行のインデックス。 .. note:: @@ -819,9 +831,9 @@ .. be created, it is important to ensure they are explicitly broken to avoid the .. delayed destruction of objects and increased memory consumption which occurs. - フレームレコードの最初の要素などのフレームオブジェクトへの参照を保存する と、循環参照になってしまう場合があります。循環参照ができると、Pythonの循 - 環参照検出機能を有効にしていたとしても関連するオブジェクトが参照している すべてのオブジェクトが解放されにくくなり、明示的に参照を削除しないとメモ - リ消費量が増大する恐れがあります。 + フレームレコードの最初の要素などのフレームオブジェクトへの参照を保存する と、循環参照になってしまう場合があります。 + 循環参照ができると、 Python の循環参照検出機能を有効にしていたとしても関 連するオブジェクトが参照しているすべてのオブジェクトが解放されにくくなり、 + 明示的に参照を削除しないとメモリ消費量が増大する恐れがあります。 .. Though the cycle detector will catch these, destruction of the frames (and local @@ -829,9 +841,8 @@ .. :keyword:`finally` clause. This is also important if the cycle detector was .. disabled when Python was compiled or using :func:`gc.disable`. For example: - 参照の削除をPythonの循環参照検出機能にまかせる事もできます が、 :keyword:`finally` 節で循環参照を解除すれば確実にフレーム(とそのローカ ル - 変数)は削除されます。また、循環参照検出機能はPythonのコンパイルオプショ ンや :func:`gc. disable` で無効とされている場合があります - ので注意が必要です。例: + 参照の削除を Python の循環参照検出機能にまかせる事もできます が、 :keyword:`finally` 節で循環参照を解除すれば確実にフレーム (とそのローカ ル変数) は削除されます。 + また、循環参照検出機能は Python のコンパイルオプションや :func:`gc. disable` で無効とされている場合がありますので注意が必要です。例: :: @@ -848,8 +859,8 @@ .. the number of lines of context to return, which are centered around the current .. line. -以下の関数でオプション引数 *context* には、戻り値のソース行リストに何行分の ソースを含めるかを指定します。ソース行リストには、実行中の行を中心 -として指定された行数分のリストを返します。 +以下の関数でオプション引数 *context* には、戻り値のソース行リストに何行分の ソースを含めるかを指定します。 +ソース行リストには、実行中の行を中心として指定された行数分のリストを返しま す。 .. function:: getframeinfo(frame[, context]) @@ -857,7 +868,8 @@ .. Get information about a frame or traceback object. A 5-tuple is returned, the .. last five elements of the frame's frame record. - フレーム又はトレースバックオブジェクトの情報を取得します。フレームレコー ドの先頭要素を除いた、長さ5のタプルを返します。 + フレーム又はトレースバックオブジェクトの情報を取得します。 + フレームレコードの先頭要素を除いた、長さ5のタプルを返します。 .. .. versionchanged:: 2.6 @@ -866,7 +878,7 @@ .. versionchanged:: 2.6 ``Traceback(filename, lineno, function, code_context, index)`` - 形式の名前付きタプル(:term:`named tuple`)を返します。 + 形式の名前付きタプル (:term:`named tuple`) を返します。 .. function:: getouterframes(frame[, context]) @@ -876,9 +888,10 @@ .. returned list represents *frame*; the last entry represents the outermost call .. on *frame*'s stack. - 指定したフレームと、その外側の全フレームのフレームレコードを返します。外 側のフレームとは *frame* が生成されるまでのすべての関数呼び出しを - 示します。戻り値のリストの先頭は *frame* のフレームレコードで、末尾の要 素は *frame* のスタックにあるもっとも外側のフレームのフレームレ - コードとなります。 + 指定したフレームと、その外側の全フレームのフレームレコードを返します。 + 外側のフレームとは *frame* が生成されるまでのすべての関数呼び出しを示し ます。 + 戻り値のリストの先頭は *frame* のフレームレコードで、 + 末尾の要素は *frame* のスタックにあるもっとも外側のフレームのフレームレ コードとなります。 .. function:: getinnerframes(traceback[, context]) @@ -888,8 +901,9 @@ .. list represents *traceback*; the last entry represents where the exception was .. raised. - 指定したフレームと、その内側の全フレームのフレームレコードを返します。内 のフレームとは *frame* から続く一連の関数呼び出しを示します。戻り - 値のリストの先頭は *traceback* のフレームレコードで、末尾の要素は例外が 発生した位置を示します。 + 指定したフレームと、その内側の全フレームのフレームレコードを返します。 + 内のフレームとは *frame* から続く一連の関数呼び出しを示します。 + 戻り値のリストの先頭は *traceback* のフレームレコードで、末尾の要素は例 外が発生した位置を示します。 .. function:: currentframe() @@ -917,8 +931,8 @@ .. returned list represents the caller; the last entry represents the outermost .. call on the stack. - 呼び出し元スタックのフレームレコードのリストを返します。最初の要素は呼び 出し元のフレームレコードで、末尾の要素はスタックにあるもっとも外側の - フレームのフレームレコードとなります。 + 呼び出し元スタックのフレームレコードのリストを返します。 + 最初の要素は呼び出し元のフレームレコードで、末尾の要素はスタックにあるも っとも外側のフレームのフレームレコードとなります。 .. function:: trace([context]) @@ -928,6 +942,6 @@ .. entry in the list represents the caller; the last entry represents where the .. exception was raised. - 実行中のフレームと処理中の例外が発生したフレームの間のフレームレコードの リストを返します。最初の要素は呼び出し元のフレームレコードで、末尾の - 要素は例外が発生した位置を示します。 - + 実行中のフレームと処理中の例外が発生したフレームの間のフレームレコードの リストを返します。 + 最初の要素は呼び出し元のフレームレコードで、末尾の要素は例外が発生した位 置を示します。 + ============================================================================== Revision: a55592ac50bc Author: Nozomu Kaneko <nozom****@gmail*****> Date: Sun Apr 17 04:19:44 2011 Log: revised: library/inspect.rst http://code.google.com/p/python-doc-ja/source/detail?r=a55592ac50bc Modified: /library/inspect.rst ======================================= --- /library/inspect.rst Sun Apr 17 04:19:33 2011 +++ /library/inspect.rst Sun Apr 17 04:19:44 2011 @@ -1,9 +1,9 @@ - -:mod:`inspect` --- 使用中オブジェクトの情報を取得する -===================================================== + +:mod:`inspect` --- 活動中のオブジェクトの情報を取得する +======================================================= .. module:: inspect - :synopsis: 使用中のオブジェクトから、情報とソースコードを取得する。 + :synopsis: 活動中のオブジェクトから、情報とソースコードを取得する。 .. moduleauthor:: Ka-Ping Yee <ping****@lfw*****> .. sectionauthor:: Ka-Ping Yee <ping****@lfw*****> @@ -18,24 +18,24 @@ .. and format the argument list for a function, or get all the information you need .. to display a detailed traceback. -:mod:`inspect` は、モジュール・クラス・メソッド・関数・トレースバック・ -フレームオブジェクト・コードオブジェクトなどのオブジェクトから情報を取得す る関数を定義しており、 -クラスの内容を調べる、メソッドのソースコードを取得する、関数の引数リストを 取得して整形する、 -トレースバックから必要な情報だけを取得して表示する、などの処理を行う場合に 利用します。 +:mod:`inspect` は、 活動中のオブジェクト (モジュール、クラス、メソッド、関 数、トレースバック、 +フレームオブジェクト、コードオブジェクトなど) から情報を取得する関数を定義 しており、 +クラスの内容を調べたり、メソッドのソースコードを取得したり、関数の引数リス トを取り出して整形したり、 +詳細なトレースバックを表示するのに必要な情報を取得したりするために利用でき ます。 .. There are four main kinds of services provided by this module: type checking, .. getting source code, inspecting classes and functions, and examining the .. interpreter stack. -このモジュールの機能は、型チェック・ソースコードの取得・クラス/関数から情 報を取得・ -インタープリタのスタック情報の調査、の4種類に分類する事ができます。 +このモジュールの機能は4種類に分類することができます。 +型チェック、ソースコードの情報取得、クラスや関数からの情報取得、インタープ リタのスタック情報の調査です。 .. _inspect-types: -型とメンバ ----------- +型とメンバー +------------ .. The :func:`getmembers` function retrieves the members of an object such as a .. class or module. The sixteen functions whose names begin with "is" are mainly @@ -43,9 +43,9 @@ .. They also help you determine when you can expect to find the following special .. attributes: -:func:`getmembers` は、クラスやモジュールなどのオブジェクトからメンバを取得 します。 -名前が"is"で始まる16個の関数は、 :func:`getmembers` の2番目の引数として利用 する事ができますし、 -以下のような特殊属性を参照できるかどうか調べる時にも使えます。 +:func:`getmembers` は、クラスやモジュールなどのオブジェクトからメンバーを取 得します。 +名前が"is"で始まる16個の関数は、主に :func:`getmembers` の第2引数として利用 するために提供されています。 +以下のような特殊属性を参照できるかどうか調べる時にも使えるでしょう。 .. +-----------+-----------------+---------------------------+-------+ @@ -227,11 +227,11 @@ .. +-----------+-----------------+---------------------------+-------+ +-----------+-----------------+-----------------------------------------------------+-------+ -| Type | Attribute | Description | Notes | +| 型 | 属性 | 説 明 | 注 | +===========+=================+=====================================================+=======+ | module | __doc__ | ドキュメント文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | __file__ | ファイル名 (組み込みモジュールには存在しな い) | | +| | __file__ | ファイル名 (組み込みモジュールには存在しま せん) | | +-----------+-----------------+-----------------------------------------------------+-------+ | class | __doc__ | ドキュメント文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -243,10 +243,10 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | im_class | メソッドを呼び出すために必要なクラスオブジ ェクト | \(1) | +-----------+-----------------+-----------------------------------------------------+-------+ -| | im_func or | メソッドを実装している関数オブジェク ト | | +| | im_func または | メソッドを実装している関数オブジェク ト | | | | __func__ | | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | im_self or | メソッドに結合しているインスタンス、または ``None`` | | +| | im_self または | メソッドに結合しているインスタンス、または ``None`` | | | | __self__ | | | +-----------+-----------------+-----------------------------------------------------+-------+ | function | __doc__ | ドキュメント文字 列 | | @@ -264,30 +264,30 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | func_name | (__name__と同じ ) | | +-----------+-----------------+-----------------------------------------------------+-------+ -| generator | __iter__ | コンテナを通したイテレーションのために定義 される | | +| generator | __iter__ | コンテナを通したイテレーションのために定義 されます | | +-----------+-----------------+-----------------------------------------------------+-------+ | | close | イテレーションを停止するために、ジェネレー タの | | -| | | 内部で GeneratorExitexception を発生させ る | | +| | | 内部で GeneratorExitexception を発生させま す | | +-----------+-----------------+-----------------------------------------------------+-------+ | | gi_code | コードオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | gi_frame | フレームオブジェクト、もしく は、 | | -| | | ジェネレータが終了したあとは None の可能性 もある | | +| | gi_frame | フレームオブジェクト。ジェネレータが終了し たあとは | | +| | | None になることもありま す | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | gi_running | ジェネレータが実行中の時は 1. | | +| | gi_running | ジェネレータが実行中の時は 1 | | | | | それ以外の場合は 0 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | next | コンテナから次の要素を返 す | | +| | next | コンテナから次の要素を返しま す | | +-----------+-----------------+-----------------------------------------------------+-------+ | | send | ジェネレータを再開して、現在の yield 式の結 果と | | -| | | なる値を送 る。 | | +| | | なる値を送りま す | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | throw | ジェネレータ内部で例外を発生させるために用 いる | | +| | throw | ジェネレータ内部で例外を発生させるために用 います | | +-----------+-----------------+-----------------------------------------------------+-------+ | traceback | tb_frame | このレベルのフレームオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ | | tb_lasti | 最後に実行しようとしたバイトコード中 の | | -| | | インストラクションを示すインデック ス。 | | +| | | インストラクションを示すインデック ス | | +-----------+-----------------+-----------------------------------------------------+-------+ | | tb_lineno | 現在の Python ソースコードの行番 号 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -302,17 +302,17 @@ | | f_code | このフレームで実行しているコードオブジェク ト | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_exc_traceback | このフレームで例外が発生した場合に は | | -| | | トレースバックオブジェクト。それ以外なら ``None`` | | +| | | トレースバックオブジェクト、それ以外なら ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_exc_type | このフレームで例外が発生した場合には例外 型。 | | +| | f_exc_type | このフレームで例外が発生した場合には例外 型、 | | | | | それ以外なら ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_exc_value | このフレームで例外が発生した場合には例外の 値。 | | +| | f_exc_value | このフレームで例外が発生した場合には例外の 値、 | | | | | それ以外なら ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_globals | このフレームで参照しているグローバル名前空 間 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | f_lasti | 最後に実行しようとしたバイトコードのインデ ックス。 | | +| | f_lasti | 最後に実行しようとしたバイトコードのインデ ックス | | +-----------+-----------------+-----------------------------------------------------+-------+ | | f_lineno | 現在の Python ソースコードの行番 号 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -322,7 +322,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | f_trace | このフレームのトレース関数、または ``None`` | | +-----------+-----------------+-----------------------------------------------------+-------+ -| code | co_argcount | 引数の数 (\*、\*\*引数は含まない ) | | +| code | co_argcount | 引数の数 (\* や \*\* 引数は含まない ) | | +-----------+-----------------+-----------------------------------------------------+-------+ | | co_code | コンパイルされたバイトコードそのままの文字 列 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -336,8 +336,8 @@ | | | ``|`` 2=newlocals ``| `` | | | | | 4=\*arg ``|`` 8=\*\*arg | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | co_lnotab | 文字列にエンコードした、行番号->バイトコー ド | | -| | | インデックスへの変換 表 | | +| | co_lnotab | 行番号からバイトコードインデックスへの変換 表を | | +| | | 文字列にエンコードしたも の | | +-----------+-----------------+-----------------------------------------------------+-------+ | | co_name | コードオブジェクトが定義されたときの名 前 | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -345,7 +345,7 @@ +-----------+-----------------+-----------------------------------------------------+-------+ | | co_nlocals | ローカル変数の 数 | | +-----------+-----------------+-----------------------------------------------------+-------+ -| | co_stacksize | 必要な仮想機械のスタックスペー ス | | +| | co_stacksize | 必要とされる仮想マシンのスタックスペー ス | | +-----------+-----------------+-----------------------------------------------------+-------+ | | co_varnames | 引数名とローカル変数名のタプ ル | | +-----------+-----------------+-----------------------------------------------------+-------+ @@ -365,7 +365,7 @@ .. :attr:`im_class` used to refer to the class that defined the method. .. versionchanged:: 2.2 - :attr:`im_class` 従来、メソッドを定義しているクラスを参照するために使 用していた. + :attr:`im_class` は、以前はメソッドを定義しているクラスを指していまし た。 .. function:: getmembers(object[, predicate]) @@ -374,7 +374,7 @@ .. name. If the optional *predicate* argument is supplied, only members for which .. the predicate returns a true value are included. - オブジェクトの全メンバを、 (名前, 値) の組み合わせのリストで返します。リ ストはメンバ名でソートされています。 + オブジェクトの全メンバーを、 (名前, 値) の組み合わせのリストで返します。 リストはメンバー名でソートされています。 *predicate* が指定されている場合、 predicate の戻り値が真となる値のみを 返します。 @@ -383,7 +383,7 @@ .. :func:`getmembers` does not return metaclass attributes when the argument .. is a class (this behavior is inherited from the :func:`dir` function). - :func:`getmembers` は、引数がクラスの場合にメタクラス属性を返さない。 + :func:`getmembers` は、引数がクラスの場合にメタクラス属性を返しませ ん。 (この動作は :func:`dir` 関数に合わせてあります。) @@ -400,12 +400,13 @@ .. defined in the :mod:`imp` module; see the documentation for that module for .. more information on module types. - *path* で指定したファイルがモジュールであればそのモジュールが Python で どのように解釈されるかを示す - ``(name, suffix, mode, mtype)`` のタプルを返し、モジュールでなければ ``None`` を返します。 - *name* はパッケージ名を含まないモジュール名、 *suffix* はファイル名から モジュール名を除いた残りの部分 (ドットによる拡張子とは限らない)、 + *path* で指定したファイルがモジュールであれば、そのモジュールが Python でどのように解釈されるかを示す + ``(name, suffix, mode, mtype)`` のタプルを返します。モジュールでなけれ ば ``None`` を返します。 + *name* はパッケージ名を含まないモジュール名、 *suffix* はファイル名から モジュール名を除いた残りの部分 + (ドット区切りの拡張子であってはなりません)、 *mode* は :func:`open` で指定されるファイルモード (``'r'`` または ``'rb'``)、 - *mtype* は :mod:`imp` で定義している整定数のいずれかが指定されます。 - モジュールタイプに付いては :mod:`imp` を参照してください。 + *mtype* は :mod:`imp` で定義している定数のいずれかが指定されます。 + モジュールタイプについては :mod:`imp` を参照してください。 .. .. versionchanged:: 2.6 @@ -508,7 +509,7 @@ .. Return true if the object is a user-defined or built-in function or method. - オブジェクトがユーザ定義か組み込みの関数・メソッドの場合は真を返します。 + オブジェクトがユーザ定義か組み込みの関数またはメソッドの場合は真を返しま す。 .. function:: isabstract(object) @@ -566,11 +567,11 @@ .. not guaranteed. データデスクリプタは :attr:`__get__` および :attr:`__set__` 属性の両方を 持ちます。 - データデスクリプタの例は (Python 上で定義された) プロパティや getset や メンバです。 + データデスクリプタの例は (Python 上で定義された) プロパティや getset や メンバーです。 後者のふたつは C で定義されており、個々の型に特有のテストも行います。 そのため、Python の実装よりもより確実です。 通常、データデスクリプタは :attr:`__name__` や :attr:`__doc__` 属性を持 ちます - (プロパティ、 getset 、メンバは両方の属性を持っています) が、保証されて いるわけではありません。 + (プロパティ、 getset 、メンバーは両方の属性を持っています) が、保証され ているわけではありません。 .. versionadded:: 2.3 @@ -589,8 +590,8 @@ .. :ctype:`PyGetSetDef` structures. For Python implementations without such .. types, this method will always return ``False``. - getsetとは :ctype:`PyGetSetDef` 構造体を用いて拡張モジュールで定義さ れている属性のことです。 - Python の実装の場合はそのような型はないので、このメソッドは常に ``False`` を返します。 + getset とは、拡張モジュールで :ctype:`PyGetSetDef` 構造体を用いて定義 された属性のことです。 + そのような型を持たない Python 実装の場合は、このメソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -600,7 +601,7 @@ .. Return true if the object is a member descriptor. - オブジェクトがメンバデスクリプタの場合に真を返します。 + オブジェクトがメンバーデスクリプタの場合に真を返します。 .. impl-detail:: @@ -609,8 +610,8 @@ .. :ctype:`PyMemberDef` structures. For Python implementations without such .. types, this method will always return ``False``. - メンバデスクリプタとは :ctype:`PyMemberDef` 構造体を用いて拡張モジ ュールで定義されている属性のことです。 - Python の実装の場合はそのような型はないので、このメソッドは常に ``False`` を返します。 + メンバーデスクリプタとは、拡張モジュールで :ctype:`PyMemberDef` 構造 体を用いて定義された属性のことです。 + そのような型を持たない Python 実装の場合は、このメソッドは常に ``False`` を返します。 .. versionadded:: 2.5 @@ -618,8 +619,8 @@ .. _inspect-source: -ソース参照 ----------- +ソースコードの情報取得 +---------------------- .. function:: getdoc(object) @@ -634,7 +635,7 @@ .. object's source code (for a class, function, or method), or at the top of the .. Python source file (if the object is a module). - オブジェクトがクラス・関数・メソッドの何れかの場合は、 + オブジェクトがクラス、関数、メソッドのいずれかの場合は、 オブジェクトのソースコードの直後にあるコメント行 (複数行) を、単一の文字 列として返します。 オブジェクトがモジュールの場合、ソースファイルの先頭にあるコメントを返し ます。 @@ -646,7 +647,7 @@ .. class, or function. オブジェクトを定義している (テキストまたはバイナリの) ファイルの名前を返 します。 - オブジェクトが組み込みモジュール・クラス・関数の場合は :exc:`TypeError` 例外が発生します。 + オブジェクトが組み込みモジュール、クラス、関数の場合は :exc:`TypeError` 例外が発生します。 .. function:: getmodule(object) @@ -676,7 +677,7 @@ .. be retrieved. オブジェクトのソース行のリストと開始行番号を返します。 - 引数にはモジュール・クラス・メソッド・関数・トレースバック・フレーム・ コードオブジェクトを指定する事ができます。 + 引数にはモジュール、クラス、メソッド、関数、トレースバック、フレーム、 コードオブジェクトを指定することができます。 戻り値は指定したオブジェクトに対応するソースコードのソース行リストと元の ソースファイル上での開始行となります。 ソースコードを取得できない場合は :exc:`IOError` が発生します。 @@ -689,7 +690,7 @@ .. cannot be retrieved. オブジェクトのソースコードを返します。 - 引数にはモジュール・クラス・メソッド・関数・トレースバック・フレーム・ コードオブジェクトを指定する事ができます。 + 引数にはモジュール、クラス、メソッド、関数、トレースバック、フレーム、 コードオブジェクトを指定することができます。 ソースコードは単一の文字列で返します。ソースコードを取得できない場合 は :exc:`IOError` が発生します。 @@ -700,7 +701,7 @@ .. onwards is removed. Also, all tabs are expanded to spaces. インデントされた docstring から、コードブロックまでのインデントを削除し ます。 - 2行目以降では行頭の空白は一様に削除されます。全てのタブはスペースに展開 されます。 + 2行目以降では行頭の空白は一様に削除されます。全てのタブはスペースに展開 されます。 .. versionadded:: 2.6 @@ -781,7 +782,7 @@ .. formatting functions that are called to turn names and values into strings. :func:`getargspec` で取得した4つの値を読みやすく整形します。 - format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す る事ができます。 + format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す ることができます。 .. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue, join]) @@ -791,7 +792,7 @@ .. formatting functions that are called to turn names and values into strings. :func:`getargvalues` で取得した4つの値を読みやすく整形します。 - format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す る事ができます。 + format\* 引数はオプションで、名前と値を文字列に変換する整形関数を指定す ることができます。 .. function:: getmro(cls) @@ -818,7 +819,8 @@ 以下の関数には、戻り値として"フレームレコード"を返す関数があります。 "フレームレコード"は長さ6のタプルで、以下の値を格納しています: -フレームオブジェクト・ファイル名・実行中の行番号・関数名・コンテキストの ソース行のリスト・ソース行リストの実行中行のインデックス。 +フレームオブジェクト、ファイル名、実行中の行番号、関数名、コンテキストの ソース行のリスト、 +ソース行のリストにおける実行中の行のインデックス。 .. note:: @@ -841,7 +843,7 @@ .. :keyword:`finally` clause. This is also important if the cycle detector was .. disabled when Python was compiled or using :func:`gc.disable`. For example: - 参照の削除を Python の循環参照検出機能にまかせる事もできます が、 :keyword:`finally` 節で循環参照を解除すれば確実にフレーム (とそのローカ ル変数) は削除されます。 + 参照の削除を Python の循環参照検出機能にまかせることもできます が、 :keyword:`finally` 節で循環参照を解除すれば確実にフレーム (とそのローカ ル変数) は削除されます。 また、循環参照検出機能は Python のコンパイルオプションや :func:`gc. disable` で無効とされている場合がありますので注意が必要です。例: @@ -868,7 +870,7 @@ .. Get information about a frame or traceback object. A 5-tuple is returned, the .. last five elements of the frame's frame record. - フレーム又はトレースバックオブジェクトの情報を取得します。 + フレームまたはトレースバックオブジェクトの情報を取得します。 フレームレコードの先頭要素を除いた、長さ5のタプルを返します。 @@ -891,7 +893,7 @@ 指定したフレームと、その外側の全フレームのフレームレコードを返します。 外側のフレームとは *frame* が生成されるまでのすべての関数呼び出しを示し ます。 戻り値のリストの先頭は *frame* のフレームレコードで、 - 末尾の要素は *frame* のスタックにあるもっとも外側のフレームのフレームレ コードとなります。 + 末尾の要素は *frame* のスタックにある最も外側のフレームのフレームレコー ドとなります。 .. function:: getinnerframes(traceback[, context]) @@ -922,7 +924,7 @@ この関数はインタプリタの Python スタックフレームサポートに依存しま す。 これは Python のすべての実装に存在している保証はありません。 - Python スタックフレームサポートのない実装で動作している場合、この関数 は ``None`` を返します。 + Python スタックフレームサポートのない環境では、この関数は ``None`` を 返します。 .. function:: stack([context]) @@ -932,7 +934,7 @@ .. call on the stack. 呼び出し元スタックのフレームレコードのリストを返します。 - 最初の要素は呼び出し元のフレームレコードで、末尾の要素はスタックにあるも っとも外側のフレームのフレームレコードとなります。 + 最初の要素は呼び出し元のフレームレコードで、末尾の要素はスタックにある最 も外側のフレームのフレームレコードとなります。 .. function:: trace([context])