- unittestと比べてfixtureという機能が素晴らしいことでテストコードがクリーンにかける
- fixtureはテスト間で共有できることが最大のメリット
- fixtureの呼び出し方がDIコンテナっぽい?
- 動的に書ける
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cofigparser | |
configparser.ConfigParser() | |
# general type | |
configparaser.RawConfigParser() | |
# the type to interporate % or ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
class PathContainer(NamedTuple): | |
root: str | |
document: str | |
exe: str | |
path_container = PathContainer("root_path","document_path","exe_path") | |
# immutableだけど各要素に名前でアクセスできるのが良い点 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('a', 'r') as a, open('b', 'w') as b: | |
do_something() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.isin([1,2]) | |
# 全ての要素が1, 2 をかどうかチェックしてくれる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# change the display | |
pd.set_option('display.max_columns', 100) | |
pd.set_option('display.max_rows', 100) |
pythonにおけるstacktraceは、例外発生時に、sys.las_traceback という変数にtracebackオブジェクトとして格納される。
その中身を参照するためにsys.exc_info()
が用意されている。
https://vaaaaaanquish.hatenablog.com/entry/2017/12/14/183225
git rm --cached 'file name'
ファイルを管理対象から外す(-rでディレクトリごと)
git stash
一時的に変更を保存する
git stash apply stash@{num}
一時的に保存した変更を元に戻す
git checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
# save parameters | |
torch.save(model.state_dict(), PATH) | |
# load parameters | |
model = ModelClass(*args, **kwargs) | |
model.load_state_dict(torch.load(PATH)) | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder