Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36568
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes |
| Date | 2013-01-10 11:34 +0000 |
| Message-ID | <XnsA14475B2A400Fduncanbooth@127.0.0.1> (permalink) |
| References | <mailman.284.1357665177.2939.python-list@python.org> |
Dave Cinege <dave@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Dave Cinege <dave@cinege.com> - 2013-01-08 12:02 -0500
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Duncan Booth <duncan.booth@invalid.invalid> - 2013-01-10 11:34 +0000
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-10 05:04 -0800
csiph-web