473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2367

"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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.