from diegame import DieGame
NB: Example
In this example, we put our class code in a separate .py
file.
Then we call it from within our notebook.
This is normal practice – class files cannot reside in notebooks if they are to be used by other code!
Open the file diegame.py
in the course repo to inspect the code.
= DieGame()
dg1 = DieGame() dg2
def check_values():
print('n_rolls:', dg1.n_rolls, dg2.n_rolls, DieGame.n_rolls, sep='\n\t')
print('weights:', dg1.weights, dg2.weights, DieGame.weights, sep='\n\t')
= 20 dg1.n_rolls
= [1, 10, 1, 1, 1, 1] dg1.weights
1) # Also alters the static because this is not an assignment dg2.weights.append(
= 50 DieGame.n_rolls
check_values()
n_rolls:
20
50
50
weights:
[1, 10, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1]