Journal Articles
Browse in : |
All
> Journals
> CVu
> 144
(17)
|
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: ACCU UK Python Users Group
Author: Administrator
Date: 03 August 2002 13:15:52 +01:00 or Sat, 03 August 2002 13:15:52 +01:00
Summary:
The sound of one coconut shell clopping
Body:
Welcome to the Python section of C Vu.
Python is a relatively new programming language that has been gathering momentum and popularity in recent years. This section of the magazine, like the ACCU-SIG "PyUK" (the Python UK Users Group) that its authors spring from, is dedicated to spreading the word, or at least trying to point out the benefits of a surprisingly elegant, simple and powerful language that has long outgrown its "scripting only" designation.
Python is used in such diverse places as NASA, Industrial Light and Magic (the Star Wars special effects people), Disney, Yahoo, Google, Thwate, RealNetworks and even IBM. It can run on a huge diversity of OS/hardware platforms (32 at last count, personally I am waiting for the ZXspectrum port) and can call and be called from Java, C and C++ code.
In short, Python is a object-orientated, very high level programming language with surprisingly clear syntax, extensive built-in data structures, strong but dynamic typing and has an enormous number of modules and libraries covering some useful, abstract and occasionally strange capabilities.
Python is sometimes characterised as everyone's favourite second language, and I would encourage anyone involved in C, C++ and Java systems work to look very closely at its capabilities, especially its ability to work seamlessly with those languages. Anyway, some background to Python and a little introduction...
One Christmas, about a dozen years ago, a young man called Guido van Rossum sat down and wrote an interpreter for a new language he wanted to create as an improvement on a previous effort. This language became Python (and yes, it was named for John Cleese and friends). In keeping with Python's offbeat history and great portability, it first ran on an Apple Mac.
Python was released from the Amsterdam laboratories where Van Rossum worked in 1991, and has been growing in popularity ever since. There are now an estimated 1/2 million programmers, 40+ books on Python and innumerable articles (now plus one).
Python is open source and free.
Python has a very strong community feel, centred around the comp.lang.python newsgroup. The group is refreshingly free from flames, egos and off-topic blathering, even though you can still find posts on how to grow certain anatomical parts by 3 inches. That apart, the group is a sadly rare thing these days, a relaxed, open, collegial group that offers help, advice and support to all from greenest newbies to the most experienced. And it is done in a generally light-hearted tone. Just like the ACCU :-)
However, Python itself takes programming seriously, even if "Pythonistas" do not take themselves too seriously. No, I do not know why Python users are called Pythonistas. It's just one of those things.
Python is kept alive and changing via an open process (Python Enhancement Proposals (PEPs)) that discuss what improvements could be made. The final decision is Van Rossums', but it is a sort of Chinese parliament. Van Rossum and a core group of developers keep up an impressive stream of improvements and changes that have satisfied just about everyone, so it seems to work.
There are also many SIGs (including the UK Python Users Group - an ACCU SIG) and quite a lively conference and training scene.
To get a copy of Python please visit www.python.org/2.2.1/. This has just about everything you want. Most of us have worked through Guido's tutorial that is included.
Windows users might find the release at activestate.org more suitable (it includes some win32 extensions that make life in Windows much easier.
Automating Word and Excel has never been [so] much fun.) Amazingly the python interpreter has also been rewritten in Java. This means python code can be run under a JRE, allowing python code to call and be called from Java code. If you want to play with this try www.jython.org.
And so just to show what Python can do, (but do not hold it responsible for this programmer's failings) here is a piece of code that downloads a web page, parses it and emails that day's news headlines to the author in less than a dozen lines of code.
import urllib, smtplib #Pythons vast library store is mostly text files of code added onto a path. headlines, en, y = [], 0 , len('<B class="h1">') #setup a list to store headlines, and a couple of useful bits htmlFile = urllib.urlopen('http://news.bbc.co.uk').read() #visit the BBC site and get the html as a single string while 1: #an infinite loop (break condition lower down) st = htmlFile.find('<B class="h1">',en) #find beginning of each headline en = htmlFile.find('</B>', st) #find end of each headline if st == -1: break #if no more headlines stop headlines.append( htmlFile[st + y:en] ) #slice up the html string at the start and end of the headline, s = smtplib.SMTP('post.myServer.co.uk') #open up a connection to smtp server s.sendmail('Python@myServer.co.uk', #send the message (From, to and body, using string formatting) 'pbrian@myServer.co.uk', 'Subject:Daily News\r\n\r\nThe headlines are:\n %s \n %s \n %s' % (headlines[0],headlines[1],headlines[2]) ) s.quit()
The first thing you probably notice is the lack of braces or brackets. Whitespace and indentation are actually part of the syntax in Python. After a while it becomes natural - honestly, try it for a few hours. Eric Raymond's comments on this follow most of our own experiences (see below).
The first line imports some helper libraries. There is a plain text file on my machine called urllib.py. I can open it and read the python code. It uses some clever socket manipulation to run HTTP to the BBC site and get me my news page. That library is part of the standard distribution. Python gets referred to as "batteries included". This is why.
Where are the type declarations? Well, Python discovers type at run-time, meaning there is strong typing (you cannot conjoin integer 12 and string "3" to get 15 (or 123), but it is dynamic, allowing less lines, less breaks in the flow. I like it.
And finally the data structures - lists are simple to set up and easy to manipulate. Dictionaries or associative arrays are just as easy (they use curly brackets not square) and they can hold anything. A dictionary containing a list of strings, dictionaries and other lists is easy. Pointless, perhaps, but easy.
Python can stretch from a 10 line throwaway to hundreds of thousands of lines of code, run on a huge variety of platforms, interact with a huge variety of other software whilst still retaining clear, readable and straight-forward code. This deserves an explanation. My best attempt is that Python takes programming seriously. This means that it is not designed for a given application domain, nor built with an eye on 30 years of backwards compatibility or the marketing needs of a multinational.
I have read that "Python gets its compromises right". I think it does too. Give it a try: you might like it :-)
Enjoy!
"Official" Distribution: http://www.python.org/2.2.1
Windows, with COM access: http://activestate.com/Products/Download/Get.plex?id=ActivePython
Tutorial: http://www.python.org/doc/current/tut/tut.html
Origins of Python: http://www.python.org/doc/essays/foreword.html
PEPs: http://www.python.org/peps/
Jython - using Python and Java: http://www.jython.org/
SWIG - using C, C++ and Python: http://www.swig.org/
Introductory Articles: http://www.python.org/doc/Intros.html
Interesting comments from Eric S Raymond: http://www.linuxjournal.com/article.php?sid=3882, http://europython.zope.nl/interviews/entries/eric_raymond
Comparisons to other languages: http://www.ipd.uka.de/~prechelt/Biblio/jccpprtTR.pdf, http://home.pacbell.net/ouster/scripting.html
Number of programmers: http://www.activestate.com/Corporate/Communications/Releases/Press957675912.html
Who else uses Python: http://www.python.org/psa/Users.html
Notes:
More fields may be available via dynamicdata ..