Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'argument': 0.05; 'arguments': 0.09; 'lines:': 0.09; 'rows': 0.09; 'rows,': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; '42,': 0.16; 'adjusted': 0.16; 'collections': 0.16; 'columns': 0.16; 'descriptor': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'given)': 0.16; 'length,': 0.16; 'merely': 0.16; 'namedtuple': 0.16; 'readable': 0.16; 'redundancy': 0.16; 'skipped': 0.16; 'typeerror:': 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'interpret': 0.24; 'tend': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; '(like': 0.30; 'statement': 0.30; 'code': 0.31; 'easier': 0.31; 'aligned': 0.31; 'chase': 0.31; 'tuples': 0.31; 'maintaining': 0.32; 'table': 0.34; 'editor': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'keyword': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'that,': 0.38; 'even': 0.60; 'break': 0.61; 'mentioned': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'benefit': 0.68; 'dr.': 0.77; 'you:': 0.81; 'dry': 0.84; 'noise': 0.84; 'received:50.22': 0.84; '"how': 0.91; 'aligning': 0.91; 'edwards': 0.91; 'wanting': 0.93 Date: Wed, 31 Jul 2013 13:19:15 -0500 From: Tim Chase To: Grant Edwards Subject: Re: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: none Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375294671 news.xs4all.nl 15964 [2001:888:2000:d::a6]:47569 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51682 On 2013-07-31 16:32, Grant Edwards wrote: > On 2013-07-31, Tim Chase wrote: > > I interpret Grant's statement as wanting the "table" to look like > > > > for name, value, description in ( > > ("cost", 42, "How much it cost"), > > ("status", 3141, "Status code from ISO-3.14159"), > > ... > > ): > > do_something(name, value) > > print(description) > > Exactly. When you have more than about 5 columns and 10 rows, > having things aligned makes it far, far, easier to maintain. As mentioned by Marcelo, when they can vary in length, maintaining is a pain. Even if your editor supports aligning (like vim with Dr. Chip's align.vim plugin). If I have a table of greater dimensions, I tend to refactor into a more readable+maintainable scheme, whether using dicts or named tuples and then break out the rows onto their own lines: from collections import namedtuple Descriptor = namedtuple("Descriptor", ["name", "value", "description"]) for name, value, description in ( Descriptor( name="cost", value=42, description="How much it cost", ), Descriptor( name="status", value=3141, description="Status code from ISO-3.14159", ), ): do_something(name, value) print(description) Using a namedtuple, if you forget one of the fields (or add an extra, or misspell one), it yells at you: TypeError: __new__() takes exactly 4 arguments (2 given) TypeError: __new__() takes exactly 4 arguments (6 given) TypeError: __new__() got an unexpected keyword argument 'nmae' There is redundancy of the kwarg params, but this can be skipped if you prefer DRY code to more readable code. Doing this also has the benefit that, when diffing, you don't get noise when columns are merely adjusted visually. -tkc