[Tutor] formating a string (partly)

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Wed Sep 24 21:53:53 EDT 2003


hi Ole, you just use a double percent like so:

txt =3D "Hello %s. This is a percentagesign: %%"

The reference for this is on:

http://www.python.org/doc/current/lib/typesseq-strings.html

%  No argument is converted, results in a "%" character in the result.

I hope that helps you.

On Thu, 25 Sep 2003, Ole Jensen wrote:

> Is there any way to =EDnclude percentage signs (as text) in a string, tha=
t 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 =3D "Hello %s. This is a percentagesign: %"
> >>> name =3D "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 w=
eb page (cgi output) where there are a lot of percentages signs that should=
n'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
>




More information about the Tutor mailing list