Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Brython, Python in the browser. Parent comment
btw: it's not a decorator :) but a camelCase->under_score renamer it's pretty easy to write
import re def unCamel(obj, *maybe_camels): if not maybe_camels: maybe_camels = filter(lambda n: not n.startswith('_'), dir(obj)) for maybe_camel in maybe_camels: underscore = re.sub(r'([^A-Z])([A-Z])([^A-Z])', lambda m: '%c_%c%c' % (m.group(1), m.group(2).lower(), m.group(3)), maybe_camel) if underscore != maybe_camel: setattr(obj, underscore, getattr(obj, maybe_camel)) if __name__ == '__main__': class CamelCase(object): def multiWordMethod(self): print('called multiWordMethod') def multiWordFunction(): print('called multiWordFunction') unCamel(CamelCase) # magic import sys unCamel(sys.modules[__name__], 'multiWordFunction') # magic CamelCase().multi_word_method() multi_word_function()
There are no comments on this comment yet.
btw: it's not a decorator :) but a camelCase->under_score renamer it's pretty easy to write
[0] http://www.python.org/dev/peps/pep-0008/