python
python libxml2 dita
python libxml2 dita
For correct transformation of DITA files (XML-standard for modular documentation), it is necessary to pull information from DTD (document...
January 21, 2016
Generating Excel XML, avoiding “found unreadable content”
In theory, changing content of an Excel file is easy:
* Parse XML from the zip-file
* Change XML
* Save XML into the zip
In practice I got the error: >>...
September 30, 2015
Tkinter sample application for a long operation
In the year 2001 I started to experiment with GUI applications in Python. The experience was summarized and published in the article "A complete Python Tkint...
July 09, 2015
Workaround for: CTR mode needs counter parameter, not IV
After upgrading the local Linux system, my python paramiko (ssh protocol implementation) program stopped working, with the error message:
CTR mode needs coun...
February 20, 2015
using freebidi from python using ctypes
GNU FriBidi is an implementation of the Unicode Bidirectional Algorithm (bidi). There is a Python binding PyFribidi, but it is not complete. What I need is n...
December 08, 2014
python libxml2: save XML as HTML
HTML is the main output format for XML transformations. Every XSLT-processor, including libxslt/libxml2, supports it. But if you transform a libxml2 tree man...
October 31, 2013
using xlrd and formatting Excel numbers
The number (and dates) in Excel are float numbers. How these numbers are displyed to an user -- as an integer, or with two digits after a point, etc -- are d...
October 22, 2013
pyinstaller, wxpython, core not found
Sometimes an error and the error message are different things. One of the examples is that my wxpython-program did not want to start after converting to exe ...
July 31, 2013
wxPython GIFAnimationCtrl: embed animation gif in the source code
In some cases it is useful to store media files inside the python code itself. For images, PyEmbeddedImage and the script img2py.py work well. But for GIFAni...
March 27, 2013
xml.etree.ElementTree and processing instructions
Python standard library xml.etree.ElementTree is convenient to work with a simple subset of XML. Unfortunately for me, this subset does not include processin...
June 19, 2012
python wtf: strip() eats too much
Many of python-xml code is probably wrong. Tracing a bug, I found an interesting WTF. A minimal example:
import string
s1 = "\xa0x\xa0"
s2 = u"\xa0x\xa0"
...
June 01, 2010
importing as module when a file has a non-identifier name
I need to reuse a function in a file. The usual way is just to import this file as a module. But what to do if the name is "bad"? The following doesn't work:...
June 12, 2009
escape a TeX string in Python
Do you generate [La]TeX files using Python? If yes, do you escape the special characters. Haven't you forgotten to escape also empty strings?
To avoid reinve...
October 17, 2008
be carefull with libxml2 in python
Unpleasant surprise from libxml2 bindings for Python: one must care for encoding conversion.
test.xml:
<text>Grüß</text>
test.py:
import libxml2...
May 27, 2008
reversing a string in python
This beautiful construction was not obvious for me.
>>> 'foo'[::-1]
'oof'
October 15, 2007
inplace, a new xslt-based CMS
I've released a content management system for static pages:
InPlace CMS
http://inplace.sourceforge.net/
Use InPlace CMS to maintain a bundle of HTML pages i...
October 04, 2007
python, re-encoding incorrected encoded string
Python has a quite decent internal support of unicode. But sometimes it's hard to find how to exploit the support.
I've lost some time solving a simple probl...
August 17, 2007
downloading log files
The best place to analyze log files is the local computer, not the server:
1) Log files grow fast, taking all the server space
2) Queries might be CPU-intens...
August 16, 2007
automating GUI tasks in Python
I have a program which is an example of usability nightmare. It's easier to create data in Excel and somehow migrate them to that program. Unfortunately, the...
July 20, 2007
breaking expectations
How do you thing, what the following Python/libxml2 code does?
for kid in node.get_children():
print kid.name
Do you think the code gets the children of ...
May 22, 2007
shut up, you dummy 7-bit Python
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:
...
March 23, 2007
execute an XPath and get the line numbers
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 contex...
March 05, 2007
plasTeX
Seems interesting: plasTeX is a LaTeX document processing framework written entirely in Python. It currently comes bundled with an XHTML renderer (including ...
October 25, 2006
scons signatures for Python actions
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...
August 24, 2006
forcing python mode in vim
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. Unfo...
August 23, 2006
currently executing python file
Here is a way to get the currently executing Python file:
print (lambda x:x).func_code.co_filename
Probably there is a simpler way, but I haven't found it. ...
August 16, 2006
parsing latex log files
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 re...
August 10, 2006
python trap
What will this code print?
for item in ('aaa'): print item
The result is:
a
a
a
I think you expected the following as the result:
aaa
I was near reporting...
August 02, 2006
Python for Lisp Programmers
A small Lisp vs Python article: "Python for Lisp Programmers". The title is very untraditional, one expects Python and Lisp swapped.
January 05, 2006