merits of Lisp vs Python

Chris Mellon arkanes at gmail.com
Fri Dec 8 16:08:00 EST 2006


On 8 Dec 2006 12:23:54 -0800, Stephen Eilert <spedrosa at gmail.com> wrote:
>
> Alex Mizrahi escreveu:
>
>
> >
> > we should feed this text to the query-builder.
> > then we should bind ?dept to our variable departament (i'm not sure how this
> > is done in SPARQL, but there should be a way).
> > then we should iterate over results and output HTML. a python-like
> > pseudocode:
> >
> > query = BuildQuery(query_str)
> > query.bind("?dept", departament)
> > results = query.execute()
> > for each rs in results:
> >     print "<tr><td>" + htmlesc(rs.get("?fname")) + "</td><td>" +
> > htmlesc(rs.get("?lname")) + "</td><td>" + rs.get("?salary") + "</td></tr>"
>
> I just want to add that this kind of HTML mixed with code is something
> that should be avoided, no matter what language is used.
>

results = doQuery(department="Accounting")
for row in results:
    for field in ["fname","lname","salary"]:
        print "<td>%s</td>" % htmlesc(row[field])

I hide away the binding etc in doQuery as the lisp version does. Note
that in any kind of real code most of the literals that take up the
space are likely to come from elsewhere.

Note how much more trivial it is to change the HTML output of this
version that the lisp - it's a matter of creating a format string,
which you can retrieve from just about anywhere, rather than requiring
a code refactoring. Just because you have macros doesn't mean it makes
sense to use them.


>
> Stephen
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list