library defined exceptions

Robin Munn rmunn at pobox.com
Wed Oct 30 18:18:18 EST 2002


On Wed, 30 Oct 2002 at 21:10 GMT, TuxTrax <TuxTrax at fortress.tuxnet.net> wrote:
> On 30 Oct 2002 12:52:18 GMT, Gerhard Häring Wrote in
> Steve Ballmers hair grease:
>> 
>> You need to qualify the exception classes as well, if you use the "import
>> module" form. I. e. use "nntplib.NNTPTemporaryError".
>> 
>> -- Gerhard
> 
> it needs to read:
> 
> try:
>     <code block>
> except nntplib.NNTPTemporaryError, errorarg:
>     <code block>
> 
> and python will recognize the nntplib defined exceptions, in this case
> NNTPTemporaryError?

That's correct. Exception names are just like any other names; they
reside in a namespace. When you import a module, only that module's name
gets added to your namespace; every name defined by the module,
including exceptions, go in that module's namespace and are referenced
as attributes of the module.

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838



More information about the Python-list mailing list