Translating a Perl script into Python

Emile van Sebille emile at fenx.com
Sun Jan 21 15:05:23 EST 2001


% based string formatting requires either a single argument,
or a tuple.  When using %(keyVal) substitution in the format
string, a single dictionary object may be used.  In this
case, only simple string keyVals are interpreted.
Otherwise, all single arguments must follow the type the %
substitution expected, ie %d accepts numbers, %s accepts
anything with a valid str/repr representation, etc.


--

Emile van Sebille
emile at fenx.com
-------------------


"Sheila King" <sheila at thinkspot.net> wrote in message
news:4tsk6t8ia6j55c1luv9l9tdqdfd6ljs8aj at 4ax.com...
> On Sun, 21 Jan 2001 01:22:40 GMT, Hamish Lawson
<hamish_lawson at yahoo.co.uk>
> wrote in comp.lang.python in article
<94ddks$ff9$1 at nnrp1.deja.com>:
>
> :It's more general and more powerful than that. The %
operator takes a
> :string on the left and a single value, tuple, list or
dictionary on the
> :right and produces a string by substituting the %
placeholders in the
> :left-hand operand with values from the right-hand
operand. Note that %
> :inside a string doesn't have any special meaning in
itself; it's the %
> :operator that treats it as placeholder. Thus
> :
> :    a = "His name is %s and his age is %d"
> :    b = ['Bob', 42]
> :    print a % b
>
> Thanks. I think it's starting to creep into my head, now.
Your examples
> helped. I've saved them in my file of examples.
>
> --
> Sheila King
> http://www.thinkspot.net/sheila/
> http://www.k12groups.org/
>





More information about the Python-list mailing list