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 [...]
Category Archives: python
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 [...]
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 [...]
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
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 [...]
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 [...]