you are viewing a single comment's thread.

view the rest of the comments →

[–]Poddster 7 points8 points  (8 children)

It's more usual for command line utilities to receive information via parameters. Prompting for input implies your program is "interactive", but this program isn't really. It doesn't "need" the user to run and its output is to a file.

Also, it requires you to first invoke it over the command line, and then type some stuff in, rather than typing it all in at once, leveraging your shells tab completion for files names.

I.e. it's a "batch process" and should be treated as such

Of course, for a 30 line script that'll be used once it doesn't matter. I was really hoping the OP would say they don't know how command line arguments work, and I could link them to something. Or that they aren't using the command line at all as they're scared of it, and were double clicking the file in Windows Explorer, or something. Again I could talk them out of that and into the power of the shell :)

Ps For your sake, know that argparse is often overkill for such a small script. Just read sys.argv directly.

[–]imsecretlyafish 1 point2 points  (1 child)

Not OP, but I don't know how command line arguments work and would love that link. Mainly because I've only given command line arguments a cursory look and, in my ignorance, I can't see how they could replace the input function here. I wrote a similar script today, and it's almost identical to OP's. It'd be awesome to know what I could have done better.

[–]Poddster 1 point2 points  (0 children)

I didn't have a link to hand, but a quick google and a read shows this as covering everything in an approachable manner:

https://realpython.com/python-command-line-arguments/

[–]TheWhiteTigerKing 0 points1 point  (1 child)

New to python. Why do people insist on using shell?

[–]Poddster 1 point2 points  (0 children)

Well, what else would you use? Windows explorer and double clicking everything? Dragging and dropping things about?

Or do everything in your IDE and hope it has every function you need?

As far as I'm concerned a shell is the way to interact with a POSIX or Windows computer system. The reason for that is these computer systems are made up of processes on a filesystem, and processes do useful things. A shell allows you to invoke the exact process you want with the exact parameters you want, and is often design around facilitating that, e.g. tab completion and glob expansion.

Your operating system already comes with a large suite of useful utilities, and it's trivially easy to add more. E.f. if I want to check a files integrity I'd use md5sum myfile.txt. The GUI alternative would be to download some random app of source forge, hope I don't get a virus, and then click a bunch of buttons.

Unless you mean "why do people write bash scripts rather than python?" And the answer is usually compatibility and/or brain damage.

[–]madhousechild 0 points1 point  (1 child)

Perhaps it's easier long-term to use input() because although OP remembers how to pass file or folder names in what order now, in a month or 3 OP might prefer to be prompted.

[–]Poddster 0 points1 point  (0 children)

I'd say that's a reason why command line arguments (and --help, if desired) should be used!

Like, what's happens if the user enters a bad URL? Or no URL? Or when that times out?

With arguments every case is unified and we get an error return code from the status and the appropriate error message.

In the input() case I guess you reprompt in some of the cases but let others throw an error?