Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with ipaddress package
#6
(Jul-13-2022, 02:01 AM)supuflounder Wrote: I have never seen the /24 notation; if, as suggested, it is the subnet mask, it is irrelevant and the simplest thing would be to remove it.

It is a very, very, very bad idea to ever use exit() in any form within a program. Ever. Forget that you ever heard of this function, or any other function that terminates execution. They are all fundamentally bad ideas.

For example in your program, you run the program, there is a bad address in it, the program exits. You fix the bad address. You run it again. There is a second bad address. You fix it. You run it again. Etc. This is a terrible interface. You should simply note that there is an error, perhaps simply by implementing an error count. When you are all done, if the error count is greater than zero, you might consider raising an exception that you interpret as requesting the program terminate, which you capture in an except clause. But never, ever, think that it is valid to exit a program.

And, frankly, I'd store a tuple, with at least the IP address and line number in it, so the error message can give useful information, such as what line the error appeared on. This is part of being a professional programmer and knowing how to treat the users right. In addition, there is no reason to exit the program, because the correct response is to simply not add the bad IP address to the list of addresses you are going to use. Since the only thing the user can do is delete the offending line, why not just do that by ignoring it and generate a list of valid IP addresses which you will then use. The error messages are warning messages, the program runs to completion.

exit() and all similar functions are evil. Do not be evil.

thank you for the feedback. Im a 20+year network engineer starting my journey to become a capable coder. so i appreciate the advice.
Reply


Messages In This Thread
help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 08:55 PM
RE: help with ipaddress package - by Larz60+ - Jul-12-2022, 10:08 PM
RE: help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 10:26 PM
RE: help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 10:27 PM
RE: help with ipaddress package - by supuflounder - Jul-13-2022, 02:01 AM
RE: help with ipaddress package - by jcrubaugh45 - Jul-13-2022, 02:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ipaddress.IPv4Network tomthirteen 11 6,733 Jan-08-2019, 10:20 PM
Last Post: tomthirteen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020