re Challenge: More Compact?
Quinn Dunkan
quinn at hork.ugcs.caltech.edu
Fri Jul 27 06:18:18 EDT 2001
On Mon, 16 Jul 2001 07:43:51 -0400, Roy Smith <roy at panix.com> wrote:
>quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) wrote:
>> for o in '.'.split(ip_addr):
>> assert 0 <= int(o) <= 255, 'ip octet not a byte in "%s"' % ip_addr
>
>Don't you also have to catch the ValueError you'll get if o is not a valid
>integer?
The whole point is to raise an exception if ip_addr is invalid, right? And
ValueError is probably the right one. In fact, you should probably catch the
AssertionError and convert that to a ValueError. But, as others have pointed
out, this will still pass a lot of invalid ip addresses.
More information about the Python-list
mailing list