{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-19T07:18:27.691397Z",
     "start_time": "2019-08-19T07:18:27.668673Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "house.sent\n",
      "\t fr L'auberge de jeunesse n'est pas chère.\n",
      "\t en The hostel is not expensive.\n",
      "\t zh 宿舍不贵。\n",
      "\t ja ホステルは高価ではありません。\n",
      "\t v1 Hosuteru wa kōkade wa arimasen.\n",
      "house.sent\n",
      "\t fr L'auberge de jeunesse n'est pas chère.\n",
      "\t en The hostel is not expensive.\n",
      "\t zh 宿舍不贵。\n",
      "\t ja ホステルは高価ではありません。\n",
      "\t v1 Konsāto ga owattanode kare wa naite imasu\n",
      "house.sent\n",
      "\t fr L'auberge de jeunesse n'est pas chère.\n",
      "\t en The hostel is not expensive.\n",
      "\t zh 宿舍不贵。\n",
      "\t ja ホステルは高価ではありません。\n",
      "\t v1 Hosuteru wa kōkade wa arimasen.\n",
      "house.sent\n",
      "\t fr L'auberge de jeunesse n'est pas chère.\n",
      "\t en The hostel is not expensive.\n",
      "\t zh 宿舍不贵。\n",
      "\t ja ホステルは高価ではありません。\n",
      "\t v1 Konsāto ga owattanode kare wa naite imasu\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "class Cats(object):\n",
    "    def __init__(self, name):\n",
    "        self.name=name\n",
    "        self.mats=[]\n",
    "    def __str__(self):\n",
    "        return self.name\n",
    "        \n",
    "class Mats(object):\n",
    "    _name = None\n",
    "    _fields = {}  # {field: field object}\n",
    "    def __init__(self, cat):\n",
    "        cat.mats.append(self)\n",
    "        self.cat=cat        \n",
    "        self.cnt=[]\n",
    "    def __getattr__(self, method):\n",
    "        \"\"\"Provide a dynamic access to a service method.\"\"\"\n",
    "        if method.startswith('_'):\n",
    "            return super(Mats, self).__getattr__(method)\n",
    "\n",
    "        def service_method(*args, **kwargs):\n",
    "            print(f\"{self.cat}.{method}\")\n",
    "            for key, value in kwargs.items():\n",
    "                print('\\t', key,value)\n",
    "            \n",
    "            self.cnt.append({'type':method, 'items':kwargs})\n",
    "            return self\n",
    "        return service_method\n",
    "\n",
    "fr_house=Cats('house')\n",
    "Mats(cat=fr_house) \\\n",
    "    .sent(fr=\"L'auberge de jeunesse n'est pas chère.\",\n",
    "          en=\"The hostel is not expensive.\",\n",
    "          zh=\"宿舍不贵。\",\n",
    "          ja=\"ホステルは高価ではありません。\",\n",
    "          v1=\"Hosuteru wa kōkade wa arimasen.\",\n",
    "          ) \\\n",
    "    .sent(fr=\"L'auberge de jeunesse n'est pas chère.\",\n",
    "          en=\"The hostel is not expensive.\",\n",
    "          zh=\"宿舍不贵。\",\n",
    "          ja=\"ホステルは高価ではありません。\",\n",
    "          v1=\"Konsāto ga owattanode kare wa naite imasu\",\n",
    "          ) \\\n",
    "        \n",
    "Mats(cat=fr_house) \\\n",
    "    .sent(fr=\"L'auberge de jeunesse n'est pas chère.\",\n",
    "          en=\"The hostel is not expensive.\",\n",
    "          zh=\"宿舍不贵。\",\n",
    "          ja=\"ホステルは高価ではありません。\",\n",
    "          v1=\"Hosuteru wa kōkade wa arimasen.\",\n",
    "          ) \\\n",
    "    .sent(fr=\"L'auberge de jeunesse n'est pas chère.\",\n",
    "          en=\"The hostel is not expensive.\",\n",
    "          zh=\"宿舍不贵。\",\n",
    "          ja=\"ホステルは高価ではありません。\",\n",
    "          v1=\"Konsāto ga owattanode kare wa naite imasu\",\n",
    "          ) \\\n",
    "    \n",
    "print(len(fr_house.mats))"
   ]
  }
 ],
 "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"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
