開発環境
- 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 python3.3
#-*- coding: utf-8 -*-
print("モジュールのインポート完了")
def f(name):
print("Hello, " + name)
a = 10
入出力結果(Terminal)
$ python
Python 3.3.0 (default, Sep 29 2012, 08:16:08)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sample
モジュールのインポート完了
>>> sample.f("Python")
Hello, Python
>>> sample.a
10
>>> quit()
$
0 コメント:
コメントを投稿