{"record":{"id":"c8a85a418e785226","repo":"TheAlgorithms/Python","slug":"usage-of-script-script-name-size-of-canvas-int","errorCode":null,"errorMessage":"Usage of script: script_name <size_of_canvas:int>","messagePattern":"Usage of script: script_name <size_of_canvas:int>","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"cellular_automata/game_of_life.py","lineNumber":112,"sourceCode":"\n    # running the rules of game here.\n    state = pt\n    if pt:\n        if alive < 2:\n            state = False\n        elif alive in {2, 3}:\n            state = True\n        elif alive > 3:\n            state = False\n    elif alive == 3:\n        state = True\n\n    return state\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) != 2:\n        raise Exception(usage_doc)\n\n    canvas_size = int(sys.argv[1])\n    # main working structure of this module.\n    c = create_canvas(canvas_size)\n    seed(c)\n    fig, ax = plt.subplots()\n    fig.show()\n    cmap = ListedColormap([\"w\", \"k\"])\n    try:\n        while True:\n            c = run(c)\n            ax.matshow(c, cmap=cmap)\n            fig.canvas.draw()\n            ax.cla()\n    except KeyboardInterrupt:\n        # do nothing.\n        pass\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/cellular_automata/game_of_life.py#L94-L130","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\n$ python cellular_automata/game_of_life.py\nException: Usage of script: script_name <size_of_canvas:int>\n\n# after\n$ python cellular_automata/game_of_life.py 50","handlingStrategy":"validation","validationCode":"import sys\nif len(sys.argv) != 2 or not sys.argv[1].isdigit():\n    sys.exit('Usage: game_of_life.py <size_of_canvas:int>')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cellular-automata","cli","usage","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}