Personal tools
You are here: Home 内部学习 The Definitive Guide to Plone Chapter 1: Introducing Plone What Is Python?
Document Actions

Chapter 1: Introducing Plone

Overview A company without a Web site is unthinkable—and most companies and organizations have more than one site.

What Is Python?

Zope is written in Python, a powerful object-oriented, open-source programming language comparable to Perl or Tcl. Knowledge of Python isn't required to use Plone or even to do some basic administration; however, customizing products and scripting Plone does require some Python.

Tommy Burnette, a senior technical director at Industrial Light & Magic, says this about Python (http://www.python.org/Quotes.html):

Note 

Python plays a key role in our production pipeline. Without it a project the size of Star Wars: Episode II would have been very difficult to pull off. From crowd rendering to batch processing to compositing, Python binds all things together.

If you plan to do anything sophisticated with Plone, take a day or two to learn the basics of Python. Not only will this allow you to customize Plone substantially, but it'll also familiarize you with objects and how they interact in the Plone environment. Teaching you Python is outside the scope of this book; instead, I assume you have a basic knowledge of Python. That fundamental knowledge of Python will be enough to get you through this book and allow you to customize the Plone installation easily.

Fortunately, Python is an easy programming language to learn; on average, it takes an experienced programmer a day to become productive in it. New programmers take a little longer. If you're installing Plone using the Windows or Mac installers, then the correct version of Python will be included. To download Python as separate product, for almost any operating system, go to http://www.python.org.

The best way to master Python is to try it from the command Python interpreter. If you have a Windows installation of Plone, there's a link for the PythonWin, a Python Integrated Development Environment (IDE) already in the Start menu; go to Start ® Programs ® Plone ® PythonWin (see Figure 1-2).

Click To expand
Figure 1-2: The Python prompt on Windows

On Linux and Mac OS X, usually typing python will start the Python interpreter:

$ python
Pyython 2.3.2 (#1, Oct  6 2003, 10:07:16)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Since Python is an interpreted language, instead of the whole Python script being compiled and run, you can just send lines of code to the interpreter as you write them. This makes the interpreter an amazingly useful place for testing and debugging code. In the interpreter, each line waiting for input is prefixed with >>>.

For example, the simplest "Hello, World" program is as follows:

>>> print "Hello, world!"
Hello, world!
>>>

To exit the interpreter, press Ctrl+D (press the D key while holding down Ctrl) on Linux or press Ctrl+Z on Windows. (You'll also use this later for more advanced Zope and Plone interaction.) You can execute normal Python scripts by passing them to the interpreter; for example, given the following script called hello.py:

print "Hello, world!"

you can run this using the following command:

$ python hello.py
Hello, world!

The Python Web site at http://www.python.org has excellent documentation, especially the tutorial. Also, the following books provide a good overview of Python:

  • Dive Into Python (Apress, 2004): Based on Mark Pilgrim's popular Web-based tutorial, this books treats readers to a fast-paced introduction to the Python language. This is a great book geared toward experienced programmers.

  • Learning Python, Second Edition (O'Reilly, 2003): This book covers version 2.3 of Python and provides a good overview of Python and all the new features. This is good for relatively new programmers.

  • Practical Python (Apress, 2002): This highly practical introduction to Python offers insight into the language's array of features. The reader can immediately put this knowledge into practice, following along with the creation of ten interesting projects, including a Web-based bulletin board and a Graphical User Interface–based file-sharing application.

  • Python Essential Reference, Second Edition (Sams, 2001): A reference book that provides a great overview of all the key libraries and functions. This is an excellent book for experienced programmers.