Triple quoted repr

Discussion in 'Python' started by Edward C. Jones, Jun 3, 2004.

  1. On 2003-09-04, Rasmus Fogh said:

    > I need a way of writing strings or arbitrary Python code that will
    >
    > a) allow the strings to be read again unchanged (like repr)
    > b) write multiline strings as multiline strings instead of escaping
    > the \n's.
    >
    > A repr function that output triple-quoted strings with explicit
    > (non-escaped) linebreaks would be perfect.
    >
    > Failing that, what is the simplest way to get close to the goal?


    There were no responses. Anyone have an answer?
     
    Edward C. Jones, Jun 3, 2004
    #1
    1. Advertising

  2. Edward C. Jones

    Terry Reedy Guest

    "Edward C. Jones" <> wrote in message
    news:40be9310$0$2979$...
    > On 2003-09-04, Rasmus Fogh said:
    >
    > > I need a way of writing strings or arbitrary Python code that will
    > >
    > > a) allow the strings to be read again unchanged (like repr)
    > > b) write multiline strings as multiline strings instead of escaping
    > > the \n's.
    > >
    > > A repr function that output triple-quoted strings with explicit
    > > (non-escaped) linebreaks would be perfect.


    Other have given you possible solutions. Some comments:

    While there are triple-quoted and possibly multiline string *literals*,
    there are no triple-quoted or multiline string *objects* any more than
    there are raw-string objects. All 'types' of (byte) string literals are
    converted to the one and same (byte) string object type. Once a string
    object is initialized, the history of how it came to be (which also could
    be as an expression instead of literal) is lost.

    In particular, while chr(10) most usually arises from a literal linebreak
    and is intended to be interpreted as such, this is not always so. For
    instance, in a string of bytes, each of which represents an integer in
    range(256), chr(10) represents 10, not 'newline'.

    Repr does something simple that meets the criterion (a) of evaluability.
    In doing so, it avoids problems with the fact that 'explicit (non-escaped)
    linebreaks' are (most unfortunately) system dependent. As it is now, you
    can, I believe, transmit repr(s) on machine x to machine y, eval it on b,
    and dependibly get back s. At least before the recent addition of the
    universal newline facility, I believe that doing b) would have made this
    undependable (ie, broken a)).

    Terry J. Reedy
     
    Terry Reedy, Jun 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian van den Broek
    Replies:
    7
    Views:
    763
    Brian van den Broek
    Apr 19, 2005
  2. dmh2000

    triple quoted strings as comments

    dmh2000, Jan 31, 2006, in forum: Python
    Replies:
    14
    Views:
    532
    Jorgen Grahn
    Feb 6, 2006
  3. Jules Stevenson
    Replies:
    1
    Views:
    235
    Duncan Booth
    Mar 2, 2008
  4. Lawrence D'Oliveiro

    Triple-quoted strings hath not the Python-nature

    Lawrence D'Oliveiro, Oct 21, 2008, in forum: Python
    Replies:
    8
    Views:
    357
    Steven D'Aprano
    Oct 27, 2008
  5. Stef Mientki

    Triple quoted string in exec function ?

    Stef Mientki, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    270
    Stef Mientki
    Dec 30, 2008
Loading...

Share This Page