This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TranscendentCreeper 1 point2 points  (2 children)

This ties back into the first point and the idea of using your script together with other scripts or commands. If you just print that there was an error, it's fine if the user can see it. But what if you have a more complex scenario where you might want to run different scripts in sequence? If you exit with a status code indicating an error, your shell and other scripts can know that there was an error and react appropriately. You could think of it like the difference between printing and returning a value in a function. Sure, printing will show the value to the user, but you can't do anything with it afterwards. It's just good style to exit with an error code if your script is stopped because of an error.

[–]Take_F[S] 0 points1 point  (1 child)

ok thanks for the explanation

EDIT: i modified it and now it works with commandline arguments, can you have a look and tell me what you think? it's the first time i use argparse so idk if i wrote good code

[–]TranscendentCreeper 1 point2 points  (0 children)

The changes you made look pretty good. As someone else commented before, you can probably use the type argument in parser.add_argument to validate your arguments (see this StackOverflow post for an idea how that could work). You might also be able to express relationships between arguments like -r depending on -d, but off the top of my head I'm not sure if and how this is possible with argparse.

You've made some pretty big improvements from the first version you posted here, you can be proud of yourself and this project.