GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialsteacher.com — Python Modules Python ModulesAny text file with the If the programming algorithm requires defining a lot of functions and classes, they are logically organized in modules. One module stores classes, functions and other resources of similar relevance. Such a modular structure of the code makes it easy to understand, use and maintain. Creating a ModuleShown below is a Python script containing the definition of calc.py Importing a ModuleWe can now import this module and execute the In the same way, to use the above Every module, either built-in or custom made, is an object of a module class. Verify the type of different modules using the built-in Example: Module Type Renaming the Imported ModuleUse the from .. import statementThe above import statement will load all the resources of the module in the current working environment (also called namespace). It is possible to import specific objects from a module by using this syntax. For example, the following module calc.py Now, we can import one or more functions using the from...import statement. For example, the following code imports only two functions in the Example: Importing Module's Functions The following example imports only one function - sum. Example: Importing Module's Function You can also import all of its functions using the Example: Import Everythin from Module Module Search PathWhen the import statement is encountered either in an interactive session or in a script:
As the Python interpreter starts, it put all the above locations in a list returned by the sys.path attribute. Example: Module Attributes If the required module is not present in any of the directories above, the message Reloading a ModuleSuppose you have already imported a module and using it. However, the owner of the module added or modified some functionalities after you imported it. So, you can reload the module to get the latest module using the Example: Reloading Module Getting Help on ModulesUse the ![]() As shown above, you can see the method names and descriptions. It will not display pages of help ending with --More--. Press Enter to see more help. You can also use the ![]() Learn about the module attributes in the next chapter. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |