June 2023
Intermediate to advanced
316 pages
4h 31m
Japanese
1 #!/usr/bin/env python 2 import sys, re, operator, string, inspect 3 4 # 5 # メソッド呼び出しで引数の型を強制するためのデコレータ 6 # 7 class AcceptTypes: 8 def __init__(self, *args): 9 self._args = args 10 11 def __call__(self, f): 12 def wrapped_f(*args): 13 for i in range(len(self._args)): 14 if type(args[i]) != self._args[i]: 15 raise TypeError( f"Expecting {self._args[i]} got {type(args[i])}") 16 return f(*args) 17 return wrapped_f 18 # 19 # 関数定義 20 # 21 @AcceptTypes(str) 22 def extract_words(path_to_file): 23 with open(path_to_file) ...
Read now
Unlock full access