[Python-Dev] Python 1.7 tokenization feature request

gvwilson@nevex.com gvwilson@nevex.com
Mon, 13 Mar 2000 16:58:27 -0500 (EST)


> >Greg Wilson wrote:
> >...would people be willing to consider extending
> >Python's token set to make HTML/XML-ish spellings using entity reference=
s
> >legal?
> >
> >i =3D 0
> >while i < 10:
> >    print i & 1
> >    i =3D i + 1

> Skip Montanaro wrote:
> What makes it difficult to pump your Python code through cgi.escape when
> embedding it?

Most non-programmers use WYSIWYG editor, and many of these are moving
toward XML-compliant formats.  Parsing the standard character entities
seemed like a good first step toward catering to this (large) audience.

> Andrew Kuchling wrote:
> I don't think that would be sufficient.  What about user-defined
> entities, as in résultat =3D max(a,b)?  (r=9Bsultat, in French.)
> Would Python have to also parse a DTD from somewhere?

Longer term, I believe that someone is going to come out with a
programming language that (finally) leaves the flat-ASCII world behind,
and lets people use the structuring mechanisms (e.g. XML) that we have
developed for everyone else's data.  I think it would be to Python's
advantage to be first, and if I'm wrong, there's little harm done.
User-defined entities, DTD's, and the like are probably part of that, but
I don't think I know enough to know what to ask for.  Escaping the
standard entites seems like an easy start.

> Andrew Kuchling also wrote:
> What about other places when Python and XML syntax collide, as in this
> contrived example:
>=20
> <![CDATA[
> # Python code starts here
> if a[index[1]]>b:
>     print ...
>=20
> Oops!  The ]]> looks like the end of the CDATA section, but it's legal
> Python code.

Yup; that's one of the reasons I'd like to be able to write:

<python>
# Python code starts here
if a[index[1]]&gt;b:
    print ...
</python>

> Users certainly won't be writing this XML by hand; writing 'if (i &lt;
> 10)' is very strange.

I'd expect my editor to put '&lt;' in the file when I press the '<' key,
and to display '<' on the screen when viewing the file.

thanks,
Greg