Translating a Perl script into Python
Carel Fellinger
cfelling at iae.nl
Sat Jan 20 17:47:16 EST 2001
My ISP is having problems with its feed so I'm a little late to react
and there is only one little thing for me left to nitpick:(
Sheila King <sheila at thinkspot.net> wrote:
for this piece of code
> print PROC "$key = $ENV{$key}\n";
you used
> PROC.write(key + " = " + os.environ[key] + "\n")
whereas I often prefer (the (to me atleast) more Pythonic)
PROC.write("%s = %s\n" % (key,os.environ[key])
and yet in some circumstances even the more elaborate variant
PROC.write("%(key)s = %(value)s\n" % {key:key, val:os.environ[key]})
The latter form comes very close to the Perl way of coding, and
is espescially suited for format strings spanning several lines.
--
groetjes, carel
More information about the Python-list
mailing list