Thursday, August 2, 2007

use * for string duplication

I have not used * operation to duplicate string until recently:
valueStr2 "( %s" + ",%s"*(len(dict)-1)+")"

rather than the following c-type implementation
tempL = []
for i in dict.keys():
tempL.append("%s")
valueStr2 = "(" + ",".join(tempL)+")"

Tuesday, July 24, 2007

restart python to get newly imported module

newly imported python module by using easy_install can not be imported instantly. you have to restart the python session to import the new module properly
C:\Documents and Settings\mwang>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named MySQLdb
>>> quit
Use quit() or Ctrl-Z plus Return to exit
>>> quit()

C:\Documents and Settings\mwang>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

Friday, July 13, 2007

a quick/good example of using the python/twill

Today I have a issue on playing http request by using one of load stress testing tool/appliance, and I suspected that the cookie setting in that appliance is not working properly: 2 cookies were set during the requst, and I expected more cookie to be set. I may ask around the developer for cookie information, but it will take time to find the right resource. Fortunately, the following 9 lines code saves my time:

from twill import get_browser
from twill.commands import *
import sys


b = get_browser()
b.go("http://www.example.com/foo")
show()
print "======="
show_cookies()


the results surprisingly tells me that 8 cookies was set after the request. the next thing is to submit an service request to the vendor, provides my expectation with my findings, then expected solution soon.