encapsulation

How to suppress warning "Access to protected member" in pycharm method?

How to suppress warning "Access to protected member" in pycharm method? Question: I have some class class A(object): def __init__(self, data): self._data = data def _equals(self, other): return self._data == other._data Pycharm doesn’t like that I access other._data because it is private. “Access to protected member” This doesn’t make sense to me, because the access …

Total answers: 3

Difference between Encapsulation and Abstraction

Difference between Encapsulation and Abstraction Question: I had an interview today. I had a question from OOP, about the difference between Encapsulation & Abstraction? I replied to my knowledge that Encapsulation is basically binding data members & member functions into a single unit called Class. Whereas Abstraction is basically to hide implementation complexity & provide …

Total answers: 22

Non-member vs member functions in Python

Non-member vs member functions in Python Question: I’m relatively new to Python and struggling to reconcile features of the language with habits I’ve picked up from my background in C++ and Java. The latest issue I’m having has to do with encapsulation, specifically an idea best summed up by Item 23 of Meyer’s “Effective C++“: …

Total answers: 6

"public" or "private" attribute in Python ? What is the best way?

"public" or "private" attribute in Python ? What is the best way? Question: In Python, I have the following example class : class Foo: self._attr = 0 @property def attr(self): return self._attr @attr.setter def attr(self, value): self._attr = value @attr.deleter def attr(self): del self._attr As you can see, I have a simple “private” attribute “_attr” …

Total answers: 9

Understanding the difference between __getattr__ and __getattribute__

Understanding the difference between __getattr__ and __getattribute__ Question: I am trying to understand the difference between __getattr__ and __getattribute__, however, I am failing at it. The answer to the Stack Overflow question Difference between __getattr__ vs __getattribute__ says: __getattribute__ is invoked before looking at the actual attributes on the object, and so can be tricky …

Total answers: 4

Why are Python's 'private' methods not actually private?

Why are Python's 'private' methods not actually private? Question: Python gives us the ability to create ‘private’ methods and variables within a class by prepending double underscores to the name, like this: __myPrivateMethod(). How, then, can one explain this >>>> class MyClass: … def myPublicMethod(self): … print ‘public method’ … def __myPrivateMethod(self): … print ‘this …

Total answers: 12