Random notes from mg

a blog by Marius Gedminas

Marius is a Python hacker. He works for Programmers of Vilnius, a small Python/Zope 3 startup. He has a personal home page at http://gedmin.as. His email is marius@gedmin.as. He does not like spam, but is not afraid of it.

Tue, 27 Jan 2009

pydoc SyntaxError

I once needed to know about SyntaxError's attributes. Here's what pydoc SyntaxError from Python 2.5 says:

 |  Data descriptors defined here:
 |  
 |  filename
 |      exception filename
 |  
 |  lineno
 |      exception lineno
 |  
 |  message
 |      exception message

So far so good

 |  
 |  msg
 |      exception msg

Hmm?

 |  
 |  offset
 |      exception offset
 |  
 |  print_file_and_line
 |      exception print_file_and_line

Doh!

 |  
 |  text
 |      exception text

My, that was useful. Maybe the online documentation will be better?

exception SyntaxError

...

Instances of this class have attributes filename, lineno, offset and text for easier access to the details. str() of the exception instance returns only the message.

Um. Well, at least now I know I can ignore both 'msg' and 'message'. I think. Still, it would be nice to warn that sometimes the exception text can be multi-line.

posted at 19:23 | tags: | permanent link to this entry | 0 comments

Mon, 05 Jan 2009

Exporting to MS Word

If you're developing a web application that runs on Linux, and a customer asks for a report in MS Word format, you're going to be in a lot of pain. One approach is buying a Windows licence, installing it in a virtual machine, and hooking up an application to drive it over COM, and then figuring a way to talk to the VM from your web app. A simpler approach is generating a web archive file (.mht) and pretending it's a .doc file. Word happily opens it, usually.

Here's a random helpful tip: try not to have more than 2047 <ul> elements in it, or they'll start spontaneously nesting.

posted at 18:54 | tags: | permanent link to this entry | 0 comments