Format string with single quotes in it

Bahadir bilgehan.balban at gmail.com
Fri Sep 25 08:42:11 EDT 2009


Hi there,

My question is simple, but I've been spending some hours over the web
and still struggling to get this right: How do I format a string that
contains single quotes in it?

I am reading a file with lines of the form:

CONT%d_VIRTMEM_REGIONS  'Container %d number of virtual regions'

and trying to format this as follows:

str % (0, 0)

I get the error:

ValueError: unsupported format character '
' (0xa) at index 5541

I also tried:

# Replace single quotes with \'
str = str.replace("'", "\'")

and doubling the backward slash as well.

What am I doing wrong?

Thank you,

Bahadir



More information about the Python-list mailing list