컴퓨터
-
클래스 데코레이터 예제컴퓨터 2019. 11. 13. 01:53
def time_this(original_function): print "decorating" def new_function(*args,**kwargs): print "starting timer" import datetime before = datetime.datetime.now() x = original_function(*args,**kwargs) after = datetime.datetime.now() print "Elapsed Time = {0}".format(after-before) return x return new_function def time_all_class_methods(Cls): class NewCls(object): def __init__(self,*args,**kwargs): se..
-
super(), inheritance 실행 순서컴퓨터 2019. 11. 12. 22:35
옛날 방식: DLR or depth-first left to right algorithm 요즘 방식: C3 Linearization algorithm 유기화학으로 치면 CIP 규칙 같은 것 super 의 parameter에는 첫째로 super가 써있는 위치의 class 명이 들어가고 둘째로 그것의 object인 self가 들어가야 한다. 어차피 class안에 쓰이면 class 명과 self는 정해지는 거 같은데 굳이 prameter로 받는 이유가 뭘까? 그래서 보통 생략하는거 같다. class Animal: def __init__(self, animalName): print(animalName, 'is an animal.') print("E") class Mammal(Animal): def __init_..
-
입문자를 위한 컴퓨터 프로그래밍 기초 용어컴퓨터 2019. 11. 8. 14:52
identifier 프로그래밍 언어에서 무슨 대상을 나타내는지, 무슨 명령을 하는지 구분이 되는 단어. Student 라는 클래스와 student라는 변수의 경우 대소문자로 구분이 되어 둘다 identifier로 쓰일 수 있다. 맨 앞글자가 대문자인지 소문자인지를 통해서 내가 원하는 것이 클래스인지 변수인지 구분이 되는 것이다. 반면에 #이나 ", ) 등을 단어에 포함시킬 경우 그 특수문자가 단어에 포함되는 것인지 문법적인 요소인지 구분하지 못하게 되어 그러한 단어들은 identifier로 쓰이기에 적절하지 않다. keyword 프로그래밍 언어에서 원래부터 정해져 있는 단어들. class, def, print, __init__, for 등등. function 행위에 대한 명령. 입출력 값의 존재 여부를 ..