views:

184

answers:

3

In this little piece of code, what is the fourth line all about?

from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
    doSomethingWithResult(result.content)
+13  A: 

It's a HTTP status code, it means "OK" (EG: The server successfully answered the http request).

See a list of them here on wikipedia

Tim Schneider
Thank you, fyjham!!!
brilliant
+6  A: 

200 is the HTTP status code for "OK", a successful response. (Other codes you may be familiar with are 404 Not Found, 403 Forbidden, and 500 Internal Server Error.)

See RFC 2616 for more information.

Wyzard
Thanks for this link, Wyzard!!!
brilliant
+4  A: 

Whoever wrote that should have used a constant instead of a magic number. The httplib module has all the http response codes.

E.g.:

>>> import httplib
>>> httplib.OK
200
>>> httplib.NOT_FOUND
404
dangph
HTTP return codes are constant rather than a magic number. They won't magically change tomorrow ...
X-Istence
@X-Istence, you don't appear to know what the term "magic number" means. A magic number, in this context, is a numeric literal that appears in the code without explanation.
dangph