Jump to content
  • entries
    334
  • comments
    900
  • views
    258,348

Adventures in Python


EricBall

763 views

Earlier this year I managed to complain enough to my cableco about their move from analog to digital for SD stations (and the impact on my dual tuner TiVo) to get a free rental HD PVR. Last week I realized there's a whole whack of movies which get shown on the HD channels (i.e. my wife taped Inglorious Bastards, and I watched one of the Transformers movies), but there's no consolidated listing which would make it easy to find the ones which I might want to watch.

 

But then I got to thinking - I have a subscription to Schedules Direct (for OTA listings used by my HD MythTV), so I can get listings for my cableco too. So my challenge is to put that data (which is an XML file retrieved via SOAP) into some kind of database which I could then query.

 

Fortunately, there were code examples on the SD forums - including one which put the data into a SQLite database. But the samples were in Python - I guess I get to learn a new programming language.

 

The code came together remarkably quickly. I used the ElementTree library to convert the XML to Python dictionaries, then a cool bit of Python from the sample code to convert the dictionaries to SQL insert statements for SQLite.

 

Stuff I liked about Python:

1. Dictionaries - these are really cool key+value lists and made a great intermediate step between the XML and the SQL insert with the key being the field name.

2. For loops for lists & dictionaries. It's kinda like the batch "for %a in (*.txt)" - no indexes or linked list pointers required. (Although this makes traditional numeric for loops more .... interesting.)

 

Stuff I disliked about Python:

1. Having to put colons at the end of def, for & if statements. Although I can respect using indentation for blocks (I still think if/endif is a less error-prone construct), the number of times I had to re-edit my code just to add colons...

2. While slicing strings with [start:end] is cool (especially being able to use negative values for RIGHT$), I don't know why [3:4] doesn't return two characters. It's like I'm having to include a character for the zero terminator.

3. I'm not sure I agree with the copy by reference default. Outside of some recursive tree routines (where the child needed to modify the child pointer in the parent), I've seldom had reason to copy by reference in my programs. I'm much more likely to want spam=eggs to have spam be a copy of eggs. It just seems to me I'm much more likely to accidentally forget the .copy() and have problems when modifying spam or eggs affecting the other.

4. I hit some runtime code errors which would have been nice to detect at compile time, like trying to use a new variable as an lvar or a type mismatch. I appreciate that Python doesn't require the programmer to declare a datatype for each variable, but that doesn't mean the compiler can't track variable initialization and types and flag obvious problems.

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...