Is there any way to make repr(aString) use double quotes?

Jeremy Fincher tweedgeezer at hotmail.com
Sat Apr 12 05:27:15 EDT 2003


Francois Pinard <pinard at iro.umontreal.ca> wrote in message news:<mailman.1049836294.24621.python-list at python.org>...
> # Python delimits a string it by single quotes preferably, unless
> # single quotes appear within the string while double quotes do
> # not, in which case it uses double quotes for string delimiters.
> # Checking the string contents, the C code stops at the first NUL.
> # We prefix the string with a single quote and a NUL, this forces
> # double quotes as delimiters for the whole prefixed string.  Then,
> # we get rid of the representation of the single quote and the NUL.
> 
> write('"' + repr("'\0" + value)[6:])

Ah, perfect!  Thanks :)

Jeremy




More information about the Python-list mailing list