Question about the wording in the python documents.

  • Thread starter grocery_stocker
  • Start date
G

grocery_stocker

At the following url...

http://docs.python.org/library/urllib2.html

They have the following...

"urllib2.urlopen(url[, data][, timeout])

Open the URL url, which can be either a string or a Request
object"

I don't get how urllib2.urlopen() can take a Request object. When I do
the following....

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
req is clearly an instance of urllib2.Request and not a Request object.
 
E

Emile van Sebille

On 5/1/2009 1:02 PM grocery_stocker said...
At the following url...

http://docs.python.org/library/urllib2.html

They have the following...

"urllib2.urlopen(url[, data][, timeout])

Open the URL url, which can be either a string or a Request
object"

I don't get how urllib2.urlopen() can take a Request object. When I do
the following....

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
req is clearly an instance of urllib2.Request and not a Request object.

Yes -- it seems both the 'Request Object' and 'Request Instance' terms
are used.

If you feel it's a bug you can report this at http://bugs.python.org,
but I'm not sure what else an object would be if not an instance of a
class...

Emile
-----
Help on module urllib2:

NAME
urllib2 - An extensible library for opening URLs
using a variety of protocols

FILE
c:\python24\lib\urllib2.py

DESCRIPTION
The simplest way to use this module is to call the
urlopen function, which accepts a string containing
a URL or a Request object (described below).
---------------^^^^^^^^^^^^^^

<snip 2 paragraphs>

urlopen(url, data=None) -- basic usage is that same
as original urllib. pass the url and optionally data
to post to an HTTP URL, and get a file-like object
back. One difference is that you can also pass a
Request instance instead of URL.
----^^^^^^^^^^^^^^^^
 
S

Steven D'Aprano

I don't get how urllib2.urlopen() can take a Request object. When I do
the following....

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19) [GCC 4.1.1 20060928 (Red Hat
4.1.1-28)] on linux2 Type "help", "copyright", "credits" or "license"
for more information.req is clearly an instance of urllib2.Request and not a Request object.

It looks like a Request object to me. You create it by calling
urllib2.Request(url), and it's an object.

I don't understand your objection. Is it that the documentation calls it
Request instead of urllib2.Request? Or that it calls it an object instead
of an instance?

In either case, I think you're picking a nit so small that it isn't
actually there. All objects are instances (in Python), and all instances
are objects. And it should be clear from context that Request refers to
urllib2.Request, and not some mythical built-in Request object. I don't
believe that needs to be spelled out.
 
L

Lawrence D'Oliveiro

In message <cb978535-4092-49ac-8d9f-
req is clearly an instance of urllib2.Request and not a Request object.

"Object" is a term commonly used to mean "instance of a class". In Python,
classes are also objects, but if classes were meant rather than instances, I
imagine it would say so.
 
G

grocery_stocker

I guess the latter ...


Exactly, so strictly seen, "Request object" could possibly refer to the
urllib2.Request class itself. I guess, the OP would prefer the term
"Request instance", emphasizing, that an instance of the request class has
to be passed, not he class itself.

Yes, I personally think that the term "Request instance" would have
made it much clearer to us people that have never taken a computer
science class in our lives.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top