[Tutor] Is socket.socket() a func or a class

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Tutor] Is socket.socket() a func or a class

Khalid Al-Ghamdi
hi all,

I'm reading this book that says when creating a socket you have to use the socket.socket() function as in :

ss=socket.socket()

but whey i check they type it says it's a class which makes sense cause you're creating a socket object.

>>> type(ss)
<class 'socket.socket'>

so, which is it? or do authors loosely use these terms interchangeably in this context?  

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] Is socket.socket() a func or a class

Alan Gauld
On 06/04/12 07:10, Khalid Al-Ghamdi wrote:

> I'm reading this book that says when creating a socket you have to use
> the socket.socket() _function _as in :
...
>  >>> type(ss)
> <class 'socket.socket'>
>
> so, which is it? or do authors loosely use these terms interchangeably
> in this context?

It just looks like sloppy terminology to me.

 >>> import socket as s
 >>> s.socket
<class 'socket._socketobject'>
 >>> s.gethostbyname
<built-in function gethostbyname>

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] Is socket.socket() a func or a class

Steven D'Aprano-8
In reply to this post by Khalid Al-Ghamdi
Khalid Al-Ghamdi wrote:

> hi all,
>
> I'm reading this book that says when creating a socket you have to use the
> socket.socket() *function *as in :
>
> ss=socket.socket()
>
> but whey i check they type it says it's a class which makes sense cause
> you're creating a socket object.
>
>>>> type(ss)
> <class 'socket.socket'>
>
> so, which is it? or do authors loosely use these terms interchangeably in
> this context?

Yes. Sometimes people call things a function when technically they mean a
"callable". A callable is anything that can be called like a function:
functions, classes, types, methods, etc.


--
Steven

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor