[Tutor] Socket error in class, part the second

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 10 14:11:49 EST 2017


On 10/03/17 12:38, leam hall wrote:

> As noted, the fix was to put the "import socket" above the class
> declaration. What confuses me is that in the calling program I'm importing
> the class:
> 
>   from mysocket import mysocket
> 
> In mysocket.py the "import socket" is above the class declaration. This
> works. I would have thought it would fail as the import statement only
> imports the class, not the entire module. 

Remember that you are importing the *name* not the
actual class code. The class object code remains
in the mysocket module where it can still access
the socket name that it, in turn, imported.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list