[Tutor] new to python error handling question
alan.gauld at blueyonder.co.uk
Mon Apr 12 19:50:00 EDT 2004
I think you maybe need to slow down and take a few steps back here.
There are a few weird things in your code that suggest you don't
really understand whats happening and that will lead to problems
BTW YOu don;t say if you have any previous programming experience
in other languages? If so that helps us phrase our responses.
> def do_list(*??*):
The *??* is where you pass in values that your function will use.
In this function a sensible thing wouyld be the address used by
the ftp.retrlines call
You would then use the address parameter in here
You don't need this it literally does nothing!
> except (AttributeError):
This checks for an AttributeError being raised in the previous
try section. BTW I donlt think you need the parens around
If the try/except was missed out the error would be passed back
to Python and it would print an error message.
> print "AttributeError"
Again the pass does nothing
> return ()
And this returns an empty tuple to the caller, which is probably not
what you want?
> Why does it for sure detect AttributError when
> if i take the Try,Except off, it does'nt.
Dunno, can you show/tell us what you do get without the try/except?
It looks like you need to read the bit about defining functions
in your tutorial (whichever it is) soince you seem confused about
how they work. Also the try/except stuff. Both are covered in my
web tutor if you can't find it elsewhere, look under
"Modules & Functions" and "Error Handling"
Author of the Learn to Program web tutor
More information about the Tutor