2012年3月27日火曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のIII部(ステートメント)14章(Pythonのドキュメント)の練習問題を解いてみる。

1.

長く詳しい説明(モジュール、関数、クラス、メソッドとか)、あるいは実行時にPythonインタプリタによって内容を記録させたいようなコメントは#で始まるコメントではなくドキュメンテーション文字列を使用すべき。

2.

ドキュメンテーション文字列を参照する方法は、

  1. オブジェクトの__doc__属性を出力する
  2. PyDocのhelp関数を使う。
  3. PyDocのGUIで調べる

という3つの方法がある。

3.

オブジェクトの属性のリストを得るには、ビルトイン関数のdir()を使用すればいい。

入出力結果(Terminal)

$ python
Python 2.7.2 (default, Feb 12 2012, 23:50:38) 
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> dir(math)
['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
>>> 

4.

PyDocのGUIインターフェースで、モジュール名を入力せずに、[open browser]とクリックすれば、利用可能なモジュールのリストを得られる。

5.

本書の後にPythonの書籍を購入するとしたら、

など。

0 コメント:

コメントを投稿