Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Question about the wording in the python documents.

Reply
Thread Tools

Question about the wording in the python documents.

 
 
grocery_stocker
Guest
Posts: n/a
 
      05-01-2009
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-2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>>
>>> url = 'http://www.google.com'
>>> req = urllib2.Request(url)
>>> response = urllib2.urlopen(req)
>>>


req is clearly an instance of urllib2.Request and not a Request object.
 
Reply With Quote
 
 
 
 
Emile van Sebille
Guest
Posts: n/a
 
      05-01-2009
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-2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import urllib2
>>>>
>>>> url = 'http://www.google.com'
>>>> req = urllib2.Request(url)
>>>> response = urllib2.urlopen(req)
>>>>

>
> 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 (urllib2)

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.
----^^^^^^^^^^^^^^^^


 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      05-02-2009
On Fri, 01 May 2009 13:02:59 -0700, grocery_stocker wrote:

> 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-2] on linux2 Type "help", "copyright", "credits" or "license"
> for more information.
>>>> import urllib2
>>>>
>>>> url = 'http://www.google.com'
>>>> req = urllib2.Request(url)
>>>> response = urllib2.urlopen(req)
>>>>
>>>>

> 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.


--
Steven
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      05-02-2009
In message <cb978535-4092-49ac-8d9f-
>, grocery_stocker wrote:

> 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.

 
Reply With Quote
 
grocery_stocker
Guest
Posts: n/a
 
      05-02-2009
On May 2, 4:14 am, Sebastian Wiesner <basti.wies...@gmx.net> wrote:
> <Steven D'Aprano>> 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?

>
> I guess the latter ...
>
> > 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.

>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wording suggestion for documentation (Data Model) Jason R. Coombs Python 0 06-13-2008 12:16 AM
Question on Wording Paulo Jorge de O. C. de Matos C Programming 8 05-05-2008 04:10 AM
clinic 2263 - wording ? Which is right ? - Bobb - MCDST 5 12-13-2005 05:14 AM
Accelerated C++: Clarification on the wording of exercises Frankie Montenegro C++ 3 10-14-2005 04:21 PM
Question on wording Kayla Digital Photography 11 07-19-2005 12:48 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57