起動方法
$ipython notebook
iPythonとmatplotlibを使ってグラフを描画するときのおまじない。
%matplotlib inline import numpy as np import matplotlib.pyplot as plt
.ipynbファイルをgistかgithubにアップロードして置くことで、vbviwerによりwebページとして表示することができる。
import time
start = time.time()
print(">> Finish Analys :{0}".format(time.time() - start))
pyinstaller SimpleTextEditor.py --onefile --noconsole
# ファイルが存在しない場合は返却
if not os.path.exists(filepath):
# raise StandardError("File is not exist %s" % (filepath))
return
try:
# ファイルオープン
data = wave.open(filepath, 'rb')
except IOError:
raise StandardError("Cant file load %s" % (filepath))
else:
# 正常時の処理
finally:
pass
まずは悪い例
def get_status(file):
if not os.path.exists(file):
print "file not found"
sys.exit(1)
return open(file).readline()
これだと、open(file)の際に出たエラーを捕まえていない。
よい例
def get_status(file):
try:
return open(file).readline()
except EnvironmentError as err:
print "Unable to open file: {}".format(err)
sys.exit(1)