not quite random: python
Not Quite Random: snippets of Python.

 January 2003 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Dec   Feb

 Python

Blogchalk:
Portsmouth, NH, US

## Friday, January 03, 2003

### It looks like Python 2.3 will have some pretty cool stuff.

It looks like Python 2.3 will have some pretty cool stuff.

8:34:10 AM   #

### odbc.py: working with dbiRaw

This post on comp.lang.python describes how to use the dbiRaw object you get back when working with binary (BLOB or IMAGE, depending on your back end) fields. And, for some reason, I seem to be getting back two bytes for every byte inserted. This is annoying.

5:34:15 PM   #

## Tuesday, December 31, 2002

### Python module for handling MS Word files

I wrote a simple python module for handling MS Word files. If you've been following along, you know that I've been wrestling with python and Word a bit recently. It turns out that it's easy enough to do, you just have to put together the right information. (Note: requires win32 extensions, Word, and FPropSet.)

7:18:30 AM   #

## Friday, December 27, 2002

### Using Python to Extract Title from MS Word Doc

Based on some code from this article, here's how to extract the "Title" property from a Word document in python.

  import win32com.client
app = win32com.client.Dispatch('Word.Application')
self.title = doc.BuiltinDocumentProperties("Title")
doc.Close(0)
app.Quit()

3:25:43 PM   #

### Hmm.

Hmm. There has got to be a faster way of getting that info. I'm pretty sure that Explorer isn't launching Word every time it wants to display the properties for a document.

3:47:27 PM   #

### Document Titles Part II: A Better Way

There is: FPropSet. This is about two magnitudes of order faster than the previous solution.

    fps = win32com.client.Dispatch('FilePropertySet.FilePropertySet')
fps.Pathname = file
print fps.BuiltInFileProperties().Item("Title")

6:30:51 PM   #

### Do Not Operate Heavy Machinery if Brain is not Working

After spending an hour trying to figure out what misunderstanding of COM was causing my problem, I realized that the file I was trying to test against DID NOT EXIST (typo). I was calling everything correctly, but the information I was sending was wrong... note that setting fps.Pathname to a non-existent file will cause an exception.

6:33:41 PM   #

## Friday, December 20, 2002

### upload.py: a script to upload files to FTP server only as-needed

This is a python script that basically implements a crude sort of upstreaming (but it's not scanning constantly, only when you run the script). I wrote this because I got tired of fighting with other software that didn't quite integrate the way I wanted it to. This is a small piece in a set of loosely joined tools that I use to manage my website(s). The script is available under an MIT style license.

7:28:25 PM   #

## Thursday, December 19, 2002

### Creating a DSN from Python

This is pretty simple. All I did was to convert the MS KB article from Visual Basic to Python. Note that this won't actually create the .mdb file. That's a little trickier -- I can't find a Python binding for the DLL call and I don't have the need for it at the moment. See init_dsn.py for details.

3:56:05 PM   #

## Wednesday, December 18, 2002

### Using the Windows System Tray with wxPython

Check out this code sample for a quick and dirty system-tray demo using wxPython. (Lifted, rearranged, and simplified from the wxPython demo.)

Note that you'll need an icon file for this to work, or you'll have to add back the images.py code from the demo.

11:28:00 AM   #

## Monday, December 16, 2002

### MS Word from Python

Note: this assumes you have python, win32all, and MS Word all installed properly.

Running Word from python is incredibly easy.

import win32com.client
# Start the application.
app = win32com.client.Dispatch('Word.Application')
# Open a document.
# Or:
app.ChangeFileOpenDirectory('c:\path\to\document\')