Results of 1 - 10 of about 65 for spam (0.007 sec.)
- 1. Extending Python with C or C++ 12539
- 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
...s of Python than writing and compiling a C extension module. 1.1. A Simple Example Let's create an extension module called spam (the favorite food of Monty Python fans...) and let's say we want to create a Python interface to the C library function s...aracter string as argument and returns an integer. We want this function to be callable from Python as follows: >>> import spam >>> status = spam . system ( "ls -l" ) Begin by creating a file spammodule.c . (Historically, if a module is called spam ,...the C file containing its implementation is called spammodule.c ; if the module name is very long, like spammify , the module name can be just spammify.c .) The first two lines o... - https://man.mtool.work/python/3.14/extending/extending.html
- 5. Windows 上での C および C++ 拡張モジュールのビルド 12095
- 5. Windows 上での C および C++ 拡張モジュールのビルド この章では Windows 向けの Python 拡張モジュールを Microsoft Visual C++ を使って作成する方法について簡単に述べ、その後に拡張モジュールのビルドがどのように動作するのかについて詳しい背景を述
...のコードにアクセスするするために実行時に用いられる情報が入っているだけです。 Windows ではインポートライブラリの使用は import spam とするようなものです; この操作によって spam の名前にアクセスできますが、コードのコピーを個別に作成したりはしません。Unix で...は、ライブラリとのリンクはむしろ from spam import * に似ています; この操作では個別にコードのコピーを生成します。 Py_NO_LINK_LIB CPython のヘッダーファイル内で行われる...は、Debug では pythonXY_d.lib 、Release では pythonXY.lib 、 Limited API を有効にした Release では pythonX.lib を選びます。 spam と、spam 内の C 関数を使う ni という 2 つの DLL をビルドするには、次のコマンドを使えます。 cl / LD / I / python / include... - https://man.mtool.work/python/3.14/extending/windows.html
- 組み込み型 11980
- 組み込み型 以下のセクションでは、インタプリタに組み込まれている標準型について記述します。 主要な組み込み型は、数値、シーケンス、マッピング、クラス、インスタンス、および例外です。 コレクションクラスには、ミュータブルなものがあります。コレクシ
...ラルに含まれます。 単式の一部であり間に空白のみを含む文字列リテラルは、一つの文字列リテラルに暗黙に変換されます。つまり、 ("spam " "eggs") == "spam eggs" です。 サポートされている エスケープシーケンス や、ほとんどのエスケープシーケンスの処理を無効化す...mpty, returns the number of empty strings between characters which is the length of the string plus one. For example: >>> 'spam, spam, spam' . count ( 'spam' ) 3 >>> 'spam, spam, spam' . count ( 'spam' , 5 ) 2 >>> 'spam, spam, spam' . count ( 'spam'..., 5 , 10 ) 1 >>> 'spam, spam, spam' . count ( 'eggs' ) 0 >>> 'spam, spam, spam' . count ( '' ) 17 str. encode ( encoding = 'utf-8' , errors = 'st... - https://man.mtool.work/python/3.14/builtins/stdtypes.html
- csv --- CSV File Reading and Writing 11723
- csv --- CSV File Reading and Writing ソースコード: Lib/csv.py CSV (Comma Separated Values、カンマ区切り値列) と呼ばれる形式は、 スプレッドシートやデータベース間でのデータのインポートやエクスポートにおける最も一般的な形式です。 CSVフォーマッ
...ルドは浮動小数点数に変換されます)。 短い利用例: >>> import csv >>> with open ( 'eggs.csv' , newline = '' ) as csvfile : ... spamreader = csv . reader ( csvfile , delimiter = ' ' , quotechar = '|' ) ... for row in spamreader : ... print ( ', ' . join (...row )) Spam, Spam, Spam, Spam, Spam, Baked Beans Spam, Lovely Spam, Wonderful Spam ここで、 eggs.csv の内容は次のとおりです: Spam Spam...Spam Spam Spam |Baked Beans| Spam |Lovely Spam| |Wonderful Spam| csv. writer ( csvfile , / , dialect = 'excel' , ** fmtparams )... - https://man.mtool.work/python/3.14/library/csv.html
- 9. クラス 9590
- 9. クラス クラスはデータと機能を組み合わせる方法を提供します。 新規にクラスを作成することで、新しいオブジェクトの 型 を作成し、その型を持つ新しい インスタンス が作れます。 クラスのそれぞれのインスタンスは自身の状態を保持する属性を持てます。
...る名前空間が直接アクセスできるような、 Python プログラムのテキスト上の領域です。 "直接アクセス可能" とは、修飾なしに (訳注: spam.egg ではなく単に egg のように) 名前を参照した際に、その名前空間から名前を見つけようと試みることを意味します。 スコープは静...されるか、また global および nonlocal が変数の束縛にどう影響するか、この例で実演します: def scope_test (): def do_local (): spam = "local spam" def do_nonlocal (): nonlocal spam spam = "nonlocal spam" def do_global (): global spam spam = "global spam"...spam = "test spam" do_local () print ( "After local assignment:" , spam ) do_nonlocal () print ( "After nonlocal assignment:" ,... - https://man.mtool.work/python/3.14/tutorial/classes.html
- reprlib --- もう一つの repr() の実装 8717
- reprlib --- もう一つの repr() の実装 ソースコード: Lib/reprlib.py reprlib モジュールは、結果の文字列のサイズに対する制限付きでオブジェクト表現を生成するための手段を提供します。これは Python デバッガの中で使用されており、他の文脈でも同様に役
...合、標準の repr() と同様に、改行やインデントなしで出力を書式化します。 例えば、次のようになります: >>> example = [ ... 1 , 'spam' , { 'a' : 2 , 'b' : 'spam eggs' , 'c' : { 3 : 4.5 , 6 : []}}, 'ham' ] >>> import reprlib >>> aRepr = reprlib . Repr () >>...> print ( aRepr . repr ( example )) [1, 'spam', {'a': 2, 'b': 'spam eggs', 'c': {3: 4.5, 6: []}}, 'ham'] indent に文字列を設定すると、再帰の各レベルを別の行に配置し、そ...の文字列でインデントします: >>> aRepr . indent = '-->' >>> print ( aRepr . repr ( example )) [ -->1, -->'spam', -->{ -->-->'a': 2, -->-->'b': 'spam eggs', -->-->'c': { -->-->-->3: 4.5, -->-->-->6: [], -->-->}, -->}, -->'ham', ] inde... - https://man.mtool.work/python/3.14/library/reprlib.html
- pprint --- データの整形表示 8473
- pprint --- データの整形表示 ソースコード: Lib/pprint.py pprint モジュールは、任意の Python データ構造を、インタープリタへの入力に使える形式で「整形表示」する機能を提供します。 整形するデータ構造に Python の基本的な型以外のオブジェクトが含ま
...3桁区切りされて表示されます。そうでなければアンダースコアは表示されません(デフォルト)。 >>> import pprint >>> stuff = [ 'spam' , 'eggs' , 'lumberjack' , 'knights' , 'ni' ] >>> stuff . insert ( 0 , stuff ) >>> pprint . pp ( stuff ) [<Recursion on li...st with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni'] Added in version 3.8. バージョン 3.10 で変更: underscore_numbers 引数が追加されま...id=number> と表されます。 それ以外の整形は行いません。 >>> pprint . saferepr ( stuff ) "[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']" PrettyPrinter オブジェクト class pprint. PrettyPrinter ( indent = 1 , width = 80... - https://man.mtool.work/python/3.14/library/pprint.html
- unittest.mock --- 入門 8030
- unittest.mock --- 入門 Added in version 3.3. Mock を使う モックでメソッドにパッチを当てる 一般的な Mock の使い方の中には次のものがあります: メソッドにパッチを当てる オブジェクトに対するメソッド呼び出しを記録する システムの他の部分からメソッ
...d = BackendProvider () ... def method ( self ): ... response = self . backend . get_endpoint ( 'foobar' ) . create_call ( 'spam' , 'eggs' ) . start_call () ... # more code BackendProvider はすでに十分テストされているとします。 method() をどうテストし...用することで、この呼び出しのリストを作成することができます: >>> chained = call . get_endpoint ( 'foobar' ) . create_call ( 'spam' , 'eggs' ) . start_call () >>> call_list = chained . call_list () >>> assert mock_backend . mock_calls == call_list 部分的...するための素晴らしいAPIがあります。 >>> mock = Mock () >>> mock . foo_bar . return_value = None >>> mock . foo_bar ( 'baz' , spam = 'eggs' ) >>> mock . foo_bar . assert_called_with ( 'baz' , spam = 'eggs' ) モックが一度だけ呼び出されるなら、 assert_cal... - https://man.mtool.work/python/3.14/library/unittest.mock-examples.html
- 5. インポートシステム 8030
- 5. インポートシステム ある 1 つの module にある Python コードから他のモジュールを インポート することで、そこにあるコードへアクセスできるようになります。 import 文はインポート機構を動かす最も一般的な方法ですが、それが唯一の方法ではありません
...が使われた場合でも、バインディングはサブモジュールオブジェクトを親モジュールの名前空間に配置します。例えば、もしパッケージ spam がサブモジュール foo を持っていた場合、 spam.foo をインポートした後は spam は値がサブモジュールに束縛された属性 foo を持ち...ます。以下のディレクトリ構造を持っているとしましょう: spam / __init__ . py foo . py そして spam/__init__.py は以下のようになっているとします: from .foo import Foo このとき、以下を実...行することにより spam モジュールの中に foo と Foo に束縛された名前が置かれます: >>> import spam >>> spam . foo <module 'spam.foo' from '/tmp/imp... - https://man.mtool.work/python/3.14/reference/import.html
- contextvars --- コンテキスト変数 7901
- contextvars --- コンテキスト変数 このモジュールは、コンテキストローカルな状態を管理し、保持し、アクセスするための API を提供します。 ContextVar クラスは コンテキスト変数 を宣言し、取り扱うために使われます。 非同期フレームワークで現時点のコン
...すか、例外が発生した場合はそれを伝播させます。 例: import contextvars var = contextvars . ContextVar ( 'var' ) var . set ( 'spam' ) print ( var . get ()) # 'spam' ctx = contextvars . copy_context () def main (): # 'copy_context()' と 'ctx.run(main)' を...呼ぶ前に # 'var' を 'spam' に設定したため、次のようになります: print ( var . get ()) # 'spam' print ( ctx [ var ]) # 'spam' var . set ( 'ham' ) # 'v...行されたので、 # 'var' の変更はその中にとどまります: print ( ctx [ var ]) # 'ham' # 一方、'ctx' の外では 'var' は依然として 'spam' に設定されています: print ( var . get ()) # 'spam' copy ( ) コンテキストオブジェクトの浅いコピーを返します。 var in conte... - https://man.mtool.work/python/3.14/library/contextvars.html