Monday, October 1, 2012

json_dumps_pretty

from functools import parital
import json
json_dumps_pretty = partial(json.dumps,  sort_keys=True, indent=4)

Friday, March 11, 2011

Tuesday, April 21, 2009

Selenium is awesome

Even if you only use the IDE, Selenium is powerful for testing web-apps.

Just download selenium, startup the IDE and starting recording tests. Then just record the test through the IDE. Organize these tests into a suite and just save them as HTML tests. You can then just run them through firefox.


Thursday, April 16, 2009

yield is awesome

Checkout this course on coroutines that use python's built in yield facility:

http://dabeaz.com/coroutines/index.html

David Beazley presented this at PyCon this year:






Wednesday, April 15, 2009

import awesome now works in Python!


Go grab the awesome Git Repository at GitHub: git://github.com/benthomasson/awesome.git


git clone git://github.com/benthomasson/awesome.git
python
>> import awesome

help() is awesome

It is awesome that I can look at the documentation for a module in the shell anywhere and at anytime.


help(awesome)


It is even more awesome that it uses 'less' to display the help.

It is even more awesome that I can call in a script and it still works the same way. Being able to introspect during execution using help is just great.



x = mysteryFunction()
help(x)

Friday, April 10, 2009

unittest is ...

Okay, the python unittest module is awesome, but the titles are getting repetitive. This little script will make running your unit tests even easier:

test.py

#!/usr/bin/env python

import unittest
import sys

for module in sys.argv[1:]:
done = False
while not done and module != "":
try:
exec('import ' + module)
done = True
except Exception:
module = module.rpartition('.')[0]


unittest.main()



This will allow you to run any unit tests in any module from the command line.


test.py mypackage.test yourpackage.test
test.py mypackage.test.TestXYZ.testRun