1 / 8

Creating and Using Modules

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 in IDLE. Modules.

gaille
Download Presentation

Creating and Using Modules

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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: • fromtestrobotsimport * • 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. Summary • 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.

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

More Related