PECS — “Producer Extends, Consumer Super”

Have you ever heard about “PECS”?

If you have, you would have ended up googling it and found…

Producer Extends, Consumer Super.”

Eh? What exactly are Producer and Consumer…? Actually, it’s not easy to understand this concept at once.

So, let’s visualize this concept so that we can understand it easily!

When you read some codes written in Java, there is a high chance that you ran into this weird looking stuff.

<? super SomeType>


<? extends SomeType>

Obviously it’s related to the concepts of ‘Generic types’ and ‘Inheritance’. …

Photo by Nigel Tadyanehondo on Unsplash

Python에서 __getattr__, __getattribute__ 의 차이점, 그리고 추가로 getattr()를 간단히 알아보자.


__getattr__는 인스턴스에 해당 attribute가 없을경우 호출된다.

즉, 다 찾아봐도 없으면 __getattr__를 호출하게된다(인풋인자로 해당 attribute를 넘겨주면서).

쉽게말해 제일 “후순위”로 호출되는 녀석이라 볼 수 있다.


__getattribute__는 인스턴스에 해당 attribute가 있든지 없든지 호출되는데,

제일 “선순위”로 호출되는 녀석이다.

즉, 인스턴스에 그 attribute가 있어도, __getattribute__를 먼저 호출하면서 인풋인자로 해당 attrib …

Photo by Nigel Tadyanehondo on Unsplash

in Python, what’s the difference between

__getattr__ , __getattribute__ , and getattr() ?


__getattr__ gets called if there is no attribute in the instance.

It’s invoked “last”, if Python can’t find that attribute.(lowest priority)


__getattribute__ gets called all the times, whether there is the attribute or not.

It’s invoked “first”(highest priority) — it actually “intercepts” every lookup.

So, even if there is the attribute in the instance, Python calls __getattribute__ first, with the attribute as an argument.


getattr() has 2 or 3 parameters.

getattr(myObj, ‘myAttribute’) is the same as myObj.myAttribute. Here, the second argument is a string.

In getattr(myObj, ‘anotherAttribute’…

Photo by Dương Hữu on Unsplash


with open(...) as f 

를 많이 볼 수 잇다.

근데, with를 사용하지 않고

f = open(...) 

이렇게 해서 open함수를 사용해주는경우도 있다(이 경우 f.close()반드시 해줘야함).

그런데, 두 경우에서 ‘f’ 는 마치 같은 녀석처럼 쓰인다.

만약 그렇다면, f는 open함수의 리턴값이니까, with A as B 에서 A는 B 와 같은 녀석인가??

결론부터 말하면, 일반적인 경우, 그렇지 않다.

open함수의 경우가 특별한 것이다.

with A as B:

라고 하면,

A는 ‘context manager’ 가 되는 객체이고,

B는 [A.__enter__메서드의 리턴값] 이다.

‘context manager’가 되 …

Photo by Joshua Hoehne on Unsplash

If you got this error when you tried training your deep learning model:

could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED

There’s a big chance that your GPU is running out of memory.

Jun-young Cha

Happy coding, enjoy learning :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store