Page 247 - Beginning Programming with Pyth - John Paul Mueller
P. 247

6. In a new cell, type SayHello(′′Angie′′) and click Run Cell.
The SayHello() function outputs the expected text, as shown in
Figure 11-7.
When you import attributes by using the from...import statement, you don’t need to precede the attribute name with a package name. This feature makes the attribute easier to access.
Using the from...import statement can also cause problems. If two attributes have the same name, you can import only one of them. The import statement prevents name collisions, which is important when you have a large number of attributes to import. In sum, you must exercise care when using the from...import statement.
7. In a new cell, type SayGoodbye(′′Harold′′) and click Run Cell.
You imported only the SayHello() function, so Python knows nothing about SayGoodbye() and displays an error message. The selective nature of the from...import statement can cause problems when you assume that an attribute is present when it really isn’t.
    FIGURE 11-5: Removing a package from the environment requires two steps.
 


























































































   245   246   247   248   249