Help with ASCII (UNIX<->DOS)

Malcolm Tredinnick malcolm at commsecure.com.au
Wed Sep 26 23:17:17 EDT 2001


Getting slightly off-topic, but ...

On Wed, Sep 26, 2001 at 11:02:55PM -0400, Peter Hansen wrote:
> Jeff Shannon wrote:
> > "CeK!" wrote:
[...]
> > '%s\n' % data[0][1]  (the inner parens are unnecessary) resolves into a
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> But nice style, given that it means any time the format string has
> another item added to it (extremely comment situation), one can just
> add a comma and the next item, rather than having to remember to add
> parentheses, and figure out where to place them.
> 
> And there'd be nothing wrong with (data[0][1], ) either..

For general debugging, there's a little trap here that the last case
solves perfectly. Often I'll have some classes with __str__ defined, so
I want to do something like '%s' % foo, rather than '%s' % repr(foo).

Now, this doesn't work if things have gone horribly wrong (and the
occasionally do) and foo is a list. The former case fails, the latter
works.

So I can either do '%s' % str(foo) or '%s' % (foo,), where the latter,
as pointed out above, allows for adding more things to the list easily.

Note that this doesn't happen to often, but if you are putting in
debugging logging because the world has gone mad, it's extra defensive
programming that can save time later.

Cheers,
Malcolm

-- 
I feel like I'm diagonally parked in a parallel universe.




More information about the Python-list mailing list