[Python-talk] Help, it's not COBOL
Christopher Schmidt
crschmidt at crschmidt.net
Wed Jan 28 12:09:09 EST 2009
On Wed, Jan 28, 2009 at 12:03:09PM -0500, Mark Ordung wrote:
> Could someone tell a python (and any modern programming language) newbie
> what is going on in the below fragment - the end of a short CGI program?
> What is the name for the %(redirect) construct inside the string and and
> why do you need globals() to supply it's value (if that's what's going on?)
> since redirect appears to be a local variable?
>
> # redirect, or return a response if not redirecting
> redirect = form.getvalue('redirect', None)
>
> print "Content-type: text/html"
>
> if redirect:
> print "Location: %(redirect)s\n" % globals()
I don't know why this is being done. I would do, instead:
print "Location: %s\n" % redirect
What this is doing is taking redirect from globals and plopping it into
the string by using 'redirect' as a key in globals.
>>> c = {'a':'b'}
>>> print '%(a)s' % c
b
But I definitely don't see that as being neccesary....
> else:
> print
> print "Thanks for your feedback!"
>
> --
> "Doubt is not a pleasant condition, but certainty is absurd." – Voltaire
> _______________________________________________
> Python-talk mailing list
> Python-talk at dlslug.org
> http://dlslug.org/mailman/listinfo/python-talk
--
Christopher Schmidt
Web Developer
More information about the Python-talk
mailing list