Skip to content

Instantly share code, notes, and snippets.

@Guilouf
Created May 16, 2018 18:18
Show Gist options
  • Save Guilouf/58142bcd30910d115a2f06dd60680470 to your computer and use it in GitHub Desktop.
Save Guilouf/58142bcd30910d115a2f06dd60680470 to your computer and use it in GitHub Desktop.
"Inherit" class attributes to instance attributes
class Params:
def __init__(self):
self.attr1 = self.attr1
@classmethod
def ret_attr1(cls):
return cls.attr1
Params.attr1 = "yuhuhu"
p2 = Params()
Params.attr1 = "gnegne"
p2attr = p2.ret_attr1() # gnegne
p2attr_inst = p2.attr1 # yuhuhu
debug = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment