TheAlgorithms/Python · error · Exception
Usage of script: script_name <size_of_canvas:int>
Error message
Usage of script: script_name <size_of_canvas:int>
What it means
Raised when the game_of_life script is run with anything other than exactly one command-line argument. The __main__ block requires a single canvas size (e.g. `python game_of_life.py 50`); zero args, or more than one, raises a generic Exception whose text is the usage string 'Usage of script: script_name <size_of_canvas:int>'.
Source
Thrown at cellular_automata/game_of_life.py:112
# running the rules of game here.
state = pt
if pt:
if alive < 2:
state = False
elif alive in {2, 3}:
state = True
elif alive > 3:
state = False
elif alive == 3:
state = True
return state
if __name__ == "__main__":
if len(sys.argv) != 2:
raise Exception(usage_doc)
canvas_size = int(sys.argv[1])
# main working structure of this module.
c = create_canvas(canvas_size)
seed(c)
fig, ax = plt.subplots()
fig.show()
cmap = ListedColormap(["w", "k"])
try:
while True:
c = run(c)
ax.matshow(c, cmap=cmap)
fig.canvas.draw()
ax.cla()
except KeyboardInterrupt:
# do nothing.
pass
View on GitHub (pinned to f5988cc097)
Solutions
- Run with exactly one integer argument: python game_of_life.py 50.
- If wrapping the script, pass the size as the single argv entry and strip other flags.
- Note the next line calls int(sys.argv[1]), so a non-integer string will raise ValueError — always pass a plain integer.
Example fix
# before $ python cellular_automata/game_of_life.py Exception: Usage of script: script_name <size_of_canvas:int> # after $ python cellular_automata/game_of_life.py 50
Defensive patterns
Strategy: validation
Validate before calling
import sys
if len(sys.argv) != 2 or not sys.argv[1].isdigit():
sys.exit('Usage: game_of_life.py <size_of_canvas:int>') Prevention
- Always invoke with exactly one integer argument, e.g. python game_of_life.py 50.
- Remember int() is applied to argv[1] — pass a plain integer string, not flags.
When it happens
Trigger: Running `python game_of_life.py` (no args) or `python game_of_life.py 50 100` (two args). Only `python game_of_life.py <int>` is accepted.
Common situations: Copy-pasting run commands from docs that omit the size argument, wrapper scripts passing extra flags, or double-clicking the file with no argv configured.
Related errors
- Input value must be a 'int' type
- the value of both inputs must be positive
- both inputs must be positive integers
- input must be a negative integer
- the value of both inputs must be positive
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/c8a85a418e785226.
Report an issue: GitHub.