472,958 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Triple quoted repr

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?
Jul 18 '05 #1
1 2346

"Edward C. Jones" <ed******@erols.com> wrote in message
news:40**********************@news.rcn.com...
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


Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anthony Roberts | last post by:
property = re.compile("""(?P<name>+)="(?P<value>.*?)""""re.I) This doesn't work because the closing quote in my regex forms the first quote of a triple quote to end the string... property =...
8
by: Christoph Zwerschke | last post by:
I sometimes use triple quotes in order to produce snippets of multiline code, like that: if output == html: snip = '''<html> <head><title>Hello, World</title></head> <body...
11
by: bearophile | last post by:
Hello, here are a four more questions (or suggestions) for the language (probably people have already discussed some of/all such things: I've seen the contracts for Python:...
7
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc...
3
by: Michele Simionato | last post by:
I am getting trouble with nested triple quoted strings in doctest. For instance $ cat x.py """ >>> dummy = ''' something here ''' """
14
by: dmh2000 | last post by:
I recently complained elsewhere that Python doesn't have multiline comments. i was told to use triple quoted strings to make multiline comments. My question is that since a triple quoted string is...
7
by: p.lavarre | last post by:
Subject: announce: FAQs suggested ... That suggested FAQ is misleadingly incorrect as stated - we need help rewording it. /F correctly commented: "eval" is never a good choice if you cannot...
2
by: Mark Tolonen | last post by:
I don't understand the behavior of the interpreter in Python 3.0. I am working at a command prompt in Windows (US English), which has a terminal encoding of cp437. In Python 2.5: Python 2.5...
8
by: Lawrence D'Oliveiro | last post by:
If triple-quoted strings had the Python-nature, then they would take indentation into account. Thus: """this is a multi-line string.""" would be equivalent to
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.