Last active
December 8, 2019 16:15
-
-
Save koi8-r/aa127d07f217cb3fd15c0f2d366779dc 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": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": { | |
"attr": { | |
"_": [], | |
"api": true, | |
"gui": true | |
}, | |
"groups": [ | |
"root", | |
"wheel" | |
], | |
"id": 0, | |
"login": "root" | |
}, | |
"text/html": [ | |
"<div><ul><li>A</li><li>B</li><li>C</li></ul></div>" | |
], | |
"text/plain": [ | |
"<__main__.HtmlVW object>" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": { | |
"application/json": { | |
"expanded": true, | |
"root": "/" | |
} | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from IPython.display import DisplayObject\n", | |
"\n", | |
"\n", | |
"class HtmlVW(DisplayObject):\n", | |
" \"\"\"\n", | |
" See also:\n", | |
" - https://github.com/mpacer/display_xml/blob/master/display_xml/xml.py\n", | |
" - https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html\n", | |
" \"\"\"\n", | |
" \n", | |
" _data = None\n", | |
" \n", | |
" def __init__(self, data=None, url=None, filename=None):\n", | |
" self.metadata = {\n", | |
" 'expanded': True,\n", | |
" 'root': '/',\n", | |
" }\n", | |
" super().__init__(data=data, url=url, filename=filename)\n", | |
"\n", | |
" @property\n", | |
" def data(self):\n", | |
" return self._data\n", | |
"\n", | |
" @data.setter\n", | |
" def data(self, data):\n", | |
" self._data = data\n", | |
"\n", | |
" def _repr_html_(self):\n", | |
" return \"\"\"<div><ul><li>A</li><li>B</li><li>C</li></ul></div>\"\"\"\n", | |
"\n", | |
" def _repr_json_(self):\n", | |
" return self.data, self.metadata\n", | |
"\n", | |
"HtmlVW({\n", | |
" 'id': 0,\n", | |
" 'login': 'root',\n", | |
" 'attr': {\n", | |
" 'api': True, 'gui': True, '_': []\n", | |
" },\n", | |
" 'groups': ['root', 'wheel']\n", | |
"})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment