Skip to content

Instantly share code, notes, and snippets.

View latsa's full-sized avatar
🎯
Focusing

latsa

🎯
Focusing
  • @ftopia
  • Paris, France
View GitHub Profile
@latsa
latsa / private.py
Created February 17, 2017 23:19
Python @Private decorator
import sys, functools
def private(member):
@functools.wraps(member)
def wrapper(*function_args):
myself = member.__name__
caller = sys._getframe(1).f_code.co_name
if (not caller in dir(function_args[0]) and not caller is myself):
raise Exception("%s called by %s is private"%(myself,caller))
return member(*function_args)