I had been a hard core Java programmer through out my career and had moved onto Python a while ago. The transition to python was a roller coaster ride of moments of unbridled exultation, deja vu and mirth followed by those of horror, surprise and deep disgust. Just to crib a bit, Python does not provide encapsulation...arrrghhhhh!!! and the best way to prevent people from calling an internal method seems to be to request them not to do so.
""" This method is meant to be consumed locally. Don't call it from outside.... please please please :( """ def _do_something_internal(): ----------------- -----------------This blog (and a few subsequent ones, hopefully) will capture my observations on some gotchas that "pleasantly" surprise people coming from the Java domain (may be relevant to other languages as well).
Scenario 1 :
def method1(): try: x = 10 except: pass print xExpected Output : Error. As the Variable x should not be visible out of the try/except scope.
Actual Output : 10
Surprised right. In Python, the scope of a variable is at an enclosing inner method/module level. Conditions in between like if, while, try e.t.c are ignored.