Skip to content

Commit 09b7104

Browse files
committed
ch19
1 parent 06ac841 commit 09b7104

1 file changed

Lines changed: 112 additions & 1 deletion

File tree

ch19-documentation.ipynb

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,112 @@
1-
{"worksheets": [{"metadata": {}, "cells": [{"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def the_function(var):\n", " \"\"\"This is a docstring, where a function definition might live\"\"\"\n", " a = 1 + var # this is a simple comment\n", " return a"], "metadata": {}, "language": "python", "prompt_number": 1}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " # first, retrieve the decay constants from the database\n", " mylist = database.decay_constants()\n", " # next, try to access an element of the list\n", " try:\n", " d = mylist[index] # gets decay constant at index in the list\n", " # if the index doesn't exist\n", " except IndexError:\n", " # throw an informative error message\n", " raise Exception(\"value not found in the list\")\n", " return d"], "metadata": {}, "language": "python", "prompt_number": 2}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " lambdas = database.decay_constants()\n", " try:\n", " lambda_i = lambdas[index] # gets decay constant at index in the list\n", " except IndexError:\n", " raise Exception(\"value not found in the list\")\n", " return lambda"], "metadata": {}, "language": "python", "prompt_number": 3}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " lambdas = database.decay_constants()\n", " try:\n", " lambda_i = lambdas[index] # gets decay constant at index in the list\n", " except LookupError:\n", " raise Exception(\"value not found in the decay constants object\")\n", " return lambda"], "metadata": {}, "language": "python", "prompt_number": 4}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["# packages and modules are short and lowercase\n", "packages\n", "modules\n", "\n", "# other objects can be long\n", "ClassesUseCamelCase\n", "ExceptionsAreClassesToo\n", "functions_use_snake_case\n", "CONSTANTS_USE_ALL_CAPS\n", "\n", "# variable scope is *suggested* by style convention\n", "_single_leading_underscore_ # internal to module\n", "single_trailing_underscore_ # avoids conflicts with Python keywords\n", "__double_leading_and_trailing__ # these are magic, like __init__"], "metadata": {}, "language": "python", "prompt_number": 5}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def <name>(<args>):\n", " \"\"\"<docstring>\"\"\"\n", " <body>"], "metadata": {}, "language": "python", "prompt_number": 6}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def power(base, x):\n", " \"\"\"Computes base^x. Both base and x should be integers,\n", " floats, or another numeric type.\n", " \"\"\"\n", " return base**x "], "metadata": {}, "language": "python", "prompt_number": 7}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["class Isotope(object):\n", " \"\"\"A class defining the data and behaviors of a radionuclide.\n", " \"\"\""], "metadata": {}, "language": "python", "prompt_number": 8}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": [".. function:: spin(self, s)\n", "\n", " Set the spin of the particle to the value, s.\n"], "metadata": {}, "language": "python", "prompt_number": 9}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": [".. function:: spin(self, s)\n", "\n", " Set the spin of the particle to the value, s.\n", "\n", " :param s: the new spin value\n", " :type s: integer or float\n", " :rtype: None"], "metadata": {}, "language": "python", "prompt_number": 10}]}], "nbformat": 3, "nbformat_minor": 0, "metadata": {"name": "", "signature": "sha256:a507e2b4823427095ab936332e4a2258de07c758f87fbb5c5e55c94c3d5e481c"}}
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:ff7085d4adddde9839084e8e96d9db19507b89aefcf331f30bf54a381832a69a"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "code",
13+
"collapsed": false,
14+
"input": [
15+
"def the_function(var):\n",
16+
" \"\"\"This is a docstring, where a function definition might live\"\"\"\n",
17+
" a = 1 + var # this is a simple comment\n",
18+
" return a"
19+
],
20+
"language": "python",
21+
"metadata": {},
22+
"outputs": [],
23+
"prompt_number": 1
24+
},
25+
{
26+
"cell_type": "code",
27+
"collapsed": false,
28+
"input": [
29+
"def decay(index, database):\n",
30+
" # first, retrieve the decay constants from the database\n",
31+
" mylist = database.decay_constants()\n",
32+
" # next, try to access an element of the list\n",
33+
" try:\n",
34+
" d = mylist[index] # gets decay constant at index in the list\n",
35+
" # if the index doesn't exist\n",
36+
" except IndexError:\n",
37+
" # throw an informative error message\n",
38+
" raise Exception(\"value not found in the list\")\n",
39+
" return d"
40+
],
41+
"language": "python",
42+
"metadata": {},
43+
"outputs": [],
44+
"prompt_number": 2
45+
},
46+
{
47+
"cell_type": "code",
48+
"collapsed": false,
49+
"input": [
50+
"def decay(index, database):\n",
51+
" lambdas = database.decay_constants()\n",
52+
" try:\n",
53+
" lambda_i = lambdas[index] # gets decay constant at index in the list\n",
54+
" except IndexError:\n",
55+
" raise Exception(\"value not found in the list\")\n",
56+
" return lambda_i"
57+
],
58+
"language": "python",
59+
"metadata": {},
60+
"outputs": [],
61+
"prompt_number": 3
62+
},
63+
{
64+
"cell_type": "code",
65+
"collapsed": false,
66+
"input": [
67+
"def decay(index, database):\n",
68+
" lambdas = database.decay_constants()\n",
69+
" try:\n",
70+
" lambda_i = lambdas[index] # gets decay constant at index in the list\n",
71+
" except LookupError:\n",
72+
" raise Exception(\"value not found in the decay constants object\")\n",
73+
" return lambda_i"
74+
],
75+
"language": "python",
76+
"metadata": {},
77+
"outputs": [],
78+
"prompt_number": 4
79+
},
80+
{
81+
"cell_type": "code",
82+
"collapsed": false,
83+
"input": [
84+
"def power(base, x):\n",
85+
" \"\"\"Computes base^x. Both base and x should be integers,\n",
86+
" floats, or another numeric type.\n",
87+
" \"\"\"\n",
88+
" return base**x "
89+
],
90+
"language": "python",
91+
"metadata": {},
92+
"outputs": [],
93+
"prompt_number": 5
94+
},
95+
{
96+
"cell_type": "code",
97+
"collapsed": false,
98+
"input": [
99+
"class Isotope(object):\n",
100+
" \"\"\"A class defining the data and behaviors of a radionuclide.\n",
101+
" \"\"\""
102+
],
103+
"language": "python",
104+
"metadata": {},
105+
"outputs": [],
106+
"prompt_number": 6
107+
}
108+
],
109+
"metadata": {}
110+
}
111+
]
112+
}

0 commit comments

Comments
 (0)