pytho****@googl*****
pytho****@googl*****
2011年 3月 26日 (土) 09:21:04 JST
6 new revisions: Revision: eea3f016fd57 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:01:46 2011 Log: library/collections.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=eea3f016fd57 Revision: 2b34061f268f Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:24 2011 Log: library/fileinput.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=2b34061f268f Revision: ed61e029ec68 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:40 2011 Log: library/gettext.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=ed61e029ec68 Revision: 637dcacb6874 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:55 2011 Log: library/operator.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=637dcacb6874 Revision: 177d855567ea Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:33:30 2011 Log: latex_font_size の代わりに latex_elements の 'pointsize' を使うよ うに http://code.google.com/p/python-doc-ja/source/detail?r=177d855567ea Revision: dbda281f3046 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 17:20:33 2011 Log: LaTeX 出力の章の表示を改善 wiki LaTeXBuild クラスファイル周りの設 定参照... http://code.google.com/p/python-doc-ja/source/detail?r=dbda281f3046 ============================================================================== Revision: eea3f016fd57 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:01:46 2011 Log: library/collections.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=eea3f016fd57 Modified: /library/collections.rst ======================================= --- /library/collections.rst Sat Nov 27 10:59:46 2010 +++ /library/collections.rst Fri Mar 25 16:01:46 2011 @@ -52,7 +52,7 @@ :class:`Container` ``__contains__`` :class:`Hashable` ``__hash__`` :class:`Iterable` ``__iter__`` -:class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__`` +:class:`Iterator` :class:`Iterable` ``next`` ``__iter__`` :class:`Sized` ``__len__`` :class:`Callable` ``__call__`` @@ -151,12 +151,9 @@ * ABCs についての詳細は、 :mod:`abc` モジュールと :pep:`3119` を参照して ください。 -.. _deque-objects: - :class:`deque` オブジェクト --------------------------- - .. class:: deque([iterable[, maxlen]]) *iterable* で与えられるデータから、新しい deque オブジェクトを (:meth:`append` をつかって) @@ -298,13 +295,32 @@ deque(['c', 'b', 'a']) -.. _deque-recipes: - :class:`deque` のレシピ ------------------------ この節では deque をつかったさまざまなアプローチを紹介します。 +長さが制限された deque は Unix における ``tail`` フィルタに相当する機能を +提供します:: + + def tail(filename, n=10): + 'ファイルの最後の n 行を返す.' + return deque(open(filename), n) + +別のアプローチとして deque を右に append して左に pop して使うことで追加し た要素を維持するのに使えます:: + + def moving_average(iterable, n=3): + # moving_average([40, 30, 50, 46, 39, 44]) --> 40.0 42.0 45.0 43.0 + # http://en.wikipedia.org/wiki/Moving_average + it = iter(iterable) + d = deque(itertools.islice(it, n-1)) + d.appendleft(0) + s = sum(d) + for elem in it: + s += elem - d.popleft() + d.append(elem) + yield s / float(n) + :meth:`rotate` メソッドのおかげで、 :class:`deque` の一部を切り出したり削除 したりできることになります。たとえば ``del d[n]`` の純粋な Python 実装では pop したい要素まで :meth:`rotate` します :: @@ -319,35 +335,10 @@ このアプローチをやや変えたものとして、Forth スタイルのスタック操作、つまり ``dup``, ``drop``, ``swap``, ``over``, ``pick``, ``rot``, および ``roll`` を実装するのも簡単です。 -複数パスのデータ・リダクションアルゴリズムは、 :meth:`popleft` を複数回呼ん で要素をとりだし、リダクション用の関数を適用してから -:meth:`append` で deque に戻してやることにより、簡潔かつ効率的に表現するこ とができます。 - -たとえば入れ子状になったリストでバランスされた二進木をつくりたい場合、 -2つの隣接するノードをひとつのリストにグループ化することになります: - - >>> def maketree(iterable): - ... d = deque(iterable) - ... while len(d) > 1: - ... pair = [d.popleft(), d.popleft()] - ... d.append(pair) - ... return list(d) - ... - >>> print maketree('abcdefgh') - [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]] - -長さが制限された deque は Unix における ``tail`` フィルタに相当する機能を -提供します:: - - def tail(filename, n=10): - 'ファイルの最後の n 行を返す.' - return deque(open(filename), n) - -.. _defaultdict-objects: :class:`defaultdict` オブジェクト --------------------------------- - .. class:: defaultdict([default_factory[, ...]]) 新しいディクショナリ状のオブジェクトを返します。 :class:`defaultdict` は 組込みの @@ -387,8 +378,6 @@ ``None`` になります。 -.. _defaultdict-examples: - :class:`defaultdict` の使用例 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -450,8 +439,6 @@ >>> d.items() [('blue', set([2, 4])), ('red', set([1, 3]))] -.. _named-tuple-factory: - :func:`namedtuple` 名前付きフィールドを持ったタプルのファクトリ関数 -------------------------------------------------------------------- @@ -489,7 +476,19 @@ .. doctest:: :options: +NORMALIZE_WHITESPACE - >>> Point = namedtuple('Point', 'x y', verbose=True) + >>> Point = namedtuple('Point', 'x y') + >>> p = Point(11, y=22) # 順序による引数やキーワード引数を使ってイン スタンス化 + >>> p[0] + p[1] # 通常の tuple (11, 22) と同じようにインデッ クスアクセス + 33 + >>> x, y = p # 通常の tuple と同じようにアンパック + >>> x, y + (11, 22) + >>> p.x + p.y # 名前でフィールドにアクセス + 33 + >>> p # name=value スタイルの読みやすい __repr__ + Point(x=11, y=22) + + >>> Point = namedtuple('Point', 'x y', verbose=True) # クラス定義を表示 class Point(tuple): 'Point(x, y)' <BLANKLINE> @@ -497,8 +496,8 @@ <BLANKLINE> _fields = ('x', 'y') <BLANKLINE> - def __new__(cls, x, y): - return tuple.__new__(cls, (x, y)) + def __new__(_cls, x, y): + return _tuple.__new__(cls, (x, y)) <BLANKLINE> @classmethod def _make(cls, iterable, new=tuple.__new__, len=len): @@ -515,9 +514,9 @@ 'Return a new dict which maps field names to their values' return {'x': t[0], 'y': t[1]} <BLANKLINE> - def _replace(self, **kwds): + def _replace(_self, **kwds): 'Return a new Point object replacing specified fields with new values' - result = self._make(map(kwds.pop, ('x', 'y'), self)) + result = _self._make(map(kwds.pop, ('x', 'y'), _self)) if kwds: raise ValueError('Got unexpected field names: %r' % kwds.keys()) return result @@ -528,16 +527,6 @@ x = property(itemgetter(0)) y = property(itemgetter(1)) - >>> p = Point(11, y=22) # 順序による引数やキーワード引数を使ってイン スタンス化 - >>> p[0] + p[1] # 通常の tuple (11, 22) と同じようにインデッ クスアクセス - 33 - >>> x, y = p # 通常の tuple と同じようにアンパック - >>> x, y - (11, 22) - >>> p.x + p.y # 名前でフィールドにアクセス - 33 - >>> p # name=value スタイルの読みやすい __repr__ - Point(x=11, y=22) 名前付きタプルは :mod:`csv` や :mod:`sqlite3` モジュールが返すタプルのフ ィールドに名前を 付けるときにとても便利です:: @@ -559,11 +548,11 @@ 一つの属性をサポートしています。フィールド名との衝突を避けるために メソッド名と属性名はアンダースコアで始まります。 -.. method:: somenamedtuple._make(iterable) +.. classmethod:: somenamedtuple._make(iterable) 既存の sequence や Iterable から新しいインスタンスを作るクラスメソッド. -.. doctest:: + .. doctest:: >>> t = [11, 22] >>> Point._make(t) @@ -578,9 +567,7 @@ .. method:: somenamedtuple._replace(kwargs) - 指定されたフィールドを新しい値で置き換えた、新しい名前付きタプルを作って 返します: - -:: + 指定されたフィールドを新しい値で置き換えた、新しい名前付きタプルを作って 返します:: >>> p = Point(x=11, y=22) >>> p._replace(x=33) @@ -594,7 +581,7 @@ フィールド名をリストにしたタプル. 内省 (introspection) したり、既存の名 前付きタプルを もとに新しい名前つきタプルを作成する時に便利です。 -.. doctest:: + .. doctest:: >>> p._fields # view the field names ('x', 'y') @@ -634,7 +621,7 @@ Point: x=14.000 y= 0.714 hypot=14.018 このサブクラスは ``__slots__`` に空のタプルをセットしています。 -これにより、インスタンス辞書の作成を抑制して低いメモリ使用量をキープしてい ます。 +これにより、インスタンス辞書の作成を抑制してメモリ使用量を低く保つのに役立 ちます。 サブクラス化は新しいフィールドを追加するのには適していません。 代わりに、新しい名前付きタプルを :attr:`_fields` 属性を元に作成してくださ い: ============================================================================== Revision: 2b34061f268f Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:24 2011 Log: library/fileinput.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=2b34061f268f Modified: /library/fileinput.rst ======================================= --- /library/fileinput.rst Thu May 6 19:18:04 2010 +++ /library/fileinput.rst Fri Mar 25 16:02:24 2011 @@ -23,9 +23,9 @@ このプログラムは ``sys.argv[1:]`` に含まれる全てのファイルをまたいで繰り返 します。 もし該当するものがなければ、 ``sys.stdin`` がデフォルトとして扱われます。 ファイル名として ``'-'`` が与えられた場合も、 ``sys.stdin`` に置き換えられ ます。別のファイル名リストを使いたい時には、 -:func:`input` の最初の引数にリストを与えます。単一ファイル名の文字列も受け 付けます。 - -全てのファイルはデフォルトでテキストモードでオープンされます。しか し、 :func:`input` や :class:`FileInput()` +:func:`.input` の最初の引数にリストを与えます。単一ファイル名の文字列も受け 付けます。 + +全てのファイルはデフォルトでテキストモードでオープンされます。しか し、 :func:`.input` や :class:`FileInput()` をコールする際に *mode* パラメータを指定すれば、これをオーバーライドするこ とができます。オープン中あるいは読み込み中にI/Oエラーが発生した場合には、 :exc:`IOError` が発生します。 @@ -133,7 +133,7 @@ デフォルトでは、拡張子は ``'.bak'`` になっていて、出力先のファイルが閉じら れればバックアップファイルも消されます。 インプレースフィルタ機能は、標準入力を読み込んでいる間は無効にされます。 -.. warning:: +.. note:: 現在の実装はMS-DOSの8+3ファイルシステムでは動作しません。 このモジュールには、次のふたつのオープン時フックが用意されています。 ============================================================================== Revision: ed61e029ec68 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:40 2011 Log: library/gettext.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=ed61e029ec68 Modified: /library/gettext.rst ======================================= --- /library/gettext.rst Sat May 15 22:07:24 2010 +++ /library/gettext.rst Fri Mar 25 16:02:40 2011 @@ -181,9 +181,9 @@ :func:`translation` に *domain* 、 *localedir* 、および *codeset* を渡し てできる関数 :func:`_` を Python の組み込み名前空間に組み込みます。 *unicode* フラグ は :func:`translation` の返す翻訳オブジェクトの - :meth:`install` メソッドに渡されます。 - - *names* パラメタについては、翻訳オブジェクトの :meth:`install` メソッド の説明を参照ください。 + :meth:`~NullTranslations.install` メソッドに渡されます。 + + *names* パラメタについては、翻訳オブジェクト の :meth:`~NullTranslations.install` メソッドの説明を参照ください。 以下に示すように、通常はアプリケーション中の文字列を関数 :func:`_` の呼 び出しで包み込んで翻訳対象候補であることを示します:: ============================================================================== Revision: 637dcacb6874 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:02:55 2011 Log: library/operator.rst 差分翻訳 http://code.google.com/p/python-doc-ja/source/detail?r=637dcacb6874 Modified: /library/operator.rst ======================================= --- /library/operator.rst Sun Nov 14 16:42:45 2010 +++ /library/operator.rst Fri Mar 25 16:02:55 2011 @@ -109,6 +109,12 @@ .. versionadded:: 2.2 +.. function:: index(a) + __index__(a) + + 整数に変換された *a* を返します。 ``a.__index__()`` と同等です。 + + .. versionadded:: 2.5 .. function:: inv(obj) invert(obj) @@ -142,7 +148,7 @@ .. function:: neg(obj) __neg__(obj) - *obj* の符号反転を返します。 + *obj* の符号反転 (``-obj``) を返します。 .. function:: or_(a, b) @@ -154,7 +160,7 @@ .. function:: pos(obj) __pos__(obj) - *obj* の符号非反転を返します。 + *obj* の符号非反転 (``+obj``) を返します。 .. function:: pow(a, b) @@ -192,15 +198,7 @@ *a* および *b* の排他的論理和を返します。 -.. function:: index(a) - __index__(a) - - 整数に変換された *a* を返します。 ``a.__index__()`` と同等です。 - - .. versionadded:: 2.5 - - -シーケンスを扱う演算子には以下のようなものがあります: +シーケンスを扱う演算子(いくつかの演算子は map 型も扱います)には以下のよう なものがあります: .. function:: concat(a, b) __concat__(a, b) @@ -602,6 +600,8 @@ | (算術)否 | ``- a`` | ``neg(a)`` | +----------------------+-------------------------+----------------------------------------+ | (論理)否 | ``not a`` | ``not_(a)`` | ++----------------------+-------------------------+----------------------------------------+ +| 符号反転 | ``+ a`` | ``pos(a)`` | +----------------------+-------------------------+----------------------------------------+ | 右シフト | ``a >> b`` | ``rshift(a, b)`` | +----------------------+-------------------------+----------------------------------------+ ============================================================================== Revision: 177d855567ea Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 16:33:30 2011 Log: latex_font_size の代わりに latex_elements の 'pointsize' を使うよ うに http://code.google.com/p/python-doc-ja/source/detail?r=177d855567ea Modified: /conf.py ======================================= --- /conf.py Sat Mar 5 01:24:08 2011 +++ /conf.py Fri Mar 25 16:33:30 2011 @@ -129,9 +129,6 @@ # The paper size ('letter' or 'a4'). latex_paper_size = 'a4' -# The font size ('10pt', '11pt' or '12pt'). -latex_font_size = '10pt' - # todo: translate commented topics. # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). @@ -180,7 +177,7 @@ latex_docclass = {'manual': 'jreport'} latex_elements = { 'papersize': 'a4paper', - 'pointsize': '12pt', + 'pointsize': '10pt', 'classoptins': ',dvipdfm', } ============================================================================== Revision: dbda281f3046 Author: Akihiro Uchida <uchid****@ike-d*****> Date: Fri Mar 25 17:20:33 2011 Log: LaTeX 出力の章の表示を改善 wiki LaTeXBuild クラスファイル周りの設 定参照 - 章のマークアップ修正 - フッタでの表示の修正 - 目次での付録の表示の修正 http://code.google.com/p/python-doc-ja/source/detail?r=dbda281f3046 Modified: /conf.py ======================================= --- /conf.py Fri Mar 25 16:33:30 2011 +++ /conf.py Fri Mar 25 17:20:33 2011 @@ -169,6 +169,30 @@ \strong{Python Software Foundation}\\ Email: \email{docs****@pytho*****} } +\makeatletter +\renewcommand{\DOCH}{ + \raggedleft\CNV\FmN{\@chapapp}\space + \CNoV\thechapter\CNV\FmN{\@chappos} + \par\nobreak\vskip40\p@ +} +\fancypagestyle{normal}{ + \fancyhf{} + \fancyfoot[LE,RO]{{\py @ HeaderFamily\thepage}} + \fancyfoot[LO]{{\py @ HeaderFamily\nouppercase{\rightmark}}} + \fancyfoot[RE]{{\py @ HeaderFamily\nouppercase{\leftmark}}} + \fancyhead[LE,RO]{{\py @ HeaderFamily \@title, \py @ release}} + \renewcommand{\headrulewidth}{0.4pt} + \renewcommand{\footrulewidth}{0.4pt} + \def\chaptermark##1{\markboth{\@chapapp\space\thechapter\space\@chappos\space ##1}{}} +} +\renewcommand{\appendix}{\par + \setcounter{chapter}{0}% + \setcounter{section}{0}% + \gdef\@chapapp{\appendixname}% + \gdef\@chappos{}% + \gdef\thechapter{\@Alph\c @ chapter} +} +\makeatother ''' # Documents to append as an appendix to all manuals.