Python equivalent of "lynx -dump"?

greg Landrum greglandrum at earthlink.net
Wed Mar 29 16:14:52 CEST 2000


Tim Roberts wrote:
> 
> 
> I hope you do not mind if I ask a Python style question unrelated to your
> issue.  That source line contains an idiom I see often in the Python code,
> and I do not understand why.  To me, it seems wasteful to use the %
> operator where simple string concatenation will do the same job more
> quickly.  For example, isn't this just as clear?
> 
>         lynxcmd = "lynx -dump " + url
> 
> Certainly, in C programming, I would never use printf where a simple strcat
> would do, and this seems like an exactly parallel situation.

Theory 1:
My simple-minded take on this is that it just makes things a bit easier.
For example:
  foo = 'Widget %d has been frobbed %d times'%(ID,count)
is a lot easier than:
  foo = 'Widget ' + str(ID) + ' has been frobbed ' + str(count) + '
times'
Sure, there's no such gain in the case you are talking about, but it is
sometimes nice to be consistent.  It also buys you a bit more
flexibility
should you want to change the content of the string.

Theory 2:
Using formatting characters makes some of us think of C, whilst the
other
approach is more C++ like.  That's argument enough for me.
;-)

-greg


-- 

greg Landrum (greglandrum at earthlink.net)
Software Carpenter/Computational Chemist



More information about the Python-list mailing list