Click to See Complete Forum and Search --> : Very basic python question


Pierre Lambion
12-15-2000, 03:26 AM
I am in no way a programmer so excuse me for this (I guess) basic question.
In Linux I was using "brag" to grap binaries from newsgroups. I wanted similar function in Beos so I wrote a small python script using the nntp and uu modules.

I don't have the code on this (at work) pc but I don't think it matters.

The idea is:

for the specified newsgroups:
get newsgroup info
for every article id :
get article body
write it to an external tmp
decode(tmp)

It was working great except when the article had no binary: uu then gives out an error and the whole process is interrupted. Python ends up with error messages.
To avoid this, the quick workaround was to call an external decde program. It's working OK but it is not the *right* way and it is not portable.

My question is: how do I avoid that an error on a part of my script makes it exit completely. I want uu to try to decode and if it fails, just do it silently and go to the next article. A simple check on the article content wouldn't be sufficient as I'm not handling multi-part attachments and therefore I would still get errors.

Should I set the decode part in a function or what?

Thx in adavnce,

Pierre

jemfinch
12-15-2000, 05:19 AM
I've never even thought of using nntplib, so it would be very helpful if you could post the code you're using (inside [ code ] tags)

Generally, though, in python errors are raised as "exceptions". This simply means an "exceptional condition has occured" and the program felt obliged to tell you. When you think an exception might occur, you stick the code that might cause it in a "try" block, telling python to "try this, and let me handle the exceptions". Then, you put stuff to handle the exceptions in an "except" block right after that. That's in an attempt to handle the exception.

I have a few try/except blocks in the code I posted in "python snippets", if you want to check it out.

Jeremy

Pierre Lambion
12-15-2000, 05:56 AM
Thx!

I think the "try:" thing should do it.

I will post tomorrow the code, hopefully corrected so you can have a look at it.

Pierre