per page, with , order by , clip by
Results of 1 - 10 of about 25 for Define (0.006 sec.)
__main__ --- トップレベルのコード環境 13317
__main__ --- トップレベルのコード環境 Python では、 __main__ という特別な名前が次の二つの重要な用途で使われます: プログラムのトップレベル環境の名前。 __name__ == '__main__' という式でチェックすることができる。 Python パッケージにおける __ma ... ジュールのインポートです。 __main__ の名前空間を利用するモジュールの例を示します。 # namely.py import __main__ def did_user_define_their_name (): return 'my_name' in dir ( __main__ ) def print_user_name (): if not did_user_define_their_name (): raise Va ... lueError ( 'Define the variable `my_name`!' ) print ( __main__ . my_name ) このモジュールは、例えば次のように使えます。 # start.py import sys ... if __name__ == "__main__" : sys . exit ( main ()) このプログラムを起動すると、次のような結果になります。 $ python start.py Define the variable `my_name`! プログラムの終了コードは、エラーを示す 1 になります。 my_name = "Dinsdale" の行のコメントを外すとプ ...
https://man.mtool.work/python/3.14/library/__main__.html
1. Extending Python with C or C++ 13068
1. Extending Python with C or C++ It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can't be done directly in Python: they can implement new built-in objec ... y can call C library functions and system calls. To support extensions, the Python API (Application Programmers Interface) defines a set of functions, macros and variables that provide access to most aspects of the Python run-time system. The Python AP ... dule name is very long, like spammify , the module name can be just spammify.c .) The first two lines of our file can be: #define PY_SSIZE_T_CLEAN #include <Python.h> which pulls in the Python API (you can add a comment describing the purpose of the mo ... dule and a copyright notice if you like). 注釈 Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any sta ...
https://man.mtool.work/python/3.14/extending/extending.html
C API Stability 9846
C API Stability 特記のない限り、Python の C API には後方互換性ポリシー PEP 387 が適用されます。 変更の大半はソース互換性を保ちます (通常は新しい API の追加だけを行います)。 既存 API の変更や削除は、非推奨の期間を経た後、または重大な問題を修 ... compiled once and be loaded on multiple versions of Python. Contents of the Limited API are listed below . Py_LIMITED_API Define this macro before including Python.h to opt in to only use the Limited API, and to select the Limited API version. Define ... mum minor version (e.g. 0x030A0000 for Python 3.10) for stability when compiling with future Python versions. You can also define Py_LIMITED_API to 3 . This works the same as 0x03020000 (Python 3.2, the version that introduced Limited API). Stable ABI ... ro can be faster because it can rely on version-specific implementation details of the list object. Without Py_LIMITED_API defined, some C API functions are inlined or replaced by macros. Defining Py_LIMITED_API disables this inlining, allowing stabili ...
https://man.mtool.work/python/3.14/c-api/stable.html
1. 他のアプリケーションへの Python の埋め込み 9348
1. 他のアプリケーションへの Python の埋め込み 前章では、 Python を拡張する方法、すなわち C 関数のライブラリを Python に結びつけて機能を拡張する方法について述べました。同じようなことを別の方法でも実行できます: それは、自分の C/C++ アプリケー ... がない Python スクリプトを実行するためのものです。例えばこれは、一つのファイル上で何らかの操作を実現するのに利用できます。 #define PY_SSIZE_T_CLEAN #include <Python.h> int main ( int argc , char * argv []) { PyStatus status ; PyConfig config ; PyConfig_ ... () < 0 ) { exit ( 120 ); } return 0 ; exception : PyConfig_Clear ( & config ); Py_ExitStatusException ( status ); } 注釈 #define PY_SSIZE_T_CLEAN は、いくつかの API では int の代わりに Py_ssize_t が使われるべきであることを示すために使われていました。こ ... 次の節でやりとりするよう変更します)。 Python スクリプト内で定義されている関数を実行するためのコードは以下のようになります: #define PY_SSIZE_T_CLEAN #include <Python.h> int main ( int argc , char * argv []) { PyObject * pName , * pModule , * pFunc ; PyOb ...
https://man.mtool.work/python/3.14/extending/embedding.html
2. 拡張の型の定義: チュートリアル 9348
2. 拡張の型の定義: チュートリアル Python では、組み込みの str 型や list 型のような Python コードから操作できる新しい型を C 拡張モジュールの作者が定義できます。 全ての拡張の型のコードはあるパターンに従うのですが、書き始める前に理解しておくべ ... ype_FromSpec() 関数を使い、ヒープ上に配置された拡張の型も定義できますが、これについてはこのチュートリアルでは扱いません。 #define PY_SSIZE_T_CLEAN #include <Python.h> typedef struct { PyObject_HEAD /* 型固有のフィールドをここに記述します。 */ } CustomO ... に、この型を基底クラスとしても利用できるようにします。ここでは新しいモジュール custom2 をつくり、これらの機能を追加します: #define PY_SSIZE_T_CLEAN #include <Python.h> #include <stddef.h> /* offsetof() 用 */ typedef struct { PyObject_HEAD PyObject * fir ... last に文字列以外の値を設定でき、削除することさえできました。 これらの属性が常に文字列を格納するようにしたいと思います。 #define PY_SSIZE_T_CLEAN #include <Python.h> #include <stddef.h> /* offsetof() 用 */ typedef struct { PyObject_HEAD PyObject * fir ...
https://man.mtool.work/python/3.14/extending/newtypes_tutorial.html
What's New In Python 3.11 8850
What's New In Python 3.11 編集者 : Pablo Galindo Salgado この記事では Python 3.10 と比較した Python 3.11 の新機能を解説します。Python 3.11 は2022年10月24日にリリースされました。全詳細については 変更履歴 をご覧ください。 概要 -- リリースハイ ... 義してコード全体で使うことができます (これらは mypy のコードベースから転載したものです)。 #if PY_VERSION_HEX >= 0x03080000 # define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc) # define CPy_TRASHCAN_END(op) Py_TRASHCAN_END #else # defin ... e CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op) # define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op) #endif Py_TPFLAGS_HAVE_GC フラグを設定しているのに巡回関数 ( PyTypeObject.tp ... TYPE() 関数を参照してください。 後方互換性のために、以下のマクロを使うことができます。 #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE) static inline void _Py_SET_TYPE ( PyObject * ob , PyTypeObject * type ) { ob -> ob_type = type ; } #define P ...
https://man.mtool.work/python/3.14/whatsnew/3.11.html
API と ABI のバージョニング 8601
API と ABI のバージョニング ビルド時のバージョン定数 CPython は以下のマクロでバージョン番号を公開しています。 これらはコードの ビルド時 のバージョンに対応します。 実行時 のバージョンについては Py_Version を参照してください。 バージョン間の ... ) 0x030a00f0 引数の範囲外のビットは無視します。 つまり、このマクロは次のように定義できます。 #ifndef Py_PACK_FULL_VERSION #define Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) ( \ (((X) & 0xff) << 24) | \ (((Y) & 0xff) << 16) | \ (((Z) & 0xff) << 8) | \ ...
https://man.mtool.work/python/3.14/c-api/apiabiversion.html
PyHash API 8352
PyHash API PyTypeObject.tp_hash メンバや 数値型のハッシュ化 も参照してください。 type Py_hash_t ハッシュ値型: 符号付き整数。 Added in version 3.2. type Py_uhash_t ハッシュ値型: 符号なし整数。 Added in version 3.2. Py_HASH_ALGORITHM str 、 b ... ef PyHash_Func When Python is built with Py_HASH_ALGORITHM set to Py_HASH_EXTERNAL , the application embedding Python must define this variable to supply a hash implementation instead of using one of Python's built-in hash algorithms. Added in version ...
https://man.mtool.work/python/3.14/c-api/hash.html
はじめに 8352
はじめに Python のアプリケーションプログラマー向けインターフェース (API) は、C と C++ のプログラマーに、Python インタープリタへのさまざまなレベルのアクセスを提供します。 C++ からも同様に使えますが、簡潔に Python/C API と呼びます。 Python/C ... 。 インクルードファイル Python/C API を使うために必要な、関数、型およびマクロの全ての定義をインクルードするには、以下の行: #define PY_SSIZE_T_CLEAN #include <Python.h> をソースコードに記述します。この行を記述すると、標準ヘッダ: <stdio.h> , <string.h> , ... をアサートする式で、評価結果は 0 です。 条件が偽の場合や、コンパイル時に評価できない場合は、ビルドに失敗します。 例えば: #define foo_to_char(foo) \ ((char *)(foo) + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0)) Added in version 3.3. 型のサイ ... Py_ssize_t 次に属します: Stable ABI . A signed integral type such that sizeof(Py_ssize_t) == sizeof(size_t) . C99 doesn't define such a thing directly (size_t is an unsigned integral type). See PEP 353 for details. Py_INVALID_SIZE A constant of type P ...
https://man.mtool.work/python/3.14/c-api/intro.html
Python インタプリタの拡張と埋め込み 8352
Python インタプリタの拡張と埋め込み This document describes how to write modules in C or C++ to extend the Python interpreter with new modules. Those modules can not only define new functions but also new object types and their methods. The ...
https://man.mtool.work/python/3.14/extending/
PREV 1 2 3 NEXT