Python 2.0 preliminary features?

Tim Peters tim_one at email.msn.com
Sat Oct 9 17:31:55 EDT 1999


[Preston Landers]
> ...
> By the way, is there a function equivilent to the following in the
> standard Python module library?
>
> def unquote(s):
>     """Remove any enclosing quotes around a string."""
>     if (s[:1] == "'" and s[-1:] == "'") or \
>        (s[:1] == '"' and s[-1:] == '"'):
>         return s[1:-1]
>     else:
>         return s

No.  Did you intend for it to transform "'" and '"' into empty strings?
Even if not, still no.  Even worse, think of any string transformation at
random, and chances are there's no std function for doing that one either
<wink>.

Note that it's a little easier to write this one via e.g.

    if s[:1] == "'" == s[-1:] or ...

or

    if s and s[0] == s[-1] and s[0] in "\"'":

guido-supplied-addition-we-can-add-42-ourselves-ly y'rs  - tim






More information about the Python-list mailing list