Advertisement
pleabargain

ipynb issues with functions not showing up

Mar 24th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.83 KB | None | 0 0
  1. {
  2.  "metadata": {
  3.   "name": "ch 8 classes and objects"
  4.  },
  5.  "nbformat": 3,
  6.  "nbformat_minor": 0,
  7.  "worksheets": [
  8.   {
  9.    "cells": [
  10.     {
  11.      "cell_type": "code",
  12.      "collapsed": false,
  13.      "input": "class Things:\n    pass",
  14.      "language": "python",
  15.      "metadata": {},
  16.      "outputs": [],
  17.      "prompt_number": 101
  18.     },
  19.     {
  20.      "cell_type": "code",
  21.      "collapsed": false,
  22.      "input": "class Inanimate(Things):\n    pass",
  23.      "language": "python",
  24.      "metadata": {},
  25.      "outputs": [],
  26.      "prompt_number": 102
  27.     },
  28.     {
  29.      "cell_type": "code",
  30.      "collapsed": false,
  31.      "input": "class Animate(Things):\n    pass",
  32.      "language": "python",
  33.      "metadata": {},
  34.      "outputs": [],
  35.      "prompt_number": 103
  36.     },
  37.     {
  38.      "cell_type": "code",
  39.      "collapsed": false,
  40.      "input": "class Sidewalks(Inanimate):\n    pass",
  41.      "language": "python",
  42.      "metadata": {},
  43.      "outputs": [],
  44.      "prompt_number": 104
  45.     },
  46.     {
  47.      "cell_type": "code",
  48.      "collapsed": false,
  49.      "input": "class Animals(Animate):\n    pass",
  50.      "language": "python",
  51.      "metadata": {},
  52.      "outputs": [],
  53.      "prompt_number": 105
  54.     },
  55.     {
  56.      "cell_type": "code",
  57.      "collapsed": false,
  58.      "input": "class Mammals(Animals):\n    pass",
  59.      "language": "python",
  60.      "metadata": {},
  61.      "outputs": [],
  62.      "prompt_number": 106
  63.     },
  64.     {
  65.      "cell_type": "code",
  66.      "collapsed": false,
  67.      "input": "class Giraffes(Mammals):\n    pass",
  68.      "language": "python",
  69.      "metadata": {},
  70.      "outputs": [],
  71.      "prompt_number": 107
  72.     },
  73.     {
  74.      "cell_type": "code",
  75.      "collapsed": false,
  76.      "input": "reginald = Giraffes()",
  77.      "language": "python",
  78.      "metadata": {},
  79.      "outputs": [],
  80.      "prompt_number": 108
  81.     },
  82.     {
  83.      "cell_type": "code",
  84.      "collapsed": false,
  85.      "input": "print(Giraffes())# printing the class doesn't do anything...yet?!",
  86.      "language": "python",
  87.      "metadata": {},
  88.      "outputs": [
  89.       {
  90.        "output_type": "stream",
  91.        "stream": "stdout",
  92.        "text": "<__main__.Giraffes object at 0x3ef4310>\n"
  93.       }
  94.      ],
  95.      "prompt_number": 109
  96.     },
  97.     {
  98.      "cell_type": "code",
  99.      "collapsed": false,
  100.      "input": "",
  101.      "language": "python",
  102.      "metadata": {},
  103.      "outputs": [],
  104.      "prompt_number": 109
  105.     },
  106.     {
  107.      "cell_type": "code",
  108.      "collapsed": false,
  109.      "input": "class Animals(Animate):\n    def breathe(self):\n        pass\n    def move(self):\n        pass\n    def eat_food(self):\n        pass",
  110.      "language": "python",
  111.      "metadata": {},
  112.      "outputs": [],
  113.      "prompt_number": 110
  114.     },
  115.     {
  116.      "cell_type": "code",
  117.      "collapsed": false,
  118.      "input": "class Mammals(Animals):\n    def feed_young_with_milk(self):\n        pass\nclass Giraffes(Mammals):\n    def eat_leaves_from_trees(self):\n        pass",
  119.      "language": "python",
  120.      "metadata": {},
  121.      "outputs": [],
  122.      "prompt_number": 111
  123.     },
  124.     {
  125.      "cell_type": "code",
  126.      "collapsed": false,
  127.      "input": "reginald= Giraffes()\nreginald.move()\nreginald.eat_leaves_from_trees()",
  128.      "language": "python",
  129.      "metadata": {},
  130.      "outputs": [],
  131.      "prompt_number": 112
  132.     },
  133.     {
  134.      "cell_type": "code",
  135.      "collapsed": false,
  136.      "input": "harold = Giraffes()",
  137.      "language": "python",
  138.      "metadata": {},
  139.      "outputs": [],
  140.      "prompt_number": 113
  141.     },
  142.     {
  143.      "cell_type": "code",
  144.      "collapsed": false,
  145.      "input": "harold.move()",
  146.      "language": "python",
  147.      "metadata": {},
  148.      "outputs": [],
  149.      "prompt_number": 114
  150.     },
  151.     {
  152.      "cell_type": "code",
  153.      "collapsed": false,
  154.      "input": "class Animals(Animate):\n    def breathe(self):\n        print('breathing')\n    def move(self):\n        print('moving')\n    def eat_food(self):\n        print('eating food')",
  155.      "language": "python",
  156.      "metadata": {},
  157.      "outputs": [],
  158.      "prompt_number": 115
  159.     },
  160.     {
  161.      "cell_type": "code",
  162.      "collapsed": false,
  163.      "input": "class Mammals(Animals):\n    def feed_young_with_milk(self):\n        print('feeding young')\nclass Giraffes(Mammals):\n    def eat_leaves_from_trees(self):\n        print('eating leaves')\n    def find_food(self):\n        self.move()\n        print (\"I've found food\")\n        self.eat_food()\n    def dance_a_jig(self):\n        for i in range (10):\n            self.move()\n            print('dance')\n    def take_a_nap(self):\n        for i in range(5):\n            self.move()\n            print(\"I'm so sleepy...\")",
  164.      "language": "python",
  165.      "metadata": {},
  166.      "outputs": [],
  167.      "prompt_number": 157
  168.     },
  169.     {
  170.      "cell_type": "code",
  171.      "collapsed": false,
  172.      "input": "reginald = Giraffes()\nharold = Giraffes()\nharold.\nreginald.eat_leaves_from_trees()\nreginald.breathe()\nharold.feed_young_with_milk()\nharold.dance_a_jig()",
  173.      "language": "python",
  174.      "metadata": {},
  175.      "outputs": [
  176.       {
  177.        "ename": "SyntaxError",
  178.        "evalue": "invalid syntax (<ipython-input-156-02308f850bda>, line 3)",
  179.        "output_type": "pyerr",
  180.        "traceback": [
  181.         "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-156-02308f850bda>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m    harold.\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
  182.        ]
  183.       }
  184.      ],
  185.      "prompt_number": 156
  186.     },
  187.     {
  188.      "cell_type": "code",
  189.      "collapsed": false,
  190.      "input": "reginald.breathe()",
  191.      "language": "python",
  192.      "metadata": {},
  193.      "outputs": [
  194.       {
  195.        "output_type": "stream",
  196.        "stream": "stdout",
  197.        "text": "breathing\n"
  198.       }
  199.      ],
  200.      "prompt_number": 118
  201.     },
  202.     {
  203.      "cell_type": "code",
  204.      "collapsed": false,
  205.      "input": "harold.move()",
  206.      "language": "python",
  207.      "metadata": {},
  208.      "outputs": [
  209.       {
  210.        "output_type": "stream",
  211.        "stream": "stdout",
  212.        "text": "moving\n"
  213.       }
  214.      ],
  215.      "prompt_number": 119
  216.     },
  217.     {
  218.      "cell_type": "code",
  219.      "collapsed": false,
  220.      "input": "reginald.eat_food()",
  221.      "language": "python",
  222.      "metadata": {},
  223.      "outputs": [
  224.       {
  225.        "output_type": "stream",
  226.        "stream": "stdout",
  227.        "text": "eating food\n"
  228.       }
  229.      ],
  230.      "prompt_number": 120
  231.     },
  232.     {
  233.      "cell_type": "code",
  234.      "collapsed": false,
  235.      "input": "reginald.feed_young_with_milk()",
  236.      "language": "python",
  237.      "metadata": {},
  238.      "outputs": [
  239.       {
  240.        "output_type": "stream",
  241.        "stream": "stdout",
  242.        "text": "feeding young\n"
  243.       }
  244.      ],
  245.      "prompt_number": 121
  246.     },
  247.     {
  248.      "cell_type": "code",
  249.      "collapsed": false,
  250.      "input": "class Giraffes(Mammals):\n    def find_food(self):\n        self.move()\n        print (\"I've found food\")\n        self.eat_food()",
  251.      "language": "python",
  252.      "metadata": {},
  253.      "outputs": [],
  254.      "prompt_number": 122
  255.     },
  256.     {
  257.      "cell_type": "code",
  258.      "collapsed": false,
  259.      "input": "harold.breathe()\nreginald.breathe()\nharold.",
  260.      "language": "python",
  261.      "metadata": {},
  262.      "outputs": [
  263.       {
  264.        "output_type": "stream",
  265.        "stream": "stdout",
  266.        "text": "breathing\nbreathing\n"
  267.       }
  268.      ],
  269.      "prompt_number": 123
  270.     },
  271.     {
  272.      "cell_type": "code",
  273.      "collapsed": false,
  274.      "input": "reginald.feed_young_with_milk()",
  275.      "language": "python",
  276.      "metadata": {},
  277.      "outputs": [
  278.       {
  279.        "output_type": "stream",
  280.        "stream": "stdout",
  281.        "text": "feeding young\n"
  282.       }
  283.      ],
  284.      "prompt_number": 124
  285.     },
  286.     {
  287.      "cell_type": "code",
  288.      "collapsed": false,
  289.      "input": "def eat_leaves_from_trees(self):\n    self.eat_food()",
  290.      "language": "python",
  291.      "metadata": {},
  292.      "outputs": [],
  293.      "prompt_number": 131
  294.     },
  295.     {
  296.      "cell_type": "code",
  297.      "collapsed": false,
  298.      "input": "reginald.eat_food()\nreginald.find_food()\nharold.eat_leaves_from_trees()\n",
  299.      "language": "python",
  300.      "metadata": {},
  301.      "outputs": [
  302.       {
  303.        "ename": "AttributeError",
  304.        "evalue": "'Giraffes' object has no attribute 'find_food'",
  305.        "output_type": "pyerr",
  306.        "traceback": [
  307.         "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
  308.         "\u001b[1;32m<ipython-input-132-873f96003fcf>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mreginald\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meat_food\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mreginald\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind_food\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mharold\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meat_leaves_from_trees\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
  309.         "\u001b[1;31mAttributeError\u001b[0m: 'Giraffes' object has no attribute 'find_food'"
  310.        ]
  311.       },
  312.       {
  313.        "output_type": "stream",
  314.        "stream": "stdout",
  315.        "text": "eating food\n"
  316.       }
  317.      ],
  318.      "prompt_number": 132
  319.     },
  320.     {
  321.      "cell_type": "code",
  322.      "collapsed": false,
  323.      "input": "harold.eat_lea",
  324.      "language": "python",
  325.      "metadata": {},
  326.      "outputs": [
  327.       {
  328.        "ename": "AttributeError",
  329.        "evalue": "'Giraffes' object has no attribute 'eat_lea'",
  330.        "output_type": "pyerr",
  331.        "traceback": [
  332.         "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
  333.         "\u001b[1;32m<ipython-input-127-c652efb4d875>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mharold\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meat_lea\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
  334.         "\u001b[1;31mAttributeError\u001b[0m: 'Giraffes' object has no attribute 'eat_lea'"
  335.        ]
  336.       }
  337.      ],
  338.      "prompt_number": 127
  339.     },
  340.     {
  341.      "cell_type": "code",
  342.      "collapsed": false,
  343.      "input": "reginald.breathe()",
  344.      "language": "python",
  345.      "metadata": {},
  346.      "outputs": [
  347.       {
  348.        "output_type": "stream",
  349.        "stream": "stdout",
  350.        "text": "breathing\n"
  351.       }
  352.      ],
  353.      "prompt_number": 128
  354.     },
  355.     {
  356.      "cell_type": "code",
  357.      "collapsed": false,
  358.      "input": "def dance_a_jig(self):\n    self.move()\n    print('dance')\n",
  359.      "language": "python",
  360.      "metadata": {},
  361.      "outputs": [],
  362.      "prompt_number": 139
  363.     },
  364.     {
  365.      "cell_type": "code",
  366.      "collapsed": false,
  367.      "input": "dance_a_jig(1)",
  368.      "language": "python",
  369.      "metadata": {},
  370.      "outputs": [
  371.       {
  372.        "ename": "AttributeError",
  373.        "evalue": "'int' object has no attribute 'move'",
  374.        "output_type": "pyerr",
  375.        "traceback": [
  376.         "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
  377.         "\u001b[1;32m<ipython-input-141-3e182466538a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdance_a_jig\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
  378.         "\u001b[1;32m<ipython-input-139-13daad1cb54c>\u001b[0m in \u001b[0;36mdance_a_jig\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdance_a_jig\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m     \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'dance'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
  379.         "\u001b[1;31mAttributeError\u001b[0m: 'int' object has no attribute 'move'"
  380.        ]
  381.       }
  382.      ],
  383.      "prompt_number": 141
  384.     },
  385.     {
  386.      "cell_type": "code",
  387.      "collapsed": false,
  388.      "input": "harold.dance_a_jig()\nreginald.eat_food()\n",
  389.      "language": "python",
  390.      "metadata": {},
  391.      "outputs": [
  392.       {
  393.        "ename": "AttributeError",
  394.        "evalue": "'Giraffes' object has no attribute 'dance_a_jig'",
  395.        "output_type": "pyerr",
  396.        "traceback": [
  397.         "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
  398.         "\u001b[1;32m<ipython-input-138-e8623aa3255b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mharold\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdance_a_jig\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mreginald\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meat_food\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
  399.         "\u001b[1;31mAttributeError\u001b[0m: 'Giraffes' object has no attribute 'dance_a_jig'"
  400.        ]
  401.       }
  402.      ],
  403.      "prompt_number": 138
  404.     },
  405.     {
  406.      "cell_type": "code",
  407.      "collapsed": false,
  408.      "input": "harold.",
  409.      "language": "python",
  410.      "metadata": {},
  411.      "outputs": [],
  412.      "prompt_number": 130
  413.     },
  414.     {
  415.      "cell_type": "code",
  416.      "collapsed": false,
  417.      "input": "??Giraffes",
  418.      "language": "python",
  419.      "metadata": {},
  420.      "outputs": [],
  421.      "prompt_number": 142
  422.     },
  423.     {
  424.      "cell_type": "code",
  425.      "collapsed": false,
  426.      "input": "?Giraffes",
  427.      "language": "python",
  428.      "metadata": {},
  429.      "outputs": [],
  430.      "prompt_number": 143
  431.     },
  432.     {
  433.      "cell_type": "code",
  434.      "collapsed": false,
  435.      "input": "harold.feed_young_with_milk()",
  436.      "language": "python",
  437.      "metadata": {},
  438.      "outputs": [
  439.       {
  440.        "output_type": "stream",
  441.        "stream": "stdout",
  442.        "text": "feeding young\n"
  443.       }
  444.      ],
  445.      "prompt_number": 152
  446.     },
  447.     {
  448.      "cell_type": "code",
  449.      "collapsed": false,
  450.      "input": "",
  451.      "language": "python",
  452.      "metadata": {},
  453.      "outputs": []
  454.     }
  455.    ],
  456.    "metadata": {}
  457.   }
  458.  ]
  459. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement