{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python Advanced (2023-10-09 - 2023-10-09)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## JSON" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "d = {\n", " 'eins': 1,\n", " 'zwei': 2,\n", " # ...\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import json" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "d_str = json.dumps(d)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"eins\": 1, \"zwei\": 2}'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d_str" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(d_str)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Jetzt uebertragen wir die Daten ..." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "d_str_received = d_str" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "d_received = json.loads(d_str_received)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'eins': 1, 'zwei': 2}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d_received" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Type Annotations" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def f(i: int) -> str:\n", " return str(i)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'i': int, 'return': str}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.__annotations__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.11" } }, "nbformat": 4, "nbformat_minor": 4 }