Using Modules

In programming, a module is a piece of software that has a specific functionality. For example, when building a sudoku game, one module would be responsible for the game logic, and another module would be responsible for drawing the game on the screen. Each module is a different file, which can be edited separately.

Importing modules is similar to importing functions and is done by writing import <name of the module> . Every Python file can be referenced as a module. The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):

So the steps you do are:

  1. Save your code in a file e.g. like “myfirstmodule.py” (Notice: it is has to be in the same directory as your main file)
  2. Import your module: watch my blog post Mastery 07 for the different options on how to import libraries and functions, it is the same here.
  3. Use the module for your purposes in your current code.

Example:

With this knowlegde you can directly start. If you want to go more into detail I can recommend this page: https://www.w3schools.com/python/python_modules.asp

#Mastery09

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s