ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

88888 Dihedral dihedral88888 at googlemail.com
Thu Jan 10 08:04:48 EST 2013


在 2013年1月10日星期四UTC+8下午7时34分23秒,Duncan Booth写道:
> Dave Cinege <dave at cinege.com> 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.
> 
> 
> 
> 
> 
> -----------------------------------------------------
> 
> 
> 
> #!python2.7
> 
> 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 {tc.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__':
> 
> 	main()
> 
> -----------------------------------------------------
> 
> 
> 
> 
> 
> -- 
> 
> Duncan Booth http://kupuguy.blogspot.com

An object can accquire new properties and methods
in the run time without the limitations from 
the class definition of the object which belongs to.

This is a true OOP language.



More information about the Python-list mailing list