Rawest raw string literals

MRAB python at mrabarnett.plus.com
Thu Apr 20 17:54:42 EDT 2017


On 2017-04-20 22:03, Mikhail V wrote:
> On 20 April 2017 at 22:43, Random832 <random832 at fastmail.com> wrote:
>> On Thu, Apr 20, 2017, at 16:01, Grant Edwards wrote:
>>> On 2017-04-20, MRAB <python at mrabarnett.plus.com> wrote:
>>> > There _is_ a "universal solution"; it's called a Hollerith constant. :-)
>>>
>>> Wow, I haven't seen one of those in a _long_ time -- probably about 45
>>> years.  I think the first FORTAN implementation I used was WATFIV,
>>> which had just introduced the character type. But, books/classes on
>>> FORTRAN all still covered Hollerith constants.
>>
>> The IMAP protocol uses a similar kind of construct (the length is
>> enclosed in braces)
>>
>> Even ignoring the maintenance difficulty, I don't think it's possible to
>> syntax highlight something like that on most common editors.
>>
>> The best solution I can think of is to have a text editor designed to
>> parse a string literal, spawn a nested editor with the unescaped
>> contents of that string literal, and then re-escape it back to place in
>> the code. If we had that, then we wouldn't even need raw strings.
> 
> Yes exactly, it would be cool to have such a satellite app
> which can escape and unescape strings according to rules.
> And which can also convert unicode literals to their ascii
> analogues and back on the fly, this would very useful
> for programming.
> Probably it is a good idea to even include such thing
> in Python package. So it would be a small standalone app
> running parallel with text editor making it to copy paste strings.
> 
I'm sure it's possible in, say, Emacs.

The editor that I use (EditPad Pro) can call external tools, so I could:

1. Select the string literal (easy when it is syntax-aware, so I can 
select all of the literal with 2 keypresses).

2. Call the external tool (1 keypress), to open, say, a simple tkinter app.

3. Edit the unescaped text (unescape with ast.literal_eval, re-escape 
with 'ascii').

4. Close the external tool, and the selection is replaced.



More information about the Python-list mailing list