Slashdot Log In
Core Python Programming
Posted by
samzenpus
on Mon Nov 06, 2006 01:54 PM
from the code-it dept.
from the code-it dept.
Ravi writes "Python, the dynamic object oriented programming language created by Guido van Rossum is known to deliver both the power and general applicability of traditional compiled languages without the complexities accompanying them. Coupled with its ease of use, programs written in Python can be run on multiple Operating systems and system architectures which gives it the same portability of any interpreted language. My first brush with Python was when I tried out a beautiful game called PySol — which is more like a collection of over 200 card games and PySol is entirely coded using the Python language. Nowadays a variety of Python web frameworks have also cropped up which promise the same kind of rapid application development that is possible using other programming languages." Read the rest of Ravi's review
| Core Python Programming - 2nd Edition | |
| author | Wesley.J.Chun |
| pages | 1050 |
| publisher | Prentice Hall |
| rating | 9 |
| reviewer | Ravi |
| ISBN | 0-13-226993-7 |
| summary | An excellent book to learn the Python programming Language |
I found the book titled "Core Python Programming" authored by Wesley.J.Chun and published by Prentice Hall to be an ideal book to learn the wonderful Python language. This book is quite voluminous, with 23 chapters spanning 1050 pages. The book is divided into two parts the first part titled Core Python which contain 14 chapters which impart a sound understanding of the semantics of the language and the second part titled "Advanced Topics" which contain a collection of 9 chapters which give a good introduction to the specialized uses such as in database programming, network programming, using threads in python, GUI programming and so on.
In the first chapter of the book, the readers get to know the various features of Python and the steps needed to install Python on ones machine. When you install Python on your machine, it also provides its own shell where you can execute pieces of python code. The author has taken advantage of this functionality of Python in narrating the concepts throughout the book. Each concept and syntax is followed by bits of code which the readers can try out in the Python shell in its entity. I found this process much easier in learning this language as one need not go through the write — compile — execute cycle which is more prevalent in the traditional languages.
In depth coverage has been provided for important concepts such as lists, tuples and dictionaries as well as data-types and string sequences and they have been provided separate chapters of their own. The sixth chapter titled "Sequences: Strings, Lists and Tuples" is the second largest in the book and is quite detailed in its coverage of the topic.
Chapter 9 deals with file manipulations where the author introduces all the built in functions available in Python which allow one to open, read from and write to a file. Interestingly, the functions are also illustrated by aid of short easy to understand examples. A couple of modules related to file handling are also introduced in this chapter.
Errors and exceptions form the basis of the 10th chapter where different errors and exceptions supported in Python are explained. This chapter also explains how programmers can create custom exception classes which I found quite informative.
One of the biggest advantages of Python is that all its functionality is split up into modules. A module could be just a single python file which contain a collection of functions or classes which can be re-used in programs written in Python. And all one has to do is import the module into ones programs to start using those pieces of code. The chapter 12 titled Modules give a firm understanding of this concept and also introduces different ways in which you can import external pieces of code into the Python program.
Chapter 13 titled "Object Oriented Programming" is by far the largest chapter in this book and spans over 100 pages. In this chapter, the author endeavors to give a sound base to Object oriented concepts as well as how they relate to programming in Python. The author introduces a large number of Python classes, methods and descriptors in this chapter.
Regular expressions play a very important part in programming verily because manipulating text/data is a necessity. And it is possible to easily modify and mould data to ones choosing by way of regular expressions. Python has strong support for regular expressions. The second part titled "Advanced concepts" of the book starts with a chapter on regular expressions. In this chapter, one gets to know about the regular expression module and many functions associated with the module. The author also provides a couple of examples which give insights into the ways in which regular expressions can be used in Python to reformat data.
The next two chapters give an introduction to the world of sockets and how Python can be used to write client server programs.
Multithreaded programming forms the basis of the 18th chapter. Here the author introduces a couple of modules available in Python which make it quite easy to create threads in ones Python program.
I found the chapter titled "Web Programming" very interesting to read. Especially since Python is used in a large way to create dynamic websites. And the next chapter titled "Database programming" gives a sound introduction to the Python objects which allow one to easily connect to and retrieve data from the databases.
I found this book really informative, especially suited for upcoming Python programmers. At the end of each chapter, there is an exercise section which imparts a nice touch to this book as it allows you to test your knowledge. Even though the advanced topics (second part of the book) are not covered in depth, the author succeeds in providing enough knowledge about the relevant Python modules and functions followed by a couple of examples which whets ones appetite without overwhelming the reader. This is the second edition of the book and it has been significantly revamped to include new features introduced in Python 2.5.
The author Wesley J. Chun has been a former employee at Yahoo and has played a major role in creating Yahoo Mail and Yahoo People Search using Python. He has over 20 years of experience in the IT field with over a decade of experience programming in Python.
Ravi Kumar likes all things related to open source and free software and enjoys sharing his experiences and thoughts through his blog All about Linux.
You can purchase Core Python Programming - 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
On the cheap side ... (Score:5, Informative)
(http://www.crackrabbit.com/ | Last Journal: Monday November 18 2002, @09:30AM)
One might try out Alan Gald's fine Learning to Program [freenetpages.co.uk] site. Short on pretty. Long on usefulness.
Oh, and all the thick books in the world will never help a budding python coder more than the tutor mailing list [python.org].
Re:On the cheap side ... (Score:4, Informative)
(http://lpetr.org/ | Last Journal: Wednesday February 07 2007, @11:04AM)
For younger children... (Score:4, Informative)
(http://gathman.org/ | Last Journal: Friday January 20 2006, @01:41PM)
An interactive (has an immediate mode prompt) language like Python is very helpful for first learning. BASIC used to fill that role, but I like starting with structured concepts. Kids have no problem "getting" that indentation marks blocks.
Some experts hate python because while the grammar is "context free", the lexing isn't. The grammar is defined in terms of INDENT and OUTDENT taking the place of '{' and '}' (or BEGIN and END). However, whether a given indent is an INDENT or OUTDENT depends on context. So you can't use a traditional lexical analyzer when programmatically generating/modifying python code. You have to translate leading whitespace to INDENT and OUTDENT based on lexical context when parsing, and translate INDENT and OUTDENT to the appropriate amount of leading whitespace when pasting code blocks.
Personally, I don't find that this is a problem. Sure 'lex' doesn't work out of the box, but the custom lexing code is pretty trivial. And the indentation sure is intuitive. Maybe that means I'm not an expert.
Python is easy to learn (Score:1)
python.org (Score:2)
(http://www.trailofjames.com/)
Got and Older Edition (Score:2)
(http://dstupid.com/geeklog/public_html/index.php)
Nice book report (Score:2)
It's no wonder I skip straight to the comments -- these reviews are just about the most content-free section of slashdot.
My favorite Python joke (Score:2)
(http://www.televisio...com/show.cgi?show=44)
A: That joke's not funny.
portable gui (Score:3, Interesting)
(http://www.halley.cc/ed/)
After a year of fiddling with Python, I find I quite like it for some things, and it's not the right fit for other things. That's fine, there's no reason to be rabid pro- or rabid con- about any language.
I happen to use Linux, OSX and Windows, and the number one annoyance for me is a lack of clear "native-looking" GUI or OpenGL toolkit offering that is reachable by scripting languages like Perl and Python.
I'd like to see PyGame in a MacPort. The Images module was pretty easy to build but it should be in MacPorts too. I don't want to rely on X11 when on a Mac, but to use X11 when on Linux, which seems to be like bringing antimatter and matter together in the same universe. A GladeXML-like module that relies only on Aqua would be great.
Similarly on Windows, you're relegated to some fugly Tk choice if you want portable GUI. I can't think of a toolkit that looks less native than Tk, unless you count the early Java Swing "Metal" theme.
The fact that OSX still isn't standardized on python2.4 makes it hard to support python-rich applications like Blender, and we still run into problems where a 2.3 parser can't let scripts use 2.4 features (even smart scripts that try:except: to fall back gracefully). I think Leopard will be python2.4 but don't recall seeing official confirmation on that.
I'm sure I've misstated something technically-- I don't have my notes from home to double-check a few things from my last gui toolkit search a couple weeks ago.
Re:portable gui (Score:4, Informative)
(http://slashdot.org/)
Re:portable gui (Score:4, Informative)
(http://david.acz.org/)
wxPython [wxpython.org] is native on X11, Windows and Mac OS X.
I used PyOpenGL [sourceforge.net] a few years ago and it was a very pleasant experience. It was easy to translate C examples to Python, without all the annoyances of using C. Obviously you wouldn't want to write a full game engine using Python, but it is nice for experimenting with OpenGL.
Re:portable gui (Score:4, Informative)
(http://www.defectivebydesign.org/)
QT [trolltech.com] with python bindings PyQt [riverbankcomputing.co.uk] will give you native looking GUI on all three platforms you are interested i.e windows, linux and OSX. Now QT4 is available as GPL even on windows, so its truly "free". QT also comes with QT-designer which IMHO is the best rapid GUI designer app.
BN is overpriced (Score:3, Informative)
(http://david.acz.org/)
Amazon.com [amazon.com] $32.99
Overstock.com [overstock.com] $31.34
Half.com [ebay.com] $28.95
use the O'Reilly Pocket Reference first (Score:2)
Python Tutorial (Score:1)
Chapter 13?!?!? (Score:2)
(http://www.proteus-tech.com)
System requirements for Python web dev seem high (Score:2)
Popular frameworks like TurboGears, or Django, also require mod_python 3.x and apache 2.x.
No problem if you are developing internally, but if you want a hosted solution, I'm not sure if python is practical.
WTH?! (Score:1, Troll)
(http://foo-projects.org/)
"Python, the dynamic object oriented programming language created by Guido van Rossum is known to deliver both the power and general applicability of traditional compiled languages without the complexities accompanying them."
Sounds like a typical spamvertisement really!
"Coupled with its ease of use"
umm hell, python is notoriously known for bad coders, writing broken applications based on underdeveloped and unmature modules, breaking forward compatibility.
Sadly enough, in the last two years, I have not seen any progress making python-based applications more stable. Programs like BitTorrent(!) have serious issues running on python-2.5(!)
"programs written in Python can be run on multiple Operating systems and system architectures which gives it the same portability of any interpreted language."
nothing new here, move along...
"My first brush with Python was when I tried out a beautiful game called PySol"
FOR CRYING OUT LOUD!!! Pysol is the ultimate proof that python programs are incredibly impossible to maintain forward because the library/module layer is so incredibly unmature. Pysol is no longer developed ! It doesn't even work with Python-2.4 !!! Even if the original developer stopped working on it, somebody should have been able to pick it up and maintain it easily, and the fact that this didn't happen is proof again that python is barring its own progress. See http://www.pysol.org/ [pysol.org] - last release was in 2003.
Python has wasted my time as a packager/distro developer many many times, and ruined quite some weekends for me.
The world would be a better place without Python.
Verily? (Score:2)
Bloat, bloat, bloat... (Score:2)
(http://www.natetech.com/)
Yawn.
Send the author back when they can get the size down to something the size of K & R while maintaining the same level of usefulness.
Python not easy to use due to reference counting. (Score:2)
Yahoo mail..... (Score:2)
(http://slashdot.org/ | Last Journal: Tuesday January 22 2002, @05:54AM)
- The search function never works as intended (I want to look for messages only in one folder, damnit!).
So assuming this guy is very clever, Python must be broken or too dificult to use.
Re:Python is SLOW (Score:3, Insightful)
In this case, would you really care about execution speed? I'll just go for the ease of string/files/array/hashes manipulation, write a powerful script in 10 minutes and go drink a coffee while my script works for me and you're still struggling with your char str[80];.
Re:Python is SLOW (Score:1)
Re:Python sucks (Score:3, Interesting)
(http://philgross.com/)
Regarding the indentation-as-syntax, consider the following C code, where someone tried to add the baz() function to a loop:
while (foo())
bar();
baz();
This code has an obvious bug. Baz() is not in the loop body, because the braces are missing. It's obvious from the indentation that that was the coder's intention. Why does one need an orthogonal and error-prone syntax for marking basic blocks, when the formatting already makes the intention obvious?
Or, consider this example from the paper Algorithm Education in Python [uci.edu]:
Here is the Insertion Sort algorithm exactly as presented in Cormen, Leiserson, Rivest, and Stein's "Introduction to Algorithms":
Insertion-Sort(A)
for j <- 2 to length[A]
do key <- A[j]
i <- j - 1
while i > 0 and A[i] > key
do A[i+1] <- A[i]
i <- i - 1
A[i + 1] <- key
Here is the same algorithm, implemented in Python:
def InsertionSort(A):
for j in range(1, len(A)):
key = A[j]
i = j - 1
while (i >=0) and (A[i] > key):
A[i+1] = A[i]
i = i - 1
A[i+1] = key
I haven't left anything out. Paste that into a Python interpreter and run it:
>>> x = [2,7,3,8,1] # create test case
>>> InsertionSort(x) # call routine
>>> x # look at result
[1, 2, 3, 7, 8]
There are about a thousand other cool things, and of course there are inevitably some warts and poor design decisions too. Bottom-line for me, at least, it's the power of Perl, but at the extreme other end of the spectrum in terms of readability. The Google folks think so too.
Re:Python is SLOW (Score:2)
Meanwhile, I can whip up apps in Python in no time and they run far faster and with less nonsense and hassle. Slower than C? Yes. Better for rapid prototyping and quick problem solving on the fly? Yes. Best language I know to bridge structured and object oriented paradigms? Yes.
If I haven't already bought this book, and I may have and just not remember given the stacks of them on my various desks, I will then do so and give a copy to my godson who is just learning about computers. The archaic school system might still be teaching LOGO and I want him to see something that he can actually use.
Re:Python is SLOW (Score:5, Interesting)
(http://www.gnulinux.net/)
Also, keep in mind Python does not use a virtual machine at all in the same way Java does -- which means it is somewhat like comparing apples to oranges.
I was a full time J2EE engineer for a while and a recent convert to Python for general programming. The things I noticed are:
- Java is great for large teams of programmers working together across the globe but as good as Python for smaller groups in the same place.
- Python's web frameworks are amazingly fast and very powerful.
- Java is almost text book perfect when it comes to programming. Unlike most other languages kids can come out of university and not have to change hardly anything to get started in the real world of Java.
- It's very rare to see stock Tomcats or even stock JVM's meaning that most (commercial) Java apps send the entire 'Java OS' (VM) with their products.
- Java web apps are very slow on startup, but scale well after the startup time.
- Python has a better RORA system, though Java isn't to far behind.
- Java terminology is very confusing compared to Pythons esp. since it is generally termed by marketers (Java2 is Java1.4 and then we hit Java 5 which is Java1.5
Here is how it seems companies leverage the languages
1. Java
Manager's reason for Java: "I have a large IT infrastructure and want to do enterprise applications with teams across the globe."
Engineer Translation for Java: "I have an over all large group of engineers and want to make an application designed by the business with at least some of the team out sourced."
2. Python
Manager's reason for Python: "I have a small IT budget and want to agile and business reactive application development."
Engineer Translation for Python "I don't have a budget to get more engineers and the requirements state that we need to be able to change and update the application on the business whim."
In scenario number 1 it is a growing company who wants to hire lots of new engineers so the plus side of using Java is:
1. Just about every engineer (good or bad) knows it
2. It enforces C++ like development cycles
3. If done right, the objects are reusable and simple for an architect to understand
4. You can hire fresh outs
In scenario number 2 it's a growing company who is not investing more money in the IT department but expects better results for the buck put into it. The plus side of Python would be:
1. It's a RAAG language (read at a glance) which means you can skim through the code quite quickly without needing tracers or debuggers.
2. By design each engineer is a mini architect
3. If done right, the objects are reusable and simple for engineers to grasp quickly
4. The quality of engineers you get tend to be quite high since most Python engineers are converts from other languages with X years of experience in the field. (though it also means you can't hire as quickly).
Bottom line there is no right or wrong answer as to which is better or faster. Python is faster in some cases and Java is faster in others and it largely depends on how you run your business and the money that you want to spend in IT as to which one would help your company.
Re:Python is SLOW (Score:2, Informative)
(http://slashdot.org/)
...and it need not be said.
Between Pyrex [canterbury.ac.nz] and Psyco [sourceforge.net], there's really very, very few applications that a language like Python isn't appropriate for. Premature optimization is the far more common programmer sin these days than choosing a language that's "too slow." Except for a few, specific application domains (that only a minority of coders are writing) dynamic languages like python are an excellent choice on today's hardware. And if you need it to be faster, just profile, find the couple of spots that matter, and pull out Pyrex.. or even the C/Python API if it makes you feel manlier. :-)
Plus, with things like PyPy [codespeak.net] + LLVM, Parrot [parrotcode.org], and IronPython [ironpython.com] emerging, things are only going to get better.. don't be the last one on the dynamic boat!
Re:Python is SLOW (Score:1)
Ruby is easily, measurably, slower than Python - its a big topic of discussion in the Ruby community and the subject of numerous projects to address.
Re:Python is SLOW (Score:5, Informative)
Really? hmmm, my team runs a huge data warehouse in which all data is transformed via python programs. This means 40+ million rows a day get hash table lookups, business rule validations, type changes and various transformations.
Then most of that data goes through an additional metadata-driven validation process that checks and confirms every single field. Again, metadata-driven - so a oouple hundred lines of various hash table lookups to determine exactly what validation applied to each field.
Ok, now let's talk performance:
1. io performance (most critical factor here)
a. same as c, in other words, extremely fast
2. cpu performance
a. much slower than c, but workable
b. psycho helps a ton
c. the ability to rewrite key functions and classes is cool
Let's also talk about productivity
1. great for ease in training part-time or junior programmers
2. great for immediately understanding old code
3. great for writing robust test-driven code
4. good for very quickly assembling a solution
The above combo of ease of writing, ease of maintaining puts it far ahead of perl, tcl and java. Ruby is really the one other one in this niche I can think of off the top of my head. And even there Python appears stronger on the maintenance side.
So, yeah - I'm sure there are many applications that have more significant performance requirements than ours does. But for this large application it is completely fine.
Re:Python is SLOW (Score:2, Insightful)
(http://www.treewalker.org/)
The key to getting good performance out of Python is to know and use the libraries well. Most of the performance sensitive library calls are implemented in C and have been optimized. As long as you use those instead of reinventing the wheel, you will get pretty decent performance from Python. Python's standard library is very complete ("batteries included"), for example it includes a unit testing framework and a profiler.
Additionally, by being able to implement things in a small amount of code, you'll get a better overview of what your program is doing. This means it is easier to spot where the performance bottlenecks are. If your program is so complex that you don't realize you're using an O(N*N) algorithm where O(N*ln(N)) is also possible, no fast compiler will be able to compensate for that unless your data sets are really small.
Ruby is SLOWER (Score:3, Funny)
(http://slashdot.org/)
Re:Python (Score:3, Interesting)
(http://robots.org.uk/)
<pre>print '%(imperative)s, a %(adjective)s %(noun)s!' % {'imperative': 'Look!', 'adjective': 'built-in', 'noun': 'templating system'}</pre>
Re:Python is SLOW (Score:2)
That simple stupidity just made everyone who knows anything about Ruby and Python dismiss your post as utter nutjobbery.
Java is indeed faster than Python by a large margin (unless the runtimes are short, in which case the sheer monstruosity of the JVM's startup time kills Java's perfs).
TCL compares very favourably to Python, even though it's mostly slightly slower, unless you're using Regexp (the Tcl regex engine is just wicked fast).
But Ruby on the other hand, is one of the slowest languages available today. The current baseline implementation is a piece of crap, it's wasteful, it doesn't have any optimization, it's more or less the slowest and worst way to implement an interpreted language. Even though Ruby is a quite nice language, speed is definitely not it's forte.
The only way for Python to be slower than Ruby would be to code Ruby in Ruby while you're coding Java in Python (using Java idioms and techniques while producing Python code, which is a bad idea).
Re:Python is SLOW (Score:1)
(http://example.com/ | Last Journal: Tuesday November 14 2006, @11:20AM)
This is why there is so much interest in a Python compilier--compiliers are much faster than interpeters. There are some starting projects--such as psycho and Python 2 C Module Generator [sourceforge.net]
Java and TCL have certainly had many more years and manpower to optimize thier implementations. I don't know much about Ruby. I'm sure in a few years, Python will improve too.
Re:Python is SLOW (Score:1)
Re:Python is SLOW (Score:2, Interesting)
(http://noam.chigh.org/)
Matplot is slow (Score:2)