コードオブジェクト—Pythonドキュメント

提供:Dev Guides
< PythonPython/docs/3.8/c-api/code
移動先:案内検索

コードオブジェクト

コードオブジェクトは、CPython実装の低レベルの詳細です。 それぞれが、まだ関数にバインドされていない実行可能コードのチャンクを表します。

type PyCodeObject
コードオブジェクトの記述に使用されるオブジェクトのC構造体。 このタイプのフィールドは、いつでも変更される可能性があります。
PyTypeObject PyCode_Type
これは、Pythonのコードタイプを表す PyTypeObject のインスタンスです。
int PyCode_Check(PyObject *co)
cocode オブジェクトの場合はtrueを返します。
int PyCode_GetNumFree(PyCodeObject *co)
co の自由変数の数を返します。
PyCodeObject *PyCode_New(int argcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
新しいコードオブジェクトを返します。 フレームを作成するためにダミーのコードオブジェクトが必要な場合は、代わりに PyCode_NewEmpty()を使用してください。 PyCode_New()を直接呼び出すと、バイトコードの定義が頻繁に変更されるため、正確なPythonバージョンにバインドできます。
PyCodeObject *PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)

PyCode_New()に似ていますが、位置のみの引数用に追加の「posonlyargcount」があります。

バージョン3.8の新機能。

PyCodeObject *PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
指定されたファイル名、関数名、および最初の行番号を持つ新しい空のコードオブジェクトを返します。 結果のコードオブジェクトを exec()または eval()することは違法です。