Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

14.9. Exercises

14-1. Callable Objects. Name Python's callable objects.

14-2. exec vs. eval(). What is the difference between the exec statement and the eval() built-in function?

14-3. input vs. raw.input(). What is the difference between the built-in functions input() and raw_input()?

14-4. Execution Environment. Create a Python script that runs other Python scripts.

14-5. os.system(). Choose a familiar system command that performs a task without requiring input and either outputs to the screen or does not output at all. Use the os.system() call to run that program.

14-6. commands.getoutput(). Solve the previous problem using commands.getoutput().

14-7. popen().Family. Choose another familiar system command that takes text from standard input and manipulates or otherwise outputs the data. Use os.popen() to communicate with this program. Where does the output go? Try using popen2.popen2() instead.

14-8. Restricted Execution. Create a restricted environment and display the contents of your __builtins__ module to prove it.

14-9. Exit Function. Design a function to be called when your program exits. Install it as sys.exitfunc(), run your program and show that your exit function was indeed called.

14-10. Shells. Create a shell (operating system interface) program: Present a command-line interface which accepts operating system commands for execution.

EXTRA CREDIT 1: support pipes (see the dup(), dup2(), and pipe() functions in the os module). This piping procedure allows the standard output of one process to be connected to the standard input of another.

EXTRA CREDIT 2: Support inverse pipes using parentheses, giving your shell a functional programming-like interface.


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint