![]() You may have noticed that when importing a module, a. If it's not found, it will continue looking for built-in modules. When the import draw directive runs, the Python interpreter looks for a file in the directory in which the script was executed with the module name and a. We need to import the draw module and then call draw.draw_game(). To reference the draw_game function from the game module, The function draw_game from the draw module, we need to specify in which module the function is The main function uses the local function play_game to run the game, and thenĭraws the result of the game using a function implemented in the draw module called draw_game. In this example, the game module imports the draw module, which enables it to use functions implemented The draw module may look something like this: # draw.py # this means that if this script is executed, then Modules are imported from other modules using the import command. ![]() Or in other words, the draw module that implements the logic for drawing the game on the screen. It uses the function draw_game from the file draw.py, The Python script game.py implements the game. ![]() The name of the module is the same as the file name.Ī Python module can have a set of functions, classes, or variables defined and implemented. Modules in Python are just Python files with a. Each module consists of a differentįile, which may be edited separately. In programming, a module is a piece of software that has a specific functionality.įor example, when building a ping pong game, one module may be responsible for the game logic, andĪnother module draws the game on the screen.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |