Mandis Quotes (aka retiring """ and ''')

Jeff Epler jepler at unpythonic.net
Mon Oct 4 17:45:32 CEST 2004


One problem I see is that certain 'x'-quoted strings are currently legal
Python program fragments.  For instance,
    xx = 'x'+'x'
and
    xx = 'x' '' 'x'
(two silly ways to speciy the string 'xx')

A real-life example where "Mandis quotes" would change the meaning of an
existing program:
    def m(rows):
        m = max([len(str(s)) for row in rows for s in row])
        return "\n".join([r(row, "%%%ds" % m) for row in rows])

    def r(row, fmt):
            return '|' + ' '.join([fmt % i for i in row]) + '|'

>>> print m([[1,2,3],[4,5,100]])
|  1   2   3|
|  4   5 100|

I didn't like that r'' strings were added, so I hope that "add one more
kind of string literal" is already dead-in-the-water as a proposal.
Especially since the removal of any kind of string literal is impossible
before Python 3000.  The fact that this would change the meaning of
legitimate programs, well, that's even worse.

These quotes are similar to perl's q{} quoting:
       Quote and Quote-like Operators

       While we usually think of quotes as literal values, in Perl they func-
       tion as operators, providing various kinds of interpolating and pattern
       matching capabilities.  Perl provides customary quote characters for
       these behaviors, but also provides a way for you to choose your quote
       character for any of them.  In the following table, a "{}" represents
       any pair of delimiters you choose.

           Customary  Generic        Meaning        Interpolates
               ''       q{}          Literal             no
               ""      qq{}          Literal             yes
[...]

       Non-bracketing delimiters use the same character fore and aft, but the
       four sorts of brackets (round, angle, square, curly) will all nest,
       which means that

               q{foo{bar}baz}

       is the same as

               'foo{bar}baz'
What advantage do mandis-quotes have over perl's q{}?  The bracketing
delimeters rule seems like a handy one when dealing with strings that
might be program source code, mathematical expressions, or even just
paragraphs of text with parentheticals.

Do any major editors (Emacs and Vim to me; others can name their favorite)
treat Mandis-quotes better than they treat triple-quotes?  For me,
the poor treatment in text editors of triple-quotes is their biggest
weakness, but parsing mandis-quotes seems no easier, and maybe harder.

Finally, I don't understand why
    ''here's the trick''
wouldn't be a single mandis-quoted string (equal to 'here\'s the trick'
and "here's the trick"), because the delimeter is '', and that
doesn't appear within the string.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041004/45b61b55/attachment.sig>


More information about the Python-list mailing list