Created
June 9, 2020 09:52
-
-
Save atkinson/9a8928615b6bb4022c1ec0061ea04dc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "'otherthing'" | |
}, | |
"metadata": {}, | |
"execution_count": 1 | |
} | |
], | |
"source": [ | |
"from inspect import getmembers\n", | |
"\n", | |
"\n", | |
"class MemberOfThing(object):\n", | |
"\n", | |
" def setup(self, token):\n", | |
" self.token = token\n", | |
"\n", | |
"\n", | |
"class ThingType(object):\n", | |
"\n", | |
" def __init__(self, token, *args, **kwargs):\n", | |
" for member, ref in getmembers(self, lambda m: isinstance(m, MemberOfThing)):\n", | |
" ref.setup(token=token)\n", | |
"\n", | |
"### Now WTF??? ####\n", | |
"\n", | |
"class Thing(ThingType):\n", | |
" member = MemberOfThing()\n", | |
"\n", | |
"# Create two instances of Thing\n", | |
"thing = Thing(token='thing')\n", | |
"otherthing = Thing(token='otherthing')\n", | |
"\n", | |
"thing.member.token " | |
] | |
} | |
], | |
"metadata": { | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.7-final" | |
}, | |
"orig_nbformat": 2, | |
"kernelspec": { | |
"name": "python37764bittradingvirtualenv7e7bee5f6d9c4e4f8a202dccd3c73e6c", | |
"display_name": "Python 3.7.7 64-bit ('trading': virtualenv)" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment