Re: [Tutor] Socket error in class, part the second

2017-03-10 Thread Alan Gauld via Tutor
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

[Tutor] Socket error in class, part the second

2017-03-10 Thread leam hall
y'all, Thanks for the explanations! Sorry for the delay in responding, it's been a rough year these past couple weeks. 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

Re: [Tutor] Socket error in class

2017-03-06 Thread Steven D'Aprano
On Mon, Mar 06, 2017 at 12:35:27PM -0500, leam hall wrote: > What am I missing? Let us start by reading the exception that you get, below the class. That tells us *what* error occurred, but not how or why: > class mysocket(): > import socket > def __init__(self, sock=None); > if sock

Re: [Tutor] Socket error in class

2017-03-06 Thread Mats Wichmann
On 03/06/2017 10:35 AM, leam hall wrote: > What am I missing? > > > class mysocket(): > import socket > def __init__(self, sock=None); > if sock is None: > self.sock = socket.socket(socket.socket.AF_NET, > socket.socket.SOCK_STREAM) > else: > self.sock = sock > > >

Re: [Tutor] Socket error in class

2017-03-06 Thread Alan Gauld via Tutor
On 06/03/17 17:35, leam hall wrote: > What am I missing? I'd start by moving the import out of the class to its more normal position at the top of the file. > > class mysocket(): > import socket > def __init__(self, sock=None); > if sock is None: > self.sock =

[Tutor] Socket error in class

2017-03-06 Thread leam hall
What am I missing? class mysocket(): import socket def __init__(self, sock=None); if sock is None: self.sock = socket.socket(socket.socket.AF_NET, socket.socket.SOCK_STREAM) else: self.sock = sock Error: NameError: global name "socket" is not defined.