Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules.

Similar presentations


Presentation on theme: "Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules."— Presentation transcript:

1 Creating and Using Modules Sec 9-6 Web Design

2 Objectives The student will: Know how to create and save a module in Python Know how to include your modules in IDLE.

3 Modules Once you start to create functions for Python you may want to store these functions and use them later in different program. The files in which you stores functions is called a module Modules are stored in files with an extension of.py (e.g. testrobots.py)

4 Creating a Module Start Python. From the File menu Select New Window Type in the functions – It’s always a good idea to comment the code so you can remember what the module and the functions do Save the file with a.py extension Save the file in the same folder as your start IDLE program

5 Including Modules in IDLE Once you save your program you “include” it in your IDLE window: from testrobots import * Now all the functions are available for use… Note that the lines not included in a function are executed immediately

6 Using Functions form a Module Once you have imported the functions you can simply call them:

7 Putting functions into modules helps keep things organized. Include the functions in your program by: from module import * – Once imported all functions can be used. Summary

8 Rest of Today Complete the program from yesterday. Show me the results when complete. – Everyone must do this!


Download ppt "Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules."

Similar presentations


Ads by Google