開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅰ.(Getting Started)、Test Your Knowledge: Part Ⅰ Exercises 3.(Modules)を解いてみる。
その他参考書籍
Test Your Knowledge: Part Ⅰ Exercises 3.(Modules)
コード(BBEdit)
module1.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- print('Hello module world!')
入出力結果(Terminal, IPython)
Python 3.4.1 (default, May 21 2014, 01:39:38) Type "copyright", "credits" or "license" for more information. IPython 2.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import module1 Hello module world! In [2]: mkdir temp In [3]: mv module1.py temp In [4]: import module1 In [5]: import imp In [6]: imp.reload(module1) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-1d4ac78a6494> in <module>() ----> 1 imp.reload(module1) /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py in reload(module) 313 314 """ --> 315 return importlib.reload(module) /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py in reload(module) 147 spec = module.__spec__ = _bootstrap._find_spec(name, pkgpath, target) 148 methods = _bootstrap._SpecMethods(spec) --> 149 methods.exec(module) 150 # The module may have replaced itself in sys.modules! 151 return sys.modules[name] /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/_bootstrap.py in exec(self, module) AttributeError: 'NoneType' object has no attribute 'name' In [7]: import temp.module1 Hello module world! In [8]: quit()
0 コメント:
コメントを投稿