Created
July 6, 2020 15:13
-
-
Save tmastny/d17ed7bd1f56569fe8a50537d333ee36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dynamically objects to completion | |
class Shape3(): | |
area = 1 | |
perimeter = 1 | |
location = 1 | |
shape_dict = {} | |
def __getitem__(self, key): | |
if hasattr(self, key): | |
return getattr(self, key) | |
return self.shape_dict[key] | |
def _ipython_key_completions_(self): | |
return ["area", "perimeter", "location"] + list(self.shape_dict) | |
def add(self, key): | |
self.shape_dict[key] = True | |
s = Shape3() | |
s.add("new_key") | |
# s["new<TAB> | |
s["new_key"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment