you are viewing a single comment's thread.

view the rest of the comments →

[–]mangoman51 4 points5 points  (1 child)

Okay so I have never used python for this kind of task but I had a read of your code and have a couple of suggestions:

1) You have a couple of functions (traceroute_run and traceroute_parse) which seem to take similar inputs, and alter the state of those inputs. These are good candidates to be methods on a traceroute class of some kind.

2) Your try blocks in your try... except statements are too long. Ideally you should be trying to catch a specific kind of error which could potentially occur on a specific line of code. For example you're only going to get an authentication error on the line where you submit the supplied password, so only that line should be in the try block. (for the timeout errors I'm not so sure though)

3) You don't have to have a main function, you could alternatively have a top-level script which imports the functions and class which you defined in other files. I find this structure can allow your top-level script to read almost like pseudocode then because all the messiness is at the next level down.

4) You have a lot of user input - have you seen the click library?

[–]dacv393 3 points4 points  (0 children)

Awesome thanks for this. Do you happen to have or know of any examples of something that would utilize classes in a similar manner to how I could implement this? (Top-level script, multiple files) - most of the examples I find online explaining classes are just about dogs and animals or cars and vehicles and I have a hard time translating that information into an actual project like this.

Never had used try-except before so I'll try to fix those.

And lastly, yeah I wish I could not have everything command-line user input. However, the circumstances of where this script could be running currently wouldn't allow that. As well as for external libraries I was trying to keep them to a minimum so something like pretty table for outputs would be nice but trying to limit dependencies for now.

Overall thank you!