開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のV部(モジュール)の18章(モジュールとインポート)練習問題1を解いてみる。
1.
インポートとするとモジュールオブジェクトになる。
コード(TextWrangler)
sample.py
#!/usr/bin/env python #encoding: utf-8 import math print(type(math)) a = 10 def f(): for x in range(10): print(x)
入出力結果(Terminal)
$ python Python 3.2.3 (default, Apr 18 2012, 20:17:30) [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 sample <class 'module'> 10 >>> print(type(sample)) <class 'module'> >>> import math >>> print(type(math)) <class 'module'> >>> print(type(sample.a)) <class 'int'> >>> print(type(sample.f)) <class 'function'> >>> type(math.sqrt) <class 'builtin_function_or_method'> >>> quit() $
0 コメント:
コメントを投稿