converting a sed / grep / awk / . . . bash pipe line into python

Roy Smith roy at panix.com
Wed Sep 3 09:35:41 EDT 2008


In article <g9lvc5$8qq$03$1 at news.t-online.com>,
 Peter Otten <__peter__ at web.de> wrote:

> > I might take it one step further, however, and do:
> > 
> >>         fields = line.split()[:2]
> >>         a, b = map(int, fields)
> > 
> > in fact, I might even get rid of the very generic, but conceptually
> > overkill, use of map() and just write:
> > 
> >>         a, b = line.split()[:2]
> >>         a = int(a)
> >>         b = int(b)
> 
> If you go that route your next step is to introduce another try...except,
> one for the unpacking and another for the integer conversion...

Why another try/except?  The potential unpack and conversion errors exist 
in both versions, and the existing try block catches them all.  Splitting 
the one line up into three with some intermediate variables doesn't change 
that.



More information about the Python-list mailing list