Python
This probably only works on Intel-based OS X machines:
>>> import ctypes
>>> print ctypes.c_char_p(
-16 * 4096 + 0x1600
).value
Your karma check for today:
There once was...
Wow, I've had a really busy month. I've attended (and spoken at) BarCamp London, Media in Transition, d.Construct, RailsConf Europe, Euro Foo and EuroOSCON. All were excellent, and each one nicely com...
I recently had the opportunity to put together the Python Developer Center for the Yahoo! Developer Network. YDN is one of my favourite parts of Yahoo! so I jumped at the chance, and the resulting min...
Python 2.5 alpha 1 is out, and as usual the What's New in Python 2.5 document provides a pleasant overview of the new features. There are some real treats in there. While I'm hoping that the syntax fo...
The amount of activity surrounding the Django web framework since its not-quite release a few weeks ago is amazing. Adrian, Jacob and Wilson have been working over-time, with 395 check-ins to source c...
You may know that I spent a year working in Kansas for a local newspaper - the Lawrence Journal-World. I'm delighted to announce that a decent chunk of the software I worked on there is now available ...
I'm back from my two week stint in the US, and currently suffering from vicious jet-lag (my body wants me to go to sleep at 5am and wake up just past noon). Herewith some observations on PyCon, SxSW a...
Python Is Not Java by Phillip J. Eby (via Ned) is the most useful article on programming I've read in ages. If you have any interest at all in either language, go and read it. It's all good, but the p...
I've written about pydoc before. In my opinion it's one of Python's best kept secrets: a way of instantly browsing the properties, methods and documentation strings of any module available to the Pyth...
A.M. Kuchling's "What's New in Python X" documents are always a treat, and his guide to the forthcoming Python 2.4 is no exception. Among other things, 2.4 elevates sets to built in type status, drama...
Just over a year ago, I started blacklisting domain names from links featured in comment spam. My idea then was that these blacklists could become a shared resource: people would publish their own bla...
I was thinking today about the problem of querying an existing authentication database from a new application - exactly the kind of thing web services are useful for. Then I realised that any web appl...
The other day, we noticed that the .py files in our main mod_python application at work did not have corresponding compiled .pyc files. mod_python runs as the unprivileged apache user, which on our se...
We have a home-grown templating system at work, which I intend to dedicate an entry to some time in the future. We originally wrote it in Python 2.2, but upgraded to Python 2.3 a while ago and have si...
Python doesn't support a native switch statement. I've found myself using the following coding idiom instead recently which seems to work pretty well:
{'option1': function1,
'option2': function2,...
Python in the Mathematics Curriculum by Kirby Urner is something of a sprawling masterpiece. It really comes in four parts: the first is a history of computer science in education, the second an appra...
Pydoc is awesome; I don't know how I missed it for so long. Simply type the following at the command line:
pydoc -p 8888
Then point a browser at http://localhost:8888/ to browse interactive docu...
Understanding Network I/O, Part 2 by George Belotsky (via The Farm) is the best tutorial on the subject of network programming I've seen yet. It provides a detailed explanation of simple threaded netw...
The above monstrosity came up today while writing a function to add zero padded line numbers to a chunk of text:
def linenumbers(text):
"Add zero padded line numbers to text"
lines = text...
At work today we stumbled across a situation where we needed to display a list of items in reverse order. The decision to show them in reverse is made in the presentation layer, so altering the code t...
In a way I'm disappointed to see python-spidermonkey released. It's a Python wrapper around the Mozilla project's SpiderMonkey Javascript engine which allows Python scripts to execute Javascript code ...
Python Programming: An Introduction to Computer Science is a new Computer Science text book designed for use in introduction to programming classes, written by John Zelle, who's Teaching with Python p...
LUFS-Python provides a relatively simple API for implementing new Linux filesystems in pure Python. You install the package, write a class implementing methods for handling filesystem operations such ...
Via Hans Nowak, Understanding Object Oriented Programming, or how to turn 19 lines of easily maintained code in to an OO monstrosity spanning 7 class files. This is not the way to make code more maint...
Via Jeremy Hylton, Mark Shuttleworth (super-rich geek and space tourist) is offering $100,000 worth of bounties in 2004 to developers willing to help out with a number of Open Source projects, most of...
Ned Batchelder recently wrote about the difficulties involved in extracting the length from an MP3 file. We're going to need to solve this problem soon at work; luckily, it seems that the answer may l...
Adrian just pointed me to a fantastic tool: Gotmail, a utility to download mail from Hotmail accounts. It's a command line utitlity, written in Perl and making use of the curl binary, which can connec...
Pyrex is a language for writing Python extension modules. It's pretty interesting - the syntax looks very similar to Python (the authors claim you can write C extension modules without knowing anythin...
I'm working on a project at the moment which involves exporting a whole bunch of data out of an existing system. The system is written in Perl and uses Berkeley DB files for most of its storage.
I'...
I've been rewriting the photo gallery management system for KUSports.com in Python. One of the new features is that the system can automagically extract caption and photographer information from the p...
Some great tips for optimising Python, courtesy of Ian Bicking:
Kata 19: an optimization anecdote demonstrates some neat techniques including use of the gc module to fine tune garbage collection...
A couple of Python tips. The first is really a tip for Mozilla/Firebird: You can set up a Custom Keyword for instantly accessing Python module documentation using the string www.python.org/doc/current...
This morning, I finally decided to install libxml2 and see what all the fuss was about, in particular with respect to XPath. What followed is best described as an enlightening experience.
XPath is ...
I've added a comment system to my new Kansas blog. Since the target audience for that site is friends and family rather than fellow web developers, I've taken a very different approach to processing t...
Python now has a Web SIG. SIGs are Special Interest Groups, each with a target to develop and improve a certain aspect of the Python language, standard library or community. The Web SIG has two purpos...
David Brown: Python is a time bomb (in a good way):
Python is a time bomb. I've yet to see someone run with it the first time they are exposed to it. We all know the drill. "Indenting for block s...
Blogged so I don't lose it (blogging as external memory):
def ordinalth(n):
""" 1 => 1st, 2 => 2nd etc """
last = n - n / 10 * 10
if last == 1:
return '%dst' % n
...
In switching from PHP to Python I'm discovering an increasing number of PHP functions that I've learnt to rely on but have no direct equivalent in the Python standard library. Often Python simply prov...
Hans Nowak has been churning out some really interesting Python stuff recently. He's been experimenting with Self style objects in Python (similar in many respects to objects in Javascript), developin...
Introducing mod_python by Gregory Trubetskoy. One of my biggest problems with mod_python is that documentation outside of the mod_python manual is pretty hard to come by. This article is more of an ex...
Sweet. Mark Pilgrim is working on Dive Into Python again, funded by a dead tree publisher for publication in 2004 (hopefully). The free version will stay available as well. I've always preferred readi...
Via Ned Batchelder, an article on Reversing Regular Expressions from Perl.com. Otherwise known as Sexeger, these offer a performance boost over normal regular expressions for certain tasks. The basic ...
I adore the Python interactive interpreter. I use it for development (it's amazing how many bugs you can skip by testing your code line by line in the interactive environment), I use it for calculatio...
Kirby Urner provides some great examples of how Python can be used as an aid to understanding mathematics on the marketing-python mailing list. I particularly liked this demonstration of Pascal's tria...
Three really useful looking Python modules: ClientForm, ClientTable and ClientCookie. ClientForm looks like it provides similar functionality to the form handling part of the WWW::Mechanize perl modul...
Techno Weenie has a detailed guide to setting up PySQLite on boxes you don't have root access to. SQLite looks ideal for small to medium sized applications so I can see this being really useful should...
My new favourite toy is SQLObject, an object-relational mapper which makes heavy use of Python's special method names to create objects which can be used to transparently access and modify data in a r...
So, I'm getting stuck in to mod_python in a pretty big way at the moment. I've never even used mod_perl before, so coming from PHP this is turning out to be a real eye opener.
The key thing to real...
10 Python pitfalls by Hans Novak (via Simon Brunning) is essential reading for anyone with more than a passing interest in Python. Python never copies implicitly. If only that were true of PHP....
In another silly Python/Windows hack, Hans Nowak shows how a simple Python script to move a file up to its parent directory can be added to the contextual menu for all Windows files. I can think of al...
Danny O'Brien compares Perl with Python. Best observation: Python code just doesn't have much personality compared to Perl....
Clearing out another several days worth of tabs. Some day I'm gonna get me a link-roll.
Zeldman's presentation on web standards, including a gallery of commercial sites designed with CSS.
mezz...
After numerous alphas and betas, Python 2.3 has been released. Python.org has highlights of the release, while A.M. Kuchling's What's New in Python 2.3 goes in to a bit more detail. There's some great...
A long, long time ago I wrote my first ever PHP templating system. It was pretty simple; it consisted of a function that took two arguments: the name of a template file, and an associative array of re...
Bruce Eckel is turning in to the world's number one Python advocate. He explains his views on Python on his Weblog in Python Answers, elaborates further on the Python productivity boost in the fourth ...
The Python-UNO bridge for Open Office 1.1 allows you to script OO using Python. At first glance, it seems to work a bit like Windows COM, which can be accessed from Python using Mark Hammond's excelle...
Rob Hudson is publishing a series of short Python tutorials explaining language features and standard modules as he teaches himself the language. Articles so far cover Sockets and making cryptograms u...
Moshe Zadka: Networking for non-programmers (and a follow up), via Hans Nowak. A nice gently introduction to sockets, with example code using Python's socket library....
Here's a nice example of a simple Python script which can be bound to the right-click menu in Windows and used to quickly upload files to a specific FTP server....
From the latest Artima interview:
One of the things I find that's remarkable about Python is that it has a very even learning curve. Maybe it's not even a curve, It's kind of a straight line. Lea...
In Jython Is Just Too Useful, Joey Gibson shows how Jython can be used to quickly demonstrate Java class libraries interactively, including using Python's dir() builtin to inspect available methods of...
Via Jarno Virtanen, a comp.lang.python post explaining the origin of the term "list comprehension", Python's clever alternative syntax for filtering lists (see this chapter of Dive Into Python). The t...
I've read several articles on Python generators now, and I had almost got my head around them, but then I read this: Iterators and Databases by Andy Todd, which demonstrates a simple but intuitive way...
Authenticating users through a third party POP3 server (Python sample code provided) is a really interesting idea, but one that I don't think could ever be used in the wild. Firstly, I haven't the sli...
Mark Lutz has announced that he is working on a second edition of Learning Python. The first edition of Learning Python is probably the best learn-programming-language-X title I have ever read. It's n...
Programming by Contract seems to be a sister technique to unit testing - instead of (or as well as) writing a set of tests for a piece of code you write a set of pre- and post-conditions for the data ...
PyMeld is a concrete implementation of something I've been thinking about for months: A template system that takes an XHTML page as a template and manipulates it based on cloning and modifying element...
In Strong Typing vs. Strong Testing, Bruce Eckel reconsiders the old idea that languages without strong typing can't be relied on to create large programs:
This became a puzzle to me: if strong sta...
Via Joe Gregorio, Functional programming in Python Part 1 and Part 2. I'm reading Structure and Interpretation of Computer Programs at the moment (available for free online, but I've got a library cop...
The Python Tutorial now includes a new appendix on the limitations of floating point arithmetic. Via Simon Brunning, who also linked to the lengthier What Every Computer Scientist Should Know About Fl...
The Python 2.2 Quick Reference, via Michael Twomey. All the essential bits of Python on a single (if quite long) HTML page. Magic....
No blogging for a while; I'm getting stuck in to a whole load of University coursework. In the meantime though here are some Python links I've been hoarding for a few days on my private wiki:
Ge...
Via Garth Kidd's Python cryptography roundup, ezPyCrypto is a cryptography API so simple even I can use it. Unfortunately the example code is only available in the download archive (not on the web sit...
Artima.com recently started hosting weblogs, with membership by invitation only. With people like Guido van Rossum and Ward Cunningham already signed up Artima looks set to become a very interesting c...
Ned Batchelder describes Verbose Python regular expressions. This is one of the things I've known about (as in known that they exist) for ages but have never got around to using. I've been working wit...
Two views on Python, from Kevin Altis and NTK respectively:
Python is an Agile programming language!
Python is like the Lament Configuration in Hellraiser: looks
like an exotic...
A post on Bryan Richard's blog about Safari leads to a query about whether or not Py (a Python print magazine) should move to PDF, which in turn leads to a fascinating discussion about the accessibili...
Like Stuart, I'm severely tempted by the UK Python conference - as a student it would cost me £85 to go for the first day, not including train fairs. That's a lot of money (considering I current...
A bunch of useful Python resources:
How to fork and return text from the child process
Driving win32 GUIs with Python, part 1
Python Coding Standards from Yahoo's eGroups system
Python Scr...
Sterling Hughes (recently blogrolled) has been working on mod_psp, a Python Server Pages module for Apache. He's up to version 0.2.1 already. Stuart once told me that the toughest problem when embeddi...
Fredrik Lundh has started posting his book The Standard Python Library online, in response to O'Reilly's decision not to publish a second edition of the book. I'd never read it before, but having samp...
Sam Ruby's ultra-simple 3-paned aggregator is a great example of the power of high level scripting languages. Using the wxPython cross-platform GUI toolkit and Mark Pilgrim's ultra-liberal RSS Parser ...
Python and Jelly: Scripting Power for Java and XML incorporates an excellent introduction to Python and Jython for Java programmers, with a whole bunch of comparative code samples and comprehensive co...
Intelligent Enterprise: For all of you unfamiliar with Python, get ready for the "next big thing."...
In response to yesterday's screen scraping post, Richard Jones describes a screen scraping technique that uses PyWebPwerf, a Python performance measuring tool.
I forgot to mention it in the article...
Via Paul Freeman, detailed instructions for installing Stuart's Vellum Python blogging system on Windows using either IIS or Apache....
Two fun bits from the Daily Python URL today (still without permalinks). SQLObject is an object-relational mapper class which can create objects that directly map to rows in a relational database, mak...
Dynamically extending APIs: Mark Pilgrim demonstrates how Python's "new" module can be used to dynamically add new methods to existing classes at run time, and shows how this can be used to increase p...
The path Python module (via The Daily Python-URL) is a nice looking wrapper class for Python's oft-confusing os.path module. Check out this neat code comparison:
# with os.path.walk
def delete_b...
Vellum 1.0a4 is out, and features comment support via a new Comments plugin and an Audience generic object type that abstracts the concept of "responses to your post" and is also used for Pingback sup...
Craig Saila points to the SearchEngineWatch Webpage Size Checker. It's a nice tool, but it doesn't appear to take the size of linked style sheets in to account. I was playing around with the idea of a...
Pythonology (via Deadly Bloody Serious about Python) is a Python advocacy site aimed at software engineers and managers. The site has a fantastic collection of case studies, Python Success Stories, wh...
Stuart has released the code for Vellum, his new Python blogging system. I haven't tried it out yet (the installation process is pretty in depth and I don't have a properly configured server to hand) ...
Oooh... Stuart has moved his blog over to Vellum, his brand new sparkly Python powered blogging system. The full post is here, but his archive / permalinks aren't working yet. It's going to be fun wat...
One for the reading list: The Making of Python - A conversation with Guido van Rossum, Part I....
If you weren't already exited about the OSAF, maybe it's time you were. I just spotted on Mitch Kapor's blog that they've hired Robin Dunn (of wxPython fame, and winner of the ActiveState 2002 Python ...
OpenEnterpriseTrends.com: Python Power: Growing Respect for an Open Source Integration Tool. Another excellent piece of Python advocacy, this time highlighting Python's power and flexibility as a midd...
Simon Brunning talks about persistence, and how much more complicated it is now that objects are involved. The best explanation I've seen of how objects and relational databases can be used together w...
Linux Gazette has a couple of interesting Python articles at the moment. Dealing with User Input in Python is a beginners guide to validating user input, while Pl/Python and Cursors in Pl/Pgsql for Po...
Kevin Altis on scripting applications written in PythonCard:
The entire object model of a PythonCard application is exposed, so if an app doesn't have the feature you want, you can probably exten...
Python 2.2.2 is out. It's mostly bug fixes, but they have also included the latest version of the Python email package. I've been playing with Python's email features recently as part of an experiment...
One of the things I really like about PythonCard is that it enables (and in fact actively encourages) you to completely separate the GUi of your application from the program logic. In PythonCard you d...
mod_python has been donated to the Apache Software Foundation. This is excellent news - I have always been slightly wary of mod_python as it has a reputation for being unstable, but with the ASF direc...
Fetching and Parsing RSS Data is the second installment of the effnews project, a series of tutorials on creating an RSS news reader in Python. This time topics covered include exception handling and ...
I've implemented two example web services to demonstrate the Incutio PHP XML-RPC library's capabilities. The services allow you to search and retrieve articles from FOLDOC and the Jargon File, two pop...
Rob Tougher: My Guide To Digital Photography. A short but informative article on using Linux and Python to manage a collection of digital photographs....
Some useful XML-RPC links (before I forget):
The XML-RPC Specification - concise and readable.
The XML-RPC Validator - a useful validation suite to ensure your XML-RPC implementation is up to scra...
R&OS PDF PHP classes (via tidak ada). This is the most useful PHP library I've seen in a long time. It allows dynamic generation of PDF files without needing any additional modules installed on th...
DevShed have published two useful new articles - MySQL Connectivity With Python and Understanding SQL Joins. They also now provide nice looking printer-friendly PDF versions of articles, which appear ...
How to Think Like a Computer Scientist: Learning with Python is a new Python text book covered by the GNU Free Documentation License and available on the web. The thread discussing it on Slashdot give...
Adding SSL support to Python on Windows is as easy as dropping a couple of DLLs and a .pyd file in to your Python DLLs directory. Grab the zip file from this page and off you go. I haven't tried it ou...
Paul Freeman has come up with new use for the Google API - generating random links. The idea is simple but effective - a random theme is selected and searched for (via pygoogle), then another search i...
Patrick O'Brien: Building GUI Applications with PythonCard and PyCrust. I'm a big fan of PythonCard, an excellent toolkit for creating GUI applications in Python that seperates the GUI layout from the...
Tip off for Stuart: The new Python Wiki includes an index of available web frameworks, but there's no mention of Castalian yet....
Small Values of Cool - links to things that I find interesting by Simon Brunning. I turns out I find them interesting as well. Lots of Python stuff on there at the moment, including a link to the new ...
Python in PHP (via HarryF on the SitePoint Forums):As both a Python and PHP enthusiast, I wanted to bring these two systems together to promote even greater and more interesting development opportunit...
xmlhack's "Editor's Newswire" is interesting. It is a small column (explained here) located on the right hand side of the site that displays the latest XML news snippets "in real time". The interestin...
CherryPy is an interesting open source Python application server. Dynamic sites are constructed in a special templating language which is then compiled by CherryPy to create a stand alone executable P...
Via techno weenie: A Python XML-RPC debugging proxy script. This solves the problem of XML-RPC errors from PHP being sent out with the XML-RPC response packet and breaking any XML parser trying to rec...
More Python advocacy: PYTHON: Yes, You SHOULD Be Using it! The article contains some background information on Python and why it is worth knowing, but the bulk of the article consists of a getting sta...
Useful resource: Cetus Links - 18,244 Links on Objects & Components. I found them via their Python page, which in itself lists over 200 Python resources split in to categories....
EuroPython 2002 kicks off today, and the EuroPython site is hosting an interview with Alex Martelli (comp.lang.python regular and author of the soon-to-be-released Python Cookbook). I haven't found an...
I just engaged in some basic Python advocacy, during which I rolled out my all time favourite Python advocacy link: Why Python? by Eric Raymond....
Dan Shafer: Space shuttle engineers use Python to streamline mission design.
"We achieve immediate functioning code so much faster in Python than in any other language that it's staggering," says ...
Via Daily Python-URL (which appears not to provide permalinks): Introduction to Python iterators. This is an extract from Deitel & Deitel's "Python How To Program" and includes extensive code samp...