Archive for the ‘python’ Category

shut up, you dummy 7-bit Python

Friday, March 23rd, 2007

I’m working on an unicode-aware application. I like to use print to debug programs, but in this case it was nightmare. The most popular result of print was:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xXX in position 0: ordinal not in range(128)

I spent two hours fixing it, and I hope it’s done. The solution is one of the ugliest hack I ever written, but it solves the pain.


execute an XPath and get the line numbers

Monday, March 5th, 2007

I’m investigating the structure of an XML file. The best tool is an usual text editor (vim), but I need to look at some specific tags in some specific contexts. The idea is to execute an XPath and somehow to get to the location in the editor. Remembering that I saw something interesting while playing with libxml internals, I re-checked… And bingo! I’ve written a script which executes an XPath and prints the result together with the line number of the source XML file.



Wednesday, October 25th, 2006

Seems interesting: plasTeX is a LaTeX document processing framework written entirely in Python. It currently comes bundled with an XHTML renderer (including multiple themes), as well as a way to simply dump the document to a generic form of XML. Other renderers can be added as well and are planned for future releases.

scons signatures for Python actions

Thursday, August 24th, 2006

Finally, I traced out why time-to-time my functional tests stop passing.
* Some steps are associated with Python functions.
* Signatures of such steps depend on the code of the functions.
* If the code of a function is changed, the signature is changes, and the step is considered out-of-date.
Therefore, small changes in code lead to changes in the build process.


forcing python mode in vim

Wednesday, August 23rd, 2006

To force the python mode for a file, add the following comment at the beginning:

# -*- mode: python -*-

It’s also possible to add other options as well. Unfortunately, I don’t remember the term for such comment, so I can’t find its descrition in the vim documentation.

currently executing python file

Wednesday, August 16th, 2006

Here is a way to get the currently executing Python file:

print (lambda x:x).func_code.co_filename


parsing latex log files

Thursday, August 10th, 2006

In mary cases, LaTeX should be run several times to get the correct result (for example, to resolve cross-references). The only way to detect if re-run is required is to analyze the log file. I haven’t found anything ready to use, so I’ve written it myself.


python trap

Wednesday, August 2nd, 2006

What will this code print?

for item in ('aaa'): print item


Python for Lisp Programmers

Thursday, January 5th, 2006

A small Lisp vs Python article: “Python for Lisp Programmers“. The title is very untraditional, one expects Python and Lisp swapped.