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

Dustan DustanGroups at gmail.com
Wed May 6 19:58:42 EDT 2009


On May 6, 6:51 pm, marek.ro... at wp.pl wrote:
> 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.



More information about the Python-list mailing list