{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import import_ipynb\n", "from PGenType import *\n", "from PGenObject import *\n", "\n", "class PInt(PGenType):\n", " \n", " def __init__(self, value = None, defined = None):\n", " super(PInt, self).__init__(value, defined)\n", " \n", " \n", " def getTypeName(self):\n", " return 'int'\n", " \n", " def getTypeClass(self):\n", " return self.__class__.__name__\n", " \n", " def __str__(self):\n", " return \"(int \" + str(self.getValue()) + \")\"\n", " \n", " def parse(self, text):\n", " value = int(text)\n", " result = PInt(value)\n", " return result\n", " \n", " def toFloat(self):\n", " return float(self.getValue())\n", " \n", " " ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n", "True\n", "4\n", "True\n", "True\n", "int\n", "PInt\n", "10\n", "False\n", "[10, False]\n", "[4, True]\n", "(int 10)\n", "(int 17)\n" ] } ], "source": [ "#### Test\n", "b = PInt(4,True)\n", "print(b.getValue())\n", "print(b.getDefined())\n", "a=PInt(4)\n", "print(a.getValue())\n", "print(a.getDefined())\n", "print(a==b)\n", "print(a.getTypeName())\n", "print(a.getTypeClass())\n", "l=[10, False]\n", "a.InFromList(l)\n", "print(a.getValue())\n", "print(a.getDefined())\n", "print(a.OutToList())\n", "print(b.OutToList())\n", "print(a)\n", "c = a.parse(\"17\")\n", "print(c)" ] }, { "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.4" } }, "nbformat": 4, "nbformat_minor": 2 }