< BACKMake Note | BookmarkCONTINUE >
156135250194107072078175030179198180024228156016206217188240240204174049228078191146090069

Exercises

1:

PathSearch vs. SearchPath. What is the difference between a path search and a search path?

2:

Importing Attributes. Assume you have a function called foo() in your module mymodule. What are the two ways of import this function into your namespace for invocation?

3:

Importing. What are the differences between using "import module" and "from module import *"?

4:

Namespaces vs. Variable Scope. How are namespaces and variable scopes different from each other?

5:

Using__import__().

(a) Use __import__() to import a module into your namespace. What is the correct syntax you finally used to get it working?

(b) Same as above, but use __import__() to import only specific names from modules.

6:

Extended Import. Create a new function called importAs(). This function will import a module or module into your namespace, but with a name you specify, not its original name. For example, calling newname=importAs('mymodule'), will import the module mymodule, but the module and all its elements are accessible only as newname or newname.attr. You will discover that this is the exact functionality provided by the new extended import syntax introduced in Python 2.0.


Last updated on 9/14/2001
Core Python Programming, © 2002 Prentice Hall PTR

< BACKMake Note | BookmarkCONTINUE >

© 2002, O'Reilly & Associates, Inc.