per page, with , order by , clip by
Results of 1 - 10 of about 95 for while (0.010 sec.)
itertools --- 効率的なループ用のイテレータ生成関数群 13797
itertools --- 効率的なループ用のイテレータ生成関数群 このモジュールは イテレータ を構築する部品を実装しています。プログラム言語 APL, Haskell, SML からアイデアを得ていますが、 Python に適した形に修正されています。 このモジュールは、高速でメモ ... *step, ... count(10) → 10 11 12 13 14 ... cycle() p p0, p1, ... plast, p0, p1, ... cycle('ABCD') → A B C D A B C D ... dropwhile() predicate, seq predicate が偽を返した位置からの seq[n], seq[n+1] dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8 filterfal ... , 3) → 10 10 10 starmap() func, seq func(*seq[0]), func(*seq[1]), ... starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000 takewhile() predicate, seq predicate が偽を返すまでの seq[0], seq[1] takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4 tee() it, n it1, it ... # batched('ABCDEFG', 3) → ABC DEF G if n < 1 : raise ValueError ( 'n must be at least one' ) iterator = iter ( iterable ) while batch := tuple ( islice ( iterator , n )): if strict and len ( batch ) != n : raise ValueError ( 'batched(): incomplete ba ...
https://man.mtool.work/python/3.14/library/itertools.html
4. その他の制御フローツール 11414
4. その他の制御フローツール 前章で紹介した while 文の他にも、 Python にはいくつか制御フローツールがあり、本章で説明します。 4.1. if 文 おそらく最もおなじみの文型は if 文でしょう。例えば: >>> x = int ( input ( "Please enter an integer: " )) ... の章では list() について詳しく説明します。 4.4. break 文と continue 文 break 文は、その文を囲む最も内側の for ループまたは while ループを抜けます。 >>> for n in range ( 2 , 10 ): ... for x in range ( 2 , n ): ... if n % x == 0 : ... print ( f " { n } ... 奇数 5 を見つけた 偶数 6 を見つけた 奇数 7 を見つけた 偶数 8 を見つけた 奇数 9 を見つけた 4.5. ループの else 節 for または while ループ中の break 文は else 節と対になる場合があります。 break を実行せずにループが終了すると、 else 節が実行されます。 for ... 文の場合、 else 節はループ処理の最後のイテレーションが実行されたあと、つまりbreakが発生しなかった場合に実行されます。 while 文の場合は、ループ条件が偽となったあとに実行されます。 どちらのループでも、ループが break によって終了した場合は else 句は ...
https://man.mtool.work/python/3.14/tutorial/controlflow.html
Logging クックブック 9637
Logging クックブック Author : Vinay Sajip <vinay_sajip at red-dove dot com> このページは、過去に有用であるとされていた、logging に関連するいくつものレシピを含んでいます。チュートリアルやリファレンス情報へのリンクについては その他のリソース ... (初期) スレッドとそれ以外のスレッドからのロギングの例です: import logging import threading import time def worker ( arg ): while not arg [ 'stop' ]: logging . debug ( 'Hi from myfunc' ) time . sleep ( 0.5 ) def main (): logging . basicConfig ( level = ... essage)s ' ) info = { 'stop' : False } thread = threading . Thread ( target = worker , args = ( info ,)) thread . start () while True : try : logging . debug ( 'Hello from main' ) time . sleep ( 0.75 ) except KeyboardInterrupt : info [ 'stop' ] = True ... g . getLogger ( 'simpleExample' ) try : # Ctrl+C が押されるまでログの呼び出しを繰り返し、 # 新しい設定による違いを確認する while True : logger . debug ( 'debug message' ) logger . info ( 'info message' ) logger . warning ( 'warn message' ) logger . er ...
https://man.mtool.work/python/3.14/howto/logging-cookbook.html
8. 複合文 (compound statement) 9031
8. 複合文 (compound statement) 複合文には、他の文 (のグループ) が入ります; 複合文は、中に入っている他の文の実行の制御に何らかのやり方で影響を及ぼします。一般的には、複合文は複数行にまたがって書かれますが、全部の文を一行に連ねた単純な書き方も ... あります。 if 、 while 、および for 文は、伝統的な制御フロー構成を実現します。 try は例外処理および/または一連の文に対するクリーンアップコードを指 ... ちらかです: if x < y < z : print ( x ); print ( y ); print ( z ) まとめると、以下のようになります: compound_stmt : if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | match_stmt | funcdef | classdef | async_with_stmt | async_for_stmt | async_funcde ... if 文の他の部分は、実行や評価をされません)。全ての式が偽になった場合、 else 節があれば、そのスイートが実行されます。 8.2. while 文 while 文は、式の値が真である間、実行を繰り返すために使われます: while_stmt : "while" assignment_expression ":" suite [ ...
https://man.mtool.work/python/3.14/reference/compound_stmts.html
10. 完全な文法仕様 9031
10. 完全な文法仕様 以下は Python の完全な文法で、CPython のパーサを生成するための文法から直接得たものです ( Grammar/python.gram を参照)。 ここでは、コード生成とエラー回復に関する詳細を省略しています。 ここで使う記法は、これまでのドキュメント ... tmt | global_stmt | nonlocal_stmt compound_stmt : | function_def | if_stmt | class_def | with_stmt | for_stmt | try_stmt | while_stmt | match_stmt # SIMPLE STATEMENTS # ================= # NOTE: annotated_rhs may start with 'yield'; yield_expr must st ... named_expression ':' block elif_stmt | 'elif' named_expression ':' block [ else_block ] else_block : | 'else' ':' block # While statement # --------------- while_stmt : | 'while' named_expression ':' block [ else_block ] # For statement # ----------- ...
https://man.mtool.work/python/3.14/reference/grammar.html
Dictionary Objects 8439
Dictionary Objects type PyDictObject この PyObject のサブタイプは Python の辞書オブジェクトを表現します。 PyTypeObject PyDict_Type 次に属します: Stable ABI . この PyTypeObject のインスタンスは Python の辞書を表現します。このオブジェクトは、 ... ットを表しており、この構造は疎であるため、オフセットは連続しません。 例えば: PyObject * key , * value ; Py_ssize_t pos = 0 ; while ( PyDict_Next ( self -> dict , & pos , & key , & value )) { /* 値を使って何らかの処理を行う... */ ... } 反復処理中に辞書 p ... 夫になりましたが、キーの集合を変更しないことが前提です。以下に例を示します: PyObject * key , * value ; Py_ssize_t pos = 0 ; while ( PyDict_Next ( self -> dict , & pos , & key , & value )) { long i = PyLong_AsLong ( value ); if ( i == -1 && PyErr_Occurr ... in the free-threaded build without external synchronization. You can use Py_BEGIN_CRITICAL_SECTION to lock the dictionary while iterating over it: Py_BEGIN_CRITICAL_SECTION ( self -> dict ); while ( PyDict_Next ( self -> dict , & pos , & key , & valu ...
https://man.mtool.work/python/3.14/c-api/dict.html
ソケットプログラミング HOWTO 8439
ソケットプログラミング HOWTO Author : Gordon McMillan 概要 ソケットはそこかしこで使われているが、最大級に誤解されている技術でもある。この文書はソケットの全体像を俯瞰しており、チュートリアルとしてはあまり役に立たない。実際に動くモノを完成させ ... よし、「サーバーソケット」ができて、80 番ポートで耳を澄ましているところまで来た。では、ウェブサーバのメインループに入ろう: while True : # 外部からの接続を受け付ける ( clientsocket , address ) = serversocket . accept () # clientsocket を使って処理する ... sock def connect ( self , host , port ): self . sock . connect (( host , port )) def mysend ( self , msg ): totalsent = 0 while totalsent < MSGLEN : sent = self . sock . send ( msg [ totalsent :]) if sent == 0 : raise RuntimeError ( "socket connectio ... n broken" ) totalsent = totalsent + sent def myreceive ( self ): chunks = [] bytes_recd = 0 while bytes_recd < MSGLEN : chunk = self . sock . recv ( min ( MSGLEN - bytes_recd , 2048 )) if chunk == b '' : raise RuntimeErr ...
https://man.mtool.work/python/3.14/howto/sockets.html
asyncio とフリースレッド Python 8439
asyncio とフリースレッド Python asyncio uses an event loop as a scheduler to enable highly efficient concurrency by switching between tasks to allow non-blocking I/O operations. This results in better performance for I/O-bound use cases. It ... ): print ( f "Producing { i } " ) q . put ( i ) q . shutdown () async def consumer ( q : queue . Queue [ int ]) -> None : while True : try : item = q . get_nowait () except queue . Empty : await asyncio . sleep ( 0.1 ) continue except queue . ShutDow ... consumer ( q )) ) consumer_thread . start () producer ( q ) consumer_thread . join () The producer runs on the main thread while the consumer runs inside an event loop on its own thread, yet they communicate safely through queue.Queue . When the queue ...
https://man.mtool.work/python/3.14/library/asyncio-threading.html
変更履歴 8439
変更履歴 次の Python バージョン リリース日: XXXX-XX-XX セキュリティ gh-160499 : Fix unbounded memory growth in asyncio TLS connections when a peer stops reading but keeps sending records that make OpenSSL generate its own replies (such as T ... crashes in the CJK incremental and stream codecs when their errors attribute or their class's codec attribute is replaced while they are in use. gh-160310 : Fix quadratic time complexity of gzip.decompress() , bz2.decompress() , lzma.decompress() and ... defense: removing trust is primarily the job of the platform root store, and the built-in denylist only blocks connections while that update has not yet reached the OS, a container image, or a bundled trust store in various Python packages. Entries ar ... h when a compression.zstd.ZstdCompressor that uses worker threads and a ZstdDict is deallocated, or the interpreter exits, while data passed to compress() is still being compressed. gh-160535 : Fix a crash in compression.zstd when the garbage collecto ...
https://man.mtool.work/python/3.14/whatsnew/changelog.html
タイマーファイル記述子 HOWTO 8149
タイマーファイル記述子 HOWTO リリース : 1.13 この HOWTO では、Linux のタイマーファイル記述子を Python で使う方法を説明します。 使用例 次の例は、タイマーファイル記述子を使って 1 秒に 2 回関数を実行する方法を示します。 # 実用的なスクリプトでは ... _nsec os . timerfd_settime_ns ( fd , initial = i // 4 , interval = i // 4 ) timeout = 3 try : conn = None is_active = True while is_active : # タイマーの満了を最大 3 秒待つ。 # epoll.poll() は (fd, event) のペアのリストを返す。 # fd はファイル記述子。 ... art = 1 ): os . timerfd_settime ( fd , initial = i / 4 , interval = i / 4 ) timeout = 3 try : conn = None is_active = True while is_active : # Wait for the timer to expire for 3 seconds. # select.select() returns a list of file descriptors or objects. ...
https://man.mtool.work/python/3.14/howto/timerfd.html
PREV 1 2 3 4 5 6 7 8 9 10 NEXT