[Tutor] looking for some general advice
Michael Klier
chi at chimeric.de
Sun Jun 10 21:19:39 CEST 2007
Alan Gauld wrote:
> 1) Best to be specific in your except clauses. Generic
> catch-anything type clauses can lead to misleading error
> messages. They are OKmat the top level of a program for
> distribution as a way of shielding innocent users from stack
> traces but during development and especially inside your
> code its better to catch specific exceptions.
>
> 2) Rather than putting the exception name in quotes
> "IndexError" just leave the quotes off and raise/catch the
> error class directly.
Ah, ok. I already wondered why one "IndexError" wasn`t caught even
though I tried to access a list item which was out of range. After
removing the quotes it worked.
Also, what would be the right exception to raise if not enough arguments
were passed to a programm?
> 3) argv = sys.argv
> Doesn't really achieve much, you might as well just use sys.argv,
> it's not much extra typing! nit-picking...
You`re right, it`s not much extra typing :).
> 4) For completeness you could avoid the os.system call to
> wget and implement it as a Python function using the ftplib
> library... (But to be honest wget is a lot easier!) Or maybe
> use the new subprocess module instead of os.system.
> You might also want to check that wget executed successfully.
I`ll take your advice about checking wegts exist status and thanks for
the tip with ftplib, although I think it`s a bit too much for my state
of python knowledge right now.
> Othewise I don't see too much to complain about.
>
> Well done, a good first program.
Thank you, and thanks for the reply.
Regards
Michael
--
Michael Klier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070610/26bfa850/attachment.pgp
More information about the Tutor
mailing list