Quoted identifiers in Python?

Eddie and Babs kca17 at dial.pipex.com
Thu Mar 29 16:27:20 EST 2001


> Well, how would this work?

> a = "Ivory the engine"
> ax = obi.a

> What is ax?

"Ivor(y) the engine" is just an attribute name like any other, so you
couldn't do this any more than you could do:-

obj.name = "Rosy Blade"

x = "name"

y = obj.x

...and expect the y variable to contain "Rosy Blade". There is nothing
special about these quoted identifiers; they are just allowed to contain
characters other than those usually reserved for identifiers.



>
> So when I do
>
> x = "turn around"
>
> How does Python know whether I mean the string or the identifier?
>

We don't necessarily have to use the existing string quote characters to
delimit the quoted identifier. We could use angle brackets <...> or one of
the as-yet unused characters ($, @, ?). Or we could just prefix the first
quote character with something else like we do with Unicode strings. So we
could have:-

    x = i"turn around"

or
    x = _"turn around"

or whatever else you prefer. However, we run the risk of the old "static
inline friend void..." problem from C++: we might end up with things like

    iur"turn around"

Anyway, lexical analysis details aside, I think the basic idea of allowing
some form of QIs is a sound one.




More information about the Python-list mailing list