1,069 items tagged “python”
The Python programming language.
2003
Programming by Contract in Python
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 being processed which are then checked whenever the program is run in debugging mode. Contracts for Python discusses the technique, providing a reference implementation and a PEP suggesting inclusion of support for the technique in the core language. Programming by contract was first demonstrated in the Eiffel language, and there’s a good introduction to it in Eiffel.com as well.
PyMeld
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 elements within the template identified using their ID attribute. It’s a very elegant solution that makes good use of Python’s object overloading support to make manipulating templates as intuitive as possible. Maybe the same thing will be possible in PHP once the new overloading functions become part of the standard package.
[... 180 words]In praise of functional programming
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 copy) and it has been getting me seriously interested in the functional programming paradigm. It’s also by far the most enlightening (in terms of “wow, that really makes sense”) computer science text book I’ve ever read. There’s something naturally elegant about the functional style, probably thanks to the encapsulation encouraged by the lack of global variables and the extensive use of recursion in functional code examples. It’s definitely true that exposure to a variety of programming styles encourages you to think about problems in different ways.
Fixed Point Arithmetic in Python
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 Floating-Point Arithmetic almost exactly a year ago.
Python 2.2 Quick Reference
The Python 2.2 Quick Reference, via Michael Twomey. All the essential bits of Python on a single (if quite long) HTML page. Magic.
Python Roundup
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:
Easy Python Cryptography
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 site) but here’s an overview of how it works:
[... 205 words]Verbose Regular Expressions
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 with some pretty heavy regular expressions recently that could really do with the clarity of being defined in verbose format with comments.
[... 96 words]Accessible Python
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 accessibility of both websites and Python source code itself. Well worth taking the time to read.
Python and micropayments
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 sampled the first two chapters I’m hooked. It works a bit like a “cookbook”, with a plethora of code samples explained in detail accompanied by tips and tricks relating to the language. The Lazy Import class, which loads a module only when an attribute of the module is called for the first time, is a classic example:
[... 209 words]Python power
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 it provides a full application in a mere 107 lines of (highly readable and maintainable) code.
[... 127 words]Python for Java programmers
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 coverage of differences between the two languages.
More Python advocacy
Intelligent Enterprise: For all of you unfamiliar with Python, get ready for the “next big thing.”
Python bits and bobs
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, making INSERTs and UPDATEs much simpler. I’ve tried to write this kind of thing in PHP before with mixed results, so I’m quite tempted to pinch the idea of tracking foreign keys and joins for my next attempt. More immediately useful however is rlcompleter2 which adds tab based auto completion to the Python interactive prompt. I had a play with it earlier and it was definitely an improvement on the vanilla command line.
Dynamic Python class methods
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 productivity when parsing XML. I’ve long been impressed with Python’s ability to add new methods to an object at runtime just by assigning a function reference to an object property but I had no idea it was possible to do this with classes as well. If you liked that tip, Dive Into Python has in depth explanations of more obscure Python features than you can shake a stick at.
Python path module
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:
Pythonology
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, which an interesting piece describing why and how Rackspace migrated their main enterprise data system from PHP to Python.
First deployment of Vellum
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 watching the system develop.
The making of Python
One for the reading list: The Making of Python—A conversation with Guido van Rossum, Part I.
2002
Python as middleware
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 middleware tool to glue together varous large enterprise systems.
Object persistence
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 was in Martin Fowler’s Patterns of Enterprise Application Architecture, but now that the book has been published he has removed the online version. IBM’s DeveloperWorks has a new article up describing persistence management in Python, which talks in details about Python’s native serialization method (pickling) but only mentions ZODB in passing. I agree with Simon—object databases just don’t seem as elegant a solution as RDBMSs. Object databases may provide persistence but they don’t seem nearly as powerful as relational databases when it comes to flexibility of accessing data.
Linux Gazette Python articles
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 PostgreSQL explains how Python can be used to write stored procedures in PostgreSQL.
Python e-mail features
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 experimental idea to import all of my mail (from various accounts) in to a mySQL database and build my own web mail / mail application program. Working with email in Python is beautfully simple, thanks to the aforementioned email package and the powerful pop3 and IMAP classes in the standard library.
mod_python donated to the ASF
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 directly supporting it hopefully any stability problems will soon be a thing of the past.
effnews part two
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 event based XML parsing using xmllib
.
Python RSS tutorials
Spotted on Python owns us: Fredrik Lundh is building an RSS newsreader in Python, and writing Python tutorials on the project as he goes along. The first tutorial, Fetching RSS Files, is available now and covers (in detail) retrieving RSS files over the web, including an excellent explanation of asynchronous HTTP requests.
DevShed stuff
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 to be dynamically generated. Having found this article on Google I suspect they are using HTMLDOC to create the PDFs.