exception problem

Michael Hudson mwh21 at cam.ac.uk
Fri Apr 14 11:58:16 CEST 2000


".:|:." <ng at hardlight.couk.com> writes:

>   File "/pr0n/getGroup.py", line 58, in ?
>     ArticleToFile(s, `i`)
>   File "/pr0n/getGroup.py", line 26, in ArticleToFile
>     decode(uufn, binfh)
>   File "/usr/lib/python1.5/uu.py", line 95, in decode
>     raise Error, 'No valid begin line found in input file'
> uu.Error: No valid begin line found in input file
> 
> from uu import *
> decode(infile, outfile)
> 
> raise Error, 'No valid begin line found in input file'
> uu.Error: No valid begin line found in input file
> 
> 
> how do i trap it
> 
> i've tried
> 
> try:
>     decode(infile, outfile)
> except uu.error:
>     pass
> 
> gives me
> 
> NameError uu :

Well, that's 'cause you did

from uu import *

which does not put `uu' into the local namespace ...

Two options:

1) don't do "from ... import *" (this is the right one <wink>)
2) try this:

try:
    decode(infile, outfile)
except error:
    pass

but that's fragile (see option 1).

Cheers,
M.

-- 
  "declare"?  my bogometer indicates that you're really programming
  in some other language and trying  to force Common Lisp into your
  mindset.  this won't work.           -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list