building strings with variable input
Tim Roberts
timr at probo.com
Wed Jan 14 02:31:31 EST 2004
Olaf Meyer <nomail at nospam.net> wrote:
>
>I just found out another way ;-) Using the locals() has the disadvantage
>that I cannot use more complex variable parameters (e.g. certain values
>of a dictionary). The following works well:
>
>cmd = (executable + " -start " + startTime + " -end " + endTime +
> " -dir " + options.dir)
Yes, that works, but you should bear in mind that it is slower than the %s
option. The "+" operations are all separate interpreter steps, while the
"%" operation is done in C.
At least, it was that way when I asked this same question several years
ago. If it has changed, I'm sure someone will point out my error.
Sometimes, it can make sense to write it this way:
cmd = ' '.join((
executable,
"-start", startTime,
"-end", endTime,
"-dir", options.dir
))
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list