Before reading further... Are you looking for great Linux hosting from a company that cares about GNU/Linux? Pick Dreamhost hosting, get a 10% bonus to the disk space (and support Free Software Magazine in the meantime!)
Introduction to Zope
Part 1: Python
Download the whole article as PDF
- 2005-12-16
- Server side | Intermediate
-
Write a full post in response to this!
Zope is a web application server, similar in concept to proprietary products like Cold Fusion. However, it is free software that is available under the GPL-compatible Zope Public License, which is very similar to the BSD License. Zope was designed with the specific goals of creating a powerful, secure framework for the development of robust web-based services with a minimum of effort.
However, Zope’s biggest distinguishing characteristic is how closely it models the language it is written in: Python. In fact, many of its features are directly derived from its underlying Python structure. Because of that, it’s difficult to truly understand or appreciate Zope without having a basic knowledge of Python. This article, the first in a two part series, is intended as a high-level introduction to the language. Next month’s instalment will build upon this by demonstrating practical examples of Zope code.
Zope’s biggest distinguishing characteristic is how closely it models the language it is written in: Python
Language features
Although Python has been in use since the early 1990’s, it’s only become relatively popular in the last few years. Many programmers view it as the spiritual successor to Perl. That is, it’s an expressive, interpreted language that’s equally at home in small system scripts or much larger applications. However, it has the deserved reputation of usually being easier to read and maintain than the equivalent Perl code. Python also sports an excellent object oriented approach that’s much cleaner and more integral to the overall design than is Perl’s. Perhaps most important, though, is a belief by the core development team in doing things the right way. It was designed from the beginning with an emphasis on practical elegance—Python strives to allow programmers to easily express their ideas in intuitive ways.
It was designed from the beginning with an emphasis on practical elegance—Python strives to allow programmers to easily express their ideas in intuitive ways
Significant whitespace
The first thing that everyone notices about Python is its use of significant whitespace. Rather than marking blocks of code with keywords such as “begin” and “end”, or curly brackets a la C, Python sets them apart with indentation. Frankly, a lot of programmers hate the idea when they first see it. If you’re one of them, don’t be discouraged; the feeling passes quickly. It enforces the style guidelines that most good programmers would be following anyway, and soon becomes quite natural. Python is flexible regarding the use of spaces versus tabs, as long as you consistently use the same kind and amount of whitespace to indent. Furthermore, almost all programming editors have Python modes that handle the details for you.
The standard comparison of formatting between C and Python is the “factorial” function. In C, that could be written as:
int factorial(int i) {
if(i == 1) {
return 1;
}
else {
return i * factorial(i - 1);
}
}
(or in one of many other common styles). A Python programmer would probably write something extremely similar to:
def factorial(i):
if i == 1:
return i
else:
return i * factorial(i - 1)
Except for the missing curly brackets, the formatting is almost identical between the two.
Interactive development
Python includes an interactive shell where you can experiment and test new code. Running the python command without any arguments will result in something like:
Python 2.3.5 (#1, Apr 27 2005, 08:55:40) >>>
At this point, you can enter Python commands directly to see their effect. If you’re working on a large project, you can load specific parts of it for manual testing without affecting other modules. It’s equally handy for verifying that short functions will work as expected before embedding them into a larger body of code. It’s difficult to convey exactly how convenient this is, and how efficient the code-experiment-code cycle can be.
Finally, the interactive prompt is an excellent place to explore objects, and the data and functions inside them. Typing dir(someobject) will return the list of objects referenced by someobject, and most of the functions in Python’s core libraries contain a doc attribute with usage information:
>>> dir(str) [lots of stuff, ..., 'translate', 'upper', 'zfill'] >>> print str.upper.__doc__ S.upper() -> string Return a copy of the string S converted to uppercase.
Tiny core language
Python 2.3.5, the version recommended for use with the latest production release of Zope, has just 29 reserved words. Perl has quite a few more: 206 as of version 5.6.8. PHP tips the scales with up to an incredible 3972 commands and functions in the base language (although many can be added and removed at compilation time). The practical upshot is that any experienced programmer should be able to memorize the entire language in an evening. This simplicity does not reflect a lack of power though. Although most of the familiar commands are similar to their counterparts in other languages, several are significantly more flexible. The for command, as an example, will cheerfully iterate across a set of numbers, a list of strings, or the keys of a dictionary object.
Any experienced programmer should be able to memorize the entire language in an evening
Python keywords
The whole language is built upon a short list of words: and, del, for, is, raise, assert, elif, from, lambda, return, break, else, global, not, try, class, except, if, or, while, continue, exec, import, pass, yield, def, finally, in, and print. If you’ve ever written a program, you probably already have an accurate idea of what most of them do.
Strong dynamic typing
Python is dynamically typed, which means that it executes its type checks during program execution (as opposed to C). It is also strongly typed, meaning that it won’t convert data from one type to another unless you explicitly ask it to (as opposed to Perl). The language makes great use of this flexibility by passing parameters to functions as reference instead of by value. The net effect is that you can pass almost any object to a function, and if the operations in the function make sense for that type of object, then the function will work as expected. For example, the following code defines a function that will add any two compatible values together:
Write a full post in response to this!
Similar articles
Do you like this post?
Vote for it!
Copyright information
This article is made available under the "Attribution-Sharealike" Creative Commons License 3.0 available from http://creativecommons.org/licenses/by-sa/3.0/.
Biography
Kirk Strauser: Kirk Strauser has a BSc in Computer Science from Missouri State University. He works as a network application developer for The Day Companies, and runs a small consulting firm that specializes in network monitoring and email filtering for a wide array of clients. He has released several programs under free software licenses, and is active on several free software support mailing lists and community websites.
- Login or register to post comments
- 12907 reads
- Printer friendly version (unavailable!)




Looking for Linux hosting, reviews, coupons, etc.? See out user-voted list
Best voted contents
-
Is Microsoft trying to kill Apache?
Gary Richmond, 2008-08-08 -
How do Drigg and Pligg compare?
Tony Mobily, 2008-08-17 -
The top 4 internet flame wars about free software
Andrew Min, 2008-08-16 -
Creating wealth with free software
Richard Rothwell, 2008-08-05
Similar entries
Buzz authors
All news
Other sites
- The Top 10 Everything (Dave). The good, the bad and the ugly.
- Free Software news (Dave & Bridget). All about free software -- free as in freedom!
- Book Reviews: Illiterarty (Bridget). Book reviews, blogs, and short stories.
Hot topics - last 60 days
-
Don't compare GNU/Linux with Windows or MacOS - they are not in the same game
Ryan Cartwright, 2008-07-07 -
Self-signed certificates and Firefox 3 - a possible solution
Ryan Cartwright, 2008-08-05 -
Dictators in free and open source software
Tony Mobily, 2008-07-22 -
Why sharing matters more than marketshare to GNU/Linux
Terry Hancock, 2008-08-01 -
Why did Javascript/AJAX mop the floor with Java, Flash and Silverlight? Or, why open standards eventually win
Tony Mobily, 2008-07-30
Hot topics - last 21 days
-
How do Drigg and Pligg compare?
Tony Mobily, 2008-08-17 -
The Bizarre Cathedral - 18
Ryan Cartwright, 2008-08-17 -
Is Microsoft trying to kill Apache?
Gary Richmond, 2008-08-08 -
An open letter to Barack Obama and the DNC (or, change video formats)
Anthony Taylor, 2008-08-27
Dedicated server
Comments from the old system
Submitted by admin on Thu, 2006-03-30 13:08.
Vote!From: gumnos
Url:
Date: 2005-12-17
Subject: Nice intro to Python, but lacking about Zope
While the article was a nice breeze-by of Python, I kept reading in the hope that it would follow up on the title of an "introduction to Zope"...however, the article never returned to talking about Zope. Ah well.
From: PaulC
Url:
Date: 2005-12-18
Subject: reply
he did mention that to grok Zope you have to understand python... just wait... things will get much clearer... but first, you have to grok Python... ;)
What I love about Python, is that it's a very short jump from getting your thoughts about a program down in pseudocode to actually fleshing in the Python program itself.
From: Kirk Strauser (SUBSCRIBER!)
Url:
Date: 2006-01-01
Subject: That comes next month (or so)
I really wanted to work a little about Zope into the article, but I just didn't have the room. I decided to dedicate this part into an overview of Python since Zope very closely parallels the language.
Keep checking back for the next installment. It should be more along the lines of what you're asking for.
From: Mike Meyer
Url: http://www.mired.org/home/mwm/try_python/
Date: 2005-12-31
Subject: Trying out interactive python
If Python sounds interesting, but you don't want to install it, there
are a couple of "Try Python" websites that let you play with a Python
interpeter with just a web browser.
Mine is at http://www.mired.org/home/mwm/try_python/. It provides
links to others as well.
From: Kirk Strauser (SUBSCRIBER!)
Url:
Date: 2006-01-01
Subject: Excellent resource!
You're a braver man than I to allow people to run code on your server, but you seem to have dodged the most obvious bullets (infinite loops, etc).
I'll be sure to point your site out to people who want to have a quick peek at the language. Thanks!