2012年12月19日水曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のV部(モジュール)まとめ演習6(リロード(python3k impモジュールのreload関数))を解いてみる。

その他参考書籍

6.

コード(TextWrangler)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

message = "First version"

def printer():
    print(message)

入出力結果(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.printer()
First version
>>> 
[1]+  Stopped                 python
$ vi sample.py
$ cat sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

message = "Second version"

def printer(a):
    print(a)
$ fg
python
import imp
import imp
>>> imp.reload(sample)
<module 'sample' from './sample.py'>
>>> sample.printer(sample.message)
Second version
>>> quit()
$

0 コメント:

コメントを投稿