Category Archives: python

string.Template with default substitution value

I wanted a string.Template class that will substitute placeholders with a default value if the mapping is not provided. For example, say I create a template A template with $value1, $value2 When I substitute this template with values, say I provide only $value1, I want other $variables to be substituted with a default value. If [...]

Posted in python | Leave a comment

doctest omits decorator functions / decorated def – a simple workaround

Apparently there is a known issue with doctests, in which tests in functions using externally defined decorators are ignored by doctest.Here’s a simple workaround.   @aspect.processedby(aspect.tracing_processor)def aa(): ”’ Returns None  — doctests —-  >>> aa() True  ”’ return False def all_tests(): ”’ Returns None  — doctests —-  >>> aa() True >>> aa() False  ”’  return False [...]

Posted in python | Leave a comment

PyWin64 ?

There is no pywin64 (yet?). What do I use pywin32 for ? I use it for: .COM programming – Excel automation. There are alternatives for building Excel files without .COM but if you need to invoke Excel macros within your python program, you need .COM. This is yet another reason to stick to Windows 32 [...]

Also posted in guide to buying a dell | 1 Comment

Upgrading from Python 2.5 to Python 2.5.4

I was hesitant to upgrade from Python 2.5 to 2.5.4 on because upgrades usually break something. I tested it first on a desktop. The default upgrade installed to a C:\Python25 directory and a lot of things broke. Python scripts that worked before stopped working. easy_install would not work because it could not find Python.exe. This [...]

Also posted in work, wow | Leave a comment

Vim compiled with Python 2.5

You might want Vim compiled with +python if you’re trying to get Vim’s wonderful omnicomplete to work. The gvim.exe at vim.org does not have +python for 2.5. You can get a python 2.5 build at Yong Wei’s site. Now omnicomplete works for me !!Read more python,work articles

Also posted in work | Leave a comment

Scheduling Python scripts as Scheduled Tasks

When scheduling python scripts as Scheduled Tasks in Windows, take note that although you specify the script with arguments eg : kl_ofm.py -g -v When the scheduled task runs, it runs as kl_ofm.py without the arguments. The above is something to take note of when scheduling Python scripts.   One option around this is to [...]

Also posted in work | Leave a comment

Python programming with Excel, how to overcome COM_error from the makepy generated python file

import win32com.client xl = win32com.client.Dispatch(‘Excel.Application’)wb = xl.Workbooks(‘Book1′)ws = wb.Worksheets(‘Sheet1′)cell = ws.Range(‘A1′)cell.SetValue(arg1 = ‘test entry in Excel’)   Above is a very simple python script to write something in Excel. To run the above, you need Mark Hammond’s pywin32 to generate the PythonCOM package. Read O’Reilly’s Python Programming on Win32 for more information on what PythonCOM packages [...]

Also posted in work | 1 Comment