Archive

Archive for the ‘Python’ Category

Django

July 28th, 2005

Django | The Web framework for perfectionists with deadlines

bq. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design

This is something I will certain look into using. a because it is a web framework written in Python, b because it is written my some clever people and c because it has a cool name.

I don’t know if it was named after the “Spaghetti Western Django”:http://www.plume-noire.com/movies/cult/django.html but if so, that would be cool. I used to live with the guy who had the rights to publishing Django in the UK (who just missed out on publishing Monkey and went off to work for the BBC instead). He had a cat called Django which was the meanest cat on the planet.

Paul Python

Python Unit Testing

June 25th, 2004

One of the projects that has been on my Someday/Maybe list for a while has been to learn about “Unit Testing”:http://diveintopython.org/unit_testing/index.html and “test driven development”:http://www.kryogenix.org/days/2004/06/14/development950408240368.

Most of the little utilities I use at work to make my life easier were written a few years ago in Java. This year I’ve started to convert some of them into “Python”:http://www.python.org as an aide to learning it. Last month I converted a small program that automatically downloads customer’s testcases from an FTP site onto my harddrive. When the service request is closed, it automatically archives the testcase (aside: the manual process to do this is very tedious and slow. The people I work don’t seen to write any code to automate their jobs in any way. Is this something you do? Or do you never have the time to write hacks that will make you job easier?)

When I rewrote this in Python, I thought it would be a good exercise to learn unit testing, however the ease of Python meant I just dived straight in and had written 95% percent of it before I’d even remembered about unit testing. I finished the code off and made a note to read the unit testing chapters and then add unit testing to the code afterwards.

I’m reading through the chapters now and come to “these basic points about unit testing”:http://diveintopython.org/refactoring/summary.html :-

bq.:http://diveintopython.org/refactoring/summary.html There are unit testing frameworks for many languages, all of which require you to understand the same basic concepts:

* Designing test cases that are specific, automated, and independent
* *Writing test cases before the code they are testing*
* Writing tests that test good input and check for proper results
* Writing tests that test bad input and check for proper failures
* Writing and updating test cases to illustrate bugs or reflect new requirements
* Refactoring mercilessly to improve performance, scalability, readability, maintainability, or whatever other -ility you’re lacking

I think I’ll start again.

Paul Python

Answering those tricky questions

December 4th, 2003
Comments Off

I should bring back my linklog (whatever you want to call it) because Estimating the Airspeed Velocity of an Unladen Swallow needs no comment [via "A Whole Lotta Nothing":http://a.wholelottanothing.org/archives.blah/007589 ]

Paul Python

Super Basic RSS Aggregator

June 11th, 2003
Comments Off

So, today I’ve been working on my new weblog system. The first thing I thought I’d do is write the RSS Aggregator, because I thought MovableType was doing a decent job of being my current weblog system. This was a bit silly really because “SharpReader”:http://www.sharpreader.net is doing a decent job at being my RSS reader, but hey I’ve started it now.

This page here shows it in action, but all it is doing is displaying the data in an order, with none of the functionality I want in the future. I just want to talk about the technology behind this one simple page, mainly for my own benefit, but perhaps you want to know too.

At the heart of things is “The Ultra Liberal RSS Parser”:http://www.diveintomark.org/projects/rss_parser/ by Mark Pilgrim. Then, in a directory called “thing”[1] is a smallish python script that uses rssparser.py to grab items and stuff them into a MySQL database (don’t start Aq). I store stuff like etag and last-modified so rssparser.py behaves itself, as well as description, time etc. In fact, the only trouble I had here was with the dates. I’m thankful to “another Mark”:http://markpasc.org/weblog/2003/06/01_prrarf_01b_rss_dates.html for being two steps ahead of me here. So, with this little program, you can add feeds, subscribe to feeds, unsubscribe to feeds and update the feed items.

Long term, I’m planning to output everything from the database as XML and then use some XSLT to pump it out to the relevant format, but I didn’t have time for that and used “PyMeld”:http://www.entrian.com/PyMeld/index.html instead.

This is really neat and very easy to use, and I might just use this for everything in the end. Only one problem; at the start the docs give an example of how to use it and then say how slow that method is. Then, they give a different method, which I tested and found to be really quick. Trouble was, that this didn’t take into account nested objects, and I couldn’t work out how to do what I wanted with that method. I went back to the old method, and whilst it outputted as I wanted, it was rather slow (and the Linux box is this running on is no slow-coach).

Next step: a bunch of other things!

I’m celebrating by listening to British Sea Power as “mentioned by Vaughan”:http://www.whereveryouare.org.uk/weblog/archives/week_2003_06_01.html#003122 to whom I’m now indebted. I saw BSP at Reading Festival 2002 and thought they were blooming marvellous. I was very disappointed to find I couldn’t find their only EP anywhere, and hadn’t noticed that they had an album out.

[1] Working title for the weblog system :)

Paul Feeds, Python

xmltramp

May 16th, 2003
Comments Off

xmltramp: Make XML documents easily accessible.

Nice and easy XML handling in Python. From ??Aaron Swartz??

Paul Python, XML

Python main() functions

May 16th, 2003
Comments Off

One of the many things I’ve yet to learn about “Python”:http://www.python.org is how to *do things properly* such as when giving out proper programs, what is the standard way of packaging the objects and functions etc. I’ve seen a number of different ways and have yet to decide which is best.

How to write a main() function in Python from ??Guido van Rossum?? are some guidelines on how to make flexible main()’s. Use optional ‘argv’ arguments, use a default argv, deal with sys.exit()’s and define a Usage() exception.

Paul Python