Lazy Crazy Coder's blog
IPython helper — ipipe
ipipe extension provides a handy way to browse and manipulate tabular data, e.g. groups of files or environment variables or data dictionaries.
- 04 Авг 02:16
ipipe extension provides a handy way to browse and manipulate tabular data, e.g. groups of files or environment variables or data dictionaries.
Finaloption is a command line parser, intended to make writing command line applications easy and painless. It uses built-in Python types (lists, dictionaries, etc) to define options, which makes configuration clear and concise. Additionally it contains possibility to handle subcommands (i.e. hg commit or svn update).
Easy to use python wrapper for Google's Chart API.
import re
import cjson
import datetime
# Encoding Date objects:
def dateEncoder(d):
assert isinstance(d, datetime.date)
return 'new Date(Date.UTC(%d,%d,%d))'%(d.year, d.month, d.day)
json=cjson.encode([1,datetime.date(2007,1,2),2], extension=dateEncoder)
assert json=='[1, new Date(Date.UTC(2007,1,2)), 2]'
# Decoding Date objects:
re_date=re.compile('^new\sDate\(Date\.UTC\(.*?\)\)')
def dateDecoder(json,idx): json=json[idx:] m=re_date.match(json)
if not m: raise 'cannot parse JSON string as Date object: %s'%json[idx:] args=cjson.decode('[%s]'% \
json[18:m.end()-2]) dt=datetime.date(*args)
return (dt,m.end()) # must return (object, character_count) tuple
data=cjson.decode('[1, new Date(Date.UTC(2007,1,2)), 2]',
extension=dateDecoder)
assert data==[1,datetime.date(2007,1,2),2]