How do I escape slashes the string formatting operator? (or: why isit behaving this way?)

D

Dustan

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):

It doesn't like the forward slash after the closed parentheses. I
don't know what it is expecting, but I need that slash there
(obviously this is a simplified example).

All help appreciated.
 
M

marek.rocki

Dustan napisa³(a):
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):

It doesn't like the forward slash after the closed parentheses. I
don't know what it is expecting, but I need that slash there
(obviously this is a simplified example).

All help appreciated.

Strign formatting docs (http://docs.python.org/library/
stdtypes.html#string-formatting) say that specifying a conversion type
is mandatory. So you actually should write something like:
'HELP!%(xyz)s/' % {'xyz':' PLEASE! '}
 
D

Dustan

Dustan napisa³(a):
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
'HELP!%(xyz)/' % {'xyz':' PLEASE! '}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unsupported format character '/' (0x2f) at index 11
It doesn't like the forward slash after the closed parentheses. I
don't know what it is expecting, but I need that slash there
(obviously this is a simplified example).
All help appreciated.

Strign formatting docs (http://docs.python.org/library/
stdtypes.html#string-formatting) say that specifying a conversion type
is mandatory. So you actually should write something like:
'HELP!%(xyz)s/' % {'xyz':' PLEASE! '}

Thanks. That seems to have worked nicely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top