[Tutor] formating a string (partly)

Ole Jensen learning.python at dbmail.dk
Wed Sep 24 21:26:39 EDT 2003


Is there any way to ínclude percentage signs (as text) in a string, that also contains format modulos (%s)?

I'm sorry if the above makes no sense, but thats the reason for posting! I have no clue what to search for... I tried but...

So I better give an example of what I want to do:

>>> txt = "Hello %s. This is a percentagesign: %"
>>> name = "Thomas"
>>> print txt % name
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in ?
    print txt % name
ValueError: incomplete format
>>> # should be this:
>>> # Hello Thomas. This is a percentagesign: %

Basically I want to use the modulo thing to insert variable values on a web page (cgi output) where there are a lot of percentages signs that shouldn't be formated because they are part of the html-code.

Alright I hope it made better sense in the end.
And thanks in advance for any suggestions.

For now
Ole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20030925/026b71b1/attachment.html


More information about the Tutor mailing list