• Programming,  Python

    [Python] Multi-Thread Queue Polling

    여러개의 thread 중 하나의 thread가 처리하게끔 만드는것을 polling이라고 한다. Linux의 경우엔 select()라는 함수가 존재하는데, 이를 Python에서 구현하면 다음과 같다. Got: 1 Got: 10 Got: hello Got: 15 운영체제 시스템에선 유저와 커널이 서로 데이터를…

  • Programming,  Python

    [Python] SSLError

    Python에서 외부 호스트에 request를 날릴 때 다음과 같은 error가 발생한다. 위를 해결하기 위해서 다음과 같은 코드를 추가하면 해결 가능하다. os.environ['HTTP_PROXY'] = os.environ['http_proxy'] = "[Proxy Server IP]"

  • Programming,  Python

    [Python] Property Extension

    deleter 지난번에 Python에서 접근 지정을 위해 property class를 사용한다고 배웠다. Property 기능은 크게 세 가지가 존재하는데, getter, setter, deleter가 존재한다. deleter는 property를 삭제할 때 호출되는 함수다. (del을 통해) Subclass에서 Property Setting name to…

  • Programming,  Python

    [Python] 다중 상속, MRO

    Python에선 다중으로 상속이 가능하다. 그래서 대표적인 상속 예시가 다이아몬드 상속이다. Base.__init__ A.__init__ Base.__init__ B.__init__ C.__init__ 위 코드는 Base라는 최상위 class가 두 번 호출된다. C++의 경우엔 virtual이라는 것을 통해 하나라는 것을 알 수 있지만…

  • Programming,  Python

    [Python] Proxy Design Pattern

    42 A.spam None Should be 37: 37 Should be 37: 37 위 코드는 객체 a를 Proxy()에 넣으면 객체 p에 접근하면 마치 a에 접근하는 것처럼 하는 proxy design pattern 이다. 위 코드에서 print(p.x) 가…

  • Programming,  Python

    [Python] Override

    Class에서 부모 class와 자식 class의 function 이름이 같을 경우 자식 class’s function을 call 할 때 부모 class function이 가려지고 자식 class function이 호출된다. B.spam A.spam Constructor 또한 일반 함수처럼 override 된다. B.__init__() 1…

  • Programming,  Python

    [Python] Property

    Python에선 C++과 Java처럼 접근지정자가 존재하지 않는다. Guido Dave Expected a string 위 코드를 보면 decorator로 property() 함수가 사용되고 있다. 실제 property() wrapper 함수를 통해서 접근 지정을 위한 기능을 추가할 수 있다. 실제 property를…

  • Programming,  Python

    [Python] Special Function

    Python은 class 구조로 대부분 이뤄져있으며, 각 class는 __init__ 과 같은 special function으로 구성된다. Pair(3, 4) __init__() __init__: 기존 class의 constructor 역할을 한다. __repr__() __repr__: class의 객체를 출력했을 때 호출되는 함수이다. 위 코드에서 'Pair({0.x!r},…

  • Programming,  Python

    [Python] Coroutine

    기존에 generator에서 yield 키워드를 lvalue로 사용해 제어권을 넘겨줬지만, coroutine은 rvalue로 사용하여 특정 변수에 값을 전달 할 수 있다. 참고로 Coroutine은 generator의 일종이다. Ready to receiveGot 1Got 2Got Hello Coroutine은 decorator를 통해 사용하기 유용하다.…