Forcing quote characters in repr(STRING), how?

Fredrik Lundh fredrik at pythonware.com
Thu May 3 13:43:11 EDT 2001


Marcin Kowalczyk wrote:
> > /* figure out which quote to use; single is preferred */
> > quote = '\'';
> > if (strchr(op->ob_sval, '\'') && !strchr(op->ob_sval, '"'))
> > quote = '"';
>
> This is inconsistent because it stops searching at '\0':
>
> >>> "asdf'gh"
> "asdf'gh"
> >>> "as\0df'gh"
> 'as\x00df\'gh'

doesn't matter much: the idea is to avoid escaping *if possible*.

if your string contains a NUL character, you'll end up with at least
one escaped character, no matter what quote you use.

Cheers /F





More information about the Python-list mailing list