variable substitution
Jimmy Retzlaff
jimmy at retzlaff.com
Wed Apr 24 09:47:01 EDT 2002
Steve Holden [mailto:sholden at holdenweb.com] wrote
> "Hugh" <h.e.w.frater at cs.cf.ac.uk> wrote ...
>> How do I get the %(variable)s thing to work. I need to substitute a
>> variable into a print statement so I can send links with sessionId's
>> attached back to the browser. I'm trying this at the moment, and It
>> says invalid sysntax.
>> print '<a href = "addItemType.py?sessionID=%(sessionId)s">Add Item
>> Type</a>'
>> I saw this in a document written by Guido that I found here:
>> http://www.w3j.com/6/s3.vanrossum.html
>
> You need to add a "%" operator and put a dictionary on its RHS. The
> parenthesised words are then used to look up the appropriate values in
the
> dictionary (technically, any mapping type will work). e.g.:
The built-in function locals() can prove to be a very handy source for
that dictionary.
Jimmy
More information about the Python-list
mailing list