Re: Handlign exceptions - NEWBIE !!

hzsbg01!jbuhrma@hvgtw.att.com
Mon, 14 Mar 94 11:58:43 +0100

>>>>> On Mon, 14 Mar 1994 11:44:38 +0000, "Adrian Phillips (Tandem User)" <tandem@freeze.oslo.dnmi.no> said:

> Okay, so now I've tried:
> s = socket (AF_INET, SOCK_STREAM)
> while (1):
> try:
> s.bind (HOST, PORT)
> except socket.error:
> sys.stdout.write (socket.error[0] + socket.error[1])
> continue
> break

> ie. removed the quotes and now I get:

> Traceback (innermost last):
> File "./t1.py", line 12
> except socket.error:
> TypeError: attribute-less object

It looks like you have done `from socket import *'. Then you bind the
socket-function to the name `socket' (which of course has no `error'
attribute).

To prevent name-clashes, it's almost always better to say something like
`import socket'. But then you must not forget to change
< s = socket (AF_INET, SOCK_STREAM)
into
> s = socket.socket(AF_INET, SOCK_STREAM)

-- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma@hzsbg01.ns-nl.att.com> --
---------------------- +31 35 87.4799 --- ...!att!hvgtw!hzsbg01!jbuhrma ---
:w:q:wqZZ^X^C^\Quit - core dumped