Perl is worse!

Steffen Ries steffen.ries at sympatico.ca
Sat Jul 29 10:16:47 EDT 2000


grey at despair.rpglink.com (Steve Lamb) writes:

>     Nono, you misunderstand me.  I prefer the Pascal notion of variables in
> place in the string with formatting attached to it instead of placeholder
> formatting strings with the variables hanging off the end of the string.
> Pseudo code from no language, bear with me.
> 
> "Here is a string with ",$a:d:0:0," variable in it."
> 
> "Here is a string with %d:0:0 variable in it.",$a
> 
>     In the former I read and I see, "Oh, $a goes here with this formatting"
> whereas in the latter it is "Oh, here is the formatting for...  uhm.. $a."
> 
>     Again, simplistic and not in any language, but taken to the extreme you
> can see the problem.
> 
> "%d:0:0 %c:U %s %s %s %s %d %s %s %s \
> %d:0:0!",$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k
> 
>     What variable goes with what again?

In this case I would use the dictionary variant of the format string:
"%(a)0d %(b)c:U %(c)s %(d)s %(e)s %(f)s %(g)s %(h)s %(i)s %(j)s %(k)s"\
   % vars()

/steffen
-- 
steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!



More information about the Python-list mailing list