On 7/22/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Log:
> Run 2to3 over the Demo/ directory to shut up parse errors from 2to3
> about lingering print statements.
> ...
> Modified: python/branches/py3k-struni/Demo/cgi/cgi2.py
>
> ==============================================================================
> --- python/branches/py3k-struni/Demo/cgi/cgi2.py (original)
> +++ python/branches/py3k-struni/Demo/cgi/cgi2.py Tue Jul 17 22:59:35
> 2007
> @@ -8,15 +8,15 @@
>
> def main():
> form = cgi.FieldStorage()
> - print "Content-type: text/html"
> - print
> + print("Content-type: text/html")
> + print()
> if not form:
> - print "<h1>No Form Keys</h1>"
> + print("<h1>No Form Keys</h1>")
> else:
> - print "<h1>Form Keys</h1>"
> - for key in form.keys():
> + print("<h1>Form Keys</h1>")
> + for key in list(form.keys()):
> value = form[key].value
> - print "<p>", cgi.escape(key), ":", cgi.escape(value)
> + print("<p>", cgi.escape(key), ":", cgi.escape(value))
>
> if __name__ == "__main__":
> main()
>
> Shouldn't the list(dictionary.keys()) construct only be applied where it's
> needed?
Yeah, but the tool doesn't know when it is or isn't needed. You'd
think that "for x in d.keys(): ..." would be a context where it's
certainly not needed, but that's (alas) not true -- if the loop body
modifies d, the list() call is needed. See various other recent
checkins.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins