Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
system.


  1. If you do not have the LXDE graphical interface started automatically at boot, start it
    now by typing startx and pressing Enter.

  2. Open the LXTerminal by double-clicking the LXTerminal icon.

  3. Open the Python interactive shell by typing python3 at the shell prompt and
    pressing Enter.

  4. At the Python interactive shell prompt, >>>, type import os and press Enter.
    Python imports the os module into your Python shell.

  5. Type import time and press Enter to import the time module and all its
    functions into your Python shell.

  6. Look to see if the os module has a .py file by typing the command
    os.file. Note that before and after the file in the command are two
    underscores (_). Press Enter to see if an absolute directory reference and a file
    ending in .py are shown. You should see that this module does have a .py file.

  7. Look to see if the time module has a .py file by typing the command
    time.file and press Enter. You should receive an error because the time
    module does not have a .py file. (It’s okay that this step generates an error!) Since
    the time module does not have a .py file, it may be built-in.

  8. To determine whether the time module is built-in, import the sys module by
    typing import sys and pressing Enter.

  9. Produce a list of the built-in modules by typing sys.builtin_module_names
    and pressing Enter. Do you see the time module listed in the output of the Python
    statement? You should!

  10. Get a little help on the time module by typing help(time) and pressing Enter.
    In the help documentation, what are the two representations of time? Can you find
    this information? One is called the epoch, and the other is a tuple.

  11. Still looking at the time module’s help information, locate the time() function
    description. Which time representation does it use: epoch or the tuple?

  12. Press Q to exit the time module’s help information.

  13. To import the antigravity module, type import antigravity and press
    Enter. You might need to wait a few minutes, until you see an Easter egg! You should
    see the Midori web browser open up, with a little surprise on the inside. Read the
    webpage that appears and then hover your mouse over it to see the secret message.
    Funny!


By the Way: What Is an Easter Egg?
An Easter egg is a secret message or hidden surprise. You have to know
exactly the right commands or keystrokes to find it.


  1. Close the Midori web browser by clicking the X on the upper-right side of the
    window.

Free download pdf