ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Duncan Booth duncan.booth at invalid.invalid
Thu Jan 10 12:34:23 CET 2013

Dave Cinege <dave at> wrote:

> You will notice that the code is disgusting simple. However I have
> found that this has completely changed the way I program in python.
> I've re-written some exiting programs using Thesaurus, and often
> relized 15-30% code reduction. Additionally I find the new code much
> easier to read. 

And here's the same code written without your class but maintaining as 
far as possible the same structure. I find my version far easier to read 
then your's with all your spurious 'g.' 'L.' prefixes.


from textwrap import dedent

class Blob(object): pass

prog = Blob()
prog.VERSION = '1.0'		# But isn't this so much cleaner?
prog.NAME = 'Thesaurus'

class TestClass:
	no = 'Class'
	way = 'this'

def main ():
	tc = TestClass()
	l = ['Some', 'objects']

	# Here's how you should create output without a fight.
	print dedent('''\
		When programing python without {prog.NAME}, it is very
		easy to access your {l[1]}.
		{l[0]} people might say {prog.NAME} has no {}.''').format(prog=prog, l=l, tc=tc)

	if hasattr(prog, 'VERSION'):
		print 'But I challenge them to write code {tc.way} clean without it!'.format(**locals())

if __name__ == '__main__':

Duncan Booth

More information about the Python-list mailing list