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

Lulu of the Lotus-Eaters mertz at gnosis.cx
Tue Apr 8 20:08:10 EDT 2003


Carl Banks <imbosol-1049844119 at aerojockey.com> wrote previously:
|> Ahh... what I MEANT to write was, of course:
|>    '"%s"' % repr(aString)[1:-1].replace('"',r'\"')
|
|You misspelt
|     '"%s"' % repr(aString)[1:-1].replace('"',r'\"').replace(r"\'","'")

I'm not sure that's so.  The OP wanted "just like" repr(), but with
surrounding double quotes rather than single quote.  That seems like an
underspecification of whether single quotes are escaped.  If left
escaped, the result is just as Python-friendly (albeit slightly less
human-eyeball-friendly), so the simpler version is not obviously wrong.

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s






More information about the Python-list mailing list